File indexing completed on 2024-04-06 12:04:46
0001 #ifndef MuonDetId_RPCDetId_h
0002 #define MuonDetId_RPCDetId_h
0003
0004
0005
0006
0007
0008
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
0021
0022 RPCDetId(uint32_t id);
0023 RPCDetId(DetId id);
0024
0025
0026 RPCDetId(int region, int ring, int station, int sector, int layer, int subsector, int roll);
0027
0028
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
0050 void buildfromTrIndex(int trIndex);
0051
0052
0053 int region() const { return int((id_ >> RegionStartBit_) & RegionMask_) + minRegionId; }
0054
0055
0056
0057
0058
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 {
0072 return int(ring_ - RingBarrelOffSet + minRingBarrelId);
0073 }
0074 }
0075
0076
0077
0078 int station() const { return int((id_ >> StationStartBit_) & StationMask_) + minStationId; }
0079
0080
0081 int sector() const { return int((id_ >> SectorStartBit_) & SectorMask_) + (minSectorId + 1); }
0082
0083
0084
0085 int layer() const { return int((id_ >> LayerStartBit_) & LayerMask_) + minLayerId; }
0086
0087
0088 int subsector() const { return int((id_ >> SubSectorStartBit_) & SubSectorMask_) + (minSubSectorId + 1); }
0089
0090
0091
0092 int roll() const {
0093 return int((id_ >> RollStartBit_) & RollMask_);
0094 }
0095
0096 int trIndex() const { return trind; }
0097
0098
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;
0132
0133
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 };
0172
0173 std::ostream& operator<<(std::ostream& os, const RPCDetId& id);
0174
0175 #endif