CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_4/src/RecoTracker/DebugTools/src/GetTrackTrajInfo.cc

Go to the documentation of this file.
00001 #include "RecoTracker/DebugTools/interface/GetTrackTrajInfo.h"
00002 
00003 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00004 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00005 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00006 
00007 // To convert detId to subdet/layer number.
00008 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00009 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00010 //#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00011 #include "DataFormats/SiStripDetId/interface/TIBDetId.h"
00012 #include "DataFormats/SiStripDetId/interface/TOBDetId.h"
00013 #include "DataFormats/SiStripDetId/interface/TECDetId.h"
00014 #include "DataFormats/SiStripDetId/interface/TIDDetId.h"
00015 #include "DataFormats/SiPixelDetId/interface/PXBDetId.h"
00016 #include "DataFormats/SiPixelDetId/interface/PXFDetId.h"
00017 
00018 #include "TrackingTools/KalmanUpdators/interface/Chi2MeasurementEstimator.h"
00019 #include "TrackingTools/GeomPropagators/interface/AnalyticalPropagator.h"
00020 
00021 #include "TrackingTools/DetLayers/interface/NavigationSchool.h"
00022 #include "RecoTracker/Record/interface/NavigationSchoolRecord.h"
00023 #include "TrackingTools/DetLayers/interface/NavigationSetter.h"
00024 
00025 #include "TrackingTools/Records/interface/TransientTrackRecord.h"
00026 #include "DataFormats/Math/interface/deltaPhi.h"
00027 
00028 #include "FWCore/MessageLogger/interface/MessageLogger.h"
00029 
00030 #include "FWCore/Utilities/interface/Exception.h"
00031 
00032 std::vector< GetTrackTrajInfo::Result > GetTrackTrajInfo::analyze(const edm::EventSetup& iSetup, const reco::Track& track) 
00033 {
00034   // Determine the track trajectory and detLayer at each layer that the track produces a hit in.
00035 
00036   std::vector< GetTrackTrajInfo::Result > results;
00037 
00038   // Initialise Tracker geometry info (not sufficient to do this only on first call).
00039   edm::ESHandle<GeometricSearchTracker> tracker;
00040   iSetup.get<TrackerRecoGeometryRecord>().get( tracker );    
00041 
00042   // This is also needed to extrapolate amongst the tracker layers.
00043   edm::ESHandle<NavigationSchool> theSchool;
00044   iSetup.get<NavigationSchoolRecord>().get("SimpleNavigationSchool",theSchool);
00045   NavigationSetter junk(*theSchool);
00046 
00047   // Get the magnetic field and use it to define a propagator for extrapolating the track trajectory.
00048   edm::ESHandle<MagneticField> magField;
00049   iSetup.get<IdealMagneticFieldRecord>().get(magField);
00050   AnalyticalPropagator  propagator(&(*magField), alongMomentum);
00051 
00052   // This is used to check if a track is compatible with crossing a sensor.
00053   // Use +3.0 rather than default -3.0 here, so hit defined as inside acceptance if 
00054   // no more than 3*sigma outside detector edge, as opposed to more than 3*sigma inside detector edge.
00055   Chi2MeasurementEstimator estimator(30.,3.0);
00056 
00057   // Convert track to transientTrack, and hence to TSOS at its point of closest approach to beam.
00058   iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",trkTool_); // Needed for vertex fits
00059   reco::TransientTrack t_trk = trkTool_->build(track);
00060   TrajectoryStateOnSurface initTSOS = t_trk.impactPointState();
00061   LogDebug("GTTI")<<"TRACK TSOS POS: x="<<initTSOS.globalPosition().x()<<" y="<<initTSOS.globalPosition().y()<<" z="<<initTSOS.globalPosition().z();
00062 
00063   // Note if the track is going into +ve or -ve z.
00064   // This is only used to guess if the track is more likely to have hit a +ve rather than a -ve endcap
00065   // disk. Since the +ve and -ve disks are a long way apart, this approximate method is good enough.
00066   // More precise would be to check both possiblities and see which one (if either) the track crosses
00067   // using detLayer::compatible().
00068   bool posSide = track.eta() > 0;
00069 
00070   // Get hit patterns of this track
00071   const reco::HitPattern& hp = track.hitPattern(); 
00072 
00073   // Loop over info for each hit
00074   // N.B. Hits are sorted according to increasing distance from origin by
00075   // RecoTracker/TrackProducer/src/TrackProducerBase.cc
00076   for (int i = 0; i < hp.numberOfHits(); i++) {
00077     uint32_t hit = hp.getHitPattern(i);
00078     if (hp.trackerHitFilter(hit) && hp.validHitFilter(hit)) {
00079       uint32_t subDet = hp.getSubStructure(hit);
00080       uint32_t layer = hp.getLayer(hit);
00081       // subdet: PixelBarrel=1, PixelEndcap=2, TIB=3, TID=4, TOB=5, TEC=6
00082       LogDebug("GTTI")<<"    hit in subdet="<<subDet<<" layer="<<layer;
00083 
00084       // Get corresponding DetLayer object (based on code in GeometricSearchTracker::idToLayer(...)
00085       const DetLayer* detLayer = 0;
00086       if (subDet == StripSubdetector::TIB) {
00087         detLayer = tracker->tibLayers()[layer - 1];
00088       } else if (subDet == StripSubdetector::TOB) {
00089         detLayer = tracker->tobLayers()[layer - 1];
00090       } else if (subDet == StripSubdetector::TID) {
00091         detLayer = posSide ? tracker->posTidLayers()[layer - 1] : tracker->negTidLayers()[layer - 1];
00092       } else if (subDet == StripSubdetector::TEC) {
00093         detLayer = posSide ? tracker->posTecLayers()[layer - 1] : tracker->negTecLayers()[layer - 1];
00094       } else if (subDet == PixelSubdetector::PixelBarrel) {
00095         detLayer = tracker->pixelBarrelLayers()[layer - 1];
00096       } else if (subDet == PixelSubdetector::PixelEndcap) {
00097         detLayer = posSide ? tracker->posPixelForwardLayers()[layer - 1] : tracker->negPixelForwardLayers()[layer - 1];
00098       }
00099 
00100       // Store the results for this hit.
00101       Result result;
00102       result.detLayer = detLayer;
00103 
00104       // Check that the track crosses this layer, and get the track trajectory at the crossing point.
00105       std::pair<bool, TrajectoryStateOnSurface> layCross = detLayer->compatible(initTSOS, propagator, estimator);
00106       if (layCross.first) {
00107         LogDebug("GTTI")<<"crossed layer at "<<" x="<<layCross.second.globalPosition().x()<<" y="<<layCross.second.globalPosition().y()<<" z="<<layCross.second.globalPosition().z();
00108 
00109         // Find the sensor in this layer which is closest to the track trajectory.
00110         // And get the track trajectory at that sensor.
00111         const PropagationDirection along = alongMomentum;
00112         propagator.setPropagationDirection(along);
00113         std::vector< GeometricSearchDet::DetWithState > detWithState = detLayer->compatibleDets(initTSOS, propagator, estimator);
00114         // Check that at least one sensor was compatible with the track trajectory.
00115         if(detWithState.size() > 0) {
00116           // Store track trajectory at this sensor.
00117           result.valid    = true;
00118           result.accurate = true;
00119           result.detTSOS  = detWithState.front().second;
00120           LogDebug("GTTI")<<"      Det in this layer compatible with TSOS: subdet="<<subDet<<" layer="<<layer;
00121           LogDebug("GTTI")<<"      crossed sensor at x="<<result.detTSOS.globalPosition().x()<<" y="<<result.detTSOS.globalPosition().y()<<" z="<<result.detTSOS.globalPosition().z();
00122 
00123         } else {
00124           // Track did not cross a sensor, so store approximate result from its intercept with the layer.
00125           result.valid    = true;
00126           result.accurate = false;
00127           result.detTSOS  = layCross.second;
00128           LogDebug("GTTI")<<"      WARNING: TSOS not compatible with any det in this layer, despite having a hit in it !";
00129         }
00130 
00131       } else {
00132         // Track trajectory did not cross layer. Pathological case.
00133         result.valid = false;
00134         LogDebug("GTTI")<<"      WARNING: track failed to cross layer, despite having a hit in hit !";
00135       }
00136 
00137       results.push_back(result);
00138     }
00139   }
00140 
00141   return results;
00142 }