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 //
117 #include <algorithm>
118 #include <ostream>
119 
120 
121 namespace reco {
122  class HitPattern {
123  public:
124  enum { MONO = 1, STEREO = 2 };
125 
126  // number of 32 bit integers to store the full pattern
127  const static unsigned short PatternSize = 25;
128 
129  // number of bits used for each hit
130  const static unsigned short HitSize = 11;
131 
132  static const int MaxHits = (PatternSize * 32) / HitSize;
133 
134  // default constructor
135  // init hit pattern array as 0x00000000, ..., 0x00000000
136  HitPattern() { for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0; }
137 
138  // constructor from iterator (begin, end) pair
139  template<typename I>
140  HitPattern(const I & begin, const I & end) { set(begin, end); }
141 
142  // constructor from hit collection
143  template<typename C>
144  HitPattern(const C & c) { set(c); }
145 
146  // set pattern from iterator (begin, end) pair
147  // init hit pattern array as 0x00000000, ..., 0x00000000
148  // loop over the hits and set hit pattern
149  template<typename I>
150  void set(const I & begin, const I & end) {
151  for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0;
152  unsigned int counter = 0;
153  for (I hit=begin; hit!=end && counter<32*PatternSize/HitSize;
154  hit++, counter++)
155  set(*hit, counter);
156  }
157 
158 
159  // generic count methods
160  typedef bool filterType(unsigned int);
162  int count = 0;
163  for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
164  uint32_t pattern = getHitPattern(i);
165  if (pattern == 0) break;
166  if (filter(pattern)) ++count;
167  }
168  return count;
169  }
170 
171  int countTypedHits(filterType typeFilter, filterType filter) const {
172  int count = 0;
173  for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
174  uint32_t pattern = getHitPattern(i);
175  if (pattern == 0) break;
176  if (typeFilter(pattern)&&filter(pattern)) ++count;
177  }
178  return count;
179  }
180 
181  template<typename F>
182  void call(filterType typeFilter, F f) const {
183  for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
184  uint32_t pattern = getHitPattern(i);
185  if (pattern == 0) break;
186  // f() return false to ask to stop looping
187  if (typeFilter(pattern) && !f(pattern) ) break;
188  }
189  }
190 
191  // print the pattern of the position-th hit
192  void printHitPattern (int position, std::ostream &stream) const;
193  void print (std::ostream &stream = std::cout) const;
194 
195  // set the pattern of the i-th hit
196  void set(const TrackingRecHit &hit, unsigned int i){setHitPattern(i, encode(hit,i));}
197 
198  // append a hit to the hit pattern
199  void appendHit(const TrackingRecHit & hit);
200 
201  // get the pattern of the position-th hit
202  uint32_t getHitPattern(int position) const;
203 
204  static bool trackerHitFilter(uint32_t pattern); // tracker hit
205  static bool muonHitFilter(uint32_t pattern); // muon hit
206 
207  static uint32_t getSubStructure(uint32_t pattern); // sub-structure
208  static bool pixelHitFilter(uint32_t pattern); // pixel
209  static bool pixelBarrelHitFilter(uint32_t pattern); // pixel barrel
210  static bool pixelEndcapHitFilter(uint32_t pattern); // pixel endcap
211  static bool stripHitFilter(uint32_t pattern); // strip
212  static bool stripTIBHitFilter(uint32_t pattern); // strip TIB
213  static bool stripTIDHitFilter(uint32_t pattern); // strip TID
214  static bool stripTOBHitFilter(uint32_t pattern); // strip TOB
215  static bool stripTECHitFilter(uint32_t pattern); // strip TEC
216  static bool muonDTHitFilter(uint32_t pattern); // muon DT
217  static bool muonCSCHitFilter(uint32_t pattern); // muon CSC
218  static bool muonRPCHitFilter(uint32_t pattern); // muon RPC
219 
220  static uint32_t getLayer(uint32_t pattern); // sub-sub-structure
221  static uint32_t getSubSubStructure(uint32_t pattern); // sub-sub-structure
222 
224  static uint32_t getMuonStation(uint32_t pattern); // only for patterns from muon, of course
226  static uint32_t getDTSuperLayer(uint32_t pattern); // only for DT patterns
228  static uint32_t getCSCRing(uint32_t pattern) ;
230  static uint32_t getRPCLayer(uint32_t pattern) ;
232  static uint32_t getRPCregion(uint32_t pattern);
233 
234  static uint32_t getHitType(uint32_t pattern); // hit type
235  static bool validHitFilter(uint32_t pattern); // hit type 0 = valid
236  static bool type_1_HitFilter(uint32_t pattern); // hit type 1
237  static bool type_2_HitFilter(uint32_t pattern); // hit type 2
238  static bool type_3_HitFilter(uint32_t pattern); // hit type 3
239 
240  static uint32_t getSide (uint32_t pattern); // mono (0) or stereo (1)
241 
242  bool hasValidHitInFirstPixelBarrel() const; // has valid hit in PXB layer 1
243  bool hasValidHitInFirstPixelEndcap() const; // has valid hit in PXF layer 1
244 
245  int numberOfHits() const; // not-null
246  int numberOfValidHits() const; // not-null, valid
247  int numberOfValidTrackerHits() const; // not-null, valid, tracker
248  int numberOfValidMuonHits() const; // not-null, valid, muon
249  int numberOfValidPixelHits() const; // not-null, valid, pixel
250  int numberOfValidPixelBarrelHits() const; // not-null, valid, pixel PXB
251  int numberOfValidPixelEndcapHits() const; // not-null, valid, pixel PXF
252  int numberOfValidStripHits() const; // not-null, valid, strip
253  int numberOfValidStripTIBHits() const; // not-null, valid, strip TIB
254  int numberOfValidStripTIDHits() const; // not-null, valid, strip TID
255  int numberOfValidStripTOBHits() const; // not-null, valid, strip TOB
256  int numberOfValidStripTECHits() const; // not-null, valid, strip TEC
257  int numberOfValidMuonDTHits() const; // not-null, valid, muon DT
258  int numberOfValidMuonCSCHits() const; // not-null, valid, muon CSC
259  int numberOfValidMuonRPCHits() const; // not-null, valid, muon RPC
260  int numberOfLostHits() const; // not-null, not valid
261  int numberOfLostTrackerHits() const; // not-null, not valid, tracker
262  int numberOfLostMuonHits() const; // not-null, not valid, muon
263  int numberOfLostPixelHits() const; // not-null, not valid, pixel
264  int numberOfLostPixelBarrelHits() const; // not-null, not valid, pixel PXB
265  int numberOfLostPixelEndcapHits() const; // not-null, not valid, pixel PXF
266  int numberOfLostStripHits() const; // not-null, not valid, strip
267  int numberOfLostStripTIBHits() const; // not-null, not valid, strip TIB
268  int numberOfLostStripTIDHits() const; // not-null, not valid, strip TID
269  int numberOfLostStripTOBHits() const; // not-null, not valid, strip TOB
270  int numberOfLostStripTECHits() const; // not-null, not valid, strip TEC
271  int numberOfLostMuonDTHits() const; // not-null, not valid, muon DT
272  int numberOfLostMuonCSCHits() const; // not-null, not valid, muon CSC
273  int numberOfLostMuonRPCHits() const; // not-null, not valid, muon RPC
274  int numberOfBadHits() const; // not-null, bad (only used in Muon Ch.)
275  int numberOfBadMuonHits() const; // not-null, bad, muon
276  int numberOfBadMuonDTHits() const; // not-null, bad, muon DT
277  int numberOfBadMuonCSCHits() const; // not-null, bad, muon CSC
278  int numberOfBadMuonRPCHits() const; // not-null, bad, muon RPC
279  int numberOfInactiveHits() const; // not-null, inactive
280  int numberOfInactiveTrackerHits() const; // not-null, inactive, tracker
281 
282 
284  const; // count strip layers that have non-null, valid mono and stereo hits
285 
286  uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const;
287  uint32_t getTrackerMonoStereo (uint32_t substr, uint32_t layer) const;
288 
289  int trackerLayersWithMeasurement() const; // case 0: tracker
290  int pixelLayersWithMeasurement() const; // case 0: pixel
291  int stripLayersWithMeasurement() const; // case 0: strip
292  int pixelBarrelLayersWithMeasurement() const; // case 0: pixel PXB
293  int pixelEndcapLayersWithMeasurement() const; // case 0: pixel PXF
294  int stripTIBLayersWithMeasurement() const; // case 0: strip TIB
295  int stripTIDLayersWithMeasurement() const; // case 0: strip TID
296  int stripTOBLayersWithMeasurement() const; // case 0: strip TOB
297  int stripTECLayersWithMeasurement() const; // case 0: strip TEC
298  int trackerLayersWithoutMeasurement() const; // case 1: tracker
299  int pixelLayersWithoutMeasurement() const; // case 1: pixel
300  int stripLayersWithoutMeasurement() const; // case 1: strip
301  int pixelBarrelLayersWithoutMeasurement() const; // case 1: pixel PXB
302  int pixelEndcapLayersWithoutMeasurement() const; // case 1: pixel PXF
303  int stripTIBLayersWithoutMeasurement() const; // case 1: strip TIB
304  int stripTIDLayersWithoutMeasurement() const; // case 1: strip TID
305  int stripTOBLayersWithoutMeasurement() const; // case 1: strip TOB
306  int stripTECLayersWithoutMeasurement() const; // case 1: strip TEC
307  int trackerLayersTotallyOffOrBad() const; // case 2: tracker
308  int pixelLayersTotallyOffOrBad() const; // case 2: pixel
309  int stripLayersTotallyOffOrBad() const; // case 2: strip
310  int pixelBarrelLayersTotallyOffOrBad() const; // case 2: pixel PXB
311  int pixelEndcapLayersTotallyOffOrBad() const; // case 2: pixel PXF
312  int stripTIBLayersTotallyOffOrBad() const; // case 2: strip TIB
313  int stripTIDLayersTotallyOffOrBad() const; // case 2: strip TID
314  int stripTOBLayersTotallyOffOrBad() const; // case 2: strip TOB
315  int stripTECLayersTotallyOffOrBad() const; // case 2: strip TEC
316  int trackerLayersNull() const; // case 999999: tracker
317  int pixelLayersNull() const; // case 999999: pixel
318  int stripLayersNull() const; // case 999999: strip
319  int pixelBarrelLayersNull() const; // case 999999: pixel PXB
320  int pixelEndcapLayersNull() const; // case 999999: pixel PXF
321  int stripTIBLayersNull() const; // case 999999: strip TIB
322  int stripTIDLayersNull() const; // case 999999: strip TID
323  int stripTOBLayersNull() const; // case 999999: strip TOB
324  int stripTECLayersNull() const; // case 999999: strip TEC
325 
326 
327 
329  int muonStations(int subdet, int hitType) const ;
330 
331  int muonStationsWithValidHits() const ;
332  int muonStationsWithBadHits() const ;
333  int muonStationsWithAnyHits() const ;
334  int dtStationsWithValidHits() const ;
335  int dtStationsWithBadHits() const ;
336  int dtStationsWithAnyHits() const ;
337  int cscStationsWithValidHits() const ;
338  int cscStationsWithBadHits() const ;
339  int cscStationsWithAnyHits() const ;
340  int rpcStationsWithValidHits() const ;
341  int rpcStationsWithBadHits() const ;
342  int rpcStationsWithAnyHits() const ;
343 
345  int innermostMuonStationWithHits(int hitType) const ;
347  int innermostMuonStationWithBadHits() const ;
348  int innermostMuonStationWithAnyHits() const ;
349 
351  int outermostMuonStationWithHits(int hitType) const ;
353  int outermostMuonStationWithBadHits() const ;
354  int outermostMuonStationWithAnyHits() const ;
355 
356  int numberOfDTStationsWithRPhiView() const ;
357  int numberOfDTStationsWithRZView() const ;
358  int numberOfDTStationsWithBothViews() const ;
359  private:
360 
361 
362  // 1 bit to distinguish tracker and muon subsystems
363  const static unsigned short SubDetectorOffset = 10;
364  const static unsigned short SubDetectorMask = 0x1;
365 
366  // 3 bits to identify the tracker/muon detector substructure
367  const static unsigned short SubstrOffset = 7;
368  const static unsigned short SubstrMask = 0x7;
369 
370  // 4 bits to identify the layer/disk/wheel within the substructure
371  const static unsigned short LayerOffset = 3;
372  const static unsigned short LayerMask = 0xF;
373 
374  // 1 bit to identify the side in double-sided detectors
375  const static unsigned short SideOffset = 2;
376  const static unsigned short SideMask = 0x1;
377 
378  // 2 bits for hit type
379  const static unsigned short HitTypeOffset = 0;
380  const static unsigned short HitTypeMask = 0x3;
381 
382  // full hit pattern information is packed in PatternSize 32 bit words
383  uint32_t hitPattern_[ PatternSize ];
384 
385  // set pattern for position-th hit
386  void setHitPattern(int position, uint32_t pattern);
387 
388  // set pattern for i-th hit passing a reference
389  void set(const TrackingRecHitRef & ref, unsigned int i) { set(* ref, i); }
390 
391  // detector side for tracker modules (mono/stereo)
392  static uint32_t isStereo (DetId);
393 
394  // encoder for pattern
395  uint32_t encode(const TrackingRecHit &,unsigned int);
396  };
397 
398  // inline function
399 
400  inline bool HitPattern::pixelHitFilter(uint32_t pattern) {
401  if unlikely(!trackerHitFilter(pattern)) return false;
402  uint32_t substructure = getSubStructure(pattern);
403  if (substructure == PixelSubdetector::PixelBarrel ||
404  substructure == PixelSubdetector::PixelEndcap) return true;
405  return false;
406  }
407 
408  inline bool HitPattern::pixelBarrelHitFilter(uint32_t pattern) {
409  if unlikely(!trackerHitFilter(pattern)) return false;
410  uint32_t substructure = getSubStructure(pattern);
411  if (substructure == PixelSubdetector::PixelBarrel) return true;
412  return false;
413  }
414 
415  inline bool HitPattern::pixelEndcapHitFilter(uint32_t pattern) {
416  if unlikely(!trackerHitFilter(pattern)) return false;
417  uint32_t substructure = getSubStructure(pattern);
418  if (substructure == PixelSubdetector::PixelEndcap) return true;
419  return false;
420  }
421 
422  inline bool HitPattern::stripHitFilter(uint32_t pattern) {
423  if unlikely(!trackerHitFilter(pattern)) return false;
424  uint32_t substructure = getSubStructure(pattern);
425  if (substructure == StripSubdetector::TIB ||
426  substructure == StripSubdetector::TID ||
427  substructure == StripSubdetector::TOB ||
428  substructure == StripSubdetector::TEC) return true;
429  return false;
430  }
431 
432  inline bool HitPattern::stripTIBHitFilter(uint32_t pattern) {
433  if unlikely(!trackerHitFilter(pattern)) return false;
434  uint32_t substructure = getSubStructure(pattern);
435  if (substructure == StripSubdetector::TIB) return true;
436  return false;
437  }
438 
439  inline bool HitPattern::stripTIDHitFilter(uint32_t pattern) {
440  if unlikely(!trackerHitFilter(pattern)) return false;
441  uint32_t substructure = getSubStructure(pattern);
442  if (substructure == StripSubdetector::TID) return true;
443  return false;
444  }
445 
446  inline bool HitPattern::stripTOBHitFilter(uint32_t pattern) {
447  if unlikely(!trackerHitFilter(pattern)) return false;
448  uint32_t substructure = getSubStructure(pattern);
449  if (substructure == StripSubdetector::TOB) return true;
450  return false;
451  }
452 
453  inline bool HitPattern::stripTECHitFilter(uint32_t pattern) {
454  if unlikely(!trackerHitFilter(pattern)) return false;
455  uint32_t substructure = getSubStructure(pattern);
456  if (substructure == StripSubdetector::TEC) return true;
457  return false;
458  }
459 
460  inline bool HitPattern::muonDTHitFilter(uint32_t pattern) {
461  if unlikely(!muonHitFilter(pattern)) return false;
462  uint32_t substructure = getSubStructure(pattern);
463  if (substructure == (uint32_t) MuonSubdetId::DT) return true;
464  return false;
465  }
466 
467  inline bool HitPattern::muonCSCHitFilter(uint32_t pattern) {
468  if unlikely(!muonHitFilter(pattern)) return false;
469  uint32_t substructure = getSubStructure(pattern);
470  if (substructure == (uint32_t) MuonSubdetId::CSC) return true;
471  return false;
472  }
473 
474  inline bool HitPattern::muonRPCHitFilter(uint32_t pattern) {
475  if unlikely(!muonHitFilter(pattern)) return false;
476  uint32_t substructure = getSubStructure(pattern);
477  if (substructure == (uint32_t) MuonSubdetId::RPC) return true;
478  return false;
479  }
480 
481 
482  inline bool HitPattern::trackerHitFilter(uint32_t pattern) {
483  if unlikely(pattern == 0) return false;
484  if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 1) return true;
485  return false;
486  }
487 
488  inline bool HitPattern::muonHitFilter(uint32_t pattern) {
489  if unlikely(pattern == 0) return false;
490  if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 0) return true;
491  return false;
492  }
493 
494 
495  inline uint32_t HitPattern::getSubStructure(uint32_t pattern) {
496  if unlikely(pattern == 0) return 999999;
497  return ((pattern >> SubstrOffset) & SubstrMask);
498  }
499 
500 
501  inline uint32_t HitPattern::getLayer(uint32_t pattern) {
502  if unlikely(pattern == 0) return 999999;
503  return ((pattern>>LayerOffset) & LayerMask);
504  }
505 
506  inline uint32_t HitPattern::getSubSubStructure(uint32_t pattern) {
507  if unlikely(pattern == 0) return 999999;
508  return ((pattern>>LayerOffset) & LayerMask);
509  }
510 
511 
512  inline uint32_t HitPattern::getSide (uint32_t pattern) {
513  if unlikely(pattern == 0) return 999999;
514  return (pattern >> SideOffset) & SideMask;
515  }
516 
517  inline uint32_t HitPattern::getHitType( uint32_t pattern ) {
518  if unlikely(pattern == 0) return 999999;
519  return ((pattern>>HitTypeOffset) & HitTypeMask);
520  }
521 
522  inline uint32_t HitPattern::getMuonStation(uint32_t pattern) {
523  return (getSubSubStructure(pattern)>>2) + 1;
524  }
525 
526  inline uint32_t HitPattern::getDTSuperLayer(uint32_t pattern) {
527  return (getSubSubStructure(pattern) & 3);
528  }
529 
530  inline uint32_t HitPattern::getCSCRing(uint32_t pattern) {
531  return (getSubSubStructure(pattern) & 3) + 1;
532  }
533 
534  inline uint32_t HitPattern::getRPCLayer(uint32_t pattern) {
535  uint32_t sss = getSubSubStructure(pattern), stat = sss >> 2;
536  if likely(stat <= 1) return ((sss >> 1) & 1) + 1;
537  return 0;
538  }
539 
540  inline uint32_t HitPattern::getRPCregion(uint32_t pattern) {
541  return getSubSubStructure(pattern) & 1;
542  }
543 
544 
545  inline bool HitPattern::validHitFilter(uint32_t pattern) {
546  if (getHitType(pattern) == 0) return true;
547  return false;
548  }
549 
550  inline bool HitPattern::type_1_HitFilter(uint32_t pattern) {
551  if (getHitType(pattern) == 1) return true;
552  return false;
553  }
554 
555  inline bool HitPattern::type_2_HitFilter(uint32_t pattern) {
556  if (getHitType(pattern) == 2) return true;
557  return false;
558  }
559 
560  inline bool HitPattern::type_3_HitFilter(uint32_t pattern) {
561  if (getHitType(pattern) == 3) return true;
562  return false;
563  }
564 
565 
566  // count methods
567 
568 // valid
569 
570 inline int HitPattern::numberOfValidHits() const {
571  return countHits(validHitFilter);
572 }
573 
576 }
577 
580 }
581 
584 }
585 
588 }
589 
592 }
593 
596 }
597 
600 }
601 
604 }
605 
608 }
609 
612 }
613 
616 }
617 
620 }
621 
624 }
625 
626 // lost
627 inline int HitPattern::numberOfLostHits() const {
628  return countHits(type_1_HitFilter);
629 }
630 
633 }
634 
637 }
638 
641 }
642 
645 }
646 
649 }
650 
653 }
654 
657 }
658 
661 }
662 
665 }
666 
669 }
670 
673 }
674 
677 }
678 
681 }
682 
683 
684 // bad
685 inline int HitPattern::numberOfBadHits() const {
686  return countHits(type_3_HitFilter);
687 }
688 
691 }
692 
695 }
696 
699 }
700 
703 }
704 
705 
706 // inactive
708  return countHits(type_2_HitFilter);
709 }
710 
713 }
714 
715 
716 
717 
718 
719 
720 
722  return pixelLayersWithMeasurement() +
724  }
725 
729  }
730 
736  }
737 
738 
742  }
743 
747  }
748 
754  }
755 
756 
758  return pixelLayersTotallyOffOrBad() +
760  }
761 
765  }
766 
772  }
773 
774  inline int HitPattern::trackerLayersNull() const {
775  return pixelLayersNull() +
776  stripLayersNull();
777  }
778 
779  inline int HitPattern::pixelLayersNull() const {
780  return pixelBarrelLayersNull() +
782  }
783 
784  inline int HitPattern::stripLayersNull() const {
785  return stripTIBLayersNull() +
787  stripTOBLayersNull() +
789  }
790 
791 
792  inline int HitPattern::muonStationsWithValidHits() const { return muonStations(0, 0); }
793  inline int HitPattern::muonStationsWithBadHits() const { return muonStations(0, 3); }
794  inline int HitPattern::muonStationsWithAnyHits() const { return muonStations(0,-1); }
795  inline int HitPattern::dtStationsWithValidHits() const { return muonStations(1, 0); }
796  inline int HitPattern::dtStationsWithBadHits() const { return muonStations(1, 3); }
797  inline int HitPattern::dtStationsWithAnyHits() const { return muonStations(1,-1); }
798  inline int HitPattern::cscStationsWithValidHits() const { return muonStations(2, 0); }
799  inline int HitPattern::cscStationsWithBadHits() const { return muonStations(2, 3); }
800  inline int HitPattern::cscStationsWithAnyHits() const { return muonStations(2,-1); }
801  inline int HitPattern::rpcStationsWithValidHits() const { return muonStations(3, 0); }
802  inline int HitPattern::rpcStationsWithBadHits() const { return muonStations(3, 3); }
803  inline int HitPattern::rpcStationsWithAnyHits() const { return muonStations(3,-1); }
804 
811 
812 #ifndef CMS_NOCXX11 // cint....
813 
814  template<int N=reco::HitPattern::MaxHits>
815  struct PatternSet {
816  static constexpr int MaxHits=N;
817  unsigned char hit[N];
818  unsigned char nhit;
819 
820  unsigned char const * begin() const { return hit;}
821  unsigned char const * end() const { return hit+nhit;}
822  unsigned char * begin() { return hit;}
823  unsigned char * end() { return hit+nhit;}
824  int size() const { return nhit;}
825  unsigned char operator[](int i) const{ return hit[i];}
826 
827  PatternSet(): nhit(0){}
829  fill(hp);
830  }
831 
832  void fill(reco::HitPattern const & hp) {
833  int lhit=0;
834  auto unpack =[&lhit,this](uint32_t pattern) -> bool {
835  unsigned char p = 255&(pattern>>3);
836  hit[lhit++]= p;
837 
838  // bouble sort
839  if (lhit>1)
840  for (auto h=hit+lhit-1; h!=hit; --h) {
841  if ( (*(h-1)) <= p) break; // { (*h)=p;break;}
842  (*h)=*(h-1); *(h-1)=p;
843  }
844  return lhit<MaxHits;
845  };
847  nhit=lhit;
848  }
849  };
850 
851  template<int N>
853  PatternSet<N> comm;
854  comm.nhit = std::set_intersection(p1.begin(),p1.end(),p2.begin(),p2.end(),comm.begin())-comm.begin();
855  return comm;
856 }
857 #endif // gcc11
858 
859 } // namespace reco
860 
861 #endif
PatternSet(reco::HitPattern const &hp)
Definition: HitPattern.h:828
unsigned char const * begin() const
Definition: HitPattern.h:820
int stripTOBLayersWithMeasurement() const
Definition: HitPattern.cc:375
int countTypedHits(filterType typeFilter, filterType filter) const
Definition: HitPattern.h:171
unsigned char const * end() const
Definition: HitPattern.h:821
int i
Definition: DBlmapReader.cc:9
int cscStationsWithAnyHits() const
Definition: HitPattern.h:800
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:534
int outermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:672
int outermostMuonStationWithValidHits() const
Definition: HitPattern.h:808
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:526
int pixelBarrelLayersNull() const
Definition: HitPattern.cc:508
int stripTIBLayersNull() const
Definition: HitPattern.cc:528
PatternSet< N > commonHits(PatternSet< N > const &p1, PatternSet< N > const &p2)
Definition: HitPattern.h:852
int numberOfInactiveHits() const
Definition: HitPattern.h:707
static uint32_t getLayer(uint32_t pattern)
Definition: HitPattern.h:501
void appendHit(const TrackingRecHit &hit)
Definition: HitPattern.cc:88
static uint32_t isStereo(DetId)
Definition: HitPattern.cc:606
static uint32_t getCSCRing(uint32_t pattern)
CSC ring (1-4). Only valid for muon CSC patterns, of course.
Definition: HitPattern.h:530
uint32_t hitPattern_[PatternSize]
Definition: HitPattern.h:383
int stripTIBLayersWithMeasurement() const
Definition: HitPattern.cc:357
int stripTECLayersNull() const
Definition: HitPattern.cc:555
static const unsigned short SideOffset
Definition: HitPattern.h:375
uint32_t encode(const TrackingRecHit &, unsigned int)
Definition: HitPattern.cc:15
void set(const TrackingRecHit &hit, unsigned int i)
Definition: HitPattern.h:196
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:643
static uint32_t getSubSubStructure(uint32_t pattern)
Definition: HitPattern.h:506
int pixelLayersWithoutMeasurement() const
Definition: HitPattern.h:744
int numberOfLostTrackerHits() const
Definition: HitPattern.h:631
static bool muonDTHitFilter(uint32_t pattern)
Definition: HitPattern.h:460
static const unsigned short SubstrOffset
Definition: HitPattern.h:367
int numberOfValidHits() const
Definition: HitPattern.h:570
static bool trackerHitFilter(uint32_t pattern)
Definition: HitPattern.h:482
uint32_t getTrackerMonoStereo(uint32_t substr, uint32_t layer) const
Definition: HitPattern.cc:294
int numberOfLostHits() const
Definition: HitPattern.h:627
int numberOfDTStationsWithRPhiView() const
Definition: HitPattern.cc:687
int numberOfBadHits() const
Definition: HitPattern.h:685
int cscStationsWithValidHits() const
Definition: HitPattern.h:798
int pixelLayersNull() const
Definition: HitPattern.h:779
int numberOfLostPixelHits() const
Definition: HitPattern.h:639
unsigned char nhit
Definition: HitPattern.h:818
int pixelLayersWithMeasurement() const
Definition: HitPattern.h:726
int trackerLayersWithoutMeasurement() const
Definition: HitPattern.h:739
int numberOfValidStripHits() const
Definition: HitPattern.h:594
static uint32_t getHitType(uint32_t pattern)
Definition: HitPattern.h:517
int stripTIDLayersWithoutMeasurement() const
Definition: HitPattern.cc:423
int rpcStationsWithValidHits() const
Definition: HitPattern.h:801
HitPattern(const C &c)
Definition: HitPattern.h:144
static bool type_2_HitFilter(uint32_t pattern)
Definition: HitPattern.h:555
static uint32_t getMuonStation(uint32_t pattern)
Muon station (1-4). Only valid for muon patterns, of course.
Definition: HitPattern.h:522
void set(const I &begin, const I &end)
Definition: HitPattern.h:150
void print(std::ostream &stream=std::cout) const
Definition: HitPattern.cc:591
static const unsigned short PatternSize
Definition: HitPattern.h:127
int numberOfValidStripLayersWithMonoAndStereo() const
Definition: HitPattern.cc:224
int pixelBarrelLayersWithoutMeasurement() const
Definition: HitPattern.cc:394
static bool stripTECHitFilter(uint32_t pattern)
Definition: HitPattern.h:453
int numberOfLostMuonHits() const
Definition: HitPattern.h:635
Float p2
Definition: deltaR.h:21
static const unsigned short HitTypeMask
Definition: HitPattern.h:380
int pixelEndcapLayersWithMeasurement() const
Definition: HitPattern.cc:347
int numberOfValidStripTOBHits() const
Definition: HitPattern.h:606
static int position[TOTALCHAMBERS][3]
Definition: ReadPGInfo.cc:509
int numberOfValidMuonCSCHits() const
Definition: HitPattern.h:618
void call(filterType typeFilter, F f) const
Definition: HitPattern.h:182
int numberOfValidMuonRPCHits() const
Definition: HitPattern.h:622
bool hasValidHitInFirstPixelEndcap() const
Definition: HitPattern.cc:198
static bool stripTIDHitFilter(uint32_t pattern)
Definition: HitPattern.h:439
int muonStationsWithBadHits() const
Definition: HitPattern.h:793
int numberOfLostStripTECHits() const
Definition: HitPattern.h:667
static bool muonHitFilter(uint32_t pattern)
Definition: HitPattern.h:488
#define unlikely(x)
Definition: Likely.h:21
int stripLayersNull() const
Definition: HitPattern.h:784
unsigned char * begin()
Definition: HitPattern.h:822
int muonStationsWithValidHits() const
Definition: HitPattern.h:792
static const int CSC
Definition: MuonSubdetId.h:15
static constexpr int MaxHits
Definition: HitPattern.h:816
int stripTOBLayersTotallyOffOrBad() const
Definition: HitPattern.cc:489
int rpcStationsWithBadHits() const
Definition: HitPattern.h:802
int stripLayersWithoutMeasurement() const
Definition: HitPattern.h:749
int innermostMuonStationWithAnyHits() const
Definition: HitPattern.h:807
int trackerLayersTotallyOffOrBad() const
Definition: HitPattern.h:757
int numberOfValidPixelBarrelHits() const
Definition: HitPattern.h:586
int stripTIDLayersTotallyOffOrBad() const
Definition: HitPattern.cc:480
static bool type_1_HitFilter(uint32_t pattern)
Definition: HitPattern.h:550
int numberOfLostPixelEndcapHits() const
Definition: HitPattern.h:647
int stripTIDLayersWithMeasurement() const
Definition: HitPattern.cc:366
int trackerLayersWithMeasurement() const
Definition: HitPattern.h:721
Float p1
Definition: deltaR.h:20
static const unsigned short SubDetectorMask
Definition: HitPattern.h:364
int numberOfLostStripTIDHits() const
Definition: HitPattern.h:659
int muonStationsWithAnyHits() const
Definition: HitPattern.h:794
static const int MaxHits
Definition: HitPattern.h:132
void fill(reco::HitPattern const &hp)
Definition: HitPattern.h:832
static bool pixelHitFilter(uint32_t pattern)
Definition: HitPattern.h:400
int pixelLayersTotallyOffOrBad() const
Definition: HitPattern.h:762
int stripTECLayersTotallyOffOrBad() const
Definition: HitPattern.cc:498
int numberOfHits() const
Definition: HitPattern.cc:213
static uint32_t getSubStructure(uint32_t pattern)
Definition: HitPattern.h:495
int numberOfBadMuonHits() const
Definition: HitPattern.h:689
int stripTIBLayersWithoutMeasurement() const
Definition: HitPattern.cc:414
int numberOfValidStripTIDHits() const
Definition: HitPattern.h:602
int size() const
Definition: HitPattern.h:824
const std::complex< double > I
Definition: I.h:8
int numberOfDTStationsWithRZView() const
Definition: HitPattern.cc:699
double f[11][100]
static bool muonRPCHitFilter(uint32_t pattern)
Definition: HitPattern.h:474
static bool validHitFilter(uint32_t pattern)
Definition: HitPattern.h:545
int numberOfValidStripTECHits() const
Definition: HitPattern.h:610
#define end
Definition: vmac.h:38
int stripTIDLayersNull() const
Definition: HitPattern.cc:537
int numberOfLostMuonRPCHits() const
Definition: HitPattern.h:679
static const unsigned short HitTypeOffset
Definition: HitPattern.h:379
int numberOfBadMuonRPCHits() const
Definition: HitPattern.h:701
int dtStationsWithValidHits() const
Definition: HitPattern.h:795
int stripLayersTotallyOffOrBad() const
Definition: HitPattern.h:767
int cscStationsWithBadHits() const
Definition: HitPattern.h:799
unsigned char * end()
Definition: HitPattern.h:823
int numberOfDTStationsWithBothViews() const
Definition: HitPattern.cc:711
static const unsigned short HitSize
Definition: HitPattern.h:130
static uint32_t getSide(uint32_t pattern)
Definition: HitPattern.h:512
int dtStationsWithAnyHits() const
Definition: HitPattern.h:797
int numberOfLostStripHits() const
Definition: HitPattern.h:651
Definition: DetId.h:20
int innermostMuonStationWithHits(int hitType) const
hitType=-1(all), 0=valid, 3=bad; 0 = no stations at all
Definition: HitPattern.cc:658
int numberOfInactiveTrackerHits() const
Definition: HitPattern.h:711
static const unsigned short SideMask
Definition: HitPattern.h:376
#define N
Definition: blowfish.cc:9
int pixelEndcapLayersWithoutMeasurement() const
Definition: HitPattern.cc:404
The Signals That Services Can Subscribe To This is based on ActivityRegistry h
Helper function to determine trigger accepts.
Definition: Activities.doc:4
int innermostMuonStationWithBadHits() const
Definition: HitPattern.h:806
static const unsigned short SubDetectorOffset
Definition: HitPattern.h:363
int trackerLayersNull() const
Definition: HitPattern.h:774
int stripLayersWithMeasurement() const
Definition: HitPattern.h:731
int pixelBarrelLayersWithMeasurement() const
Definition: HitPattern.cc:337
int numberOfBadMuonDTHits() const
Definition: HitPattern.h:693
static uint32_t getRPCregion(uint32_t pattern)
RPC region: 0 = barrel, 1 = endcap. Only valid for muon RPC patterns, of course.
Definition: HitPattern.h:540
int outermostMuonStationWithBadHits() const
Definition: HitPattern.h:809
int dtStationsWithBadHits() const
Definition: HitPattern.h:796
int numberOfValidStripTIBHits() const
Definition: HitPattern.h:598
int numberOfValidTrackerHits() const
Definition: HitPattern.h:574
int numberOfValidPixelEndcapHits() const
Definition: HitPattern.h:590
int stripTOBLayersNull() const
Definition: HitPattern.cc:546
uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const
Definition: HitPattern.cc:260
static bool type_3_HitFilter(uint32_t pattern)
Definition: HitPattern.h:560
int pixelBarrelLayersTotallyOffOrBad() const
Definition: HitPattern.cc:451
#define likely(x)
Definition: Likely.h:20
int numberOfLostMuonDTHits() const
Definition: HitPattern.h:671
#define begin
Definition: vmac.h:31
static const unsigned short SubstrMask
Definition: HitPattern.h:368
int numberOfBadMuonCSCHits() const
Definition: HitPattern.h:697
int numberOfLostStripTOBHits() const
Definition: HitPattern.h:663
unsigned char hit[N]
Definition: HitPattern.h:817
static const int RPC
Definition: MuonSubdetId.h:16
static const unsigned short LayerOffset
Definition: HitPattern.h:371
int stripTECLayersWithoutMeasurement() const
Definition: HitPattern.cc:441
int numberOfValidMuonDTHits() const
Definition: HitPattern.h:614
static bool stripHitFilter(uint32_t pattern)
Definition: HitPattern.h:422
int stripTECLayersWithMeasurement() const
Definition: HitPattern.cc:384
int stripTOBLayersWithoutMeasurement() const
Definition: HitPattern.cc:432
int pixelEndcapLayersTotallyOffOrBad() const
Definition: HitPattern.cc:461
int numberOfValidPixelHits() const
Definition: HitPattern.h:582
static bool pixelEndcapHitFilter(uint32_t pattern)
Definition: HitPattern.h:415
static bool muonCSCHitFilter(uint32_t pattern)
Definition: HitPattern.h:467
tuple cout
Definition: gather_cfg.py:121
static const int DT
Definition: MuonSubdetId.h:14
bool filterType(unsigned int)
Definition: HitPattern.h:160
void printHitPattern(int position, std::ostream &stream) const
Definition: HitPattern.cc:564
bool hasValidHitInFirstPixelBarrel() const
Definition: HitPattern.cc:183
int numberOfValidMuonHits() const
Definition: HitPattern.h:578
static bool stripTOBHitFilter(uint32_t pattern)
Definition: HitPattern.h:446
static uInt32 F(BLOWFISH_CTX *ctx, uInt32 x)
Definition: blowfish.cc:281
int stripTIBLayersTotallyOffOrBad() const
Definition: HitPattern.cc:471
static const unsigned short LayerMask
Definition: HitPattern.h:372
int numberOfLostStripTIBHits() const
Definition: HitPattern.h:655
uint32_t getHitPattern(int position) const
Definition: HitPattern.cc:144
int rpcStationsWithAnyHits() const
Definition: HitPattern.h:803
int numberOfLostPixelBarrelHits() const
Definition: HitPattern.h:643
void set(const TrackingRecHitRef &ref, unsigned int i)
Definition: HitPattern.h:389
int countHits(filterType filter) const
Definition: HitPattern.h:161
static bool pixelBarrelHitFilter(uint32_t pattern)
Definition: HitPattern.h:408
unsigned char operator[](int i) const
Definition: HitPattern.h:825
#define constexpr
int innermostMuonStationWithValidHits() const
Definition: HitPattern.h:805
int numberOfLostMuonCSCHits() const
Definition: HitPattern.h:675
int outermostMuonStationWithAnyHits() const
Definition: HitPattern.h:810
int pixelEndcapLayersNull() const
Definition: HitPattern.cc:518
void setHitPattern(int position, uint32_t pattern)
Definition: HitPattern.cc:79
static bool stripTIBHitFilter(uint32_t pattern)
Definition: HitPattern.h:432
HitPattern(const I &begin, const I &end)
Definition: HitPattern.h:140