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  //only used by ROOT IO rule to read v12 HitPatterns
449  static bool fillNewHitPatternWithOldHitPattern_v12(const uint16_t oldHitPattern[],
450  uint8_t hitCount,
451  uint8_t beginTrackHits, uint8_t endTrackHits,
452  uint8_t beginInner, uint8_t endInner,
453  uint8_t beginOuter, uint8_t endOuter,
454  reco::HitPattern* newObj);
455 
456 private:
457 
458  // 3 bits for hit type
459  const static unsigned short HitTypeOffset = 0;
460  const static unsigned short HitTypeMask = 0x3;
461 
462  // 1 bit to identify the side in double-sided detectors
463  const static unsigned short SideOffset = 2;
464  const static unsigned short SideMask = 0x1;
465 
466  // 4 bits to identify the layer/disk/wheel within the substructure
467  const static unsigned short LayerOffset = 3;
468  const static unsigned short LayerMask = 0xF;
469 
470  // 3 bits to identify the tracker/muon detector substructure
471  const static unsigned short SubstrOffset = 7;
472  const static unsigned short SubstrMask = 0x7;
473 
474  // 2 bits to distinguish tracker, muon, mtd subsystems
475  const static unsigned short SubDetectorOffset = 10;
476  const static unsigned short SubDetectorMask = 0x3;
477 
478  const static unsigned short minTrackerWord = 1 << SubDetectorOffset;
479  const static unsigned short maxTrackerWord = (2 << SubDetectorOffset) - 1;
480  const static unsigned short minPixelWord = minTrackerWord | (1<<SubstrOffset);
481  const static unsigned short minStripWord = minTrackerWord | (3<<SubstrOffset);
482 
483 
484  // detector side for tracker modules (mono/stereo)
485  static uint16_t isStereo(DetId i, const TrackerTopology& ttopo);
486  static bool stripSubdetectorHitFilter(uint16_t pattern, StripSubdetector::SubDetector substructure);
487 
488  static uint16_t encode(const TrackingRecHit &hit, const TrackerTopology& ttopo);
489  static uint16_t encode(const DetId &id, TrackingRecHit::Type hitType, const TrackerTopology& ttopo);
490  static uint16_t encode(uint16_t det, uint16_t subdet, uint16_t layer, uint16_t side, TrackingRecHit::Type hitType);
491 
492  // generic count methods
493  typedef bool filterType(uint16_t);
494 
495  template<typename F>
496  void call(HitCategory category, filterType typeFilter, F f) const;
497 
499  int countTypedHits(HitCategory category, filterType typeFilter, filterType filter) const;
500 
501  bool insertTrackHit(const uint16_t pattern);
502  bool insertExpectedInnerHit(const uint16_t pattern);
503  bool insertExpectedOuterHit(const uint16_t pattern);
504  void insertHit(const uint16_t pattern);
505 
506  uint16_t getHitPatternByAbsoluteIndex(int position) const;
507 
508  std::pair<uint8_t, uint8_t> getCategoryIndexRange(HitCategory category) const;
509 
510  uint16_t hitPattern[ARRAY_LENGTH];
511  uint8_t hitCount;
512 
513  uint8_t beginTrackHits;
514  uint8_t endTrackHits;
515  uint8_t beginInner;
516  uint8_t endInner;
517  uint8_t beginOuter;
518  uint8_t endOuter;
519 
521 
522  template<int N>
523  friend struct PatternSet;
524 };
525 
526 inline std::pair<uint8_t, uint8_t> HitPattern::getCategoryIndexRange(HitCategory category) const
527 {
528  switch (category) {
529  case TRACK_HITS:
530  return std::pair<uint8_t, uint8_t>(beginTrackHits, endTrackHits);
531  break;
532  case MISSING_INNER_HITS:
533  return std::pair<uint8_t, uint8_t>(beginInner, endInner);
534  break;
535  case MISSING_OUTER_HITS:
536  return std::pair<uint8_t, uint8_t>(beginOuter, endOuter);
537  break;
538  }
539  return std::pair<uint8_t, uint8_t>(-1, -1);
540 }
541 
542 template<typename I>
543 bool HitPattern::appendHits(const I &begin, const I &end, const TrackerTopology& ttopo)
544 {
545  for (I hit = begin; hit != end; hit++) {
546  if UNLIKELY((!appendHit(*hit, ttopo))) {
547  return false;
548  }
549  }
550  return true;
551 }
552 
553 inline uint16_t HitPattern::getHitPattern(HitCategory category, int position) const
554 {
555  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
556  if UNLIKELY((position < 0 || (position + range.first) >= range.second)) {
557  return HitPattern::EMPTY_PATTERN;
558  }
559 
560  return getHitPatternByAbsoluteIndex(range.first + position);
561 }
562 
564 {
565  int count = 0;
566  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
567  for (int i = range.first; i < range.second; ++i) {
568  if (filter(getHitPatternByAbsoluteIndex(i))) {
569  ++count;
570  }
571  }
572  return count;
573 }
574 
575 
576 template<typename F>
577 void HitPattern::call(HitCategory category, filterType typeFilter, F f) const
578 {
579  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
580  for (int i = range.first; i < range.second; i++) {
581  uint16_t pattern = getHitPatternByAbsoluteIndex(i);
582  // f() return false to ask to stop looping
583  if (typeFilter(pattern) && !f(pattern)) {
584  break;
585  }
586  }
587 }
588 
589 inline int HitPattern::countTypedHits(HitCategory category, filterType typeFilter, filterType filter) const
590 {
591  int count = 0;
592  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
593  for (int i = range.first; i < range.second; ++i) {
594  uint16_t pattern = getHitPatternByAbsoluteIndex(i);
595  if (typeFilter(pattern) && filter(pattern)) {
596  ++count;
597  }
598  }
599  return count;
600 }
601 
602 inline bool HitPattern::pixelHitFilter(uint16_t pattern)
603 {
604  if UNLIKELY(!trackerHitFilter(pattern)) {
605  return false;
606  }
607 
608  uint32_t substructure = getSubStructure(pattern);
609  return (substructure == PixelSubdetector::PixelBarrel ||
610  substructure == PixelSubdetector::PixelEndcap);
611 }
612 
613 inline bool HitPattern::pixelBarrelHitFilter(uint16_t pattern)
614 {
615  if UNLIKELY(!trackerHitFilter(pattern)) {
616  return false;
617  }
618 
619  uint32_t substructure = getSubStructure(pattern);
620  return (substructure == PixelSubdetector::PixelBarrel);
621 }
622 
623 inline bool HitPattern::pixelEndcapHitFilter(uint16_t pattern)
624 {
625  if UNLIKELY(!trackerHitFilter(pattern)) {
626  return false;
627  }
628 
629  uint32_t substructure = getSubStructure(pattern);
630  return (substructure == PixelSubdetector::PixelEndcap);
631 }
632 
633 inline bool HitPattern::stripHitFilter(uint16_t pattern)
634 {
635  return pattern > minStripWord && pattern <= maxTrackerWord;
636 }
637 
638 
639 inline bool HitPattern::stripSubdetectorHitFilter(uint16_t pattern, StripSubdetector::SubDetector substructure)
640 {
641  if UNLIKELY(!trackerHitFilter(pattern)) {
642  return false;
643  }
644 
645  return substructure == getSubStructure(pattern);
646 }
647 
648 inline bool HitPattern::stripTIBHitFilter(uint16_t pattern)
649 {
650  return stripSubdetectorHitFilter(pattern, StripSubdetector::TIB);
651 }
652 
653 inline bool HitPattern::stripTIDHitFilter(uint16_t pattern)
654 {
655  return stripSubdetectorHitFilter(pattern, StripSubdetector::TID);
656 }
657 
658 inline bool HitPattern::stripTOBHitFilter(uint16_t pattern)
659 {
660  return stripSubdetectorHitFilter(pattern, StripSubdetector::TOB);
661 }
662 
663 inline bool HitPattern::stripTECHitFilter(uint16_t pattern)
664 {
665  return stripSubdetectorHitFilter(pattern, StripSubdetector::TEC);
666 }
667 
668 inline bool HitPattern::muonDTHitFilter(uint16_t pattern)
669 {
670  if UNLIKELY(!muonHitFilter(pattern)) {
671  return false;
672  }
673 
674  uint32_t substructure = getSubStructure(pattern);
675  return (substructure == (uint32_t) MuonSubdetId::DT);
676 }
677 
678 inline bool HitPattern::muonCSCHitFilter(uint16_t pattern)
679 {
680  if UNLIKELY(!muonHitFilter(pattern)) {
681  return false;
682  }
683 
684  uint32_t substructure = getSubStructure(pattern);
685  return (substructure == (uint32_t) MuonSubdetId::CSC);
686 }
687 
688 inline bool HitPattern::muonRPCHitFilter(uint16_t pattern)
689 {
690  if UNLIKELY(!muonHitFilter(pattern)) {
691  return false;
692  }
693 
694  uint32_t substructure = getSubStructure(pattern);
695  return (substructure == (uint32_t) MuonSubdetId::RPC);
696 }
697 
698 inline bool HitPattern::muonGEMHitFilter(uint16_t pattern)
699 {
700  if UNLIKELY(!muonHitFilter(pattern)) {
701  return false;
702  }
703 
704  uint32_t substructure = getSubStructure(pattern);
705  return (substructure == (uint32_t) MuonSubdetId::GEM);
706 }
707 
708 inline bool HitPattern::muonME0HitFilter(uint16_t pattern) {
709  if UNLIKELY(!muonHitFilter(pattern)) return false;
710  uint16_t substructure = getSubStructure(pattern);
711  return (substructure == (uint16_t) MuonSubdetId::ME0);
712 }
713 
714 
715 inline bool HitPattern::trackerHitFilter(uint16_t pattern)
716 {
717  return pattern > minTrackerWord && pattern <= maxTrackerWord;
718 }
719 
720 inline bool HitPattern::muonHitFilter(uint16_t pattern)
721 {
722  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
723  return false;
724  }
725 
726  return (((pattern >> SubDetectorOffset) & SubDetectorMask) == 0);
727 }
728 
729 inline bool HitPattern::timingBTLHitFilter(uint16_t pattern) {
730  if UNLIKELY(!timingHitFilter(pattern)) return false;
731  uint16_t substructure = getSubStructure(pattern);
732  return (substructure == (uint16_t) MTDDetId::BTL);
733 }
734 
735 inline bool HitPattern::timingETLHitFilter(uint16_t pattern) {
736  if UNLIKELY(!timingHitFilter(pattern)) return false;
737  uint16_t substructure = getSubStructure(pattern);
738  return (substructure == (uint16_t) MTDDetId::ETL);
739 }
740 
741 inline bool HitPattern::timingHitFilter(uint16_t pattern)
742 {
743  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
744  return false;
745  }
746 
747  return (((pattern >> SubDetectorOffset) & SubDetectorMask) == 2);
748 }
749 
750 inline uint32_t HitPattern::getSubStructure(uint16_t pattern)
751 {
752  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
753  return NULL_RETURN;
754  }
755 
756  return ((pattern >> SubstrOffset) & SubstrMask);
757 }
758 
759 inline uint32_t HitPattern::getLayer(uint16_t pattern)
760 {
761  return HitPattern::getSubSubStructure(pattern);
762 }
763 
764 inline uint32_t HitPattern::getSubSubStructure(uint16_t pattern)
765 {
766  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
767  return NULL_RETURN;
768  }
769 
770  return ((pattern >> LayerOffset) & LayerMask);
771 }
772 
773 inline uint32_t HitPattern::getSubDetector(uint16_t pattern)
774 {
775  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
776  return NULL_RETURN;
777  }
778 
779  return ((pattern >> SubDetectorOffset) & SubDetectorMask);
780 }
781 
782 
783 inline uint32_t HitPattern::getSide(uint16_t pattern)
784 {
785  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
786  return NULL_RETURN;
787  }
788 
789  return (pattern >> SideOffset) & SideMask;
790 }
791 
792 inline uint32_t HitPattern::getHitType(uint16_t pattern)
793 {
794  if UNLIKELY(pattern == HitPattern::EMPTY_PATTERN) {
795  return NULL_RETURN;
796  }
797 
798  return ((pattern >> HitTypeOffset) & HitTypeMask);
799 }
800 
801 inline uint16_t HitPattern::getMuonStation(uint16_t pattern)
802 {
803  return (getSubSubStructure(pattern) >> 2) + 1;
804 }
805 
806 inline uint16_t HitPattern::getDTSuperLayer(uint16_t pattern)
807 {
808  return (getSubSubStructure(pattern) & 3);
809 }
810 
811 inline uint16_t HitPattern::getCSCRing(uint16_t pattern)
812 {
813  return (getSubSubStructure(pattern) & 3) + 1;
814 }
815 
816 inline uint16_t HitPattern::getRPCLayer(uint16_t pattern)
817 {
818  uint16_t subSubStructure = getSubSubStructure(pattern);
819  uint16_t stat = subSubStructure >> 2;
820 
821  if LIKELY(stat <= 1) {
822  return ((subSubStructure >> 1) & 1) + 1;
823  }
824 
825  return 0;
826 }
827 
828 inline uint16_t HitPattern::getRPCregion(uint16_t pattern)
829 {
830  return getSubSubStructure(pattern) & 1;
831 }
832 
834 inline uint16_t HitPattern::getGEMStation(uint16_t pattern)
835 
836 {
837  uint16_t sss = getSubSubStructure(pattern), stat = sss >> 1;
838  return stat + 1;
839 }
840 
842 inline uint16_t HitPattern::getBTLModType(uint16_t pattern) {
843  return getSubSubStructure(pattern);
844 }
845 
846 inline uint16_t HitPattern::getETLRing(uint16_t pattern) {
847  return getSubSubStructure(pattern);
848 }
849 
850 inline uint16_t HitPattern::getGEMLayer(uint16_t pattern)
851 {
852  return (getSubSubStructure(pattern) & 1) + 1;
853 }
854 
855 inline bool HitPattern::validHitFilter(uint16_t pattern)
856 {
857  return getHitType(pattern) == HitPattern::VALID;
858 }
859 
860 inline bool HitPattern::missingHitFilter(uint16_t pattern)
861 {
862  return getHitType(pattern) == HitPattern::MISSING;
863 }
864 
865 inline bool HitPattern::inactiveHitFilter(uint16_t pattern)
866 {
867  return getHitType(pattern) == HitPattern::INACTIVE;
868 }
869 
870 inline bool HitPattern::badHitFilter(uint16_t pattern)
871 {
872  return getHitType(pattern) == HitPattern::BAD;
873 }
874 
875 inline int HitPattern::numberOfAllHits(HitCategory category) const
876 {
877  std::pair<uint8_t, uint8_t> range = getCategoryIndexRange(category);
878  return range.second - range.first;
879 }
880 
881 inline int HitPattern::numberOfAllTrackerHits(HitCategory category) const
882 {
883  return countHits(category, trackerHitFilter);
884 }
885 
886 inline int HitPattern::numberOfMuonHits() const
887 {
888  return countHits(TRACK_HITS, muonHitFilter);
889 }
890 
891 inline int HitPattern::numberOfTimingHits() const
892 {
893  return countHits(TRACK_HITS, timingHitFilter);
894 }
895 
896 inline int HitPattern::numberOfValidHits() const
897 {
898  return countHits(TRACK_HITS, validHitFilter);
899 }
900 
901 inline int HitPattern::numberOfValidTrackerHits() const
902 {
903  return countTypedHits(TRACK_HITS, validHitFilter, trackerHitFilter);
904 }
905 
906 inline int HitPattern::numberOfValidMuonHits() const
907 {
908  return countTypedHits(TRACK_HITS, validHitFilter, muonHitFilter);
909 }
910 
911 inline int HitPattern::numberOfValidTimingHits() const
912 {
913  return countTypedHits(TRACK_HITS, validHitFilter, timingHitFilter);
914 }
915 
916 inline int HitPattern::numberOfValidPixelHits() const
917 {
918  return countTypedHits(TRACK_HITS, validHitFilter, pixelHitFilter);
919 }
920 
921 inline int HitPattern::numberOfValidPixelBarrelHits() const
922 {
923  return countTypedHits(TRACK_HITS, validHitFilter, pixelBarrelHitFilter);
924 }
925 
926 inline int HitPattern::numberOfValidPixelEndcapHits() const
927 {
928  return countTypedHits(TRACK_HITS, validHitFilter, pixelEndcapHitFilter);
929 }
930 
931 inline int HitPattern::numberOfValidStripHits() const
932 {
933  return countTypedHits(TRACK_HITS, validHitFilter, stripHitFilter);
934 }
935 
936 inline int HitPattern::numberOfValidStripTIBHits() const
937 {
938  return countTypedHits(TRACK_HITS, validHitFilter, stripTIBHitFilter);
939 }
940 
941 inline int HitPattern::numberOfValidStripTIDHits() const
942 {
943  return countTypedHits(TRACK_HITS, validHitFilter, stripTIDHitFilter);
944 }
945 
946 inline int HitPattern::numberOfValidStripTOBHits() const
947 {
948  return countTypedHits(TRACK_HITS, validHitFilter, stripTOBHitFilter);
949 }
950 
951 inline int HitPattern::numberOfValidStripTECHits() const
952 {
953  return countTypedHits(TRACK_HITS, validHitFilter, stripTECHitFilter);
954 }
955 
956 inline int HitPattern::numberOfValidMuonDTHits() const
957 {
958  return countTypedHits(TRACK_HITS, validHitFilter, muonDTHitFilter);
959 }
960 
961 inline int HitPattern::numberOfValidMuonCSCHits() const
962 {
963  return countTypedHits(TRACK_HITS, validHitFilter, muonCSCHitFilter);
964 }
965 
966 inline int HitPattern::numberOfValidMuonRPCHits() const
967 {
968  return countTypedHits(TRACK_HITS, validHitFilter, muonRPCHitFilter);
969 }
970 
971 inline int HitPattern::numberOfValidMuonGEMHits() const
972 {
973  return countTypedHits(TRACK_HITS, validHitFilter, muonGEMHitFilter);
974 }
975 
976 inline int HitPattern::numberOfValidMuonME0Hits() const {
977  return countTypedHits(TRACK_HITS, validHitFilter, muonME0HitFilter);
978 }
979 
980 inline int HitPattern::numberOfValidTimingBTLHits() const
981 {
982  return countTypedHits(TRACK_HITS, validHitFilter, timingBTLHitFilter);
983 }
984 
985 inline int HitPattern::numberOfValidTimingETLHits() const
986 {
987  return countTypedHits(TRACK_HITS, validHitFilter, timingETLHitFilter);
988 }
989 
990 inline int HitPattern::numberOfLostHits(HitCategory category) const
991 {
992  return countHits(category, missingHitFilter);
993 }
994 
995 inline int HitPattern::numberOfLostTrackerHits(HitCategory category) const
996 {
997  return countTypedHits(category, missingHitFilter, trackerHitFilter);
998 }
999 
1000 inline int HitPattern::numberOfLostMuonHits() const
1001 {
1002  return countTypedHits(TRACK_HITS, missingHitFilter, muonHitFilter);
1003 }
1004 
1005 inline int HitPattern::numberOfLostTimingHits() const
1006 {
1007  return countTypedHits(TRACK_HITS, missingHitFilter, timingHitFilter);
1008 }
1009 
1010 inline int HitPattern::numberOfLostTimingBTLHits() const
1011 {
1012  return countTypedHits(TRACK_HITS, missingHitFilter, timingBTLHitFilter);
1013 }
1014 
1015 inline int HitPattern::numberOfLostTimingETLHits() const
1016 {
1017  return countTypedHits(TRACK_HITS, missingHitFilter, timingETLHitFilter);
1018 }
1019 
1020 inline int HitPattern::numberOfLostPixelHits(HitCategory category) const
1021 {
1022  return countTypedHits(category, missingHitFilter, pixelHitFilter);
1023 }
1024 
1025 inline int HitPattern::numberOfLostPixelBarrelHits(HitCategory category) const
1026 {
1027  return countTypedHits(category, missingHitFilter, pixelBarrelHitFilter);
1028 }
1029 
1030 inline int HitPattern::numberOfLostPixelEndcapHits(HitCategory category) const
1031 {
1032  return countTypedHits(category, missingHitFilter, pixelEndcapHitFilter);
1033 }
1034 
1035 inline int HitPattern::numberOfLostStripHits(HitCategory category) const
1036 {
1037  return countTypedHits(category, missingHitFilter, stripHitFilter);
1038 }
1039 
1040 inline int HitPattern::numberOfLostStripTIBHits(HitCategory category) const
1041 {
1042  return countTypedHits(category, missingHitFilter, stripTIBHitFilter);
1043 }
1044 
1045 inline int HitPattern::numberOfLostStripTIDHits(HitCategory category) const
1046 {
1047  return countTypedHits(category, missingHitFilter, stripTIDHitFilter);
1048 }
1049 
1050 inline int HitPattern::numberOfLostStripTOBHits(HitCategory category) const
1051 {
1052  return countTypedHits(category, missingHitFilter, stripTOBHitFilter);
1053 }
1054 
1055 inline int HitPattern::numberOfLostStripTECHits(HitCategory category) const
1056 {
1057  return countTypedHits(category, missingHitFilter, stripTECHitFilter);
1058 }
1059 
1060 inline int HitPattern::numberOfLostMuonDTHits() const
1061 {
1062  return countTypedHits(TRACK_HITS, missingHitFilter, muonDTHitFilter);
1063 }
1064 
1065 inline int HitPattern::numberOfLostMuonCSCHits() const
1066 {
1067  return countTypedHits(TRACK_HITS, missingHitFilter, muonCSCHitFilter);
1068 }
1069 
1070 inline int HitPattern::numberOfLostMuonRPCHits() const
1071 {
1072  return countTypedHits(TRACK_HITS, missingHitFilter, muonRPCHitFilter);
1073 }
1074 
1075 inline int HitPattern::numberOfLostMuonGEMHits() const
1076 {
1077  return countTypedHits(TRACK_HITS, missingHitFilter, muonGEMHitFilter);
1078 }
1079 
1080 inline int HitPattern::numberOfLostMuonME0Hits() const {
1081  return countTypedHits(TRACK_HITS, missingHitFilter, muonME0HitFilter);
1082 }
1083 
1084 inline int HitPattern::numberOfBadHits() const
1085 {
1086  return countHits(TRACK_HITS, badHitFilter);
1087 }
1088 
1089 inline int HitPattern::numberOfBadMuonHits() const
1090 {
1091  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonHitFilter);
1092 }
1093 
1094 inline int HitPattern::numberOfBadMuonDTHits() const
1095 {
1096  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonDTHitFilter);
1097 }
1098 
1099 inline int HitPattern::numberOfBadMuonCSCHits() const
1100 {
1101  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonCSCHitFilter);
1102 }
1103 
1104 inline int HitPattern::numberOfBadMuonRPCHits() const
1105 {
1106  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonRPCHitFilter);
1107 }
1108 
1109 inline int HitPattern::numberOfBadMuonGEMHits() const
1110 {
1111  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonGEMHitFilter);
1112 }
1113 
1114 inline int HitPattern::numberOfBadMuonME0Hits() const {
1115  return countTypedHits(TRACK_HITS, inactiveHitFilter, muonME0HitFilter);
1116 }
1117 
1118 inline int HitPattern::numberOfInactiveHits() const
1119 {
1120  return countHits(TRACK_HITS, inactiveHitFilter);
1121 }
1122 
1123 inline int HitPattern::numberOfInactiveTrackerHits() const
1124 {
1125  return countTypedHits(TRACK_HITS, inactiveHitFilter, trackerHitFilter);
1126 }
1127 
1128 inline int HitPattern::trackerLayersWithMeasurementOld() const
1129 {
1130  return pixelLayersWithMeasurement() + stripLayersWithMeasurement();
1131 }
1132 
1133 inline int HitPattern::pixelLayersWithMeasurementOld() const
1134 {
1135  return pixelBarrelLayersWithMeasurement() + pixelEndcapLayersWithMeasurement();
1136 }
1137 
1138 inline int HitPattern::stripLayersWithMeasurement() const
1139 {
1140  return stripTIBLayersWithMeasurement() + stripTIDLayersWithMeasurement() +
1141  stripTOBLayersWithMeasurement() + stripTECLayersWithMeasurement();
1142 }
1143 
1144 inline int HitPattern::trackerLayersWithoutMeasurementOld(HitCategory category) const
1145 {
1146  return pixelLayersWithoutMeasurement(category) +
1147  stripLayersWithoutMeasurement(category);
1148 }
1149 
1150 inline int HitPattern::pixelLayersWithoutMeasurement(HitCategory category) const
1151 {
1152  return pixelBarrelLayersWithoutMeasurement(category) +
1153  pixelEndcapLayersWithoutMeasurement(category);
1154 }
1155 
1156 inline int HitPattern::stripLayersWithoutMeasurement(HitCategory category) const
1157 {
1158  return stripTIBLayersWithoutMeasurement(category) +
1159  stripTIDLayersWithoutMeasurement(category) +
1160  stripTOBLayersWithoutMeasurement(category) +
1161  stripTECLayersWithoutMeasurement(category);
1162 }
1163 
1164 inline int HitPattern::trackerLayersTotallyOffOrBad(HitCategory category) const
1165 {
1166  return pixelLayersTotallyOffOrBad(category) +
1167  stripLayersTotallyOffOrBad(category);
1168 }
1169 
1170 inline int HitPattern::pixelLayersTotallyOffOrBad(HitCategory category) const
1171 {
1172  return pixelBarrelLayersTotallyOffOrBad(category) +
1173  pixelEndcapLayersTotallyOffOrBad(category);
1174 }
1175 
1176 inline int HitPattern::stripLayersTotallyOffOrBad(HitCategory category) const
1177 {
1178  return stripTIBLayersTotallyOffOrBad(category) +
1179  stripTIDLayersTotallyOffOrBad(category) +
1180  stripTOBLayersTotallyOffOrBad(category) +
1181  stripTECLayersTotallyOffOrBad(category);
1182 }
1183 
1184 inline int HitPattern::trackerLayersNull() const
1185 {
1186  return pixelLayersNull() +
1187  stripLayersNull();
1188 }
1189 
1190 inline int HitPattern::pixelLayersNull() const
1191 {
1192  return pixelBarrelLayersNull() +
1193  pixelEndcapLayersNull();
1194 }
1195 
1196 inline int HitPattern::stripLayersNull() const
1197 {
1198  return stripTIBLayersNull() +
1199  stripTIDLayersNull() +
1200  stripTOBLayersNull() +
1201  stripTECLayersNull();
1202 }
1203 
1204 inline int HitPattern::muonStationsWithValidHits() const
1205 {
1206  return muonStations(0, 0);
1207 }
1208 
1209 inline int HitPattern::muonStationsWithBadHits() const
1210 {
1211  return muonStations(0, 3);
1212 }
1213 
1214 inline int HitPattern::muonStationsWithAnyHits() const
1215 {
1216  return muonStations(0, -1);
1217 }
1218 
1219 inline int HitPattern::dtStationsWithValidHits() const
1220 {
1221  return muonStations(1, 0);
1222 }
1223 
1224 inline int HitPattern::dtStationsWithBadHits() const
1225 {
1226  return muonStations(1, 3);
1227 }
1228 
1229 inline int HitPattern::dtStationsWithAnyHits() const
1230 {
1231  return muonStations(1, -1);
1232 }
1233 
1234 inline int HitPattern::cscStationsWithValidHits() const
1235 {
1236  return muonStations(2, 0);
1237 }
1238 
1239 inline int HitPattern::cscStationsWithBadHits() const
1240 {
1241  return muonStations(2, 3);
1242 }
1243 
1244 inline int HitPattern::cscStationsWithAnyHits() const
1245 {
1246  return muonStations(2, -1);
1247 }
1248 
1249 inline int HitPattern::rpcStationsWithValidHits() const
1250 {
1251  return muonStations(3, 0);
1252 }
1253 
1254 inline int HitPattern::rpcStationsWithBadHits() const
1255 {
1256  return muonStations(3, 3);
1257 }
1258 
1259 inline int HitPattern::rpcStationsWithAnyHits() const
1260 {
1261  return muonStations(3, -1);
1262 }
1263 
1264 inline int HitPattern::gemStationsWithValidHits() const
1265 {
1266  return muonStations(4, 0);
1267 }
1268 
1269 inline int HitPattern::gemStationsWithBadHits() const
1270 {
1271  return muonStations(4, 3);
1272 }
1273 
1274 inline int HitPattern::gemStationsWithAnyHits() const
1275 {
1276  return muonStations(4,-1);
1277 }
1278 
1279 inline int HitPattern::me0StationsWithValidHits() const
1280 {
1281  return muonStations(5, 0);
1282 }
1283 
1284 inline int HitPattern::me0StationsWithBadHits() const
1285 {
1286  return muonStations(5, 3);
1287 }
1288 
1289 inline int HitPattern::me0StationsWithAnyHits() const
1290 {
1291  return muonStations(5,-1);
1292 }
1293 
1294 inline int HitPattern::innermostMuonStationWithValidHits() const
1295 {
1296  return innermostMuonStationWithHits(0);
1297 }
1298 
1299 inline int HitPattern::innermostMuonStationWithBadHits() const
1300 {
1301  return innermostMuonStationWithHits(3);
1302 }
1303 
1304 inline int HitPattern::innermostMuonStationWithAnyHits() const
1305 {
1306  return innermostMuonStationWithHits(-1);
1307 }
1308 
1309 inline int HitPattern::outermostMuonStationWithValidHits() const
1310 {
1311  return outermostMuonStationWithHits(0);
1312 }
1313 
1314 inline int HitPattern::outermostMuonStationWithBadHits() const
1315 {
1316  return outermostMuonStationWithHits(3);
1317 }
1318 
1319 inline int HitPattern::outermostMuonStationWithAnyHits() const
1320 {
1321  return outermostMuonStationWithHits(-1);
1322 }
1323 
1324 
1325 template<int N = HitPattern::MaxHits>
1326 struct PatternSet {
1327  static constexpr int MaxHits = N;
1328  unsigned char hit[N];
1329  unsigned char nhit;
1330 
1331  unsigned char const *begin() const
1332  {
1333  return hit;
1334  }
1335 
1336  unsigned char const *end() const
1337  {
1338  return hit + nhit;
1339  }
1340 
1341  unsigned char *begin()
1342  {
1343  return hit;
1344  }
1345 
1346  unsigned char *end()
1347  {
1348  return hit + nhit;
1349  }
1350 
1351  int size() const
1352  {
1353  return nhit;
1354  }
1355 
1356  unsigned char operator[](int i) const
1357  {
1358  return hit[i];
1359  }
1360 
1361  PatternSet() : nhit(0) {}
1362 
1364  {
1365  fill(category, hp);
1366  }
1367 
1369  {
1370  int lhit = 0;
1371  auto unpack = [&lhit, this](uint16_t pattern) -> bool {
1372  unsigned char p = 255 & (pattern >> 3);
1373  hit[lhit++] = p;
1374 
1375  // bouble sort
1376  if (lhit > 1) {
1377  for (auto h = hit + lhit - 1; h != hit; --h) {
1378  if ((*(h - 1)) <= p) {
1379  break;
1380  }
1381  (*h) = *(h - 1);
1382  *(h - 1) = p;
1383  }
1384  }
1385  return lhit < MaxHits;
1386  };
1387 
1388  hp.call(category, HitPattern::validHitFilter, unpack);
1389  nhit = lhit;
1390  }
1391 };
1392 
1393 template<int N>
1395 {
1396  PatternSet<N> comm;
1397  comm.nhit = std::set_intersection(p1.begin(), p1.end(), p2.begin(), p2.end(), comm.begin()) - comm.begin();
1398  return comm;
1399 }
1400 
1401 } // namespace reco
1402 
1403 #endif
1404 
unsigned char const * begin() const
Definition: HitPattern.h:1331
unsigned char const * end() const
Definition: HitPattern.h:1336
static constexpr int GEM
Definition: MuonSubdetId.h:15
PatternSet< N > commonHits(PatternSet< N > const &p1, PatternSet< N > const &p2)
Definition: HitPattern.h:1394
FWCore Framework interface EventSetupRecordImplementation h
Helper function to determine trigger accepts.
void call(HitCategory category, filterType typeFilter, F f) const
Definition: HitPattern.h:577
unsigned char nhit
Definition: HitPattern.h:1329
#define LIKELY(x)
Definition: Likely.h:20
S & print(S &os, JobReport::InputFile const &f)
Definition: JobReport.cc:66
bool filterType(uint16_t)
Definition: HitPattern.h:493
uint8_t endInner
Definition: HitPattern.h:516
unsigned char * begin()
Definition: HitPattern.h:1341
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:1351
const std::complex< double > I
Definition: I.h:8
double f[11][100]
static constexpr int ME0
Definition: MuonSubdetId.h:16
uint8_t beginInner
Definition: HitPattern.h:515
#define end
Definition: vmac.h:39
double p2[4]
Definition: TauolaWrapper.h:90
uint8_t beginTrackHits
Definition: HitPattern.h:513
unsigned char * end()
Definition: HitPattern.h:1346
Definition: DetId.h:18
uint8_t endTrackHits
Definition: HitPattern.h:514
double const BAD
Definition: Constants.h:15
#define N
Definition: blowfish.cc:9
uint8_t hitCount
Definition: HitPattern.h:511
uint8_t beginOuter
Definition: HitPattern.h:517
static constexpr int RPC
Definition: MuonSubdetId.h:14
def encode(args, files)
fixed size matrix
#define begin
Definition: vmac.h:32
double p1[4]
Definition: TauolaWrapper.h:89
void fill(HitPattern::HitCategory category, HitPattern const &hp)
Definition: HitPattern.h:1368
static int position[264][3]
Definition: ReadPGInfo.cc:509
#define UNLIKELY(x)
Definition: Likely.h:21
static constexpr int DT
Definition: MuonSubdetId.h:12
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
static constexpr int CSC
Definition: MuonSubdetId.h:13
PatternSet(HitPattern::HitCategory category, HitPattern const &hp)
Definition: HitPattern.h:1363
uint8_t endOuter
Definition: HitPattern.h:518
void countHits(const reco::Muon &muon, std::vector< int > &numHitsDT, std::vector< int > &numHitsCSC, std::vector< int > &numHitsRPC)
unsigned char operator[](int i) const
Definition: HitPattern.h:1356
#define constexpr