File indexing completed on 2024-04-06 12:04:47
0001
0002
0003
0004
0005
0006
0007
0008 #include <DataFormats/MuonDetId/interface/RPCDetId.h>
0009 #include <DataFormats/MuonDetId/interface/MuonSubdetId.h>
0010
0011 #include <iostream>
0012
0013 RPCDetId::RPCDetId() : DetId(DetId::Muon, MuonSubdetId::RPC), trind(0) {}
0014
0015 RPCDetId::RPCDetId(uint32_t id) : DetId(id), trind(0) {
0016
0017 if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
0018 throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
0019 << " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
0020 }
0021 }
0022 RPCDetId::RPCDetId(DetId id) : DetId(id), trind(0) {
0023
0024 if (det() != DetId::Muon || subdetId() != MuonSubdetId::RPC) {
0025 throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
0026 << " det: " << det() << " subdet: " << subdetId() << " is not a valid RPC id";
0027 }
0028 }
0029
0030 RPCDetId::RPCDetId(int region, int ring, int station, int sector, int layer, int subsector, int roll)
0031 : DetId(DetId::Muon, MuonSubdetId::RPC), trind(0) {
0032 this->init(region, ring, station, sector, layer, subsector, roll);
0033 }
0034
0035 void RPCDetId::buildfromDB(int region,
0036 int ring,
0037 int trlayer,
0038 int sector,
0039 const std::string& subs,
0040 const std::string& roll,
0041 const std::string& dbname) {
0042 bool barrel = (region == 0);
0043
0044 int station = -1;
0045 if (barrel) {
0046 if (trlayer == 1 || trlayer == 2)
0047 station = 1;
0048 else if (trlayer == 3 || trlayer == 4)
0049 station = 2;
0050 else
0051 station = trlayer - 2;
0052 } else {
0053 station = abs(ring);
0054 }
0055
0056
0057
0058
0059
0060
0061
0062 int subsector = 1;
0063
0064 if (barrel) {
0065 if (station == 3 && subs == "+")
0066 subsector = 2;
0067 if (station == 4 &&
0068 (sector == 1 || sector == 2 || sector == 3 || sector == 5 || sector == 6 || sector == 7 || sector == 8 ||
0069 sector == 10 || sector == 12) &&
0070 (subs == "+")) {
0071 subsector = 2;
0072 }
0073
0074 if (station == 4 && sector == 4) {
0075 if (subs == "--")
0076 subsector = 1;
0077 if (subs == "-")
0078 subsector = 2;
0079 if (subs == "+")
0080 subsector = 3;
0081 if (subs == "++")
0082 subsector = 4;
0083 }
0084 }
0085
0086
0087 int iroll = 0;
0088
0089 if (roll == "Backward" || roll == "A")
0090 iroll = 1;
0091 else if (roll == "Central" || roll == "B")
0092 iroll = 2;
0093 else if (roll == "Forward" || roll == "C")
0094 iroll = 3;
0095 else if (roll == "D")
0096 iroll = 4;
0097 else {
0098 std::cout << "** RPC: DBSpecToDetUnit, how to assigne roll to: " << roll << " ???" << std::endl;
0099 }
0100
0101 int trIndex = 0;
0102 if (barrel) {
0103
0104 int eta_id = 6 + ring;
0105 int plane_id = station;
0106 if (trlayer == 2)
0107 plane_id = 5;
0108 if (trlayer == 4)
0109 plane_id = 6;
0110 int sector_id = sector * 3;
0111 int copy_id = subsector;
0112 int roll_id = iroll;
0113 trIndex = (eta_id * 10000 + plane_id * 1000 + sector_id * 10 + copy_id) * 10 + roll_id;
0114 } else {
0115
0116 int eta_id = trlayer;
0117 if (ring > 0)
0118 eta_id = 12 - trlayer;
0119 int plane_id = abs(ring);
0120 int sector_id = sector;
0121
0122 if (region < 0) {
0123 if (sector_id < 20) {
0124 sector_id = 19 + 1 - sector_id;
0125 } else {
0126 sector_id = 36 + 20 - sector_id;
0127 }
0128 }
0129 sector_id -= 1;
0130
0131
0132 int copy_id = 1;
0133 int roll_id = iroll;
0134 trIndex = (eta_id * 10000 + plane_id * 1000 + sector_id * 10 + copy_id) * 10 + roll_id;
0135 }
0136 this->buildfromTrIndex(trIndex);
0137 }
0138
0139 void RPCDetId::buildfromTrIndex(int trIndex) {
0140 trind = trIndex;
0141 int eta_id = trIndex / 100000;
0142 int region = 0;
0143 int ring = 0;
0144 if (eta_id <= 3) {
0145 region = -1;
0146 ring = eta_id;
0147 } else if (eta_id >= 9) {
0148 region = 1;
0149 ring = 12 - eta_id;
0150 } else {
0151 region = 0;
0152 ring = eta_id - 6;
0153 }
0154 trIndex = trIndex % 100000;
0155 int plane_id = trIndex / 10000;
0156 int station = 0;
0157 int layer = 0;
0158 if (plane_id <= 4) {
0159 station = plane_id;
0160 layer = 1;
0161 } else {
0162 station = plane_id - 4;
0163 layer = 2;
0164 }
0165 trIndex = trIndex % 10000;
0166 int sector_id = trIndex / 100;
0167
0168
0169
0170
0171
0172
0173
0174
0175
0176 if (region != 0) {
0177 if (!(ring == 1 && station > 1 && region == 1)) {
0178
0179 if (!(ring == 1 && station == 1 && region != 0)) {
0180 sector_id += 1;
0181 if (sector_id == 37)
0182 sector_id = 1;
0183 }
0184 }
0185 }
0186
0187 if (region == -1) {
0188 if (sector_id < 20) {
0189 sector_id = 19 + 1 - sector_id;
0190 } else {
0191 sector_id = 36 + 20 - sector_id;
0192 }
0193 }
0194 trIndex = trIndex % 100;
0195 int copy_id = trIndex / 10;
0196 int sector = (sector_id - 1) / 3 + 1;
0197 if (region != 0) {
0198 sector = (sector + 1) / 2;
0199 }
0200 int subsector = 0;
0201 if (region == 0) {
0202 subsector = copy_id;
0203 } else {
0204 if (ring == 1 && station > 1) {
0205
0206 subsector = ((sector_id + 1) / 2 - 1) % 3 + 1;
0207 } else {
0208
0209 subsector = (sector_id - 1) % 6 + 1;
0210 }
0211
0212
0213 }
0214
0215 int roll = trIndex % 10;
0216 this->init(region, ring, station, sector, layer, subsector, roll);
0217 }
0218
0219 void RPCDetId::init(int region, int ring, int station, int sector, int layer, int subsector, int roll) {
0220 int minRing = 0;
0221 int maxRing = RPCDetId::maxRingForwardId;
0222 if (!region) {
0223 minRing = RPCDetId::minRingBarrelId;
0224 maxRing = RPCDetId::maxRingBarrelId;
0225 }
0226
0227 if (region < minRegionId || region > maxRegionId || ring < minRing || ring > maxRing || station < minStationId ||
0228 station > maxStationId || sector < minSectorId || sector > maxSectorId || layer < minLayerId ||
0229 layer > maxLayerId || subsector < minSubSectorId || subsector > maxSubSectorId || roll < minRollId ||
0230 roll > maxRollId) {
0231 throw cms::Exception("InvalidDetId") << "RPCDetId ctor:"
0232 << " Invalid parameters: "
0233 << " region " << region << " ring " << ring << " station " << station
0234 << " sector " << sector << " layer " << layer << " subsector " << subsector
0235 << " roll " << roll << std::endl;
0236 }
0237
0238 int regionInBits = region - minRegionId;
0239 int ringInBits = 0;
0240 if (region != 0)
0241 ringInBits = ring - minRingForwardId;
0242 if (!region)
0243 ringInBits = ring + RingBarrelOffSet - minRingBarrelId;
0244
0245 int stationInBits = station - minStationId;
0246 int sectorInBits = sector - (minSectorId + 1);
0247 int layerInBits = layer - minLayerId;
0248 int subSectorInBits = subsector - (minSubSectorId + 1);
0249 int rollInBits = roll;
0250
0251 id_ |= (regionInBits & RegionMask_) << RegionStartBit_ | (ringInBits & RingMask_) << RingStartBit_ |
0252 (stationInBits & StationMask_) << StationStartBit_ | (sectorInBits & SectorMask_) << SectorStartBit_ |
0253 (layerInBits & LayerMask_) << LayerStartBit_ | (subSectorInBits & SubSectorMask_) << SubSectorStartBit_ |
0254 (rollInBits & RollMask_) << RollStartBit_;
0255 }
0256
0257 std::ostream& operator<<(std::ostream& os, const RPCDetId& id) {
0258 os << " Re " << id.region() << " Ri " << id.ring() << " St " << id.station() << " Se " << id.sector() << " La "
0259 << id.layer() << " Su " << id.subsector() << " Ro " << id.roll() << " Tr " << id.trIndex() << " ";
0260
0261 return os;
0262 }