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