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 }
Vector3DBase
Definition: Vector3DBase.h:8
edm::ESHandle::product
T const * product() const
Definition: ESHandle.h:86
reco::HitPattern::getSubStructure
static uint32_t getSubStructure(uint16_t pattern)
Definition: HitPattern.h:707
taus_updatedMVAIds_cff.category
category
Definition: taus_updatedMVAIds_cff.py:31
mps_fire.i
i
Definition: mps_fire.py:428
PixelSubdetector.h
HLT_FULL_cff.track
track
Definition: HLT_FULL_cff.py:11724
MessageLogger.h
TrackerGeometry.h
PixelSubdetector::PixelBarrel
Definition: PixelSubdetector.h:11
CheckHitPattern::Result
Definition: CheckHitPattern.h:27
CheckHitPattern::barrel
static bool barrel(uint32_t subDet)
Definition: CheckHitPattern.cc:88
deltaPhi.h
CheckHitPattern::rangeRorZ_
RZrangeMap rangeRorZ_
Definition: CheckHitPattern.h:61
CheckHitPattern::trkTool_
edm::ESHandle< TransientTrackBuilder > trkTool_
Definition: CheckHitPattern.h:64
TrackerTopology
Definition: TrackerTopology.h:16
reco::HitPattern::validHitFilter
static bool validHitFilter(uint16_t pattern)
Definition: HitPattern.h:783
gather_cfg.cout
cout
Definition: gather_cfg.py:144
reco::HitPattern::trackerHitFilter
static bool trackerHitFilter(uint16_t pattern)
Definition: HitPattern.h:673
if
if(0==first)
Definition: CAHitNtupletGeneratorKernelsImpl.h:58
edm::second
U second(std::pair< T, U > const &p)
Definition: ParameterSet.cc:222
TrackerTopology::layer
unsigned int layer(const DetId &id) const
Definition: TrackerTopology.cc:47
PV3DBase::z
T z() const
Definition: PV3DBase.h:61
CheckHitPattern::interpretDetId
static DetInfo interpretDetId(DetId detId, const TrackerTopology *tTopo)
Definition: CheckHitPattern.cc:82
DetId
Definition: DetId.h:17
TrackerTopology.h
CheckHitPattern::print
static void print(const reco::Track &track)
Definition: CheckHitPattern.cc:172
reco::HitPattern
Definition: HitPattern.h:147
TrackerTopologyRcd.h
trackingPlots.hp
hp
Definition: trackingPlots.py:1231
edm::EventSetup::get
T get() const
Definition: EventSetup.h:87
TrackerDigiGeometryRecord
Definition: TrackerDigiGeometryRecord.h:16
DDAxes::z
TransientTrackRecord
Definition: TransientTrackRecord.h:11
reco::Track
Definition: Track.h:27
edm::ESHandle< TrackerTopology >
StripSubdetector::TIB
static constexpr auto TIB
Definition: StripSubdetector.h:16
reco::HitPattern::missingHitFilter
static bool missingHitFilter(uint16_t pattern)
Definition: HitPattern.h:785
DetId::subdetId
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector's numbering enum)
Definition: DetId.h:48
phase1PixelTopology::layer
constexpr std::array< uint8_t, layerIndexSize > layer
Definition: phase1PixelTopology.h:99
reco::TransientTrack::trajectoryStateClosestToPoint
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
Definition: TransientTrack.h:88
reco::HitPattern::getLayer
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:715
TrackerDigiGeometryRecord.h
LogDebug
#define LogDebug(id)
Definition: MessageLogger.h:233
TrackingGeometry::DetContainer
std::vector< const GeomDet * > DetContainer
Definition: TrackingGeometry.h:29
position
static int position[264][3]
Definition: ReadPGInfo.cc:289
CheckHitPattern::operator()
Result operator()(const reco::Track &track, const VertexState &vert) const
Definition: CheckHitPattern.cc:94
M_PI
#define M_PI
Definition: BXVectorInputProducer.cc:49
CheckHitPattern::DetInfo
std::pair< uint32_t, uint32_t > DetInfo
Definition: CheckHitPattern.h:46
edm::EventSetup
Definition: EventSetup.h:58
TrackerGeometry::dets
const DetContainer & dets() const override
Returm a vector of all GeomDet (including all GeomDetUnits)
Definition: TrackerGeometry.h:62
TransientTrackRecord.h
get
#define get
reco::HitPattern::TRACK_HITS
Definition: HitPattern.h:155
GeomDet.h
reco::HitPattern::HitCategory
HitCategory
Definition: HitPattern.h:155
reco::TransientTrack
Definition: TransientTrack.h:19
VertexState
Definition: VertexState.h:13
CheckHitPattern::init
void init(const edm::EventSetup &iSetup)
Definition: CheckHitPattern.cc:21
Exception
Definition: hltDiff.cc:245
reco::HitPattern::MISSING_INNER_HITS
Definition: HitPattern.h:155
StripSubdetector::TOB
static constexpr auto TOB
Definition: StripSubdetector.h:18
CheckHitPattern::geomInitDone_
bool geomInitDone_
Definition: CheckHitPattern.h:56
VertexState::position
GlobalPoint position() const
Definition: VertexState.h:62
Exception.h
TransientTrackBuilder::build
reco::TransientTrack build(const reco::Track *p) const
Definition: TransientTrackBuilder.cc:20
ztail.d
d
Definition: ztail.py:151
mps_fire.result
result
Definition: mps_fire.py:311
TrackerTopologyRcd
Definition: TrackerTopologyRcd.h:10
CheckHitPattern.h
StripSubdetector.h
PV3DBase::perp
T perp() const
Definition: PV3DBase.h:69
hit
Definition: SiStripHitEffFromCalibTree.cc:88