CMS 3D CMS Logo

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            layer                             hit type = 0-3
00033 //      |mu = 0      CSC = 2            layer                             hit type = 0-3
00034 //      |mu = 0      RPC = 3            layer                             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 
00174     uint32_t getHitType(uint32_t pattern) const;   // hit type
00175     bool validHitFilter(uint32_t pattern) const;   // hit type 0 = valid
00176     bool type_1_HitFilter(uint32_t pattern) const; // hit type 1
00177     bool type_2_HitFilter(uint32_t pattern) const; // hit type 2
00178     bool type_3_HitFilter(uint32_t pattern) const; // hit type 3
00179 
00180     static uint32_t getSide (uint32_t pattern);         // mono (0) or stereo (1)
00181 
00182     bool hasValidHitInFirstPixelBarrel() const; // has valid hit in PXB layer 1
00183 
00184     int numberOfHits() const;                 // not-null
00185     int numberOfValidHits() const;            // not-null, valid
00186     int numberOfValidTrackerHits() const;     // not-null, valid, tracker
00187     int numberOfValidMuonHits() const;        // not-null, valid, muon
00188     int numberOfValidPixelHits() const;       // not-null, valid, pixel
00189     int numberOfValidPixelBarrelHits() const; // not-null, valid, pixel PXB
00190     int numberOfValidPixelEndcapHits() const; // not-null, valid, pixel PXF
00191     int numberOfValidStripHits() const;       // not-null, valid, strip
00192     int numberOfValidStripTIBHits() const;    // not-null, valid, strip TIB
00193     int numberOfValidStripTIDHits() const;    // not-null, valid, strip TID
00194     int numberOfValidStripTOBHits() const;    // not-null, valid, strip TOB
00195     int numberOfValidStripTECHits() const;    // not-null, valid, strip TEC
00196     int numberOfValidMuonDTHits() const;      // not-null, valid, muon DT
00197     int numberOfValidMuonCSCHits() const;     // not-null, valid, muon CSC
00198     int numberOfValidMuonRPCHits() const;     // not-null, valid, muon RPC
00199     int numberOfLostHits() const;             // not-null, not valid
00200     int numberOfLostTrackerHits() const;      // not-null, not valid, tracker
00201     int numberOfLostMuonHits() const;         // not-null, not valid, muon
00202     int numberOfLostPixelHits() const;        // not-null, not valid, pixel
00203     int numberOfLostPixelBarrelHits() const;  // not-null, not valid, pixel PXB
00204     int numberOfLostPixelEndcapHits() const;  // not-null, not valid, pixel PXF
00205     int numberOfLostStripHits() const;        // not-null, not valid, strip
00206     int numberOfLostStripTIBHits() const;     // not-null, not valid, strip TIB
00207     int numberOfLostStripTIDHits() const;     // not-null, not valid, strip TID
00208     int numberOfLostStripTOBHits() const;     // not-null, not valid, strip TOB
00209     int numberOfLostStripTECHits() const;     // not-null, not valid, strip TEC
00210     int numberOfLostMuonDTHits() const;       // not-null, not valid, muon DT
00211     int numberOfLostMuonCSCHits() const;      // not-null, not valid, muon CSC
00212     int numberOfLostMuonRPCHits() const;      // not-null, not valid, muon RPC
00213 
00214     int numberOfValidStripLayersWithMonoAndStereo () 
00215       const; // count strip layers that have non-null, valid mono and stereo hits
00216 
00217     uint32_t getTrackerLayerCase(uint32_t substr, uint32_t layer) const;
00218     uint32_t getTrackerMonoStereo (uint32_t substr, uint32_t layer) const;
00219 
00220     int trackerLayersWithMeasurement() const;        // case 0: tracker
00221     int pixelLayersWithMeasurement() const;          // case 0: pixel
00222     int stripLayersWithMeasurement() const;          // case 0: strip
00223     int pixelBarrelLayersWithMeasurement() const;    // case 0: pixel PXB
00224     int pixelEndcapLayersWithMeasurement() const;    // case 0: pixel PXF
00225     int stripTIBLayersWithMeasurement() const;       // case 0: strip TIB
00226     int stripTIDLayersWithMeasurement() const;       // case 0: strip TID
00227     int stripTOBLayersWithMeasurement() const;       // case 0: strip TOB
00228     int stripTECLayersWithMeasurement() const;       // case 0: strip TEC
00229     int trackerLayersWithoutMeasurement() const;     // case 1: tracker
00230     int pixelLayersWithoutMeasurement() const;       // case 1: pixel
00231     int stripLayersWithoutMeasurement() const;       // case 1: strip
00232     int pixelBarrelLayersWithoutMeasurement() const; // case 1: pixel PXB
00233     int pixelEndcapLayersWithoutMeasurement() const; // case 1: pixel PXF
00234     int stripTIBLayersWithoutMeasurement() const;    // case 1: strip TIB
00235     int stripTIDLayersWithoutMeasurement() const;    // case 1: strip TID
00236     int stripTOBLayersWithoutMeasurement() const;    // case 1: strip TOB
00237     int stripTECLayersWithoutMeasurement() const;    // case 1: strip TEC
00238     int trackerLayersTotallyOffOrBad() const;        // case 2: tracker
00239     int pixelLayersTotallyOffOrBad() const;          // case 2: pixel
00240     int stripLayersTotallyOffOrBad() const;          // case 2: strip
00241     int pixelBarrelLayersTotallyOffOrBad() const;    // case 2: pixel PXB
00242     int pixelEndcapLayersTotallyOffOrBad() const;    // case 2: pixel PXF
00243     int stripTIBLayersTotallyOffOrBad() const;       // case 2: strip TIB
00244     int stripTIDLayersTotallyOffOrBad() const;       // case 2: strip TID
00245     int stripTOBLayersTotallyOffOrBad() const;       // case 2: strip TOB
00246     int stripTECLayersTotallyOffOrBad() const;       // case 2: strip TEC
00247     int trackerLayersNull() const;                   // case 999999: tracker
00248     int pixelLayersNull() const;                     // case 999999: pixel
00249     int stripLayersNull() const;                     // case 999999: strip
00250     int pixelBarrelLayersNull() const;               // case 999999: pixel PXB
00251     int pixelEndcapLayersNull() const;               // case 999999: pixel PXF
00252     int stripTIBLayersNull() const;                  // case 999999: strip TIB
00253     int stripTIDLayersNull() const;                  // case 999999: strip TID
00254     int stripTOBLayersNull() const;                  // case 999999: strip TOB
00255     int stripTECLayersNull() const;                  // case 999999: strip TEC
00256 
00257   private:
00258 
00259     // number of 32 bit integers to store the full pattern
00260     const static unsigned short PatternSize = 25;
00261 
00262     // number of bits used for each hit
00263     const static unsigned short HitSize = 11;    
00264  
00265     // 1 bit to distinguish tracker and muon subsystems
00266     const static unsigned short SubDetectorOffset = 10; 
00267     const static unsigned short SubDetectorMask = 0x1;
00268 
00269     // 3 bits to identify the tracker/muon detector substructure
00270     const static unsigned short SubstrOffset = 7; 
00271     const static unsigned short SubstrMask = 0x7;
00272 
00273     // 4 bits to identify the layer/disk/wheel within the substructure
00274     const static unsigned short LayerOffset = 3; 
00275     const static unsigned short LayerMask = 0xF;
00276 
00277     // 1 bit to identify the side in double-sided detectors
00278     const static unsigned short SideOffset = 2;
00279     const static unsigned short SideMask = 0x1;
00280 
00281     // 2 bits for hit type
00282     const static unsigned short HitTypeOffset = 0;
00283     const static unsigned short HitTypeMask = 0x3;
00284 
00285     // full hit pattern information is packed in PatternSize 32 bit words
00286     uint32_t hitPattern_[ PatternSize ]; 
00287 
00288     // set pattern for position-th hit
00289     void setHitPattern(int position, uint32_t pattern);
00290 
00291     // set pattern for i-th hit passing a reference
00292     void set(const TrackingRecHitRef & ref, unsigned int i) { set(* ref, i); }
00293 
00294     // detector side for tracker modules (mono/stereo)
00295     static uint32_t isStereo (DetId);
00296   };
00297 } 
00298 
00299 #endif

Generated on Tue Jun 9 17:31:47 2009 for CMSSW by  doxygen 1.5.4