CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
HitPattern.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 #ifndef TrackReco_HitPattern_h
3 #define TrackReco_HitPattern_h
4 
5 //
6 // File: DataFormats/TrackReco/interface/HitPattern.h
7 //
8 // Marcel Vos, INFN Pisa
9 // v1.10 2007/05/08 bellan
10 // Zongru Wan, Kansas State University
11 // Jean-Roch Vlimant
12 // Kevin Burkett
13 // Boris Mangano
14 //
15 // Hit pattern is the summary information of the hits associated to track in
16 // AOD. When RecHits are no longer available, the compact hit pattern should
17 // allow basic track selection based on the hits in various subdetectors. The
18 // hits of a track are saved in unit32_t hitPattern_[28], initialized as
19 // 0x00000000, ..., 0x00000000. Set one hit with 10 bits
20 //
21 // +-----+-----+-----+-----+-----+-----+-----+-----+----------------+-----+-----+
22 // |tk/mu| sub-structure | sub-sub-structure | stereo | hit type |
23 // +-----+-----+-----+-----+-----+-----+-----+-----+----------------+-----+-----+
24 // ... | 10 | 9 8 7 | 6 5 4 3 | 2 | 1 0 | bit
25 //
26 // |tk = 1 PXB = 1 layer = 1-3 hit type = 0-3
27 // |tk = 1 PXF = 2 disk = 1-2 hit type = 0-3
28 // |tk = 1 TIB = 3 layer = 1-4 0=rphi,1=stereo hit type = 0-3
29 // |tk = 1 TID = 4 wheel = 1-3 0=rphi,1=stereo hit type = 0-3
30 // |tk = 1 TOB = 5 layer = 1-6 0=rphi,1=stereo hit type = 0-3
31 // |tk = 1 TEC = 6 wheel = 1-9 0=rphi,1=stereo hit type = 0-3
32 // |mu = 0 DT = 1 4*(stat-1)+superlayer hit type = 0-3
33 // |mu = 0 CSC = 2 4*(stat-1)+(ring-1) hit type = 0-3
34 // |mu = 0 RPC = 3 4*(stat-1)+2*layer+region hit type = 0-3
35 //
36 // hit type, see DataFormats/TrackingRecHit/interface/TrackingRecHit.h
37 // valid = valid hit = 0
38 // missing = detector is good, but no rec hit found = 1
39 // inactive = detector is off, so there was no hope = 2
40 // bad = there were many bad strips within the ellipse = 3
41 //
42 // The maximum number of hits = 32*28/11 = 81. It had been shown by Zongru
43 // using a 100 GeV muon sample with 5000 events uniform in eta and phi, the
44 // average (maximum) number of tracker hits is 13 (17) and the average
45 // (maximum) number of muon detector hits is about 26 (50). If the number of
46 // hits of a track is larger than 80 then the extra hits are ignored by hit
47 // pattern. The static hit pattern array might be improved to a dynamic one
48 // in the future.
49 //
50 // Because of tracking with/without overlaps and with/without hit-splitting,
51 // the final number of hits per track is pretty "variable". Compared with the
52 // number of valid hits, the number of crossed layers with measurement should
53 // be more robust to discriminate between good and fake track.
54 //
55 // Since 4-bit for sub-sub-structure is not enough to specify a muon layer,
56 // the layer case counting methods are implemented for tracker only. This is
57 // different from the hit counting methods which are implemented for both
58 // tracker and muon detector.
59 //
60 // Given a tracker layer, specified by sub-structure and layer, the method
61 // getTrackerLayerCase(substr, layer) groups all of the hits in the hit pattern
62 // array for the layer together and returns one of the four cases
63 //
64 // crossed
65 // layer case 0: valid + (missing, off, bad) ==> with measurement
66 // layer case 1: missing + (off, bad) ==> without measurement
67 // layer case 2: off, bad ==> totally off or bad, cannot say much
68 // not crossed
69 // layer case 999999: track outside acceptance or in gap ==> null
70 //
71 // Given a tracker layer, specified by sub-structure and layer, the method
72 // getTrackerMonoStereo(substr, layer) groups all of the valid hits in the hit
73 // pattern array for the layer together and returns
74 //
75 // 0: neither a valid mono nor a valid stereo hit
76 // MONO: valid mono hit
77 // STEREO: valid stereo hit
78 // MONO | STEREO: both
79 //
80 // Given a track, here is an example usage of hit pattern
81 //
82 // // hit pattern of the track
83 // const reco::HitPattern& p = track->hitPattern();
84 //
85 // // loop over the hits of the track
86 // for (int i=0; i<p.numberOfHits(); i++) {
87 // uint32_t hit = p.getHitPattern(i);
88 //
89 // // if the hit is valid and in pixel barrel, print out the layer
90 // if (p.validHitFilter(hit) && p.pixelBarrelHitFilter(hit))
91 // std::cout << "valid hit found in pixel barrel layer "
92 // << p.getLayer(hit) << std::endl;
93 //
94 // // expert level: printout the hit in 10-bit binary format
95 // std::cout << "hit in 10-bit binary format = ";
96 // for (int j=9; j>=0; j--) {
97 // int bit = (hit >> j) & 0x1;
98 // std::cout << bit;
99 // }
100 // std::cout << std::endl;
101 // }
102 //
103 // // count the number of valid pixel barrel *** hits ***
104 // std::cout << "number of of valid pixel barrel hits is "
105 // << p.numberOfValidPixelBarrelHits() << std::endl;
106 //
107 // // count the number of pixel barrel *** layers *** with measurement
108 // std::cout << "number of of pixel barrel layers with measurement is "
109 // << p.pixelBarrelLayersWithMeasurement() << std::endl;
110 //
118 #include <algorithm>
119 #include <iostream>
120 #include <ostream>
121 
122 
123 namespace reco {
124  class HitPattern {
125  public:
126  enum { MONO = 1, STEREO = 2 };
127 
128  // number of 32 bit integers to store the full pattern
129  const static unsigned short PatternSize = 25;
130 
131  // number of bits used for each hit
132  const static unsigned short HitSize = 11;
133 
134  static const int MaxHits = (PatternSize * 32) / HitSize;
135 
136  // default constructor
137  // init hit pattern array as 0x00000000, ..., 0x00000000
138  HitPattern() { for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0; }
139 
140  // constructor from iterator (begin, end) pair
141  template<typename I>
142  HitPattern(const I & begin, const I & end) { set(begin, end); }
143 
144  // constructor from hit collection
145  template<typename C>
146  HitPattern(const C & c) { set(c); }
147 
148  // set pattern from iterator (begin, end) pair
149  // init hit pattern array as 0x00000000, ..., 0x00000000
150  // loop over the hits and set hit pattern
151  template<typename I>
152  void set(const I & begin, const I & end) {
153  for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0;
154  unsigned int counter = 0;
155  for (I hit=begin; hit!=end && counter<32*PatternSize/HitSize;
156  hit++, counter++)
157  set(*hit, counter);
158  }
159 
160 
161  // generic count methods
162  typedef bool filterType(unsigned int);
164  int count = 0;
165  for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
166  uint32_t pattern = getHitPattern(i);
167  if (pattern == 0) break;
168  if (filter(pattern)) ++count;
169  }
170  return count;
171  }
172 
173  int countTypedHits(filterType typeFilter, filterType filter) const {
174  int count = 0;
175  for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
176  uint32_t pattern = getHitPattern(i);
177  if (pattern == 0) break;
178  if (typeFilter(pattern)&&filter(pattern)) ++count;
179  }
180  return count;
181  }
182 
183  template<typename F>
184  void call(filterType typeFilter, F f) const {
185  for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
186  uint32_t pattern = getHitPattern(i);
187  if (pattern == 0) break;
188  // f() return false to ask to stop looping
189  if (typeFilter(pattern) && !f(pattern) ) break;
190  }
191  }
192 
193  // print the pattern of the position-th hit
194  void printHitPattern (int position, std::ostream &stream) const;
195  void print (std::ostream &stream = std::cout) const;
196 
197  // set the pattern of the i-th hit
198  void set(const TrackingRecHit &hit, unsigned int i){setHitPattern(i, encode(hit,i));}
199 
200  // set the pattern of the i-th hit
201  void set(const DetId id, uint32_t hitType, unsigned int i) { setHitPattern(i, encode(id,hitType,i)); }
202 
203  // append a hit to the hit pattern
204  void appendHit(const TrackingRecHit & hit);
205 
206  // get the pattern of the position-th hit
207  uint32_t getHitPattern(int position) const;
208 
209  static bool trackerHitFilter(uint32_t pattern); // tracker hit
210  static bool muonHitFilter(uint32_t pattern); // muon hit
211 
212  static uint32_t getSubStructure(uint32_t pattern); // sub-structure
213  static bool pixelHitFilter(uint32_t pattern); // pixel
214  static bool pixelBarrelHitFilter(uint32_t pattern); // pixel barrel
215  static bool pixelEndcapHitFilter(uint32_t pattern); // pixel endcap
216  static bool stripHitFilter(uint32_t pattern); // strip
217  static bool stripTIBHitFilter(uint32_t pattern); // strip TIB
218  static bool stripTIDHitFilter(uint32_t pattern); // strip TID
219  static bool stripTOBHitFilter(uint32_t pattern); // strip TOB
220  static bool stripTECHitFilter(uint32_t pattern); // strip TEC
221  static bool muonDTHitFilter(uint32_t pattern); // muon DT
222  static bool muonCSCHitFilter(uint32_t pattern); // muon CSC
223  static bool muonRPCHitFilter(uint32_t pattern); // muon RPC
224 
225  static uint32_t getLayer(uint32_t pattern); // sub-sub-structure
226  static uint32_t getSubSubStructure(uint32_t pattern); // sub-sub-structure
227 
229  static uint32_t getMuonStation(uint32_t pattern); // only for patterns from muon, of course
231  static uint32_t getDTSuperLayer(uint32_t pattern); // only for DT patterns
233  static uint32_t getCSCRing(uint32_t pattern) ;
235  static uint32_t getRPCLayer(uint32_t pattern) ;
237  static uint32_t getRPCregion(uint32_t pattern);
238 
239  static uint32_t getHitType(uint32_t pattern); // hit type
240  static bool validHitFilter(uint32_t pattern); // hit type 0 = valid
241  static bool type_1_HitFilter(uint32_t pattern); // hit type 1
242  static bool type_2_HitFilter(uint32_t pattern); // hit type 2
243  static bool type_3_HitFilter(uint32_t pattern); // hit type 3
244 
245  static uint32_t getSide (uint32_t pattern); // mono (0) or stereo (1)
246 
247  bool hasValidHitInFirstPixelBarrel() const; // has valid hit in PXB layer 1
248  bool hasValidHitInFirstPixelEndcap() const; // has valid hit in PXF layer 1
249 
250  int numberOfHits() const; // not-null
251  int numberOfValidHits() const; // not-null, valid
252  int numberOfValidTrackerHits() const; // not-null, valid, tracker
253  int numberOfValidMuonHits() const; // not-null, valid, muon
254  int numberOfValidPixelHits() const; // not-null, valid, pixel
255  int numberOfValidPixelBarrelHits() const; // not-null, valid, pixel PXB
256  int numberOfValidPixelEndcapHits() const; // not-null, valid, pixel PXF
257  int numberOfValidStripHits() const; // not-null, valid, strip
258  int numberOfValidStripTIBHits() const; // not-null, valid, strip TIB
259  int numberOfValidStripTIDHits() const; // not-null, valid, strip TID
260  int numberOfValidStripTOBHits() const; // not-null, valid, strip TOB
261  int numberOfValidStripTECHits() const; // not-null, valid, strip TEC
262  int numberOfValidMuonDTHits() const; // not-null, valid, muon DT
263  int numberOfValidMuonCSCHits() const; // not-null, valid, muon CSC
264  int numberOfValidMuonRPCHits() const; // not-null, valid, muon RPC
265  int numberOfLostHits() const; // not-null, not valid
266  int numberOfLostTrackerHits() const; // not-null, not valid, tracker
267  int numberOfLostMuonHits() const; // not-null, not valid, muon
268  int numberOfLostPixelHits() const; // not-null, not valid, pixel
269  int numberOfLostPixelBarrelHits() const; // not-null, not valid, pixel PXB
270  int numberOfLostPixelEndcapHits() const; // not-null, not valid, pixel PXF
271  int numberOfLostStripHits() const; // not-null, not valid, strip
272  int numberOfLostStripTIBHits() const; // not-null, not valid, strip TIB
273  int numberOfLostStripTIDHits() const; // not-null, not valid, strip TID
274  int numberOfLostStripTOBHits() const; // not-null, not valid, strip TOB
275  int numberOfLostStripTECHits() const; // not-null, not valid, strip TEC
276  int numberOfLostMuonDTHits() const; // not-null, not valid, muon DT
277  int numberOfLostMuonCSCHits() const; // not-null, not valid, muon CSC
278  int numberOfLostMuonRPCHits() const; // not-null, not valid, muon RPC
279  int numberOfBadHits() const; // not-null, bad (only used in Muon Ch.)
280  int numberOfBadMuonHits() const; // not-null, bad, muon
281  int numberOfBadMuonDTHits() const; // not-null, bad, muon DT
282  int numberOfBadMuonCSCHits() const; // not-null, bad, muon CSC
283  int numberOfBadMuonRPCHits() const; // not-null, bad, muon RPC
284  int numberOfInactiveHits() const; // not-null, inactive
285  int numberOfInactiveTrackerHits() const; // not-null, inactive, tracker
286 
287  int numberOfValidStripLayersWithMonoAndStereo (uint32_t stripdet, uint32_t layer)
288  const; // count strip layers that have non-null, valid mono and stereo hits
289 
291  const {return numberOfValidStripLayersWithMonoAndStereo(0,0);}
292 
293  int numberOfValidTOBLayersWithMonoAndStereo (uint32_t layer = 0)
295  int numberOfValidTIBLayersWithMonoAndStereo (uint32_t layer = 0)
297  int numberOfValidTIDLayersWithMonoAndStereo (uint32_t layer = 0)
299  int numberOfValidTECLayersWithMonoAndStereo (uint32_t layer = 0)
301 
302  uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const;
303  uint32_t getTrackerMonoStereo (uint32_t substr, uint32_t layer) const;
304 
305  int trackerLayersWithMeasurement() const; // case 0: tracker
306  int pixelLayersWithMeasurement() const; // case 0: pixel
307  int stripLayersWithMeasurement() const; // case 0: strip
308  int pixelBarrelLayersWithMeasurement() const; // case 0: pixel PXB
309  int pixelEndcapLayersWithMeasurement() const; // case 0: pixel PXF
310  int stripTIBLayersWithMeasurement() const; // case 0: strip TIB
311  int stripTIDLayersWithMeasurement() const; // case 0: strip TID
312  int stripTOBLayersWithMeasurement() const; // case 0: strip TOB
313  int stripTECLayersWithMeasurement() const; // case 0: strip TEC
314  int trackerLayersWithoutMeasurement() const; // case 1: tracker
315  int pixelLayersWithoutMeasurement() const; // case 1: pixel
316  int stripLayersWithoutMeasurement() const; // case 1: strip
317  int pixelBarrelLayersWithoutMeasurement() const; // case 1: pixel PXB
318  int pixelEndcapLayersWithoutMeasurement() const; // case 1: pixel PXF
319  int stripTIBLayersWithoutMeasurement() const; // case 1: strip TIB
320  int stripTIDLayersWithoutMeasurement() const; // case 1: strip TID
321  int stripTOBLayersWithoutMeasurement() const; // case 1: strip TOB
322  int stripTECLayersWithoutMeasurement() const; // case 1: strip TEC
323  int trackerLayersTotallyOffOrBad() const; // case 2: tracker
324  int pixelLayersTotallyOffOrBad() const; // case 2: pixel
325  int stripLayersTotallyOffOrBad() const; // case 2: strip
326  int pixelBarrelLayersTotallyOffOrBad() const; // case 2: pixel PXB
327  int pixelEndcapLayersTotallyOffOrBad() const; // case 2: pixel PXF
328  int stripTIBLayersTotallyOffOrBad() const; // case 2: strip TIB
329  int stripTIDLayersTotallyOffOrBad() const; // case 2: strip TID
330  int stripTOBLayersTotallyOffOrBad() const; // case 2: strip TOB
331  int stripTECLayersTotallyOffOrBad() const; // case 2: strip TEC
332  int trackerLayersNull() const; // case 999999: tracker
333  int pixelLayersNull() const; // case 999999: pixel
334  int stripLayersNull() const; // case 999999: strip
335  int pixelBarrelLayersNull() const; // case 999999: pixel PXB
336  int pixelEndcapLayersNull() const; // case 999999: pixel PXF
337  int stripTIBLayersNull() const; // case 999999: strip TIB
338  int stripTIDLayersNull() const; // case 999999: strip TID
339  int stripTOBLayersNull() const; // case 999999: strip TOB
340  int stripTECLayersNull() const; // case 999999: strip TEC
341 
342 
343 
345  int muonStations(int subdet, int hitType) const ;
346 
347  int muonStationsWithValidHits() const ;
348  int muonStationsWithBadHits() const ;
349  int muonStationsWithAnyHits() const ;
350  int dtStationsWithValidHits() const ;
351  int dtStationsWithBadHits() const ;
352  int dtStationsWithAnyHits() const ;
353  int cscStationsWithValidHits() const ;
354  int cscStationsWithBadHits() const ;
355  int cscStationsWithAnyHits() const ;
356  int rpcStationsWithValidHits() const ;
357  int rpcStationsWithBadHits() const ;
358  int rpcStationsWithAnyHits() const ;
359 
361  int innermostMuonStationWithHits(int hitType) const ;
363  int innermostMuonStationWithBadHits() const ;
364  int innermostMuonStationWithAnyHits() const ;
365 
367  int outermostMuonStationWithHits(int hitType) const ;
369  int outermostMuonStationWithBadHits() const ;
370  int outermostMuonStationWithAnyHits() const ;
371 
372  int numberOfDTStationsWithRPhiView() const ;
373  int numberOfDTStationsWithRZView() const ;
374  int numberOfDTStationsWithBothViews() const ;
375 
376  private:
377 
378 
379  // 1 bit to distinguish tracker and muon subsystems
380  const static unsigned short SubDetectorOffset = 10;
381  const static unsigned short SubDetectorMask = 0x1;
382 
383  // 3 bits to identify the tracker/muon detector substructure
384  const static unsigned short SubstrOffset = 7;
385  const static unsigned short SubstrMask = 0x7;
386 
387  // 4 bits to identify the layer/disk/wheel within the substructure
388  const static unsigned short LayerOffset = 3;
389  const static unsigned short LayerMask = 0xF;
390 
391  // 1 bit to identify the side in double-sided detectors
392  const static unsigned short SideOffset = 2;
393  const static unsigned short SideMask = 0x1;
394 
395  // 2 bits for hit type
396  const static unsigned short HitTypeOffset = 0;
397  const static unsigned short HitTypeMask = 0x3;
398 
399  // full hit pattern information is packed in PatternSize 32 bit words
400  uint32_t hitPattern_[ PatternSize ];
401 
402  // set pattern for position-th hit
403  void setHitPattern(int position, uint32_t pattern);
404 
405  // set pattern for i-th hit passing a reference
406  void set(const TrackingRecHitRef & ref, unsigned int i) { set(* ref, i); }
407 
408  // detector side for tracker modules (mono/stereo)
409  static uint32_t isStereo (DetId);
410 
411  // encoder for pattern
412  uint32_t encode(const TrackingRecHit &hit, unsigned int i) { return encode(hit.geographicalId(), hit.getType(), i); }
413  // encoder for pattern
414  uint32_t encode(DetId id, uint32_t hitType, unsigned int i) ;
415  };
416 
417  // inline function
418 
419  inline bool HitPattern::pixelHitFilter(uint32_t pattern) {
420  if unlikely(!trackerHitFilter(pattern)) return false;
421  uint32_t substructure = getSubStructure(pattern);
422  if (substructure == PixelSubdetector::PixelBarrel ||
423  substructure == PixelSubdetector::PixelEndcap) return true;
424  return false;
425  }
426 
427  inline bool HitPattern::pixelBarrelHitFilter(uint32_t pattern) {
428  if unlikely(!trackerHitFilter(pattern)) return false;
429  uint32_t substructure = getSubStructure(pattern);
430  if (substructure == PixelSubdetector::PixelBarrel) return true;
431  return false;
432  }
433 
434  inline bool HitPattern::pixelEndcapHitFilter(uint32_t pattern) {
435  if unlikely(!trackerHitFilter(pattern)) return false;
436  uint32_t substructure = getSubStructure(pattern);
437  if (substructure == PixelSubdetector::PixelEndcap) return true;
438  return false;
439  }
440 
441  inline bool HitPattern::stripHitFilter(uint32_t pattern) {
442  if unlikely(!trackerHitFilter(pattern)) return false;
443  uint32_t substructure = getSubStructure(pattern);
444  if (substructure == StripSubdetector::TIB ||
445  substructure == StripSubdetector::TID ||
446  substructure == StripSubdetector::TOB ||
447  substructure == StripSubdetector::TEC) return true;
448  return false;
449  }
450 
451  inline bool HitPattern::stripTIBHitFilter(uint32_t pattern) {
452  if unlikely(!trackerHitFilter(pattern)) return false;
453  uint32_t substructure = getSubStructure(pattern);
454  if (substructure == StripSubdetector::TIB) return true;
455  return false;
456  }
457 
458  inline bool HitPattern::stripTIDHitFilter(uint32_t pattern) {
459  if unlikely(!trackerHitFilter(pattern)) return false;
460  uint32_t substructure = getSubStructure(pattern);
461  if (substructure == StripSubdetector::TID) return true;
462  return false;
463  }
464 
465  inline bool HitPattern::stripTOBHitFilter(uint32_t pattern) {
466  if unlikely(!trackerHitFilter(pattern)) return false;
467  uint32_t substructure = getSubStructure(pattern);
468  if (substructure == StripSubdetector::TOB) return true;
469  return false;
470  }
471 
472  inline bool HitPattern::stripTECHitFilter(uint32_t pattern) {
473  if unlikely(!trackerHitFilter(pattern)) return false;
474  uint32_t substructure = getSubStructure(pattern);
475  if (substructure == StripSubdetector::TEC) return true;
476  return false;
477  }
478 
479  inline bool HitPattern::muonDTHitFilter(uint32_t pattern) {
480  if unlikely(!muonHitFilter(pattern)) return false;
481  uint32_t substructure = getSubStructure(pattern);
482  if (substructure == (uint32_t) MuonSubdetId::DT) return true;
483  return false;
484  }
485 
486  inline bool HitPattern::muonCSCHitFilter(uint32_t pattern) {
487  if unlikely(!muonHitFilter(pattern)) return false;
488  uint32_t substructure = getSubStructure(pattern);
489  if (substructure == (uint32_t) MuonSubdetId::CSC) return true;
490  return false;
491  }
492 
493  inline bool HitPattern::muonRPCHitFilter(uint32_t pattern) {
494  if unlikely(!muonHitFilter(pattern)) return false;
495  uint32_t substructure = getSubStructure(pattern);
496  if (substructure == (uint32_t) MuonSubdetId::RPC) return true;
497  return false;
498  }
499 
500 
501  inline bool HitPattern::trackerHitFilter(uint32_t pattern) {
502  if unlikely(pattern == 0) return false;
503  if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 1) return true;
504  return false;
505  }
506 
507  inline bool HitPattern::muonHitFilter(uint32_t pattern) {
508  if unlikely(pattern == 0) return false;
509  if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 0) return true;
510  return false;
511  }
512 
513 
514  inline uint32_t HitPattern::getSubStructure(uint32_t pattern) {
515  if unlikely(pattern == 0) return 999999;
516  return ((pattern >> SubstrOffset) & SubstrMask);
517  }
518 
519 
520  inline uint32_t HitPattern::getLayer(uint32_t pattern) {
521  if unlikely(pattern == 0) return 999999;
522  return ((pattern>>LayerOffset) & LayerMask);
523  }
524 
525  inline uint32_t HitPattern::getSubSubStructure(uint32_t pattern) {
526  if unlikely(pattern == 0) return 999999;
527  return ((pattern>>LayerOffset) & LayerMask);
528  }
529 
530 
531  inline uint32_t HitPattern::getSide (uint32_t pattern) {
532  if unlikely(pattern == 0) return 999999;
533  return (pattern >> SideOffset) & SideMask;
534  }
535 
536  inline uint32_t HitPattern::getHitType( uint32_t pattern ) {
537  if unlikely(pattern == 0) return 999999;
538  return ((pattern>>HitTypeOffset) & HitTypeMask);
539  }
540 
541  inline uint32_t HitPattern::getMuonStation(uint32_t pattern) {
542  return (getSubSubStructure(pattern)>>2) + 1;
543  }
544 
545  inline uint32_t HitPattern::getDTSuperLayer(uint32_t pattern) {
546  return (getSubSubStructure(pattern) & 3);
547  }
548 
549  inline uint32_t HitPattern::getCSCRing(uint32_t pattern) {
550  return (getSubSubStructure(pattern) & 3) + 1;
551  }
552 
553  inline uint32_t HitPattern::getRPCLayer(uint32_t pattern) {
554  uint32_t sss = getSubSubStructure(pattern), stat = sss >> 2;
555  if likely(stat <= 1) return ((sss >> 1) & 1) + 1;
556  return 0;
557  }
558 
559  inline uint32_t HitPattern::getRPCregion(uint32_t pattern) {
560  return getSubSubStructure(pattern) & 1;
561  }
562 
563 
564  inline bool HitPattern::validHitFilter(uint32_t pattern) {
565  if (getHitType(pattern) == 0) return true;
566  return false;
567  }
568 
569  inline bool HitPattern::type_1_HitFilter(uint32_t pattern) {
570  if (getHitType(pattern) == 1) return true;
571  return false;
572  }
573 
574  inline bool HitPattern::type_2_HitFilter(uint32_t pattern) {
575  if (getHitType(pattern) == 2) return true;
576  return false;
577  }
578 
579  inline bool HitPattern::type_3_HitFilter(uint32_t pattern) {
580  if (getHitType(pattern) == 3) return true;
581  return false;
582  }
583 
584 
585  // count methods
586 
587 // valid
588 
589 inline int HitPattern::numberOfValidHits() const {
590  return countHits(validHitFilter);
591 }
592 
595 }
596 
599 }
600 
603 }
604 
607 }
608 
611 }
612 
615 }
616 
619 }
620 
623 }
624 
627 }
628 
631 }
632 
635 }
636 
639 }
640 
643 }
644 
645 // lost
646 inline int HitPattern::numberOfLostHits() const {
647  return countHits(type_1_HitFilter);
648 }
649 
652 }
653 
656 }
657 
660 }
661 
664 }
665 
668 }
669 
672 }
673 
676 }
677 
680 }
681 
684 }
685 
688 }
689 
692 }
693 
696 }
697 
700 }
701 
702 
703 // bad
704 inline int HitPattern::numberOfBadHits() const {
705  return countHits(type_3_HitFilter);
706 }
707 
710 }
711 
714 }
715 
718 }
719 
722 }
723 
724 
725 // inactive
727  return countHits(type_2_HitFilter);
728 }
729 
732 }
733 
734 
735 
736 
737 
738 
739 
741  return pixelLayersWithMeasurement() +
743  }
744 
748  }
749 
755  }
756 
757 
761  }
762 
766  }
767 
773  }
774 
775 
777  return pixelLayersTotallyOffOrBad() +
779  }
780 
784  }
785 
791  }
792 
793  inline int HitPattern::trackerLayersNull() const {
794  return pixelLayersNull() +
795  stripLayersNull();
796  }
797 
798  inline int HitPattern::pixelLayersNull() const {
799  return pixelBarrelLayersNull() +
801  }
802 
803  inline int HitPattern::stripLayersNull() const {
804  return stripTIBLayersNull() +
806  stripTOBLayersNull() +
808  }
809 
810 
811  inline int HitPattern::muonStationsWithValidHits() const { return muonStations(0, 0); }
812  inline int HitPattern::muonStationsWithBadHits() const { return muonStations(0, 3); }
813  inline int HitPattern::muonStationsWithAnyHits() const { return muonStations(0,-1); }
814  inline int HitPattern::dtStationsWithValidHits() const { return muonStations(1, 0); }
815  inline int HitPattern::dtStationsWithBadHits() const { return muonStations(1, 3); }
816  inline int HitPattern::dtStationsWithAnyHits() const { return muonStations(1,-1); }
817  inline int HitPattern::cscStationsWithValidHits() const { return muonStations(2, 0); }
818  inline int HitPattern::cscStationsWithBadHits() const { return muonStations(2, 3); }
819  inline int HitPattern::cscStationsWithAnyHits() const { return muonStations(2,-1); }
820  inline int HitPattern::rpcStationsWithValidHits() const { return muonStations(3, 0); }
821  inline int HitPattern::rpcStationsWithBadHits() const { return muonStations(3, 3); }
822  inline int HitPattern::rpcStationsWithAnyHits() const { return muonStations(3,-1); }
823 
830 
831 #ifndef CMS_NOCXX11 // cint....
832 
833  template<int N=reco::HitPattern::MaxHits>
834  struct PatternSet {
835  static constexpr int MaxHits=N;
836  unsigned char hit[N];
837  unsigned char nhit;
838 
839  unsigned char const * begin() const { return hit;}
840  unsigned char const * end() const { return hit+nhit;}
841  unsigned char * begin() { return hit;}
842  unsigned char * end() { return hit+nhit;}
843  int size() const { return nhit;}
844  unsigned char operator[](int i) const{ return hit[i];}
845 
846  PatternSet(): nhit(0){}
847  PatternSet(reco::HitPattern const & hp) {
848  fill(hp);
849  }
850 
851  void fill(reco::HitPattern const & hp) {
852  int lhit=0;
853  auto unpack =[&lhit,this](uint32_t pattern) -> bool {
854  unsigned char p = 255&(pattern>>3);
855  hit[lhit++]= p;
856 
857  // bouble sort
858  if (lhit>1)
859  for (auto h=hit+lhit-1; h!=hit; --h) {
860  if ( (*(h-1)) <= p) break; // { (*h)=p;break;}
861  (*h)=*(h-1); *(h-1)=p;
862  }
863  return lhit<MaxHits;
864  };
866  nhit=lhit;
867  }
868  };
869 
870  template<int N>
871  inline PatternSet<N> commonHits(PatternSet<N> const & p1, PatternSet<N> const & p2) {
872  PatternSet<N> comm;
873  comm.nhit = std::set_intersection(p1.begin(),p1.end(),p2.begin(),p2.end(),comm.begin())-comm.begin();
874  return comm;
875 }
876 #endif // gcc11
877 
878 } // namespace reco
879 
880 #endif
int stripTOBLayersWithMeasurement() const
Definition: HitPattern.cc:374
int countTypedHits(filterType typeFilter, filterType filter) const
Definition: HitPattern.h:173
int i
Definition: DBlmapReader.cc:9
int cscStationsWithAnyHits() const
Definition: HitPattern.h:819
static uint32_t getRPCLayer(uint32_t pattern)
RPC layer: for station 1 and 2, layer = 1(inner) or 2(outer); for station 3, 4 layer is always 0...
Definition: HitPattern.h:553
int outermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:671
int outermostMuonStationWithValidHits() const
Definition: HitPattern.h:827
static uint32_t getDTSuperLayer(uint32_t pattern)
DT superlayer (1-3). Where the &quot;hit&quot; was a DT segment, superlayer is 0. Only valid for muon DT patter...
Definition: HitPattern.h:545
string fill
Definition: lumiContext.py:319
int pixelBarrelLayersNull() const
Definition: HitPattern.cc:507
int stripTIBLayersNull() const
Definition: HitPattern.cc:527
int numberOfInactiveHits() const
Definition: HitPattern.h:726
int numberOfValidTECLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.h:299
static uint32_t getLayer(uint32_t pattern)
Definition: HitPattern.h:520
void appendHit(const TrackingRecHit &hit)
Definition: HitPattern.cc:86
static uint32_t isStereo(DetId)
Definition: HitPattern.cc:605
static uint32_t getCSCRing(uint32_t pattern)
CSC ring (1-4). Only valid for muon CSC patterns, of course.
Definition: HitPattern.h:549
uint32_t hitPattern_[PatternSize]
Definition: HitPattern.h:400
int stripTIBLayersWithMeasurement() const
Definition: HitPattern.cc:356
int stripTECLayersNull() const
Definition: HitPattern.cc:554
static const unsigned short SideOffset
Definition: HitPattern.h:392
void set(const TrackingRecHit &hit, unsigned int i)
Definition: HitPattern.h:198
int muonStations(int subdet, int hitType) const
subdet = 0(all), 1(DT), 2(CSC), 3(RPC); hitType=-1(all), 0=valid, 3=bad
Definition: HitPattern.cc:642
static uint32_t getSubSubStructure(uint32_t pattern)
Definition: HitPattern.h:525
int pixelLayersWithoutMeasurement() const
Definition: HitPattern.h:763
int numberOfLostTrackerHits() const
Definition: HitPattern.h:650
static bool muonDTHitFilter(uint32_t pattern)
Definition: HitPattern.h:479
static const unsigned short SubstrOffset
Definition: HitPattern.h:384
int numberOfValidHits() const
Definition: HitPattern.h:589
static bool trackerHitFilter(uint32_t pattern)
Definition: HitPattern.h:501
uint32_t getTrackerMonoStereo(uint32_t substr, uint32_t layer) const
Definition: HitPattern.cc:293
int numberOfLostHits() const
Definition: HitPattern.h:646
int numberOfDTStationsWithRPhiView() const
Definition: HitPattern.cc:686
int numberOfBadHits() const
Definition: HitPattern.h:704
int cscStationsWithValidHits() const
Definition: HitPattern.h:817
int pixelLayersNull() const
Definition: HitPattern.h:798
int numberOfLostPixelHits() const
Definition: HitPattern.h:658
int pixelLayersWithMeasurement() const
Definition: HitPattern.h:745
int trackerLayersWithoutMeasurement() const
Definition: HitPattern.h:758
int numberOfValidStripHits() const
Definition: HitPattern.h:613
static uint32_t getHitType(uint32_t pattern)
Definition: HitPattern.h:536
int numberOfValidTOBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.h:293
int stripTIDLayersWithoutMeasurement() const
Definition: HitPattern.cc:422
int rpcStationsWithValidHits() const
Definition: HitPattern.h:820
HitPattern(const C &c)
Definition: HitPattern.h:146
static bool type_2_HitFilter(uint32_t pattern)
Definition: HitPattern.h:574
static uint32_t getMuonStation(uint32_t pattern)
Muon station (1-4). Only valid for muon patterns, of course.
Definition: HitPattern.h:541
void set(const I &begin, const I &end)
Definition: HitPattern.h:152
void print(std::ostream &stream=std::cout) const
Definition: HitPattern.cc:590
int numberOfValidTIDLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.h:297
static const unsigned short PatternSize
Definition: HitPattern.h:129
int pixelBarrelLayersWithoutMeasurement() const
Definition: HitPattern.cc:393
static bool stripTECHitFilter(uint32_t pattern)
Definition: HitPattern.h:472
int numberOfLostMuonHits() const
Definition: HitPattern.h:654
static const unsigned short HitTypeMask
Definition: HitPattern.h:397
int pixelEndcapLayersWithMeasurement() const
Definition: HitPattern.cc:346
int numberOfValidTIBLayersWithMonoAndStereo(uint32_t layer=0) const
Definition: HitPattern.h:295
int numberOfValidStripTOBHits() const
Definition: HitPattern.h:625
#define constexpr
int numberOfValidMuonCSCHits() const
Definition: HitPattern.h:637
void call(filterType typeFilter, F f) const
Definition: HitPattern.h:184
int numberOfValidMuonRPCHits() const
Definition: HitPattern.h:641
bool hasValidHitInFirstPixelEndcap() const
Definition: HitPattern.cc:196
static bool stripTIDHitFilter(uint32_t pattern)
Definition: HitPattern.h:458
int muonStationsWithBadHits() const
Definition: HitPattern.h:812
int numberOfLostStripTECHits() const
Definition: HitPattern.h:686
#define unlikely(x)
void set(const DetId id, uint32_t hitType, unsigned int i)
Definition: HitPattern.h:201
static bool muonHitFilter(uint32_t pattern)
Definition: HitPattern.h:507
int stripLayersNull() const
Definition: HitPattern.h:803
#define likely(x)
int muonStationsWithValidHits() const
Definition: HitPattern.h:811
static const int CSC
Definition: MuonSubdetId.h:13
int stripTOBLayersTotallyOffOrBad() const
Definition: HitPattern.cc:488
int rpcStationsWithBadHits() const
Definition: HitPattern.h:821
int stripLayersWithoutMeasurement() const
Definition: HitPattern.h:768
int innermostMuonStationWithAnyHits() const
Definition: HitPattern.h:826
int trackerLayersTotallyOffOrBad() const
Definition: HitPattern.h:776
int numberOfValidPixelBarrelHits() const
Definition: HitPattern.h:605
int stripTIDLayersTotallyOffOrBad() const
Definition: HitPattern.cc:479
static bool type_1_HitFilter(uint32_t pattern)
Definition: HitPattern.h:569
int numberOfLostPixelEndcapHits() const
Definition: HitPattern.h:666
int stripTIDLayersWithMeasurement() const
Definition: HitPattern.cc:365
int trackerLayersWithMeasurement() const
Definition: HitPattern.h:740
susybsm::HSCParticleRefProd hp
Definition: classes.h:27
static const unsigned short SubDetectorMask
Definition: HitPattern.h:381
int numberOfLostStripTIDHits() const
Definition: HitPattern.h:678
int muonStationsWithAnyHits() const
Definition: HitPattern.h:813
static const int MaxHits
Definition: HitPattern.h:134
static bool pixelHitFilter(uint32_t pattern)
Definition: HitPattern.h:419
int pixelLayersTotallyOffOrBad() const
Definition: HitPattern.h:781
int stripTECLayersTotallyOffOrBad() const
Definition: HitPattern.cc:497
int numberOfHits() const
Definition: HitPattern.cc:211
static uint32_t getSubStructure(uint32_t pattern)
Definition: HitPattern.h:514
int numberOfBadMuonHits() const
Definition: HitPattern.h:708
int stripTIBLayersWithoutMeasurement() const
Definition: HitPattern.cc:413
T operator[](int i) const
int numberOfValidStripTIDHits() const
Definition: HitPattern.h:621
const std::complex< double > I
Definition: I.h:8
int numberOfDTStationsWithRZView() const
Definition: HitPattern.cc:698
double f[11][100]
static bool muonRPCHitFilter(uint32_t pattern)
Definition: HitPattern.h:493
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
static bool validHitFilter(uint32_t pattern)
Definition: HitPattern.h:564
int numberOfValidStripTECHits() const
Definition: HitPattern.h:629
#define end
Definition: vmac.h:37
int stripTIDLayersNull() const
Definition: HitPattern.cc:536
int numberOfLostMuonRPCHits() const
Definition: HitPattern.h:698
static const unsigned short HitTypeOffset
Definition: HitPattern.h:396
double p2[4]
Definition: TauolaWrapper.h:90
int numberOfBadMuonRPCHits() const
Definition: HitPattern.h:720
int dtStationsWithValidHits() const
Definition: HitPattern.h:814
int stripLayersTotallyOffOrBad() const
Definition: HitPattern.h:786
int cscStationsWithBadHits() const
Definition: HitPattern.h:818
int numberOfDTStationsWithBothViews() const
Definition: HitPattern.cc:710
static const unsigned short HitSize
Definition: HitPattern.h:132
static uint32_t getSide(uint32_t pattern)
Definition: HitPattern.h:531
int dtStationsWithAnyHits() const
Definition: HitPattern.h:816
int numberOfLostStripHits() const
Definition: HitPattern.h:670
Definition: DetId.h:18
int innermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:657
int numberOfInactiveTrackerHits() const
Definition: HitPattern.h:730
Type getType() const
static const unsigned short SideMask
Definition: HitPattern.h:393
#define N
Definition: blowfish.cc:9
int pixelEndcapLayersWithoutMeasurement() const
Definition: HitPattern.cc:403
int innermostMuonStationWithBadHits() const
Definition: HitPattern.h:825
static const unsigned short SubDetectorOffset
Definition: HitPattern.h:380
int trackerLayersNull() const
Definition: HitPattern.h:793
int stripLayersWithMeasurement() const
Definition: HitPattern.h:750
int pixelBarrelLayersWithMeasurement() const
Definition: HitPattern.cc:336
int numberOfBadMuonDTHits() const
Definition: HitPattern.h:712
static uint32_t getRPCregion(uint32_t pattern)
RPC region: 0 = barrel, 1 = endcap. Only valid for muon RPC patterns, of course.
Definition: HitPattern.h:559
int outermostMuonStationWithBadHits() const
Definition: HitPattern.h:828
int dtStationsWithBadHits() const
Definition: HitPattern.h:815
int numberOfValidStripTIBHits() const
Definition: HitPattern.h:617
int numberOfValidTrackerHits() const
Definition: HitPattern.h:593
int numberOfValidPixelEndcapHits() const
Definition: HitPattern.h:609
int stripTOBLayersNull() const
Definition: HitPattern.cc:545
uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const
Definition: HitPattern.cc:259
static bool type_3_HitFilter(uint32_t pattern)
Definition: HitPattern.h:579
int pixelBarrelLayersTotallyOffOrBad() const
Definition: HitPattern.cc:450
int numberOfLostMuonDTHits() const
Definition: HitPattern.h:690
#define begin
Definition: vmac.h:30
double p1[4]
Definition: TauolaWrapper.h:89
static const unsigned short SubstrMask
Definition: HitPattern.h:385
int numberOfBadMuonCSCHits() const
Definition: HitPattern.h:716
int numberOfLostStripTOBHits() const
Definition: HitPattern.h:682
static const int RPC
Definition: MuonSubdetId.h:14
static const unsigned short LayerOffset
Definition: HitPattern.h:388
int stripTECLayersWithoutMeasurement() const
Definition: HitPattern.cc:440
static std::atomic< unsigned int > counter
static int position[264][3]
Definition: ReadPGInfo.cc:509
int numberOfValidMuonDTHits() const
Definition: HitPattern.h:633
static bool stripHitFilter(uint32_t pattern)
Definition: HitPattern.h:441
int stripTECLayersWithMeasurement() const
Definition: HitPattern.cc:383
int stripTOBLayersWithoutMeasurement() const
Definition: HitPattern.cc:431
int pixelEndcapLayersTotallyOffOrBad() const
Definition: HitPattern.cc:460
int numberOfValidPixelHits() const
Definition: HitPattern.h:601
static bool pixelEndcapHitFilter(uint32_t pattern)
Definition: HitPattern.h:434
static bool muonCSCHitFilter(uint32_t pattern)
Definition: HitPattern.h:486
tuple cout
Definition: gather_cfg.py:121
static const int DT
Definition: MuonSubdetId.h:12
bool filterType(unsigned int)
Definition: HitPattern.h:162
void printHitPattern(int position, std::ostream &stream) const
Definition: HitPattern.cc:563
bool hasValidHitInFirstPixelBarrel() const
Definition: HitPattern.cc:181
DetId geographicalId() const
int numberOfValidMuonHits() const
Definition: HitPattern.h:597
static bool stripTOBHitFilter(uint32_t pattern)
Definition: HitPattern.h:465
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
int stripTIBLayersTotallyOffOrBad() const
Definition: HitPattern.cc:470
static const unsigned short LayerMask
Definition: HitPattern.h:389
int numberOfLostStripTIBHits() const
Definition: HitPattern.h:674
uint32_t getHitPattern(int position) const
Definition: HitPattern.cc:142
int rpcStationsWithAnyHits() const
Definition: HitPattern.h:822
int numberOfLostPixelBarrelHits() const
Definition: HitPattern.h:662
void set(const TrackingRecHitRef &ref, unsigned int i)
Definition: HitPattern.h:406
int numberOfValidStripLayersWithMonoAndStereo() const
Definition: HitPattern.h:290
int countHits(filterType filter) const
Definition: HitPattern.h:163
tuple size
Write out results.
static bool pixelBarrelHitFilter(uint32_t pattern)
Definition: HitPattern.h:427
int innermostMuonStationWithValidHits() const
Definition: HitPattern.h:824
int numberOfLostMuonCSCHits() const
Definition: HitPattern.h:694
int outermostMuonStationWithAnyHits() const
Definition: HitPattern.h:829
int pixelEndcapLayersNull() const
Definition: HitPattern.cc:517
void setHitPattern(int position, uint32_t pattern)
Definition: HitPattern.cc:77
static bool stripTIBHitFilter(uint32_t pattern)
Definition: HitPattern.h:451
HitPattern(const I &begin, const I &end)
Definition: HitPattern.h:142
uint32_t encode(const TrackingRecHit &hit, unsigned int i)
Definition: HitPattern.h:412