CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
PFCheckHitPattern.cc
Go to the documentation of this file.
2 
3 // To get Tracker Geometry
9 
10 // To convert detId to subdet/layer number.
19 
20 #include <map>
21 
22 using namespace reco;
23 using namespace std;
24 
25 // For a given subdetector & layer number, this static map stores the minimum and maximum
26 // r (or z) values if it is barrel (or endcap) respectively.
28 
30 
31  //
32  // Note min/max radius (z) of each barrel layer (endcap disk).
33  //
34 
35  geomInitDone_ = true;
36 
37  // Get Tracker geometry
38  const TrackingGeometry::DetContainer& dets = tkerGeomHandle_->dets();
39 
40  // Loop over all modules in the Tracker.
41  for (unsigned int i = 0; i < dets.size(); i++) {
42 
43  // Get subdet and layer of this module
44  DetInfo detInfo = this->interpretDetId(dets[i]->geographicalId());
45  uint32_t subDet = detInfo.first;
46 
47  // Note r (or z) of module if barrel (or endcap).
48  double r_or_z;
49  if (this->barrel(subDet)) {
50  r_or_z = dets[i]->position().perp();
51  } else {
52  r_or_z = fabs(dets[i]->position().z());
53  }
54 
55  // Recover min/max r/z value of this layer/disk found so far.
56  double minRZ = 999.;
57  double maxRZ = 0.;
58  if (rangeRorZ_.find(detInfo) != rangeRorZ_.end()) {
59  minRZ = rangeRorZ_[detInfo].first;
60  maxRZ = rangeRorZ_[detInfo].second;
61  }
62 
63  // Update with those of this module if it exceeds them.
64  if (minRZ > r_or_z) minRZ = r_or_z;
65  if (maxRZ < r_or_z) maxRZ = r_or_z;
66  rangeRorZ_[detInfo] = pair<double, double>(minRZ, maxRZ);
67  }
68 
69 #if 0
70  //def DEBUG_CHECKHITPATTERN
71  RZrangeMap::const_iterator d;
72  for (d = rangeRorZ_.begin(); d != rangeRorZ_.end(); d++) {
73  DetInfo detInfo = d->first;
74  pair<double, double> rangeRZ = d->second;
75  }
76 #endif
77 }
78 
80  // Convert detId to a pair<uint32, uint32> consisting of the numbers used by HitPattern
81  // to identify subdetector and layer number respectively.
82  if (detId.subdetId() == StripSubdetector::TIB) {
83  return DetInfo( detId.subdetId() , TIBDetId(detId).layer() );
84  } else if (detId.subdetId() == StripSubdetector::TOB) {
85  return DetInfo( detId.subdetId() , TOBDetId(detId).layer() );
86  } else if (detId.subdetId() == StripSubdetector::TID) {
87  return DetInfo( detId.subdetId() , TIDDetId(detId).wheel() );
88  } else if (detId.subdetId() == StripSubdetector::TEC) {
89  return DetInfo( detId.subdetId() , TECDetId(detId).wheel() );
90  } else if (detId.subdetId() == PixelSubdetector::PixelBarrel) {
91  return DetInfo( detId.subdetId() , PXBDetId(detId).layer() );
92  } else if (detId.subdetId() == PixelSubdetector::PixelEndcap) {
93  return DetInfo( detId.subdetId() , PXFDetId(detId).disk() );
94  } else {
95  throw cms::Exception("RecoParticleFlow", "Found DetId that is not in Tracker");
96  }
97 }
98 
99 bool PFCheckHitPattern::barrel(uint32_t subDet) {
100  // Determines if given sub-detector is in the barrel.
101  return (subDet == StripSubdetector::TIB || subDet == StripSubdetector::TOB ||
102  subDet == PixelSubdetector::PixelBarrel);
103 }
104 
105 
106 pair< PFCheckHitPattern::PFTrackHitInfo, PFCheckHitPattern::PFTrackHitInfo>
108  const TrackBaseRef track, const TransientVertex& vert)
109 {
110 
111  // PFCheck if hit pattern of this track is consistent with it being produced
112  // at given vertex. Pair.first gives number of hits on track in front of vertex.
113  // Pair.second gives number of missing hits between vertex and innermost hit
114  // on track.
115 
116  // Initialise geometry info if not yet done.
117  if (!geomInitDone_) this->init(tkerGeomHandle_);
118 
119  // Get hit patterns of this track
120  const reco::HitPattern& hp = track.get()->hitPattern();
121  const reco::HitPattern& ip = track.get()->trackerExpectedHitsInner();
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  unsigned int nHitAfter = 0;
127 
128  for (int i = 0; i < hp.numberOfHits(); i++) {
129  uint32_t hit = hp.getHitPattern(i);
130  if (hp.trackerHitFilter(hit) && hp.validHitFilter(hit)) {
131  uint32_t subDet = hp.getSubStructure(hit);
132  uint32_t layer = hp.getLayer(hit);
133  DetInfo detInfo(subDet, layer);
134  double maxRZ = rangeRorZ_[detInfo].second;
135 
136  if (this->barrel(subDet)) {
137  if (vert.position().perp() > maxRZ) nHitBefore++;
138  else nHitAfter++;
139  } else {
140  if (fabs(vert.position().z()) > maxRZ) nHitBefore++;
141  else nHitAfter++;
142  }
143  }
144  }
145 
146  // Count number of missing hits before the innermost hit on the track,
147  // taking into account finite depth of each layer.
148  unsigned int nMissHitAfter = 0;
149  unsigned int nMissHitBefore = 0;
150 
151  for (int i = 0; i < ip.numberOfHits(); i++) {
152  uint32_t hit = ip.getHitPattern(i);
153  if (ip.trackerHitFilter(hit)) {
154  uint32_t subDet = ip.getSubStructure(hit);
155  uint32_t layer = ip.getLayer(hit);
156  DetInfo detInfo(subDet, layer);
157  double minRZ = rangeRorZ_[detInfo].first;
158 
159  // cout << "subDet = " << subDet << " layer = " << layer << " minRZ = " << minRZ << endl;
160 
161  if (this->barrel(subDet)) {
162  if (vert.position().perp() < minRZ) nMissHitAfter++;
163  else nMissHitBefore++;
164  } else {
165  if (fabs(vert.position().z()) < minRZ) nMissHitAfter++;
166  else nMissHitBefore++;
167  }
168  }
169  }
170 
171 
172  PFTrackHitInfo trackToVertex(nHitBefore, nMissHitBefore);
173  PFTrackHitInfo trackFromVertex(nHitAfter, nMissHitAfter);
174 
175 
176  return pair< PFTrackHitInfo, PFTrackHitInfo>(trackToVertex, trackFromVertex);
177 }
178 
179 void PFCheckHitPattern::print(const TrackBaseRef track) const {
180  // Get hit patterns of this track
181  const reco::HitPattern& hp = track.get()->hitPattern();
182  const reco::HitPattern& ip = track.get()->trackerExpectedHitsInner();
183 
184  cout<<"=== Hits on Track ==="<<endl;
185  this->print(hp);
186  cout<<"=== Hits before track ==="<<endl;
187  this->print(ip);
188 }
189 
191  for (int i = 0; i < hp.numberOfHits(); i++) {
192  uint32_t hit = hp.getHitPattern(i);
193  if (hp.trackerHitFilter(hit)) {
194  uint32_t subdet = hp.getSubStructure(hit);
195  uint32_t layer = hp.getLayer(hit);
196  cout<<"hit "<<i<<" subdet="<<subdet<<" layer="<<layer<<" type "<<hp.getHitType(hit)<<endl;
197  }
198  }
199 }
int i
Definition: DBlmapReader.cc:9
static RZrangeMap rangeRorZ_
T perp() const
Definition: PV3DBase.h:72
unsigned int layer() const
layer id
Definition: TOBDetId.h:39
static uint32_t getLayer(uint32_t pattern)
Definition: HitPattern.h:513
static bool trackerHitFilter(uint32_t pattern)
Definition: HitPattern.h:494
std::string print(const Track &, edm::Verbosity=edm::Concise)
Track print utility.
Definition: print.cc:8
int init
Definition: HydjetWrapper.h:62
static uint32_t getHitType(uint32_t pattern)
Definition: HitPattern.h:529
void print(const reco::TrackBaseRef track) const
Print hit pattern on track.
std::vector< GeomDet * > DetContainer
float float float z
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
unsigned int layer() const
layer id
Definition: PXBDetId.h:35
PFTrackHitFullInfo analyze(edm::ESHandle< TrackerGeometry >, const reco::TrackBaseRef track, const TransientVertex &vert)
std::pair< unsigned int, unsigned int > PFTrackHitInfo
static DetInfo interpretDetId(DetId detId)
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
GlobalPoint position() const
T z() const
Definition: PV3DBase.h:64
int numberOfHits() const
Definition: HitPattern.cc:213
static uint32_t getSubStructure(uint32_t pattern)
Definition: HitPattern.h:507
const HitPattern & trackerExpectedHitsInner() const
Access the hit pattern counting (in the Tracker) the number of expected crossed layers before the fir...
Definition: TrackBase.h:223
static bool validHitFilter(uint32_t pattern)
Definition: HitPattern.h:557
const HitPattern & hitPattern() const
Access the hit pattern, indicating in which Tracker layers the track has hits.
Definition: TrackBase.h:221
int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:37
unsigned int disk() const
disk id
Definition: PXFDetId.h:43
Definition: DetId.h:18
unsigned int wheel() const
wheel id
Definition: TECDetId.h:52
unsigned int layer() const
layer id
Definition: TIBDetId.h:41
std::pair< uint32_t, uint32_t > DetInfo
std::map< DetInfo, std::pair< double, double > > RZrangeMap
void init(edm::ESHandle< TrackerGeometry >)
Create map indicating r/z values of all layers/disks.
tuple cout
Definition: gather_cfg.py:121
uint32_t getHitPattern(int position) const
Definition: HitPattern.cc:144
value_type const * get() const
Definition: RefToBase.h:212
static bool barrel(uint32_t subDet)
Return a bool indicating if a given subdetector is in the barrel.
unsigned int wheel() const
wheel id
Definition: TIDDetId.h:50