CMS 3D CMS Logo

HitPattern.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 
3 #ifndef TrackReco_HitPattern_h
4 #define TrackReco_HitPattern_h
5 
6 //
7 // File: DataFormats/TrackReco/interface/HitPattern.h
8 //
9 // Marcel Vos, INFN Pisa
10 // v1.10 2007/05/08 bellan
11 // Zongru Wan, Kansas State University
12 // Jean-Roch Vlimant
13 // Kevin Burkett
14 // Boris Mangano
15 //
16 // Hit pattern is the summary information of the hits associated to track in
17 // AOD. When RecHits are no longer available, the compact hit pattern should
18 // allow basic track selection based on the hits in various subdetectors.
19 // The hits of a track are saved in unit16_t hitPattern[MaxHits].
20 //
21 // uint16_t
22 // +------------+---------------+---------------------------+-----------------+----------------+
23 // | tk/mu/mtd | sub-structure | sub-sub-structure | stereo | hit type |
24 // +------------+---------------+---------------------------+-----------------+----------------+
25 // | 11-10 | 9 8 7 | 6 5 4 3 | 2 | 1 0 | bit
26 // +------------+---------------+---------------------------+-----------------+----------------|
27 // | tk = 1 | PXB = 1 | layer = 1-3 | | hit type = 0-3 |
28 // | tk = 1 | PXF = 2 | disk = 1-2 | | hit type = 0-3 |
29 // | tk = 1 | TIB = 3 | layer = 1-4 | 0=rphi,1=stereo | hit type = 0-3 |
30 // | tk = 1 | TID = 4 | wheel = 1-3 | 0=rphi,1=stereo | hit type = 0-3 |
31 // | tk = 1 | TOB = 5 | layer = 1-6 | 0=rphi,1=stereo | hit type = 0-3 |
32 // | tk = 1 | TEC = 6 | wheel = 1-9 | 0=rphi,1=stereo | hit type = 0-3 |
33 // | mu = 0 | DT = 1 | 4*(stat-1)+superlayer | | hit type = 0-3 |
34 // | mu = 0 | CSC = 2 | 4*(stat-1)+(ring-1) | | hit type = 0-3 |
35 // | mu = 0 | RPC = 3 | 4*(stat-1)+2*layer+region | | hit type = 0-3 |
36 // | mu = 0 | GEM = 4 | 2*(stat-1)+2*(layer-1) | | hit type = 0-3 |
37 // | mu = 0 | ME0 = 5 | roll | | hit type = 0-3 |
38 // | mtd = 2 | BTL = 1 | moduleType = 1-3 | | hit type = 0-3 |
39 // | mtd = 2 | ETL = 2 | ring = 1-12 | | hit type = 0-3 |
40 // +------------+---------------+---------------------------+-----------------+----------------+
41 //
42 // hit type, see DataFormats/TrackingRecHit/interface/TrackingRecHit.h
43 // VALID = valid hit = 0
44 // MISSING = detector is good, but no rec hit found = 1
45 // INACTIVE = detector is off, so there was no hope = 2
46 // BAD = there were many bad strips within the ellipse = 3
47 //
48 // It had been shown by Zongru using a 100 GeV muon sample with 5000 events
49 // uniform in eta and phi, the average (maximum) number of tracker hits is
50 // 13 (17) and the average (maximum) number of muon detector hits is about
51 // 26 (50). If the number of hits of a track is larger than 80 then the extra
52 // hits are ignored by hit pattern. The static hit pattern array might be
53 // improved to a dynamic one in the future.
54 //
55 // Because of tracking with/without overlaps and with/without hit-splitting,
56 // the final number of hits per track is pretty "variable". Compared with the
57 // number of valid hits, the number of crossed layers with measurement should
58 // be more robust to discriminate between good and fake track.
59 //
60 // Since 4-bit for sub-sub-structure is not enough to specify a muon layer,
61 // the layer case counting methods are implemented for tracker only. This is
62 // different from the hit counting methods which are implemented for both
63 // tracker and muon detector.
64 //
65 // Given a tracker layer, specified by sub-structure and layer, the method
66 // getTrackerLayerCase(substr, layer) groups all of the hits in the hit pattern
67 // array for the layer together and returns one of the four cases
68 //
69 // crossed
70 // layer case 0: VALID + (MISSING, OFF, BAD) ==> with measurement
71 // layer case 1: MISSING + (OFF, BAD) ==> without measurement
72 // layer case 2: OFF, BAD ==> totally off or bad, cannot say much
73 // not crossed
74 // layer case NULL_RETURN: track outside acceptance or in gap ==> null
75 //
76 // Given a tracker layer, specified by sub-structure and layer, the method
77 // getTrackerMonoStereo(substr, layer) groups all of the valid hits in the hit
78 // pattern array for the layer together and returns
79 //
80 // 0: neither a valid mono nor a valid stereo hit
81 // MONO: valid mono hit
82 // STEREO: valid stereo hit
83 // MONO | STEREO: both
84 //
85 //
86 // Given a track, here is an example usage of hit pattern
87 //
88 // // hit pattern of the track
89 // const reco::HitPattern &p = track->hitPattern();
90 //
91 // // loop over the hits of the track.
92 // for (int i = 0; i < p.numberOfAllHits(HitPattern::TRACK_HITS); i++) {
93 // uint32_t hit = p.getHitPattern(HitPattern::TRACK_HITS, i);
94 //
95 // // if the hit is valid and in pixel barrel, print out the layer
96 // if (p.validHitFilter(hit) && p.pixelBarrelHitFilter(hit)){
97 // cout << "valid hit found in pixel barrel layer "
98 // << p.getLayer(hit)
99 // << endl;
100 // }
101 //
102 // // expert level: printout the hit in 11-bit binary format
103 // cout << "hit in 11-bit binary format = ";
104 // for (int j = 10; j >= 0; j--){
105 // int bit = (hit >> j) & 0x1;
106 // cout << bit;
107 // }
108 // cout << endl;
109 // }
110 //
111 // //count the number of valid pixel barrel *** hits ***
112 // cout << "number of of valid pixel barrel hits is "
113 // << p.numberOfValidPixelBarrelHits()
114 // << endl;
115 //
116 // //count the number of pixel barrel *** layers *** with measurement
117 // cout << "number of of pixel barrel layers with measurement is "
118 // << p.pixelBarrelLayersWithMeasurement()
119 // << endl;
120 //
121 
131 
132 #include <utility>
133 #include <algorithm>
134 #include <iostream>
135 #include <ostream>
136 #include <memory>
137 
138 class TrackerTopology;
139 
140 namespace test {
141  namespace TestHitPattern {
142  int test();
143  }
144 }
145 
146 namespace reco
147 {
148 
150 {
151 
152 public:
153  enum {
154  MONO = 1,
155  STEREO = 2
156  };
157 
159  MUON_HIT = 0,
160  TRACKER_HIT = 1,
161  MTD_HIT = 2
162  };
163 
164  enum HIT_TYPE {
165  VALID = 0,
166  MISSING = 1,
167  INACTIVE = 2,
168  BAD = 3
169  };
170 
171  enum HitCategory {
172  TRACK_HITS = 0,
173  MISSING_INNER_HITS = 1,
174  MISSING_OUTER_HITS = 2
175  };
176  const static unsigned short ARRAY_LENGTH = 57;
177  const static unsigned short HIT_LENGTH = 12;
178  const static unsigned short MaxHits = (8 * sizeof(uint16_t) * ARRAY_LENGTH) / HIT_LENGTH;
179 
180  static const uint32_t NULL_RETURN = 999999;
181  static const uint16_t EMPTY_PATTERN = 0x0;
182 
183  static bool trackerHitFilter(uint16_t pattern);
184  static bool muonHitFilter(uint16_t pattern);
185  static bool timingHitFilter(uint16_t pattern);
186 
187  static bool validHitFilter(uint16_t pattern);
188  static bool missingHitFilter(uint16_t pattern);
189  static bool inactiveHitFilter(uint16_t pattern);
190  static bool badHitFilter(uint16_t pattern);
191 
192  static bool pixelHitFilter(uint16_t pattern);
193  static bool pixelBarrelHitFilter(uint16_t pattern);
194  static bool pixelEndcapHitFilter(uint16_t pattern);
195  static bool stripHitFilter(uint16_t pattern);
196  static bool stripTIBHitFilter(uint16_t pattern);
197  static bool stripTIDHitFilter(uint16_t pattern);
198  static bool stripTOBHitFilter(uint16_t pattern);
199  static bool stripTECHitFilter(uint16_t pattern);
200 
201  static bool muonDTHitFilter(uint16_t pattern);
202  static bool muonCSCHitFilter(uint16_t pattern);
203  static bool muonRPCHitFilter(uint16_t pattern);
204  static bool muonGEMHitFilter(uint16_t pattern);
205  static bool muonME0HitFilter(uint16_t pattern);
206 
207  static bool timingBTLHitFilter(uint16_t pattern);
208  static bool timingETLHitFilter(uint16_t pattern);
209 
210  static uint32_t getHitType(uint16_t pattern);
211 
212  // mono (0) or stereo (1)
213  static uint32_t getSide(uint16_t pattern);
214  static uint32_t getLayer(uint16_t pattern);
215  static uint32_t getSubSubStructure(uint16_t pattern);
216  static uint32_t getSubStructure(uint16_t pattern);
217  static uint32_t getSubDetector(uint16_t pattern);
218 
220  static uint16_t getMuonStation(uint16_t pattern);
221 
223  static uint16_t getDTSuperLayer(uint16_t pattern); // only for DT patterns
224 
226  static uint16_t getCSCRing(uint16_t pattern) ;
227 
229  static uint16_t getRPCLayer(uint16_t pattern) ;
230 
232  static uint16_t getRPCregion(uint16_t pattern);
233 
235  static uint16_t getGEMStation(uint16_t pattern);
236 
238  static uint16_t getGEMLayer(uint16_t pattern);
239 
241  static uint16_t getBTLModType(uint16_t pattern);
242 
244  static uint16_t getETLRing(uint16_t pattern);
245 
246  HitPattern();
247 
248  ~HitPattern();
249 
250  HitPattern(const HitPattern &other);
251 
252  HitPattern &operator=(const HitPattern &other);
253 
254  template<typename I>
255  bool appendHits(const I &begin, const I &end, const TrackerTopology& ttopo);
256  bool appendHit(const TrackingRecHit &hit, const TrackerTopology& ttopo);
257  bool appendHit(const TrackingRecHitRef &ref, const TrackerTopology& ttopo);
258  bool appendHit(const DetId &id, TrackingRecHit::Type hitType, const TrackerTopology& ttopo);
259  bool appendHit(const uint16_t pattern, TrackingRecHit::Type hitType);
260 
267  bool appendTrackerHit(uint16_t subdet, uint16_t layer, uint16_t stereo, TrackingRecHit::Type hitType);
268 
275  bool appendMuonHit(const DetId& id, TrackingRecHit::Type hitType);
276 
277  // get the pattern of the position-th hit
278  uint16_t getHitPattern(HitCategory category, int position) const;
279 
280  void clear();
281 
282  // print the pattern of the position-th hit
283  void printHitPattern(HitCategory category, int position, std::ostream &stream) const;
284  void print(HitCategory category, std::ostream &stream = std::cout) const;
285 
286  // has valid hit in PXB/PXF layer x
287  bool hasValidHitInPixelLayer(enum PixelSubdetector::SubDetector, uint16_t layer) const;
288 
289  int numberOfAllHits(HitCategory category) const; // not-null
290  int numberOfValidHits() const; // not-null, valid
291 
292  int numberOfAllTrackerHits(HitCategory category) const; // not-null, tracker
293  int numberOfValidTrackerHits() const; // not-null, valid, tracker
294  int numberOfValidPixelHits() const; // not-null, valid, pixel
295  int numberOfValidPixelBarrelHits() const; // not-null, valid, pixel PXB
296  int numberOfValidPixelEndcapHits() const; // not-null, valid, pixel PXF
297  int numberOfValidStripHits() const; // not-null, valid, strip
298  int numberOfValidStripTIBHits() const; // not-null, valid, strip TIB
299  int numberOfValidStripTIDHits() const; // not-null, valid, strip TID
300  int numberOfValidStripTOBHits() const; // not-null, valid, strip TOB
301  int numberOfValidStripTECHits() const; // not-null, valid, strip TEC
302 
303  int numberOfLostHits(HitCategory category) const; // not-null, not valid
304  int numberOfLostTrackerHits(HitCategory category) const; // not-null, not valid, tracker
305  int numberOfLostPixelHits(HitCategory category) const; // not-null, not valid, pixel
306  int numberOfLostPixelBarrelHits(HitCategory category) const; // not-null, not valid, pixel PXB
307  int numberOfLostPixelEndcapHits(HitCategory category) const; // not-null, not valid, pixel PXF
308  int numberOfLostStripHits(HitCategory category) const; // not-null, not valid, strip
309  int numberOfLostStripTIBHits(HitCategory category) const; // not-null, not valid, strip TIB
310  int numberOfLostStripTIDHits(HitCategory category) const; // not-null, not valid, strip TID
311  int numberOfLostStripTOBHits(HitCategory category) const; // not-null, not valid, strip TOB
312  int numberOfLostStripTECHits(HitCategory category) const; // not-null, not valid, strip TEC
313 
314  int numberOfTimingHits() const; // not-null timing
315  int numberOfValidTimingHits() const; // not-null, valid, timing
316  int numberOfValidTimingBTLHits() const; // not-null, valid, timing BTL
317  int numberOfValidTimingETLHits() const; // not-null, valid, timing ETL
318 
319  int numberOfLostTimingHits() const; // not-null, not valid, timing
320  int numberOfLostTimingBTLHits() const; // not-null, not valid, timing BTL
321  int numberOfLostTimingETLHits() const; // not-null, not valid, timing ETL
322 
323  int numberOfMuonHits() const; // not-null, muon
324  int numberOfValidMuonHits() const; // not-null, valid, muon
325  int numberOfValidMuonDTHits() const; // not-null, valid, muon DT
326  int numberOfValidMuonCSCHits() const; // not-null, valid, muon CSC
327  int numberOfValidMuonRPCHits() const; // not-null, valid, muon RPC
328  int numberOfValidMuonGEMHits() const; // not-null, valid, muon GEM
329  int numberOfValidMuonME0Hits() const; // not-null, valid, muon ME0
330 
331  int numberOfLostMuonHits() const; // not-null, not valid, muon
332  int numberOfLostMuonDTHits() const; // not-null, not valid, muon DT
333  int numberOfLostMuonCSCHits() const; // not-null, not valid, muon CSC
334  int numberOfLostMuonRPCHits() const; // not-null, not valid, muon RPC
335  int numberOfLostMuonGEMHits() const; // not-null, not valid, muon GEM
336  int numberOfLostMuonME0Hits() const; // not-null, not valid, muon ME0
337 
338  int numberOfBadHits() const; // not-null, bad (only used in Muon Ch.)
339  int numberOfBadMuonHits() const; // not-null, bad, muon
340  int numberOfBadMuonDTHits() const; // not-null, bad, muon DT
341  int numberOfBadMuonCSCHits() const; // not-null, bad, muon CSC
342  int numberOfBadMuonRPCHits() const; // not-null, bad, muon RPC
343  int numberOfBadMuonGEMHits() const; // not-null, bad, muon GEM
344  int numberOfBadMuonME0Hits() const; // not-null, bad, muon ME0
345 
346  int numberOfInactiveHits() const; // not-null, inactive
347  int numberOfInactiveTrackerHits() const; // not-null, inactive, tracker
348  int numberOfInactiveTimingHits() const; // not-null, inactive, timing
349 
350  // count strip layers that have non-null, valid mono and stereo hits
351  int numberOfValidStripLayersWithMonoAndStereo(uint16_t stripdet, uint16_t layer) const;
352  int numberOfValidStripLayersWithMonoAndStereo() const;
353  int numberOfValidTOBLayersWithMonoAndStereo(uint32_t layer = 0) const;
354  int numberOfValidTIBLayersWithMonoAndStereo(uint32_t layer = 0) const;
355  int numberOfValidTIDLayersWithMonoAndStereo(uint32_t layer = 0) const;
356  int numberOfValidTECLayersWithMonoAndStereo(uint32_t layer = 0) const;
357 
358  uint32_t getTrackerLayerCase(HitCategory category, uint16_t substr, uint16_t layer) const;
359  uint16_t getTrackerMonoStereo(HitCategory category, uint16_t substr, uint16_t layer) const;
360 
361  int trackerLayersWithMeasurementOld() const; // case 0: tracker
362  int trackerLayersWithMeasurement() const; // case 0: tracker
363  int pixelLayersWithMeasurementOld() const; // case 0: pixel
364  int pixelLayersWithMeasurement() const; // case 0: pixel
365  int stripLayersWithMeasurement() const; // case 0: strip
366  int pixelBarrelLayersWithMeasurement() const; // case 0: pixel PXB
367  int pixelEndcapLayersWithMeasurement() const; // case 0: pixel PXF
368  int stripTIBLayersWithMeasurement() const; // case 0: strip TIB
369  int stripTIDLayersWithMeasurement() const; // case 0: strip TID
370  int stripTOBLayersWithMeasurement() const; // case 0: strip TOB
371  int stripTECLayersWithMeasurement() const; // case 0: strip TEC
372 
373  int trackerLayersWithoutMeasurement(HitCategory category) const; // case 1: tracker
374  int trackerLayersWithoutMeasurementOld(HitCategory category) const; // case 1: tracker
375  int pixelLayersWithoutMeasurement(HitCategory category) const; // case 1: pixel
376  int stripLayersWithoutMeasurement(HitCategory category) const; // case 1: strip
377  int pixelBarrelLayersWithoutMeasurement(HitCategory category) const; // case 1: pixel PXB
378  int pixelEndcapLayersWithoutMeasurement(HitCategory category) const; // case 1: pixel PXF
379  int stripTIBLayersWithoutMeasurement(HitCategory category) const; // case 1: strip TIB
380  int stripTIDLayersWithoutMeasurement(HitCategory category) const; // case 1: strip TID
381  int stripTOBLayersWithoutMeasurement(HitCategory category) const; // case 1: strip TOB
382  int stripTECLayersWithoutMeasurement(HitCategory category) const; // case 1: strip TEC
383 
384  int trackerLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: tracker
385  int pixelLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: pixel
386  int stripLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: strip
387  int pixelBarrelLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: pixel PXB
388  int pixelEndcapLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: pixel PXF
389  int stripTIBLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: strip TIB
390  int stripTIDLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: strip TID
391  int stripTOBLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: strip TOB
392  int stripTECLayersTotallyOffOrBad(HitCategory category=TRACK_HITS) const; // case 2: strip TEC
393 
394  int trackerLayersNull() const; // case NULL_RETURN: tracker
395  int pixelLayersNull() const; // case NULL_RETURN: pixel
396  int stripLayersNull() const; // case NULL_RETURN: strip
397  int pixelBarrelLayersNull() const; // case NULL_RETURN: pixel PXB
398  int pixelEndcapLayersNull() const; // case NULL_RETURN: pixel PXF
399  int stripTIBLayersNull() const; // case NULL_RETURN: strip TIB
400  int stripTIDLayersNull() const; // case NULL_RETURN: strip TID
401  int stripTOBLayersNull() const; // case NULL_RETURN: strip TOB
402  int stripTECLayersNull() const; // case NULL_RETURN: strip TEC
403 
405  int muonStations(int subdet, int hitType) const ;
406 
407  int muonStationsWithValidHits() const;
408  int muonStationsWithBadHits() const;
409  int muonStationsWithAnyHits() const;
410 
411  int dtStationsWithValidHits() const;
412  int dtStationsWithBadHits() const;
413  int dtStationsWithAnyHits() const;
414 
415  int cscStationsWithValidHits() const;
416  int cscStationsWithBadHits() const;
417  int cscStationsWithAnyHits() const;
418 
419  int rpcStationsWithValidHits() const;
420  int rpcStationsWithBadHits() const;
421  int rpcStationsWithAnyHits() const;
422 
423  int gemStationsWithValidHits() const ;
424  int gemStationsWithBadHits() const ;
425  int gemStationsWithAnyHits() const ;
426 
427  int me0StationsWithValidHits() const ;
428  int me0StationsWithBadHits() const ;
429  int me0StationsWithAnyHits() const ;
430 
431 
433  int innermostMuonStationWithHits(int hitType) const;
434  int innermostMuonStationWithValidHits() const;
435  int innermostMuonStationWithBadHits() const;
436  int innermostMuonStationWithAnyHits() const;
437 
439  int outermostMuonStationWithHits(int hitType) const;
440  int outermostMuonStationWithValidHits() const;
441  int outermostMuonStationWithBadHits() const;
442  int outermostMuonStationWithAnyHits() const;
443 
444  int numberOfDTStationsWithRPhiView() const;
445  int numberOfDTStationsWithRZView() const;
446  int numberOfDTStationsWithBothViews() const;
447 
448 private:
449 
450  // 3 bits for hit type
451  const static unsigned short HitTypeOffset = 0;
452  const static unsigned short HitTypeMask = 0x3;
453 
454  // 1 bit to identify the side in double-sided detectors
455  const static unsigned short SideOffset = 2;
456  const static unsigned short SideMask = 0x1;
457 
458  // 4 bits to identify the layer/disk/wheel within the substructure
459  const static unsigned short LayerOffset = 3;
460  const static unsigned short LayerMask = 0xF;
461 
462  // 3 bits to identify the tracker/muon detector substructure
463  const static unsigned short SubstrOffset = 7;
464  const static unsigned short SubstrMask = 0x7;
465 
466  // 2 bits to distinguish tracker, muon, mtd subsystems
467  const static unsigned short SubDetectorOffset = 10;
468  const static unsigned short SubDetectorMask = 0x3;
469 
470  const static unsigned short minTrackerWord = 1 << SubDetectorOffset;
471  const static unsigned short maxTrackerWord = (2 << SubDetectorOffset) - 1;
472  const static unsigned short minPixelWord = minTrackerWord | (1<<SubstrOffset);
473  const static unsigned short minStripWord = minTrackerWord | (3<<SubstrOffset);
474 
475 
476  // detector side for tracker modules (mono/stereo)
477  static uint16_t isStereo(DetId i, const TrackerTopology& ttopo);
478  static bool stripSubdetectorHitFilter(uint16_t pattern, StripSubdetector::SubDetector substructure);
479 
480  static uint16_t encode(const TrackingRecHit &hit, const TrackerTopology& ttopo);
481  static uint16_t encode(const DetId &id, TrackingRecHit::Type hitType, const TrackerTopology& ttopo);
482  static uint16_t encode(uint16_t det, uint16_t subdet, uint16_t layer, uint16_t side, TrackingRecHit::Type hitType);
483 
484  // generic count methods
485  typedef bool filterType(uint16_t);
486 
487  template<typename F>
488  void call(HitCategory category, filterType typeFilter, F f) const;
489 
490  int countHits(HitCategory category, filterType filter) const;
491  int countTypedHits(HitCategory category, filterType typeFilter, filterType filter) const;
492 
493  bool insertTrackHit(const uint16_t pattern);
494  bool insertExpectedInnerHit(const uint16_t pattern);
495  bool insertExpectedOuterHit(const uint16_t pattern);
496  void insertHit(const uint16_t pattern);
497 
498  uint16_t getHitPatternByAbsoluteIndex(int position) const;
499 
500  std::pair<uint8_t, uint8_t> getCategoryIndexRange(HitCategory category) const;
501 
502  uint16_t hitPattern[ARRAY_LENGTH];
503  uint8_t hitCount;
504 
505  uint8_t beginTrackHits;
506  uint8_t endTrackHits;
507  uint8_t beginInner;
508  uint8_t endInner;
509  uint8_t beginOuter;
510  uint8_t endOuter;
511 
513 
514  template<int N>
515  friend struct PatternSet;
516 };
517 
518 inline std::pair<uint8_t, uint8_t> HitPattern::getCategoryIndexRange(HitCategory category) const
519 {
520  switch (category) {
521  case TRACK_HITS:
522  return std::pair<uint8_t, uint8_t>(beginTrackHits, endTrackHits);
523  break;
524  case MISSING_INNER_HITS:
525  return std::pair<uint8_t, uint8_t>(beginInner, endInner);
526  break;
527  case MISSING_OUTER_HITS:
528  return std::pair<uint8_t, uint8_t>(beginOuter, endOuter);
529  break;
530  }
531  return std::pair<uint8_t, uint8_t>(-1, -1);
532 }
533 
534 template<typename I>
535 bool HitPattern::appendHits(const I &begin, const I &end, const TrackerTopology& ttopo)
536 {
537  for (I hit = begin; hit != end; hit++) {
538  if UNLIKELY((!appendHit(*hit, ttopo))) {
539  return false;
540  }
541  }
542  return true;
543 }
544 
545 inline uint16_t HitPattern::getHitPattern(HitCategory category, int position) const
546 {
547  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
548  if UNLIKELY((position < 0 || (position + range.first) >= range.second)) {
549  return HitPattern::EMPTY_PATTERN;
550  }
551 
552  return getHitPatternByAbsoluteIndex(range.first + position);
553 }
554 
555 inline int HitPattern::countHits(HitCategory category, filterType filter) const
556 {
557  int count = 0;
558  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
559  for (int i = range.first; i < range.second; ++i) {
560  if (filter(getHitPatternByAbsoluteIndex(i))) {
561  ++count;
562  }
563  }
564  return count;
565 }
566 
567 
568 template<typename F>
569 void HitPattern::call(HitCategory category, filterType typeFilter, F f) const
570 {
571  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
572  for (int i = range.first; i < range.second; i++) {
573  uint16_t pattern = getHitPatternByAbsoluteIndex(i);
574  // f() return false to ask to stop looping
575  if (typeFilter(pattern) && !f(pattern)) {
576  break;
577  }
578  }
579 }
580 
581 inline int HitPattern::countTypedHits(HitCategory category, filterType typeFilter, filterType filter) const
582 {
583  int count = 0;
584  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
585  for (int i = range.first; i < range.second; ++i) {
586  uint16_t pattern = getHitPatternByAbsoluteIndex(i);
587  if (typeFilter(pattern) && filter(pattern)) {
588  ++count;
589  }
590  }
591  return count;
592 }
593 
594 inline bool HitPattern::pixelHitFilter(uint16_t pattern)
595 {
596  if UNLIKELY(!trackerHitFilter(pattern)) {
597  return false;
598  }
599 
600  uint32_t substructure = getSubStructure(pattern);
601  return (substructure == PixelSubdetector::PixelBarrel ||
602  substructure == PixelSubdetector::PixelEndcap);
603 }
604 
605 inline bool HitPattern::pixelBarrelHitFilter(uint16_t pattern)
606 {
607  if UNLIKELY(!trackerHitFilter(pattern)) {
608  return false;
609  }
610 
611  uint32_t substructure = getSubStructure(pattern);
612  return (substructure == PixelSubdetector::PixelBarrel);
613 }
614 
615 inline bool HitPattern::pixelEndcapHitFilter(uint16_t pattern)
616 {
617  if UNLIKELY(!trackerHitFilter(pattern)) {
618  return false;
619  }
620 
621  uint32_t substructure = getSubStructure(pattern);
622  return (substructure == PixelSubdetector::PixelEndcap);
623 }
624 
625 inline bool HitPattern::stripHitFilter(uint16_t pattern)
626 {
627  return pattern > minStripWord;
628 }
629 
630 
631 inline bool HitPattern::stripSubdetectorHitFilter(uint16_t pattern, StripSubdetector::SubDetector substructure)
632 {
633  if UNLIKELY(!trackerHitFilter(pattern)) {
634  return false;
635  }
636 
637  return substructure == getSubStructure(pattern);
638 }
639 
640 inline bool HitPattern::stripTIBHitFilter(uint16_t pattern)
641 {
642  return stripSubdetectorHitFilter(pattern, StripSubdetector::TIB);
643 }
644 
645 inline bool HitPattern::stripTIDHitFilter(uint16_t pattern)
646 {
647  return stripSubdetectorHitFilter(pattern, StripSubdetector::TID);
648 }
649 
650 inline bool HitPattern::stripTOBHitFilter(uint16_t pattern)
651 {
652  return stripSubdetectorHitFilter(pattern, StripSubdetector::TOB);
653 }
654 
655 inline bool HitPattern::stripTECHitFilter(uint16_t pattern)
656 {
657  return stripSubdetectorHitFilter(pattern, StripSubdetector::TEC);
658 }
659 
660 inline bool HitPattern::muonDTHitFilter(uint16_t pattern)
661 {
662  if UNLIKELY(!muonHitFilter(pattern)) {
663  return false;
664  }
665 
666  uint32_t substructure = getSubStructure(pattern);
667  return (substructure == (uint32_t) MuonSubdetId::DT);
668 }
669 
670 inline bool HitPattern::muonCSCHitFilter(uint16_t pattern)
671 {
672  if UNLIKELY(!muonHitFilter(pattern)) {
673  return false;
674  }
675 
676  uint32_t substructure = getSubStructure(pattern);
677  return (substructure == (uint32_t) MuonSubdetId::CSC);
678 }
679 
680 inline bool HitPattern::muonRPCHitFilter(uint16_t pattern)
681 {
682  if UNLIKELY(!muonHitFilter(pattern)) {
683  return false;
684  }
685 
686  uint32_t substructure = getSubStructure(pattern);
687  return (substructure == (uint32_t) MuonSubdetId::RPC);
688 }
689 
690 inline bool HitPattern::muonGEMHitFilter(uint16_t pattern)
691 {
692  if UNLIKELY(!muonHitFilter(pattern)) {
693  return false;
694  }
695 
696  uint32_t substructure = getSubStructure(pattern);
697  return (substructure == (uint32_t) MuonSubdetId::GEM);
698 }
699 
700 inline bool HitPattern::muonME0HitFilter(uint16_t pattern) {
701  if UNLIKELY(!muonHitFilter(pattern)) return false;
702  uint16_t substructure = getSubStructure(pattern);
703  return (substructure == (uint16_t) MuonSubdetId::ME0);
704 }
705 
706 
707 inline bool HitPattern::trackerHitFilter(uint16_t pattern)
708 {
709  return pattern > minTrackerWord && pattern <= maxTrackerWord;
710 }
711 
712 inline bool HitPattern::muonHitFilter(uint16_t pattern)
713 {
714  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
715  return false;
716  }
717 
718  return (((pattern >> SubDetectorOffset) & SubDetectorMask) == 0);
719 }
720 
721 inline bool HitPattern::timingBTLHitFilter(uint16_t pattern) {
722  if UNLIKELY(!timingHitFilter(pattern)) return false;
723  uint16_t substructure = getSubStructure(pattern);
724  return (substructure == (uint16_t) MTDDetId::BTL);
725 }
726 
727 inline bool HitPattern::timingETLHitFilter(uint16_t pattern) {
728  if UNLIKELY(!timingHitFilter(pattern)) return false;
729  uint16_t substructure = getSubStructure(pattern);
730  return (substructure == (uint16_t) MTDDetId::ETL);
731 }
732 
733 inline bool HitPattern::timingHitFilter(uint16_t pattern)
734 {
735  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
736  return false;
737  }
738 
739  return (((pattern >> SubDetectorOffset) & SubDetectorMask) == 2);
740 }
741 
742 inline uint32_t HitPattern::getSubStructure(uint16_t pattern)
743 {
744  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
745  return NULL_RETURN;
746  }
747 
748  return ((pattern >> SubstrOffset) & SubstrMask);
749 }
750 
751 inline uint32_t HitPattern::getLayer(uint16_t pattern)
752 {
753  return HitPattern::getSubSubStructure(pattern);
754 }
755 
756 inline uint32_t HitPattern::getSubSubStructure(uint16_t pattern)
757 {
758  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
759  return NULL_RETURN;
760  }
761 
762  return ((pattern >> LayerOffset) & LayerMask);
763 }
764 
765 inline uint32_t HitPattern::getSubDetector(uint16_t pattern)
766 {
767  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
768  return NULL_RETURN;
769  }
770 
771  return ((pattern >> SubDetectorOffset) & SubDetectorMask);
772 }
773 
774 
775 inline uint32_t HitPattern::getSide(uint16_t pattern)
776 {
777  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
778  return NULL_RETURN;
779  }
780 
781  return (pattern >> SideOffset) & SideMask;
782 }
783 
784 inline uint32_t HitPattern::getHitType(uint16_t pattern)
785 {
786  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
787  return NULL_RETURN;
788  }
789 
790  return ((pattern >> HitTypeOffset) & HitTypeMask);
791 }
792 
793 inline uint16_t HitPattern::getMuonStation(uint16_t pattern)
794 {
795  return (getSubSubStructure(pattern) >> 2) + 1;
796 }
797 
798 inline uint16_t HitPattern::getDTSuperLayer(uint16_t pattern)
799 {
800  return (getSubSubStructure(pattern) & 3);
801 }
802 
803 inline uint16_t HitPattern::getCSCRing(uint16_t pattern)
804 {
805  return (getSubSubStructure(pattern) & 3) + 1;
806 }
807 
808 inline uint16_t HitPattern::getRPCLayer(uint16_t pattern)
809 {
810  uint16_t subSubStructure = getSubSubStructure(pattern);
811  uint16_t stat = subSubStructure >> 2;
812 
813  if LIKELY(stat <= 1) {
814  return ((subSubStructure >> 1) & 1) + 1;
815  }
816 
817  return 0;
818 }
819 
820 inline uint16_t HitPattern::getRPCregion(uint16_t pattern)
821 {
822  return getSubSubStructure(pattern) & 1;
823 }
824 
826 inline uint16_t HitPattern::getGEMStation(uint16_t pattern)
827 
828 {
829  uint16_t sss = getSubSubStructure(pattern), stat = sss >> 1;
830  return stat + 1;
831 }
832 
834 inline uint16_t HitPattern::getBTLModType(uint16_t pattern) {
835  return getSubSubStructure(pattern);
836 }
837 
838 inline uint16_t HitPattern::getETLRing(uint16_t pattern) {
839  return getSubSubStructure(pattern);
840 }
841 
842 inline uint16_t HitPattern::getGEMLayer(uint16_t pattern)
843 {
844  return (getSubSubStructure(pattern) & 1) + 1;
845 }
846 
847 inline bool HitPattern::validHitFilter(uint16_t pattern)
848 {
849  return getHitType(pattern) == HitPattern::VALID;
850 }
851 
852 inline bool HitPattern::missingHitFilter(uint16_t pattern)
853 {
854  return getHitType(pattern) == HitPattern::MISSING;
855 }
856 
857 inline bool HitPattern::inactiveHitFilter(uint16_t pattern)
858 {
859  return getHitType(pattern) == HitPattern::INACTIVE;
860 }
861 
862 inline bool HitPattern::badHitFilter(uint16_t pattern)
863 {
864  return getHitType(pattern) == HitPattern::BAD;
865 }
866 
867 inline int HitPattern::numberOfAllHits(HitCategory category) const
868 {
869  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
870  return range.second - range.first;
871 }
872 
873 inline int HitPattern::numberOfAllTrackerHits(HitCategory category) const
874 {
875  return countHits(category, trackerHitFilter);
876 }
877 
878 inline int HitPattern::numberOfMuonHits() const
879 {
880  return countHits(TRACK_HITS, muonHitFilter);
881 }
882 
883 inline int HitPattern::numberOfTimingHits() const
884 {
885  return countHits(TRACK_HITS, timingHitFilter);
886 }
887 
888 inline int HitPattern::numberOfValidHits() const
889 {
890  return countHits(TRACK_HITS, validHitFilter);
891 }
892 
893 inline int HitPattern::numberOfValidTrackerHits() const
894 {
895  return countTypedHits(TRACK_HITS, validHitFilter, trackerHitFilter);
896 }
897 
898 inline int HitPattern::numberOfValidMuonHits() const
899 {
900  return countTypedHits(TRACK_HITS, validHitFilter, muonHitFilter);
901 }
902 
903 inline int HitPattern::numberOfValidTimingHits() const
904 {
905  return countTypedHits(TRACK_HITS, validHitFilter, timingHitFilter);
906 }
907 
908 inline int HitPattern::numberOfValidPixelHits() const
909 {
910  return countTypedHits(TRACK_HITS, validHitFilter, pixelHitFilter);
911 }
912 
913 inline int HitPattern::numberOfValidPixelBarrelHits() const
914 {
915  return countTypedHits(TRACK_HITS, validHitFilter, pixelBarrelHitFilter);
916 }
917 
918 inline int HitPattern::numberOfValidPixelEndcapHits() const
919 {
920  return countTypedHits(TRACK_HITS, validHitFilter, pixelEndcapHitFilter);
921 }
922 
923 inline int HitPattern::numberOfValidStripHits() const
924 {
925  return countTypedHits(TRACK_HITS, validHitFilter, stripHitFilter);
926 }
927 
928 inline int HitPattern::numberOfValidStripTIBHits() const
929 {
930  return countTypedHits(TRACK_HITS, validHitFilter, stripTIBHitFilter);
931 }
932 
933 inline int HitPattern::numberOfValidStripTIDHits() const
934 {
935  return countTypedHits(TRACK_HITS, validHitFilter, stripTIDHitFilter);
936 }
937 
938 inline int HitPattern::numberOfValidStripTOBHits() const
939 {
940  return countTypedHits(TRACK_HITS, validHitFilter, stripTOBHitFilter);
941 }
942 
943 inline int HitPattern::numberOfValidStripTECHits() const
944 {
945  return countTypedHits(TRACK_HITS, validHitFilter, stripTECHitFilter);
946 }
947 
948 inline int HitPattern::numberOfValidMuonDTHits() const
949 {
950  return countTypedHits(TRACK_HITS, validHitFilter, muonDTHitFilter);
951 }
952 
953 inline int HitPattern::numberOfValidMuonCSCHits() const
954 {
955  return countTypedHits(TRACK_HITS, validHitFilter, muonCSCHitFilter);
956 }
957 
958 inline int HitPattern::numberOfValidMuonRPCHits() const
959 {
960  return countTypedHits(TRACK_HITS, validHitFilter, muonRPCHitFilter);
961 }
962 
963 inline int HitPattern::numberOfValidMuonGEMHits() const
964 {
965  return countTypedHits(TRACK_HITS, validHitFilter, muonGEMHitFilter);
966 }
967 
968 inline int HitPattern::numberOfValidMuonME0Hits() const {
969  return countTypedHits(TRACK_HITS, validHitFilter, muonME0HitFilter);
970 }
971 
972 inline int HitPattern::numberOfValidTimingBTLHits() const
973 {
974  return countTypedHits(TRACK_HITS, validHitFilter, timingBTLHitFilter);
975 }
976 
977 inline int HitPattern::numberOfValidTimingETLHits() const
978 {
979  return countTypedHits(TRACK_HITS, validHitFilter, timingETLHitFilter);
980 }
981 
982 inline int HitPattern::numberOfLostHits(HitCategory category) const
983 {
984  return countHits(category, missingHitFilter);
985 }
986 
987 inline int HitPattern::numberOfLostTrackerHits(HitCategory category) const
988 {
989  return countTypedHits(category, missingHitFilter, trackerHitFilter);
990 }
991 
992 inline int HitPattern::numberOfLostMuonHits() const
993 {
994  return countTypedHits(TRACK_HITS, missingHitFilter, muonHitFilter);
995 }
996 
997 inline int HitPattern::numberOfLostTimingHits() const
998 {
999  return countTypedHits(TRACK_HITS, missingHitFilter, timingHitFilter);
1000 }
1001 
1002 inline int HitPattern::numberOfLostTimingBTLHits() const
1003 {
1004  return countTypedHits(TRACK_HITS, missingHitFilter, timingBTLHitFilter);
1005 }
1006 
1007 inline int HitPattern::numberOfLostTimingETLHits() const
1008 {
1009  return countTypedHits(TRACK_HITS, missingHitFilter, timingETLHitFilter);
1010 }
1011 
1012 inline int HitPattern::numberOfLostPixelHits(HitCategory category) const
1013 {
1014  return countTypedHits(category, missingHitFilter, pixelHitFilter);
1015 }
1016 
1017 inline int HitPattern::numberOfLostPixelBarrelHits(HitCategory category) const
1018 {
1019  return countTypedHits(category, missingHitFilter, pixelBarrelHitFilter);
1020 }
1021 
1022 inline int HitPattern::numberOfLostPixelEndcapHits(HitCategory category) const
1023 {
1024  return countTypedHits(category, missingHitFilter, pixelEndcapHitFilter);
1025 }
1026 
1027 inline int HitPattern::numberOfLostStripHits(HitCategory category) const
1028 {
1029  return countTypedHits(category, missingHitFilter, stripHitFilter);
1030 }
1031 
1032 inline int HitPattern::numberOfLostStripTIBHits(HitCategory category) const
1033 {
1034  return countTypedHits(category, missingHitFilter, stripTIBHitFilter);
1035 }
1036 
1037 inline int HitPattern::numberOfLostStripTIDHits(HitCategory category) const
1038 {
1039  return countTypedHits(category, missingHitFilter, stripTIDHitFilter);
1040 }
1041 
1042 inline int HitPattern::numberOfLostStripTOBHits(HitCategory category) const
1043 {
1044  return countTypedHits(category, missingHitFilter, stripTOBHitFilter);
1045 }
1046 
1047 inline int HitPattern::numberOfLostStripTECHits(HitCategory category) const
1048 {
1049  return countTypedHits(category, missingHitFilter, stripTECHitFilter);
1050 }
1051 
1052 inline int HitPattern::numberOfLostMuonDTHits() const
1053 {
1054  return countTypedHits(TRACK_HITS, missingHitFilter, muonDTHitFilter);
1055 }
1056 
1057 inline int HitPattern::numberOfLostMuonCSCHits() const
1058 {
1059  return countTypedHits(TRACK_HITS, missingHitFilter, muonCSCHitFilter);
1060 }
1061 
1062 inline int HitPattern::numberOfLostMuonRPCHits() const
1063 {
1064  return countTypedHits(TRACK_HITS, missingHitFilter, muonRPCHitFilter);
1065 }
1066 
1067 inline int HitPattern::numberOfLostMuonGEMHits() const
1068 {
1069  return countTypedHits(TRACK_HITS, missingHitFilter, muonGEMHitFilter);
1070 }
1071 
1072 inline int HitPattern::numberOfLostMuonME0Hits() const {
1073  return countTypedHits(TRACK_HITS, missingHitFilter, muonME0HitFilter);
1074 }
1075 
1076 inline int HitPattern::numberOfBadHits() const
1077 {
1078  return countHits(TRACK_HITS, badHitFilter);
1079 }
1080 
1081 inline int HitPattern::numberOfBadMuonHits() const
1082 {
1083  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonHitFilter);
1084 }
1085 
1086 inline int HitPattern::numberOfBadMuonDTHits() const
1087 {
1088  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonDTHitFilter);
1089 }
1090 
1091 inline int HitPattern::numberOfBadMuonCSCHits() const
1092 {
1093  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonCSCHitFilter);
1094 }
1095 
1096 inline int HitPattern::numberOfBadMuonRPCHits() const
1097 {
1098  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonRPCHitFilter);
1099 }
1100 
1101 inline int HitPattern::numberOfBadMuonGEMHits() const
1102 {
1103  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonGEMHitFilter);
1104 }
1105 
1106 inline int HitPattern::numberOfBadMuonME0Hits() const {
1107  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonME0HitFilter);
1108 }
1109 
1110 inline int HitPattern::numberOfInactiveHits() const
1111 {
1112  return countHits(TRACK_HITS, inactiveHitFilter);
1113 }
1114 
1115 inline int HitPattern::numberOfInactiveTrackerHits() const
1116 {
1117  return countTypedHits(TRACK_HITS, inactiveHitFilter, trackerHitFilter);
1118 }
1119 
1120 inline int HitPattern::trackerLayersWithMeasurementOld() const
1121 {
1122  return pixelLayersWithMeasurement() + stripLayersWithMeasurement();
1123 }
1124 
1125 inline int HitPattern::pixelLayersWithMeasurementOld() const
1126 {
1127  return pixelBarrelLayersWithMeasurement() + pixelEndcapLayersWithMeasurement();
1128 }
1129 
1130 inline int HitPattern::stripLayersWithMeasurement() const
1131 {
1132  return stripTIBLayersWithMeasurement() + stripTIDLayersWithMeasurement() +
1133  stripTOBLayersWithMeasurement() + stripTECLayersWithMeasurement();
1134 }
1135 
1136 inline int HitPattern::trackerLayersWithoutMeasurementOld(HitCategory category) const
1137 {
1138  return pixelLayersWithoutMeasurement(category) +
1139  stripLayersWithoutMeasurement(category);
1140 }
1141 
1142 inline int HitPattern::pixelLayersWithoutMeasurement(HitCategory category) const
1143 {
1144  return pixelBarrelLayersWithoutMeasurement(category) +
1145  pixelEndcapLayersWithoutMeasurement(category);
1146 }
1147 
1148 inline int HitPattern::stripLayersWithoutMeasurement(HitCategory category) const
1149 {
1150  return stripTIBLayersWithoutMeasurement(category) +
1151  stripTIDLayersWithoutMeasurement(category) +
1152  stripTOBLayersWithoutMeasurement(category) +
1153  stripTECLayersWithoutMeasurement(category);
1154 }
1155 
1156 inline int HitPattern::trackerLayersTotallyOffOrBad(HitCategory category) const
1157 {
1158  return pixelLayersTotallyOffOrBad(category) +
1159  stripLayersTotallyOffOrBad(category);
1160 }
1161 
1162 inline int HitPattern::pixelLayersTotallyOffOrBad(HitCategory category) const
1163 {
1164  return pixelBarrelLayersTotallyOffOrBad(category) +
1165  pixelEndcapLayersTotallyOffOrBad(category);
1166 }
1167 
1168 inline int HitPattern::stripLayersTotallyOffOrBad(HitCategory category) const
1169 {
1170  return stripTIBLayersTotallyOffOrBad(category) +
1171  stripTIDLayersTotallyOffOrBad(category) +
1172  stripTOBLayersTotallyOffOrBad(category) +
1173  stripTECLayersTotallyOffOrBad(category);
1174 }
1175 
1176 inline int HitPattern::trackerLayersNull() const
1177 {
1178  return pixelLayersNull() +
1179  stripLayersNull();
1180 }
1181 
1182 inline int HitPattern::pixelLayersNull() const
1183 {
1184  return pixelBarrelLayersNull() +
1185  pixelEndcapLayersNull();
1186 }
1187 
1188 inline int HitPattern::stripLayersNull() const
1189 {
1190  return stripTIBLayersNull() +
1191  stripTIDLayersNull() +
1192  stripTOBLayersNull() +
1193  stripTECLayersNull();
1194 }
1195 
1196 inline int HitPattern::muonStationsWithValidHits() const
1197 {
1198  return muonStations(0, 0);
1199 }
1200 
1201 inline int HitPattern::muonStationsWithBadHits() const
1202 {
1203  return muonStations(0, 3);
1204 }
1205 
1206 inline int HitPattern::muonStationsWithAnyHits() const
1207 {
1208  return muonStations(0, -1);
1209 }
1210 
1211 inline int HitPattern::dtStationsWithValidHits() const
1212 {
1213  return muonStations(1, 0);
1214 }
1215 
1216 inline int HitPattern::dtStationsWithBadHits() const
1217 {
1218  return muonStations(1, 3);
1219 }
1220 
1221 inline int HitPattern::dtStationsWithAnyHits() const
1222 {
1223  return muonStations(1, -1);
1224 }
1225 
1226 inline int HitPattern::cscStationsWithValidHits() const
1227 {
1228  return muonStations(2, 0);
1229 }
1230 
1231 inline int HitPattern::cscStationsWithBadHits() const
1232 {
1233  return muonStations(2, 3);
1234 }
1235 
1236 inline int HitPattern::cscStationsWithAnyHits() const
1237 {
1238  return muonStations(2, -1);
1239 }
1240 
1241 inline int HitPattern::rpcStationsWithValidHits() const
1242 {
1243  return muonStations(3, 0);
1244 }
1245 
1246 inline int HitPattern::rpcStationsWithBadHits() const
1247 {
1248  return muonStations(3, 3);
1249 }
1250 
1251 inline int HitPattern::rpcStationsWithAnyHits() const
1252 {
1253  return muonStations(3, -1);
1254 }
1255 
1256 inline int HitPattern::gemStationsWithValidHits() const
1257 {
1258  return muonStations(4, 0);
1259 }
1260 
1261 inline int HitPattern::gemStationsWithBadHits() const
1262 {
1263  return muonStations(4, 3);
1264 }
1265 
1266 inline int HitPattern::gemStationsWithAnyHits() const
1267 {
1268  return muonStations(4,-1);
1269 }
1270 
1271 inline int HitPattern::me0StationsWithValidHits() const
1272 {
1273  return muonStations(5, 0);
1274 }
1275 
1276 inline int HitPattern::me0StationsWithBadHits() const
1277 {
1278  return muonStations(5, 3);
1279 }
1280 
1281 inline int HitPattern::me0StationsWithAnyHits() const
1282 {
1283  return muonStations(5,-1);
1284 }
1285 
1286 inline int HitPattern::innermostMuonStationWithValidHits() const
1287 {
1288  return innermostMuonStationWithHits(0);
1289 }
1290 
1291 inline int HitPattern::innermostMuonStationWithBadHits() const
1292 {
1293  return innermostMuonStationWithHits(3);
1294 }
1295 
1296 inline int HitPattern::innermostMuonStationWithAnyHits() const
1297 {
1298  return innermostMuonStationWithHits(-1);
1299 }
1300 
1301 inline int HitPattern::outermostMuonStationWithValidHits() const
1302 {
1303  return outermostMuonStationWithHits(0);
1304 }
1305 
1306 inline int HitPattern::outermostMuonStationWithBadHits() const
1307 {
1308  return outermostMuonStationWithHits(3);
1309 }
1310 
1311 inline int HitPattern::outermostMuonStationWithAnyHits() const
1312 {
1313  return outermostMuonStationWithHits(-1);
1314 }
1315 
1316 
1317 template<int N = HitPattern::MaxHits>
1318 struct PatternSet {
1319  static constexpr int MaxHits = N;
1320  unsigned char hit[N];
1321  unsigned char nhit;
1322 
1323  unsigned char const *begin() const
1324  {
1325  return hit;
1326  }
1327 
1328  unsigned char const *end() const
1329  {
1330  return hit + nhit;
1331  }
1332 
1333  unsigned char *begin()
1334  {
1335  return hit;
1336  }
1337 
1338  unsigned char *end()
1339  {
1340  return hit + nhit;
1341  }
1342 
1343  int size() const
1344  {
1345  return nhit;
1346  }
1347 
1348  unsigned char operator[](int i) const
1349  {
1350  return hit[i];
1351  }
1352 
1353  PatternSet() : nhit(0) {}
1354 
1356  {
1357  fill(category, hp);
1358  }
1359 
1361  {
1362  int lhit = 0;
1363  auto unpack = [&lhit, this](uint16_t pattern) -> bool {
1364  unsigned char p = 255 & (pattern >> 3);
1365  hit[lhit++] = p;
1366 
1367  // bouble sort
1368  if (lhit > 1) {
1369  for (auto h = hit + lhit - 1; h != hit; --h) {
1370  if ((*(h - 1)) <= p) {
1371  break;
1372  }
1373  (*h) = *(h - 1);
1374  *(h - 1) = p;
1375  }
1376  }
1377  return lhit < MaxHits;
1378  };
1379 
1380  hp.call(category, HitPattern::validHitFilter, unpack);
1381  nhit = lhit;
1382  }
1383 };
1384 
1385 template<int N>
1387 {
1388  PatternSet<N> comm;
1389  comm.nhit = std::set_intersection(p1.begin(), p1.end(), p2.begin(), p2.end(), comm.begin()) - comm.begin();
1390  return comm;
1391 }
1392 
1393 } // namespace reco
1394 
1395 #endif
1396 
unsigned char const * begin() const
Definition: HitPattern.h:1323
unsigned char const * end() const
Definition: HitPattern.h:1328
PatternSet< N > commonHits(PatternSet< N > const &p1, PatternSet< N > const &p2)
Definition: HitPattern.h:1386
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
static const int GEM
Definition: MuonSubdetId.h:15
void call(HitCategory category, filterType typeFilter, F f) const
Definition: HitPattern.h:569
unsigned char nhit
Definition: HitPattern.h:1321
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
bool filterType(uint16_t)
Definition: HitPattern.h:485
#define constexpr
uint8_t endInner
Definition: HitPattern.h:508
static const int ME0
Definition: MuonSubdetId.h:16
unsigned char * begin()
Definition: HitPattern.h:1333
static const int CSC
Definition: MuonSubdetId.h:13
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
void clear(CLHEP::HepGenMatrix &m)
Helper function: Reset all elements of a matrix to 0.
Definition: matutil.cc:167
int size() const
Definition: HitPattern.h:1343
const std::complex< double > I
Definition: I.h:8
double f[11][100]
uint8_t beginInner
Definition: HitPattern.h:507
#define end
Definition: vmac.h:39
double p2[4]
Definition: TauolaWrapper.h:90
uint8_t beginTrackHits
Definition: HitPattern.h:505
unsigned char * end()
Definition: HitPattern.h:1338
Definition: DetId.h:18
uint8_t endTrackHits
Definition: HitPattern.h:506
double const BAD
Definition: Constants.h:17
#define N
Definition: blowfish.cc:9
uint8_t hitCount
Definition: HitPattern.h:503
uint8_t beginOuter
Definition: HitPattern.h:509
def encode(args, files)
fixed size matrix
#define begin
Definition: vmac.h:32
double p1[4]
Definition: TauolaWrapper.h:89
static const int RPC
Definition: MuonSubdetId.h:14
void fill(HitPattern::HitCategory category, HitPattern const &hp)
Definition: HitPattern.h:1360
static int position[264][3]
Definition: ReadPGInfo.cc:509
#define LIKELY(x)
static const int DT
Definition: MuonSubdetId.h:12
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
PatternSet(HitPattern::HitCategory category, HitPattern const &hp)
Definition: HitPattern.h:1355
uint8_t endOuter
Definition: HitPattern.h:510
unsigned char operator[](int i) const
Definition: HitPattern.h:1348
#define UNLIKELY(x)