ATLAS Offline Software
Loading...
Searching...
No Matches
RpcRdoToRpcPrepDataTool.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
14
17
20
21
22
23namespace MuonR4{
25 ATH_CHECK(m_idHelperSvc.retrieve());
26 ATH_CHECK(m_rdoKey.initialize());
27 ATH_CHECK(m_cablingKey.initialize());
28 ATH_CHECK(detStore()->retrieve(m_detMgr));
29 ATH_CHECK(m_writeKey.initialize());
31 return StatusCode::SUCCESS;
32 }
33
34 StatusCode RpcRdoToRpcPrepDataTool::decode(const EventContext& ctx,
35 const std::vector<IdentifierHash>& idVect) const {
36
37
38 const xAOD::NRPCRDOContainer* rdoContainer{nullptr};
39 ATH_CHECK(SG::get(rdoContainer, m_rdoKey, ctx));
40
41 const Muon::RpcCablingMap* cablingMap{nullptr};
42 ATH_CHECK(SG::get(cablingMap, m_cablingKey, ctx));
43
44 const std::unordered_set<IdentifierHash> hashToSelect(idVect.begin(), idVect.end());
45 using RdoPairs = std::array<const xAOD::NRPCRDO*, 2>;
46 std::map<Identifier, RdoPairs, Muon::IdentifierByDetElSorter> sortedRdos{Muon::IdentifierByDetElSorter{m_idHelperSvc.get()}};
47 for (const xAOD::NRPCRDO* rdo : *rdoContainer){
48 /* cabling data conversion */
49 Muon::RpcCablingData cabling{};
50 cabling.subDetector = rdo->subdetector();
51 cabling.boardSector = rdo->boardsector();
52 cabling.board = rdo->board();
53 cabling.channelId = rdo->channel();
54
55
56 if (!cablingMap->getOfflineId(cabling, msgStream())){
57 return StatusCode::FAILURE;
58 }
59 Identifier offId{};
60 if (!cablingMap->convert(cabling, offId)){
61 ATH_MSG_FATAL("Cabling conversion failed "<<cabling);
62 return StatusCode::FAILURE;
63 }
64 if (hashToSelect.size() && !hashToSelect.count(m_idHelperSvc->moduleHash(offId))) {
65 ATH_MSG_VERBOSE("Skip "<<m_idHelperSvc->toString(offId)<<" due to ROI selection ");
66 continue;
67 }
69 const bool stripSide = cabling.stripSide();
70 sortedRdos[offId][stripSide] = rdo;
71 }
72
73 Strip1DFiller_t stripHandle{};
74 Strip2DFiller_t strip2DHandle{};
75
76 const RpcIdHelper& idHelper{m_idHelperSvc->rpcIdHelper()};
77
78 auto setMeasValues = [&idHelper,this](xAOD::RpcMeasurement* outputMeas,
79 const xAOD::NRPCRDO* rdo,
80 const Identifier& offId){
81
82 const MuonGMR4::RpcReadoutElement* reElement = m_detMgr->getRpcReadoutElement(offId);
83 outputMeas->setIdentifierHash(m_idHelperSvc->detElementHash(offId));
84 outputMeas->setReadoutElement(reElement);
85 outputMeas->setIdentifier(offId.get_compact());
86 outputMeas->setDoubletPhi(idHelper.doubletPhi(offId));
87 outputMeas->setGasGap(idHelper.gasGap(offId));
88 outputMeas->setChannelNumber(idHelper.channel(offId));
89 outputMeas->setTimeOverThreshold(rdo->timeoverthr());
91 outputMeas->setTime(rdo->time());
92 outputMeas->setTimeCovariance(std::pow(m_stripTimeResolution,2));
93 };
94
96 using CheckVector2D = MuonGMR4::StripDesign::CheckVector2D;
97 for (const auto& [offId, rdoPairs] : sortedRdos) {
98 const MuonGMR4::RpcReadoutElement* reElement = m_detMgr->getRpcReadoutElement(offId);
99 const IdentifierHash measHash = reElement->measurementHash(offId);
100
101 const MuonGMR4::StripDesign& design{reElement->sensorLayout(measHash)->design(idHelper.measuresPhi(offId))};
102
103 CheckVector2D stripPos = design.center(idHelper.channel(offId));
104 if (!stripPos) {
105 ATH_MSG_WARNING("Failed to fetch a valid stripPosition for "<<m_idHelperSvc->toString(offId));
106 continue;
107 }
108 const double stripLocX = (*stripPos).x();
109 const double stripCovX = std::pow(design.stripPitch(), 2) / std::sqrt(12.);
110
111 if (m_decode2DStrips && rdoPairs[0] && rdoPairs[1]) {
112 xAOD::RpcStrip2D* measurement = strip2DHandle->push_back(std::make_unique<xAOD::RpcStrip2D>());
113
116
117 lPos[0] = stripLocX;
118 lPos[1] = 0.5*m_propagationVelocity *(rdoPairs[0]->time() - rdoPairs[1]->time());
119 lCov(0,0) = stripCovX;
120 lCov(1,1) = M_SQRT1_2 * m_propagationVelocity* m_stripTimeResolution;
122 measurement->setMeasurement<2>(0, lPos, lCov);
123 // CheckVector2D stripPos
124 setMeasValues(measurement, rdoPairs[0], offId);
125 ATH_MSG_VERBOSE("Measurement "<<m_idHelperSvc->toString(offId)<<" "<<lPos.x()<<", "<<lPos.y());
126 continue;
127 }
128
129 xAOD::RpcStrip* strip = stripHandle->push_back(std::make_unique<xAOD::RpcStrip>());
132 lPos[0] = stripLocX;
133 lCov(0,0) = stripCovX;
134
135 strip->setMeasuresPhi(idHelper.measuresPhi(offId));
137 strip->setMeasurement<1>(0, lPos, lCov);
138 setMeasValues(strip, rdoPairs[0] ? rdoPairs[0] : rdoPairs[1], offId);
139 }
140
141 ATH_CHECK(stripHandle.record(m_writeKey, ctx));
142 ATH_CHECK(strip2DHandle.record(m_writeKeyBI, ctx));
143 return StatusCode::SUCCESS;
144
145 }
146 StatusCode RpcRdoToRpcPrepDataTool::decode(const EventContext& ctx,
147 const std::vector<uint32_t>& robIds) const {
148 const Muon::RpcCablingMap* cablingMap{nullptr};
149 ATH_CHECK(SG::get(cablingMap, m_cablingKey, ctx));
150 return decode(ctx, cablingMap->getChamberHashVec(robIds, msgStream()));
151 }
152 StatusCode RpcRdoToRpcPrepDataTool::provideEmptyContainer(const EventContext& ctx) const {
153 SG::WriteHandle stripHandle{m_writeKey, ctx};
154 ATH_CHECK(stripHandle.record(std::make_unique<xAOD::RpcStripContainer>(),
155 std::make_unique<xAOD::RpcStripAuxContainer>()));
156
157 if (!m_writeKeyBI.empty()) {
158 SG::WriteHandle strip2DHandle{m_writeKeyBI, ctx};
159 ATH_CHECK(strip2DHandle.record(std::make_unique<xAOD::RpcStrip2DContainer>(),
160 std::make_unique<xAOD::RpcStrip2DAuxContainer>()));
161
162 }
163 return StatusCode::SUCCESS;
164 }
165
166}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
xAOD::FillContainer< xAOD::RpcStrip2DContainer, xAOD::RpcStrip2DAuxContainer > Strip2DFiller_t
xAOD::FillContainer< xAOD::RpcStripContainer, xAOD::RpcStripAuxContainer > Strip1DFiller_t
Handle class for recording to StoreGate.
This is a "hash" representation of an Identifier.
IdentifierHash measurementHash(const Identifier &measId) const override final
Constructs the identifier hash from the full measurement Identifier.
const StripLayerPtr & sensorLayout(const IdentifierHash &measHash) const
Access to the StripLayer associated to a given measurement Hash.
CheckVector2D center(int stripNumb) const
Returns the bisector of the strip (Global numbering scheme).
std::optional< Amg::Vector2D > CheckVector2D
Definition StripDesign.h:82
double stripPitch() const
Distance between two adjacent strips.
StatusCode provideEmptyContainer(const EventContext &ctx) const override final
Method to create the empty containers.. Only used for seeded decoding.
SG::ReadHandleKey< xAOD::NRPCRDOContainer > m_rdoKey
Gaudi::Property< double > m_propagationVelocity
SG::ReadCondHandleKey< Muon::RpcCablingMap > m_cablingKey
StatusCode initialize() override final
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
StatusCode decode(const EventContext &ctx, const std::vector< IdentifierHash > &idVect) const override final
SG::WriteHandleKey< xAOD::RpcStripContainer > m_writeKey
SG::WriteHandleKey< xAOD::RpcStrip2DContainer > m_writeKeyBI
Gaudi::Property< double > m_stripTimeResolution
const MuonGMR4::MuonDetectorManager * m_detMgr
int gasGap(const Identifier &id) const override
get the hashes
int channel(const Identifier &id) const override
int doubletPhi(const Identifier &id) const
bool measuresPhi(const Identifier &id) const override
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
StatusCode record(const SG::WriteHandleKey< Cont_t > &key, const EventContext &ctx)
Record the container to store gate using the passed write handle key.
void setMeasurement(const DetectorIDHashType idHash, MeasVector< N > locPos, MeasMatrix< N > locCov)
Sets IdentifierHash, local position and local covariance of the measurement.
This header ties the generic definitions in this package.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
RpcStrip_v1 RpcStrip
Definition RpcStripFwd.h:11
RpcStrip2D_v1 RpcStrip2D
RpcStripContainer_v1 RpcStripContainer
RpcStripAuxContainer_v1 RpcStripAuxContainer
Definition RpcStripFwd.h:14
Eigen::Matrix< float, N, N > MeasMatrix
NRPCRDO_v1 NRPCRDO
Define the version of the NRPC RDO class.
Definition NRPCRDO.h:13
RpcStrip2DAuxContainer_v1 RpcStrip2DAuxContainer
Eigen::Matrix< float, N, 1 > MeasVector
Abrivation of the Matrix & Covariance definitions.
NRPCRDOContainer_v1 NRPCRDOContainer
Define the version of the NRPC RDO container.
RpcMeasurement_v1 RpcMeasurement
RpcStrip2DContainer_v1 RpcStrip2DContainer
Helper struct that is parsed to the cabling map to translate between the offline & online Identifiers...