CMS 3D CMS Logo

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