ATLAS Offline Software
Loading...
Searching...
No Matches
MuonIdHelperSvc.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6
7#include <iostream>
8#include <format>
9#include <ranges>
10
11
12namespace Muon {
13 using namespace MuonStationIndex;
14
15 MuonIdHelperSvc::MuonIdHelperSvc(const std::string& name, ISvcLocator* svc) :
16 base_class(name, svc) {}
17
19 ATH_CHECK(m_detStore.retrieve());
26
28 using AllHelperArray = std::array<const MuonIdHelper*, 6>;
29 const AllHelperArray allHelpers{m_mdtIdHelper, m_rpcIdHelper, m_tgcIdHelper,
31 AllHelperArray::const_iterator itr = std::ranges::find_if(allHelpers,
32 [](const MuonIdHelper* h){return h != nullptr;});
33 if (itr == allHelpers.end()){
34 ATH_MSG_WARNING("No MuonIdHelper has been created before. Please do not setup the service if no muon layout is loaded");
35 return StatusCode::SUCCESS;
36 }
37 m_primaryHelper = (*itr);
38
39 std::stringstream techStr{};
40
41 for (int tech = 0; tech <= m_primaryHelper->technologyNameIndexMax(); ++tech) {
42 std::string name = m_primaryHelper->technologyString(tech);
43
44 if (name == "MDT") m_technologies.push_back(TechIdx::MDT);
45 if (name == "CSC") m_technologies.push_back(TechIdx::CSC);
46 if (name == "RPC") m_technologies.push_back(TechIdx::RPC);
47 if (name == "TGC") m_technologies.push_back(TechIdx::TGC);
48 if (name == "STGC") m_technologies.push_back(TechIdx::STGC);
49 if (name == "MM") m_technologies.push_back(TechIdx::MM);
50 techStr<< ", " << tech << " " << name;
51 }
52 ATH_MSG_DEBUG(" Technologies: size " << m_primaryHelper->technologyNameIndexMax()<<" "<<techStr.str());
53
54 unsigned int nstationsNames = m_primaryHelper->stationNameIndexMax() + 1;
55 m_stationNameData.resize(nstationsNames);
56 for (int i = 0; i <= m_primaryHelper->stationNameIndexMax(); ++i) {
57 std::string name = m_primaryHelper->stationNameString(i);
58 if (name.compare(MuonIdHelper::BAD_NAME) == 0) continue;
59
61
62 data.stationName = std::move(name);
63 data.isEndcap = m_primaryHelper->isEndcap(i);
64 data.isSmall = m_primaryHelper->isSmall(i);
65
66 if (data.isEndcap) {
67 if (data.stationName[1] == '1')
68 data.chIndex = ChIdx::EML;
69 else if (data.stationName[1] == '2')
70 data.chIndex = ChIdx::EML;
71 else if (data.stationName[1] == '3')
72 data.chIndex = ChIdx::EML;
73 else if (data.stationName[1] == '4')
74 data.chIndex = ChIdx::EIL;
75
76 if (data.stationName[1] == 'O') {
77 if (data.stationName[2] == 'L')
78 data.chIndex = ChIdx::EOL;
79 else
80 data.chIndex = ChIdx::EOS;
81 } else if (data.stationName[1] == 'M') {
82 if (data.stationName[2] == 'L')
83 data.chIndex = ChIdx::EML;
84 else
85 data.chIndex = ChIdx::EMS;
86 } else if (data.stationName[1] == 'I') {
87 if (data.stationName[2] == 'L')
88 data.chIndex = ChIdx::EIL;
89 else
90 data.chIndex = ChIdx::EIS;
91 } else if (data.stationName[1] == 'E') {
92 if (data.stationName[0] == 'B') {
93 data.chIndex = ChIdx::BEE;
94 } else {
95 if (data.stationName[2] == 'L')
96 data.chIndex = ChIdx::EEL;
97 else
98 data.chIndex = ChIdx::EES;
99 }
100 } else if (data.stationName[0] == 'C') {
101 if (data.stationName[2] == 'L')
102 data.chIndex = ChIdx::CSL;
103 else
104 data.chIndex = ChIdx::CSS;
105 }
106 if (data.stationName[0] == 'S' || data.stationName[0] == 'M') {
107 if (data.isSmall)
108 data.chIndex = ChIdx::EIS;
109 else
110 data.chIndex = ChIdx::EIL;
111 }
112
113 } else {
114 if (data.stationName[1] == 'O') {
115 if (data.stationName[2] == 'L')
116 data.chIndex = ChIdx::BOL;
117 else
118 data.chIndex = ChIdx::BOS;
119 } else if (data.stationName[1] == 'M') {
120 if (data.stationName[2] == 'L' || data.stationName[2] == 'E')
121 data.chIndex = ChIdx::BML;
122 else
123 data.chIndex = ChIdx::BMS;
124 } else if (data.stationName[1] == 'I') {
125 if (data.stationName[2] == 'L' || data.stationName[2] == 'M' || data.stationName[2] == 'R')
126 data.chIndex = ChIdx::BIL;
127 else
128 data.chIndex = ChIdx::BIS;
129 }
130 }
131 if (data.chIndex == ChIdx::ChUnknown) {
132 ATH_MSG_ERROR("data.chIndex is negative in MuonIdHelperSvc::initialize ");
133 return StatusCode::FAILURE;
134 }
135 data.stIndex = toStationIndex(data.chIndex);
136
137 if (msgLvl(MSG::DEBUG)) {
138 msg(MSG::DEBUG) << "Adding station " << i << " " << data.stationName << " ";
139 if (data.isEndcap)
140 msg(MSG::DEBUG) << " Endcap, ";
141 else
142 msg(MSG::DEBUG) << " Barrel, ";
143 if (data.isSmall)
144 msg(MSG::DEBUG) << " Small, ";
145 else
146 msg(MSG::DEBUG) << " Large, ";
147
148 msg(MSG::DEBUG) << chName(data.chIndex) << " " << stName(data.stIndex) << endmsg;
149 }
150 }
152 // now, let's check if we are in the inner barrel layer, and if there are RPCs installed
153 // if yes, the MDT chambers must be sMDTs
155 m_BIS_stat = m_mdtIdHelper->stationNameIndex("BIS");
156 for (int eta = MdtIdHelper::stationEtaMin(true); eta <= MdtIdHelper::stationEtaMax(true); ++eta) {
157 for (int phi = 1; phi <= 8; ++phi) {
158 // now, let's check if we are in the inner barrel layer, and if there are RPCs installed
159 // if yes, the MDT chambers must be sMDTs
160 // now try to retrieve RPC identifier with the same station name/eta/phi and check if it is valid
161 bool isValid = false;
162 m_rpcIdHelper->elementID(m_BIS_stat, eta, phi, 1, isValid);
163 // last 4 arguments are: doubletR, check, isValid
164 // there is a BI RPC in the same station, thus, this station was already upgraded and sMDTs are present
165 if (!isValid) continue;
166 m_smdt_stat.emplace(m_mdtIdHelper->elementID(m_BIS_stat, eta, phi));
167 }
168 }
169 }
170
171 std::ranges::for_each(allHelpers, [this](const MuonIdHelper* idHelper){
172 if (!idHelper) return;
173 const TechIdx techIdx = technologyIndex(*idHelper->module_begin());
174 for (auto itr = idHelper->module_begin(); itr != idHelper->module_end(); ++itr) {
175 const auto idx = toStationIndex(chamberIndex(*itr));
176 if (idx == StIndex::StUnknown) continue;
177 m_techPerStation[toInt(idx)].insert(techIdx);
178 }
179 });
180
181 ATH_MSG_DEBUG("Configured the service with the following flags --- hasMDT: "<< hasMDT()<<" hasRPC: "<<hasRPC()
182 <<" hasTGC"<< hasTGC() << " hasCSC: "<< hasCSC() << " hasSTGC: " << hasSTGC() << " hasMM: " << hasMM() );
183 return StatusCode::SUCCESS;
184 }
185
186 int MuonIdHelperSvc::gasGap(const Identifier& id) const {
187 if (isRpc(id)) {
188 return m_rpcIdHelper->gasGap(id);
189 } else if (isTgc(id)) {
190 return m_tgcIdHelper->gasGap(id);
191 } else if (isCsc(id)) {
192 return m_cscIdHelper->wireLayer(id);
193 } else if (issTgc(id)) {
194 return m_stgcIdHelper->gasGap(id);
195 } else if (isMM(id)) {
196 return m_mmIdHelper->gasGap(id);
197 } else {
198 return m_mdtIdHelper->channel(id);
199 }
200 return 1;
201 }
202
203 bool MuonIdHelperSvc::isMuon(const Identifier& id) const {
204 return m_primaryHelper && m_primaryHelper->is_muon(id);
205 }
206 bool MuonIdHelperSvc::isMdt(const Identifier& id) const {
207 return m_mdtIdHelper && m_mdtIdHelper->is_mdt(id);
208 }
209 bool MuonIdHelperSvc::isMM(const Identifier& id) const {
210 return m_mmIdHelper && m_mmIdHelper->is_mm(id);
211 }
212 bool MuonIdHelperSvc::isCsc(const Identifier& id) const {
213 return m_cscIdHelper && m_cscIdHelper->is_csc(id);
214 }
215 bool MuonIdHelperSvc::isRpc(const Identifier& id) const {
216 return m_rpcIdHelper && m_rpcIdHelper->is_rpc(id);
217 }
218
219 bool MuonIdHelperSvc::isTgc(const Identifier& id) const {
220 return m_tgcIdHelper && m_tgcIdHelper->is_tgc(id);
221 }
222
223 bool MuonIdHelperSvc::issTgc(const Identifier& id) const {
224 return m_stgcIdHelper && m_stgcIdHelper->is_stgc(id);
225 }
226
227 const std::set<TechnologyIndex>&
229 assert(toInt(stIndex) < static_cast<int>(m_techPerStation.size()));
230 return m_techPerStation[toInt(stIndex)];
231 }
232 bool MuonIdHelperSvc::issMdt(const Identifier& id) const {
233 if (!isMdt(id))
234 return false;
235 if (stationName(id) == m_BIS_stat) {
236 return m_smdt_stat.find(m_mdtIdHelper->elementID(id)) != m_smdt_stat.end();
237 }
238 return m_mdtIdHelper->isBME(id) || m_mdtIdHelper->isBMG(id);
239 }
240
241 bool MuonIdHelperSvc::hasHPTDC(const Identifier& id) const {
244 // the remaining sMDTs (installed in BI in LS1) all have an HPTDC in Run3
245 // all BME sMDTs have no HPTDC
246 return issMdt(id) && !m_mdtIdHelper->isBME(id);
247 }
248
250 if (isRpc(id)) {
251 return m_rpcIdHelper->measuresPhi(id);
252 } else if (isTgc(id)) {
253 return m_tgcIdHelper->measuresPhi(id);
254 } else if (isCsc(id)) {
255 return m_cscIdHelper->measuresPhi(id);
256 } else if (issTgc(id)) {
257 return m_stgcIdHelper->measuresPhi(id);
258 }
259 // MM and MDTs only measure eta
260 return false;
261 }
262
264 return isRpc(id) || isTgc(id);
265 }
266
267 bool MuonIdHelperSvc::isEndcap(const Identifier& id) const { return m_primaryHelper->isEndcap(id); }
268
269 bool MuonIdHelperSvc::isSmallChamber(const Identifier& id) const { return m_primaryHelper->isSmall(id); }
270
272 if (!id.is_valid() || !isMuon(id)) {
273 if (id.is_valid()) ATH_MSG_WARNING("chamberIndex: invalid ID " << m_primaryHelper->print_to_string(id));
274 return ChIdx::ChUnknown;
275 }
276 return m_stationNameData[stationName(id)].chIndex;
277 }
278
280 if (!id.is_valid() || !isMuon(id)) {
281 if (id.is_valid()) ATH_MSG_WARNING("stationIndex: invalid ID " << m_primaryHelper->print_to_string(id));
282 return StIdx::StUnknown;
283 }
284 return m_stationNameData[stationName(id)].stIndex;
285 }
286
288 if (!id.is_valid() || !isMuon(id)) {
289 if (id.is_valid()) ATH_MSG_WARNING("phiIndex: invalid ID " << m_primaryHelper->print_to_string(id));
290 return PhiIdx::PhiUnknown;
291 }
292 if (isMdt(id) || isMM(id)) {
293 ATH_MSG_WARNING("phiIndex: not supported for " << toString(id));
294 return PhiIdx::PhiUnknown;
295 }
296 PhiIdx index{PhiIdx::PhiUnknown};
297 const StIdx stIndex = stationIndex(id);
298 if (stIndex == StIdx::BI) {
299 index = m_rpcIdHelper->doubletR(id) == 1 ? PhiIdx::BI1 : PhiIdx::BI2;
300 } else if (stIndex == StIdx::BM) {
301 index = m_rpcIdHelper->doubletR(id) == 1 ? PhiIdx::BM1 : PhiIdx::BM2;
302 } else if (stIndex == StIdx::BO) {
303 index = m_rpcIdHelper->doubletR(id) == 1 ? PhiIdx::BO1 : PhiIdx::BO2;
304 } else if (stIndex == StIdx::EI) {
305 if (isCsc(id)) {
306 index = PhiIdx::CSC;
307 } else if (isTgc(id)) {
308 index = PhiIdx::T4;
309 } else if (m_stgcIdHelper->multilayer(id) == 1) {
310 index = PhiIdx::STGC1;
311 } else {
312 index = PhiIdx::STGC2;
313 }
314 } else if (stIndex == StIdx::EM) {
315 std::string chamberName = chamberNameString(id);
316 if (chamberName[1] == '1')
317 index = PhiIdx::T1;
318 else if (chamberName[1] == '2')
319 index = PhiIdx::T2;
320 else
321 index = PhiIdx::T3;
322 }
323 return index;
324 }
325
327 if (isEndcap(id)) return stationEta(id) < 0 ? DetectorRegionIndex::EndcapC : DetectorRegionIndex::EndcapA;
328 return DetectorRegionIndex::Barrel;
329 }
330
334
336 if (isMdt(id)) return TechIdx::MDT;
337 else if (isCsc(id)) return TechIdx::CSC;
338 else if (isTgc(id)) return TechIdx::TGC;
339 else if (isRpc(id)) return TechIdx::RPC;
340 else if (issTgc(id)) return TechIdx::STGC;
341 else if (isMM(id)) return TechIdx::MM;
342 return TechIdx::TechnologyUnknown;
343 }
344 std::string MuonIdHelperSvc::toString(const Identifier& id) const {
345 if (!id.is_valid()) return " Invalid Identifier";
346 if (isMdt(id)) {
347 return toStringGasGap(id);
348 }
349 const std::string_view phiStr{measuresPhi(id) ? "phi" : "eta"};
350 if (isRpc(id)) {
351 return std::format("{:} {:} channel {:2d}",toStringGasGap(id), measuresPhi(id) ? "phi" : "eta", m_rpcIdHelper->channel(id));
352 } else if (isTgc(id)) {
353 return std::format("{:} {:} channel {:2d}",toStringGasGap(id), measuresPhi(id) ? "phi" : "eta", m_tgcIdHelper->channel(id));
354 } else if (isCsc(id)) {
355 return std::format("{:} {:} channel {:2d}",toStringGasGap(id), measuresPhi(id) ? "phi" : "eta", m_cscIdHelper->channel(id));
356 } else if (isMM(id)) {
357 return std::format("{:} channel {:4d}",toStringGasGap(id), m_mmIdHelper->channel(id));
358 }
359 using sTgcType = sTgcIdHelper::sTgcChannelTypes;
360 const int channelType = m_stgcIdHelper->channelType(id);
361 return std::format("{:} {:} channel {:3d}",toStringGasGap(id),
362 channelType == sTgcType::Strip ? "eta" : channelType == sTgcType::Wire ? "phi" : "pad" ,
363 m_stgcIdHelper->channel(id));
364 }
365
366 std::string MuonIdHelperSvc::toStringTech(const Identifier& id) const {
368 }
369
370 std::string MuonIdHelperSvc::chamberNameString(const Identifier& id) const {
371 return m_primaryHelper->stationNameString(stationName(id));
372 }
373
374 std::string MuonIdHelperSvc::toStringStation(const Identifier& id) const {
375 return std::format("{:} {:} eta {:2d} phi {:2d}", toStringTech(id),stationNameString(id),
376 stationEta(id), stationPhi(id));
377 }
378 std::string MuonIdHelperSvc::toStringChamber(const Identifier& id) const {
379 if (!id.is_valid()) {
380 return " Invalid Identifier";
381 }
382 if (isRpc(id)) {
383 return std::format("{:} dbR {:1}", toStringStation(id), m_rpcIdHelper->doubletR(id));
384 }
385 return toStringStation(id);
386 }
387
388 std::string MuonIdHelperSvc::toStringDetEl(const Identifier& id) const {
389
390 if (!id.is_valid()) return " Invalid Identifier";
391 if (isMdt(id)) {
392 return std::format("{:} ml {:1d}", toStringChamber(id), m_mdtIdHelper->multilayer(id));
393 } else if (isRpc(id)) {
394 return std::format("{:} dbZ {:1d} dbPhi {:1d}", toStringChamber(id), m_rpcIdHelper->doubletZ(id), m_rpcIdHelper->doubletPhi(id));
395 } else if (isTgc(id)) {
396 return toStringChamber(id);
397 }
398 int ml{0};
399 if (isCsc(id)) {
400 ml = m_cscIdHelper->chamberLayer(id);
401 } else if (isMM(id)) {
402 ml = m_mmIdHelper->multilayer(id);
403 } else {
404 ml = m_stgcIdHelper->multilayer(id);
405 }
406 return std::format("{:} chlay {:1d}",toStringChamber(id), ml);
407 }
408
409 std::string MuonIdHelperSvc::toStringGasGap(const Identifier& id) const {
410 if (!id.is_valid()) return " Invalid Identifier";
411 if (isMdt(id)) {
412 return std::format("{:} lay {:1d} tube {:1d}", toStringDetEl(id),m_mdtIdHelper->tubeLayer(id), m_mdtIdHelper->tube(id));
413 } else if (isRpc(id) || isTgc(id)) {
414 return std::format("{:} gap {:1d}", toStringDetEl(id), gasGap(id));
415 }
416 return std::format("{:} lay {:1d}", toStringDetEl(id), gasGap(id));
417 }
418
420 Identifier chId;
421 // use phi hits on segment
422 if (isTgc(id)) {
423 chId = m_tgcIdHelper->elementID(id);
424 } else if (isRpc(id)) {
425 chId = m_rpcIdHelper->elementID(id);
426 } else if (isMM(id)) {
427 chId = m_mmIdHelper->elementID(id);
428 } else if (issTgc(id)) {
429 chId = m_stgcIdHelper->elementID(id);
430 } else if (isCsc(id)) {
431 chId = m_cscIdHelper->channelID(id, 2, 1, 1, 1);
432 } else if (isMdt(id)) {
433 chId = m_mdtIdHelper->elementID(id);
434 }
435 return chId;
436 }
437
439 // use phi hits on segment
440 if (isTgc(id)) {
441 return m_tgcIdHelper->elementID(id);
442 } else if (isRpc(id)) {
443 return m_rpcIdHelper->channelID(id, m_rpcIdHelper->doubletZ(id), m_rpcIdHelper->doubletPhi(id), 1, false, 1);
444 } else if (isCsc(id)) {
445 return m_cscIdHelper->channelID(id, 2, 1, 1, 1);
446 } else if (issTgc(id)) {
447 return m_stgcIdHelper->channelID(id, m_stgcIdHelper->multilayer(id), 1, sTgcIdHelper::sTgcChannelTypes::Strip, 1);
448 } else if (isMM(id)) {
449 return m_mmIdHelper->channelID(id, m_mmIdHelper->multilayer(id), 1, 1);
450 }
451 return m_mdtIdHelper->channelID(id, m_mdtIdHelper->multilayer(id), 1, 1);
452 }
453
455 // use phi hits on segment
456 if (isTgc(id)) {
457 return m_tgcIdHelper->channelID(id, m_tgcIdHelper->gasGap(id), m_tgcIdHelper->measuresPhi(id), 1);
458 } else if (isRpc(id)) {
459 return m_rpcIdHelper->channelID(id, m_rpcIdHelper->doubletZ(id), m_rpcIdHelper->doubletPhi(id),
460 m_rpcIdHelper->gasGap(id), m_rpcIdHelper->measuresPhi(id), 1);
461 } else if (isCsc(id)) {
462 return m_cscIdHelper->channelID(id, m_cscIdHelper->chamberLayer(id), m_cscIdHelper->wireLayer(id),
463 m_cscIdHelper->measuresPhi(id), 1);
464 } else if (isMM(id)) {
465 return m_mmIdHelper->channelID(id, m_mmIdHelper->multilayer(id), m_mmIdHelper->gasGap(id), 1);
466 } else if (issTgc(id)) {
467 return m_stgcIdHelper->channelID(id, m_stgcIdHelper->multilayer(id),
468 m_stgcIdHelper->gasGap(id), m_stgcIdHelper->channelType(id), 1);
469 }
471 return id;
472 }
473
475 // use phi hits on segment
476 if (isTgc(id)) {
477 return m_tgcIdHelper->channelID(id, m_tgcIdHelper->gasGap(id), false, 1);
478
479 } else if (isRpc(id)) {
480 return m_rpcIdHelper->channelID(id, m_rpcIdHelper->doubletZ(id), m_rpcIdHelper->doubletPhi(id),
481 m_rpcIdHelper->gasGap(id), false, 1);
482
483 } else if (isCsc(id)) {
484 return m_cscIdHelper->channelID(id, m_cscIdHelper->chamberLayer(id), m_cscIdHelper->wireLayer(id), 1, 1);
485 } else if (isMM(id)) {
486 return m_mmIdHelper->channelID(id, m_mmIdHelper->multilayer(id), m_mmIdHelper->gasGap(id), 1);
487
488 } else if (issTgc(id)) {
489 return m_stgcIdHelper->channelID(id, m_stgcIdHelper->multilayer(id), m_stgcIdHelper->gasGap(id),
491
492 }
493 return m_mdtIdHelper->channelID(id, m_mdtIdHelper->multilayer(id), m_mdtIdHelper->tubeLayer(id), 1);
494 }
495
497 if (!id.is_valid()) {
498 ATH_MSG_WARNING("stationPhi: invalid ID");
499 return 0;
500 }
501 if (isRpc(id)) {
502 return m_rpcIdHelper->stationPhi(id);
503 } else if (isTgc(id)) {
504 return m_tgcIdHelper->stationPhi(id);
505 } else if (isMdt(id)) {
506 return m_mdtIdHelper->stationPhi(id);
507 } else if (isCsc(id)) {
508 return m_cscIdHelper->stationPhi(id);
509 } else if (issTgc(id)) {
510 return m_stgcIdHelper->stationPhi(id);
511 } else if (isMM(id)) {
512 return m_mmIdHelper->stationPhi(id);
513 }
514 return 0;
515 }
516
518 if (!id.is_valid()) {
519 ATH_MSG_WARNING("stationEta: invalid ID");
520 return 0;
521 }
522 if (isRpc(id)) {
523 return m_rpcIdHelper->stationEta(id);
524 } else if (isTgc(id)) {
525 return m_tgcIdHelper->stationEta(id);
526 } else if (isMdt(id)) {
527 return m_mdtIdHelper->stationEta(id);
528 } else if (isCsc(id)) {
529 return m_cscIdHelper->stationEta(id);
530 } else if (issTgc(id)) {
531 return m_stgcIdHelper->stationEta(id);
532 } else if (isMM(id)) {
533 return m_mmIdHelper->stationEta(id);
534 }
535 return 0;
536 }
537
539 if (!id.is_valid()) {
540 ATH_MSG_WARNING("stationName: invalid ID");
541 return 0;
542 }
543 if (isRpc(id)) {
544 return m_rpcIdHelper->stationName(id);
545 } else if (isTgc(id)) {
546 return m_tgcIdHelper->stationName(id);
547 } else if (isMdt(id)) {
548 return m_mdtIdHelper->stationName(id);
549 } else if (isCsc(id)) {
550 return m_cscIdHelper->stationName(id);
551 } else if (issTgc(id)) {
552 return m_stgcIdHelper->stationName(id);
553 } else if (isMM(id)) {
554 return m_mmIdHelper->stationName(id);
555 }
556 return 0;
557 }
558
560 if (!id.is_valid()) {
561 ATH_MSG_WARNING("stationRegion: invalid ID");
562 return 0;
563 }
564 if (isRpc(id)) {
565 return m_rpcIdHelper->stationRegion(id);
566 } else if (isTgc(id)) {
567 return m_tgcIdHelper->stationRegion(id);
568 } else if (isMdt(id)) {
569 return m_mdtIdHelper->stationRegion(id);
570 } else if (isCsc(id)) {
571 return m_cscIdHelper->stationRegion(id);
572 } else if (issTgc(id)) {
573 return m_stgcIdHelper->stationRegion(id);
574 } else if (isMM(id)) {
575 return m_mmIdHelper->stationRegion(id);
576 }
577 return 0;
578 }
579
580 int MuonIdHelperSvc::sector(const Identifier& id) const {
581 // TGC has different segmentation, return 0 for the moment
582 if (isTgc(id)) {
583 auto initTgcSectorMapping = [&]() -> std::vector<int>* {
584 std::vector<int>* mapping = nullptr;
585 StatusCode sc = m_detStore->retrieve(mapping, "TGC_SectorMapping");
586 if (sc.isFailure() || !mapping) {
587 ATH_MSG_WARNING("sector: failed to retrieve TGC sector mapping");
588 return nullptr;
589 }
590 ATH_MSG_DEBUG("sector: retrieve TGC sector mapping " << mapping->size());
591 return mapping;
592 };
593 static const std::vector<int> tgcSectorMapping = *initTgcSectorMapping();
594
595 IdentifierHash hash;
596 m_tgcIdHelper->get_module_hash(id, hash);
597 if (hash >= tgcSectorMapping.size()) {
598 ATH_MSG_WARNING("sector: TGC not yet supported");
599 return 0;
600 }
601 return tgcSectorMapping[hash];
602 }
603 int sect = 2 * stationPhi(id);
604 if (!isSmallChamber(id)) --sect;
605 return sect;
606 }
607
608 bool MuonIdHelperSvc::hasRPC() const { return m_rpcIdHelper != nullptr; }
609 bool MuonIdHelperSvc::hasTGC() const { return m_tgcIdHelper != nullptr; }
610 bool MuonIdHelperSvc::hasMDT() const { return m_mdtIdHelper != nullptr; }
611 bool MuonIdHelperSvc::hasCSC() const { return m_hasCSC; }
612 bool MuonIdHelperSvc::hasSTGC() const { return m_hasSTGC; }
613 bool MuonIdHelperSvc::hasMM() const { return m_hasMM; }
614
615 std::string MuonIdHelperSvc::stationNameString(const Identifier& id) const {
616 const int station = stationName(id);
617 if (isMdt(id)) return m_mdtIdHelper->stationNameString(station);
618 else if (isRpc(id)) return m_rpcIdHelper->stationNameString(station);
619 else if (isTgc(id)) return m_tgcIdHelper->stationNameString(station);
620 else if (isMM(id)) return m_mmIdHelper->stationNameString(station);
621 else if (issTgc(id)) return m_stgcIdHelper->stationNameString(station);
622 else if (isCsc(id)) return m_cscIdHelper->stationNameString(station);
623 return "UNKNOWN";
624 }
625 inline IdentifierHash MuonIdHelperSvc::moduleHash(const MuonIdHelper& idHelper, const Identifier& id) const{
626 IdentifierHash hash{};
627 if (idHelper.get_module_hash(id, hash) ||
628 static_cast<unsigned int>(hash) >= idHelper.module_hash_max()){
629 ATH_MSG_VERBOSE("Failed to deduce module hash "<<toString(id));
630 }
631 return hash;
632 }
634 IdentifierHash hash{};
635 if (idHelper.get_detectorElement_hash(id, hash) ||
636 static_cast<unsigned int>(hash)>= idHelper.detectorElement_hash_max()) {
637 ATH_MSG_VERBOSE("Failed to deduce detector element hash "<<toString(id));
638 }
639 return hash;
640 }
642 if (isMdt(id)) return moduleHash(*m_mdtIdHelper, id);
643 else if (isRpc(id)) return moduleHash(*m_rpcIdHelper, id);
644 else if (isTgc(id)) return moduleHash(*m_tgcIdHelper, id);
645 else if (isMM(id)) return moduleHash(*m_mmIdHelper, id);
646 else if (issTgc(id)) return moduleHash(*m_stgcIdHelper, id);
647 else if (isCsc(id)) return moduleHash(*m_cscIdHelper, id);
648 ATH_MSG_WARNING("moduleHash(): No muon Identifier "<<id);
649 return IdentifierHash{};
650 }
652 if (isMdt(id)) return detElementHash(*m_mdtIdHelper, id);
653 else if (isRpc(id)) return detElementHash(*m_rpcIdHelper, id);
654 else if (isTgc(id)) return detElementHash(*m_tgcIdHelper, id);
655 else if (isMM(id)) return detElementHash(*m_mmIdHelper, id);
656 else if (issTgc(id)) return detElementHash(*m_stgcIdHelper, id);
657 else if (isCsc(id)) return detElementHash(*m_cscIdHelper, id);
658 ATH_MSG_WARNING("detElementHash(): No muon Identifier "<<id);
659 return IdentifierHash{};
660 }
661
662} // namespace Muon
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
#define endmsg
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
bool isValid(const T &p)
Av: we implement here an ATLAS-sepcific convention: all particles which are 99xxxxx are fine.
Definition AtlasPID.h:878
char data[hepevt_bytes_allocation_ATLAS]
Definition HepEvt.cxx:11
static Double_t sc
Header file for AthHistogramAlgorithm.
This is a "hash" representation of an Identifier.
static int stationEtaMax(bool barrel)
static int stationEtaMin(bool barrel)
Access to min and max of level ranges.
const_id_iterator module_end() const
const_id_iterator module_begin() const
Iterators over full set of ids.
virtual int get_detectorElement_hash(const Identifier &id, IdentifierHash &hash_id) const
static const std::string BAD_NAME
virtual int get_module_hash(const Identifier &id, IdentifierHash &hash_id) const
size_type module_hash_max() const
the maximum hash value
size_type detectorElement_hash_max() const
MuonStationIndex::PhiIndex PhiIdx
virtual StatusCode initialize() override
AlgTool initilize.
virtual bool isMM(const Identifier &id) const override
returns whether this is a MM Identifier or not
const TgcIdHelper * m_tgcIdHelper
virtual std::string chamberNameString(const Identifier &id) const override
print chamber name to string
const MdtIdHelper * m_mdtIdHelper
virtual Identifier detElId(const Identifier &id) const override
create a detector element ID
virtual bool isTgc(const Identifier &id) const override
returns whether this is a TGC Identifier or not
virtual MuonStationIndex::TechnologyIndex technologyIndex(const Identifier &id) const override
calculate layer index from Identifier
virtual IdentifierHash detElementHash(const Identifier &id) const override
Returns the detector element hash associated to an Identifier.
virtual bool isMdt(const Identifier &id) const override
returns whether this is a MDT Identifier or not
ServiceHandle< StoreGateSvc > m_detStore
bool hasCSC() const override
virtual int gasGap(const Identifier &id) const override
returns gas gap: gasGap for RPC + TGC, wireLayer for CSC, tube for MDT
virtual MuonStationIndex::DetectorRegionIndex regionIndex(const Identifier &id) const override
calculate detector region index from Identifier
Gaudi::Property< bool > m_hasMDT
virtual std::string toStringGasGap(const Identifier &id) const override
print all fields up to gas gap to string
std::unordered_set< Identifier > m_smdt_stat
virtual bool issTgc(const Identifier &id) const override
returns whether this is a sTGC Identifier or not
virtual bool issMdt(const Identifier &id) const override
returns whether this is a sMDT Identifier or not
virtual int stationRegion(const Identifier &id) const override
Return stationRegion for all technologies.
bool hasMDT() const override
virtual std::string toStringDetEl(const Identifier &id) const override
print all fields up to detector element to string
Gaudi::Property< bool > m_hasMM
MuonStationIndex::StIndex StIdx
std::vector< TechIdx > m_technologies
virtual std::string toStringChamber(const Identifier &id) const override
print all fields up to chamber to string
virtual bool isSmallChamber(const Identifier &id) const override
returns whether this is a small chamber, always returns true for TGCs
virtual int stationName(const Identifier &id) const override
Return stationName for all technologies.
MuonStationIndex::TechnologyIndex TechIdx
const RpcIdHelper * m_rpcIdHelper
Sub detector specific IdHelpers.
virtual std::string toString(const Identifier &id) const override
print all fields to string
virtual bool measuresPhi(const Identifier &id) const override
returns whether channel measures phi or not
const sTgcIdHelper * m_stgcIdHelper
virtual MuonStationIndex::ChIndex chamberIndex(const Identifier &id) const override
calculate chamber index from Identifier
virtual std::string stationNameString(const Identifier &id) const override
Return the station name string for all technologies.
virtual const std::set< MuonStationIndex::TechnologyIndex > & technologiesInStation(MuonStationIndex::StIndex stIndex) const override
Recieve all technologies in a station.
bool hasSTGC() const override
virtual MuonStationIndex::PhiIndex phiIndex(const Identifier &id) const override
calculate phi index from Identifier (not supported for MDT hits)
virtual std::string toStringTech(const Identifier &id) const override
print all fields up to technology to string
const MmIdHelper * m_mmIdHelper
virtual int stationPhi(const Identifier &id) const override
Return stationPhi for all technologies.
const MuonIdHelper * m_primaryHelper
std::array< std::set< TechIdx >, static_cast< int >(StIdx::StIndexMax)> m_techPerStation
Array holding which technologies are there per station.
virtual int stationEta(const Identifier &id) const override
Return stationEta for all technologies.
Gaudi::Property< bool > m_hasRPC
virtual bool isTrigger(const Identifier &id) const override
returns whether trigger chamber id or not
std::vector< StationNameData > m_stationNameData
bool hasMM() const override
virtual Identifier gasGapId(const Identifier &id) const override
create a gasGap ID (will return layer Id for MDTs)
MuonIdHelperSvc(const std::string &name, ISvcLocator *svc)
default AlgService constructor
virtual bool isRpc(const Identifier &id) const override
returns whether this is a RPC Identifier or not
Gaudi::Property< bool > m_hasSTGC
Gaudi::Property< bool > m_hasTGC
bool hasRPC() const override
virtual bool isEndcap(const Identifier &id) const override
returns whether this is an endcap Identifier or not
const CscIdHelper * m_cscIdHelper
virtual MuonStationIndex::StIndex stationIndex(const Identifier &id) const override
calculate station index from Identifier
virtual bool isCsc(const Identifier &id) const override
returns whether this is a CSC Identifier or not
virtual std::string toStringStation(const Identifier &id) const override
print all fields up to stationName to string
Gaudi::Property< bool > m_hasCSC
virtual bool isMuon(const Identifier &id) const override
returns whether this is a Muon Identifier or not
virtual MuonStationIndex::LayerIndex layerIndex(const Identifier &id) const override
calculate layer index from Identifier
virtual Identifier layerId(const Identifier &id) const override
create a layer ID, returns tube id for the MDTs
virtual bool hasHPTDC(const Identifier &id) const override
returns whether this Identifier belongs to an MDT with HPTDC or not NOTE that in Run4,...
virtual int sector(const Identifier &id) const override
return sector number 1-16, odd=large, even=small
virtual Identifier chamberId(const Identifier &id) const override
create a chamber ID
virtual IdentifierHash moduleHash(const Identifier &id) const override
Returns the module hash associated to an Identifier.
bool hasTGC() const override
StIndex
enum to classify the different station layers in the muon spectrometer
TechnologyIndex
enum to classify the different layers in the muon spectrometer
DetectorRegionIndex
enum to classify the different layers in the muon spectrometer
PhiIndex
enum to classify the different phi layers in the muon spectrometer
StIndex toStationIndex(ChIndex index)
convert ChIndex into StIndex
constexpr int toInt(const EnumType enumVal)
const std::string & stName(StIndex index)
convert StIndex into a string
const std::string & technologyName(TechnologyIndex index)
convert LayerIndex into a string
const std::string & chName(ChIndex index)
convert ChIndex into a string
LayerIndex toLayerIndex(ChIndex index)
convert ChIndex into LayerIndex
LayerIndex
enum to classify the different layers in the muon spectrometer
ChIndex
enum to classify the different chamber layers in the muon spectrometer
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition index.py:1
MsgStream & msg
Definition testRead.cxx:32