CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_5_3_14/src/CalibTracker/SiStripHitEfficiency/src/TrajectoryAtInvalidHit.cc

Go to the documentation of this file.
00001 #include "CalibTracker/SiStripHitEfficiency/interface/TrajectoryAtInvalidHit.h"
00002 #include "TrackingTools/TrackFitters/interface/TrajectoryStateCombiner.h"
00003 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateOnSurface.h"
00004 #include "TrackingTools/TrajectoryState/interface/TrajectoryStateTransform.h"
00005 #include "Geometry/CommonDetUnit/interface/GeomDetUnit.h"
00006 #include "Geometry/CommonTopologies/interface/StripTopology.h"
00007 #include "Geometry/CommonTopologies/interface/PixelTopology.h"
00008 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementError.h"
00009 #include "DataFormats/GeometryCommonDetAlgo/interface/MeasurementVector.h"
00010 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00011 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00012 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00013 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00014 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00015 #include "Geometry/TrackerGeometryBuilder/interface/GluedGeomDet.h"
00016 // #include "RecoTracker/MeasurementDet/interface/RecHitPropagator.h"
00017 #include "TrackingTools/TransientTrackingRecHit/interface/TrackingRecHitProjector.h"
00018 #include "RecoTracker/TransientTrackingRecHit/interface/ProjectedRecHit2D.h"
00019 
00020 using namespace std;
00021 TrajectoryAtInvalidHit::TrajectoryAtInvalidHit( const TrajectoryMeasurement& tm, 
00022                                             const TrackerGeometry* tracker,
00023                                             const Propagator& propagator,
00024                                             const unsigned int mono)
00025 {
00026   if ( tm.backwardPredictedState().isValid() ) 
00027     theCombinedPredictedState = TrajectoryStateCombiner().combine( tm.forwardPredictedState(),
00028                                                                    tm.backwardPredictedState());
00029   else 
00030     theCombinedPredictedState = tm.forwardPredictedState();
00031   
00032   if (!theCombinedPredictedState.isValid()) {
00033     return;
00034   }
00035   theHit = tm.recHit();  
00036   iidd = theHit->geographicalId().rawId();
00037   StripSubdetector strip=StripSubdetector(iidd);
00038   unsigned int subid=strip.subdetId();
00039   // xB and yB are for absolute borders on the trajectories included in the study, sigmaX sigmaY are 
00040   // significance cuts on the distance from the detector surface
00041   float xB = 0.; float sigmaX = 5.0;
00042   float yB = 0.; float sigmaY = 5.0;
00043   float sigmaYBond = 0.;
00044   //set bounds for point to be within to be counted in the study
00045   if (subid ==  StripSubdetector::TOB) { 
00046     sigmaYBond = 5.0;
00047   }
00048   const GeomDetUnit * monodet;
00049   
00050   // if module is from a double sided layer, write out info for either the
00051   // rphi surface (mono = 1) or the stereo surface (mono = 2)--not the matched hit surface
00052   if (( mono > 0 ) && isDoubleSided(iidd) ) {
00053     // find matched det id, that is the matched hit surface between the two sensors
00054     unsigned int matched_iidd = iidd-(iidd & 0x3);
00055     DetId matched_id(matched_iidd);
00056     
00057     GluedGeomDet * gdet=(GluedGeomDet *)tracker->idToDet(matched_id);
00058     
00059     // get the sensor det indicated by mono
00060     if (mono == 1) monodet=gdet->stereoDet();
00061     else  monodet=gdet->monoDet(); // this should only be mono == 2
00062 
00063     // set theCombinedPredictedState to be on the sensor surface, not the matched surface
00064     DetId mono_id = monodet->geographicalId();
00065     const Surface &surface = tracker->idToDet(mono_id)->surface();
00066     theCombinedPredictedState = propagator.propagate(theCombinedPredictedState, 
00067                                                      surface);
00068 
00069     if (!theCombinedPredictedState.isValid()) {
00070       cout << "found invalid combinedpredictedstate after propagation"<< endl;
00071       return;
00072     }
00073 
00074     //check if hit on trajectory is valid for this sensor
00075     if ((iidd & 0x3)==0) {
00076       // passed id is on matched surface (ie neither rphi, nor stereo surface)
00077       // so the rechits on both sensors should be invalid
00078       hasValidHit = theHit->isValid();
00079       //cout << "should always be invalid = " << theHit->isValid() << endl;
00080     } else {
00081       if (iidd==mono_id) {
00082         //mono sensor for this TrajAtInvalidHit is same as originally passed in from trajectory
00083         //normally should only happen for valid hits, but sometimes is invalid
00084         hasValidHit = theHit->isValid();
00085         //cout << "check always true = " << theHit->isValid() << endl;
00086       } else {
00087         // mono sensor for this TrajAtInvalidHit is not as originally passed in from trajectory
00088         // so this is a partner missing from the trajectory and is thus invalid
00089         hasValidHit = false;
00090         //cout << "setting invalid by fiat" << endl;
00091       }
00092     }
00093     
00094     //set module id to be mono det
00095     iidd = monodet->geographicalId().rawId();
00096   } else {
00097     monodet = (GeomDetUnit*)theHit->det();
00098     hasValidHit = theHit->isValid();
00099   }
00100   
00101   locX = theCombinedPredictedState.localPosition().x();
00102   locY = theCombinedPredictedState.localPosition().y();
00103   locZ = theCombinedPredictedState.localPosition().z();
00104   locXError = sqrt(theCombinedPredictedState.localError().positionError().xx());
00105   locYError = sqrt(theCombinedPredictedState.localError().positionError().yy());
00106   locDxDz = theCombinedPredictedState.localParameters().vector()[1];
00107   locDyDz = theCombinedPredictedState.localParameters().vector()[2];
00108   globX = theCombinedPredictedState.globalPosition().x();
00109   globY = theCombinedPredictedState.globalPosition().y();
00110   globZ = theCombinedPredictedState.globalPosition().z();
00111   
00112   // this should never be a glued det, only rphi or stero
00113   //cout << "From TrajAtValidHit module " << iidd << "   matched/stereo/rphi = " << ((iidd & 0x3)==0) << "/" << ((iidd & 0x3)==1) << "/" << ((iidd & 0x3)==2) << endl;
00114     
00115   // Restrict the bound regions for better understanding of the modul assignment. 
00116 
00117   LocalPoint BoundedPoint;
00118   float xx, yy ,zz;
00119 
00120   // Insert the bounded values 
00121   if (locX < 0. ) xx = min(locX - xB,locX - sigmaX*locXError);
00122   else  xx = max(locX + xB, locX + sigmaX*locXError);
00123 
00124   if (locY < 0. ) yy = min(locY - yB,locY - sigmaY*locYError);
00125   else  yy = max(locY + yB, locY + sigmaY*locYError);
00126 
00127   zz = theCombinedPredictedState.localPosition().z();
00128 
00129   BoundedPoint = LocalPoint(xx,yy,zz);
00130   
00131   if ( monodet->surface().bounds().inside(BoundedPoint) && abs(locY) > sigmaYBond*locYError ){
00132     acceptance = true;
00133   }
00134   else {
00135     // hit is within xB, yB from the edge of the detector, so throw it out 
00136     acceptance = false;
00137   }
00138 }
00139 
00140 double TrajectoryAtInvalidHit::localX() const
00141 {
00142   return locX;
00143 }
00144 double TrajectoryAtInvalidHit::localY() const
00145 {
00146   return locY;
00147 }
00148 double TrajectoryAtInvalidHit::localZ() const
00149 {
00150   return locZ;
00151 }
00152 double TrajectoryAtInvalidHit::localErrorX() const
00153 {
00154   return locXError;
00155 }
00156 double TrajectoryAtInvalidHit::localErrorY() const
00157 {
00158   return locYError;
00159 }
00160 double TrajectoryAtInvalidHit::localDxDz() const {
00161   return locDxDz;
00162 }
00163 double TrajectoryAtInvalidHit::localDyDz() const {
00164   return locDyDz;
00165 }
00166 double TrajectoryAtInvalidHit::globalX() const
00167 {
00168   return globX;
00169 }
00170 double TrajectoryAtInvalidHit::globalY() const
00171 {
00172   return globY;
00173 }
00174 double TrajectoryAtInvalidHit::globalZ() const
00175 {
00176   return globZ;
00177 }
00178 
00179 unsigned int TrajectoryAtInvalidHit::monodet_id() const
00180 {
00181   return iidd;
00182 }
00183 
00184 bool TrajectoryAtInvalidHit::withinAcceptance() const
00185 {
00186   return acceptance;
00187 }
00188 
00189 bool TrajectoryAtInvalidHit::validHit() const
00190 {
00191   return hasValidHit;
00192 }
00193 
00194 bool TrajectoryAtInvalidHit::isDoubleSided(unsigned int iidd) const {
00195   StripSubdetector strip=StripSubdetector(iidd);
00196   unsigned int subid=strip.subdetId();
00197   unsigned int layer = 0;
00198   if (subid ==  StripSubdetector::TIB) { 
00199     TIBDetId tibid(iidd);
00200     layer = tibid.layer();
00201     if (layer == 1 || layer == 2) return true;
00202     else return false;
00203   }
00204   else if (subid ==  StripSubdetector::TOB) { 
00205     TOBDetId tobid(iidd);
00206     layer = tobid.layer() + 4 ; 
00207     if (layer == 5 || layer == 6) return true;
00208     else return false;
00209   }
00210   else if (subid ==  StripSubdetector::TID) { 
00211     TIDDetId tidid(iidd);
00212     layer = tidid.ring() + 10;
00213     if (layer == 11 || layer == 12) return true;
00214     else return false;
00215   }
00216   else if (subid ==  StripSubdetector::TEC) { 
00217     TECDetId tecid(iidd);
00218     layer = tecid.ring() + 13 ; 
00219     if (layer == 14 || layer == 15 || layer == 18) return true;
00220     else return false;
00221   }
00222   else
00223     return false;
00224 }
00225 
00226 TrajectoryStateOnSurface TrajectoryAtInvalidHit::tsos() const {
00227   return theCombinedPredictedState;
00228 }