CMS 3D CMS Logo

/afs/cern.ch/work/a/aaltunda/public/www/CMSSW_6_2_5/src/DataFormats/MuonDetId/interface/CSCDetId.h

Go to the documentation of this file.
00001 #ifndef MuonDetId_CSCDetId_h
00002 #define MuonDetId_CSCDetId_h
00003 
00019 #include <iosfwd>
00020 #include <DataFormats/DetId/interface/DetId.h>
00021 #include <DataFormats/MuonDetId/interface/MuonSubdetId.h>
00022 
00023 class CSCDetId;
00024 
00025 std::ostream& operator<<( std::ostream& os, const CSCDetId& id );
00026 
00027 class CSCDetId : public DetId {
00028 
00029 public:
00030 
00033   CSCDetId();
00034 
00037   CSCDetId(uint32_t id);
00038   CSCDetId(DetId id);
00039 
00044   CSCDetId( int iendcap, int istation, 
00045             int iring, int ichamber, 
00046             int ilayer = 0 );
00047 
00050   CSCDetId( const CSCDetId& id )
00051      : DetId(id.id_) { }  
00052 
00055   CSCDetId chamberId() const {
00056     // build chamber id by removing layer bits
00057     return CSCDetId( id_ - layer() ) ; }
00058 
00063   int layer() const {
00064     return (id_ & MASK_LAYER); } 
00065 
00070    int chamber() const {
00071      return (  (id_>>START_CHAMBER) & MASK_CHAMBER ); }
00072 
00077    int ring() const {
00078      if (((id_>>START_STATION) & MASK_STATION) == 1)
00079        return (  detIdToInt((id_>>START_RING) & MASK_RING )); 
00080      else
00081        return (((id_>>START_RING) & MASK_RING )); 
00082    }
00083 
00088    int station() const {
00089      return (  (id_>>START_STATION) & MASK_STATION ); }
00090 
00095    int endcap() const {
00096      return (  (id_>>START_ENDCAP) & MASK_ENDCAP ); }
00097 
00102    short int zendcap() const {
00103      return ( endcap()!=1 ? -1 : +1 );
00104    }
00105 
00109    unsigned short iChamberType() {
00110      return iChamberType( station(), ring() );
00111    }
00112 
00120    int channel( int istrip ) { 
00121      if ( ring()== 4 ) 
00122        // strips 1-48 mapped to channels 1-16:
00123        // 1+17+33->1, 2+18+34->2, .... 16+32+48->16
00124        return 1 + (istrip-1)%16; 
00125      else 
00126        return istrip; 
00127    }
00128 
00129   // static methods
00130   // Used when we need information about subdetector labels.
00131 
00146    static int rawIdMaker( int iendcap, int istation, int iring, 
00147                int ichamber, int ilayer ) {
00148      return ( (DetId::Muon&0xF)<<(DetId::kDetOffset) ) |            // set Muon flag
00149             ( (MuonSubdetId::CSC&0x7)<<(DetId::kSubdetOffset) ) |   // set CSC flag
00150                init(iendcap, istation, iring, ichamber, ilayer) ; } // set CSC id
00151 
00156    static int layer( int index ) {
00157      return (index & MASK_LAYER); }
00158 
00163    static int chamber( int index ) {
00164      return (  (index>>START_CHAMBER) & MASK_CHAMBER ); }
00165 
00170    static int ring( int index ) {
00171      if (((index>>START_STATION) & MASK_STATION) == 1)
00172        return (  detIdToInt((index>>START_RING) & MASK_RING )); 
00173      else
00174        return (( index>>START_RING) & MASK_RING ); 
00175    }
00176 
00181    static int station( int index ) {
00182      return (  (index>>START_STATION) & MASK_STATION ); }
00183 
00188    static int endcap( int index ) {
00189      return (  (index>>START_ENDCAP) & MASK_ENDCAP ); }
00190 
00197    static unsigned short iChamberType( unsigned short istation, unsigned short iring );
00198 
00218    int triggerSector() const;
00219 
00233    int triggerCscId() const;
00234 
00238    static int minEndcapId()  { return MIN_ENDCAP; }
00239    static int maxEndcapId()  { return MAX_ENDCAP; }
00240    static int minStationId() { return MIN_STATION; }
00241    static int maxStationId() { return MAX_STATION; }
00242    static int minRingId()    { return MIN_RING; }
00243    static int maxRingId()    { return MAX_RING; }
00244    static int minChamberId() { return MIN_CHAMBER; }
00245    static int maxChamberId() { return MAX_CHAMBER; }
00246    static int minLayerId()   { return MIN_LAYER; }
00247    static int maxLayerId()   { return MAX_LAYER; }
00248 
00249 private:
00250  
00255   static uint32_t init( int iendcap, int istation, 
00256                         int iring, int ichamber, int ilayer ) {
00257     
00258     if (istation == 1)
00259       iring = intToDetId(iring);
00260 
00261      return
00262          (ilayer   & MASK_LAYER)                      |
00263        ( (ichamber & MASK_CHAMBER) << START_CHAMBER ) |
00264        ( (iring    & MASK_RING)    << START_RING )    |
00265        ( (istation & MASK_STATION) << START_STATION ) | 
00266        ( (iendcap  & MASK_ENDCAP)  << START_ENDCAP ) ; }
00267 
00278   static int intToDetId(int iring) {
00279     // change iring = 1, 2, 3, 4 input to 2, 3, 4, 1 for use inside the DetId
00280     // i.e. ME1b, ME12, ME13, ME1a externally become stored internally in order ME1a, ME1b, ME12, ME13
00281     int i = (iring+1)%4;
00282     if (i == 0)
00283       i = 4;
00284     return i;
00285   }
00286 
00287   static int detIdToInt(int iring) {
00288     // reverse intToDetId: change 1, 2, 3, 4 inside the DetId to 4, 1, 2, 3 for external use
00289     // i.e. output ring # 1, 2, 3, 4 in ME1 means ME1b, ME12, ME13, ME1a as usual in the offline software.
00290     int i = (iring-1);
00291     if (i == 0)
00292       i = 4;
00293     return i;
00294   }
00295  
00296   // The following define the bit-packing implementation...
00297 
00298   // The maximum numbers of various parts
00299   enum eMaxNum{ MAX_ENDCAP=2, MAX_STATION=4, MAX_RING=4, MAX_CHAMBER=36, MAX_LAYER=6 };
00300   // We count from 1 
00301   enum eMinNum{ MIN_ENDCAP=1, MIN_STATION=1, MIN_RING=1, MIN_CHAMBER=1, MIN_LAYER=1 };
00302 
00303   // BITS_det is no. of binary bits required to label 'det' but allow 0 as a wild-card character
00304   // Keep as multiples of 3 so that number can be easily decodable from octal
00305   enum eNumBitDet{ BITS_ENDCAP=3, BITS_STATION=3,  BITS_RING=3, BITS_CHAMBER=6, BITS_LAYER=3 };
00306 
00307   // MASK_det is binary bits set to pick off the bits for 'det' (defined as octal)
00308   enum eMaskBitDet{ MASK_ENDCAP=07, MASK_STATION=07, MASK_RING=07, MASK_CHAMBER=077, MASK_LAYER=07 };
00309 
00310   // START_det is bit position (counting from zero) at which bits for 'det' start in 'rawId' word
00311   enum eStartBitDet{ START_CHAMBER=BITS_LAYER, START_RING=START_CHAMBER+BITS_CHAMBER,
00312           START_STATION=START_RING+BITS_RING, START_ENDCAP=START_STATION+BITS_STATION };
00313 };
00314 
00315 #endif
00316 
00317