CMS 3D CMS Logo

/data/doxygen/doxygen-1.7.3/gen/CMSSW_4_2_8/src/AnalysisAlgos/TrackInfoProducer/src/TrackInfoProducerAlgorithm.cc

Go to the documentation of this file.
00001 #include "AnalysisAlgos/TrackInfoProducer/interface/TrackInfoProducerAlgorithm.h"
00002 #include "AnalysisDataFormats/TrackInfo/interface/TrackingRecHitInfo.h"
00003 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00004 #include "DataFormats/TrackReco/interface/Track.h"
00005 #include "DataFormats/TrackReco/interface/TrackFwd.h"
00006 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00007 #include "DataFormats/TrackerRecHit2D/interface/ProjectedSiStripRecHit2D.h"
00008 #include "DataFormats/TrackerRecHit2D/interface/SiStripMatchedRecHit2D.h"
00009 
00010 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00011 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00012 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00013 #include "Utilities/General/interface/CMSexception.h"
00014 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00015 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00016 
00017 using namespace reco;
00018 
00019 void TrackInfoProducerAlgorithm::run(const edm::Ref<std::vector<Trajectory> > traj_iterator,TrackRef track,
00020                                      TrackInfo &output,        const TrackerGeometry * tracker)
00021 {
00022 
00023     std::vector<TrajectoryMeasurement> measurements =traj_iterator->measurements();
00024     
00025     std::vector<TrajectoryMeasurement>::iterator traj_mes_iterator;
00026     //edm::LogInfo("TrackInfoProducer") << "Number of Measurements: "<<measurements.size();
00027     TrackInfo::TrajectoryInfo trajinfo;
00028     int nhit=0;
00029     for(traj_mes_iterator=measurements.begin();traj_mes_iterator!=measurements.end();traj_mes_iterator++){//loop on measurements
00030       
00031       TrajectoryStateOnSurface  fwdtsos=traj_mes_iterator->forwardPredictedState();
00032       TrajectoryStateOnSurface  bwdtsos=traj_mes_iterator->backwardPredictedState();
00033       TrajectoryStateOnSurface  updatedtsos=traj_mes_iterator->updatedState();
00034       TrajectoryStateCombiner statecombiner;
00035       TrajectoryStateOnSurface  combinedtsos=statecombiner.combine(fwdtsos, bwdtsos);
00036 
00037       ConstRecHitPointer ttrh=traj_mes_iterator->recHit();
00038       LocalPoint pos;
00039       if (ttrh->isValid())pos=ttrh->hit()->localPosition() ;
00040       nhit++;
00041       unsigned int detid=ttrh->hit()->geographicalId().rawId();
00042       
00043       trackingRecHit_iterator thehit;
00044       TrackingRecHitRef thehitref;
00045       int i=0,j=0;
00046 
00047       for (thehit=track->recHitsBegin();thehit!=track->recHitsEnd();thehit++){
00048         i++;
00049         LocalPoint hitpos;
00050         if ((*thehit)->isValid())hitpos=(*thehit)->localPosition();
00051         if((*thehit)->geographicalId().rawId()==detid&&
00052            (hitpos - pos).mag() < 1e-4)
00053           {
00054             thehitref=(*thehit);
00055             j++;
00056             break;
00057           }
00058       }
00059       TrajectoryStateTransform tsostransform;
00060       PTrajectoryStateOnDet* fwdptsod=tsostransform.persistentState( fwdtsos,detid);
00061       PTrajectoryStateOnDet* bwdptsod=tsostransform.persistentState( bwdtsos,detid);
00062       PTrajectoryStateOnDet* updatedptsod=tsostransform.persistentState( updatedtsos,detid);
00063       PTrajectoryStateOnDet* combinedptsod=tsostransform.persistentState( combinedtsos,detid);
00064       
00065 
00066       const ProjectedSiStripRecHit2D* phit=dynamic_cast<const ProjectedSiStripRecHit2D*>( &*(thehitref));
00067       const SiStripMatchedRecHit2D* matchedhit=dynamic_cast<const SiStripMatchedRecHit2D*>( &*(thehitref));
00068 
00069       RecHitType type=Single;
00070       LocalVector monofwd, stereofwd;
00071       LocalVector monobwd, stereobwd;
00072       LocalVector monoco, stereoco;
00073       LocalVector monoup, stereoup;
00074 
00075       LocalPoint pmonofwd, pstereofwd;
00076       LocalPoint pmonobwd, pstereobwd;
00077       LocalPoint pmonoco, pstereoco;
00078       LocalPoint pmonoup, pstereoup;
00079       if(matchedhit){
00080         type=Matched;
00081         GluedGeomDet * gdet=(GluedGeomDet *)tracker->idToDet(matchedhit->geographicalId());
00082         
00083         GlobalVector gtrkdirfwd=gdet->toGlobal(fwdptsod->parameters().momentum());
00084         GlobalVector gtrkdirbwd=gdet->toGlobal(bwdptsod->parameters().momentum());
00085         GlobalVector gtrkdirup=gdet->toGlobal(updatedptsod->parameters().momentum());
00086         GlobalVector gtrkdirco=gdet->toGlobal(combinedptsod->parameters().momentum());
00087         
00088 
00089         
00090         const GeomDetUnit * monodet=gdet->monoDet();
00091         
00092         monofwd=monodet->toLocal(gtrkdirfwd);
00093         monobwd=monodet->toLocal(gtrkdirbwd);
00094         monoup=monodet->toLocal(gtrkdirup);
00095         monoco=monodet->toLocal(gtrkdirco);
00096 
00097         pmonofwd=project(gdet,monodet,fwdptsod->parameters().position(),monofwd);
00098         pmonobwd=project(gdet,monodet,bwdptsod->parameters().position(),monobwd);
00099         pmonoup=project(gdet,monodet,updatedptsod->parameters().position(),monoup);
00100         pmonoco=project(gdet,monodet,combinedptsod->parameters().position(),monoco);
00101 
00102 
00103         const GeomDetUnit * stereodet=gdet->stereoDet();
00104         
00105         stereofwd=stereodet->toLocal(gtrkdirfwd);
00106         stereobwd=stereodet->toLocal(gtrkdirbwd);
00107         stereoup=stereodet->toLocal(gtrkdirup);
00108         stereoco=stereodet->toLocal(gtrkdirco);
00109 
00110         pstereofwd=project(gdet,stereodet,fwdptsod->parameters().position(),stereofwd);
00111         pstereobwd=project(gdet,stereodet,bwdptsod->parameters().position(),stereobwd);
00112         pstereoup=project(gdet,stereodet,updatedptsod->parameters().position(),stereoup);
00113         pstereoco=project(gdet,stereodet,combinedptsod->parameters().position(),stereoco);
00114 
00115 
00116       }
00117       else if(phit){
00118         type=Projected;
00119         GluedGeomDet * gdet=(GluedGeomDet *)tracker->idToDet(phit->geographicalId());
00120         
00121         GlobalVector gtrkdirfwd=gdet->toGlobal(fwdptsod->parameters().momentum());
00122         GlobalVector gtrkdirbwd=gdet->toGlobal(bwdptsod->parameters().momentum());
00123         GlobalVector gtrkdirup=gdet->toGlobal(updatedptsod->parameters().momentum());
00124         GlobalVector gtrkdirco=gdet->toGlobal(combinedptsod->parameters().momentum());
00125         const SiStripRecHit2D&  originalhit=phit->originalHit();
00126         const GeomDetUnit * det;
00127         if(!StripSubdetector(originalhit.geographicalId().rawId()).stereo()){
00128           det=gdet->monoDet();
00129           monofwd= det->toLocal(gtrkdirfwd);
00130           monobwd= det->toLocal(gtrkdirbwd);
00131           monoup=  det->toLocal(gtrkdirup);
00132           monoco=  det->toLocal(gtrkdirco);
00133           pmonofwd=project(gdet,det,fwdptsod->parameters().position(),monofwd);
00134           pmonobwd=project(gdet,det,bwdptsod->parameters().position(),monobwd);
00135           pmonoup=project(gdet,det,updatedptsod->parameters().position(),monoup);
00136           pmonoco=project(gdet,det,combinedptsod->parameters().position(),monoco);
00137         }
00138         else{
00139           det=gdet->stereoDet();
00140           stereofwd= det->toLocal(gtrkdirfwd);
00141           stereobwd= det->toLocal(gtrkdirbwd);
00142           stereoup=  det->toLocal(gtrkdirup);
00143           stereoco=  det->toLocal(gtrkdirco);
00144           pstereofwd=project(gdet,det,fwdptsod->parameters().position(),stereofwd);
00145           pstereobwd=project(gdet,det,bwdptsod->parameters().position(),stereobwd);
00146           pstereoup=project(gdet,det,updatedptsod->parameters().position(),stereoup);
00147           pstereoco=project(gdet,det,combinedptsod->parameters().position(),stereoco);
00148         }
00149       }
00150       TrackingRecHitInfo::TrackingStates states;
00151       if(forwardPredictedStateTag_!="") states.insert(std::make_pair(FwPredicted, TrackingStateInfo(std::make_pair(monofwd,stereofwd), std::make_pair(pmonofwd,pstereofwd), *fwdptsod)));
00152       if(backwardPredictedStateTag_!="")states.insert(std::make_pair(BwPredicted, TrackingStateInfo(std::make_pair(monobwd,stereobwd), std::make_pair(pmonobwd,pstereobwd), *bwdptsod)));
00153       if(updatedStateTag_!="")states.insert(std::make_pair(Updated, TrackingStateInfo(std::make_pair(monoup,stereoup), std::make_pair(pmonoup,pstereoup), *updatedptsod)));
00154       if(combinedStateTag_!="")states.insert(std::make_pair(Combined, TrackingStateInfo(std::make_pair(monoco,stereoco), std::make_pair(pmonoco,pstereoco), *combinedptsod)));
00155       
00156       TrackingRecHitInfo  tkRecHitInfo(type, states);
00157       
00158       
00159       
00160       if(j!=0){
00161         trajinfo.insert(std::make_pair(thehitref,tkRecHitInfo));
00162       }
00163       //      else  edm::LogInfo("TrackInfoProducer") << "RecHit not associated ";
00164     }
00165     //edm::LogInfo("TrackInfoProducer") << "Found "<<nhit<< " hits";
00166     //if(fwdtrajinfo.size()!=nhit) edm::LogInfo("TrackInfoProducer") << "Number of trackinfos  "<<fwdtrajinfo.size()<< " doesn't match!";
00167     output=TrackInfo((traj_iterator->seed()),trajinfo);
00168     
00169 }
00170 
00171 LocalPoint TrackInfoProducerAlgorithm::project(const GeomDet *det,const GeomDet* projdet,LocalPoint position,LocalVector trackdirection)const
00172 {
00173   
00174   GlobalPoint globalpoint=(det->surface()).toGlobal(position);
00175   
00176   // position of the initial and final point of the strip in glued local coordinates
00177   LocalPoint projposition=(projdet->surface()).toLocal(globalpoint);
00178   
00179   //correct the position with the track direction
00180   
00181   float scale=-projposition.z()/trackdirection.z();
00182   
00183   projposition+= scale*trackdirection;
00184   
00185   return projposition;
00186 }