CMS 3D CMS Logo

HitPattern.cc
Go to the documentation of this file.
10 
12 
14 
15 #include <bitset>
16 
17 using namespace reco;
18 
20  : hitCount(0), beginTrackHits(0), endTrackHits(0), beginInner(0), endInner(0), beginOuter(0), endOuter(0) {
22 }
23 
25  : hitCount(other.hitCount),
28  beginInner(other.beginInner),
29  endInner(other.endInner),
30  beginOuter(other.beginOuter),
31  endOuter(other.endOuter) {
32  memcpy(this->hitPattern, other.hitPattern, sizeof(uint16_t) * HitPattern::ARRAY_LENGTH);
33 }
34 
36 
38  if (this == &other) {
39  return *this;
40  }
41 
42  this->hitCount = other.hitCount;
43 
44  this->beginTrackHits = other.beginTrackHits;
45  this->endTrackHits = other.endTrackHits;
46 
47  this->beginInner = other.beginInner;
48  this->endInner = other.endInner;
49 
50  this->beginOuter = other.beginOuter;
51  this->endOuter = other.endOuter;
52 
53  memcpy(this->hitPattern, other.hitPattern, sizeof(uint16_t) * HitPattern::ARRAY_LENGTH);
54 
55  return *this;
56 }
57 
58 void HitPattern::clear(void) {
59  this->hitCount = 0;
60  this->beginTrackHits = 0;
61  this->endTrackHits = 0;
62  this->beginInner = 0;
63  this->endInner = 0;
64  this->beginOuter = 0;
65  this->endOuter = 0;
66 
67  memset(this->hitPattern, EMPTY_PATTERN, sizeof(uint16_t) * HitPattern::ARRAY_LENGTH);
68 }
69 
71  return appendHit(*ref, ttopo);
72 }
73 
74 uint16_t HitPattern::encode(const TrackingRecHit& hit, const TrackerTopology& ttopo) {
75  return encode(hit.geographicalId(), hit.getType(), ttopo);
76 }
77 
78 namespace {
79  uint16_t encodeMuonLayer(const DetId& id) {
80  uint16_t detid = id.det();
81  uint16_t subdet = id.subdetId();
82 
83  uint16_t layer = 0x0;
84  if (detid == DetId::Muon) {
85  switch (subdet) {
86  case MuonSubdetId::DT:
87  layer = ((DTLayerId(id.rawId()).station() - 1) << 2);
88  layer |= DTLayerId(id.rawId()).superLayer();
89  break;
90  case MuonSubdetId::CSC:
91  layer = ((CSCDetId(id.rawId()).station() - 1) << 2);
92  layer |= (CSCDetId(id.rawId()).ring() - 1);
93  break;
94  case MuonSubdetId::RPC: {
95  RPCDetId rpcid(id.rawId());
96  layer = ((rpcid.station() - 1) << 2);
97  layer |= (rpcid.station() <= 2) ? ((rpcid.layer() - 1) << 1) : 0x0;
98  layer |= abs(rpcid.region());
99  } break;
100  case MuonSubdetId::GEM: {
101  GEMDetId gemid(id.rawId());
102  layer = ((gemid.station() - 1) << 2);
103  layer |= abs(gemid.layer() - 1);
104  } break;
105  case MuonSubdetId::ME0: {
106  ME0DetId me0id(id.rawId());
107  //layer = ((me0id.roll()-1)<<1) + abs(me0id.layer()-1);
108  //layer = ((me0id.roll()-1)<<1) + abs(me0id.layer());
109  //Only layer information that is meaningful is in the roll/etapartition
110  layer = (me0id.roll());
111  } break;
112  }
113  }
114  return layer;
115  }
116  uint16_t encodeTimingLayer(const DetId& id) {
117  uint16_t detid = id.det();
118  uint16_t subdet = id.subdetId();
119  uint16_t layer = 0x0;
120  if (detid == DetId::Forward && subdet == FastTime) {
121  MTDDetId mtdid(id);
122  switch (mtdid.mtdSubDetector()) {
123  case MTDDetId::BTL:
124  layer = BTLDetId(id).modType();
125  break;
126  case MTDDetId::ETL:
127  layer = ETLDetId(id).mtdRR();
128  break;
129  default:
130  throw cms::Exception("HitPattern") << "Invalid MTD Subdetector " << mtdid.mtdSubDetector() << "!";
131  }
132  } else {
133  throw cms::Exception("HitPattern") << "Invalid DetId for FastTime det= " << detid << " subdet= " << subdet << "!";
134  }
135  return layer;
136  }
137 } // namespace
138 
139 uint16_t HitPattern::encode(const DetId& id, TrackingRecHit::Type hitType, const TrackerTopology& ttopo) {
140  uint16_t detid = id.det();
141  uint16_t subdet = id.subdetId();
142 
143  // adding layer/disk/wheel bits
144  uint16_t layer = 0x0;
145  if (detid == DetId::Tracker) {
146  layer = ttopo.layer(id);
147  } else if (detid == DetId::Muon) {
148  layer = encodeMuonLayer(id);
149  } else if (detid == DetId::Forward && subdet == FastTime) {
150  layer = encodeTimingLayer(id);
151  }
152 
153  // adding mono/stereo bit
154  uint16_t side = 0x0;
155  if (detid == DetId::Tracker) {
156  side = isStereo(id, ttopo);
157  } else if (detid == DetId::Muon || (detid == DetId::Forward && subdet == FastTime)) {
158  side = 0x0;
159  }
160 
161  // juggle the detid around to deal with the fact the bitwidth is larger
162  // DetId::Muon is 2 and DetId::Forward is 6, must map to 0 and 2 respectively
163  if (detid == DetId::Tracker) {
164  detid = TRACKER_HIT;
165  } else if (detid == DetId::Muon) {
166  detid = MUON_HIT; // DetId::Muon is 2 and needs to be reordered to match old encoding where it got masked
167  } else if (detid == DetId::Forward && subdet == FastTime) {
168  detid = MTD_HIT; // since DetId::Forward is some other number, reorder it here
169  }
170 
171  return encode(detid, subdet, layer, side, hitType);
172 }
173 
174 uint16_t HitPattern::encode(uint16_t det, uint16_t subdet, uint16_t layer, uint16_t side, TrackingRecHit::Type hitType) {
176 
177  // adding tracker/muon/mtd detector bits
178  pattern |= (det & SubDetectorMask) << SubDetectorOffset;
179 
180  // adding substructure (PXB, PXF, TIB, TID, TOB, TEC, or DT, CSC, RPC,GEM, or BTL, ETL) bits
181  pattern |= (subdet & SubstrMask) << SubstrOffset;
182 
183  // adding layer/disk/wheel/ring/modType bits
184  pattern |= (layer & LayerMask) << LayerOffset;
185 
186  // adding mono/stereo bit
187  pattern |= (side & SideMask) << SideOffset;
188 
189  TrackingRecHit::Type patternHitType =
194  : hitType);
195 
196  pattern |= (patternHitType & HitTypeMask) << HitTypeOffset;
197 
198  return pattern;
199 }
200 
202  return appendHit(hit.geographicalId(), hit.getType(), ttopo);
203 }
204 
205 bool HitPattern::appendHit(const DetId& id, TrackingRecHit::Type hitType, const TrackerTopology& ttopo) {
206  //if HitPattern is full, journey ends no matter what.
207  if
208  UNLIKELY((hitCount == HitPattern::MaxHits)) { return false; }
209 
210  uint16_t pattern = HitPattern::encode(id, hitType, ttopo);
211 
212  return appendHit(pattern, hitType);
213 }
214 
215 bool HitPattern::appendHit(const uint16_t pattern, TrackingRecHit::Type hitType) {
216  //if HitPattern is full, journey ends no matter what.
217  if
218  UNLIKELY((hitCount == HitPattern::MaxHits)) { return false; }
219 
220  switch (hitType) {
224  case TrackingRecHit::bad:
225  // hitCount != endT => we are not inserting T type of hits but of T'
226  // 0 != beginT || 0 != endT => we already have hits of T type
227  // so we already have hits of T in the vector and we don't want to
228  // mess them with T' hits.
229  if
230  UNLIKELY(((hitCount != endTrackHits) && (0 != beginTrackHits || 0 != endTrackHits))) {
231  cms::Exception("HitPattern")
232  << "TRACK_HITS"
233  << " were stored on this object before hits of some other category were inserted "
234  << "but hits of the same category should be inserted in a row. "
235  << "Please rework the code so it inserts all "
236  << "TRACK_HITS"
237  << " in a row.";
238  return false;
239  }
240  return insertTrackHit(pattern);
241  break;
244  if
245  UNLIKELY(((hitCount != endInner) && (0 != beginInner || 0 != endInner))) {
246  cms::Exception("HitPattern")
247  << "MISSING_INNER_HITS"
248  << " were stored on this object before hits of some other category were inserted "
249  << "but hits of the same category should be inserted in a row. "
250  << "Please rework the code so it inserts all "
251  << "MISSING_INNER_HITS"
252  << " in a row.";
253  return false;
254  }
255  return insertExpectedInnerHit(pattern);
256  break;
259  if
260  UNLIKELY(((hitCount != endOuter) && (0 != beginOuter || 0 != endOuter))) {
261  cms::Exception("HitPattern")
262  << "MISSING_OUTER_HITS"
263  << " were stored on this object before hits of some other category were inserted "
264  << "but hits of the same category should be inserted in a row. "
265  << "Please rework the code so it inserts all "
266  << "MISSING_OUTER_HITS"
267  << " in a row.";
268  return false;
269  }
270  return insertExpectedOuterHit(pattern);
271  break;
272  }
273 
274  return false;
275 }
276 
277 bool HitPattern::appendTrackerHit(uint16_t subdet, uint16_t layer, uint16_t stereo, TrackingRecHit::Type hitType) {
278  return appendHit(encode(TRACKER_HIT, subdet, layer, stereo, hitType), hitType);
279 }
280 
282  //if HitPattern is full, journey ends no matter what.
283  if
284  UNLIKELY((hitCount == HitPattern::MaxHits)) { return false; }
285 
286  if
287  UNLIKELY(id.det() != DetId::Muon) {
288  throw cms::Exception("HitPattern")
289  << "Got DetId from det " << id.det()
290  << " that is not Muon in appendMuonHit(), which should only be used for muon hits in the HitPattern IO rule";
291  }
292 
293  uint16_t subdet = id.subdetId();
294  return appendHit(encode(MUON_HIT, subdet, encodeMuonLayer(id), 0, hitType), hitType);
295 }
296 
298  if
299  UNLIKELY((position < 0 || position >= hitCount)) { return HitPattern::EMPTY_PATTERN; }
300  /*
301  Note: you are not taking a consecutive sequence of HIT_LENGTH bits starting from position * HIT_LENGTH
302  as the bit order in the words are reversed.
303  e.g. if position = 0 you take the lowest 12 bits of the first word.
304 
305  I hope this can clarify what is the memory layout of such thing
306 
307  straight 01234567890123456789012345678901 | 23456789012345678901234567890123 | 4567
308  (global) 0 1 2 3 | 3 4 5 6 | 6
309  words [--------------0---------------] | [--------------1---------------] | [---
310  word 01234567890123456789012345678901 | 01234567890123456789012345678901 | 0123
311  (str) 0 1 2 3 | 0 1 2 3 | 0
312  [--------------0---------------] | [--------------1---------------] | [---
313  word 10987654321098765432109876543210 | 10987654321098765432109876543210 | 1098
314  (rev) 32 21 10 0 | 32 21 10 0 | 32
315  reverse 10987654321098765432109876543210 | 32109876543210987654321098765432 | 5432
316  32 21 10 0 | 6 65 54 43 3 9
317 
318  ugly enough, but it's not my fault, I was not even in CMS at that time [gpetrucc]
319  */
320 
321  uint16_t bitEndOffset = (position + 1) * HIT_LENGTH;
322  uint8_t secondWord = (bitEndOffset >> 4);
323  uint8_t secondWordBits = bitEndOffset & (16 - 1); // that is, bitEndOffset % 16
324  if (secondWordBits >= HIT_LENGTH) { // full block is in this word
325  uint8_t lowBitsToTrash = secondWordBits - HIT_LENGTH;
326  uint16_t myResult = (hitPattern[secondWord] >> lowBitsToTrash) & ((1 << HIT_LENGTH) - 1);
327  return myResult;
328  } else {
329  uint8_t firstWordBits = HIT_LENGTH - secondWordBits;
330  uint16_t firstWordBlock = hitPattern[secondWord - 1] >> (16 - firstWordBits);
331  uint16_t secondWordBlock = hitPattern[secondWord] & ((1 << secondWordBits) - 1);
332  uint16_t myResult = firstWordBlock + (secondWordBlock << firstWordBits);
333  return myResult;
334  }
335 }
336 
338  for (int i = beginTrackHits; i < endTrackHits; ++i) {
340  bool pixelHitFilter = ((det == 1 && pixelBarrelHitFilter(pattern)) || (det == 2 && pixelEndcapHitFilter(pattern)));
341  if (pixelHitFilter && (getLayer(pattern) == layer) && validHitFilter(pattern)) {
342  return true;
343  }
344  }
345  return false;
346 }
347 
348 int HitPattern::numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const {
349  bool hasMono[SubstrMask + 1][LayerMask + 1];
350  bool hasStereo[SubstrMask + 1][LayerMask + 1];
351  memset(hasMono, 0, sizeof(hasMono));
352  memset(hasStereo, 0, sizeof(hasStereo));
353 
354  // mark which layers have mono/stereo hits
355  for (int i = beginTrackHits; i < endTrackHits; ++i) {
357  uint16_t subStructure = getSubStructure(pattern);
358 
359  if (validHitFilter(pattern) && stripHitFilter(pattern)) {
360  if (stripdet != 0 && subStructure != stripdet) {
361  continue;
362  }
363 
364  if (layer != 0 && getSubSubStructure(pattern) != layer) {
365  continue;
366  }
367 
368  switch (getSide(pattern)) {
369  case 0: // mono
370  hasMono[subStructure][getLayer(pattern)] = true;
371  break;
372  case 1: // stereo
373  hasStereo[subStructure][getLayer(pattern)] = true;
374  break;
375  default:;
376  break;
377  }
378  }
379  }
380 
381  // count how many layers have mono and stereo hits
382  int count = 0;
383  for (int i = 0; i < SubstrMask + 1; ++i) {
384  for (int j = 0; j < LayerMask + 1; ++j) {
385  if (hasMono[i][j] && hasStereo[i][j]) {
386  count++;
387  }
388  }
389  }
390  return count;
391 }
392 
394  auto category = TRACK_HITS;
395  std::bitset<128> side[2];
396  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
397  for (int i = range.first; i < range.second; ++i) {
399  if (pattern > maxTrackerWord)
400  continue;
401  if (pattern < minStripWord)
402  continue;
403  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
404  if (hitType != HIT_TYPE::VALID)
405  continue;
406  auto apattern = (pattern - minTrackerWord) >> LayerOffset;
407  // assert(apattern<128);
408  side[getSide(pattern)].set(apattern);
409  }
410  // assert(numberOfValidStripLayersWithMonoAndStereo(0, 0)==int((side[0]&side[1]).count()));
411  return (side[0] & side[1]).count();
412 }
413 
416 }
417 
420 }
421 
424 }
425 
428 }
429 
430 uint32_t HitPattern::getTrackerLayerCase(HitCategory category, uint16_t substr, uint16_t layer) const {
431  uint16_t tk_substr_layer =
432  (0x1 << SubDetectorOffset) + ((substr & SubstrMask) << SubstrOffset) + ((layer & LayerMask) << LayerOffset);
433 
434  uint16_t mask = (SubDetectorMask << SubDetectorOffset) + (SubstrMask << SubstrOffset) + (LayerMask << LayerOffset);
435 
436  // layer case 0: valid + (missing, off, bad) ==> with measurement
437  // layer case 1: missing + (off, bad) ==> without measurement
438  // layer case 2: off, bad ==> totally off or bad, cannot say much
439  // layer case NULL_RETURN: track outside acceptance or in gap ==> null
440  uint32_t layerCase = NULL_RETURN;
441  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
442  for (int i = range.first; i < range.second; ++i) {
444  if ((pattern & mask) == tk_substr_layer) {
445  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
446  if (hitType < layerCase) {
447  // BAD and INACTIVE as the same type (as INACTIVE)
448  layerCase = (hitType == HIT_TYPE::BAD ? (uint32_t)HIT_TYPE::INACTIVE : hitType);
449  if (layerCase == HIT_TYPE::VALID) {
450  break;
451  }
452  }
453  }
454  }
455  return layerCase;
456 }
457 
458 uint16_t HitPattern::getTrackerMonoStereo(HitCategory category, uint16_t substr, uint16_t layer) const {
459  uint16_t tk_substr_layer =
460  (0x1 << SubDetectorOffset) + ((substr & SubstrMask) << SubstrOffset) + ((layer & LayerMask) << LayerOffset);
461  uint16_t mask = (SubDetectorMask << SubDetectorOffset) + (SubstrMask << SubstrOffset) + (LayerMask << LayerOffset);
462 
463  // 0: neither a valid mono nor a valid stereo hit
464  // MONO: valid mono hit
465  // STEREO: valid stereo hit
466  // MONO | STEREO: both
467  uint16_t monoStereo = 0x0;
468  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
469  for (int i = range.first; i < range.second; ++i) {
471  if ((pattern & mask) == tk_substr_layer) {
472  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
473  if (hitType == HIT_TYPE::VALID) {
474  switch (getSide(pattern)) {
475  case 0: // mono
476  monoStereo |= MONO;
477  break;
478  case 1: // stereo
479  monoStereo |= STEREO;
480  break;
481  }
482  }
483 
484  if (monoStereo == (MONO | STEREO)) {
485  break;
486  }
487  }
488  }
489  return monoStereo;
490 }
491 
493  auto category = TRACK_HITS;
494  std::bitset<128> layerOk;
495  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
496  for (int i = range.first; i < range.second; ++i) {
498  if
499  UNLIKELY(!trackerHitFilter(pattern)) continue;
500  if (pattern > minStripWord)
501  continue;
502  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
503  if (hitType != HIT_TYPE::VALID)
504  continue;
506  // assert(pattern<128);
507  layerOk.set(pattern);
508  }
509  // assert(pixelLayersWithMeasurementOld()==int(layerOk.count()));
510  return layerOk.count();
511 }
512 
514  auto category = TRACK_HITS;
515  std::bitset<128> layerOk;
516  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
517  for (int i = range.first; i < range.second; ++i) {
519  if
520  UNLIKELY(!trackerHitFilter(pattern)) continue;
521  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
522  if (hitType != HIT_TYPE::VALID)
523  continue;
525  // assert(pattern<128);
526  layerOk.set(pattern);
527  }
528  // assert(trackerLayersWithMeasurementOld()==int(layerOk.count()));
529  return layerOk.count();
530 }
531 
533  std::bitset<128> layerOk;
534  std::bitset<128> layerMissed;
535  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
536  for (int i = range.first; i < range.second; ++i) {
538  if
539  UNLIKELY(!trackerHitFilter(pattern)) continue;
540  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
542  // assert(pattern<128);
543  if (hitType == HIT_TYPE::VALID)
544  layerOk.set(pattern);
545  if (hitType == HIT_TYPE::MISSING)
546  layerMissed.set(pattern);
547  }
548  layerMissed &= ~layerOk;
549 
550  // assert(trackerLayersWithoutMeasurementOld(category)==int(layerMissed.count()));
551 
552  return layerMissed.count();
553 }
554 
556  int count = 0;
557  uint16_t NPixBarrel = 4;
558  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
559  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::VALID) {
560  count++;
561  }
562  }
563  return count;
564 }
565 
567  int count = 0;
568  uint16_t NPixForward = 3;
569  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
570  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::VALID) {
571  count++;
572  }
573  }
574  return count;
575 }
576 
578  int count = 0;
579  for (uint16_t layer = 1; layer <= 4; layer++) {
580  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TIB, layer) == HIT_TYPE::VALID) {
581  count++;
582  }
583  }
584  return count;
585 }
586 
588  int count = 0;
589  for (uint16_t layer = 1; layer <= 3; layer++) {
590  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TID, layer) == HIT_TYPE::VALID) {
591  count++;
592  }
593  }
594  return count;
595 }
596 
598  int count = 0;
599  for (uint16_t layer = 1; layer <= 6; layer++) {
600  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TOB, layer) == HIT_TYPE::VALID) {
601  count++;
602  }
603  }
604  return count;
605 }
606 
608  int count = 0;
609  for (uint16_t layer = 1; layer <= 9; layer++) {
610  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TEC, layer) == HIT_TYPE::VALID) {
611  count++;
612  }
613  }
614  return count;
615 }
616 
618  int count = 0;
619  uint16_t NPixBarrel = 4;
620  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
621  if (getTrackerLayerCase(category, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::MISSING) {
622  count++;
623  }
624  }
625  return count;
626 }
627 
629  int count = 0;
630  uint16_t NPixForward = 3;
631  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
632  if (getTrackerLayerCase(category, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::MISSING) {
633  count++;
634  }
635  }
636  return count;
637 }
638 
640  int count = 0;
641  for (uint16_t layer = 1; layer <= 4; layer++) {
642  if (getTrackerLayerCase(category, StripSubdetector::TIB, layer) == HIT_TYPE::MISSING) {
643  count++;
644  }
645  }
646  return count;
647 }
648 
650  int count = 0;
651  for (uint16_t layer = 1; layer <= 3; layer++) {
652  if (getTrackerLayerCase(category, StripSubdetector::TID, layer) == HIT_TYPE::MISSING) {
653  count++;
654  }
655  }
656  return count;
657 }
658 
660  int count = 0;
661  for (uint16_t layer = 1; layer <= 6; layer++) {
662  if (getTrackerLayerCase(category, StripSubdetector::TOB, layer) == HIT_TYPE::MISSING) {
663  count++;
664  }
665  }
666  return count;
667 }
668 
670  int count = 0;
671  for (uint16_t layer = 1; layer <= 9; layer++) {
672  if (getTrackerLayerCase(category, StripSubdetector::TEC, layer) == HIT_TYPE::MISSING) {
673  count++;
674  }
675  }
676  return count;
677 }
678 
680  int count = 0;
681  uint16_t NPixBarrel = 4;
682  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
683  if (getTrackerLayerCase(category, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::INACTIVE) {
684  count++;
685  }
686  }
687  return count;
688 }
689 
691  int count = 0;
692  uint16_t NPixForward = 3;
693  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
694  if (getTrackerLayerCase(category, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::INACTIVE) {
695  count++;
696  }
697  }
698  return count;
699 }
700 
702  int count = 0;
703  for (uint16_t layer = 1; layer <= 4; layer++) {
704  if (getTrackerLayerCase(category, StripSubdetector::TIB, layer) == HIT_TYPE::INACTIVE) {
705  count++;
706  }
707  }
708  return count;
709 }
710 
712  int count = 0;
713  for (uint16_t layer = 1; layer <= 3; layer++) {
714  if (getTrackerLayerCase(category, StripSubdetector::TID, layer) == HIT_TYPE::INACTIVE) {
715  count++;
716  }
717  }
718  return count;
719 }
720 
722  int count = 0;
723  for (uint16_t layer = 1; layer <= 6; layer++) {
724  if (getTrackerLayerCase(category, StripSubdetector::TOB, layer) == HIT_TYPE::INACTIVE) {
725  count++;
726  }
727  }
728  return count;
729 }
730 
732  int count = 0;
733  for (uint16_t layer = 1; layer <= 9; layer++) {
734  if (getTrackerLayerCase(category, StripSubdetector::TEC, layer) == HIT_TYPE::INACTIVE) {
735  count++;
736  }
737  }
738  return count;
739 }
740 
742  int count = 0;
743  uint16_t NPixBarrel = 4;
744  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
746  count++;
747  }
748  }
749  return count;
750 }
751 
753  int count = 0;
754  uint16_t NPixForward = 3;
755  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
757  count++;
758  }
759  }
760  return count;
761 }
762 
764  int count = 0;
765  for (uint16_t layer = 1; layer <= 4; layer++) {
767  count++;
768  }
769  }
770  return count;
771 }
772 
774  int count = 0;
775  for (uint16_t layer = 1; layer <= 3; layer++) {
777  count++;
778  }
779  }
780  return count;
781 }
782 
784  int count = 0;
785  for (uint16_t layer = 1; layer <= 6; layer++) {
787  count++;
788  }
789  }
790  return count;
791 }
792 
794  int count = 0;
795  for (uint16_t layer = 1; layer <= 9; layer++) {
797  count++;
798  }
799  }
800  return count;
801 }
802 
803 void HitPattern::printHitPattern(HitCategory category, int position, std::ostream& stream) const {
804  uint16_t pattern = getHitPattern(category, position);
805  stream << "\t";
806  if (muonHitFilter(pattern)) {
807  stream << "muon";
808  } else if (trackerHitFilter(pattern)) {
809  stream << "tracker";
810  } else if (timingHitFilter(pattern)) {
811  stream << "timing";
812  }
813 
814  stream << "\tsubstructure " << getSubStructure(pattern);
815  if (muonHitFilter(pattern)) {
816  stream << "\tstation " << getMuonStation(pattern);
817  if (muonDTHitFilter(pattern)) {
818  stream << "\tdt superlayer " << getDTSuperLayer(pattern);
819  } else if (muonCSCHitFilter(pattern)) {
820  stream << "\tcsc ring " << getCSCRing(pattern);
821  } else if (muonRPCHitFilter(pattern)) {
822  stream << "\trpc " << (getRPCregion(pattern) ? "endcaps" : "barrel") << ", layer " << getRPCLayer(pattern);
823  } else if (muonGEMHitFilter(pattern)) {
824  stream << "\tgem " << (getGEMLayer(pattern) ? "layer1" : "layer2") << ", station " << getGEMStation(pattern);
825  } else if (muonME0HitFilter(pattern)) {
826  stream << "\tme0 ";
827  } else {
828  stream << "(UNKNOWN Muon SubStructure!) \tsubsubstructure " << getSubStructure(pattern);
829  }
830  } else if (timingHitFilter(pattern)) {
831  stream << "\tdetector " << getSubStructure(pattern);
832  } else {
833  stream << "\tlayer " << getLayer(pattern);
834  }
835  stream << "\thit type " << getHitType(pattern);
836  stream << std::endl;
837 }
838 
839 void HitPattern::print(HitCategory category, std::ostream& stream) const {
840  stream << "HitPattern" << std::endl;
841  for (int i = 0; i < numberOfAllHits(category); ++i) {
842  printHitPattern(category, i, stream);
843  }
844  std::ios_base::fmtflags flags = stream.flags();
845  stream.setf(std::ios_base::hex, std::ios_base::basefield);
846  stream.setf(std::ios_base::showbase);
847 
848  for (int i = 0; i < this->numberOfAllHits(category); ++i) {
849  stream << getHitPattern(category, i) << std::endl;
850  }
851 
852  stream.flags(flags);
853 }
854 
855 uint16_t HitPattern::isStereo(DetId i, const TrackerTopology& ttopo) {
856  if (i.det() != DetId::Tracker) {
857  return 0;
858  }
859 
860  switch (i.subdetId()) {
863  return 0;
865  return ttopo.tibIsStereo(i);
867  return ttopo.tidIsStereo(i);
869  return ttopo.tobIsStereo(i);
871  return ttopo.tecIsStereo(i);
872  default:
873  return 0;
874  }
875 }
876 
877 int HitPattern::muonStations(int subdet, int hitType) const {
878  int stations[4] = {0, 0, 0, 0};
879  for (int i = beginTrackHits; i < endTrackHits; ++i) {
881  if (muonHitFilter(pattern) && (subdet == 0 || int(getSubStructure(pattern)) == subdet) &&
882  (hitType == -1 || int(getHitType(pattern)) == hitType)) {
883  stations[getMuonStation(pattern) - 1] = 1;
884  }
885  }
886 
887  return stations[0] + stations[1] + stations[2] + stations[3];
888 }
889 
891  int ret = 0;
892  for (int i = beginTrackHits; i < endTrackHits; ++i) {
894  if (muonHitFilter(pattern) && (hitType == -1 || int(getHitType(pattern)) == hitType)) {
895  int stat = getMuonStation(pattern);
896  if (ret == 0 || stat < ret) {
897  ret = stat;
898  }
899  }
900  }
901 
902  return ret;
903 }
904 
906  int ret = 0;
907  for (int i = beginTrackHits; i < endTrackHits; ++i) {
909  if (muonHitFilter(pattern) && (hitType == -1 || int(getHitType(pattern)) == hitType)) {
910  int stat = getMuonStation(pattern);
911  if (ret == 0 || stat > ret) {
912  ret = stat;
913  }
914  }
915  }
916  return ret;
917 }
918 
920  int stations[4] = {0, 0, 0, 0};
921  for (int i = beginTrackHits; i < endTrackHits; ++i) {
923 
924  if (muonDTHitFilter(pattern) && validHitFilter(pattern) && getDTSuperLayer(pattern) != 2) {
925  stations[getMuonStation(pattern) - 1] = 1;
926  }
927  }
928  return stations[0] + stations[1] + stations[2] + stations[3];
929 }
930 
932  int stations[4] = {0, 0, 0, 0};
933  for (int i = beginTrackHits; i < endTrackHits; ++i) {
935  if (muonDTHitFilter(pattern) && validHitFilter(pattern) && getDTSuperLayer(pattern) == 2) {
936  stations[getMuonStation(pattern) - 1] = 1;
937  }
938  }
939  return stations[0] + stations[1] + stations[2] + stations[3];
940 }
941 
943  int stations[4][2] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
944  for (int i = beginTrackHits; i < endTrackHits; ++i) {
946  if (muonDTHitFilter(pattern) && validHitFilter(pattern)) {
947  stations[getMuonStation(pattern) - 1][getDTSuperLayer(pattern) == 2] = 1;
948  }
949  }
950 
951  return stations[0][0] * stations[0][1] + stations[1][0] * stations[1][1] + stations[2][0] * stations[2][1] +
952  stations[3][0] * stations[3][1];
953 }
954 
955 void HitPattern::insertHit(const uint16_t pattern) {
956  int offset = hitCount * HIT_LENGTH;
957  for (int i = 0; i < HIT_LENGTH; i++) {
958  int pos = offset + i;
959  uint16_t bit = (pattern >> i) & 0x1;
960  //equivalent to hitPattern[pos / 16] += bit << ((offset + i) % 16);
961  hitPattern[pos >> 4] += bit << ((offset + i) & (16 - 1));
962  }
963  hitCount++;
964 }
965 
966 bool HitPattern::insertTrackHit(const uint16_t pattern) {
967  // if begin is 0, this is the first hit of this type being inserted, so
968  // we need to update begin so it points to the correct index, the first
969  // empty index.
970  // unlikely, because it will happen only when inserting
971  // the first hit of this type
972  if
973  UNLIKELY((0 == beginTrackHits && 0 == endTrackHits)) {
975  // before the first hit of this type is inserted, there are no hits
977  }
978 
979  insertHit(pattern);
980  endTrackHits++;
981 
982  return true;
983 }
984 
986  if
987  UNLIKELY((0 == beginInner && 0 == endInner)) {
990  }
991 
992  insertHit(pattern);
993  endInner++;
994 
995  return true;
996 }
997 
999  if
1000  UNLIKELY((0 == beginOuter && 0 == endOuter)) {
1001  beginOuter = hitCount;
1002  endOuter = beginOuter;
1003  }
1004 
1005  insertHit(pattern);
1006  endOuter++;
1007 
1008  return true;
1009 }
int stripTOBLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:721
int stripTOBLayersWithMeasurement() const
Definition: HitPattern.cc:597
static uint16_t getCSCRing(uint16_t pattern)
CSC ring (1-4). Only valid for muon CSC patterns, of course.
Definition: HitPattern.h:737
static constexpr auto TEC
int pixelBarrelLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:617
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:703
void insertHit(const uint16_t pattern)
Definition: HitPattern.cc:955
int outermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:905
static const unsigned short HIT_LENGTH
Definition: HitPattern.h:158
static const unsigned short ARRAY_LENGTH
Definition: HitPattern.h:157
static const uint32_t NULL_RETURN
Definition: HitPattern.h:161
static constexpr int GEM
Definition: MuonSubdetId.h:14
int pixelBarrelLayersNull() const
Definition: HitPattern.cc:741
static bool timingHitFilter(uint16_t pattern)
Definition: HitPattern.h:689
static bool pixelHitFilter(uint16_t pattern)
Definition: HitPattern.h:574
int stripTIBLayersNull() const
Definition: HitPattern.cc:763
int pixelBarrelLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:679
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
Definition: HitPattern.cc:337
static uint16_t isStereo(DetId i, const TrackerTopology &ttopo)
Definition: HitPattern.cc:855
bool tobIsStereo(const DetId &id) const
int stripTIBLayersWithMeasurement() const
Definition: HitPattern.cc:577
int stripTECLayersNull() const
Definition: HitPattern.cc:793
static const unsigned short SideOffset
Definition: HitPattern.h:445
static const uint16_t EMPTY_PATTERN
Definition: HitPattern.h:162
int muonStations(int subdet, int hitType) const
subdet = 0(all), 1(DT), 2(CSC), 3(RPC) 4(GEM); hitType=-1(all), 0=valid, 3=bad
Definition: HitPattern.cc:877
static uint16_t getDTSuperLayer(uint16_t pattern)
DT superlayer (1-3). Where the "hit" was a DT segment, superlayer is 0. Only valid for muon DT patter...
Definition: HitPattern.h:735
static bool muonME0HitFilter(uint16_t pattern)
Definition: HitPattern.h:657
ret
prodAgent to be discontinued
static const unsigned short SubstrOffset
Definition: HitPattern.h:453
int stripTOBLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:659
int numberOfDTStationsWithRPhiView() const
Definition: HitPattern.cc:919
HitPattern & operator=(const HitPattern &other)
Definition: HitPattern.cc:37
uint16_t getTrackerMonoStereo(HitCategory category, uint16_t substr, uint16_t layer) const
Definition: HitPattern.cc:458
static const unsigned short MaxHits
Definition: HitPattern.h:159
uint32_t getTrackerLayerCase(HitCategory category, uint16_t substr, uint16_t layer) const
Definition: HitPattern.cc:430
static const unsigned short maxTrackerWord
Definition: HitPattern.h:461
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:492
int numberOfValidStripLayersWithMonoAndStereo() const
Definition: HitPattern.cc:393
int pixelEndcapLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:628
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:513
static const unsigned short HitTypeMask
Definition: HitPattern.h:442
static bool pixelBarrelHitFilter(uint16_t pattern)
Definition: HitPattern.h:582
int pixelEndcapLayersWithMeasurement() const
Definition: HitPattern.cc:566
Detector identifier base class for the MIP Timing Layer.
Definition: MTDDetId.h:21
bool insertExpectedOuterHit(const uint16_t pattern)
Definition: HitPattern.cc:998
bool tidIsStereo(const DetId &id) const
static bool pixelEndcapHitFilter(uint16_t pattern)
Definition: HitPattern.h:590
static bool validHitFilter(uint16_t pattern)
Definition: HitPattern.h:766
uint8_t endInner
Definition: HitPattern.h:497
void printHitPattern(HitCategory category, int position, std::ostream &stream) const
Definition: HitPattern.cc:803
bool tecIsStereo(const DetId &id) const
static uint16_t getGEMLayer(uint16_t pattern)
GEM layer: 1,2. Only valid for muon GEM patterns, of course.
Definition: HitPattern.h:764
static const unsigned short minTrackerWord
Definition: HitPattern.h:460
uint16_t hitPattern[ARRAY_LENGTH]
Definition: HitPattern.h:491
int stripTIBLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:701
static bool muonCSCHitFilter(uint16_t pattern)
Definition: HitPattern.h:633
static uint32_t getHitType(uint16_t pattern)
Definition: HitPattern.h:726
int numberOfValidTECLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:426
int stripTIDLayersWithMeasurement() const
Definition: HitPattern.cc:587
static const unsigned short SubDetectorMask
Definition: HitPattern.h:458
int layer() const
Definition: GEMDetId.h:184
static bool stripHitFilter(uint16_t pattern)
Definition: HitPattern.h:598
constexpr int subdetId() const
get the contents of the subdetector field (not cast into any detector&#39;s numbering enum) ...
Definition: DetId.h:48
int numberOfAllHits(HitCategory category) const
Definition: HitPattern.h:774
int station() const
Definition: GEMDetId.h:173
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int superLayer() const
Return the superlayer number.
bool appendHit(const TrackingRecHit &hit, const TrackerTopology &ttopo)
Definition: HitPattern.cc:201
int numberOfDTStationsWithRZView() const
Definition: HitPattern.cc:931
static constexpr int ME0
Definition: MuonSubdetId.h:15
uint8_t beginInner
Definition: HitPattern.h:496
static constexpr auto TOB
int stripTIDLayersNull() const
Definition: HitPattern.cc:773
static const unsigned short HitTypeOffset
Definition: HitPattern.h:441
int numberOfValidTIDLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:422
int mtdRR() const
Definition: MTDDetId.h:64
bool appendTrackerHit(uint16_t subdet, uint16_t layer, uint16_t stereo, TrackingRecHit::Type hitType)
Definition: HitPattern.cc:277
uint8_t beginTrackHits
Definition: HitPattern.h:494
static uint32_t getSubStructure(uint16_t pattern)
Definition: HitPattern.h:696
int numberOfDTStationsWithBothViews() const
Definition: HitPattern.cc:942
int numberOfValidTIBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:418
static uint16_t getRPCregion(uint16_t pattern)
RPC region: 0 = barrel, 1 = endcap. Only valid for muon RPC patterns, of course.
Definition: HitPattern.h:749
int ring() const
Definition: CSCDetId.h:68
static bool muonGEMHitFilter(uint16_t pattern)
Definition: HitPattern.h:649
static uint16_t getGEMStation(uint16_t pattern)
GEM station: 1,2. Only valid for muon GEM patterns, of course.
Definition: HitPattern.h:752
int stripTIDLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:649
int layer() const
Definition: RPCDetId.h:85
Definition: DetId.h:17
int innermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:890
static bool muonHitFilter(uint16_t pattern)
Definition: HitPattern.h:668
Type getType() const
static bool trackerHitFilter(uint16_t pattern)
Definition: HitPattern.h:664
uint8_t endTrackHits
Definition: HitPattern.h:495
double const BAD
Definition: Constants.h:15
static constexpr auto TIB
static const unsigned short SideMask
Definition: HitPattern.h:446
static const unsigned short minStripWord
Definition: HitPattern.h:463
std::pair< uint8_t, uint8_t > getCategoryIndexRange(HitCategory category) const
Definition: HitPattern.h:507
uint8_t hitCount
Definition: HitPattern.h:492
uint8_t beginOuter
Definition: HitPattern.h:498
static const unsigned short SubDetectorOffset
Definition: HitPattern.h:457
bool tibIsStereo(const DetId &id) const
static constexpr int RPC
Definition: MuonSubdetId.h:13
int pixelBarrelLayersWithMeasurement() const
Definition: HitPattern.cc:555
int roll() const
Definition: ME0DetId.h:48
unsigned int layer(const DetId &id) const
uint16_t getHitPatternByAbsoluteIndex(int position) const
Definition: HitPattern.cc:297
static uint32_t getSide(uint16_t pattern)
Definition: HitPattern.h:719
int stripTOBLayersNull() const
Definition: HitPattern.cc:783
static bool muonDTHitFilter(uint16_t pattern)
Definition: HitPattern.h:625
int stripTIDLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:711
int trackerLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:532
bool insertExpectedInnerHit(const uint16_t pattern)
Definition: HitPattern.cc:985
Detector identifier class for the Endcap Timing Layer.
Definition: ETLDetId.h:15
fixed size matrix
static const unsigned short SubstrMask
Definition: HitPattern.h:454
static const unsigned short LayerOffset
Definition: HitPattern.h:449
static int position[264][3]
Definition: ReadPGInfo.cc:289
Detector identifier class for the Barrel Timing Layer. The crystal count must start from 0...
Definition: BTLDetId.h:18
int mtdSubDetector() const
Definition: MTDDetId.h:56
int pixelEndcapLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:690
bool insertTrackHit(const uint16_t pattern)
Definition: HitPattern.cc:966
int stripTECLayersWithMeasurement() const
Definition: HitPattern.cc:607
int stripTECLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:669
static uint16_t getRPCLayer(uint16_t pattern)
RPC layer: for station 1 and 2, layer = 1(inner) or 2(outer); for station 3, 4 layer is always 0...
Definition: HitPattern.h:739
int station() const
Definition: CSCDetId.h:79
static uint16_t getMuonStation(uint16_t pattern)
Muon station (1-4). Only valid for muon patterns, of course. only for patterns from muon...
Definition: HitPattern.h:733
void print(HitCategory category, std::ostream &stream=std::cout) const
Definition: HitPattern.cc:839
int numberOfValidTOBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:414
DetId geographicalId() const
#define UNLIKELY(x)
Definition: Likely.h:21
static uint32_t getSubSubStructure(uint16_t pattern)
Definition: HitPattern.h:705
static constexpr int DT
Definition: MuonSubdetId.h:11
uint16_t getHitPattern(HitCategory category, int position) const
Definition: HitPattern.h:531
int station() const
Return the station number.
Definition: DTChamberId.h:42
static const unsigned short LayerMask
Definition: HitPattern.h:450
static bool muonRPCHitFilter(uint16_t pattern)
Definition: HitPattern.h:641
static constexpr int CSC
Definition: MuonSubdetId.h:12
static constexpr auto TID
uint8_t endOuter
Definition: HitPattern.h:499
static uint16_t encode(const TrackingRecHit &hit, const TrackerTopology &ttopo)
Definition: HitPattern.cc:74
int modType() const
Definition: BTLDetId.h:99
int stripTECLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:731
int stripTIBLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:639
bool appendMuonHit(const DetId &id, TrackingRecHit::Type hitType)
Definition: HitPattern.cc:281
int pixelEndcapLayersNull() const
Definition: HitPattern.cc:752
constexpr Detector det() const
get the detector field from this detid
Definition: DetId.h:46
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:53
int station() const
Definition: RPCDetId.h:78