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  //Retrieve tracker topology from geometry
24  iSetup.get<TrackerTopologyRcd>().get(tTopoHandle);
25  const TrackerTopology* const tTopo = tTopoHandle.product();
26 
27  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder", trkTool_); // Needed for vertex fits
28 
29  //
30  // Note min/max radius (z) of each barrel layer (endcap disk).
31  //
32 
33  geomInitDone_ = true;
34 
35  // Get Tracker geometry
36  edm::ESHandle<TrackerGeometry> trackerGeometry;
37  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
38  const TrackingGeometry::DetContainer& dets = trackerGeometry->dets();
39 
40  // Loop over all modules in the Tracker.
41  for (unsigned int i = 0; i < dets.size(); i++) {
42  // Get subdet and layer of this module
43  DetInfo detInfo = this->interpretDetId(dets[i]->geographicalId(), tTopo);
44  uint32_t subDet = detInfo.first;
45 
46  // Note r (or z) of module if barrel (or endcap).
47  double r_or_z;
48  if (this->barrel(subDet)) {
49  r_or_z = dets[i]->position().perp();
50  } else {
51  r_or_z = fabs(dets[i]->position().z());
52  }
53 
54  // Recover min/max r/z value of this layer/disk found so far.
55  double minRZ = 999.;
56  double maxRZ = 0.;
57  if (rangeRorZ_.find(detInfo) != rangeRorZ_.end()) {
58  minRZ = rangeRorZ_[detInfo].first;
59  maxRZ = rangeRorZ_[detInfo].second;
60  }
61 
62  // Update with those of this module if it exceeds them.
63  if (minRZ > r_or_z)
64  minRZ = r_or_z;
65  if (maxRZ < r_or_z)
66  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
77  << std::std::endl;
78  }
79 #endif
80 }
81 
83  // Convert detId to a pair<uint32, uint32> consisting of the numbers used by HitPattern
84  // to identify subdetector and layer number respectively.
85  return DetInfo(detId.subdetId(), tTopo->layer(detId));
86 }
87 
88 bool CheckHitPattern::barrel(uint32_t subDet) {
89  // Determines if given sub-detector is in the barrel.
90  return (subDet == StripSubdetector::TIB || subDet == StripSubdetector::TOB ||
92 }
93 
95  // Check if hit pattern of this track is consistent with it being produced
96  // at given vertex.
97 
98  // Initialise geometry info if not yet done.
99  if (!geomInitDone_)
100  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.
107  GlobalVector p3_trk = t_trk.trajectoryStateClosestToPoint(vert.position()).momentum();
108  bool trkGoesInsideOut =
109  fabs(reco::deltaPhi<const GlobalVector, const GlobalPoint>(p3_trk, vert.position())) < 0.5 * M_PI;
110 
111  LogDebug("CHP") << "TRACK: in-->out ? " << trkGoesInsideOut << " dxy=" << track.dxy() << " sz=" << track.dz()
112  << " eta=" << track.eta() << " barrel hits=" << track.hitPattern().numberOfValidPixelHits() << "/"
113  << track.hitPattern().numberOfValidStripTIBHits() << "/"
114  << track.hitPattern().numberOfValidStripTOBHits();
115  LogDebug("CHP") << "VERT: r=" << vert.position().perp() << " z=" << vert.position().z();
116  // 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";
117  // Get hit patterns of this track
118  const reco::HitPattern& hp = track.hitPattern();
119 
120  // Count number of valid hits on track definately in front of the vertex,
121  // taking into account finite depth of each layer.
122  unsigned int nHitBefore = 0;
123  for (int i = 0; i < hp.numberOfAllHits(reco::HitPattern::TRACK_HITS); i++) {
124  uint32_t hit = hp.getHitPattern(reco::HitPattern::TRACK_HITS, i);
126  uint32_t subDet = reco::HitPattern::getSubStructure(hit);
128  DetInfo detInfo(subDet, layer);
129  auto maxRZ = (*rangeRorZ_.find(detInfo)).second.second;
130 
131  if (this->barrel(subDet)) {
132  // Be careful. If the track starts by going outside-->in, it is allowed to have hits before the vertex !
133  if (vert.position().perp() > maxRZ && trkGoesInsideOut)
134  nHitBefore++;
135  } else {
136  if (fabs(vert.position().z()) > maxRZ)
137  nHitBefore++;
138  }
139  }
140  }
141 
142  // Count number of missing hits before the innermost hit on the track,
143  // taking into account finite depth of each layer.
144  unsigned int nMissHitAfter = 0;
145  for (int i = 0; i < hp.numberOfAllHits(reco::HitPattern::MISSING_INNER_HITS); i++) {
146  uint32_t hit = hp.getHitPattern(reco::HitPattern::MISSING_INNER_HITS, i);
147  // if (hp.trackerHitFilter(hit)) {
149  uint32_t subDet = reco::HitPattern::getSubStructure(hit);
151  DetInfo detInfo(subDet, layer);
152  auto minRZ = (*rangeRorZ_.find(detInfo)).second.first;
153 
154  if (this->barrel(subDet)) {
155  // Be careful. If the track starts by going outside-->in, then it misses hits
156  // in all layers it crosses before its innermost valid hit.
157  if (vert.position().perp() < minRZ || !trkGoesInsideOut)
158  nMissHitAfter++;
159  } else {
160  if (fabs(vert.position().z()) < minRZ)
161  nMissHitAfter++;
162  }
163  }
164  }
165 
166  Result result;
167  result.hitsInFrontOfVert = nHitBefore;
168  result.missHitsAfterVert = nMissHitAfter;
169  return result;
170 }
171 
173  // Get hit patterns of this track
174  const reco::HitPattern& hp = track.hitPattern();
175  std::cout << "=== Hits on Track ===" << std::endl;
177  std::cout << "=== Hits before track ===" << std::endl;
179 }
180 
182  for (int i = 0; i < hp.numberOfAllHits(category); i++) {
183  uint32_t hit = hp.getHitPattern(category, i);
185  uint32_t subdet = reco::HitPattern::getSubStructure(hit);
187  std::cout << "hit " << i << " subdet=" << subdet << " layer=" << layer << " type " << hp.getHitType(hit)
188  << std::endl;
189  }
190  }
191 }
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:721
T perp() const
Definition: PV3DBase.h:69
std::pair< uint32_t, uint32_t > DetInfo
T z() const
Definition: PV3DBase.h:61
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
static bool missingHitFilter(uint16_t pattern)
Definition: HitPattern.h:798
unsigned int layer(const DetId &id) const
constexpr std::array< uint8_t, layerIndexSize > layer
static bool validHitFilter(uint16_t pattern)
Definition: HitPattern.h:796
reco::TransientTrack build(const reco::Track *p) const
U second(std::pair< T, U > const &p)
std::vector< const GeomDet * > DetContainer
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
T const * product() const
Definition: ESHandle.h:86
T get() const
Definition: EventSetup.h:82
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
static constexpr auto TOB
Result operator()(const reco::Track &track, const VertexState &vert) const
d
Definition: ztail.py:151
static uint32_t getSubStructure(uint16_t pattern)
Definition: HitPattern.h:713
#define M_PI
Definition: DetId.h:17
void init(const edm::EventSetup &iSetup)
static bool trackerHitFilter(uint16_t pattern)
Definition: HitPattern.h:679
static constexpr auto TIB
static DetInfo interpretDetId(DetId detId, const TrackerTopology *tTopo)
static void print(const reco::Track &track)
static int position[264][3]
Definition: ReadPGInfo.cc:289
edm::ESHandle< TransientTrackBuilder > trkTool_
static bool barrel(uint32_t subDet)
RZrangeMap rangeRorZ_
#define LogDebug(id)
GlobalPoint position() const
Definition: VertexState.h:62