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