CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/DataFormats/TrackReco/interface/HitPattern.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 #ifndef TrackReco_HitPattern_h
00003 #define TrackReco_HitPattern_h
00004 
00005 //
00006 // File: DataFormats/TrackReco/interface/HitPattern.h
00007 //
00008 // Marcel Vos, INFN Pisa
00009 // v1.10 2007/05/08 bellan
00010 // Zongru Wan, Kansas State University
00011 // Jean-Roch Vlimant
00012 // Kevin Burkett
00013 // Boris Mangano
00014 //
00015 // Hit pattern is the summary information of the hits associated to track in
00016 // AOD.  When RecHits are no longer available, the compact hit pattern should
00017 // allow basic track selection based on the hits in various subdetectors.  The
00018 // hits of a track are saved in unit32_t hitPattern_[28], initialized as
00019 // 0x00000000, ..., 0x00000000.  Set one hit with 10 bits
00020 //
00021 //      +-----+-----+-----+-----+-----+-----+-----+-----+----------------+-----+-----+
00022 //      |tk/mu|  sub-structure  |   sub-sub-structure   |     stereo     |  hit type |
00023 //      +-----+-----+-----+-----+-----+-----+-----+-----+----------------+-----+-----+
00024 //  ... | 10  |   9    8     7  |   6    5     4     3  |        2       |  1     0  | bit
00025 //
00026 //      |tk = 1      PXB = 1            layer = 1-3                       hit type = 0-3
00027 //      |tk = 1      PXF = 2            disk  = 1-2                       hit type = 0-3
00028 //      |tk = 1      TIB = 3            layer = 1-4      0=rphi,1=stereo  hit type = 0-3
00029 //      |tk = 1      TID = 4            wheel = 1-3      0=rphi,1=stereo  hit type = 0-3
00030 //      |tk = 1      TOB = 5            layer = 1-6      0=rphi,1=stereo  hit type = 0-3
00031 //      |tk = 1      TEC = 6            wheel = 1-9      0=rphi,1=stereo  hit type = 0-3
00032 //      |mu = 0      DT  = 1            4*(stat-1)+superlayer             hit type = 0-3
00033 //      |mu = 0      CSC = 2            4*(stat-1)+(ring-1)               hit type = 0-3
00034 //      |mu = 0      RPC = 3            4*(stat-1)+2*layer+region         hit type = 0-3
00035 //
00036 //      hit type, see DataFormats/TrackingRecHit/interface/TrackingRecHit.h
00037 //      valid    = valid hit                                     = 0
00038 //      missing  = detector is good, but no rec hit found        = 1
00039 //      inactive = detector is off, so there was no hope         = 2
00040 //      bad      = there were many bad strips within the ellipse = 3
00041 //
00042 // The maximum number of hits = 32*28/11 = 81.  It had been shown by Zongru
00043 // using a 100 GeV muon sample with 5000 events uniform in eta and phi, the 
00044 // average (maximum) number of tracker hits is 13 (17) and the average 
00045 // (maximum) number of muon detector hits is about 26 (50).  If the number of 
00046 // hits of a track is larger than 80 then the extra hits are ignored by hit 
00047 // pattern.  The static hit pattern array might be improved to a dynamic one
00048 // in the future.
00049 //
00050 // Because of tracking with/without overlaps and with/without hit-splitting, 
00051 // the final number of hits per track is pretty "variable".  Compared with the
00052 // number of valid hits, the number of crossed layers with measurement should
00053 // be more robust to discriminate between good and fake track.
00054 //
00055 // Since 4-bit for sub-sub-structure is not enough to specify a muon layer,
00056 // the layer case counting methods are implemented for tracker only.  This is
00057 // different from the hit counting methods which are implemented for both 
00058 // tracker and muon detector.
00059 //
00060 // Given a tracker layer, specified by sub-structure and layer, the method
00061 // getTrackerLayerCase(substr, layer) groups all of the hits in the hit pattern
00062 // array for the layer together and returns one of the four cases
00063 //
00064 //      crossed
00065 //        layer case 0: valid + (missing, off, bad) ==> with measurement
00066 //        layer case 1: missing + (off, bad) ==> without measurement
00067 //        layer case 2: off, bad ==> totally off or bad, cannot say much
00068 //      not crossed
00069 //        layer case 999999: track outside acceptance or in gap ==> null
00070 //
00071 // Given a tracker layer, specified by sub-structure and layer, the method
00072 // getTrackerMonoStereo(substr, layer) groups all of the valid hits in the hit
00073 // pattern array for the layer together and returns 
00074 //
00075 //      0:              neither a valid mono nor a valid stereo hit
00076 //      MONO:           valid mono hit
00077 //      STEREO:         valid stereo hit
00078 //      MONO | STEREO:  both
00079 //
00080 // Given a track, here is an example usage of hit pattern
00081 //
00082 //      // hit pattern of the track
00083 //      const reco::HitPattern& p = track->hitPattern();
00084 //
00085 //      // loop over the hits of the track
00086 //      for (int i=0; i<p.numberOfHits(); i++) {
00087 //        uint32_t hit = p.getHitPattern(i);
00088 //
00089 //        // if the hit is valid and in pixel barrel, print out the layer
00090 //        if (p.validHitFilter(hit) && p.pixelBarrelHitFilter(hit))
00091 //          std::cout << "valid hit found in pixel barrel layer "
00092 //                    << p.getLayer(hit) << std::endl;
00093 //
00094 //        // expert level: printout the hit in 10-bit binary format
00095 //        std::cout << "hit in 10-bit binary format = "; 
00096 //        for (int j=9; j>=0; j--) {
00097 //          int bit = (hit >> j) & 0x1;
00098 //          std::cout << bit;
00099 //        }
00100 //        std::cout << std::endl;
00101 //      }
00102 //
00103 //      // count the number of valid pixel barrel *** hits ***
00104 //      std::cout << "number of of valid pixel barrel hits is "
00105 //                << p.numberOfValidPixelBarrelHits() << std::endl;
00106 //
00107 //      // count the number of pixel barrel *** layers *** with measurement
00108 //      std::cout << "number of of pixel barrel layers with measurement is "
00109 //                << p.pixelBarrelLayersWithMeasurement() << std::endl;
00110 //
00111 #include <ostream>
00112 #include "DataFormats/DetId/interface/DetId.h"
00113 #include "DataFormats/SiPixelDetId/interface/PixelSubdetector.h"
00114 #include "DataFormats/SiStripDetId/interface/StripSubdetector.h"
00115 #include "DataFormats/MuonDetId/interface/MuonSubdetId.h"
00116 #include "DataFormats/TrackingRecHit/interface/TrackingRecHitFwd.h"
00117 #include "FWCore/Utilities/interface/Likely.h"
00118 namespace reco {
00119   class HitPattern {
00120   public:
00121     enum { MONO = 1, STEREO = 2 };
00122 
00123     // default constructor
00124     // init hit pattern array as 0x00000000, ..., 0x00000000
00125     HitPattern() { for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0; }
00126 
00127     // constructor from iterator (begin, end) pair
00128     template<typename I>
00129     HitPattern(const I & begin, const I & end) { set(begin, end); }
00130 
00131     // constructor from hit collection
00132     template<typename C>
00133     HitPattern(const C & c) { set(c); }
00134 
00135     // set pattern from iterator (begin, end) pair
00136     // init hit pattern array as 0x00000000, ..., 0x00000000
00137     // loop over the hits and set hit pattern
00138     template<typename I>
00139     void set(const I & begin, const I & end) {
00140       for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0;
00141       unsigned int counter = 0;
00142       for (I hit=begin; hit!=end && counter<32*PatternSize/HitSize;
00143            hit++, counter++)
00144         set(*hit, counter);
00145     }
00146 
00147 
00148     // generic count methods
00149     typedef bool filterType(unsigned int);
00150     int countHits(filterType filter) const {
00151       int count = 0;
00152       for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00153         uint32_t pattern = getHitPattern(i);
00154         if (pattern == 0) break;
00155         if (filter(pattern)) ++count;
00156       }
00157       return count;
00158     }
00159 
00160     int countTypedHits(filterType typeFilter, filterType filter) const {
00161       int count = 0;
00162       for (int i=0; i<(PatternSize * 32) / HitSize; i++) {
00163         uint32_t pattern = getHitPattern(i);
00164         if (pattern == 0) break;
00165         if (typeFilter(pattern)&&filter(pattern)) ++count;
00166       }
00167       return count;
00168     }
00169 
00170     // print the pattern of the position-th hit
00171     void printHitPattern (int position, std::ostream &stream) const;
00172     void print (std::ostream &stream = std::cout) const;
00173 
00174     // set the pattern of the i-th hit
00175     void set(const TrackingRecHit &, unsigned int i); 
00176 
00177     // get the pattern of the position-th hit
00178     uint32_t getHitPattern(int position) const; 
00179 
00180     static bool trackerHitFilter(uint32_t pattern); // tracker hit
00181     static bool muonHitFilter(uint32_t pattern);    // muon hit
00182 
00183     static uint32_t getSubStructure(uint32_t pattern);  // sub-structure
00184     static bool pixelHitFilter(uint32_t pattern);       // pixel
00185     static bool pixelBarrelHitFilter(uint32_t pattern); // pixel barrel
00186     static bool pixelEndcapHitFilter(uint32_t pattern); // pixel endcap
00187     static bool stripHitFilter(uint32_t pattern);       // strip 
00188     static bool stripTIBHitFilter(uint32_t pattern);    // strip TIB
00189     static bool stripTIDHitFilter(uint32_t pattern);    // strip TID
00190     static bool stripTOBHitFilter(uint32_t pattern);    // strip TOB
00191     static bool stripTECHitFilter(uint32_t pattern);    // strip TEC
00192     static bool muonDTHitFilter(uint32_t pattern);      // muon DT
00193     static bool muonCSCHitFilter(uint32_t pattern);     // muon CSC
00194     static bool muonRPCHitFilter(uint32_t pattern);     // muon RPC
00195 
00196     static uint32_t getLayer(uint32_t pattern); // sub-sub-structure
00197     static uint32_t getSubSubStructure(uint32_t pattern); // sub-sub-structure
00198 
00200     static uint32_t getMuonStation(uint32_t pattern);  // only for patterns from muon, of course
00202     static uint32_t getDTSuperLayer(uint32_t pattern); // only for DT patterns
00204     static uint32_t getCSCRing(uint32_t pattern) ; 
00206     static uint32_t getRPCLayer(uint32_t pattern) ; 
00208     static uint32_t getRPCregion(uint32_t pattern);
00209 
00210     static uint32_t getHitType(uint32_t pattern);   // hit type
00211     static bool validHitFilter(uint32_t pattern);   // hit type 0 = valid
00212     static bool type_1_HitFilter(uint32_t pattern); // hit type 1
00213     static bool type_2_HitFilter(uint32_t pattern); // hit type 2
00214     static bool type_3_HitFilter(uint32_t pattern); // hit type 3
00215 
00216     static uint32_t getSide (uint32_t pattern);         // mono (0) or stereo (1)
00217 
00218     bool hasValidHitInFirstPixelBarrel() const; // has valid hit in PXB layer 1
00219     bool hasValidHitInFirstPixelEndcap() const; // has valid hit in PXF layer 1
00220 
00221     int numberOfHits() const;                 // not-null
00222     int numberOfValidHits() const;            // not-null, valid
00223     int numberOfValidTrackerHits() const;     // not-null, valid, tracker
00224     int numberOfValidMuonHits() const;        // not-null, valid, muon
00225     int numberOfValidPixelHits() const;       // not-null, valid, pixel
00226     int numberOfValidPixelBarrelHits() const; // not-null, valid, pixel PXB
00227     int numberOfValidPixelEndcapHits() const; // not-null, valid, pixel PXF
00228     int numberOfValidStripHits() const;       // not-null, valid, strip
00229     int numberOfValidStripTIBHits() const;    // not-null, valid, strip TIB
00230     int numberOfValidStripTIDHits() const;    // not-null, valid, strip TID
00231     int numberOfValidStripTOBHits() const;    // not-null, valid, strip TOB
00232     int numberOfValidStripTECHits() const;    // not-null, valid, strip TEC
00233     int numberOfValidMuonDTHits() const;      // not-null, valid, muon DT
00234     int numberOfValidMuonCSCHits() const;     // not-null, valid, muon CSC
00235     int numberOfValidMuonRPCHits() const;     // not-null, valid, muon RPC
00236     int numberOfLostHits() const;             // not-null, not valid
00237     int numberOfLostTrackerHits() const;      // not-null, not valid, tracker
00238     int numberOfLostMuonHits() const;         // not-null, not valid, muon
00239     int numberOfLostPixelHits() const;        // not-null, not valid, pixel
00240     int numberOfLostPixelBarrelHits() const;  // not-null, not valid, pixel PXB
00241     int numberOfLostPixelEndcapHits() const;  // not-null, not valid, pixel PXF
00242     int numberOfLostStripHits() const;        // not-null, not valid, strip
00243     int numberOfLostStripTIBHits() const;     // not-null, not valid, strip TIB
00244     int numberOfLostStripTIDHits() const;     // not-null, not valid, strip TID
00245     int numberOfLostStripTOBHits() const;     // not-null, not valid, strip TOB
00246     int numberOfLostStripTECHits() const;     // not-null, not valid, strip TEC
00247     int numberOfLostMuonDTHits() const;       // not-null, not valid, muon DT
00248     int numberOfLostMuonCSCHits() const;      // not-null, not valid, muon CSC
00249     int numberOfLostMuonRPCHits() const;      // not-null, not valid, muon RPC
00250     int numberOfBadHits() const;              // not-null, bad (only used in Muon Ch.)
00251     int numberOfBadMuonHits() const;          // not-null, bad, muon
00252     int numberOfBadMuonDTHits() const;        // not-null, bad, muon DT
00253     int numberOfBadMuonCSCHits() const;       // not-null, bad, muon CSC
00254     int numberOfBadMuonRPCHits() const;       // not-null, bad, muon RPC
00255     int numberOfInactiveHits() const;         // not-null, inactive
00256     int numberOfInactiveTrackerHits() const;  // not-null, inactive, tracker
00257 
00258 
00259     int numberOfValidStripLayersWithMonoAndStereo () 
00260       const; // count strip layers that have non-null, valid mono and stereo hits
00261 
00262     uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const;
00263     uint32_t getTrackerMonoStereo (uint32_t substr, uint32_t layer) const;
00264 
00265     int trackerLayersWithMeasurement() const;        // case 0: tracker
00266     int pixelLayersWithMeasurement() const;          // case 0: pixel
00267     int stripLayersWithMeasurement() const;          // case 0: strip
00268     int pixelBarrelLayersWithMeasurement() const;    // case 0: pixel PXB
00269     int pixelEndcapLayersWithMeasurement() const;    // case 0: pixel PXF
00270     int stripTIBLayersWithMeasurement() const;       // case 0: strip TIB
00271     int stripTIDLayersWithMeasurement() const;       // case 0: strip TID
00272     int stripTOBLayersWithMeasurement() const;       // case 0: strip TOB
00273     int stripTECLayersWithMeasurement() const;       // case 0: strip TEC
00274     int trackerLayersWithoutMeasurement() const;     // case 1: tracker
00275     int pixelLayersWithoutMeasurement() const;       // case 1: pixel
00276     int stripLayersWithoutMeasurement() const;       // case 1: strip
00277     int pixelBarrelLayersWithoutMeasurement() const; // case 1: pixel PXB
00278     int pixelEndcapLayersWithoutMeasurement() const; // case 1: pixel PXF
00279     int stripTIBLayersWithoutMeasurement() const;    // case 1: strip TIB
00280     int stripTIDLayersWithoutMeasurement() const;    // case 1: strip TID
00281     int stripTOBLayersWithoutMeasurement() const;    // case 1: strip TOB
00282     int stripTECLayersWithoutMeasurement() const;    // case 1: strip TEC
00283     int trackerLayersTotallyOffOrBad() const;        // case 2: tracker
00284     int pixelLayersTotallyOffOrBad() const;          // case 2: pixel
00285     int stripLayersTotallyOffOrBad() const;          // case 2: strip
00286     int pixelBarrelLayersTotallyOffOrBad() const;    // case 2: pixel PXB
00287     int pixelEndcapLayersTotallyOffOrBad() const;    // case 2: pixel PXF
00288     int stripTIBLayersTotallyOffOrBad() const;       // case 2: strip TIB
00289     int stripTIDLayersTotallyOffOrBad() const;       // case 2: strip TID
00290     int stripTOBLayersTotallyOffOrBad() const;       // case 2: strip TOB
00291     int stripTECLayersTotallyOffOrBad() const;       // case 2: strip TEC
00292     int trackerLayersNull() const;                   // case 999999: tracker
00293     int pixelLayersNull() const;                     // case 999999: pixel
00294     int stripLayersNull() const;                     // case 999999: strip
00295     int pixelBarrelLayersNull() const;               // case 999999: pixel PXB
00296     int pixelEndcapLayersNull() const;               // case 999999: pixel PXF
00297     int stripTIBLayersNull() const;                  // case 999999: strip TIB
00298     int stripTIDLayersNull() const;                  // case 999999: strip TID
00299     int stripTOBLayersNull() const;                  // case 999999: strip TOB
00300     int stripTECLayersNull() const;                  // case 999999: strip TEC
00301 
00302 
00303 
00305     int muonStations(int subdet, int hitType) const ;
00306 
00307     int muonStationsWithValidHits() const ;
00308     int muonStationsWithBadHits() const ;
00309     int muonStationsWithAnyHits() const ;
00310     int dtStationsWithValidHits() const ;
00311     int dtStationsWithBadHits() const ;
00312     int dtStationsWithAnyHits() const ;
00313     int cscStationsWithValidHits() const ;
00314     int cscStationsWithBadHits() const ;
00315     int cscStationsWithAnyHits() const ;
00316     int rpcStationsWithValidHits() const ;
00317     int rpcStationsWithBadHits() const ;
00318     int rpcStationsWithAnyHits() const ;
00319 
00321     int innermostMuonStationWithHits(int hitType) const ;
00322     int innermostMuonStationWithValidHits() const ;
00323     int innermostMuonStationWithBadHits() const ;
00324     int innermostMuonStationWithAnyHits() const ;
00325 
00327     int outermostMuonStationWithHits(int hitType) const ;
00328     int outermostMuonStationWithValidHits() const ;
00329     int outermostMuonStationWithBadHits() const ;
00330     int outermostMuonStationWithAnyHits() const ;
00331 
00332     int numberOfDTStationsWithRPhiView() const ;
00333     int numberOfDTStationsWithRZView() const ;
00334     int numberOfDTStationsWithBothViews() const ;
00335   private:
00336 
00337     // number of 32 bit integers to store the full pattern
00338     const static unsigned short PatternSize = 25;
00339 
00340     // number of bits used for each hit
00341     const static unsigned short HitSize = 11;    
00342  
00343     // 1 bit to distinguish tracker and muon subsystems
00344     const static unsigned short SubDetectorOffset = 10; 
00345     const static unsigned short SubDetectorMask = 0x1;
00346 
00347     // 3 bits to identify the tracker/muon detector substructure
00348     const static unsigned short SubstrOffset = 7; 
00349     const static unsigned short SubstrMask = 0x7;
00350 
00351     // 4 bits to identify the layer/disk/wheel within the substructure
00352     const static unsigned short LayerOffset = 3; 
00353     const static unsigned short LayerMask = 0xF;
00354 
00355     // 1 bit to identify the side in double-sided detectors
00356     const static unsigned short SideOffset = 2;
00357     const static unsigned short SideMask = 0x1;
00358 
00359     // 2 bits for hit type
00360     const static unsigned short HitTypeOffset = 0;
00361     const static unsigned short HitTypeMask = 0x3;
00362 
00363     // full hit pattern information is packed in PatternSize 32 bit words
00364     uint32_t hitPattern_[ PatternSize ]; 
00365 
00366     // set pattern for position-th hit
00367     void setHitPattern(int position, uint32_t pattern);
00368 
00369     // set pattern for i-th hit passing a reference
00370     void set(const TrackingRecHitRef & ref, unsigned int i) { set(* ref, i); }
00371 
00372     // detector side for tracker modules (mono/stereo)
00373     static uint32_t isStereo (DetId);
00374   };
00375 
00376   // inline function
00377 
00378   inline bool HitPattern::pixelHitFilter(uint32_t pattern) { 
00379     if  unlikely(!trackerHitFilter(pattern)) return false;
00380     uint32_t substructure = getSubStructure(pattern);
00381     if (substructure == PixelSubdetector::PixelBarrel || 
00382         substructure == PixelSubdetector::PixelEndcap) return true; 
00383     return false;
00384   }
00385   
00386   inline bool HitPattern::pixelBarrelHitFilter(uint32_t pattern) { 
00387     if  unlikely(!trackerHitFilter(pattern)) return false;
00388     uint32_t substructure = getSubStructure(pattern);
00389     if (substructure == PixelSubdetector::PixelBarrel) return true; 
00390     return false;
00391   }
00392   
00393   inline bool HitPattern::pixelEndcapHitFilter(uint32_t pattern) { 
00394     if  unlikely(!trackerHitFilter(pattern)) return false;
00395     uint32_t substructure = getSubStructure(pattern);
00396     if (substructure == PixelSubdetector::PixelEndcap) return true; 
00397     return false;
00398   }
00399   
00400   inline bool HitPattern::stripHitFilter(uint32_t pattern) { 
00401     if  unlikely(!trackerHitFilter(pattern)) return false;
00402     uint32_t substructure = getSubStructure(pattern);
00403     if (substructure == StripSubdetector::TIB ||
00404         substructure == StripSubdetector::TID ||
00405         substructure == StripSubdetector::TOB ||
00406         substructure == StripSubdetector::TEC) return true; 
00407     return false;
00408   }
00409   
00410   inline bool HitPattern::stripTIBHitFilter(uint32_t pattern) { 
00411     if  unlikely(!trackerHitFilter(pattern)) return false;
00412     uint32_t substructure = getSubStructure(pattern);
00413     if (substructure == StripSubdetector::TIB) return true; 
00414     return false;
00415   }
00416   
00417   inline bool HitPattern::stripTIDHitFilter(uint32_t pattern) { 
00418     if  unlikely(!trackerHitFilter(pattern)) return false;
00419     uint32_t substructure = getSubStructure(pattern);
00420     if (substructure == StripSubdetector::TID) return true; 
00421     return false;
00422   }
00423   
00424   inline bool HitPattern::stripTOBHitFilter(uint32_t pattern) { 
00425     if  unlikely(!trackerHitFilter(pattern)) return false;
00426     uint32_t substructure = getSubStructure(pattern);
00427     if (substructure == StripSubdetector::TOB) return true; 
00428     return false;
00429   }
00430   
00431   inline bool HitPattern::stripTECHitFilter(uint32_t pattern) { 
00432     if  unlikely(!trackerHitFilter(pattern)) return false;
00433     uint32_t substructure = getSubStructure(pattern);
00434     if (substructure == StripSubdetector::TEC) return true; 
00435     return false;
00436   }
00437   
00438   inline bool HitPattern::muonDTHitFilter(uint32_t pattern) { 
00439     if  unlikely(!muonHitFilter(pattern)) return false;
00440     uint32_t substructure = getSubStructure(pattern);
00441     if (substructure == (uint32_t) MuonSubdetId::DT) return true; 
00442     return false;
00443   }
00444   
00445   inline bool HitPattern::muonCSCHitFilter(uint32_t pattern) { 
00446     if  unlikely(!muonHitFilter(pattern)) return false;
00447     uint32_t substructure = getSubStructure(pattern);
00448     if (substructure == (uint32_t) MuonSubdetId::CSC) return true; 
00449     return false;
00450   }
00451 
00452   inline bool HitPattern::muonRPCHitFilter(uint32_t pattern) { 
00453     if  unlikely(!muonHitFilter(pattern)) return false;
00454     uint32_t substructure = getSubStructure(pattern);
00455     if (substructure == (uint32_t) MuonSubdetId::RPC) return true; 
00456     return false;
00457   }
00458   
00459   
00460   inline bool HitPattern::trackerHitFilter(uint32_t pattern) {
00461     if  unlikely(pattern == 0) return false;
00462     if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 1) return true;
00463     return false;
00464   }
00465   
00466   inline bool HitPattern::muonHitFilter(uint32_t pattern) {
00467     if  unlikely(pattern == 0) return false;
00468     if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 0) return true; 
00469     return false;
00470   }
00471 
00472 
00473   inline uint32_t HitPattern::getSubStructure(uint32_t pattern) {
00474     if  unlikely(pattern == 0) return 999999;
00475     return ((pattern >> SubstrOffset) & SubstrMask);
00476   }
00477   
00478   
00479   inline uint32_t HitPattern::getLayer(uint32_t pattern) {
00480     if  unlikely(pattern == 0) return 999999;
00481     return ((pattern>>LayerOffset) & LayerMask);
00482   }
00483   
00484   inline uint32_t HitPattern::getSubSubStructure(uint32_t pattern) {
00485     if  unlikely(pattern == 0) return 999999;
00486     return ((pattern>>LayerOffset) & LayerMask);
00487   }
00488   
00489   
00490   inline uint32_t HitPattern::getSide (uint32_t pattern)  {
00491     if  unlikely(pattern == 0) return 999999;
00492     return (pattern >> SideOffset) & SideMask;
00493   }
00494   
00495   inline uint32_t HitPattern::getHitType( uint32_t pattern ) {
00496     if  unlikely(pattern == 0) return 999999;
00497     return ((pattern>>HitTypeOffset) & HitTypeMask);
00498   }
00499   
00500   inline uint32_t HitPattern::getMuonStation(uint32_t pattern) {
00501     return (getSubSubStructure(pattern)>>2) + 1;
00502   }
00503   
00504   inline uint32_t HitPattern::getDTSuperLayer(uint32_t pattern) {
00505     return (getSubSubStructure(pattern) & 3);
00506   }
00507   
00508   inline uint32_t HitPattern::getCSCRing(uint32_t pattern) {
00509     return (getSubSubStructure(pattern) & 3) + 1;
00510   }
00511   
00512   inline uint32_t HitPattern::getRPCLayer(uint32_t pattern) {
00513     uint32_t sss = getSubSubStructure(pattern), stat = sss >> 2;
00514     if likely(stat <= 1) return ((sss >> 1) & 1) + 1;
00515     return 0;
00516   }
00517   
00518   inline uint32_t HitPattern::getRPCregion(uint32_t pattern) {
00519     return getSubSubStructure(pattern) & 1;
00520   }
00521   
00522   
00523   inline bool  HitPattern::validHitFilter(uint32_t pattern) {
00524     if (getHitType(pattern) == 0) return true; 
00525     return false;
00526   }
00527   
00528   inline bool  HitPattern::type_1_HitFilter(uint32_t pattern) {
00529     if (getHitType(pattern) == 1) return true; 
00530     return false;
00531   }
00532   
00533   inline bool  HitPattern::type_2_HitFilter(uint32_t pattern) {
00534     if (getHitType(pattern) == 2) return true; 
00535     return false;
00536   }
00537   
00538   inline bool  HitPattern::type_3_HitFilter(uint32_t pattern) {
00539     if (getHitType(pattern) == 3) return true; 
00540     return false;
00541   }
00542   
00543 
00544   // count methods
00545 
00546 // valid
00547 
00548 inline int HitPattern::numberOfValidHits() const {
00549   return countHits(validHitFilter);
00550 }
00551 
00552 inline int HitPattern::numberOfValidTrackerHits() const {
00553   return countTypedHits(validHitFilter, trackerHitFilter);
00554 }
00555 
00556 inline int HitPattern::numberOfValidMuonHits() const {
00557   return countTypedHits(validHitFilter, muonHitFilter);
00558 }
00559 
00560 inline int HitPattern::numberOfValidPixelHits() const {
00561   return countTypedHits(validHitFilter, pixelHitFilter);
00562 }
00563 
00564 inline int HitPattern::numberOfValidPixelBarrelHits() const {
00565   return countTypedHits(validHitFilter, pixelBarrelHitFilter);
00566 }
00567 
00568 inline int HitPattern::numberOfValidPixelEndcapHits() const {
00569   return countTypedHits(validHitFilter, pixelEndcapHitFilter);
00570 }
00571 
00572 inline int HitPattern::numberOfValidStripHits() const {
00573   return countTypedHits(validHitFilter, stripHitFilter);
00574 }
00575 
00576 inline int HitPattern::numberOfValidStripTIBHits() const {
00577   return countTypedHits(validHitFilter, stripTIBHitFilter);
00578 }
00579 
00580 inline int HitPattern::numberOfValidStripTIDHits() const {
00581   return countTypedHits(validHitFilter, stripTIDHitFilter);
00582 }
00583 
00584 inline int HitPattern::numberOfValidStripTOBHits() const {
00585   return countTypedHits(validHitFilter, stripTOBHitFilter);
00586 }
00587 
00588 inline int HitPattern::numberOfValidStripTECHits() const {
00589   return countTypedHits(validHitFilter, stripTECHitFilter);
00590 }
00591 
00592 inline int HitPattern::numberOfValidMuonDTHits() const {
00593   return countTypedHits(validHitFilter, muonDTHitFilter);
00594 }
00595 
00596 inline int HitPattern::numberOfValidMuonCSCHits() const {
00597   return countTypedHits(validHitFilter, muonCSCHitFilter);
00598 }
00599 
00600 inline int HitPattern::numberOfValidMuonRPCHits() const {
00601   return countTypedHits(validHitFilter, muonRPCHitFilter);
00602 }
00603 
00604 // lost
00605 inline int HitPattern::numberOfLostHits() const {
00606   return countHits(type_1_HitFilter);
00607 }
00608 
00609 inline int HitPattern::numberOfLostTrackerHits() const {
00610   return countTypedHits(type_1_HitFilter, trackerHitFilter);
00611 }
00612 
00613 inline int HitPattern::numberOfLostMuonHits() const {
00614   return countTypedHits(type_1_HitFilter, muonHitFilter);
00615 }
00616 
00617 inline int HitPattern::numberOfLostPixelHits() const {
00618   return countTypedHits(type_1_HitFilter, pixelHitFilter);
00619 }
00620 
00621 inline int HitPattern::numberOfLostPixelBarrelHits() const {
00622   return countTypedHits(type_1_HitFilter, pixelBarrelHitFilter);
00623 }
00624 
00625 inline int HitPattern::numberOfLostPixelEndcapHits() const {
00626   return countTypedHits(type_1_HitFilter, pixelEndcapHitFilter);
00627 }
00628 
00629 inline int HitPattern::numberOfLostStripHits() const {
00630   return countTypedHits(type_1_HitFilter, stripHitFilter);
00631 }
00632 
00633 inline int HitPattern::numberOfLostStripTIBHits() const {
00634   return countTypedHits(type_1_HitFilter, stripTIBHitFilter);
00635 }
00636 
00637 inline int HitPattern::numberOfLostStripTIDHits() const {
00638   return countTypedHits(type_1_HitFilter, stripTIDHitFilter);
00639 }
00640 
00641 inline int HitPattern::numberOfLostStripTOBHits() const {
00642   return countTypedHits(type_1_HitFilter, stripTOBHitFilter);
00643 }
00644 
00645 inline int HitPattern::numberOfLostStripTECHits() const {
00646   return countTypedHits(type_1_HitFilter, stripTECHitFilter);
00647 }
00648 
00649 inline int HitPattern::numberOfLostMuonDTHits() const {
00650   return countTypedHits(type_1_HitFilter, muonDTHitFilter);
00651 }
00652 
00653 inline int HitPattern::numberOfLostMuonCSCHits() const {
00654   return countTypedHits(type_1_HitFilter, muonCSCHitFilter);
00655 }
00656 
00657 inline int HitPattern::numberOfLostMuonRPCHits() const {
00658   return countTypedHits(type_1_HitFilter, muonRPCHitFilter);
00659 }
00660 
00661 
00662 // bad
00663 inline int HitPattern::numberOfBadHits() const {
00664   return countHits(type_3_HitFilter);
00665 }
00666 
00667 inline int HitPattern::numberOfBadMuonHits() const {
00668   return countTypedHits(type_2_HitFilter, muonHitFilter);
00669 }
00670 
00671 inline int HitPattern::numberOfBadMuonDTHits() const {
00672   return countTypedHits(type_2_HitFilter, muonDTHitFilter);
00673 }
00674 
00675 inline int HitPattern::numberOfBadMuonCSCHits() const {
00676   return countTypedHits(type_2_HitFilter, muonCSCHitFilter);
00677 }
00678 
00679 inline int HitPattern::numberOfBadMuonRPCHits() const {
00680   return countTypedHits(type_2_HitFilter, muonRPCHitFilter);
00681 }
00682 
00683 
00684 // inactive
00685 inline int HitPattern::numberOfInactiveHits() const {
00686   return countHits(type_2_HitFilter);
00687 }
00688 
00689 inline int HitPattern::numberOfInactiveTrackerHits() const {
00690   return countTypedHits(type_2_HitFilter, trackerHitFilter);
00691 }
00692 
00693 
00694 
00695 
00696 
00697 
00698   
00699   inline int HitPattern::trackerLayersWithMeasurement() const {
00700     return pixelLayersWithMeasurement() + 
00701       stripLayersWithMeasurement();
00702   }
00703   
00704   inline int HitPattern::pixelLayersWithMeasurement() const {
00705     return pixelBarrelLayersWithMeasurement() +
00706       pixelEndcapLayersWithMeasurement();
00707   }
00708   
00709   inline int HitPattern::stripLayersWithMeasurement() const {
00710     return stripTIBLayersWithMeasurement() + 
00711       stripTIDLayersWithMeasurement() +
00712       stripTOBLayersWithMeasurement() + 
00713       stripTECLayersWithMeasurement();
00714   }
00715   
00716 
00717   inline int HitPattern::trackerLayersWithoutMeasurement() const {
00718     return pixelLayersWithoutMeasurement() + 
00719       stripLayersWithoutMeasurement();
00720   }
00721   
00722   inline int HitPattern::pixelLayersWithoutMeasurement() const {
00723     return pixelBarrelLayersWithoutMeasurement() +
00724       pixelEndcapLayersWithoutMeasurement();
00725   }
00726   
00727   inline int HitPattern::stripLayersWithoutMeasurement() const {
00728     return stripTIBLayersWithoutMeasurement() + 
00729       stripTIDLayersWithoutMeasurement() +
00730       stripTOBLayersWithoutMeasurement() + 
00731       stripTECLayersWithoutMeasurement();
00732   }
00733 
00734 
00735   inline int HitPattern::trackerLayersTotallyOffOrBad() const {
00736     return pixelLayersTotallyOffOrBad() + 
00737       stripLayersTotallyOffOrBad();
00738   }
00739   
00740   inline int HitPattern::pixelLayersTotallyOffOrBad() const {
00741     return pixelBarrelLayersTotallyOffOrBad() +
00742       pixelEndcapLayersTotallyOffOrBad();
00743   }
00744   
00745   inline int HitPattern::stripLayersTotallyOffOrBad() const {
00746     return stripTIBLayersTotallyOffOrBad() + 
00747       stripTIDLayersTotallyOffOrBad() +
00748       stripTOBLayersTotallyOffOrBad() + 
00749       stripTECLayersTotallyOffOrBad();
00750   }
00751   
00752   inline int HitPattern::trackerLayersNull() const {
00753     return pixelLayersNull() + 
00754       stripLayersNull();
00755   }
00756   
00757   inline int HitPattern::pixelLayersNull() const {
00758     return pixelBarrelLayersNull() +
00759       pixelEndcapLayersNull();
00760   }
00761   
00762   inline int HitPattern::stripLayersNull() const {
00763     return stripTIBLayersNull() + 
00764       stripTIDLayersNull() +
00765       stripTOBLayersNull() + 
00766       stripTECLayersNull();
00767   }
00768   
00769 
00770   inline int HitPattern::muonStationsWithValidHits() const { return muonStations(0, 0); }
00771   inline int HitPattern::muonStationsWithBadHits()   const { return muonStations(0, 3); }
00772   inline int HitPattern::muonStationsWithAnyHits()   const { return muonStations(0,-1); }
00773   inline int HitPattern::dtStationsWithValidHits()   const { return muonStations(1, 0); }
00774   inline int HitPattern::dtStationsWithBadHits()     const { return muonStations(1, 3); }
00775   inline int HitPattern::dtStationsWithAnyHits()     const { return muonStations(1,-1); }
00776   inline int HitPattern::cscStationsWithValidHits()  const { return muonStations(2, 0); }
00777   inline int HitPattern::cscStationsWithBadHits()    const { return muonStations(2, 3); }
00778   inline int HitPattern::cscStationsWithAnyHits()    const { return muonStations(2,-1); }
00779   inline int HitPattern::rpcStationsWithValidHits()  const { return muonStations(3, 0); }
00780   inline int HitPattern::rpcStationsWithBadHits()    const { return muonStations(3, 3); }
00781   inline int HitPattern::rpcStationsWithAnyHits()    const { return muonStations(3,-1); }
00782   
00783   inline int HitPattern::innermostMuonStationWithValidHits() const { return innermostMuonStationWithHits(0);  }
00784   inline int HitPattern::innermostMuonStationWithBadHits()   const { return innermostMuonStationWithHits(3);  }
00785   inline int HitPattern::innermostMuonStationWithAnyHits()   const { return innermostMuonStationWithHits(-1); }
00786   inline int HitPattern::outermostMuonStationWithValidHits() const { return outermostMuonStationWithHits(0);  }
00787   inline int HitPattern::outermostMuonStationWithBadHits()   const { return outermostMuonStationWithHits(3);  }
00788   inline int HitPattern::outermostMuonStationWithAnyHits()   const { return outermostMuonStationWithHits(-1); }
00789 
00790 }
00791   
00792 #endif