CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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/TrackingRecHit/interface/TrackingRecHitFwd.h"
00116 
00117 namespace reco {
00118   class HitPattern {
00119   public:
00120     enum { MONO = 1, STEREO = 2 };
00121 
00122     // default constructor
00123     // init hit pattern array as 0x00000000, ..., 0x00000000
00124     HitPattern() { for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0; }
00125 
00126     // constructor from iterator (begin, end) pair
00127     template<typename I>
00128     HitPattern(const I & begin, const I & end) { set(begin, end); }
00129 
00130     // constructor from hit collection
00131     template<typename C>
00132     HitPattern(const C & c) { set(c); }
00133 
00134     // set pattern from iterator (begin, end) pair
00135     // init hit pattern array as 0x00000000, ..., 0x00000000
00136     // loop over the hits and set hit pattern
00137     template<typename I>
00138     void set(const I & begin, const I & end) {
00139       for (int i=0; i<PatternSize; i++) hitPattern_[i] = 0;
00140       unsigned int counter = 0;
00141       for (I hit=begin; hit!=end && counter<32*PatternSize/HitSize;
00142            hit++, counter++)
00143         set(*hit, counter);
00144     }
00145 
00146     // print the pattern of the position-th hit
00147     void printHitPattern (int position, std::ostream &stream) const;
00148     void print (std::ostream &stream = std::cout) const;
00149 
00150     // set the pattern of the i-th hit
00151     void set(const TrackingRecHit &, unsigned int i); 
00152 
00153     // get the pattern of the position-th hit
00154     uint32_t getHitPattern(int position) const; 
00155 
00156     bool trackerHitFilter(uint32_t pattern) const; // tracker hit
00157     bool muonHitFilter(uint32_t pattern) const;    // muon hit
00158 
00159     uint32_t getSubStructure(uint32_t pattern) const;  // sub-structure
00160     bool pixelHitFilter(uint32_t pattern) const;       // pixel
00161     bool pixelBarrelHitFilter(uint32_t pattern) const; // pixel barrel
00162     bool pixelEndcapHitFilter(uint32_t pattern) const; // pixel endcap
00163     bool stripHitFilter(uint32_t pattern) const;       // strip 
00164     bool stripTIBHitFilter(uint32_t pattern) const;    // strip TIB
00165     bool stripTIDHitFilter(uint32_t pattern) const;    // strip TID
00166     bool stripTOBHitFilter(uint32_t pattern) const;    // strip TOB
00167     bool stripTECHitFilter(uint32_t pattern) const;    // strip TEC
00168     bool muonDTHitFilter(uint32_t pattern) const;      // muon DT
00169     bool muonCSCHitFilter(uint32_t pattern) const;     // muon CSC
00170     bool muonRPCHitFilter(uint32_t pattern) const;     // muon RPC
00171 
00172     uint32_t getLayer(uint32_t pattern) const; // sub-sub-structure
00173     uint32_t getSubSubStructure(uint32_t pattern) const; // sub-sub-structure
00174 
00176     uint32_t getMuonStation(uint32_t pattern) const;  // only for patterns from muon, of course
00178     uint32_t getDTSuperLayer(uint32_t pattern) const; // only for DT patterns
00180     uint32_t getCSCRing(uint32_t pattern) const ; 
00182     uint32_t getRPCLayer(uint32_t pattern) const ; 
00184     uint32_t getRPCregion(uint32_t pattern) const;
00185 
00186     uint32_t getHitType(uint32_t pattern) const;   // hit type
00187     bool validHitFilter(uint32_t pattern) const;   // hit type 0 = valid
00188     bool type_1_HitFilter(uint32_t pattern) const; // hit type 1
00189     bool type_2_HitFilter(uint32_t pattern) const; // hit type 2
00190     bool type_3_HitFilter(uint32_t pattern) const; // hit type 3
00191 
00192     static uint32_t getSide (uint32_t pattern);         // mono (0) or stereo (1)
00193 
00194     bool hasValidHitInFirstPixelBarrel() const; // has valid hit in PXB layer 1
00195     bool hasValidHitInFirstPixelEndcap() const; // has valid hit in PXF layer 1
00196 
00197     int numberOfHits() const;                 // not-null
00198     int numberOfValidHits() const;            // not-null, valid
00199     int numberOfValidTrackerHits() const;     // not-null, valid, tracker
00200     int numberOfValidMuonHits() const;        // not-null, valid, muon
00201     int numberOfValidPixelHits() const;       // not-null, valid, pixel
00202     int numberOfValidPixelBarrelHits() const; // not-null, valid, pixel PXB
00203     int numberOfValidPixelEndcapHits() const; // not-null, valid, pixel PXF
00204     int numberOfValidStripHits() const;       // not-null, valid, strip
00205     int numberOfValidStripTIBHits() const;    // not-null, valid, strip TIB
00206     int numberOfValidStripTIDHits() const;    // not-null, valid, strip TID
00207     int numberOfValidStripTOBHits() const;    // not-null, valid, strip TOB
00208     int numberOfValidStripTECHits() const;    // not-null, valid, strip TEC
00209     int numberOfValidMuonDTHits() const;      // not-null, valid, muon DT
00210     int numberOfValidMuonCSCHits() const;     // not-null, valid, muon CSC
00211     int numberOfValidMuonRPCHits() const;     // not-null, valid, muon RPC
00212     int numberOfLostHits() const;             // not-null, not valid
00213     int numberOfLostTrackerHits() const;      // not-null, not valid, tracker
00214     int numberOfLostMuonHits() const;         // not-null, not valid, muon
00215     int numberOfLostPixelHits() const;        // not-null, not valid, pixel
00216     int numberOfLostPixelBarrelHits() const;  // not-null, not valid, pixel PXB
00217     int numberOfLostPixelEndcapHits() const;  // not-null, not valid, pixel PXF
00218     int numberOfLostStripHits() const;        // not-null, not valid, strip
00219     int numberOfLostStripTIBHits() const;     // not-null, not valid, strip TIB
00220     int numberOfLostStripTIDHits() const;     // not-null, not valid, strip TID
00221     int numberOfLostStripTOBHits() const;     // not-null, not valid, strip TOB
00222     int numberOfLostStripTECHits() const;     // not-null, not valid, strip TEC
00223     int numberOfLostMuonDTHits() const;       // not-null, not valid, muon DT
00224     int numberOfLostMuonCSCHits() const;      // not-null, not valid, muon CSC
00225     int numberOfLostMuonRPCHits() const;      // not-null, not valid, muon RPC
00226     int numberOfBadHits() const;              // not-null, bad (only used in Muon Ch.)
00227     int numberOfBadMuonHits() const;          // not-null, bad, muon
00228     int numberOfBadMuonDTHits() const;        // not-null, bad, muon DT
00229     int numberOfBadMuonCSCHits() const;       // not-null, bad, muon CSC
00230     int numberOfBadMuonRPCHits() const;       // not-null, bad, muon RPC
00231 
00232     int numberOfValidStripLayersWithMonoAndStereo () 
00233       const; // count strip layers that have non-null, valid mono and stereo hits
00234 
00235     uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const;
00236     uint32_t getTrackerMonoStereo (uint32_t substr, uint32_t layer) const;
00237 
00238     int trackerLayersWithMeasurement() const;        // case 0: tracker
00239     int pixelLayersWithMeasurement() const;          // case 0: pixel
00240     int stripLayersWithMeasurement() const;          // case 0: strip
00241     int pixelBarrelLayersWithMeasurement() const;    // case 0: pixel PXB
00242     int pixelEndcapLayersWithMeasurement() const;    // case 0: pixel PXF
00243     int stripTIBLayersWithMeasurement() const;       // case 0: strip TIB
00244     int stripTIDLayersWithMeasurement() const;       // case 0: strip TID
00245     int stripTOBLayersWithMeasurement() const;       // case 0: strip TOB
00246     int stripTECLayersWithMeasurement() const;       // case 0: strip TEC
00247     int trackerLayersWithoutMeasurement() const;     // case 1: tracker
00248     int pixelLayersWithoutMeasurement() const;       // case 1: pixel
00249     int stripLayersWithoutMeasurement() const;       // case 1: strip
00250     int pixelBarrelLayersWithoutMeasurement() const; // case 1: pixel PXB
00251     int pixelEndcapLayersWithoutMeasurement() const; // case 1: pixel PXF
00252     int stripTIBLayersWithoutMeasurement() const;    // case 1: strip TIB
00253     int stripTIDLayersWithoutMeasurement() const;    // case 1: strip TID
00254     int stripTOBLayersWithoutMeasurement() const;    // case 1: strip TOB
00255     int stripTECLayersWithoutMeasurement() const;    // case 1: strip TEC
00256     int trackerLayersTotallyOffOrBad() const;        // case 2: tracker
00257     int pixelLayersTotallyOffOrBad() const;          // case 2: pixel
00258     int stripLayersTotallyOffOrBad() const;          // case 2: strip
00259     int pixelBarrelLayersTotallyOffOrBad() const;    // case 2: pixel PXB
00260     int pixelEndcapLayersTotallyOffOrBad() const;    // case 2: pixel PXF
00261     int stripTIBLayersTotallyOffOrBad() const;       // case 2: strip TIB
00262     int stripTIDLayersTotallyOffOrBad() const;       // case 2: strip TID
00263     int stripTOBLayersTotallyOffOrBad() const;       // case 2: strip TOB
00264     int stripTECLayersTotallyOffOrBad() const;       // case 2: strip TEC
00265     int trackerLayersNull() const;                   // case 999999: tracker
00266     int pixelLayersNull() const;                     // case 999999: pixel
00267     int stripLayersNull() const;                     // case 999999: strip
00268     int pixelBarrelLayersNull() const;               // case 999999: pixel PXB
00269     int pixelEndcapLayersNull() const;               // case 999999: pixel PXF
00270     int stripTIBLayersNull() const;                  // case 999999: strip TIB
00271     int stripTIDLayersNull() const;                  // case 999999: strip TID
00272     int stripTOBLayersNull() const;                  // case 999999: strip TOB
00273     int stripTECLayersNull() const;                  // case 999999: strip TEC
00274 
00275 
00276 
00278     int muonStations(int subdet, int hitType) const ;
00279 
00280     int muonStationsWithValidHits() const ;
00281     int muonStationsWithBadHits() const ;
00282     int muonStationsWithAnyHits() const ;
00283     int dtStationsWithValidHits() const ;
00284     int dtStationsWithBadHits() const ;
00285     int dtStationsWithAnyHits() const ;
00286     int cscStationsWithValidHits() const ;
00287     int cscStationsWithBadHits() const ;
00288     int cscStationsWithAnyHits() const ;
00289     int rpcStationsWithValidHits() const ;
00290     int rpcStationsWithBadHits() const ;
00291     int rpcStationsWithAnyHits() const ;
00292 
00294     int innermostMuonStationWithHits(int hitType) const ;
00295     int innermostMuonStationWithValidHits() const ;
00296     int innermostMuonStationWithBadHits() const ;
00297     int innermostMuonStationWithAnyHits() const ;
00298 
00300     int outermostMuonStationWithHits(int hitType) const ;
00301     int outermostMuonStationWithValidHits() const ;
00302     int outermostMuonStationWithBadHits() const ;
00303     int outermostMuonStationWithAnyHits() const ;
00304 
00305     int numberOfDTStationsWithRPhiView() const ;
00306     int numberOfDTStationsWithRZView() const ;
00307     int numberOfDTStationsWithBothViews() const ;
00308   private:
00309 
00310     // number of 32 bit integers to store the full pattern
00311     const static unsigned short PatternSize = 25;
00312 
00313     // number of bits used for each hit
00314     const static unsigned short HitSize = 11;    
00315  
00316     // 1 bit to distinguish tracker and muon subsystems
00317     const static unsigned short SubDetectorOffset = 10; 
00318     const static unsigned short SubDetectorMask = 0x1;
00319 
00320     // 3 bits to identify the tracker/muon detector substructure
00321     const static unsigned short SubstrOffset = 7; 
00322     const static unsigned short SubstrMask = 0x7;
00323 
00324     // 4 bits to identify the layer/disk/wheel within the substructure
00325     const static unsigned short LayerOffset = 3; 
00326     const static unsigned short LayerMask = 0xF;
00327 
00328     // 1 bit to identify the side in double-sided detectors
00329     const static unsigned short SideOffset = 2;
00330     const static unsigned short SideMask = 0x1;
00331 
00332     // 2 bits for hit type
00333     const static unsigned short HitTypeOffset = 0;
00334     const static unsigned short HitTypeMask = 0x3;
00335 
00336     // full hit pattern information is packed in PatternSize 32 bit words
00337     uint32_t hitPattern_[ PatternSize ]; 
00338 
00339     // set pattern for position-th hit
00340     void setHitPattern(int position, uint32_t pattern);
00341 
00342     // set pattern for i-th hit passing a reference
00343     void set(const TrackingRecHitRef & ref, unsigned int i) { set(* ref, i); }
00344 
00345     // detector side for tracker modules (mono/stereo)
00346     static uint32_t isStereo (DetId);
00347   };
00348 } 
00349 
00350 #endif