CMS 3D CMS Logo

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