CMS 3D CMS Logo

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