CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_3_10_patch1/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 &hit, unsigned int i){setHitPattern(i, encode(hit,i));}
00176     
00177     // append a hit to the hit pattern
00178     void appendHit(const TrackingRecHit & hit);
00179 
00180     // get the pattern of the position-th hit
00181     uint32_t getHitPattern(int position) const; 
00182 
00183     static bool trackerHitFilter(uint32_t pattern); // tracker hit
00184     static bool muonHitFilter(uint32_t pattern);    // muon hit
00185 
00186     static uint32_t getSubStructure(uint32_t pattern);  // sub-structure
00187     static bool pixelHitFilter(uint32_t pattern);       // pixel
00188     static bool pixelBarrelHitFilter(uint32_t pattern); // pixel barrel
00189     static bool pixelEndcapHitFilter(uint32_t pattern); // pixel endcap
00190     static bool stripHitFilter(uint32_t pattern);       // strip 
00191     static bool stripTIBHitFilter(uint32_t pattern);    // strip TIB
00192     static bool stripTIDHitFilter(uint32_t pattern);    // strip TID
00193     static bool stripTOBHitFilter(uint32_t pattern);    // strip TOB
00194     static bool stripTECHitFilter(uint32_t pattern);    // strip TEC
00195     static bool muonDTHitFilter(uint32_t pattern);      // muon DT
00196     static bool muonCSCHitFilter(uint32_t pattern);     // muon CSC
00197     static bool muonRPCHitFilter(uint32_t pattern);     // muon RPC
00198 
00199     static uint32_t getLayer(uint32_t pattern); // sub-sub-structure
00200     static uint32_t getSubSubStructure(uint32_t pattern); // sub-sub-structure
00201 
00203     static uint32_t getMuonStation(uint32_t pattern);  // only for patterns from muon, of course
00205     static uint32_t getDTSuperLayer(uint32_t pattern); // only for DT patterns
00207     static uint32_t getCSCRing(uint32_t pattern) ; 
00209     static uint32_t getRPCLayer(uint32_t pattern) ; 
00211     static uint32_t getRPCregion(uint32_t pattern);
00212 
00213     static uint32_t getHitType(uint32_t pattern);   // hit type
00214     static bool validHitFilter(uint32_t pattern);   // hit type 0 = valid
00215     static bool type_1_HitFilter(uint32_t pattern); // hit type 1
00216     static bool type_2_HitFilter(uint32_t pattern); // hit type 2
00217     static bool type_3_HitFilter(uint32_t pattern); // hit type 3
00218 
00219     static uint32_t getSide (uint32_t pattern);         // mono (0) or stereo (1)
00220 
00221     bool hasValidHitInFirstPixelBarrel() const; // has valid hit in PXB layer 1
00222     bool hasValidHitInFirstPixelEndcap() const; // has valid hit in PXF layer 1
00223 
00224     int numberOfHits() const;                 // not-null
00225     int numberOfValidHits() const;            // not-null, valid
00226     int numberOfValidTrackerHits() const;     // not-null, valid, tracker
00227     int numberOfValidMuonHits() const;        // not-null, valid, muon
00228     int numberOfValidPixelHits() const;       // not-null, valid, pixel
00229     int numberOfValidPixelBarrelHits() const; // not-null, valid, pixel PXB
00230     int numberOfValidPixelEndcapHits() const; // not-null, valid, pixel PXF
00231     int numberOfValidStripHits() const;       // not-null, valid, strip
00232     int numberOfValidStripTIBHits() const;    // not-null, valid, strip TIB
00233     int numberOfValidStripTIDHits() const;    // not-null, valid, strip TID
00234     int numberOfValidStripTOBHits() const;    // not-null, valid, strip TOB
00235     int numberOfValidStripTECHits() const;    // not-null, valid, strip TEC
00236     int numberOfValidMuonDTHits() const;      // not-null, valid, muon DT
00237     int numberOfValidMuonCSCHits() const;     // not-null, valid, muon CSC
00238     int numberOfValidMuonRPCHits() const;     // not-null, valid, muon RPC
00239     int numberOfLostHits() const;             // not-null, not valid
00240     int numberOfLostTrackerHits() const;      // not-null, not valid, tracker
00241     int numberOfLostMuonHits() const;         // not-null, not valid, muon
00242     int numberOfLostPixelHits() const;        // not-null, not valid, pixel
00243     int numberOfLostPixelBarrelHits() const;  // not-null, not valid, pixel PXB
00244     int numberOfLostPixelEndcapHits() const;  // not-null, not valid, pixel PXF
00245     int numberOfLostStripHits() const;        // not-null, not valid, strip
00246     int numberOfLostStripTIBHits() const;     // not-null, not valid, strip TIB
00247     int numberOfLostStripTIDHits() const;     // not-null, not valid, strip TID
00248     int numberOfLostStripTOBHits() const;     // not-null, not valid, strip TOB
00249     int numberOfLostStripTECHits() const;     // not-null, not valid, strip TEC
00250     int numberOfLostMuonDTHits() const;       // not-null, not valid, muon DT
00251     int numberOfLostMuonCSCHits() const;      // not-null, not valid, muon CSC
00252     int numberOfLostMuonRPCHits() const;      // not-null, not valid, muon RPC
00253     int numberOfBadHits() const;              // not-null, bad (only used in Muon Ch.)
00254     int numberOfBadMuonHits() const;          // not-null, bad, muon
00255     int numberOfBadMuonDTHits() const;        // not-null, bad, muon DT
00256     int numberOfBadMuonCSCHits() const;       // not-null, bad, muon CSC
00257     int numberOfBadMuonRPCHits() const;       // not-null, bad, muon RPC
00258     int numberOfInactiveHits() const;         // not-null, inactive
00259     int numberOfInactiveTrackerHits() const;  // not-null, inactive, tracker
00260 
00261 
00262     int numberOfValidStripLayersWithMonoAndStereo () 
00263       const; // count strip layers that have non-null, valid mono and stereo hits
00264 
00265     uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const;
00266     uint32_t getTrackerMonoStereo (uint32_t substr, uint32_t layer) const;
00267 
00268     int trackerLayersWithMeasurement() const;        // case 0: tracker
00269     int pixelLayersWithMeasurement() const;          // case 0: pixel
00270     int stripLayersWithMeasurement() const;          // case 0: strip
00271     int pixelBarrelLayersWithMeasurement() const;    // case 0: pixel PXB
00272     int pixelEndcapLayersWithMeasurement() const;    // case 0: pixel PXF
00273     int stripTIBLayersWithMeasurement() const;       // case 0: strip TIB
00274     int stripTIDLayersWithMeasurement() const;       // case 0: strip TID
00275     int stripTOBLayersWithMeasurement() const;       // case 0: strip TOB
00276     int stripTECLayersWithMeasurement() const;       // case 0: strip TEC
00277     int trackerLayersWithoutMeasurement() const;     // case 1: tracker
00278     int pixelLayersWithoutMeasurement() const;       // case 1: pixel
00279     int stripLayersWithoutMeasurement() const;       // case 1: strip
00280     int pixelBarrelLayersWithoutMeasurement() const; // case 1: pixel PXB
00281     int pixelEndcapLayersWithoutMeasurement() const; // case 1: pixel PXF
00282     int stripTIBLayersWithoutMeasurement() const;    // case 1: strip TIB
00283     int stripTIDLayersWithoutMeasurement() const;    // case 1: strip TID
00284     int stripTOBLayersWithoutMeasurement() const;    // case 1: strip TOB
00285     int stripTECLayersWithoutMeasurement() const;    // case 1: strip TEC
00286     int trackerLayersTotallyOffOrBad() const;        // case 2: tracker
00287     int pixelLayersTotallyOffOrBad() const;          // case 2: pixel
00288     int stripLayersTotallyOffOrBad() const;          // case 2: strip
00289     int pixelBarrelLayersTotallyOffOrBad() const;    // case 2: pixel PXB
00290     int pixelEndcapLayersTotallyOffOrBad() const;    // case 2: pixel PXF
00291     int stripTIBLayersTotallyOffOrBad() const;       // case 2: strip TIB
00292     int stripTIDLayersTotallyOffOrBad() const;       // case 2: strip TID
00293     int stripTOBLayersTotallyOffOrBad() const;       // case 2: strip TOB
00294     int stripTECLayersTotallyOffOrBad() const;       // case 2: strip TEC
00295     int trackerLayersNull() const;                   // case 999999: tracker
00296     int pixelLayersNull() const;                     // case 999999: pixel
00297     int stripLayersNull() const;                     // case 999999: strip
00298     int pixelBarrelLayersNull() const;               // case 999999: pixel PXB
00299     int pixelEndcapLayersNull() const;               // case 999999: pixel PXF
00300     int stripTIBLayersNull() const;                  // case 999999: strip TIB
00301     int stripTIDLayersNull() const;                  // case 999999: strip TID
00302     int stripTOBLayersNull() const;                  // case 999999: strip TOB
00303     int stripTECLayersNull() const;                  // case 999999: strip TEC
00304 
00305 
00306 
00308     int muonStations(int subdet, int hitType) const ;
00309 
00310     int muonStationsWithValidHits() const ;
00311     int muonStationsWithBadHits() const ;
00312     int muonStationsWithAnyHits() const ;
00313     int dtStationsWithValidHits() const ;
00314     int dtStationsWithBadHits() const ;
00315     int dtStationsWithAnyHits() const ;
00316     int cscStationsWithValidHits() const ;
00317     int cscStationsWithBadHits() const ;
00318     int cscStationsWithAnyHits() const ;
00319     int rpcStationsWithValidHits() const ;
00320     int rpcStationsWithBadHits() const ;
00321     int rpcStationsWithAnyHits() const ;
00322 
00324     int innermostMuonStationWithHits(int hitType) const ;
00325     int innermostMuonStationWithValidHits() const ;
00326     int innermostMuonStationWithBadHits() const ;
00327     int innermostMuonStationWithAnyHits() const ;
00328 
00330     int outermostMuonStationWithHits(int hitType) const ;
00331     int outermostMuonStationWithValidHits() const ;
00332     int outermostMuonStationWithBadHits() const ;
00333     int outermostMuonStationWithAnyHits() const ;
00334 
00335     int numberOfDTStationsWithRPhiView() const ;
00336     int numberOfDTStationsWithRZView() const ;
00337     int numberOfDTStationsWithBothViews() const ;
00338   private:
00339 
00340     // number of 32 bit integers to store the full pattern
00341     const static unsigned short PatternSize = 25;
00342 
00343     // number of bits used for each hit
00344     const static unsigned short HitSize = 11;    
00345  
00346     // 1 bit to distinguish tracker and muon subsystems
00347     const static unsigned short SubDetectorOffset = 10; 
00348     const static unsigned short SubDetectorMask = 0x1;
00349 
00350     // 3 bits to identify the tracker/muon detector substructure
00351     const static unsigned short SubstrOffset = 7; 
00352     const static unsigned short SubstrMask = 0x7;
00353 
00354     // 4 bits to identify the layer/disk/wheel within the substructure
00355     const static unsigned short LayerOffset = 3; 
00356     const static unsigned short LayerMask = 0xF;
00357 
00358     // 1 bit to identify the side in double-sided detectors
00359     const static unsigned short SideOffset = 2;
00360     const static unsigned short SideMask = 0x1;
00361 
00362     // 2 bits for hit type
00363     const static unsigned short HitTypeOffset = 0;
00364     const static unsigned short HitTypeMask = 0x3;
00365 
00366     // full hit pattern information is packed in PatternSize 32 bit words
00367     uint32_t hitPattern_[ PatternSize ]; 
00368 
00369     // set pattern for position-th hit
00370     void setHitPattern(int position, uint32_t pattern);
00371 
00372     // set pattern for i-th hit passing a reference
00373     void set(const TrackingRecHitRef & ref, unsigned int i) { set(* ref, i); }
00374 
00375     // detector side for tracker modules (mono/stereo)
00376     static uint32_t isStereo (DetId);
00377 
00378     // encoder for pattern
00379     uint32_t encode(const TrackingRecHit &,unsigned int);
00380   };
00381 
00382   // inline function
00383 
00384   inline bool HitPattern::pixelHitFilter(uint32_t pattern) { 
00385     if  unlikely(!trackerHitFilter(pattern)) return false;
00386     uint32_t substructure = getSubStructure(pattern);
00387     if (substructure == PixelSubdetector::PixelBarrel || 
00388         substructure == PixelSubdetector::PixelEndcap) return true; 
00389     return false;
00390   }
00391   
00392   inline bool HitPattern::pixelBarrelHitFilter(uint32_t pattern) { 
00393     if  unlikely(!trackerHitFilter(pattern)) return false;
00394     uint32_t substructure = getSubStructure(pattern);
00395     if (substructure == PixelSubdetector::PixelBarrel) return true; 
00396     return false;
00397   }
00398   
00399   inline bool HitPattern::pixelEndcapHitFilter(uint32_t pattern) { 
00400     if  unlikely(!trackerHitFilter(pattern)) return false;
00401     uint32_t substructure = getSubStructure(pattern);
00402     if (substructure == PixelSubdetector::PixelEndcap) return true; 
00403     return false;
00404   }
00405   
00406   inline bool HitPattern::stripHitFilter(uint32_t pattern) { 
00407     if  unlikely(!trackerHitFilter(pattern)) return false;
00408     uint32_t substructure = getSubStructure(pattern);
00409     if (substructure == StripSubdetector::TIB ||
00410         substructure == StripSubdetector::TID ||
00411         substructure == StripSubdetector::TOB ||
00412         substructure == StripSubdetector::TEC) return true; 
00413     return false;
00414   }
00415   
00416   inline bool HitPattern::stripTIBHitFilter(uint32_t pattern) { 
00417     if  unlikely(!trackerHitFilter(pattern)) return false;
00418     uint32_t substructure = getSubStructure(pattern);
00419     if (substructure == StripSubdetector::TIB) return true; 
00420     return false;
00421   }
00422   
00423   inline bool HitPattern::stripTIDHitFilter(uint32_t pattern) { 
00424     if  unlikely(!trackerHitFilter(pattern)) return false;
00425     uint32_t substructure = getSubStructure(pattern);
00426     if (substructure == StripSubdetector::TID) return true; 
00427     return false;
00428   }
00429   
00430   inline bool HitPattern::stripTOBHitFilter(uint32_t pattern) { 
00431     if  unlikely(!trackerHitFilter(pattern)) return false;
00432     uint32_t substructure = getSubStructure(pattern);
00433     if (substructure == StripSubdetector::TOB) return true; 
00434     return false;
00435   }
00436   
00437   inline bool HitPattern::stripTECHitFilter(uint32_t pattern) { 
00438     if  unlikely(!trackerHitFilter(pattern)) return false;
00439     uint32_t substructure = getSubStructure(pattern);
00440     if (substructure == StripSubdetector::TEC) return true; 
00441     return false;
00442   }
00443   
00444   inline bool HitPattern::muonDTHitFilter(uint32_t pattern) { 
00445     if  unlikely(!muonHitFilter(pattern)) return false;
00446     uint32_t substructure = getSubStructure(pattern);
00447     if (substructure == (uint32_t) MuonSubdetId::DT) return true; 
00448     return false;
00449   }
00450   
00451   inline bool HitPattern::muonCSCHitFilter(uint32_t pattern) { 
00452     if  unlikely(!muonHitFilter(pattern)) return false;
00453     uint32_t substructure = getSubStructure(pattern);
00454     if (substructure == (uint32_t) MuonSubdetId::CSC) return true; 
00455     return false;
00456   }
00457 
00458   inline bool HitPattern::muonRPCHitFilter(uint32_t pattern) { 
00459     if  unlikely(!muonHitFilter(pattern)) return false;
00460     uint32_t substructure = getSubStructure(pattern);
00461     if (substructure == (uint32_t) MuonSubdetId::RPC) return true; 
00462     return false;
00463   }
00464   
00465   
00466   inline bool HitPattern::trackerHitFilter(uint32_t pattern) {
00467     if  unlikely(pattern == 0) return false;
00468     if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 1) return true;
00469     return false;
00470   }
00471   
00472   inline bool HitPattern::muonHitFilter(uint32_t pattern) {
00473     if  unlikely(pattern == 0) return false;
00474     if (((pattern>>SubDetectorOffset) & SubDetectorMask) == 0) return true; 
00475     return false;
00476   }
00477 
00478 
00479   inline uint32_t HitPattern::getSubStructure(uint32_t pattern) {
00480     if  unlikely(pattern == 0) return 999999;
00481     return ((pattern >> SubstrOffset) & SubstrMask);
00482   }
00483   
00484   
00485   inline uint32_t HitPattern::getLayer(uint32_t pattern) {
00486     if  unlikely(pattern == 0) return 999999;
00487     return ((pattern>>LayerOffset) & LayerMask);
00488   }
00489   
00490   inline uint32_t HitPattern::getSubSubStructure(uint32_t pattern) {
00491     if  unlikely(pattern == 0) return 999999;
00492     return ((pattern>>LayerOffset) & LayerMask);
00493   }
00494   
00495   
00496   inline uint32_t HitPattern::getSide (uint32_t pattern)  {
00497     if  unlikely(pattern == 0) return 999999;
00498     return (pattern >> SideOffset) & SideMask;
00499   }
00500   
00501   inline uint32_t HitPattern::getHitType( uint32_t pattern ) {
00502     if  unlikely(pattern == 0) return 999999;
00503     return ((pattern>>HitTypeOffset) & HitTypeMask);
00504   }
00505   
00506   inline uint32_t HitPattern::getMuonStation(uint32_t pattern) {
00507     return (getSubSubStructure(pattern)>>2) + 1;
00508   }
00509   
00510   inline uint32_t HitPattern::getDTSuperLayer(uint32_t pattern) {
00511     return (getSubSubStructure(pattern) & 3);
00512   }
00513   
00514   inline uint32_t HitPattern::getCSCRing(uint32_t pattern) {
00515     return (getSubSubStructure(pattern) & 3) + 1;
00516   }
00517   
00518   inline uint32_t HitPattern::getRPCLayer(uint32_t pattern) {
00519     uint32_t sss = getSubSubStructure(pattern), stat = sss >> 2;
00520     if likely(stat <= 1) return ((sss >> 1) & 1) + 1;
00521     return 0;
00522   }
00523   
00524   inline uint32_t HitPattern::getRPCregion(uint32_t pattern) {
00525     return getSubSubStructure(pattern) & 1;
00526   }
00527   
00528   
00529   inline bool  HitPattern::validHitFilter(uint32_t pattern) {
00530     if (getHitType(pattern) == 0) return true; 
00531     return false;
00532   }
00533   
00534   inline bool  HitPattern::type_1_HitFilter(uint32_t pattern) {
00535     if (getHitType(pattern) == 1) return true; 
00536     return false;
00537   }
00538   
00539   inline bool  HitPattern::type_2_HitFilter(uint32_t pattern) {
00540     if (getHitType(pattern) == 2) return true; 
00541     return false;
00542   }
00543   
00544   inline bool  HitPattern::type_3_HitFilter(uint32_t pattern) {
00545     if (getHitType(pattern) == 3) return true; 
00546     return false;
00547   }
00548   
00549 
00550   // count methods
00551 
00552 // valid
00553 
00554 inline int HitPattern::numberOfValidHits() const {
00555   return countHits(validHitFilter);
00556 }
00557 
00558 inline int HitPattern::numberOfValidTrackerHits() const {
00559   return countTypedHits(validHitFilter, trackerHitFilter);
00560 }
00561 
00562 inline int HitPattern::numberOfValidMuonHits() const {
00563   return countTypedHits(validHitFilter, muonHitFilter);
00564 }
00565 
00566 inline int HitPattern::numberOfValidPixelHits() const {
00567   return countTypedHits(validHitFilter, pixelHitFilter);
00568 }
00569 
00570 inline int HitPattern::numberOfValidPixelBarrelHits() const {
00571   return countTypedHits(validHitFilter, pixelBarrelHitFilter);
00572 }
00573 
00574 inline int HitPattern::numberOfValidPixelEndcapHits() const {
00575   return countTypedHits(validHitFilter, pixelEndcapHitFilter);
00576 }
00577 
00578 inline int HitPattern::numberOfValidStripHits() const {
00579   return countTypedHits(validHitFilter, stripHitFilter);
00580 }
00581 
00582 inline int HitPattern::numberOfValidStripTIBHits() const {
00583   return countTypedHits(validHitFilter, stripTIBHitFilter);
00584 }
00585 
00586 inline int HitPattern::numberOfValidStripTIDHits() const {
00587   return countTypedHits(validHitFilter, stripTIDHitFilter);
00588 }
00589 
00590 inline int HitPattern::numberOfValidStripTOBHits() const {
00591   return countTypedHits(validHitFilter, stripTOBHitFilter);
00592 }
00593 
00594 inline int HitPattern::numberOfValidStripTECHits() const {
00595   return countTypedHits(validHitFilter, stripTECHitFilter);
00596 }
00597 
00598 inline int HitPattern::numberOfValidMuonDTHits() const {
00599   return countTypedHits(validHitFilter, muonDTHitFilter);
00600 }
00601 
00602 inline int HitPattern::numberOfValidMuonCSCHits() const {
00603   return countTypedHits(validHitFilter, muonCSCHitFilter);
00604 }
00605 
00606 inline int HitPattern::numberOfValidMuonRPCHits() const {
00607   return countTypedHits(validHitFilter, muonRPCHitFilter);
00608 }
00609 
00610 // lost
00611 inline int HitPattern::numberOfLostHits() const {
00612   return countHits(type_1_HitFilter);
00613 }
00614 
00615 inline int HitPattern::numberOfLostTrackerHits() const {
00616   return countTypedHits(type_1_HitFilter, trackerHitFilter);
00617 }
00618 
00619 inline int HitPattern::numberOfLostMuonHits() const {
00620   return countTypedHits(type_1_HitFilter, muonHitFilter);
00621 }
00622 
00623 inline int HitPattern::numberOfLostPixelHits() const {
00624   return countTypedHits(type_1_HitFilter, pixelHitFilter);
00625 }
00626 
00627 inline int HitPattern::numberOfLostPixelBarrelHits() const {
00628   return countTypedHits(type_1_HitFilter, pixelBarrelHitFilter);
00629 }
00630 
00631 inline int HitPattern::numberOfLostPixelEndcapHits() const {
00632   return countTypedHits(type_1_HitFilter, pixelEndcapHitFilter);
00633 }
00634 
00635 inline int HitPattern::numberOfLostStripHits() const {
00636   return countTypedHits(type_1_HitFilter, stripHitFilter);
00637 }
00638 
00639 inline int HitPattern::numberOfLostStripTIBHits() const {
00640   return countTypedHits(type_1_HitFilter, stripTIBHitFilter);
00641 }
00642 
00643 inline int HitPattern::numberOfLostStripTIDHits() const {
00644   return countTypedHits(type_1_HitFilter, stripTIDHitFilter);
00645 }
00646 
00647 inline int HitPattern::numberOfLostStripTOBHits() const {
00648   return countTypedHits(type_1_HitFilter, stripTOBHitFilter);
00649 }
00650 
00651 inline int HitPattern::numberOfLostStripTECHits() const {
00652   return countTypedHits(type_1_HitFilter, stripTECHitFilter);
00653 }
00654 
00655 inline int HitPattern::numberOfLostMuonDTHits() const {
00656   return countTypedHits(type_1_HitFilter, muonDTHitFilter);
00657 }
00658 
00659 inline int HitPattern::numberOfLostMuonCSCHits() const {
00660   return countTypedHits(type_1_HitFilter, muonCSCHitFilter);
00661 }
00662 
00663 inline int HitPattern::numberOfLostMuonRPCHits() const {
00664   return countTypedHits(type_1_HitFilter, muonRPCHitFilter);
00665 }
00666 
00667 
00668 // bad
00669 inline int HitPattern::numberOfBadHits() const {
00670   return countHits(type_3_HitFilter);
00671 }
00672 
00673 inline int HitPattern::numberOfBadMuonHits() const {
00674   return countTypedHits(type_2_HitFilter, muonHitFilter);
00675 }
00676 
00677 inline int HitPattern::numberOfBadMuonDTHits() const {
00678   return countTypedHits(type_2_HitFilter, muonDTHitFilter);
00679 }
00680 
00681 inline int HitPattern::numberOfBadMuonCSCHits() const {
00682   return countTypedHits(type_2_HitFilter, muonCSCHitFilter);
00683 }
00684 
00685 inline int HitPattern::numberOfBadMuonRPCHits() const {
00686   return countTypedHits(type_2_HitFilter, muonRPCHitFilter);
00687 }
00688 
00689 
00690 // inactive
00691 inline int HitPattern::numberOfInactiveHits() const {
00692   return countHits(type_2_HitFilter);
00693 }
00694 
00695 inline int HitPattern::numberOfInactiveTrackerHits() const {
00696   return countTypedHits(type_2_HitFilter, trackerHitFilter);
00697 }
00698 
00699 
00700 
00701 
00702 
00703 
00704   
00705   inline int HitPattern::trackerLayersWithMeasurement() const {
00706     return pixelLayersWithMeasurement() + 
00707       stripLayersWithMeasurement();
00708   }
00709   
00710   inline int HitPattern::pixelLayersWithMeasurement() const {
00711     return pixelBarrelLayersWithMeasurement() +
00712       pixelEndcapLayersWithMeasurement();
00713   }
00714   
00715   inline int HitPattern::stripLayersWithMeasurement() const {
00716     return stripTIBLayersWithMeasurement() + 
00717       stripTIDLayersWithMeasurement() +
00718       stripTOBLayersWithMeasurement() + 
00719       stripTECLayersWithMeasurement();
00720   }
00721   
00722 
00723   inline int HitPattern::trackerLayersWithoutMeasurement() const {
00724     return pixelLayersWithoutMeasurement() + 
00725       stripLayersWithoutMeasurement();
00726   }
00727   
00728   inline int HitPattern::pixelLayersWithoutMeasurement() const {
00729     return pixelBarrelLayersWithoutMeasurement() +
00730       pixelEndcapLayersWithoutMeasurement();
00731   }
00732   
00733   inline int HitPattern::stripLayersWithoutMeasurement() const {
00734     return stripTIBLayersWithoutMeasurement() + 
00735       stripTIDLayersWithoutMeasurement() +
00736       stripTOBLayersWithoutMeasurement() + 
00737       stripTECLayersWithoutMeasurement();
00738   }
00739 
00740 
00741   inline int HitPattern::trackerLayersTotallyOffOrBad() const {
00742     return pixelLayersTotallyOffOrBad() + 
00743       stripLayersTotallyOffOrBad();
00744   }
00745   
00746   inline int HitPattern::pixelLayersTotallyOffOrBad() const {
00747     return pixelBarrelLayersTotallyOffOrBad() +
00748       pixelEndcapLayersTotallyOffOrBad();
00749   }
00750   
00751   inline int HitPattern::stripLayersTotallyOffOrBad() const {
00752     return stripTIBLayersTotallyOffOrBad() + 
00753       stripTIDLayersTotallyOffOrBad() +
00754       stripTOBLayersTotallyOffOrBad() + 
00755       stripTECLayersTotallyOffOrBad();
00756   }
00757   
00758   inline int HitPattern::trackerLayersNull() const {
00759     return pixelLayersNull() + 
00760       stripLayersNull();
00761   }
00762   
00763   inline int HitPattern::pixelLayersNull() const {
00764     return pixelBarrelLayersNull() +
00765       pixelEndcapLayersNull();
00766   }
00767   
00768   inline int HitPattern::stripLayersNull() const {
00769     return stripTIBLayersNull() + 
00770       stripTIDLayersNull() +
00771       stripTOBLayersNull() + 
00772       stripTECLayersNull();
00773   }
00774   
00775 
00776   inline int HitPattern::muonStationsWithValidHits() const { return muonStations(0, 0); }
00777   inline int HitPattern::muonStationsWithBadHits()   const { return muonStations(0, 3); }
00778   inline int HitPattern::muonStationsWithAnyHits()   const { return muonStations(0,-1); }
00779   inline int HitPattern::dtStationsWithValidHits()   const { return muonStations(1, 0); }
00780   inline int HitPattern::dtStationsWithBadHits()     const { return muonStations(1, 3); }
00781   inline int HitPattern::dtStationsWithAnyHits()     const { return muonStations(1,-1); }
00782   inline int HitPattern::cscStationsWithValidHits()  const { return muonStations(2, 0); }
00783   inline int HitPattern::cscStationsWithBadHits()    const { return muonStations(2, 3); }
00784   inline int HitPattern::cscStationsWithAnyHits()    const { return muonStations(2,-1); }
00785   inline int HitPattern::rpcStationsWithValidHits()  const { return muonStations(3, 0); }
00786   inline int HitPattern::rpcStationsWithBadHits()    const { return muonStations(3, 3); }
00787   inline int HitPattern::rpcStationsWithAnyHits()    const { return muonStations(3,-1); }
00788   
00789   inline int HitPattern::innermostMuonStationWithValidHits() const { return innermostMuonStationWithHits(0);  }
00790   inline int HitPattern::innermostMuonStationWithBadHits()   const { return innermostMuonStationWithHits(3);  }
00791   inline int HitPattern::innermostMuonStationWithAnyHits()   const { return innermostMuonStationWithHits(-1); }
00792   inline int HitPattern::outermostMuonStationWithValidHits() const { return outermostMuonStationWithHits(0);  }
00793   inline int HitPattern::outermostMuonStationWithBadHits()   const { return outermostMuonStationWithHits(3);  }
00794   inline int HitPattern::outermostMuonStationWithAnyHits()   const { return outermostMuonStationWithHits(-1); }
00795 
00796 }
00797   
00798 #endif