Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:04:46

0001 #ifndef MuonDetId_RPCDetId_h
0002 #define MuonDetId_RPCDetId_h
0003 
0004 /** \class RPCDetId
0005  * 
0006  *  DetUnit identifier for RPCs
0007  *
0008  *  \author Ilaria Segoni
0009  */
0010 
0011 #include <DataFormats/DetId/interface/DetId.h>
0012 #include <FWCore/Utilities/interface/Exception.h>
0013 
0014 #include <iosfwd>
0015 
0016 class RPCDetId : public DetId {
0017 public:
0018   RPCDetId();
0019 
0020   /// Construct from a packed id. It is required that the Detector part of
0021   /// id is Muon and the SubDet part is RPC, otherwise an exception is thrown.
0022   RPCDetId(uint32_t id);
0023   RPCDetId(DetId id);
0024 
0025   /// Construct from fully qualified identifier.
0026   RPCDetId(int region, int ring, int station, int sector, int layer, int subsector, int roll);
0027 
0028   /// Sort Operator based on the raw detector id
0029   bool operator<(const RPCDetId& r) const {
0030     if (r.station() == this->station()) {
0031       if (this->layer() == r.layer()) {
0032         return this->rawId() < r.rawId();
0033       } else {
0034         return (this->layer() < r.layer());
0035       }
0036     } else {
0037       return this->station() < r.station();
0038     }
0039   }
0040 
0041   void buildfromDB(int region,
0042                    int ring,
0043                    int layer,
0044                    int sector,
0045                    const std::string& subsector,
0046                    const std::string& roll,
0047                    const std::string& dbname);
0048 
0049   /// Built from the trigger det Index
0050   void buildfromTrIndex(int trIndex);
0051 
0052   /// Region id: 0 for Barrel, +/-1 For +/- Endcap
0053   int region() const { return int((id_ >> RegionStartBit_) & RegionMask_) + minRegionId; }
0054 
0055   /// Ring id: Wheel number in Barrel (from -2 to +2) Ring Number in Endcap (from 1 to 3)
0056   /// Ring has a different meaning in Barrel and Endcap! In Barrel it is wheel, in Endcap
0057   /// it is the physical ring located on a disk (a disk contains three rings). In Endcap
0058   /// the ring is the group of chambers with same r (distance of beam axis) and increasing phi
0059   int ring() const {
0060     int ring_ = (id_ >> RingStartBit_) & RingMask_;
0061 
0062     if (ring_ < RingBarrelOffSet) {
0063       if (this->region() == 0) {
0064         throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
0065                                              << " Ring - Region Inconsistency, "
0066                                              << " region " << this->region() << " ring " << ring_ << std::endl;
0067       }
0068 
0069       return int(ring_ + minRingForwardId);
0070 
0071     } else {  // if(ring_ >= RingBarrelOffSet)
0072       return int(ring_ - RingBarrelOffSet + minRingBarrelId);
0073     }
0074   }
0075 
0076   /// Station id : For Barrel: the four groups of chambers at same r (distance from beam axis) and increasing phi
0077   ///              For Endcap: the three groups of chambers at same z (distance from interaction point), i.e. the disk
0078   int station() const { return int((id_ >> StationStartBit_) & StationMask_) + minStationId; }
0079 
0080   /// Sector id: the group of chambers at same phi (and increasing r)
0081   int sector() const { return int((id_ >> SectorStartBit_) & SectorMask_) + (minSectorId + 1); }
0082 
0083   /// Layer id: each station can have two layers of chambers: layer 1 is the inner chamber and layer 2 is the outer chamber (when present)
0084   /// Only in Barrel: RB1 and RB2.
0085   int layer() const { return int((id_ >> LayerStartBit_) & LayerMask_) + minLayerId; }
0086 
0087   /// SubSector id : some sectors are divided along the phi direction in subsectors (from 1 to 4 in Barrel, from 1 to 6 in Endcap)
0088   int subsector() const { return int((id_ >> SubSectorStartBit_) & SubSectorMask_) + (minSubSectorId + 1); }
0089 
0090   /// Roll id  (also known as eta partition): each chamber is divided along the strip direction in
0091   /// two or three parts (rolls) for Barrel and two, three or four parts for endcap
0092   int roll() const {
0093     return int((id_ >> RollStartBit_) & RollMask_);  // value 0 is used as wild card
0094   }
0095 
0096   int trIndex() const { return trind; }
0097 
0098   /// Return the corresponding ChamberId
0099   RPCDetId chamberId() const { return RPCDetId(id_ & chamberIdMask_); }
0100 
0101   static constexpr int minRegionId = -1;
0102   static constexpr int maxRegionId = 1;
0103 
0104   static constexpr int minRingForwardId = 1;
0105   static constexpr int maxRingForwardId = 3;
0106   static constexpr int minRingBarrelId = -2;
0107   static constexpr int maxRingBarrelId = 2;
0108   static constexpr int RingBarrelOffSet = 3;
0109 
0110   static constexpr int minStationId = 1;
0111   static constexpr int maxStationId = 4;
0112 
0113   static constexpr int minSectorId = 0;
0114   static constexpr int maxSectorId = 12;
0115   static constexpr int minSectorBarrelId = 1;
0116   static constexpr int maxSectorBarrelId = 12;
0117   static constexpr int minSectorForwardId = 1;
0118   static constexpr int maxSectorForwardId = 6;
0119 
0120   static constexpr int minLayerId = 1;
0121   static constexpr int maxLayerId = 2;
0122 
0123   static constexpr int minSubSectorId = 0;
0124   static constexpr int maxSubSectorId = 6;
0125   static constexpr int minSubSectorBarrelId = 1;
0126   static constexpr int maxSubSectorBarrelId = 4;
0127   static constexpr int minSubSectorForwardId = 1;
0128   static constexpr int maxSubSectorForwardId = 6;
0129 
0130   static constexpr int minRollId = 0;
0131   static constexpr int maxRollId = 5;  // used to be 4 ... need 5 for upgrade
0132                                        // if we decide to divide the upgrade RE3/1 and RE4/1 up to eta=2.4
0133                                        // and we want basically to have 0.10 eta / roll ...
0134 
0135 private:
0136   static constexpr int RegionNumBits_ = 2;
0137   static constexpr int RegionStartBit_ = 0;
0138   static constexpr int RegionMask_ = 0X3;
0139 
0140   static constexpr int RingNumBits_ = 3;
0141   static constexpr int RingStartBit_ = RegionStartBit_ + RegionNumBits_;
0142   static constexpr unsigned int RingMask_ = 0X7;
0143 
0144   static constexpr int StationNumBits_ = 2;
0145   static constexpr int StationStartBit_ = RingStartBit_ + RingNumBits_;
0146   static constexpr unsigned int StationMask_ = 0X3;
0147 
0148   static constexpr int SectorNumBits_ = 4;
0149   static constexpr int SectorStartBit_ = StationStartBit_ + StationNumBits_;
0150   static constexpr unsigned int SectorMask_ = 0XF;
0151 
0152   static constexpr int LayerNumBits_ = 1;
0153   static constexpr int LayerStartBit_ = SectorStartBit_ + SectorNumBits_;
0154   static constexpr unsigned int LayerMask_ = 0X1;
0155 
0156   static constexpr int SubSectorNumBits_ = 3;
0157   static constexpr int SubSectorStartBit_ = LayerStartBit_ + LayerNumBits_;
0158   static constexpr unsigned int SubSectorMask_ = 0X7;
0159 
0160   static constexpr int RollNumBits_ = 3;
0161   static constexpr int RollStartBit_ = SubSectorStartBit_ + SubSectorNumBits_;
0162   static constexpr unsigned int RollMask_ = 0X7;
0163 
0164 public:
0165   static constexpr uint32_t chamberIdMask_ = ~(RollMask_ << RollStartBit_);
0166 
0167 private:
0168   void init(int region, int ring, int station, int sector, int layer, int subsector, int roll);
0169 
0170   int trind;
0171 };  // RPCDetId
0172 
0173 std::ostream& operator<<(std::ostream& os, const RPCDetId& id);
0174 
0175 #endif