CMS 3D CMS Logo

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