CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_7/src/RecoTracker/DebugTools/src/FixTrackHitPattern.cc

Go to the documentation of this file.
00001 #include "RecoTracker/DebugTools/interface/FixTrackHitPattern.h"
00002 #include "RecoTracker/DebugTools/interface/GetTrackTrajInfo.h"
00003 
00004 #include "RecoTracker/Record/interface/TrackerRecoGeometryRecord.h"
00005 #include "RecoTracker/TkDetLayers/interface/GeometricSearchTracker.h"
00006 #include "RecoTracker/MeasurementDet/interface/MeasurementTracker.h"
00007 #include "TrackingTools/MeasurementDet/interface/MeasurementDet.h"
00008 #include "RecoTracker/Record/interface/CkfComponentsRecord.h"
00009 #include "DataFormats/TrackingRecHit/interface/InvalidTrackingRecHit.h"
00010 
00011 // To convert detId to subdet/layer number.
00012 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00013 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00014 //#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
00015 #include "DataFormats/TrackerCommon/interface/TrackerTopology.h"
00016 #include "Geometry/Records/interface/IdealGeometryRecord.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/Utilities/interface/Exception.h"
00029 
00030 FixTrackHitPattern::Result FixTrackHitPattern::analyze(const edm::EventSetup& iSetup, const reco::Track& track) 
00031 {
00032   // Recalculate the inner and outer missing hit patterns. See header file for detailed comments.
00033 
00034   Result result;
00035 
00036   using namespace std;
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   // This is needed to determine which sensors are functioning.
00048   edm::ESHandle<MeasurementTracker> measTk;
00049   iSetup.get<CkfComponentsRecord>().get(measTk);
00050   // Don't do this. It tries getting the tracker clusters, which do not exist in AOD.
00051   // Hopefully not needed if one simply wants to know which sensors are active.
00052   // measTk->update(iEvent);
00053 
00054   // Get the magnetic field and use it to define a propagator for extrapolating the track trajectory.
00055   edm::ESHandle<MagneticField> magField;
00056   iSetup.get<IdealMagneticFieldRecord>().get(magField);
00057   AnalyticalPropagator  propagator(&(*magField), alongMomentum);
00058 
00059   // This is used to check if a track is compatible with crossing a sensor.
00060   // Use +3.0 rather than default -3.0 here, so hit defined as inside acceptance if 
00061   // no more than 3*sigma outside detector edge, as opposed to more than 3*sigma inside detector edge.
00062   Chi2MeasurementEstimator estimator(30.,3.0);
00063 
00064   // Get the track trajectory and detLayer at each valid hit on the track.
00065   static GetTrackTrajInfo getTrackTrajInfo;
00066   vector<GetTrackTrajInfo::Result> trkTrajInfo = getTrackTrajInfo.analyze(iSetup, track);
00067   unsigned int nValidHits = trkTrajInfo.size();
00068 
00069   // Calculate the inner and outer hitPatterns on the track.
00070   // i.e. The list of where the track should have had hits inside its innermost valid hit 
00071   // and outside its outmost valid hit.
00072 
00073   enum InnerOuter {INNER = 1, OUTER=2};
00074   for (unsigned int inOut = INNER; inOut <= OUTER; inOut++) {
00075 
00076     // Get the track trajectory and detLayer at the inner/outermost valid hit.
00077     unsigned int ihit = (inOut == INNER) ? 0 : nValidHits - 1;
00078 
00079     // Check that information about the track trajectory was available for this hit.
00080     if (trkTrajInfo[ihit].valid) {
00081       const DetLayer* detLayer = trkTrajInfo[ihit].detLayer;
00082       const TrajectoryStateOnSurface& detTSOS = trkTrajInfo[ihit].detTSOS;
00083       const FreeTrajectoryState* detFTS = detTSOS.freeTrajectoryState();
00084 
00085       // When getting inner hit pattern, must propagate track inwards from innermost layer with valid hit.
00086       // When getting outer hit pattern, must propagate track outwards from outermost layer with valid hit.
00087       const PropagationDirection direc = (inOut == INNER) ? oppositeToMomentum : alongMomentum;
00088 
00089       // Find all layers this track is compatible with in the desired direction, starting from this layer.
00090       // Based on code in RecoTracker/TrackProducer/interface/TrackProducerBase.icc
00091       // N.B. The following call uses code in RecoTracker/TkNavigation/src/SimpleBarrelNavigableLayer::compatibleLayers() 
00092       // and RecoTracker/TkNavigation/src/SimpleNavigableLayer::wellInside(). 
00093       // These make some curious checks on the direction of the trajectory relative to its starting point,
00094       // so care was required above when calculating detFTS.
00095       vector<const DetLayer*> compLayers = detLayer->compatibleLayers(*detFTS, direc);
00096       LogDebug("FTHP")<<"Number of inner/outer "<<inOut<<" layers intercepted by track = "<<compLayers.size()<<endl;
00097 
00098       int counter = 0;
00099       reco::HitPattern newHitPattern;
00100 
00101       for(vector<const DetLayer *>::const_iterator it=compLayers.begin(); it!=compLayers.end();
00102           ++it){
00103         if ((*it)->basicComponents().empty()) {
00104           //this should never happen. but better protect for it
00105           edm::LogWarning("FixTrackHitPattern")<<"a detlayer with no components: I can not figure out a DetId from this layer. please investigate.";
00106           continue;
00107         }
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         propagator.setPropagationDirection(direc);
00112         vector< GeometricSearchDet::DetWithState > detWithState = (*it)->compatibleDets(detTSOS, propagator, estimator);
00113         // Check that at least one sensor was compatible with the track trajectory.
00114         if(detWithState.size() > 0) {
00115           // Check that this sensor is functional
00116           DetId id = detWithState.front().first->geographicalId();
00117           const MeasurementDet* measDet = measTk->idToDet(id);      
00118           if(measDet->isActive()){    
00119             // Hence record that the track should have produced a hit here, but did not.
00120             // Store the information in a HitPattern.
00121             InvalidTrackingRecHit  tmpHit(id, TrackingRecHit::missing);
00122             newHitPattern.set(tmpHit, counter);      
00123             counter++; 
00124           } else {
00125             // Missing hit expected here, since sensor was not functioning.
00126           }
00127         }
00128       }//end loop over compatible layers
00129 
00130       // Store this result.
00131       if (inOut == INNER) {
00132         result.innerHitPattern = newHitPattern;
00133       } else {
00134         result.outerHitPattern = newHitPattern;
00135       }
00136 
00137       // Print result for debugging.
00138       LogDebug("FTHP")<<"Number of missing hits "<<newHitPattern.numberOfHits()<<"/"<<counter<<endl;
00139       for (int j = 0; j < std::max(newHitPattern.numberOfHits(), counter); j++) {
00140         uint32_t hp = newHitPattern.getHitPattern(j);
00141         uint32_t subDet = newHitPattern.getSubStructure(hp);
00142         uint32_t layer = newHitPattern.getLayer(hp);
00143         uint32_t status = newHitPattern.getHitType(hp);
00144         LogDebug("FTHP")<<"           layer with no matched hit at counter="<<j<<" subdet="<<subDet<<" layer="<<layer<<" status="<<status<<endl;
00145       }
00146 
00147     } else {
00148       LogDebug("FTHP")<<"WARNING: could not calculate inner/outer hit pattern as trajectory info for inner/out hit missing"<<endl;
00149     }
00150 
00151   }
00152 
00153   return result;
00154 }