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  (hitType == TrackingRecHit::inactive_inner ||
180  :hitType);
181 
182  pattern |= (patternHitType & HitTypeMask) << HitTypeOffset;
183 
184  return pattern;
185 }
186 
188 {
189  return appendHit(hit.geographicalId(), hit.getType(), ttopo);
190 }
191 
192 bool HitPattern::appendHit(const DetId &id, TrackingRecHit::Type hitType, const TrackerTopology& ttopo)
193 {
194  //if HitPattern is full, journey ends no matter what.
196  return false;
197  }
198 
199  uint16_t pattern = HitPattern::encode(id, hitType, ttopo);
200 
201  return appendHit(pattern, hitType);
202 }
203 
205 {
206  //if HitPattern is full, journey ends no matter what.
208  return false;
209  }
210 
211  switch (hitType) {
215  case TrackingRecHit::bad:
216  // hitCount != endT => we are not inserting T type of hits but of T'
217  // 0 != beginT || 0 != endT => we already have hits of T type
218  // so we already have hits of T in the vector and we don't want to
219  // mess them with T' hits.
220  if unlikely(((hitCount != endTrackHits) && (0 != beginTrackHits || 0 != endTrackHits))) {
221  cms::Exception("HitPattern")
222  << "TRACK_HITS"
223  << " were stored on this object before hits of some other category were inserted "
224  << "but hits of the same category should be inserted in a row. "
225  << "Please rework the code so it inserts all "
226  << "TRACK_HITS"
227  << " in a row.";
228  return false;
229  }
230  return insertTrackHit(pattern);
231  break;
234  if unlikely(((hitCount != endInner) && (0 != beginInner || 0 != endInner))) {
235  cms::Exception("HitPattern")
236  << "MISSING_INNER_HITS"
237  << " were stored on this object before hits of some other category were inserted "
238  << "but hits of the same category should be inserted in a row. "
239  << "Please rework the code so it inserts all "
240  << "MISSING_INNER_HITS"
241  << " in a row.";
242  return false;
243  }
244  return insertExpectedInnerHit(pattern);
245  break;
248  if unlikely(((hitCount != endOuter) && (0 != beginOuter || 0 != endOuter))) {
249  cms::Exception("HitPattern")
250  << "MISSING_OUTER_HITS"
251  << " were stored on this object before hits of some other category were inserted "
252  << "but hits of the same category should be inserted in a row. "
253  << "Please rework the code so it inserts all "
254  << "MISSING_OUTER_HITS"
255  << " in a row.";
256  return false;
257  }
258  return insertExpectedOuterHit(pattern);
259  break;
260  }
261 
262  return false;
263 }
264 
265 bool HitPattern::appendTrackerHit(uint16_t subdet, uint16_t layer, uint16_t stereo, TrackingRecHit::Type hitType) {
266  return appendHit(encode(DetId::Tracker, subdet, layer, stereo, hitType), hitType);
267 }
268 
270  //if HitPattern is full, journey ends no matter what.
272  return false;
273  }
274 
275  if unlikely(id.det() != DetId::Muon) {
276  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";
277  }
278 
279  uint16_t detid = id.det();
280  uint16_t subdet = id.subdetId();
281  return appendHit(encode(detid, subdet, encodeMuonLayer(id), 0, hitType), hitType);
282 }
283 
285 {
286  if unlikely((position < 0 || position >= hitCount)) {
288  }
289  /*
290  Note: you are not taking a consecutive sequence of HIT_LENGTH bits starting from position * HIT_LENGTH
291  as the bit order in the words are reversed.
292  e.g. if position = 0 you take the lowest 10 bits of the first word.
293 
294  I hope this can clarify what is the memory layout of such thing
295 
296  straight 01234567890123456789012345678901 | 23456789012345678901234567890123 | 4567
297  (global) 0 1 2 3 | 3 4 5 6 | 6
298  words [--------------0---------------] | [--------------1---------------] | [---
299  word 01234567890123456789012345678901 | 01234567890123456789012345678901 | 0123
300  (str) 0 1 2 3 | 0 1 2 3 | 0
301  [--------------0---------------] | [--------------1---------------] | [---
302  word 10987654321098765432109876543210 | 10987654321098765432109876543210 | 1098
303  (rev) 32 21 10 0 | 32 21 10 0 | 32
304  reverse 10987654321098765432109876543210 | 32109876543210987654321098765432 | 5432
305  32 21 10 0 | 6 65 54 43 3 9
306 
307  ugly enough, but it's not my fault, I was not even in CMS at that time [gpetrucc]
308  */
309 
310  uint16_t bitEndOffset = (position + 1) * HIT_LENGTH;
311  uint8_t secondWord = (bitEndOffset >> 4);
312  uint8_t secondWordBits = bitEndOffset & (16 - 1); // that is, bitEndOffset % 16
313  if (secondWordBits >= HIT_LENGTH) { // full block is in this word
314  uint8_t lowBitsToTrash = secondWordBits - HIT_LENGTH;
315  uint16_t myResult = (hitPattern[secondWord] >> lowBitsToTrash) & ((1 << HIT_LENGTH) - 1);
316  return myResult;
317  } else {
318  uint8_t firstWordBits = HIT_LENGTH - secondWordBits;
319  uint16_t firstWordBlock = hitPattern[secondWord - 1] >> (16 - firstWordBits);
320  uint16_t secondWordBlock = hitPattern[secondWord] & ((1 << secondWordBits) - 1);
321  uint16_t myResult = firstWordBlock + (secondWordBlock << firstWordBits);
322  return myResult;
323  }
324 }
325 
326 
328 {
329  for (int i = beginTrackHits; i < endTrackHits; ++i) {
331  bool pixelHitFilter = ( (det==1 && pixelBarrelHitFilter(pattern)) ||
332  (det==2 && pixelEndcapHitFilter(pattern)) );
333  if (pixelHitFilter && (getLayer(pattern) == layer) && validHitFilter(pattern)) {
334  return true;
335  }
336  }
337  return false;
338 }
339 
340 
341 int HitPattern::numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
342 {
343  bool hasMono[SubstrMask + 1][LayerMask + 1];
344  bool hasStereo[SubstrMask + 1][LayerMask + 1];
345  memset(hasMono, 0, sizeof(hasMono));
346  memset(hasStereo, 0, sizeof(hasStereo));
347 
348  // mark which layers have mono/stereo hits
349  for (int i = beginTrackHits; i < endTrackHits; ++i) {
351  uint16_t subStructure = getSubStructure(pattern);
352 
353  if (validHitFilter(pattern) && stripHitFilter(pattern)) {
354  if (stripdet != 0 && subStructure != stripdet) {
355  continue;
356  }
357 
358  if (layer != 0 && getSubSubStructure(pattern) != layer) {
359  continue;
360  }
361 
362  switch (getSide(pattern)) {
363  case 0: // mono
364  hasMono[subStructure][getLayer(pattern)] = true;
365  break;
366  case 1: // stereo
367  hasStereo[subStructure][getLayer(pattern)] = true;
368  break;
369  default:
370  ;
371  break;
372  }
373  }
374  }
375 
376  // count how many layers have mono and stereo hits
377  int count = 0;
378  for (int i = 0; i < SubstrMask + 1; ++i) {
379  for (int j = 0; j < LayerMask + 1; ++j) {
380  if (hasMono[i][j] && hasStereo[i][j]) {
381  count++;
382  }
383  }
384  }
385  return count;
386 }
387 
389 {
390  auto category = TRACK_HITS;
391  std::bitset<128> side[2];
392  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
393  for (int i = range.first; i < range.second; ++i) {
395  if (pattern<minStripWord) continue;
396  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
397  if (hitType != HIT_TYPE::VALID) continue;
398  auto apattern = (pattern-minTrackerWord) >> LayerOffset;
399  // assert(apattern<128);
400  side[getSide(pattern)].set(apattern);
401  }
402  // assert(numberOfValidStripLayersWithMonoAndStereo(0, 0)==int((side[0]&side[1]).count()));
403  return (side[0]&side[1]).count();
404 
405 
406 }
407 
409 {
411 }
412 
414 {
416 }
417 
419 {
421 }
422 
424 {
426 }
427 
428 uint32_t HitPattern::getTrackerLayerCase(HitCategory category, uint16_t substr, uint16_t layer) const
429 {
430  uint16_t tk_substr_layer = (0x1 << SubDetectorOffset)
431  + ((substr & SubstrMask) << SubstrOffset)
432  + ((layer & LayerMask) << LayerOffset);
433 
434  uint16_t mask = (SubDetectorMask << SubDetectorOffset)
435  + (SubstrMask << SubstrOffset)
436  + (LayerMask << LayerOffset);
437 
438  // layer case 0: valid + (missing, off, bad) ==> with measurement
439  // layer case 1: missing + (off, bad) ==> without measurement
440  // layer case 2: off, bad ==> totally off or bad, cannot say much
441  // layer case NULL_RETURN: track outside acceptance or in gap ==> null
442  uint32_t layerCase = NULL_RETURN;
443  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
444  for (int i = range.first; i < range.second; ++i) {
446  if ((pattern & mask) == tk_substr_layer) {
447  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
448  if (hitType < layerCase) {
449  // BAD and INACTIVE as the same type (as INACTIVE)
450  layerCase = (hitType == HIT_TYPE::BAD ? HIT_TYPE::INACTIVE : hitType);
451  if (layerCase == HIT_TYPE::VALID) {
452  break;
453  }
454  }
455  }
456  }
457  return layerCase;
458 }
459 
460 uint16_t HitPattern::getTrackerMonoStereo(HitCategory category, uint16_t substr, uint16_t layer) const
461 {
462  uint16_t tk_substr_layer = (0x1 << SubDetectorOffset)
463  + ((substr & SubstrMask) << SubstrOffset)
464  + ((layer & LayerMask) << LayerOffset);
465  uint16_t mask = (SubDetectorMask << SubDetectorOffset)
466  + (SubstrMask << SubstrOffset)
467  + (LayerMask << LayerOffset);
468 
469  // 0: neither a valid mono nor a valid stereo hit
470  // MONO: valid mono hit
471  // STEREO: valid stereo hit
472  // MONO | STEREO: both
473  uint16_t monoStereo = 0x0;
474  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
475  for (int i = range.first; i < range.second; ++i) {
477  if ((pattern & mask) == tk_substr_layer) {
478  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
479  if (hitType == HIT_TYPE::VALID) {
480  switch (getSide(pattern)) {
481  case 0: // mono
482  monoStereo |= MONO;
483  break;
484  case 1: // stereo
485  monoStereo |= STEREO;
486  break;
487  }
488  }
489 
490  if (monoStereo == (MONO | STEREO)) {
491  break;
492  }
493  }
494  }
495  return monoStereo;
496 }
497 
498 
500  auto category = TRACK_HITS;
501  std::bitset<128> layerOk;
502  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
503  for (int i = range.first; i < range.second; ++i) {
505  if unlikely(!trackerHitFilter(pattern)) continue;
506  if (pattern>minStripWord) continue;
507  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
508  if (hitType != HIT_TYPE::VALID) continue;
510  // assert(pattern<128);
511  layerOk.set(pattern);
512  }
513  // assert(pixelLayersWithMeasurementOld()==int(layerOk.count()));
514  return layerOk.count();
515 }
516 
517 
519  auto category = TRACK_HITS;
520  std::bitset<128> layerOk;
521  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
522  for (int i = range.first; i < range.second; ++i) {
524  if unlikely(!trackerHitFilter(pattern)) continue;
525  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
526  if (hitType != HIT_TYPE::VALID) continue;
528  // assert(pattern<128);
529  layerOk.set(pattern);
530  }
531  // assert(trackerLayersWithMeasurementOld()==int(layerOk.count()));
532  return layerOk.count();
533 }
534 
536  std::bitset<128> layerOk;
537  std::bitset<128> layerMissed;
538  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
539  for (int i = range.first; i < range.second; ++i) {
541  if unlikely(!trackerHitFilter(pattern)) continue;
542  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
544  // assert(pattern<128);
545  if (hitType == HIT_TYPE::VALID) layerOk.set(pattern);
546  if (hitType == HIT_TYPE::MISSING) layerMissed.set(pattern);
547  }
548  layerMissed &= ~layerOk;
549 
550  // assert(trackerLayersWithoutMeasurementOld(category)==int(layerMissed.count()));
551 
552  return layerMissed.count();
553 
554 
555 }
556 
557 
559 {
560  int count = 0;
561  uint16_t NPixBarrel = 4;
562  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
563  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::VALID) {
564  count++;
565  }
566  }
567  return count;
568 }
569 
571 {
572  int count = 0;
573  uint16_t NPixForward = 3;
574  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
575  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::VALID) {
576  count++;
577  }
578  }
579  return count;
580 }
581 
583 {
584  int count = 0;
585  for (uint16_t layer = 1; layer <= 4; layer++) {
586  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TIB, layer) == HIT_TYPE::VALID) {
587  count++;
588  }
589  }
590  return count;
591 }
592 
594 {
595  int count = 0;
596  for (uint16_t layer = 1; layer <= 3; layer++) {
597  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TID, layer) == HIT_TYPE::VALID) {
598  count++;
599  }
600  }
601  return count;
602 }
603 
605 {
606  int count = 0;
607  for (uint16_t layer = 1; layer <= 6; layer++) {
608  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TOB, layer) == HIT_TYPE::VALID) {
609  count++;
610  }
611  }
612  return count;
613 }
614 
616 {
617  int count = 0;
618  for (uint16_t layer = 1; layer <= 9; layer++) {
619  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TEC, layer) == HIT_TYPE::VALID) {
620  count++;
621  }
622  }
623  return count;
624 }
625 
627 {
628  int count = 0;
629  uint16_t NPixBarrel = 4;
630  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
631  if (getTrackerLayerCase(category, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::MISSING) {
632  count++;
633  }
634  }
635  return count;
636 }
637 
639 {
640  int count = 0;
641  uint16_t NPixForward = 3;
642  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
643  if (getTrackerLayerCase(category, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::MISSING) {
644  count++;
645  }
646  }
647  return count;
648 }
649 
651 {
652  int count = 0;
653  for (uint16_t layer = 1; layer <= 4; layer++) {
654  if (getTrackerLayerCase(category, StripSubdetector::TIB, layer) == HIT_TYPE::MISSING) {
655  count++;
656  }
657  }
658  return count;
659 }
660 
662 {
663  int count = 0;
664  for (uint16_t layer = 1; layer <= 3; layer++) {
665  if (getTrackerLayerCase(category, StripSubdetector::TID, layer) == HIT_TYPE::MISSING) {
666  count++;
667  }
668  }
669  return count;
670 }
671 
673 {
674  int count = 0;
675  for (uint16_t layer = 1; layer <= 6; layer++) {
676  if (getTrackerLayerCase(category, StripSubdetector::TOB, layer) == HIT_TYPE::MISSING) {
677  count++;
678  }
679  }
680  return count;
681 }
682 
684 {
685  int count = 0;
686  for (uint16_t layer = 1; layer <= 9; layer++) {
687  if (getTrackerLayerCase(category, StripSubdetector::TEC, layer) == HIT_TYPE::MISSING) {
688  count++;
689  }
690  }
691  return count;
692 }
693 
694 
696 {
697  int count = 0;
698  uint16_t NPixBarrel = 4;
699  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
700  if (getTrackerLayerCase(category, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::INACTIVE) {
701  count++;
702  }
703  }
704  return count;
705 }
706 
708 {
709  int count = 0;
710  uint16_t NPixForward = 3;
711  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
712  if (getTrackerLayerCase(category, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::INACTIVE) {
713  count++;
714  }
715  }
716  return count;
717 }
718 
720 {
721  int count = 0;
722  for (uint16_t layer = 1; layer <= 4; layer++) {
723  if (getTrackerLayerCase(category, StripSubdetector::TIB, layer) == HIT_TYPE::INACTIVE) {
724  count++;
725  }
726  }
727  return count;
728 }
729 
731 {
732  int count = 0;
733  for (uint16_t layer = 1; layer <= 3; layer++) {
734  if (getTrackerLayerCase(category, StripSubdetector::TID, layer) == HIT_TYPE::INACTIVE) {
735  count++;
736  }
737  }
738  return count;
739 }
740 
742 {
743  int count = 0;
744  for (uint16_t layer = 1; layer <= 6; layer++) {
745 
746  if (getTrackerLayerCase(category, StripSubdetector::TOB, layer) == HIT_TYPE::INACTIVE) {
747  count++;
748  }
749  }
750  return count;
751 }
752 
754 {
755  int count = 0;
756  for (uint16_t layer = 1; layer <= 9; layer++) {
757  if (getTrackerLayerCase(category, StripSubdetector::TEC, layer) == HIT_TYPE::INACTIVE) {
758  count++;
759  }
760  }
761  return count;
762 }
763 
765 {
766  int count = 0;
767  uint16_t NPixBarrel = 4;
768  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
770  count++;
771  }
772  }
773  return count;
774 }
775 
777 {
778  int count = 0;
779  uint16_t NPixForward = 3;
780  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
782  count++;
783  }
784  }
785  return count;
786 }
787 
789 {
790  int count = 0;
791  for (uint16_t layer = 1; layer <= 4; layer++) {
793  count++;
794  }
795  }
796  return count;
797 }
798 
800 {
801  int count = 0;
802  for (uint16_t layer = 1; layer <= 3; layer++) {
804  count++;
805  }
806  }
807  return count;
808 }
809 
811 {
812  int count = 0;
813  for (uint16_t layer = 1; layer <= 6; layer++) {
815  count++;
816  }
817  }
818  return count;
819 }
820 
822 {
823  int count = 0;
824  for (uint16_t layer = 1; layer <= 9; layer++) {
826  count++;
827  }
828  }
829  return count;
830 }
831 
832 void HitPattern::printHitPattern(HitCategory category, int position, std::ostream &stream) const
833 {
834  uint16_t pattern = getHitPattern(category, position);
835  stream << "\t";
836  if (muonHitFilter(pattern)) {
837  stream << "muon";
838  } else if (trackerHitFilter(pattern)) {
839  stream << "tracker";
840  }
841 
842  stream << "\tsubstructure " << getSubStructure(pattern);
843  if (muonHitFilter(pattern)) {
844  stream << "\tstation " << getMuonStation(pattern);
845  if (muonDTHitFilter(pattern)) {
846  stream << "\tdt superlayer " << getDTSuperLayer(pattern);
847  } else if (muonCSCHitFilter(pattern)) {
848  stream << "\tcsc ring " << getCSCRing(pattern);
849  } else if (muonRPCHitFilter(pattern)) {
850  stream << "\trpc " << (getRPCregion(pattern) ? "endcaps" : "barrel")
851  << ", layer " << getRPCLayer(pattern);
852  } else if (muonGEMHitFilter(pattern)) {
853  stream << "\tgem " << (getGEMLayer(pattern) ? "layer1" : "layer2")
854  << ", station " << getGEMStation(pattern);
855  } else if (muonME0HitFilter(pattern)) {
856  stream << "\tme0 ";
857  } else {
858  stream << "(UNKNOWN Muon SubStructure!) \tsubsubstructure "
859  << getSubStructure(pattern);
860  }
861  } else {
862  stream << "\tlayer " << getLayer(pattern);
863  }
864  stream << "\thit type " << getHitType(pattern);
865  stream << std::endl;
866 }
867 
868 void HitPattern::print(HitCategory category, std::ostream &stream) const
869 {
870  stream << "HitPattern" << std::endl;
871  for (int i = 0; i < numberOfAllHits(category); ++i) {
872  printHitPattern(category, i, stream);
873  }
874  std::ios_base::fmtflags flags = stream.flags();
875  stream.setf(std::ios_base::hex, std::ios_base::basefield);
876  stream.setf(std::ios_base::showbase);
877 
878  for (int i = 0; i < this->numberOfAllHits(category); ++i) {
879  stream << getHitPattern(category, i) << std::endl;
880  }
881 
882  stream.flags(flags);
883 }
884 
886 {
887  if (i.det() != DetId::Tracker) {
888  return 0;
889  }
890 
891  switch (i.subdetId()) {
894  return 0;
896  return ttopo.tibIsStereo(i);
898  return ttopo.tidIsStereo(i);
900  return ttopo.tobIsStereo(i);
902  return ttopo.tecIsStereo(i);
903  default:
904  return 0;
905  }
906 }
907 
908 int HitPattern::muonStations(int subdet, int hitType) const
909 {
910  int stations[4] = {0, 0, 0, 0};
911  for (int i = beginTrackHits; i < endTrackHits; ++i) {
913  if (muonHitFilter(pattern)
914  && (subdet == 0 || int(getSubStructure(pattern)) == subdet)
915  && (hitType == -1 || int(getHitType(pattern)) == hitType)) {
916  stations[getMuonStation(pattern) - 1] = 1;
917  }
918  }
919 
920  return stations[0] + stations[1] + stations[2] + stations[3];
921 }
922 
924 {
925  int ret = 0;
926  for (int i = beginTrackHits; i < endTrackHits; ++i) {
928  if (muonHitFilter(pattern)
929  && (hitType == -1 || int(getHitType(pattern)) == hitType)) {
930  int stat = getMuonStation(pattern);
931  if (ret == 0 || stat < ret) {
932  ret = stat;
933  }
934  }
935  }
936 
937  return ret;
938 }
939 
941 {
942  int ret = 0;
943  for (int i = beginTrackHits; i < endTrackHits; ++i) {
945  if (muonHitFilter(pattern) &&
946  (hitType == -1 || int(getHitType(pattern)) == hitType)) {
947  int stat = getMuonStation(pattern);
948  if (ret == 0 || stat > ret) {
949  ret = stat;
950  }
951  }
952  }
953  return ret;
954 }
955 
957 {
958  int stations[4] = {0, 0, 0, 0};
959  for (int i = beginTrackHits; i < endTrackHits; ++i) {
961 
962  if (muonDTHitFilter(pattern) && validHitFilter(pattern)
963  && getDTSuperLayer(pattern) != 2) {
964  stations[getMuonStation(pattern) - 1] = 1;
965  }
966  }
967  return stations[0] + stations[1] + stations[2] + stations[3];
968 }
969 
971 {
972  int stations[4] = {0, 0, 0, 0};
973  for (int i = beginTrackHits; i < endTrackHits; ++i) {
975  if (muonDTHitFilter(pattern) && validHitFilter(pattern)
976  && getDTSuperLayer(pattern) == 2) {
977  stations[getMuonStation(pattern) - 1] = 1;
978  }
979  }
980  return stations[0] + stations[1] + stations[2] + stations[3];
981 }
982 
984 {
985  int stations[4][2] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
986  for (int i = beginTrackHits; i < endTrackHits; ++i) {
988  if (muonDTHitFilter(pattern) && validHitFilter(pattern)) {
989  stations[getMuonStation(pattern) - 1][getDTSuperLayer(pattern) == 2] = 1;
990  }
991  }
992 
993  return stations[0][0] * stations[0][1]
994  + stations[1][0] * stations[1][1]
995  + stations[2][0] * stations[2][1]
996  + stations[3][0] * stations[3][1];
997 }
998 
999 void HitPattern::insertHit(const uint16_t pattern)
1000 {
1001  int offset = hitCount * HIT_LENGTH;
1002  for (int i = 0; i < HIT_LENGTH; i++) {
1003  int pos = offset + i;
1004  uint16_t bit = (pattern >> i) & 0x1;
1005  //equivalent to hitPattern[pos / 16] += bit << ((offset + i) % 16);
1006  hitPattern[pos >> 4] += bit << ((offset + i) & (16 - 1));
1007  }
1008  hitCount++;
1009 }
1010 
1012 {
1013  // if begin is 0, this is the first hit of this type being inserted, so
1014  // we need to update begin so it points to the correct index, the first
1015  // empty index.
1016  // unlikely, because it will happen only when inserting
1017  // the first hit of this type
1018  if unlikely((0 == beginTrackHits && 0 == endTrackHits)) {
1020  // before the first hit of this type is inserted, there are no hits
1022  }
1023 
1024  insertHit(pattern);
1025  endTrackHits++;
1026 
1027  return true;
1028 }
1029 
1031 {
1032  if unlikely((0 == beginInner && 0 == endInner)) {
1033  beginInner = hitCount;
1034  endInner = beginInner;
1035  }
1036 
1037  insertHit(pattern);
1038  endInner++;
1039 
1040  return true;
1041 }
1042 
1044 {
1045  if unlikely((0 == beginOuter && 0 == endOuter)) {
1046  beginOuter = hitCount;
1047  endOuter = beginOuter;
1048  }
1049 
1050  insertHit(pattern);
1051  endOuter++;
1052 
1053  return true;
1054 }
1055 
int stripTOBLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:741
int stripTOBLayersWithMeasurement() const
Definition: HitPattern.cc:604
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:626
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:700
void insertHit(const uint16_t pattern)
Definition: HitPattern.cc:999
int outermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:940
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:764
static bool pixelHitFilter(uint16_t pattern)
Definition: HitPattern.h:564
int stripTIBLayersNull() const
Definition: HitPattern.cc:788
int pixelBarrelLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:695
bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const
Definition: HitPattern.cc:327
static uint16_t isStereo(DetId i, const TrackerTopology &ttopo)
Definition: HitPattern.cc:885
bool tobIsStereo(const DetId &id) const
int stripTIBLayersWithMeasurement() const
Definition: HitPattern.cc:582
int stripTECLayersNull() const
Definition: HitPattern.cc:821
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:908
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:672
int numberOfDTStationsWithRPhiView() const
Definition: HitPattern.cc:956
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:460
static const unsigned short MaxHits
Definition: HitPattern.h:168
uint32_t getTrackerLayerCase(HitCategory category, uint16_t substr, uint16_t layer) const
Definition: HitPattern.cc:428
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:499
int numberOfValidStripLayersWithMonoAndStereo() const
Definition: HitPattern.cc:388
int pixelEndcapLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:638
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:518
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:570
bool insertExpectedOuterHit(const uint16_t pattern)
Definition: HitPattern.cc:1043
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:832
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
static const unsigned short minTrackerWord
Definition: HitPattern.h:441
uint16_t hitPattern[ARRAY_LENGTH]
Definition: HitPattern.h:472
int stripTIBLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:719
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:423
int stripTIDLayersWithMeasurement() const
Definition: HitPattern.cc:593
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 numberOfAllHits(HitCategory category) const
Definition: HitPattern.h:807
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:187
int numberOfDTStationsWithRZView() const
Definition: HitPattern.cc:970
uint8_t beginInner
Definition: HitPattern.h:477
int stripTIDLayersNull() const
Definition: HitPattern.cc:799
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:38
int numberOfValidTIDLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:418
bool appendTrackerHit(uint16_t subdet, uint16_t layer, uint16_t stereo, TrackingRecHit::Type hitType)
Definition: HitPattern.cc:265
uint8_t beginTrackHits
Definition: HitPattern.h:475
static uint32_t getSubStructure(uint16_t pattern)
Definition: HitPattern.h:691
int numberOfDTStationsWithBothViews() const
Definition: HitPattern.cc:983
int numberOfValidTIBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:413
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:661
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:923
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:558
int roll() const
Definition: ME0DetId.h:62
unsigned int layer(const DetId &id) const
uint16_t getHitPatternByAbsoluteIndex(int position) const
Definition: HitPattern.cc:284
static uint32_t getSide(uint16_t pattern)
Definition: HitPattern.h:724
int stripTOBLayersNull() const
Definition: HitPattern.cc:810
static bool muonDTHitFilter(uint16_t pattern)
Definition: HitPattern.h:630
int stripTIDLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:730
int trackerLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:535
bool insertExpectedInnerHit(const uint16_t pattern)
Definition: HitPattern.cc:1030
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
int pixelEndcapLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:707
bool insertTrackHit(const uint16_t pattern)
Definition: HitPattern.cc:1011
int stripTECLayersWithMeasurement() const
Definition: HitPattern.cc:615
int stripTECLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:683
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:868
int numberOfValidTOBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:408
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
static const unsigned short LayerMask
Definition: HitPattern.h:431
Detector det() const
get the detector field from this detid
Definition: DetId.h:36
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 stripTECLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const
Definition: HitPattern.cc:753
int stripTIBLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:650
bool appendMuonHit(const DetId &id, TrackingRecHit::Type hitType)
Definition: HitPattern.cc:269
int pixelEndcapLayersNull() const
Definition: HitPattern.cc:776
int region() const
Region id: 0 for Barrel, +/-1 For +/- Endcap.
Definition: RPCDetId.h:63
int station() const
Definition: RPCDetId.h:96