test
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.
14 
16 
17 
18 #include<bitset>
19 
20 using namespace reco;
21 
23  hitCount(0),
24  beginTrackHits(0),
25  endTrackHits(0),
26  beginInner(0),
27  endInner(0),
28  beginOuter(0),
29  endOuter(0)
30 {
32 }
33 
35  hitCount(other.hitCount),
36  beginTrackHits(other.beginTrackHits),
37  endTrackHits(other.endTrackHits),
38  beginInner(other.beginInner),
39  endInner(other.endInner),
40  beginOuter(other.beginOuter),
41  endOuter(other.endOuter)
42 {
43  memcpy(this->hitPattern, other.hitPattern, sizeof(uint16_t) * HitPattern::ARRAY_LENGTH);
44 }
45 
47 {
48  ;
49 }
50 
52 {
53  if (this == &other) {
54  return *this;
55  }
56 
57  this->hitCount = other.hitCount;
58 
59  this->beginTrackHits = other.beginTrackHits;
60  this->endTrackHits = other.endTrackHits;
61 
62  this->beginInner = other.beginInner;
63  this->endInner = other.endInner;
64 
65  this->beginOuter = other.beginOuter;
66  this->endOuter = other.endOuter;
67 
68  memcpy(this->hitPattern, other.hitPattern, sizeof(uint16_t) * HitPattern::ARRAY_LENGTH);
69 
70  return *this;
71 }
72 
74 {
75  this->hitCount = 0;
76  this->beginTrackHits = 0;
77  this->endTrackHits = 0;
78  this->beginInner = 0;
79  this->endInner = 0;
80  this->beginOuter = 0;
81  this->endOuter = 0;
82 
83  memset(this->hitPattern, EMPTY_PATTERN, sizeof(uint16_t) * HitPattern::ARRAY_LENGTH);
84 }
85 
87 {
88  return appendHit(*ref, ttopo);
89 }
90 
91 uint16_t HitPattern::encode(const TrackingRecHit &hit, const TrackerTopology& ttopo)
92 {
93  return encode(hit.geographicalId(), hit.getType(), ttopo);
94 }
95 
96 namespace {
97  uint16_t encodeMuonLayer(const DetId& id) {
98  uint16_t detid = id.det();
99  uint16_t subdet = id.subdetId();
100 
101  uint16_t layer = 0x0;
102  if (detid == DetId::Muon) {
103  switch (subdet) {
104  case MuonSubdetId::DT:
105  layer = ((DTLayerId(id.rawId()).station() - 1) << 2);
106  layer |= DTLayerId(id.rawId()).superLayer();
107  break;
108  case MuonSubdetId::CSC:
109  layer = ((CSCDetId(id.rawId()).station() - 1) << 2);
110  layer |= (CSCDetId(id.rawId()).ring() - 1);
111  break;
112  case MuonSubdetId::RPC:
113  {
114  RPCDetId rpcid(id.rawId());
115  layer = ((rpcid.station() - 1) << 2);
116  layer |= (rpcid.station() <= 2) ? ((rpcid.layer() - 1) << 1) : 0x0;
117  layer |= abs(rpcid.region());
118  }
119  break;
120  case MuonSubdetId::GEM:
121  {
122  GEMDetId gemid(id.rawId());
123  layer = ((gemid.station()-1)<<2);
124  layer |= abs(gemid.layer()-1);
125  }
126  break;
127  case MuonSubdetId::ME0:
128  {
129  ME0DetId me0id(id.rawId());
130  //layer = ((me0id.roll()-1)<<1) + abs(me0id.layer()-1);
131  //layer = ((me0id.roll()-1)<<1) + abs(me0id.layer());
132  //Only layer information that is meaningful is in the roll/etapartition
133  layer = (me0id.roll());
134  }
135  break;
136  }
137  }
138  return layer;
139  }
140 }
141 
142 uint16_t HitPattern::encode(const DetId &id, TrackingRecHit::Type hitType, const TrackerTopology& ttopo)
143 {
144  uint16_t detid = id.det();
145  uint16_t subdet = id.subdetId();
146 
147  // adding layer/disk/wheel bits
148  uint16_t layer = 0x0;
149  if (detid == DetId::Tracker) {
150  layer = ttopo.layer(id);
151  } else if (detid == DetId::Muon) {
152  layer = encodeMuonLayer(id);
153  }
154 
155  // adding mono/stereo bit
156  uint16_t side = 0x0;
157  if (detid == DetId::Tracker) {
158  side = isStereo(id, ttopo);
159  } else if (detid == DetId::Muon) {
160  side = 0x0;
161  }
162 
163  return encode(detid, subdet, layer, side, hitType);
164 }
165 
166 uint16_t HitPattern::encode(uint16_t det, uint16_t subdet, uint16_t layer, uint16_t side, TrackingRecHit::Type hitType) {
168 
169  // adding tracker/muon detector bit
170  pattern |= (det & SubDetectorMask) << SubDetectorOffset;
171 
172  // adding substructure (PXB, PXF, TIB, TID, TOB, TEC, or DT, CSC, RPC,GEM) bits
173  pattern |= (subdet & SubstrMask) << SubstrOffset;
174 
175  // adding layer/disk/wheel bits
176  pattern |= (layer & LayerMask) << LayerOffset;
177 
178  // adding mono/stereo bit
179  pattern |= (side & SideMask) << SideOffset;
180 
181  TrackingRecHit::Type patternHitType = (hitType == TrackingRecHit::missing_inner ||
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;
235  if unlikely(((hitCount != endInner) && (0 != beginInner || 0 != endInner))) {
236  cms::Exception("HitPattern")
237  << "MISSING_INNER_HITS"
238  << " were stored on this object before hits of some other category were inserted "
239  << "but hits of the same category should be inserted in a row. "
240  << "Please rework the code so it inserts all "
241  << "MISSING_INNER_HITS"
242  << " in a row.";
243  return false;
244  }
245  return insertExpectedInnerHit(pattern);
246  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 
327 {
328  for (int i = beginTrackHits; i < endTrackHits; ++i) {
330  if (pixelBarrelHitFilter(pattern) && (getLayer(pattern) == 1)
331  && validHitFilter(pattern)) {
332  return true;
333  }
334  }
335  return false;
336 }
337 
339 {
340  for (int i = beginTrackHits; i < endTrackHits; ++i) {
342  if (pixelEndcapHitFilter(pattern) && (getLayer(pattern) == 1)
343  && validHitFilter(pattern)) {
344  return true;
345  }
346  }
347  return false;
348 }
349 
350 int HitPattern::numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const
351 {
352  bool hasMono[SubstrMask + 1][LayerMask + 1];
353  bool hasStereo[SubstrMask + 1][LayerMask + 1];
354  memset(hasMono, 0, sizeof(hasMono));
355  memset(hasStereo, 0, sizeof(hasStereo));
356 
357  // mark which layers have mono/stereo hits
358  for (int i = beginTrackHits; i < endTrackHits; ++i) {
360  uint16_t subStructure = getSubStructure(pattern);
361 
362  if (validHitFilter(pattern) && stripHitFilter(pattern)) {
363  if (stripdet != 0 && subStructure != stripdet) {
364  continue;
365  }
366 
367  if (layer != 0 && getSubSubStructure(pattern) != layer) {
368  continue;
369  }
370 
371  switch (getSide(pattern)) {
372  case 0: // mono
373  hasMono[subStructure][getLayer(pattern)] = true;
374  break;
375  case 1: // stereo
376  hasStereo[subStructure][getLayer(pattern)] = true;
377  break;
378  default:
379  ;
380  break;
381  }
382  }
383  }
384 
385  // count how many layers have mono and stereo hits
386  int count = 0;
387  for (int i = 0; i < SubstrMask + 1; ++i) {
388  for (int j = 0; j < LayerMask + 1; ++j) {
389  if (hasMono[i][j] && hasStereo[i][j]) {
390  count++;
391  }
392  }
393  }
394  return count;
395 }
396 
398 {
399  auto category = TRACK_HITS;
400  std::bitset<128> side[2];
401  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
402  for (int i = range.first; i < range.second; ++i) {
404  if (pattern<minStripWord) continue;
405  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
406  if (hitType != HIT_TYPE::VALID) continue;
407  auto apattern = (pattern-minTrackerWord) >> LayerOffset;
408  // assert(apattern<128);
409  side[getSide(pattern)].set(apattern);
410  }
411  // assert(numberOfValidStripLayersWithMonoAndStereo(0, 0)==int((side[0]&side[1]).count()));
412  return (side[0]&side[1]).count();
413 
414 
415 }
416 
418 {
420 }
421 
423 {
425 }
426 
428 {
430 }
431 
433 {
435 }
436 
437 uint32_t HitPattern::getTrackerLayerCase(HitCategory category, uint16_t substr, uint16_t layer) const
438 {
439  uint16_t tk_substr_layer = (0x1 << SubDetectorOffset)
440  + ((substr & SubstrMask) << SubstrOffset)
441  + ((layer & LayerMask) << LayerOffset);
442 
443  uint16_t mask = (SubDetectorMask << SubDetectorOffset)
444  + (SubstrMask << SubstrOffset)
445  + (LayerMask << LayerOffset);
446 
447  // layer case 0: valid + (missing, off, bad) ==> with measurement
448  // layer case 1: missing + (off, bad) ==> without measurement
449  // layer case 2: off, bad ==> totally off or bad, cannot say much
450  // layer case NULL_RETURN: track outside acceptance or in gap ==> null
451  uint32_t layerCase = NULL_RETURN;
452  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
453  for (int i = range.first; i < range.second; ++i) {
455  if ((pattern & mask) == tk_substr_layer) {
456  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
457  if (hitType < layerCase) {
458  // BAD and INACTIVE as the same type (as INACTIVE)
459  layerCase = (hitType == HIT_TYPE::BAD ? HIT_TYPE::INACTIVE : hitType);
460  if (layerCase == HIT_TYPE::VALID) {
461  break;
462  }
463  }
464  }
465  }
466  return layerCase;
467 }
468 
469 uint16_t HitPattern::getTrackerMonoStereo(HitCategory category, uint16_t substr, uint16_t layer) const
470 {
471  uint16_t tk_substr_layer = (0x1 << SubDetectorOffset)
472  + ((substr & SubstrMask) << SubstrOffset)
473  + ((layer & LayerMask) << LayerOffset);
474  uint16_t mask = (SubDetectorMask << SubDetectorOffset)
475  + (SubstrMask << SubstrOffset)
476  + (LayerMask << LayerOffset);
477 
478  // 0: neither a valid mono nor a valid stereo hit
479  // MONO: valid mono hit
480  // STEREO: valid stereo hit
481  // MONO | STEREO: both
482  uint16_t monoStereo = 0x0;
483  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
484  for (int i = range.first; i < range.second; ++i) {
486  if ((pattern & mask) == tk_substr_layer) {
487  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
488  if (hitType == HIT_TYPE::VALID) {
489  switch (getSide(pattern)) {
490  case 0: // mono
491  monoStereo |= MONO;
492  break;
493  case 1: // stereo
494  monoStereo |= STEREO;
495  break;
496  }
497  }
498 
499  if (monoStereo == (MONO | STEREO)) {
500  break;
501  }
502  }
503  }
504  return monoStereo;
505 }
506 
507 
509  auto category = TRACK_HITS;
510  std::bitset<128> layerOk;
511  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
512  for (int i = range.first; i < range.second; ++i) {
514  if unlikely(!trackerHitFilter(pattern)) continue;
515  if (pattern>minStripWord) continue;
516  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
517  if (hitType != HIT_TYPE::VALID) continue;
519  // assert(pattern<128);
520  layerOk.set(pattern);
521  }
522  // assert(pixelLayersWithMeasurementOld()==int(layerOk.count()));
523  return layerOk.count();
524 }
525 
526 
528  auto category = TRACK_HITS;
529  std::bitset<128> layerOk;
530  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
531  for (int i = range.first; i < range.second; ++i) {
533  if unlikely(!trackerHitFilter(pattern)) continue;
534  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
535  if (hitType != HIT_TYPE::VALID) continue;
537  // assert(pattern<128);
538  layerOk.set(pattern);
539  }
540  // assert(trackerLayersWithMeasurementOld()==int(layerOk.count()));
541  return layerOk.count();
542 }
543 
545  std::bitset<128> layerOk;
546  std::bitset<128> layerMissed;
547  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
548  for (int i = range.first; i < range.second; ++i) {
550  if unlikely(!trackerHitFilter(pattern)) continue;
551  uint16_t hitType = (pattern >> HitTypeOffset) & HitTypeMask;
553  // assert(pattern<128);
554  if (hitType == HIT_TYPE::VALID) layerOk.set(pattern);
555  if (hitType == HIT_TYPE::MISSING) layerMissed.set(pattern);
556  }
557  layerMissed &= ~layerOk;
558 
559  // assert(trackerLayersWithoutMeasurementOld(category)==int(layerMissed.count()));
560 
561  return layerMissed.count();
562 
563 
564 }
565 
566 
568 {
569  int count = 0;
570  uint16_t NPixBarrel = 4;
571  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
572  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::VALID) {
573  count++;
574  }
575  }
576  return count;
577 }
578 
580 {
581  int count = 0;
582  uint16_t NPixForward = 3;
583  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
584  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::VALID) {
585  count++;
586  }
587  }
588  return count;
589 }
590 
592 {
593  int count = 0;
594  for (uint16_t layer = 1; layer <= 4; layer++) {
595  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TIB, layer) == HIT_TYPE::VALID) {
596  count++;
597  }
598  }
599  return count;
600 }
601 
603 {
604  int count = 0;
605  for (uint16_t layer = 1; layer <= 3; layer++) {
606  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TID, layer) == HIT_TYPE::VALID) {
607  count++;
608  }
609  }
610  return count;
611 }
612 
614 {
615  int count = 0;
616  for (uint16_t layer = 1; layer <= 6; layer++) {
617  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TOB, layer) == HIT_TYPE::VALID) {
618  count++;
619  }
620  }
621  return count;
622 }
623 
625 {
626  int count = 0;
627  for (uint16_t layer = 1; layer <= 9; layer++) {
628  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TEC, layer) == HIT_TYPE::VALID) {
629  count++;
630  }
631  }
632  return count;
633 }
634 
636 {
637  int count = 0;
638  uint16_t NPixBarrel = 4;
639  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
640  if (getTrackerLayerCase(category, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::MISSING) {
641  count++;
642  }
643  }
644  return count;
645 }
646 
648 {
649  int count = 0;
650  uint16_t NPixForward = 3;
651  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
652  if (getTrackerLayerCase(category, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::MISSING) {
653  count++;
654  }
655  }
656  return count;
657 }
658 
660 {
661  int count = 0;
662  for (uint16_t layer = 1; layer <= 4; layer++) {
663  if (getTrackerLayerCase(category, StripSubdetector::TIB, layer) == HIT_TYPE::MISSING) {
664  count++;
665  }
666  }
667  return count;
668 }
669 
671 {
672  int count = 0;
673  for (uint16_t layer = 1; layer <= 3; layer++) {
674  if (getTrackerLayerCase(category, StripSubdetector::TID, layer) == HIT_TYPE::MISSING) {
675  count++;
676  }
677  }
678  return count;
679 }
680 
682 {
683  int count = 0;
684  for (uint16_t layer = 1; layer <= 6; layer++) {
685  if (getTrackerLayerCase(category, StripSubdetector::TOB, layer) == HIT_TYPE::MISSING) {
686  count++;
687  }
688  }
689  return count;
690 }
691 
693 {
694  int count = 0;
695  for (uint16_t layer = 1; layer <= 9; layer++) {
696  if (getTrackerLayerCase(category, StripSubdetector::TEC, layer) == HIT_TYPE::MISSING) {
697  count++;
698  }
699  }
700  return count;
701 }
702 
703 
705 {
706  int count = 0;
707  uint16_t NPixBarrel = 4;
708  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
709  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelBarrel, layer) == HIT_TYPE::INACTIVE) {
710  count++;
711  }
712  }
713  return count;
714 }
715 
717 {
718  int count = 0;
719  uint16_t NPixForward = 3;
720  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
721  if (getTrackerLayerCase(TRACK_HITS, PixelSubdetector::PixelEndcap, layer) == HIT_TYPE::INACTIVE) {
722  count++;
723  }
724  }
725  return count;
726 }
727 
729 {
730  int count = 0;
731  for (uint16_t layer = 1; layer <= 4; layer++) {
732  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TIB, layer) == HIT_TYPE::INACTIVE) {
733  count++;
734  }
735  }
736  return count;
737 }
738 
740 {
741  int count = 0;
742  for (uint16_t layer = 1; layer <= 3; layer++) {
743  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TID, layer) == HIT_TYPE::INACTIVE) {
744  count++;
745  }
746  }
747  return count;
748 }
749 
751 {
752  int count = 0;
753  for (uint16_t layer = 1; layer <= 6; layer++) {
754 
755  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TOB, layer) == HIT_TYPE::INACTIVE) {
756  count++;
757  }
758  }
759  return count;
760 }
761 
763 {
764  int count = 0;
765  for (uint16_t layer = 1; layer <= 9; layer++) {
766  if (getTrackerLayerCase(TRACK_HITS, StripSubdetector::TEC, layer) == HIT_TYPE::INACTIVE) {
767  count++;
768  }
769  }
770  return count;
771 }
772 
774 {
775  int count = 0;
776  uint16_t NPixBarrel = 4;
777  for (uint16_t layer = 1; layer <= NPixBarrel; layer++) {
779  count++;
780  }
781  }
782  return count;
783 }
784 
786 {
787  int count = 0;
788  uint16_t NPixForward = 3;
789  for (uint16_t layer = 1; layer <= NPixForward; layer++) {
791  count++;
792  }
793  }
794  return count;
795 }
796 
798 {
799  int count = 0;
800  for (uint16_t layer = 1; layer <= 4; layer++) {
802  count++;
803  }
804  }
805  return count;
806 }
807 
809 {
810  int count = 0;
811  for (uint16_t layer = 1; layer <= 3; layer++) {
813  count++;
814  }
815  }
816  return count;
817 }
818 
820 {
821  int count = 0;
822  for (uint16_t layer = 1; layer <= 6; layer++) {
824  count++;
825  }
826  }
827  return count;
828 }
829 
831 {
832  int count = 0;
833  for (uint16_t layer = 1; layer <= 9; layer++) {
835  count++;
836  }
837  }
838  return count;
839 }
840 
841 void HitPattern::printHitPattern(HitCategory category, int position, std::ostream &stream) const
842 {
843  uint16_t pattern = getHitPattern(category, position);
844  stream << "\t";
845  if (muonHitFilter(pattern)) {
846  stream << "muon";
847  } else if (trackerHitFilter(pattern)) {
848  stream << "tracker";
849  }
850 
851  stream << "\tsubstructure " << getSubStructure(pattern);
852  if (muonHitFilter(pattern)) {
853  stream << "\tstation " << getMuonStation(pattern);
854  if (muonDTHitFilter(pattern)) {
855  stream << "\tdt superlayer " << getDTSuperLayer(pattern);
856  } else if (muonCSCHitFilter(pattern)) {
857  stream << "\tcsc ring " << getCSCRing(pattern);
858  } else if (muonRPCHitFilter(pattern)) {
859  stream << "\trpc " << (getRPCregion(pattern) ? "endcaps" : "barrel")
860  << ", layer " << getRPCLayer(pattern);
861  } else if (muonGEMHitFilter(pattern)) {
862  stream << "\tgem " << (getGEMLayer(pattern) ? "layer1" : "layer2")
863  << ", station " << getGEMStation(pattern);
864  } else if (muonME0HitFilter(pattern)) {
865  stream << "\tme0 ";
866  } else {
867  stream << "(UNKNOWN Muon SubStructure!) \tsubsubstructure "
868  << getSubStructure(pattern);
869  }
870  } else {
871  stream << "\tlayer " << getLayer(pattern);
872  }
873  stream << "\thit type " << getHitType(pattern);
874  stream << std::endl;
875 }
876 
877 void HitPattern::print(HitCategory category, std::ostream &stream) const
878 {
879  stream << "HitPattern" << std::endl;
880  for (int i = 0; i < numberOfHits(category); ++i) {
881  printHitPattern(category, i, stream);
882  }
883  std::ios_base::fmtflags flags = stream.flags();
884  stream.setf(std::ios_base::hex, std::ios_base::basefield);
885  stream.setf(std::ios_base::showbase);
886 
887  for (int i = 0; i < this->numberOfHits(category); ++i) {
888  stream << getHitPattern(category, i) << std::endl;
889  }
890 
891  stream.flags(flags);
892 }
893 
895 {
896  if (i.det() != DetId::Tracker) {
897  return 0;
898  }
899 
900  switch (i.subdetId()) {
903  return 0;
905  return ttopo.tibIsStereo(i);
907  return ttopo.tidIsStereo(i);
909  return ttopo.tobIsStereo(i);
911  return ttopo.tecIsStereo(i);
912  default:
913  return 0;
914  }
915 }
916 
917 int HitPattern::muonStations(int subdet, int hitType) const
918 {
919  int stations[4] = {0, 0, 0, 0};
920  for (int i = beginTrackHits; i < endTrackHits; ++i) {
922  if (muonHitFilter(pattern)
923  && (subdet == 0 || int(getSubStructure(pattern)) == subdet)
924  && (hitType == -1 || int(getHitType(pattern)) == hitType)) {
925  stations[getMuonStation(pattern) - 1] = 1;
926  }
927  }
928 
929  return stations[0] + stations[1] + stations[2] + stations[3];
930 }
931 
933 {
934  int ret = 0;
935  for (int i = beginTrackHits; i < endTrackHits; ++i) {
937  if (muonHitFilter(pattern)
938  && (hitType == -1 || int(getHitType(pattern)) == hitType)) {
939  int stat = getMuonStation(pattern);
940  if (ret == 0 || stat < ret) {
941  ret = stat;
942  }
943  }
944  }
945 
946  return ret;
947 }
948 
950 {
951  int ret = 0;
952  for (int i = beginTrackHits; i < endTrackHits; ++i) {
954  if (muonHitFilter(pattern) &&
955  (hitType == -1 || int(getHitType(pattern)) == hitType)) {
956  int stat = getMuonStation(pattern);
957  if (ret == 0 || stat > ret) {
958  ret = stat;
959  }
960  }
961  }
962  return ret;
963 }
964 
966 {
967  int stations[4] = {0, 0, 0, 0};
968  for (int i = beginTrackHits; i < endTrackHits; ++i) {
970 
971  if (muonDTHitFilter(pattern) && validHitFilter(pattern)
972  && getDTSuperLayer(pattern) != 2) {
973  stations[getMuonStation(pattern) - 1] = 1;
974  }
975  }
976  return stations[0] + stations[1] + stations[2] + stations[3];
977 }
978 
980 {
981  int stations[4] = {0, 0, 0, 0};
982  for (int i = beginTrackHits; i < endTrackHits; ++i) {
984  if (muonDTHitFilter(pattern) && validHitFilter(pattern)
985  && getDTSuperLayer(pattern) == 2) {
986  stations[getMuonStation(pattern) - 1] = 1;
987  }
988  }
989  return stations[0] + stations[1] + stations[2] + stations[3];
990 }
991 
993 {
994  int stations[4][2] = {{0, 0}, {0, 0}, {0, 0}, {0, 0}};
995  for (int i = beginTrackHits; i < endTrackHits; ++i) {
997  if (muonDTHitFilter(pattern) && validHitFilter(pattern)) {
998  stations[getMuonStation(pattern) - 1][getDTSuperLayer(pattern) == 2] = 1;
999  }
1000  }
1001 
1002  return stations[0][0] * stations[0][1]
1003  + stations[1][0] * stations[1][1]
1004  + stations[2][0] * stations[2][1]
1005  + stations[3][0] * stations[3][1];
1006 }
1007 
1008 void HitPattern::insertHit(const uint16_t pattern)
1009 {
1010  int offset = hitCount * HIT_LENGTH;
1011  for (int i = 0; i < HIT_LENGTH; i++) {
1012  int pos = offset + i;
1013  uint16_t bit = (pattern >> i) & 0x1;
1014  //equivalent to hitPattern[pos / 16] += bit << ((offset + i) % 16);
1015  hitPattern[pos >> 4] += bit << ((offset + i) & (16 - 1));
1016  }
1017  hitCount++;
1018 }
1019 
1021 {
1022  // if begin is 0, this is the first hit of this type being inserted, so
1023  // we need to update begin so it points to the correct index, the first
1024  // empty index.
1025  // unlikely, because it will happen only when inserting
1026  // the first hit of this type
1027  if unlikely((0 == beginTrackHits && 0 == endTrackHits)) {
1029  // before the first hit of this type is inserted, there are no hits
1031  }
1032 
1033  insertHit(pattern);
1034  endTrackHits++;
1035 
1036  return true;
1037 }
1038 
1040 {
1041  if unlikely((0 == beginInner && 0 == endInner)) {
1042  beginInner = hitCount;
1043  endInner = beginInner;
1044  }
1045 
1046  insertHit(pattern);
1047  endInner++;
1048 
1049  return true;
1050 }
1051 
1053 {
1054  if unlikely((0 == beginOuter && 0 == endOuter)) {
1055  beginOuter = hitCount;
1056  endOuter = beginOuter;
1057  }
1058 
1059  insertHit(pattern);
1060  endOuter++;
1061 
1062  return true;
1063 }
1064 
int stripTOBLayersWithMeasurement() const
Definition: HitPattern.cc:613
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:635
int i
Definition: DBlmapReader.cc:9
static uint32_t getLayer(uint16_t pattern)
Definition: HitPattern.h:700
void insertHit(const uint16_t pattern)
Definition: HitPattern.cc:1008
tuple ret
prodAgent to be discontinued
int outermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:949
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:773
int stripTIBLayersNull() const
Definition: HitPattern.cc:797
static uint16_t isStereo(DetId i, const TrackerTopology &ttopo)
Definition: HitPattern.cc:894
bool tobIsStereo(const DetId &id) const
int stripTIBLayersWithMeasurement() const
Definition: HitPattern.cc:591
int stripTECLayersNull() const
Definition: HitPattern.cc:830
static const unsigned short SideOffset
Definition: HitPattern.h:425
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:917
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:747
static bool muonME0HitFilter(uint16_t pattern)
Definition: HitPattern.h:670
static const unsigned short SubstrOffset
Definition: HitPattern.h:433
int stripTOBLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:681
int numberOfDTStationsWithRPhiView() const
Definition: HitPattern.cc:965
static const int GEM
Definition: MuonSubdetId.h:15
HitPattern & operator=(const HitPattern &other)
Definition: HitPattern.cc:51
uint16_t getTrackerMonoStereo(HitCategory category, uint16_t substr, uint16_t layer) const
Definition: HitPattern.cc:469
static const unsigned short MaxHits
Definition: HitPattern.h:168
uint32_t getTrackerLayerCase(HitCategory category, uint16_t substr, uint16_t layer) const
Definition: HitPattern.cc:437
std::vector< Variable::Flags > flags
Definition: MVATrainer.cc:135
int pixelLayersWithMeasurement() const
Definition: HitPattern.cc:508
int numberOfValidStripLayersWithMonoAndStereo() const
Definition: HitPattern.cc:397
int pixelEndcapLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:647
int trackerLayersWithMeasurement() const
Definition: HitPattern.cc:527
static const unsigned short HitTypeMask
Definition: HitPattern.h:422
static bool pixelBarrelHitFilter(uint16_t pattern)
Definition: HitPattern.h:575
int pixelEndcapLayersWithMeasurement() const
Definition: HitPattern.cc:579
bool insertExpectedOuterHit(const uint16_t pattern)
Definition: HitPattern.cc:1052
bool tidIsStereo(const DetId &id) const
static bool pixelEndcapHitFilter(uint16_t pattern)
Definition: HitPattern.h:585
bool hasValidHitInFirstPixelEndcap() const
Definition: HitPattern.cc:338
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:841
bool tecIsStereo(const DetId &id) const
static const int ME0
Definition: MuonSubdetId.h:16
static uint16_t getGEMLayer(uint16_t pattern)
GEM layer: 1,2. Only valid for muon GEM patterns, of course.
Definition: HitPattern.h:782
static const int CSC
Definition: MuonSubdetId.h:13
int stripTOBLayersTotallyOffOrBad() const
Definition: HitPattern.cc:750
static const unsigned short minTrackerWord
Definition: HitPattern.h:440
uint16_t hitPattern[ARRAY_LENGTH]
Definition: HitPattern.h:472
int stripTIDLayersTotallyOffOrBad() const
Definition: HitPattern.cc:739
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:432
int stripTIDLayersWithMeasurement() const
Definition: HitPattern.cc:602
static const unsigned short SubDetectorMask
Definition: HitPattern.h:438
static bool stripHitFilter(uint16_t pattern)
Definition: HitPattern.h:595
int stripTECLayersTotallyOffOrBad() const
Definition: HitPattern.cc:762
Abs< T >::type abs(const T &t)
Definition: Abs.h:22
int j
Definition: DBlmapReader.cc:9
bool appendHit(const TrackingRecHit &hit, const TrackerTopology &ttopo)
Definition: HitPattern.cc:189
int numberOfDTStationsWithRZView() const
Definition: HitPattern.cc:979
uint8_t beginInner
Definition: HitPattern.h:477
int stripTIDLayersNull() const
Definition: HitPattern.cc:808
static const unsigned short HitTypeOffset
Definition: HitPattern.h:421
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:427
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:992
int numberOfValidTIBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:422
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
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:670
Definition: DetId.h:18
int innermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:932
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:426
static const unsigned short minStripWord
Definition: HitPattern.h:442
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:437
bool tibIsStereo(const DetId &id) const
int pixelBarrelLayersWithMeasurement() const
Definition: HitPattern.cc:567
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:819
static bool muonDTHitFilter(uint16_t pattern)
Definition: HitPattern.h:630
int trackerLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:544
bool insertExpectedInnerHit(const uint16_t pattern)
Definition: HitPattern.cc:1039
int pixelBarrelLayersTotallyOffOrBad() const
Definition: HitPattern.cc:704
static const unsigned short SubstrMask
Definition: HitPattern.h:434
static const int RPC
Definition: MuonSubdetId.h:14
static const unsigned short LayerOffset
Definition: HitPattern.h:429
static int position[264][3]
Definition: ReadPGInfo.cc:509
bool insertTrackHit(const uint16_t pattern)
Definition: HitPattern.cc:1020
int stripTECLayersWithMeasurement() const
Definition: HitPattern.cc:624
int stripTECLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:692
int pixelEndcapLayersTotallyOffOrBad() const
Definition: HitPattern.cc:716
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
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:877
int numberOfValidTOBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.cc:417
bool hasValidHitInFirstPixelBarrel() const
Definition: HitPattern.cc:326
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 stripTIBLayersTotallyOffOrBad() const
Definition: HitPattern.cc:728
static const unsigned short LayerMask
Definition: HitPattern.h:430
Detector det() const
get the detector field from this detid
Definition: DetId.h:35
static bool muonRPCHitFilter(uint16_t pattern)
Definition: HitPattern.h:650
uint8_t endOuter
Definition: HitPattern.h:480
static uint16_t encode(const TrackingRecHit &hit, const TrackerTopology &ttopo)
Definition: HitPattern.cc:91
int numberOfHits(HitCategory category) const
Definition: HitPattern.h:807
int stripTIBLayersWithoutMeasurement(HitCategory category) const
Definition: HitPattern.cc:659
bool appendMuonHit(const DetId &id, TrackingRecHit::Type hitType)
Definition: HitPattern.cc:269
int pixelEndcapLayersNull() const
Definition: HitPattern.cc:785