CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/src/DataFormats/MuonDetId/interface/RPCDetId.h

Go to the documentation of this file.
00001 #ifndef MuonDetId_RPCDetId_h
00002 #define MuonDetId_RPCDetId_h
00003 
00014 #include <DataFormats/DetId/interface/DetId.h>
00015 #include <FWCore/Utilities/interface/Exception.h>
00016 
00017 #include <iosfwd>
00018 #include <iostream>
00019 
00020 class RPCDetId :public DetId {
00021   
00022  public:
00023       
00024   RPCDetId();
00025 
00028   RPCDetId(uint32_t id);
00029   RPCDetId(DetId id);
00030 
00031 
00033   RPCDetId(int region, 
00034            int ring,
00035            int station, 
00036            int sector,
00037            int layer,
00038            int subsector,
00039            int roll);
00040            
00042   bool operator < (const RPCDetId& r) const{
00043     if (r.station() == this->station()){
00044       if (this->layer() == r.layer()){
00045         return this->rawId()<r.rawId();
00046       }
00047       else{
00048         return (this->layer() < r.layer());
00049       }
00050     }
00051     else {
00052       return this->station() < r.station();
00053     }
00054   }
00055 
00056   void buildfromDB(int region, int ring, int layer, int sector, 
00057                    const std::string& subsector,
00058                    const std::string& roll,
00059                    const std::string& dbname);
00060 
00062   void buildfromTrIndex(int trIndex);
00063 
00065   int region() const{
00066     return int((id_>>RegionStartBit_) & RegionMask_) + minRegionId;
00067   }
00068 
00069 
00074   int ring() const{
00075   
00076     int ring_= (id_>>RingStartBit_) & RingMask_;
00077     
00078     if(ring_ <RingBarrelOffSet){
00079     
00080         if(this->region() == 0)
00081         {
00082          throw cms::Exception("InvalidDetId") << "RPCDetId ctor:" 
00083                                          << " Ring - Region Inconsistency, " 
00084                                          << " region "<< this->region()
00085                                          << " ring "<<ring_
00086                                          << std::endl;
00087         }
00088          
00089         return int(ring_ + minRingForwardId);
00090 
00091     } else { // if(ring_ >= RingBarrelOffSet) 
00092       return int(ring_ - RingBarrelOffSet + minRingBarrelId);
00093     }
00094   }
00095 
00098   int station() const{
00099     return int((id_>>StationStartBit_) & StationMask_) + minStationId;
00100   }
00101 
00102 
00104   int sector() const{
00105     return int((id_>>SectorStartBit_) & SectorMask_) + (minSectorId+1);
00106   }
00107 
00110   int layer() const{
00111     return int((id_>>LayerStartBit_) & LayerMask_) + minLayerId;
00112   }
00113 
00114 
00116   int subsector() const{
00117     return int((id_>>SubSectorStartBit_) & SubSectorMask_) + (minSubSectorId+1);
00118   }
00119 
00122   int roll() const{
00123     return int((id_>>RollStartBit_) & RollMask_); // value 0 is used as wild card
00124   }
00125 
00126 
00127   int trIndex() const{
00128     return trind;
00129   }
00130 
00132   RPCDetId chamberId() const {
00133     return RPCDetId(id_ & chamberIdMask_);
00134   }
00135 
00136 
00137   static const int minRegionId=     -1;
00138   static const int maxRegionId=      1;
00139  
00140   static const int minRingForwardId=   1;
00141   static const int maxRingForwardId=   3;
00142   static const int minRingBarrelId=   -2;
00143   static const int maxRingBarrelId=    2;
00144   static const int RingBarrelOffSet=   3;
00145  
00146   static const int minStationId=     1;
00147   static const int maxStationId=     4;
00148 
00149   static const int minSectorId=     0;
00150   static const int maxSectorId=     12;
00151   static const int minSectorBarrelId=     1;
00152   static const int maxSectorBarrelId=     12;
00153   static const int minSectorForwardId=     1;
00154   static const int maxSectorForwardId=     6;
00155 
00156   static const int minLayerId=     1;
00157   static const int maxLayerId=     2;
00158 
00159   static const int minSubSectorId=       0;
00160   static const int maxSubSectorId=       6;
00161   static const int minSubSectorBarrelId=         1;
00162   static const int maxSubSectorBarrelId=         4;
00163   static const int minSubSectorForwardId=        1;
00164   static const int maxSubSectorForwardId=        6;
00165 
00166   static const int minRollId=     0;
00167   static const int maxRollId=     4;
00168 
00169 
00170  private:
00171   static const int RegionNumBits_  =  2;
00172   static const int RegionStartBit_ =  0;  
00173   static const int RegionMask_     =  0X3;
00174 
00175   static const int RingNumBits_  =  3;
00176   static const int RingStartBit_ =  RegionStartBit_+RegionNumBits_;  
00177   static const unsigned int RingMask_     =  0X7;
00178 
00179   static const int StationNumBits_  =  2;
00180   static const int StationStartBit_ =  RingStartBit_+RingNumBits_;  
00181   static const unsigned int StationMask_     =  0X3;
00182 
00183 
00184   static const int SectorNumBits_  =  4;
00185   static const int SectorStartBit_ =  StationStartBit_+StationNumBits_;  
00186   static const unsigned int SectorMask_     =  0XF;
00187 
00188   static const int LayerNumBits_  =  1;
00189   static const int LayerStartBit_ =  SectorStartBit_+SectorNumBits_;  
00190   static const unsigned int LayerMask_     =  0X1;
00191 
00192   static const int SubSectorNumBits_  =  3;
00193   static const int SubSectorStartBit_ =  LayerStartBit_+LayerNumBits_;  
00194   static const unsigned int SubSectorMask_     =  0X7;
00195   
00196   static const int RollNumBits_  =  3;
00197   static const int RollStartBit_ =  SubSectorStartBit_+SubSectorNumBits_;  
00198   static const unsigned int RollMask_     =  0X7;
00199  
00200   static const uint32_t chamberIdMask_ = ~(RollMask_<<RollStartBit_);
00201 
00202  private:
00203   void init(int region, 
00204             int ring,
00205             int station, 
00206             int sector,
00207             int layer,
00208             int subsector,
00209             int roll);
00210   
00211   int trind;
00212 }; // RPCDetId
00213 
00214 std::ostream& operator<<( std::ostream& os, const RPCDetId& id );
00215 
00216 #endif