ATLAS Offline Software
Loading...
Searching...
No Matches
RPCSLStripConverter.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5// Class to create unique 32-bit identifiers for the RPC strips and to convert them back to the original offline variables.
6// The identifiers are created by packing the following variables into a single 32-bit integer:
7// NOTICE: Most of the offline variables are 1-based, but this tool assumes 0-based indexing for the identifier to be packed.
8// sector, doubletPhi, doubletR, RPCStation, stationEta, doubletZ, strip are all 1-based in the offline variables.
9// side: 1 bit (0 for negative eta, 1 for positive eta, bit 21)
10// sector: 4 bits (0-15, corresponding to sectors 1-16, bits 17-20)
11// doubletPhi: 1 bit (0-1, corresponding to doubletPhi=1,2, bit 16)
12// doubletR: 1 bit (0-1, corresponding to doubletR=1,2, only used to distinguish BM1 and BM2, BO-BOR/BOM, no corresponding bit)
13// station: 2 bits (0-3, corresponding to stations BI/BORBOM, BM1, BM2, BO, bits 14-15)
14// chamber: 4 bits (0-15, corresponding to chambers 1-16, bits 10-13)
15// doubletZ: 2 bits (0-2, corresponding to doubletZ=1,2, bits 8-9)
16// strip: 7 bits (0-127, corresponding to strips 1-128, bits 1-7)
17// measuresPhi: 1 bit (0 for measuresEta, 1 for measuresPhi, bit 0)
18
19#ifndef RPCSLStripConverter_H
20#define RPCSLStripConverter_H
21
23#include "GaudiKernel/MsgStream.h"
25
26//standalone converter for SL strip identifiers
27namespace L1Muon {
28
29enum class SLRPCStation {
31 BM1 = 1,
32 BM2 = 2,
33 BO = 3
34};
35
37 public:
40
41 static uint32_t pack( bool side, uint8_t sector, bool doubletPhi,
42 Muon::MuonStationIndex::StIndex station, uint8_t doubletR, uint8_t chamber,
43 uint8_t doubletZ, uint8_t strip, bool measuresPhi) {
44 SLRPCStation correctedStation = static_cast<SLRPCStation>(station);
45 if (station == Muon::MuonStationIndex::StIndex::BO) {correctedStation = SLRPCStation::BO;}
46 else if (station == Muon::MuonStationIndex::StIndex::BM && doubletR >= 1) {correctedStation = SLRPCStation::BM2;}
47
48 if (station == Muon::MuonStationIndex::StIndex::BO && doubletR == 0 && (sector+1 == 11 || sector+1 == 15)) {
49 //set bit 6 of strip to 1 to indicate that this is a BOR/BOM station
50 //For trigger purposes, we treat the BOR/BOM stations as BI stations,
51 // but we need to distinguish them from the BI stations in the other sectors
52 correctedStation = SLRPCStation::BI_BOR_BOM;
53 strip |= 0x40;
54 }
55
56 // Sanity check to ensure that the input values are within the expected ranges
57 if (s_runSanityChecks && !SanityCheck(sector, correctedStation, doubletR, chamber, doubletZ, strip, measuresPhi)) {
58 MsgStream log(Athena::getMessageSvc(), "RPCSLStripConverter");
59 log << MSG::WARNING << "Found invalid input values for packing RPC SL strip identifier: "
60 << "side=" << side << ", sector=" << static_cast<int>(sector) << ", doubletPhi=" << static_cast<int>(doubletPhi)
61 << ", station=" << static_cast<int>(correctedStation) << ", doubletR=" << static_cast<int>(doubletR)
62 << ", chamber=" << static_cast<int>(chamber) << ", doubletZ=" << static_cast<int>(doubletZ)
63 << ", strip=" << static_cast<int>(strip) << ", measuresPhi=" << static_cast<int>(measuresPhi)
64 << endmsg;
65 }
66
67 return (static_cast<uint32_t>(side) << s_sideShift) |
68 (static_cast<uint32_t>(sector) << s_sectorShift) |
69 (static_cast<uint32_t>(doubletPhi) << s_doubletPhiShift) |
70 (static_cast<uint32_t>(correctedStation)<< s_stationShift) |
71 (static_cast<uint32_t>(chamber) << s_chamberShift) |
72 (static_cast<uint32_t>(doubletZ) << s_doubletZShift) |
73 (static_cast<uint32_t>(strip) << s_stripShift) |
74 (static_cast<uint32_t>(measuresPhi));
75 }
76
77 static void unpack( uint32_t packed, bool& side, uint8_t& sector, uint8_t& doubletPhi,
78 Muon::MuonStationIndex::StIndex& station, uint8_t& chamber,
79 uint8_t& doubletZ, uint8_t& strip, bool& measuresPhi) {
80 side = getSide(packed);
81 sector = getSector(packed);
82 doubletPhi = getDoubletPhi(packed);
83 station = getRPCStation(packed);
84 chamber = getChamber(packed);
85 doubletZ = getDoubletZ(packed);
86 strip = getStrip(packed); // mask out the bit 6 which is used to indicate BOR/BOM stations
87 measuresPhi = getMeasuresPhi(packed);
88 }
89
90 static uint8_t getSide(uint32_t packed) {
91 return (packed >> s_sideShift) & s_lower1BitMask;
92 }
93 static uint8_t getSector(uint32_t packed) {
94 return ((packed >> s_sectorShift) & s_lower4BitsMask) + 1 ; // add 1 to convert back to 1-based indexing
95 }
96 static uint8_t getDoubletPhi(uint32_t packed) {
97 return ((packed >> s_doubletPhiShift) & s_lower1BitMask) + 1; // add 1 to convert back to 1-based indexing
98 }
99 static SLRPCStation getStation(uint32_t packed) {
100 return static_cast<SLRPCStation>((packed >> s_stationShift) & s_lower2BitsMask);
101 }
102 static uint8_t getChamber(uint32_t packed) {
103 return ((packed >> s_chamberShift) & s_lower4BitsMask) + 1; // add 1 to convert back to 1-based indexing
104 }
105 static uint8_t getDoubletZ(uint32_t packed) {
106 return ((packed >> s_doubletZShift) & s_lower2BitsMask) + 1; // add 1 to convert back to 1-based indexing
107 }
108 static uint8_t getStrip(uint32_t packed) {
109 SLRPCStation corrected_station = getStation(packed);
110 uint8_t sector = getSector(packed);
111 if (corrected_station == SLRPCStation::BI_BOR_BOM && (sector == 11 || sector == 15)) {
112 // This is a BOR/BOM station, so we need to mask out the bit 6 of the strip number
113 return ((packed >> s_stripShift) & s_lower6BitsMask) + 1; // mask out bit 6
114 }
115 return ((packed >> s_stripShift) & s_lower7BitsMask) + 1; // add 1 to convert back to 1-based indexing
116 }
117 static uint8_t getMeasuresPhi(uint32_t packed) {
118 return packed & s_lower1BitMask;
119 }
120 static uint16_t getTriggerSector(uint32_t packed) {
121 return (packed >> s_triggerSectorShift) & s_lower6BitsMask;
122 }
123
125 SLRPCStation corrected_station = getStation(packed);
126 uint8_t sector = getSector(packed);
127 if (corrected_station == SLRPCStation::BO) { return Muon::MuonStationIndex::StIndex::BO; }
128 else if (corrected_station == SLRPCStation::BI_BOR_BOM) {
129 if (sector == 11 || sector == 15) { return Muon::MuonStationIndex::StIndex::BO; }
130 else { return Muon::MuonStationIndex::StIndex::BI; }
131 }
132 else { return Muon::MuonStationIndex::StIndex::BM; }
133 }
134
135 static uint8_t getDoubletR(uint32_t packed) {
136 SLRPCStation correctedStation = getStation(packed);
137 uint8_t sector = getSector(packed);
138 if (correctedStation == SLRPCStation::BO) {
139 if (sector == 11 || sector == 15) { return 2; } // BO
140 return 1;
141 } // BO
142 else if (correctedStation == SLRPCStation::BM2) { return 2; } // BM2
143 else if (correctedStation == SLRPCStation::BM1) { return 1; } // BM1
144 else { return 1; } // BI/BORBOM
145
146 }
147
148 static constexpr uint32_t s_maskStripNumber = 0xFFFFFF01; //mask to exclude strip number bits
149 static constexpr uint32_t s_maskChamberGeometry = 0xFFFFC001; //mask to exclude chamber, doubletZ and strip number bits
150 static constexpr uint32_t s_maskStationGeometry = 0xFFFF0001; //mask to exclude station, chamber, doubletZ and strip number bits
151
152 private:
153
154 static constexpr uint32_t s_lower1BitMask = 0x00000001;
155 static constexpr uint32_t s_lower2BitsMask = 0x00000003;
156 static constexpr uint32_t s_lower4BitsMask = 0x0000000F;
157 static constexpr uint32_t s_lower6BitsMask = 0x0000003F;
158 static constexpr uint32_t s_lower7BitsMask = 0x0000007F;
159
160 static constexpr int s_maxSector = 15; // maximum sector value (0-15 for sectors 1-16)
161 static constexpr SLRPCStation s_maxStation = SLRPCStation::BO; // maximum station value (0-3 for stations BI, BM1, BM2, BO)
162 static constexpr int s_maxDoubletR = 1; // maximum doubletR value (0 for doubletR=1, 1 for doubletR=2)
163 static constexpr int s_maxChamber = 15; // maximum chamber value (0-15 for chambers 1-16)
164 static constexpr int s_maxDoubletZ = 2; // maximum doubletZ value (0-2 for doubletZ=1,2,3)
165 static constexpr int s_maxStrip = 127; // maximum strip value (0-127 for strips 1-128)
166
167 static constexpr int s_sideShift = 21;
168 static constexpr int s_sectorShift = 17;
169 static constexpr int s_doubletPhiShift = 16;
170 static constexpr int s_stationShift = 14;
171 static constexpr int s_chamberShift = 10;
172 static constexpr int s_doubletZShift = 8;
173 static constexpr int s_stripShift = 1;
174 static constexpr int s_triggerSectorShift = 16;
175
176 static constexpr uint16_t s_nullBIStrip = 0x0000;
177 static constexpr uint16_t s_nullBM1Strip = 0x4000;
178 static constexpr uint16_t s_nullBM2Strip = 0x8000;
179 static constexpr uint16_t s_nullBOStrip = 0xC000;
180
181 static constexpr bool s_runSanityChecks = true; // Set to true to enable sanity checks on input values
182 static bool SanityCheck( uint8_t sector,
183 SLRPCStation correctedStation, uint8_t doubletR, uint8_t chamber,
184 uint8_t doubletZ, uint8_t strip, bool measuresPhi) {
185 MsgStream log(Athena::getMessageSvc(), "RPCSLStripConverter");
186 if (sector > s_maxSector) {
187 log << MSG::WARNING << "Sanity Check Failed: Invalid sector value: " << static_cast<int>(sector) << endmsg;
188 return false; }
189 if (correctedStation > s_maxStation) {
190 log << MSG::WARNING << "Sanity Check Failed: Invalid station value: " << static_cast<int>(correctedStation) << endmsg;
191 return false; }
192 if (doubletR > s_maxDoubletR) {
193 log << MSG::WARNING << "Sanity Check Failed: Invalid doubletR value: " << static_cast<int>(doubletR) << endmsg;
194 return false; }
195 if (chamber > s_maxChamber) {
196 log << MSG::WARNING << "Sanity Check Failed: Invalid chamber value: " << static_cast<int>(chamber) << endmsg;
197 return false; }
198 if (doubletZ > s_maxDoubletZ) {
199 log << MSG::WARNING << "Sanity Check Failed: Invalid doubletZ value: " << static_cast<int>(doubletZ) << endmsg;
200 return false; }
201 if (strip > s_maxStrip) {
202 log << MSG::WARNING << "Sanity Check Failed: Invalid strip value: " << static_cast<int>(strip) << endmsg;
203 return false; }
204
205 if (correctedStation == SLRPCStation::BI_BOR_BOM && (sector == 11 || sector == 15)) {
206 // This is a BOR/BOM station, so we need to ensure that the strip number is within the valid range
207 strip &= s_lower6BitsMask; // mask out bit 6
208 }
209
210 uint32_t strip_16bit = (static_cast<uint32_t>(correctedStation) << s_stationShift) |
211 (static_cast<uint32_t>(chamber) << s_chamberShift) |
212 (static_cast<uint32_t>(doubletZ) << s_doubletZShift) |
213 (static_cast<uint32_t>(strip) << s_stripShift) |
214 (static_cast<uint32_t>(measuresPhi));
215
216 if (correctedStation == SLRPCStation::BI_BOR_BOM && (strip_16bit >= s_nullBM1Strip)) {
217 log << MSG::WARNING << "Sanity Check Failed for BI: " << std::hex << strip_16bit << std::dec << endmsg;
218 return false;
219 }
220 if (correctedStation == SLRPCStation::BM1 && (strip_16bit >= s_nullBM2Strip || strip_16bit < s_nullBM1Strip)) {
221 log << MSG::WARNING << "Sanity Check Failed for BM1: " << std::hex << strip_16bit << std::dec << endmsg;
222 return false;
223 }
224 if (correctedStation == SLRPCStation::BM2 && (strip_16bit >= s_nullBOStrip || strip_16bit < s_nullBM2Strip)) {
225 log << MSG::WARNING << "Sanity Check Failed for BM2: " << std::hex << strip_16bit << std::dec << endmsg;
226 return false;
227 }
228 if (correctedStation == SLRPCStation::BO && strip_16bit < s_nullBOStrip) {
229 log << MSG::WARNING << "Sanity Check Failed for BO: " << std::hex << strip_16bit << std::dec << endmsg;
230 return false;
231 }
232
233 return true;
234 }
235
236};
237
238} // end of namespace
239
240#endif // RPCSLStripConverter_H
#define endmsg
static constexpr uint32_t s_maskChamberGeometry
static SLRPCStation getStation(uint32_t packed)
static void unpack(uint32_t packed, bool &side, uint8_t &sector, uint8_t &doubletPhi, Muon::MuonStationIndex::StIndex &station, uint8_t &chamber, uint8_t &doubletZ, uint8_t &strip, bool &measuresPhi)
static constexpr uint32_t s_lower1BitMask
static uint8_t getMeasuresPhi(uint32_t packed)
static constexpr uint32_t s_lower2BitsMask
static constexpr uint32_t s_maskStripNumber
static uint8_t getDoubletPhi(uint32_t packed)
static uint8_t getDoubletZ(uint32_t packed)
static uint8_t getSector(uint32_t packed)
static constexpr SLRPCStation s_maxStation
static constexpr uint16_t s_nullBM1Strip
static constexpr uint16_t s_nullBOStrip
static constexpr uint16_t s_nullBM2Strip
static constexpr bool s_runSanityChecks
static constexpr int s_doubletPhiShift
static bool SanityCheck(uint8_t sector, SLRPCStation correctedStation, uint8_t doubletR, uint8_t chamber, uint8_t doubletZ, uint8_t strip, bool measuresPhi)
static constexpr int s_sectorShift
static constexpr int s_maxDoubletR
static uint8_t getSide(uint32_t packed)
static constexpr int s_chamberShift
static constexpr uint32_t s_maskStationGeometry
static constexpr int s_triggerSectorShift
static uint8_t getStrip(uint32_t packed)
static uint8_t getChamber(uint32_t packed)
static constexpr int s_stationShift
static constexpr uint16_t s_nullBIStrip
static constexpr int s_maxDoubletZ
static constexpr int s_stripShift
static Muon::MuonStationIndex::StIndex getRPCStation(uint32_t packed)
static constexpr uint32_t s_lower7BitsMask
static constexpr uint32_t s_lower6BitsMask
static uint8_t getDoubletR(uint32_t packed)
static constexpr uint32_t s_lower4BitsMask
static constexpr int s_doubletZShift
static constexpr int s_maxChamber
static uint32_t pack(bool side, uint8_t sector, bool doubletPhi, Muon::MuonStationIndex::StIndex station, uint8_t doubletR, uint8_t chamber, uint8_t doubletZ, uint8_t strip, bool measuresPhi)
static uint16_t getTriggerSector(uint32_t packed)
singleton-like access to IMessageSvc via open function and helper
IMessageSvc * getMessageSvc(bool quiet=false)
StIndex
enum to classify the different station layers in the muon spectrometer