ATLAS Offline Software
Loading...
Searching...
No Matches
HelpersPhase1.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3*/
4
5#ifndef TRIGT1MUCTPIBITS_HELPERSPHASE1_H
6#define TRIGT1MUCTPIBITS_HELPERSPHASE1_H
7
8#include "MuCTPI_Bits.h"
9#include <array>
10#include <vector>
11#include <string_view>
12#include <iostream>
13
15 // Helper types
17 enum class SubsysID : uint8_t {Undefined=0, Barrel, Forward, Endcap, MAX};
18
19 // Mapping of the six RPC indexes into the 15 TGC indexes
20 const uint32_t RPCtoTGC_pt_map[7] = {0, 2, 4, 6, 8, 10, 12};
21
22 // Status data word error definitions
23 static constexpr std::array<std::string_view,16> DataStatusWordErrors = {
24 "Event number mismatch between MSPA and TRP in the central time slice",
25 "Event number mismatch between MSPC and TRP in the central time slice",
26 "Event number mismatch between MSPA and MSPC in any time slice",
27 "BCID mismatch between TRP and MSPA in the central time slice",
28 "BCID mismatch between TRP and MSPC in the central time slice",
29 "BCID mismatch between MSPA and MSPC in any time slice",
30 "MSPA multiplicity LVDS link CRC error in any time slice",
31 "MSPC multiplicity LVDS link CRC error in any time slice",
32 "Sector logic error flag set on any of the 104 MSPA sectors",
33 "Sector logic error flag set on any of the 104 MSPC sectors",
34 "Error flag set in any of the muon candidates in the event after zero-supression",
35 "CRC error on the MSPA DAQ link (in any time slice)",
36 "CRC error on the MSPC DAQ link (in any time slice)",
37 "TriggerType reception timeout error",
38 "MSPA DAQ link input FIFO full flag (cleared at EOF)",
39 "MSPC DAQ link input FIFO full flag (cleared at EOF)"
40 };
41
42 // Helper functions
44 inline constexpr uint32_t maskedWord(uint32_t word, uint32_t shift, uint32_t mask) {
45 return ((word >> shift) & mask);
46 }
47
49 inline constexpr uint32_t maskedWord(uint64_t word, uint32_t shift, uint32_t mask) {
50 return ((word >> shift) & mask);
51 }
52
54 inline constexpr uint32_t buildWord(uint32_t value, uint32_t shift, uint32_t mask) {
55 return ((value & mask) << shift);
56 }
57
59 inline constexpr bool wordEquals(uint32_t word, uint32_t shift, uint32_t mask, uint32_t value) {
60 return maskedWord(word, shift, mask) == value;
61 }
62
79
81 inline constexpr auto timesliceHeader(uint32_t word) {
82 struct {
83 uint32_t bcid{0};
84 uint32_t tobCount{0};
85 uint32_t candCount{0};
86 } header;
90 return header;
91 }
92
103
105 inline constexpr auto topoHeader(uint32_t word) {
106 struct {
107 bool flag0{0};
108 bool flag1{0};
109 bool flag2{0};
110 bool flag3{0};
111 uint32_t pt{0};
112 uint32_t etacode{0};
113 uint32_t phicode{0};
114 uint32_t barrel_eta_lookup{0};
115 uint32_t barrel_phi_lookup{0};
116 uint32_t hemi{0};
117 uint32_t det{0};
118 uint32_t sec{0};
119 uint32_t roi{0};
120 } header;
121 header.flag0 = maskedWord(word, RUN3_TOPO_WORD_FLAGS_SHIFT, 0x1); //20
122 header.flag1 = maskedWord(word, RUN3_TOPO_WORD_FLAGS_SHIFT+1, 0x1); //21
123 header.flag2 = maskedWord(word, RUN3_TOPO_WORD_FLAGS_SHIFT+2, 0x1); //22
124 header.flag3 = maskedWord(word, RUN3_TOPO_WORD_FLAGS_SHIFT+3, 0x1); //23
128 // HEMISPHERE 0: C-side (-) / 1: A-side (-)
130 // Barrel: 00 - EC: 1X - FW: 01 - see: https://indico.cern.ch/event/864390/contributions/3642129/attachments/1945776/3234220/ctp_topo_encoding.pdf
132 // set EC to 2 instead of sometimes 3 - see above why
133 if (header.det > 2) header.det = 2;
134 // Decode Barrel:
135 if (header.det == 0){
136 header.sec = header.phicode >> 3;
137 header.barrel_eta_lookup = (header.etacode >> 1) & 0xf;
138 header.barrel_phi_lookup = header.phicode & 0x7;
139 }
140 // FWD
141 else if (header.det == 1){
142 header.sec = header.phicode >> 3 ;
143 header.roi = ((header.etacode & 0x1f) << 2) | ((header.phicode >> 1) & 0x3) ;
144 }
145 // EC
146 else if (header.det == 2){
147 header.sec = header.phicode >> 2 ;
148 header.roi = ((header.etacode & 0x3f) << 2) | (header.phicode & 0x3) ;
149 }
150 return header;
151 }
152
154 inline constexpr uint32_t multiplicityWordNumber(uint32_t word) {
156 }
157
159 inline constexpr std::array<uint32_t,3> multiplicityWords(uint64_t multiplicity, uint32_t triggerBits, bool overflow) {
160 std::array<uint32_t,3> words{}; // zero-initialised
161 for (uint32_t iWord=0; iWord<words.size(); ++iWord) {
164 }
169 words[2] |= maskedWord(static_cast<uint32_t>(overflow), RUN3_MULTIPLICITY_OVERFLOW_SHIFT, RUN3_MULTIPLICITY_OVERFLOW_MASK);
170 return words;
171 }
172
184
186 inline std::vector<size_t> getDataStatusWordErrors(uint32_t word) {
188 if (status==0) return {};
189 std::vector<size_t> errors;
190 for (size_t bit=0; bit<DataStatusWordErrors.size(); ++bit) {
191 if (wordEquals(status, bit, 1u, 1u)) {
192 errors.push_back(bit);
193 }
194 }
195 return errors;
196 }
197
199 inline constexpr uint32_t dataStatusWord(uint16_t status) {
201 word |= status;
202 return word;
203 }
205 uint16_t bcid{0};
206 uint16_t tobCount{0};
207 uint16_t candCount{0};
208 };
210 bool nswMon = false;
211 bool candOverflow = false;
212 std::vector<uint32_t> cnt = {};
213 uint64_t bits = 0;
214 };
215 struct Candidate {
216 bool side = false;//C=0 A=1
218 uint32_t num{0};
219 uint32_t pt{0}; //1-15
220 // RPC pT in the cand word is a number between 1 and 6. Needs to be mapped between 1 and 15
221 uint32_t mappedPt{0};
222 uint32_t roi{0};
223 uint32_t subsystem{0};
224 float eta{0.};
225 float phi{0.};
226 bool errorFlag = false;
227 bool vetoFlag = false;
228 bool sectorFlag_gtN = false;//BA: gt2, EC/FW: gt4
229 bool sectorFlag_nswMon = false;//EC/FW only
230 bool candFlag_phiOverlap = false;//BA only
231 bool candFlag_gt1CandRoi = false;//BA only
232 bool candFlag_GoodMF = false;//EC/FW only
233 bool candFlag_InnerCoin = false;//EC/FW only
234 bool candFlag_BW23 = false;//EC/FW only
235 bool candFlag_Charge = false;//EC/FW only
236 Candidate(uint32_t word)
237 {
239 type = getSubsysID(word);
253 subsystem = 1;
254 }
255 else if(type==SubsysID::Barrel)
256 {
259 subsystem = 0;
261 }
262 else
263 {
269 subsystem = 2;
270 }
271 }
272 void print() const//this function has only debug purposes
273 {
274 std::cout << "Muon word content (cand): ";
275 std::cout << (side?"Side A, ":"Side C, ");
277 std::cout << "BA" << num << " ";
278 else
279 std::cout << (type==SubsysID::Forward?"FW":"EC") << num << " ";
280 std::cout << "Eta = " << eta << " ";
281 std::cout << "Phi = " << phi << " ";
282 std::cout << "pT = " << pt << " "; //Remember the internal mapping. RPC has 6 thresholds and TGC has 15.
283 std::cout << "mappedPt = " << mappedPt << " ";
284 std::cout << "CF: ";
285 if(type != SubsysID::Barrel) {
286 std::cout << " GMF: " << (candFlag_GoodMF?"1":"0");
287 std::cout << " InC: " << (candFlag_InnerCoin?"1":"0");
288 std::cout << " -BW: " << (candFlag_BW23?"1":"0");
289 std::cout << " Chg: " << (candFlag_Charge?"1":"0");
290 }
291 else {
292 std::cout << " PhO: " << (candFlag_phiOverlap?"1":"0");
293 std::cout << " 1Ro: " << (candFlag_gt1CandRoi?"1":"0");
294 }
295 std::cout << " SF: " << std::endl;
296 if(type != SubsysID::Barrel) {
297 std::cout << " NSM: " << (sectorFlag_nswMon?"1":"0");
298 std::cout << " 4SL: " << (sectorFlag_gtN?"1":"0");
299 }
300 else {
301 std::cout << " 2SL: " << (sectorFlag_gtN?"1":"0");
302 }
303 std::cout << " Veto = " << (vetoFlag?"1":"0") << " ";
304 std::cout << std::endl;
305 }
306 };
307 struct TopoTOB {
308 bool side = false;//C=0 A=1
309 uint32_t pt{0};//1-15
310 uint32_t etaRaw{0};
311 uint32_t phiRaw{0};
312 uint32_t roi{0};
313 uint32_t barrel_eta_lookup{0};
314 uint32_t barrel_phi_lookup{0};
315 uint32_t det{0};
316 uint32_t sec{0};
317 uint32_t subsystem{0};
318 float etaDecoded{0.};
319 float phiDecoded{0.};
320 bool candFlag_GoodMF = false;//EC/FW only
321 bool candFlag_InnerCoin = false;//EC/FW only
322 bool candFlag_BW23 = false;//EC/FW only
323 bool candFlag_Charge = false;//EC/FW only
325 {
326 // BA
327 if (det == 0){
328 sec = phiRaw >> 3;
329 barrel_eta_lookup = (etaRaw >> 1) & 0xf;
331 }
332 // FWD
333 else if (det == 1){
334 sec = phiRaw >> 3 ;
335 roi = ((etaRaw & 0x1f) << 2) | ((phiRaw >> 1) & 0x3) ;
336 }
337 // EC
338 else if (det == 2){
339 sec = phiRaw >> 2 ;
340 roi = ((etaRaw & 0x3f) << 2) | (phiRaw & 0x3) ;
341 }
342 }
362 void print() const //this function is just for debug purposes
363 {
364 std::cout << "Muon word content (TOB) : ";
365 std::cout << (side?"Side A, ":"Side C, ");
366 if(det == 0)
367 std::cout << "BA" << sec << " ";
368 else
369 std::cout << (det==1?"FW":"EC") << sec << " ";
370 std::cout << "Eta = " << etaDecoded << " ";
371 std::cout << "Phi = " << phiDecoded << " ";
372 std::cout << "pT = " << pt << std::endl;
373 std::cout << "CF:";
374 if(det == 1 || det == 2) {
375 std::cout << " GMF: " << (candFlag_GoodMF?"1":"0");
376 std::cout << " InC: " << (candFlag_InnerCoin?"1":"0");
377 std::cout << " -BW: " << (candFlag_BW23?"1":"0");
378 std::cout << " Chg: " << (candFlag_Charge?"1":"0");
379 }
380 std::cout << std::endl;
381 }
382 };
383
384 struct Slice {
385 uint32_t bcid{0},nTOB{0},nCand{0};
387 std::vector<Candidate> cand = {};
388 std::vector<TopoTOB> tob = {};
389 };
390
391} // namespace LVL1::MuCTPIBits
392
393#endif // TRIGT1MUCTPIBITS_HELPERSPHASE1_H
static constexpr uint32_t RUN3_CAND_WORD_SECTORFLAGS_GTN_SHIFT
static constexpr uint32_t RUN3_TIMESLICE_MULT_WORD_ID_VAL
static constexpr uint32_t RUN3_CAND_WORD_ID_MASK
static constexpr uint32_t RUN3_MULTIPLICITY_TRIGBITS_SHIFT
static constexpr uint32_t RUN3_STATUS_WORD_SHIFT
static constexpr uint32_t RUN3_TIMESLICE_NTOB_MASK
static constexpr uint32_t RUN3_TOPO_WORD_ETA_MASK
static constexpr uint32_t RUN3_SUBSYS_HEMISPHERE_MASK
constexpr uint32_t maskedWord(uint32_t word, uint32_t shift, uint32_t mask)
Extract sub-word from 32-bit word by applying a shift and a mask.
static constexpr uint32_t RUN3_TIMESLICE_WORD_NUM_VAL
constexpr uint32_t multiplicityWordNumber(uint32_t word)
Decode the index of the multitpicity word, which is 1, 2, or 3.
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_BA_GT1ROI_MASK
static constexpr uint32_t RUN3_TIMESLICE_MULT_WORD_ID_MASK
static constexpr uint32_t RUN3_CAND_WORD_PT_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_CHARGE_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_ETA_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_VETO_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_GOODMF_MASK
static constexpr uint32_t RUN3_CAND_WORD_ID_VAL
static constexpr uint32_t BARREL_SECTORID_MASK
Mask for extracting the sector ID for barrel candidates from the data word.
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_GOODMF_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_ID_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_PHI_SHIFT
static constexpr uint32_t RUN3_SUBSYS_ADDRESS_EC_VAL
static constexpr uint32_t RUN3_TOPO_WORD_DET_SHIFT
static constexpr uint32_t RUN3_MULTIPLICITY_PART1_MASK
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_INNERCOIN_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_BW23_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_ROI_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_ROI_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_BA_GT1ROI_SHIFT
static constexpr uint32_t RUN3_SUBSYS_ADDRESS_BAFW_SHIFT
Run-3 subsystem identifier bits location and values.
Definition MuCTPI_Bits.h:96
static constexpr std::array< std::string_view, 16 > DataStatusWordErrors
static constexpr uint32_t RUN3_SUBSYS_ADDRESS_BAFW_MASK
Definition MuCTPI_Bits.h:97
static constexpr uint32_t RUN3_TOPO_WORD_FLAGS_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_BW23_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_INNERCOIN_MASK
static constexpr uint32_t RUN3_TIMESLICE_NTOB_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_ID_MASK
static constexpr uint32_t RUN3_TIMESLICE_MULT_WORD_NUM_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_CHARGE_MASK
static constexpr uint32_t RUN3_SUBSYS_ADDRESS_FW_VAL
Definition MuCTPI_Bits.h:99
constexpr bool wordEquals(uint32_t word, uint32_t shift, uint32_t mask, uint32_t value)
Compare a sub-word of a 32-bit word to an expected value.
constexpr auto timesliceHeader(uint32_t word)
Decode timeslice word.
static constexpr uint32_t RUN3_STATUS_WORD_ID_MASK
static constexpr uint32_t RUN3_TIMESLICE_BCID_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_ID_SHIFT
static constexpr uint32_t RUN3_SUBSYS_ADDRESS_EC_MASK
static constexpr uint32_t RUN3_STATUS_WORD_MASK
static constexpr uint32_t RUN3_TOPO_WORD_HEMI_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_PT_MASK
static constexpr uint32_t RUN3_TIMESLICE_BCID_MASK
static constexpr uint32_t RUN3_SUBSYS_ADDRESS_EC_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_GOODMF_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_BA_PHIOVERLAP_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_BW23_MASK
static constexpr uint32_t RUN3_TOPO_WORD_PHI_MASK
static constexpr uint32_t RUN3_STATUS_WORD_ID_SHIFT
static constexpr uint32_t RUN3_TIMESLICE_NCAND_SHIFT
static constexpr uint32_t RUN3_SUBSYS_ADDRESS_BA_VAL
Definition MuCTPI_Bits.h:98
static constexpr uint32_t RUN3_TIMESLICE_NCAND_MASK
static constexpr uint32_t RUN3_TOPO_WORD_ID_VAL
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_CHARGE_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_NSWMON_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_VETO_SHIFT
static constexpr uint32_t RUN3_TIMESLICE_MULT_WORD_NUM_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_SECTORERRORFLAG_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_BW23_SHIFT
static constexpr uint32_t ENDCAP_SECTORID_MASK
Mask for extracting the sector ID for endcap candidates from the data word.
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_INNERCOIN_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_BA_PHIOVERLAP_MASK
static constexpr uint32_t RUN3_MULTIPLICITY_PART1_SHIFT
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_GOODMF_SHIFT
constexpr WordType getWordType(uint32_t word)
Determine the type of a MUCTPI ROD word.
static constexpr uint32_t RUN3_TOPO_WORD_HEMI_MASK
static constexpr uint32_t RUN3_CAND_WORD_SECTORERRORFLAG_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_SECTORFLAGS_GTN_MASK
constexpr uint32_t dataStatusWord(uint16_t status)
Encode the data status word.
constexpr uint32_t buildWord(uint32_t value, uint32_t shift, uint32_t mask)
Extract sub-word from 32-bit word by applying a shift and a mask.
static constexpr uint32_t RUN3_MULTIPLICITY_OVERFLOW_MASK
static constexpr uint32_t RUN3_MULTIPLICITY_PART2_MASK
static constexpr uint32_t RUN3_TOPO_WORD_DET_MASK
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_ECFW_INNERCOIN_SHIFT
static constexpr uint32_t RUN3_MULTIPLICITY_TRIGBITS_MASK
std::vector< size_t > getDataStatusWordErrors(uint32_t word)
Decode the data status word (returns a vector of bit indices for the errors set - empty if no errors)
static constexpr uint32_t RUN3_CAND_SECTORID_SHIFT
constexpr std::array< uint32_t, 3 > multiplicityWords(uint64_t multiplicity, uint32_t triggerBits, bool overflow)
Encode the multiplicity words.
static constexpr uint32_t RUN3_MULTIPLICITY_PART3_SHIFT
static constexpr uint32_t RUN3_STATUS_WORD_ID_VAL
static constexpr uint32_t RUN3_TIMESLICE_MULT_WORD_ID_SHIFT
const uint32_t RPCtoTGC_pt_map[7]
static constexpr uint32_t RUN3_TOPO_WORD_CANDFLAGS_ECFW_CHARGE_MASK
constexpr auto topoHeader(uint32_t word)
Decode topo word :
static constexpr uint32_t RUN3_SUBSYS_HEMISPHERE_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_PT_MASK
constexpr SubsysID getSubsysID(uint32_t word)
Decode the subsys ID from RoI candidate word.
static constexpr uint32_t RUN3_TOPO_WORD_PT_SHIFT
static constexpr uint32_t RUN3_MULTIPLICITY_PART3_MASK
static constexpr uint32_t RUN3_MULTIPLICITY_PART2_SHIFT
static constexpr uint32_t RUN3_MULTIPLICITY_OVERFLOW_SHIFT
static constexpr uint32_t RUN3_CAND_WORD_CANDFLAGS_NSWMON_MASK
std::vector< uint32_t > cnt
std::vector< TopoTOB > tob
std::vector< Candidate > cand