CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
CheckHitPattern.cc
Go to the documentation of this file.
3 
4 // To get Tracker Geometry
8 
9 // To convert detId to subdet/layer number.
12 //#include "DataFormats/SiStripDetId/interface/SiStripDetId.h"
15 
18 
20 
21 // For a given subdetector & layer number, this static map stores the minimum and maximum
22 // r (or z) values if it is barrel (or endcap) respectively.
24 
26 
27  //Retrieve tracker topology from geometry
29  iSetup.get<IdealGeometryRecord>().get(tTopoHandle);
30  const TrackerTopology* const tTopo = tTopoHandle.product();
31 
32  //
33  // Note min/max radius (z) of each barrel layer (endcap disk).
34  //
35 
36  geomInitDone_ = true;
37 
38  // Get Tracker geometry
39  edm::ESHandle<TrackerGeometry> trackerGeometry;
40  iSetup.get<TrackerDigiGeometryRecord>().get(trackerGeometry);
41  const TrackingGeometry::DetContainer& dets = trackerGeometry->dets();
42 
43  // Loop over all modules in the Tracker.
44  for (unsigned int i = 0; i < dets.size(); i++) {
45 
46  // Get subdet and layer of this module
47  DetInfo detInfo = this->interpretDetId(dets[i]->geographicalId(), tTopo);
48  uint32_t subDet = detInfo.first;
49 
50  // Note r (or z) of module if barrel (or endcap).
51  double r_or_z;
52  if (this->barrel(subDet)) {
53  r_or_z = dets[i]->position().perp();
54  } else {
55  r_or_z = fabs(dets[i]->position().z());
56  }
57 
58  // Recover min/max r/z value of this layer/disk found so far.
59  double minRZ = 999.;
60  double maxRZ = 0.;
61  if (rangeRorZ_.find(detInfo) != rangeRorZ_.end()) {
62  minRZ = rangeRorZ_[detInfo].first;
63  maxRZ = rangeRorZ_[detInfo].second;
64  }
65 
66  // Update with those of this module if it exceeds them.
67  if (minRZ > r_or_z) minRZ = r_or_z;
68  if (maxRZ < r_or_z) maxRZ = r_or_z;
69  rangeRorZ_[detInfo] = std::pair<double, double>(minRZ, maxRZ);
70  }
71 
72 #ifdef DEBUG_CHECKHITPATTERN
73  RZrangeMap::const_iterator d;
74  for (d = rangeRorZ_.begin(); d != rangeRorZ_.end(); d++) {
75  DetInfo detInfo = d->first;
76  std::pair<double, double> rangeRZ = d->second;
77  std::std::cout<<"CHECKHITPATTERN: Tracker subdetector type="<<detInfo.first<<" layer="<<detInfo.second
78  <<" has min r (or z) ="<<rangeRZ.first<<" and max r (or z) = "<<rangeRZ.second<<std::std::endl;
79  }
80 #endif
81 }
82 
84  // Convert detId to a pair<uint32, uint32> consisting of the numbers used by HitPattern
85  // to identify subdetector and layer number respectively.
86  if (detId.subdetId() == StripSubdetector::TIB) {
87  return DetInfo( detId.subdetId(), tTopo->tibLayer(detId) );
88  } else if (detId.subdetId() == StripSubdetector::TOB) {
89  return DetInfo( detId.subdetId(), tTopo->tobLayer(detId) );
90  } else if (detId.subdetId() == StripSubdetector::TID) {
91  return DetInfo( detId.subdetId(), tTopo->tidWheel(detId) );
92  } else if (detId.subdetId() == StripSubdetector::TEC) {
93  return DetInfo( detId.subdetId(), tTopo->tecWheel(detId) );
94  } else if (detId.subdetId() == PixelSubdetector::PixelBarrel) {
95  return DetInfo( detId.subdetId(), tTopo->pxbLayer(detId) );
96  } else if (detId.subdetId() == PixelSubdetector::PixelEndcap) {
97  return DetInfo( detId.subdetId(), tTopo->pxfDisk(detId) );
98  } else {
99  throw cms::Exception("NotFound","Found DetId that is not in Tracker");
100  }
101 }
102 
103 bool CheckHitPattern::barrel(uint32_t subDet) {
104  // Determines if given sub-detector is in the barrel.
105  return (subDet == StripSubdetector::TIB || subDet == StripSubdetector::TOB ||
106  subDet == PixelSubdetector::PixelBarrel);
107 }
108 
109 
111  const reco::Track& track, const VertexState& vert, bool fixHitPattern)
112 {
113  // Check if hit pattern of this track is consistent with it being produced
114  // at given vertex.
115 
116  // Initialise geometry info if not yet done.
117  if (!geomInitDone_) this->init(iSetup);
118 
119  // Optionally set vertex position to zero for debugging.
120  // VertexState vertDebug( GlobalPoint(0.,0.,0.) , GlobalError(1e-8, 0., 1e-8, 0., 0., 1e-8) );
121 
122  // Evaluate track parameters at vertex.
123  iSetup.get<TransientTrackRecord>().get("TransientTrackBuilder",trkTool_); // Needed for vertex fits
124  reco::TransientTrack t_trk = trkTool_->build(track);
125  GlobalVector p3_trk = t_trk.trajectoryStateClosestToPoint(vert.position()).momentum();
126  bool trkGoesInsideOut = fabs(reco::deltaPhi<const GlobalVector, const GlobalPoint>(p3_trk, vert.position())) < 0.5*M_PI;
127 
128  LogDebug("CHP") << "TRACK: in-->out ? "
129  << trkGoesInsideOut
130  << " dxy=" << track.dxy()
131  << " sz=" <<track.dz()
132  << " eta=" <<track.eta()
133  <<" barrel hits=" << track.hitPattern().numberOfValidPixelHits()
134  <<"/" << track.hitPattern().numberOfValidStripTIBHits()
135  <<"/" << track.hitPattern().numberOfValidStripTOBHits();
136  LogDebug("CHP")<<"VERT: r="<<vert.position().perp()<<" z="<<vert.position().z();
137  // 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";
138  // Get hit patterns of this track
139  const reco::HitPattern &hp = track.hitPattern();
140  reco::HitPattern ip = track.hitPattern();
141 
142  // Optionally fix inner hit pattern (needed if uncertainty on track trajectory is large).
143  if (fixHitPattern) {
144  static FixTrackHitPattern fixTrackHitPattern;
145  ip = fixTrackHitPattern.analyze(iSetup, track).innerHitPattern;
146  }
147 
148  // Count number of valid hits on track definately in front of the vertex,
149  // taking into account finite depth of each layer.
150  unsigned int nHitBefore = 0;
151  for (int i = 0; i < hp.numberOfHits(reco::HitPattern::TRACK_HITS); i++) {
154  uint32_t subDet = reco::HitPattern::getSubStructure(hit);
155  uint32_t layer = reco::HitPattern::getLayer(hit);
156  DetInfo detInfo(subDet, layer);
157  double maxRZ = rangeRorZ_[detInfo].second;
158 
159  if (this->barrel(subDet)) {
160  // Be careful. If the track starts by going outside-->in, it is allowed to have hits before the vertex !
161  if (vert.position().perp() > maxRZ && trkGoesInsideOut) nHitBefore++;
162  } else {
163  if (fabs(vert.position().z()) > maxRZ) nHitBefore++;
164  }
165  }
166  }
167 
168  // Count number of missing hits before the innermost hit on the track,
169  // taking into account finite depth of each layer.
170  unsigned int nMissHitAfter = 0;
171  for (int i = 0; i < ip.numberOfHits(reco::HitPattern::MISSING_INNER_HITS); i++) {
173  // if (ip.trackerHitFilter(hit)) {
175  uint32_t subDet = reco::HitPattern::getSubStructure(hit);
176  uint32_t layer = reco::HitPattern::getLayer(hit);
177  DetInfo detInfo(subDet, layer);
178  double minRZ = rangeRorZ_[detInfo].first;
179 
180  if (this->barrel(subDet)) {
181  // Be careful. If the track starts by going outside-->in, then it misses hits
182  // in all layers it crosses before its innermost valid hit.
183  if (vert.position().perp() < minRZ || ! trkGoesInsideOut) nMissHitAfter++;
184  } else {
185  if (fabs(vert.position().z()) < minRZ) nMissHitAfter++;
186  }
187  }
188  }
189 
190  Result result;
191  result.hitsInFrontOfVert = nHitBefore;
192  result.missHitsAfterVert = nMissHitAfter;
193  return result;
194 }
195 
196 void CheckHitPattern::print(const reco::Track& track) const {
197  // Get hit patterns of this track
198  const reco::HitPattern &hp = track.hitPattern();
199  std::cout<<"=== Hits on Track ==="<<std::endl;
201  std::cout<<"=== Hits before track ==="<<std::endl;
203 }
204 
206  for (int i = 0; i < hp.numberOfHits(category); i++) {
207  uint32_t hit = hp.getHitPattern(category, i);
209  uint32_t subdet = reco::HitPattern::getSubStructure(hit);
210  uint32_t layer = reco::HitPattern::getLayer(hit);
211  std::cout<<"hit "<<i<<" subdet="<<subdet<<" layer="<<layer<<" type "<<hp.getHitType(hit)<<std::endl;
212  }
213  }
214 }
215 
#define LogDebug(id)
int i
Definition: DBlmapReader.cc:9
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:624
std::map< DetInfo, std::pair< double, double > > RZrangeMap
T perp() const
Definition: PV3DBase.h:72
unsigned int tibLayer(const DetId &id) const
Result analyze(const edm::EventSetup &iSetup, const reco::Track &track, const VertexState &vert, bool fixHitPattern=true)
std::pair< uint32_t, uint32_t > DetInfo
unsigned int pxfDisk(const DetId &id) const
unsigned int tidWheel(const DetId &id) const
static bool missingHitFilter(uint16_t pattern)
Definition: HitPattern.h:703
GlobalPoint position() const
Definition: VertexState.h:50
int numberOfValidStripTOBHits() const
Definition: HitPattern.h:779
float float float z
static bool validHitFilter(uint16_t pattern)
Definition: HitPattern.h:698
unsigned int missHitsAfterVert
unsigned int hitsInFrontOfVert
double eta() const
pseudorapidity of momentum vector
Definition: TrackBase.h:699
Result analyze(const edm::EventSetup &iSetup, const reco::Track &track)
static uint32_t getHitType(uint16_t pattern)
Definition: HitPattern.h:657
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
T z() const
Definition: PV3DBase.h:64
tuple result
Definition: query.py:137
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
#define M_PI
static uint32_t getSubStructure(uint16_t pattern)
Definition: HitPattern.h:615
unsigned int pxbLayer(const DetId &id) const
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:657
Definition: DetId.h:18
void init(const edm::EventSetup &iSetup)
static bool trackerHitFilter(uint16_t pattern)
Definition: HitPattern.h:601
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:384
static DetInfo interpretDetId(DetId detId, const TrackerTopology *tTopo)
TrajectoryStateClosestToPoint trajectoryStateClosestToPoint(const GlobalPoint &point) const
const T & get() const
Definition: EventSetup.h:55
T const * product() const
Definition: ESHandle.h:86
int numberOfValidStripTIBHits() const
Definition: HitPattern.h:769
static RZrangeMap rangeRorZ_
static int position[264][3]
Definition: ReadPGInfo.cc:509
int numberOfValidPixelHits() const
Definition: HitPattern.h:749
edm::ESHandle< TransientTrackBuilder > trkTool_
static bool barrel(uint32_t subDet)
tuple cout
Definition: gather_cfg.py:121
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:456
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:639
unsigned int tecWheel(const DetId &id) const
std::vector< GeomDet const * > DetContainer
unsigned int tobLayer(const DetId &id) const
int numberOfHits(HitCategory category) const
Definition: HitPattern.h:718
void print(const reco::Track &track) const