CMS 3D CMS Logo

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