ATLAS Offline Software
Loading...
Searching...
No Matches
RpcRdoToRpcDigit.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
5#include "RpcRdoToRpcDigit.h"
6#include "GaudiKernel/PhysicalConstants.h"
8namespace {
9 constexpr double inverseSpeedOfLight = 1 / Gaudi::Units::c_light;
10}
11
12namespace Muon {
14 ATH_CHECK(m_idHelperSvc.retrieve());
15 ATH_CHECK(m_rpcDigitKey.initialize());
17 ATH_MSG_ERROR("Neither legacy or xAOD::Rpcs shall be translated.");
18 return StatusCode::FAILURE;
19 }
21 ATH_CHECK(m_rpcRdoDecoderTool.retrieve(EnableTool{m_decodeLegacyRDO}));
23
27
28 return StatusCode::SUCCESS;
29 }
30 StatusCode RpcRdoToRpcDigit::execute(const EventContext& ctx) const {
31 ATH_MSG_DEBUG("in execute()");
32 // retrieve the collection of RDO
33
34 const size_t modHashMax{m_idHelperSvc->rpcIdHelper().module_hash_max()};
35 TempDigitContainer tempOut(modHashMax);
36
37 ATH_CHECK(decodeLegacyRdo(ctx, tempOut));
38 ATH_CHECK(decodeNRpc(ctx, tempOut));
39
40 if (msgLvl(MSG::VERBOSE)) {
41 for (const std::unique_ptr<RpcDigitCollection>& digitCollPtr : tempOut) {
42 if (!digitCollPtr) {
43 continue;
44 }
45 std::sort(digitCollPtr->begin(), digitCollPtr->end(), [](const RpcDigit* a,
46 const RpcDigit* b) {
47 return a->identify() < b->identify();
48 });
49
50 for (const RpcDigit* digitPtr : *digitCollPtr) {
51 ATH_MSG_VERBOSE(" Digit id: " << m_idHelperSvc->toString(digitPtr->identify())
52 << " time: " << digitPtr->time()
53 << " ToT: " << digitPtr->ToT()
54 << " stripSide: " << digitPtr->stripSide());
55 }
56 }
57 }
58
59 SG::WriteHandle writeHandle{m_rpcDigitKey, ctx};
60 ATH_CHECK(writeHandle.record(std::make_unique<RpcDigitContainer>(modHashMax)));
61
62 for (size_t coll_hash = 0; coll_hash < modHashMax; ++coll_hash) {
63 if (tempOut[coll_hash] && tempOut[coll_hash]->size()) {
64 ATH_CHECK(writeHandle->addCollection(tempOut[coll_hash].release(), coll_hash));
65 }
66 }
67
68 ATH_MSG_DEBUG("Decoding RPC RDO into RPC Digit");
69 return StatusCode::SUCCESS;
70 }
71
72 StatusCode RpcRdoToRpcDigit::decodeLegacyRdo(const EventContext& ctx, TempDigitContainer& container) const {
73 if (!m_decodeLegacyRDO) {
74 ATH_MSG_VERBOSE("No legacy containers to be decoded ");
75 return StatusCode::SUCCESS;
76 }
77 SG::ReadHandle rdoContainer(m_rpcRdoKey, ctx);
78 ATH_CHECK(rdoContainer.isPresent());
79 ATH_MSG_DEBUG("Retrieved " << rdoContainer->size() << " RPC RDOs.");
80 SG::ReadCondHandle cablingMap{m_rpcReadKey, ctx};
81 ATH_CHECK(cablingMap.isValid());
82
83 for (const RpcPad* rdoColl : *rdoContainer) {
84 ATH_MSG_DEBUG(" Number of CMs in this Pad " << rdoColl->size());
85 // Get pad online id and sector id
86 uint16_t padId = rdoColl->onlineId();
87 uint16_t sectorId = rdoColl->sector();
88
90 for (const RpcCoinMatrix* coinMatrix : *rdoColl) {
91 // Get CM online Id
92 uint16_t cmaId = coinMatrix->onlineId();
93
94 // For each CM, loop on the fired channels
95 for (const RpcFiredChannel* rpcChan : *coinMatrix) {
96 std::vector<std::unique_ptr<RpcDigit>> digitVec{m_rpcRdoDecoderTool->getDigit(rpcChan, sectorId,
97 padId, cmaId,
98 cablingMap.cptr())};
99
100 if (digitVec.empty()) continue;
101
103 for (std::unique_ptr<RpcDigit>& newDigit : digitVec) {
104 const IdentifierHash collHash = m_idHelperSvc->moduleHash(newDigit->identify());
105 std::unique_ptr<RpcDigitCollection>& digitColl = container[collHash];
106 if (!digitColl) {
107 digitColl = std::make_unique<RpcDigitCollection>(m_idHelperSvc->chamberId(newDigit->identify()),
108 collHash);
109 }
110 digitColl->push_back(std::move(newDigit));
111 }
112 }
113 }
114 }
115 return StatusCode::SUCCESS;
116 }
117 StatusCode RpcRdoToRpcDigit::decodeNRpc(const EventContext& ctx, TempDigitContainer& digit_map) const {
118 if (!m_decodeNrpcRDO) {
119 ATH_MSG_VERBOSE("NRPC rdo decoding has been switched off ");
120 return StatusCode::SUCCESS;
121 }
122
123 SG::ReadHandle rdoContainer{m_nRpcRdoKey, ctx};
124 ATH_CHECK(rdoContainer.isPresent());
125 ATH_MSG_DEBUG("Retrieved " << rdoContainer->size() << " NRPC RDOs.");
127 if (!cabling.isValid()) {
128 ATH_MSG_FATAL("Failed to retrieve "<<m_nRpcCablingKey.fullKey());
129 return StatusCode::FAILURE;
130 }
132 if (!muonDetMgr.isValid()) {
133 ATH_MSG_FATAL("Failed to retrieve the readout geometry "<<muonDetMgr.fullKey());
134 return StatusCode::FAILURE;
135 }
136 const RpcIdHelper& id_helper = m_idHelperSvc->rpcIdHelper();
137
139 for (const xAOD::NRPCRDO* rdo : *rdoContainer) {
140 ATH_MSG_VERBOSE("Convert RDO boardSector: "<< static_cast<int>(rdo->boardsector())<<", board:"
141 <<static_cast<int>(rdo->board())<<" channel: "<<static_cast<int>(rdo->channel()) <<", time: "
142 <<rdo->time()<<", ToT: "<<rdo->timeoverthr());
143
145 RpcCablingData convObj{};
146 convObj.subDetector = rdo->subdetector();
147 convObj.boardSector = rdo->boardsector();
148 convObj.board = rdo->board();
149 convObj.channelId = rdo->channel();
150
151 if (!cabling->getOfflineId(convObj, msgStream())) {
152 ATH_MSG_FATAL("Failed to convert online -> offline");
153 return StatusCode::FAILURE;
154 }
155 Identifier chanId{0};
156 if (!cabling->convert(convObj, chanId)) {
157 return StatusCode::FAILURE;
158 }
160 IdentifierHash modHash = m_idHelperSvc->moduleHash(chanId);
161 std::unique_ptr<RpcDigitCollection>& coll = digit_map[modHash];
163 if (!coll) {
164 coll = std::make_unique<RpcDigitCollection>(id_helper.elementID(chanId), modHash);
165 }
168 const double timeOfFlight = inverseSpeedOfLight * (muonDetMgr->getRpcReadoutElement(chanId)->stripPos(chanId)).mag();
169 const float digit_time = rdo->time() - timeOfFlight;
170 const float ToT = m_patch_for_rpc_time ? rdo->timeoverthr() + timeOfFlight : rdo->timeoverthr() ;
171 std::unique_ptr<RpcDigit> digit = std::make_unique<RpcDigit>(chanId, digit_time, ToT, convObj.stripSide());
172 coll->push_back(std::move(digit));
173 }
174 return StatusCode::SUCCESS;
175 }
176}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_DEBUG(x)
static Double_t a
bool msgLvl(const MSG::Level lvl) const
This is a "hash" representation of an Identifier.
Gaudi::Property< bool > m_decodeNrpcRDO
Gaudi::Property< bool > m_decodeLegacyRDO
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadHandleKey< xAOD::NRPCRDOContainer > m_nRpcRdoKey
ToolHandle< IRPC_RDO_Decoder > m_rpcRdoDecoderTool
SG::ReadCondHandleKey< RpcCablingCondData > m_rpcReadKey
Gaudi::Property< bool > m_patch_for_rpc_time
StatusCode decodeNRpc(const EventContext &ctx, TempDigitContainer &container) const
SG::ReadCondHandleKey< RpcCablingMap > m_nRpcCablingKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
StatusCode decodeLegacyRdo(const EventContext &ctx, TempDigitContainer &container) const
: Decode the legacy RpcRdo format
ServiceHandle< IMuonIdHelperSvc > m_idHelperSvc
virtual StatusCode initialize() override final
SG::WriteHandleKey< RpcDigitContainer > m_rpcDigitKey
SG::ReadHandleKey< RpcPadContainer > m_rpcRdoKey
std::vector< std::unique_ptr< RpcDigitCollection > > TempDigitContainer
Identifier elementID(int stationName, int stationEta, int stationPhi, int doubletR) const
const DataObjID & fullKey() const
bool isPresent() const
Is the referenced object present in SG?
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
void sort(typename DataModel_detail::iterator< DVL > beg, typename DataModel_detail::iterator< DVL > end)
Specialization of sort for DataVector/List.
NRPCRDO_v1 NRPCRDO
Define the version of the NRPC RDO class.
Definition NRPCRDO.h:13
Helper struct that is parsed to the cabling map to translate between the offline & online Identifiers...
uint8_t channelId
Online board channel number.
bool stripSide() const
: Is the strip readout on the opposite side
int16_t & board
Unique identifier of the tdc chip.
int16_t & boardSector
Unique Identifier of the Rpc chamber from an online perspective.
int16_t & subDetector
Identifier of the subdetector region in the readout BA / BC etc.