ATLAS Offline Software
Loading...
Searching...
No Matches
TgcL0RdoDecoder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "TgcL0RdoDecoder.h"
6
8#include "Identifier/Identifier.h"
10#include "MuonRDO/TgcRawData.h"
11#include "MuonRDO/TgcRdo.h"
16
17#include <cmath>
18#include <numbers>
19
20namespace {
21
23 const Identifier& identifier, const Muon::IMuonIdHelperSvc& idHelperSvc) {
26
27 switch (idHelperSvc.phiIndex(identifier)) {
28 case PhiIndex::T1:
29 return Station::M1;
30 case PhiIndex::T2:
31 return Station::M2;
32 case PhiIndex::T3:
33 return Station::M3;
34 case PhiIndex::T4:
35 return Station::Inner;
36 default:
37 return Station::Unknown;
38 }
39}
40
41std::uint16_t triggerSector(const float phi) {
42 if (!std::isfinite(phi)) return 0U;
43 constexpr std::uint16_t nSectors = 24U;
44 const float fullTurn = 2.F * std::numbers::pi_v<float>;
45 const float sectorWidth = fullTurn / static_cast<float>(nSectors);
46 float wrapped = static_cast<float>(xAOD::P4Helpers::deltaPhi(phi, 0.));
47 if (wrapped < 0.F) wrapped += fullTurn;
48 std::uint16_t sector = static_cast<std::uint16_t>(
49 std::floor(wrapped / sectorWidth)) + 2U;
50 if (sector > nSectors) sector -= nSectors;
51 return sector;
52}
53
54} // namespace
55
56namespace L0Muon {
57namespace TgcL0Floating {
58
59StatusCode RdoDecoder::decode(const TgcRdoContainer& rdos,
60 const Muon::TgcCablingMap& cabling,
61 const Muon::IMuonIdHelperSvc& idHelperSvc,
62 const MuonGM::MuonDetectorManager& detectorManager,
63 HitGroups& hitGroups,
64 DecodeStatistics& statistics) const {
65 hitGroups.clear();
66 statistics = DecodeStatistics{};
67
68 // Run-3 RDO conversion is isolated here. Hits are routed immediately to the
69 // Phase-II side/Trigger-Sector/BC processing chain, as in the validated
70 // Floating simulation. Chamber identifiers remain hit provenance only.
71 for (const TgcRdo* rdo : rdos) {
72 for (const TgcRawData* rawData : *rdo) {
73 ++statistics.nRawData;
74 if (rawData->type() != TgcRawData::TYPE_HIT) continue;
75
76 Identifier identifier;
77 const bool mapped = cabling.getOfflineIDfromReadoutID(
78 identifier, rawData->subDetectorId(), rawData->rodId(),
79 rawData->sswId(), rawData->slbId(), rawData->channel());
80 if (!mapped) {
81 ++statistics.nMappingFailures;
82 continue;
83 }
84
85 const Station hitStation = station(identifier, idHelperSvc);
86 const bool hitIsStrip = idHelperSvc.tgcIdHelper().isStrip(identifier);
87 float eta = 0.F;
88 float phi = 0.F;
89 float r = 0.F;
90 float z = 0.F;
91 const MuonGM::TgcReadoutElement* readoutElement =
92 detectorManager.getTgcReadoutElement(identifier);
93 if (readoutElement != nullptr) {
94 const Amg::Vector3D globalPosition = readoutElement->channelPos(identifier);
95 eta = static_cast<float>(globalPosition.eta());
96 phi = static_cast<float>(globalPosition.phi());
97 r = static_cast<float>(globalPosition.perp());
98 z = static_cast<float>(globalPosition.z());
99 }
100 const std::uint16_t hitTriggerSector = triggerSector(phi);
101 if (hitTriggerSector == 0U) {
102 ++statistics.nMappingFailures;
103 continue;
104 }
105
106 const Hit hit{
107 .subDetectorId = rawData->subDetectorId(),
108 .triggerSector = hitTriggerSector,
109 .detectorSector = rawData->rodId(),
110 .bcTag = rawData->bcTag(),
111 .sswId = rawData->sswId(),
112 .slbId = rawData->slbId(),
113 .readoutChannel = rawData->channel(),
114 .stationEta = static_cast<std::int16_t>(
115 idHelperSvc.tgcIdHelper().stationEta(identifier)),
116 .stationPhi = static_cast<std::uint16_t>(
117 idHelperSvc.tgcIdHelper().stationPhi(identifier)),
118 .gasGap = static_cast<std::uint8_t>(
119 idHelperSvc.tgcIdHelper().gasGap(identifier)),
120 .channel = static_cast<std::uint16_t>(
121 idHelperSvc.tgcIdHelper().channel(identifier)),
122 .station = hitStation,
123 .isStrip = hitIsStrip,
124 .eta = eta,
125 .phi = phi,
126 .r = r,
127 .z = z,
128 };
129 const HitGroupKey key{.subDetectorId = hit.subDetectorId,
130 .triggerSector = hit.triggerSector,
131 .bcTag = hit.bcTag};
132 hitGroups[key].emplace_back(hit);
133
134 ++statistics.nHits;
135 if (hitIsStrip) ++statistics.nStripHits;
136 else ++statistics.nWireHits;
137 switch (hitStation) {
138 case Station::M1:
139 ++statistics.nM1Hits;
140 break;
141 case Station::M2:
142 ++statistics.nM2Hits;
143 break;
144 case Station::M3:
145 ++statistics.nM3Hits;
146 break;
147 case Station::Inner:
148 ++statistics.nInnerHits;
149 break;
150 default:
151 ++statistics.nUnknownStation;
152 break;
153 }
154 }
155 }
156 return StatusCode::SUCCESS;
157}
158
159} // namespace TgcL0Floating
160} // namespace L0Muon
Scalar eta() const
pseudorapidity method
Scalar phi() const
phi method
bool hit(const Container &ids, int pdgId)
#define z
StatusCode decode(const TgcRdoContainer &rdos, const Muon::TgcCablingMap &cabling, const Muon::IMuonIdHelperSvc &idHelperSvc, const MuonGM::MuonDetectorManager &detectorManager, HitGroups &hitGroups, DecodeStatistics &statistics) const
The MuonDetectorManager stores the transient representation of the Muon Spectrometer geometry and pro...
const TgcReadoutElement * getTgcReadoutElement(const Identifier &id) const
access via extended identifier (requires unpacking)
A TgcReadoutElement corresponds to a single TGC chamber; therefore typically a TGC station contains s...
Amg::Vector3D channelPos(const Identifier &id) const
Returns the position of the active channel (wireGang or strip).
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
virtual MuonStationIndex::PhiIndex phiIndex(const Identifier &id) const =0
calculate phi index from Identifier (not supported for MDT hits)
virtual const TgcIdHelper & tgcIdHelper() const =0
access to TgcIdHelper
int isStrip(const Identifier &id) const
isStrip corresponds to measuresPhi
An unit object of TGC ROD output.
Definition TgcRawData.h:23
int r
Definition globals.cxx:22
std::vector< std::string > mapped
Definition hcg.cxx:56
Eigen::Matrix< double, 3, 1 > Vector3D
std::map< HitGroupKey, HitContainer > HitGroups
PhiIndex
enum to classify the different phi layers in the muon spectrometer
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Event-local hardware processing key.