CMS 3D CMS Logo

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