CMS 3D CMS Logo

CheckHitPattern.cc
Go to the documentation of this file.
2 
3 // To get Tracker Geometry
7 
8 // To convert detId to subdet/layer number.
11 //#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
14 
17 
20 
22 
23  //Retrieve tracker topology from geometry
25  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
26  const TrackerTopology* const tTopo = tTopoHandle.product();
27 
28  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",trkTool_); // Needed for vertex fits
29 
30  //
31  // Note min/max radius (z) of each barrel layer (endcap disk).
32  //
33 
34  geomInitDone_ = true;
35 
36  // Get Tracker geometry
37  edm::ESHandle<TrackerGeometry> trackerGeometry;
38  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
39  const TrackingGeometry::DetContainer& dets = trackerGeometry->dets();
40 
41  // Loop over all modules in the Tracker.
42  for (unsigned int i = 0; i < dets.size(); i++) {
43 
44  // Get subdet and layer of this module
45  DetInfo detInfo = this->interpretDetId(dets[i]->geographicalId(), tTopo);
46  uint32_t subDet = detInfo.first;
47 
48  // Note r (or z) of module if barrel (or endcap).
49  double r_or_z;
50  if (this->barrel(subDet)) {
51  r_or_z = dets[i]->position().perp();
52  } else {
53  r_or_z = fabs(dets[i]->position().z());
54  }
55 
56  // Recover min/max r/z value of this layer/disk found so far.
57  double minRZ = 999.;
58  double maxRZ = 0.;
59  if (rangeRorZ_.find(detInfo) != rangeRorZ_.end()) {
60  minRZ = rangeRorZ_[detInfo].first;
61  maxRZ = rangeRorZ_[detInfo].second;
62  }
63 
64  // Update with those of this module if it exceeds them.
65  if (minRZ > r_or_z) minRZ = r_or_z;
66  if (maxRZ < r_or_z) maxRZ = r_or_z;
67  rangeRorZ_[detInfo] = std::pair<double, double>(minRZ, maxRZ);
68  }
69 
70 #ifdef DEBUG_CHECKHITPATTERN
71  RZrangeMap::const_iterator d;
72  for (d = rangeRorZ_.begin(); d != rangeRorZ_.end(); d++) {
73  DetInfo detInfo = d->first;
74  std::pair<double, double> rangeRZ = d->second;
75  std::std::cout<<"CHECKHITPATTERN: Tracker subdetector type="<<detInfo.first<<" layer="<<detInfo.second
76  <<" has min r (or z) ="<<rangeRZ.first<<" and max r (or z) = "<<rangeRZ.second<<std::std::endl;
77  }
78 #endif
79 }
80 
82  // Convert detId to a pair<uint32, uint32> consisting of the numbers used by HitPattern
83  // to identify subdetector and layer number respectively.
84  return DetInfo( detId.subdetId(), tTopo->layer(detId) );
85 }
86 
87 bool CheckHitPattern::barrel(uint32_t subDet) {
88  // Determines if given sub-detector is in the barrel.
89  return (subDet == StripSubdetector::TIB || subDet == StripSubdetector::TOB ||
91 }
92 
93 
95 {
96  // Check if hit pattern of this track is consistent with it being produced
97  // at given vertex.
98 
99  // Initialise geometry info if not yet done.
100  if (!geomInitDone_) throw cms::Exception("CheckHitPattern::operator() called before CheckHitPattern::init");
101 
102  // Optionally set vertex position to zero for debugging.
103  // VertexState vertDebug( GlobalPoint(0.,0.,0.) , GlobalError(1e-8, 0., 1e-8, 0., 0., 1e-8) );
104 
105  // Evaluate track parameters at vertex.
106  reco::TransientTrack t_trk = trkTool_->build(track);
107  GlobalVector p3_trk = t_trk.trajectoryStateClosestToPoint(vert.position()).momentum();
108  bool trkGoesInsideOut = fabs(reco::deltaPhi<const GlobalVector, const GlobalPoint>(p3_trk, vert.position())) < 0.5*M_PI;
109 
110  LogDebug("CHP") << "TRACK: in-->out ? "
111  << trkGoesInsideOut
112  << " dxy=" << track.dxy()
113  << " sz=" <<track.dz()
114  << " eta=" <<track.eta()
115  <<" barrel hits=" << track.hitPattern().numberOfValidPixelHits()
116  <<"/" << track.hitPattern().numberOfValidStripTIBHits()
117  <<"/" << track.hitPattern().numberOfValidStripTOBHits();
118  LogDebug("CHP")<<"VERT: r="<<vert.position().perp()<<" z="<<vert.position().z();
119  // if (vert.position().perp() < 3.5 && fabs(vert.position().z()) < 10. && fabs(track.eta()) < 1 && fabs(track.dxy()) < 2 && fabs(track.dz()) < 2 && track.hitPattern().numberOfValidPixelHits() == 0 && track.hitPattern().numberOfValidStripTIBHits() == 0) LogDebug("CHP")<<"LOOKATTHISTRACK";
120  // Get hit patterns of this track
121  const reco::HitPattern &hp = track.hitPattern();
122 
123  // Count number of valid hits on track definately in front of the vertex,
124  // taking into account finite depth of each layer.
125  unsigned int nHitBefore = 0;
126  for (int i = 0; i < hp.numberOfAllHits(reco::HitPattern::TRACK_HITS); i++) {
129  uint32_t subDet = reco::HitPattern::getSubStructure(hit);
130  uint32_t layer = reco::HitPattern::getLayer(hit);
131  DetInfo detInfo(subDet, layer);
132  auto maxRZ = (*rangeRorZ_.find(detInfo)).second.second;
133 
134  if (this->barrel(subDet)) {
135  // Be careful. If the track starts by going outside-->in, it is allowed to have hits before the vertex !
136  if (vert.position().perp() > maxRZ && trkGoesInsideOut) nHitBefore++;
137  } else {
138  if (fabs(vert.position().z()) > maxRZ) nHitBefore++;
139  }
140  }
141  }
142 
143  // Count number of missing hits before the innermost hit on the track,
144  // taking into account finite depth of each layer.
145  unsigned int nMissHitAfter = 0;
146  for (int i = 0; i < hp.numberOfAllHits(reco::HitPattern::MISSING_INNER_HITS); i++) {
148  // if (hp.trackerHitFilter(hit)) {
150  uint32_t subDet = reco::HitPattern::getSubStructure(hit);
151  uint32_t layer = reco::HitPattern::getLayer(hit);
152  DetInfo detInfo(subDet, layer);
153  auto minRZ = (*rangeRorZ_.find(detInfo)).second.first;
154 
155  if (this->barrel(subDet)) {
156  // Be careful. If the track starts by going outside-->in, then it misses hits
157  // in all layers it crosses before its innermost valid hit.
158  if (vert.position().perp() < minRZ || ! trkGoesInsideOut) nMissHitAfter++;
159  } else {
160  if (fabs(vert.position().z()) < minRZ) nMissHitAfter++;
161  }
162  }
163  }
164 
165  Result result;
166  result.hitsInFrontOfVert = nHitBefore;
167  result.missHitsAfterVert = nMissHitAfter;
168  return result;
169 }
170 
172  // Get hit patterns of this track
173  const reco::HitPattern &hp = track.hitPattern();
174  std::cout<<"=== Hits on Track ==="<<std::endl;
176  std::cout<<"=== Hits before track ==="<<std::endl;
178 }
179 
181  for (int i = 0; i < hp.numberOfAllHits(category); i++) {
182  uint32_t hit = hp.getHitPattern(category, i);
184  uint32_t subdet = reco::HitPattern::getSubStructure(hit);
185  uint32_t layer = reco::HitPattern::getLayer(hit);
186  std::cout<<"hit "<<i<<" subdet="<<subdet<<" layer="<<layer<<" type "<<hp.getHitType(hit)<<std::endl;
187  }
188  }
189 }
190 
#define LogDebug(id)
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:701
T perp() const
Definition: PV3DBase.h:72
std::pair< uint32_t, uint32_t > DetInfo
Result operator()(const reco::Track &track, const VertexState &vert) const
reco::TransientTrack build(const reco::Track *p) const
static bool missingHitFilter(uint16_t pattern)
Definition: HitPattern.h:793
GlobalPoint position() const
Definition: VertexState.h:69
int numberOfValidStripTOBHits() const
Definition: HitPattern.h:869
static bool validHitFilter(uint16_t pattern)
Definition: HitPattern.h:788
U second(std::pair< T, U > const &p)
unsigned int missHitsAfterVert
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
unsigned int hitsInFrontOfVert
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:651
static uint32_t getHitType(uint16_t pattern)
Definition: HitPattern.h:734
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
T z() const
Definition: PV3DBase.h:64
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:41
int numberOfAllHits(HitCategory category) const
Definition: HitPattern.h:808
static uint32_t getSubStructure(uint16_t pattern)
Definition: HitPattern.h:692
#define M_PI
double dz() const
dz parameter (= dsz/cos(lambda)). This is the track z0 w.r.t (0,0,0) only if the refPoint is close to...
Definition: TrackBase.h:609
Definition: DetId.h:18
void init(const edm::EventSetup &iSetup)
static bool trackerHitFilter(uint16_t pattern)
Definition: HitPattern.h:678
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:446
static DetInfo interpretDetId(DetId detId, const TrackerTopology *tTopo)
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
static void print(const reco::Track &track)
int numberOfValidStripTIBHits() const
Definition: HitPattern.h:859
unsigned int layer(const DetId &id) const
std::vector< const GeomDet * > DetContainer
static int position[264][3]
Definition: ReadPGInfo.cc:509
T get() const
Definition: EventSetup.h:63
int numberOfValidPixelHits() const
Definition: HitPattern.h:839
edm::ESHandle< TransientTrackBuilder > trkTool_
static bool barrel(uint32_t subDet)
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:516
double dxy() const
dxy parameter. (This is the transverse impact parameter w.r.t. to (0,0,0) ONLY if refPoint is close t...
Definition: TrackBase.h:591
T const * product() const
Definition: ESHandle.h:86
RZrangeMap rangeRorZ_