CMS 3D CMS Logo

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