ATLAS Offline Software
RpcRdoToRpcDigit.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 #include "RpcRdoToRpcDigit.h"
6 #include "GaudiKernel/PhysicalConstants.h"
8 namespace {
9  constexpr double inverseSpeedOfLight = 1 / Gaudi::Units::c_light;
10 }
11 
12 namespace Muon {
14  ATH_CHECK(m_idHelperSvc.retrieve());
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  SG::WriteHandle writeHandle{m_rpcDigitKey, ctx};
41  ATH_CHECK(writeHandle.record(std::make_unique<RpcDigitContainer>(modHashMax)));
42 
43  for (size_t coll_hash = 0; coll_hash < modHashMax; ++coll_hash) {
44  if (tempOut[coll_hash] && tempOut[coll_hash]->size()) {
45  ATH_CHECK(writeHandle->addCollection(tempOut[coll_hash].release(), coll_hash));
46  }
47  }
48 
49  ATH_MSG_DEBUG("Decoding RPC RDO into RPC Digit");
50  return StatusCode::SUCCESS;
51  }
52 
53  StatusCode RpcRdoToRpcDigit::decodeLegacyRdo(const EventContext& ctx, TempDigitContainer& container) const {
54  if (!m_decodeLegacyRDO) {
55  ATH_MSG_VERBOSE("No legacy containers to be decoded ");
56  return StatusCode::SUCCESS;
57  }
58  SG::ReadHandle rdoContainer(m_rpcRdoKey, ctx);
59  ATH_CHECK(rdoContainer.isPresent());
60  ATH_MSG_DEBUG("Retrieved " << rdoContainer->size() << " RPC RDOs.");
62  ATH_CHECK(cablingMap.isValid());
63 
64  for (const RpcPad* rdoColl : *rdoContainer) {
65  ATH_MSG_DEBUG(" Number of CMs in this Pad " << rdoColl->size());
66  // Get pad online id and sector id
67  uint16_t padId = rdoColl->onlineId();
68  uint16_t sectorId = rdoColl->sector();
69 
71  for (const RpcCoinMatrix* coinMatrix : *rdoColl) {
72  // Get CM online Id
73  uint16_t cmaId = coinMatrix->onlineId();
74 
75  // For each CM, loop on the fired channels
76  for (const RpcFiredChannel* rpcChan : *coinMatrix) {
77  std::vector<std::unique_ptr<RpcDigit>> digitVec{m_rpcRdoDecoderTool->getDigit(rpcChan, sectorId,
78  padId, cmaId,
79  cablingMap.cptr())};
80 
81  if (digitVec.empty()) continue;
82 
84  for (std::unique_ptr<RpcDigit>& newDigit : digitVec) {
85  const IdentifierHash collHash = m_idHelperSvc->moduleHash(newDigit->identify());
86  std::unique_ptr<RpcDigitCollection>& digitColl = container[collHash];
87  if (!digitColl) {
88  digitColl = std::make_unique<RpcDigitCollection>(m_idHelperSvc->chamberId(newDigit->identify()),
89  collHash);
90  }
91  digitColl->push_back(std::move(newDigit));
92  }
93  }
94  }
95  }
96  return StatusCode::SUCCESS;
97  }
98  StatusCode RpcRdoToRpcDigit::decodeNRpc(const EventContext& ctx, TempDigitContainer& digit_map) const {
99  if (!m_decodeNrpcRDO) {
100  ATH_MSG_VERBOSE("NRPC rdo decoding has been switched off ");
101  return StatusCode::SUCCESS;
102  }
103 
104  SG::ReadHandle rdoContainer{m_nRpcRdoKey, ctx};
105  ATH_CHECK(rdoContainer.isPresent());
107  if (!cabling.isValid()) {
108  ATH_MSG_FATAL("Failed to retrieve "<<m_nRpcCablingKey.fullKey());
109  return StatusCode::FAILURE;
110  }
112  if (!muonDetMgr.isValid()) {
113  ATH_MSG_FATAL("Failed to retrieve the readout geometry "<<muonDetMgr.fullKey());
114  return StatusCode::FAILURE;
115  }
116  const RpcIdHelper& id_helper = m_idHelperSvc->rpcIdHelper();
117 
119  for (const xAOD::NRPCRDO* rdo : *rdoContainer) {
120  ATH_MSG_VERBOSE("Convert RDO tdcSector: "<< static_cast<int>(rdo->tdcsector())<<", tdc:"
121  <<static_cast<int>(rdo->tdc())<<" channel: "<<static_cast<int>(rdo->channel()) <<", time: "
122  <<rdo->time()<<", ToT: "<<rdo->timeoverthr());
123 
125  RpcCablingData convObj{};
126  convObj.subDetector = rdo->subdetector();
127  convObj.tdcSector = rdo->tdcsector();
128  convObj.tdc = rdo->tdc();
129  convObj.channelId = rdo->channel();
130 
131  if (!cabling->getOfflineId(convObj, msgStream())) {
132  ATH_MSG_FATAL("Failed to convert online -> offline");
133  return StatusCode::FAILURE;
134  }
135  Identifier chanId{0};
136  if (!cabling->convert(convObj, chanId)) {
137  return StatusCode::FAILURE;
138  }
140  IdentifierHash modHash = m_idHelperSvc->moduleHash(chanId);
141  std::unique_ptr<RpcDigitCollection>& coll = digit_map[modHash];
143  if (!coll) {
144  coll = std::make_unique<RpcDigitCollection>(id_helper.elementID(chanId), modHash);
145  }
148  const float digit_time = rdo->time();
149  const float ToT = m_patch_for_rpc_time ? rdo->timeoverthr()
150  + inverseSpeedOfLight * (muonDetMgr->getRpcReadoutElement(chanId)->stripPos(chanId)).mag() : rdo->timeoverthr() ;
151 
152  std::unique_ptr<RpcDigit> digit = std::make_unique<RpcDigit>(chanId, digit_time, ToT, convObj.stripSide());
153  coll->push_back(std::move(digit));
154  }
155  return StatusCode::SUCCESS;
156  }
157 }
Muon::RpcRdoToRpcDigit::m_nRpcRdoKey
SG::ReadHandleKey< xAOD::NRPCRDOContainer > m_nRpcRdoKey
Definition: RpcRdoToRpcDigit.h:44
ATH_MSG_FATAL
#define ATH_MSG_FATAL(x)
Definition: AthMsgStreamMacros.h:34
Muon::RpcRdoToRpcDigit::m_decodeNrpcRDO
Gaudi::Property< bool > m_decodeNrpcRDO
Definition: RpcRdoToRpcDigit.h:41
Muon::RpcRdoToRpcDigit::m_rpcReadKey
SG::ReadCondHandleKey< RpcCablingCondData > m_rpcReadKey
Definition: RpcRdoToRpcDigit.h:38
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Muon::RpcCablingOnlineID::subDetector
int16_t & subDetector
Identifier of the subdetector region in the readout BA / BC etc.
Definition: RpcCablingData.h:80
RpcIdHelper::elementID
Identifier elementID(int stationName, int stationEta, int stationPhi, int doubletR) const
Definition: RpcIdHelper.cxx:801
SG::ReadHandle
Definition: StoreGate/StoreGate/ReadHandle.h:70
ReadCellNoiseFromCool.cabling
cabling
Definition: ReadCellNoiseFromCool.py:154
xAOD::NRPCRDO_v1
Definition: NRPCRDO_v1.h:14
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
checkRpcDigits.digit
digit
Definition: checkRpcDigits.py:186
Muon
NRpcCablingAlg reads raw condition data and writes derived condition data to the condition store.
Definition: TrackSystemController.h:45
RpcCoinMatrix
Definition: RpcCoinMatrix.h:20
RpcIdHelper
Definition: RpcIdHelper.h:51
RpcFiredChannel
Definition: RpcFiredChannel.h:20
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
RpcRdoToRpcDigit.h
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
Muon::RpcRdoToRpcDigit::m_DetectorManagerKey
SG::ReadCondHandleKey< MuonGM::MuonDetectorManager > m_DetectorManagerKey
Definition: RpcRdoToRpcDigit.h:47
xAOD::uint16_t
setWord1 uint16_t
Definition: eFexEMRoI_v1.cxx:93
Muon::RpcRdoToRpcDigit::m_nRpcCablingKey
SG::ReadCondHandleKey< RpcCablingMap > m_nRpcCablingKey
Definition: RpcRdoToRpcDigit.h:45
Muon::RpcRdoToRpcDigit::initialize
virtual StatusCode initialize() override final
Definition: RpcRdoToRpcDigit.cxx:13
Muon::RpcRdoToRpcDigit::m_rpcRdoKey
SG::ReadHandleKey< RpcPadContainer > m_rpcRdoKey
Definition: RpcRdoToRpcDigit.h:36
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
MdtMezzExtraction.cablingMap
cablingMap
Definition: MdtMezzExtraction.py:19
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Muon::RpcRdoToRpcDigit::m_rpcRdoDecoderTool
ToolHandle< IRPC_RDO_Decoder > m_rpcRdoDecoderTool
Definition: RpcRdoToRpcDigit.h:34
SG::VarHandleKey::initialize
StatusCode initialize(bool used=true)
If this object is used as a property, then this should be called during the initialize phase.
Definition: AthToolSupport/AsgDataHandles/Root/VarHandleKey.cxx:103
Muon::RpcCablingData
Helper struct that is parsed to the cabling map to translate between the offline & online Identifiers...
Definition: RpcCablingData.h:94
DataVector::push_back
value_type push_back(value_type pElem)
Add an element to the end of the collection.
SG::CondHandleKey::initialize
StatusCode initialize(bool used=true)
python.PhysicalConstants.c_light
float c_light
Definition: PhysicalConstants.py:63
RpcPad
Definition: RpcPad.h:21
Muon::RpcRdoToRpcDigit::execute
virtual StatusCode execute(const EventContext &ctx) const override final
Definition: RpcRdoToRpcDigit.cxx:30
SG::WriteHandle
Definition: StoreGate/StoreGate/WriteHandle.h:76
Muon::RpcRdoToRpcDigit::m_idHelperSvc
ServiceHandle< IMuonIdHelperSvc > m_idHelperSvc
Definition: RpcRdoToRpcDigit.h:35
Muon::RpcRdoToRpcDigit::TempDigitContainer
std::vector< std::unique_ptr< RpcDigitCollection > > TempDigitContainer
Definition: RpcRdoToRpcDigit.h:29
Muon::RpcRdoToRpcDigit::m_decodeLegacyRDO
Gaudi::Property< bool > m_decodeLegacyRDO
Definition: RpcRdoToRpcDigit.h:40
Muon::RpcRdoToRpcDigit::decodeLegacyRdo
StatusCode decodeLegacyRdo(const EventContext &ctx, TempDigitContainer &container) const
: Decode the legacy RpcRdo format
Definition: RpcRdoToRpcDigit.cxx:53
Muon::RpcRdoToRpcDigit::m_patch_for_rpc_time
Gaudi::Property< bool > m_patch_for_rpc_time
Definition: RpcRdoToRpcDigit.h:42
SG::VarHandleBase::isPresent
bool isPresent() const
Is the referenced object present in SG?
Definition: StoreGate/src/VarHandleBase.cxx:394
Muon::RpcRdoToRpcDigit::decodeNRpc
StatusCode decodeNRpc(const EventContext &ctx, TempDigitContainer &container) const
Definition: RpcRdoToRpcDigit.cxx:98
Muon::RpcRdoToRpcDigit::m_rpcDigitKey
SG::WriteHandleKey< RpcDigitContainer > m_rpcDigitKey
Definition: RpcRdoToRpcDigit.h:37
IdentifierHash
This is a "hash" representation of an Identifier. This encodes a 32 bit index which can be used to lo...
Definition: IdentifierHash.h:25
mag
Scalar mag() const
mag method
Definition: AmgMatrixBasePlugin.h:26
RpcReadoutElement.h
Identifier
Definition: IdentifierFieldParser.cxx:14