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#include <string>
20
21namespace {
22
24 const Identifier& identifier, const Muon::IMuonIdHelperSvc& idHelperSvc) {
26 const std::string stationName = idHelperSvc.tgcIdHelper().stationNameString(
27 idHelperSvc.tgcIdHelper().stationName(identifier));
28 if (stationName.rfind("T1", 0) == 0) return Station::M1;
29 if (stationName.rfind("T2", 0) == 0) return Station::M2;
30 if (stationName.rfind("T3", 0) == 0) return Station::M3;
31 if (stationName.rfind("T4", 0) == 0) return Station::Inner;
32 return Station::Unknown;
33}
34
35std::uint16_t triggerSector(const float phi) {
36 if (!std::isfinite(phi)) return 0U;
37 constexpr std::uint16_t nSectors = 24U;
38 const float fullTurn = 2.F * std::numbers::pi_v<float>;
39 const float sectorWidth = fullTurn / static_cast<float>(nSectors);
40 float wrapped = static_cast<float>(xAOD::P4Helpers::deltaPhi(phi, 0.));
41 if (wrapped < 0.F) wrapped += fullTurn;
42 std::uint16_t sector = static_cast<std::uint16_t>(
43 std::floor(wrapped / sectorWidth)) + 2U;
44 if (sector > nSectors) sector -= nSectors;
45 return sector;
46}
47
48} // namespace
49
50namespace L0Muon {
51namespace TgcL0Floating {
52
53StatusCode RdoDecoder::decode(const TgcRdoContainer& rdos,
54 const Muon::TgcCablingMap& cabling,
55 const Muon::IMuonIdHelperSvc& idHelperSvc,
56 const MuonGM::MuonDetectorManager& detectorManager,
57 HitGroups& hitGroups,
58 DecodeStatistics& statistics) const {
59 hitGroups.clear();
60 statistics = DecodeStatistics{};
61
62 // Run-3 RDO conversion is isolated here. Hits are routed immediately to the
63 // Phase-II side/Trigger-Sector/BC processing chain, as in the validated
64 // Floating simulation. Chamber identifiers remain hit provenance only.
65 for (const TgcRdo* rdo : rdos) {
66 for (const TgcRawData* rawData : *rdo) {
67 ++statistics.nRawData;
68 if (rawData->type() != TgcRawData::TYPE_HIT) continue;
69
70 Identifier identifier;
71 const bool mapped = cabling.getOfflineIDfromReadoutID(
72 identifier, rawData->subDetectorId(), rawData->rodId(),
73 rawData->sswId(), rawData->slbId(), rawData->channel());
74 if (!mapped) {
75 ++statistics.nMappingFailures;
76 continue;
77 }
78
79 const Station hitStation = station(identifier, idHelperSvc);
80 const bool hitIsStrip = idHelperSvc.tgcIdHelper().isStrip(identifier);
81 float eta = 0.F;
82 float phi = 0.F;
83 float r = 0.F;
84 float z = 0.F;
85 const MuonGM::TgcReadoutElement* readoutElement =
86 detectorManager.getTgcReadoutElement(identifier);
87 if (readoutElement != nullptr) {
88 const Amg::Vector3D globalPosition = readoutElement->channelPos(identifier);
89 eta = static_cast<float>(globalPosition.eta());
90 phi = static_cast<float>(globalPosition.phi());
91 r = static_cast<float>(globalPosition.perp());
92 z = static_cast<float>(globalPosition.z());
93 }
94 const std::uint16_t hitTriggerSector = triggerSector(phi);
95 if (hitTriggerSector == 0U) {
96 ++statistics.nMappingFailures;
97 continue;
98 }
99
100 const Hit hit{
101 .subDetectorId = rawData->subDetectorId(),
102 .triggerSector = hitTriggerSector,
103 .detectorSector = rawData->rodId(),
104 .bcTag = rawData->bcTag(),
105 .sswId = rawData->sswId(),
106 .slbId = rawData->slbId(),
107 .readoutChannel = rawData->channel(),
108 .stationEta = static_cast<std::int16_t>(
109 idHelperSvc.tgcIdHelper().stationEta(identifier)),
110 .stationPhi = static_cast<std::uint16_t>(
111 idHelperSvc.tgcIdHelper().stationPhi(identifier)),
112 .gasGap = static_cast<std::uint8_t>(
113 idHelperSvc.tgcIdHelper().gasGap(identifier)),
114 .channel = static_cast<std::uint16_t>(
115 idHelperSvc.tgcIdHelper().channel(identifier)),
116 .station = hitStation,
117 .isStrip = hitIsStrip,
118 .eta = eta,
119 .phi = phi,
120 .r = r,
121 .z = z,
122 };
123 const HitGroupKey key{.subDetectorId = hit.subDetectorId,
124 .triggerSector = hit.triggerSector,
125 .bcTag = hit.bcTag};
126 hitGroups[key].emplace_back(hit);
127
128 ++statistics.nHits;
129 if (hitIsStrip) ++statistics.nStripHits;
130 else ++statistics.nWireHits;
131 switch (hitStation) {
132 case Station::M1:
133 ++statistics.nM1Hits;
134 break;
135 case Station::M2:
136 ++statistics.nM2Hits;
137 break;
138 case Station::M3:
139 ++statistics.nM3Hits;
140 break;
141 case Station::Inner:
142 ++statistics.nInnerHits;
143 break;
144 default:
145 ++statistics.nUnknownStation;
146 break;
147 }
148 }
149 }
150 return StatusCode::SUCCESS;
151}
152
153} // namespace TgcL0Floating
154} // 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).
const std::string & stationNameString(const Identifier &id) const
int stationName(const Identifier &id) const
Interface for Helper service that creates muon Identifiers and can be used to print Identifiers.
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
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
Event-local hardware processing key.