CMS 3D CMS Logo

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