ATLAS Offline Software
Loading...
Searching...
No Matches
MeasTruthAssocMapProvider.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
8
11
12namespace MuonR4{
14 ATH_CHECK(m_readKey.initialize());
15 ATH_CHECK(m_linkKey.initialize());
16 ATH_CHECK(m_writeKey.initialize());
17 ATH_CHECK(m_truthKey.initialize());
18 ATH_CHECK(m_segLinkKey.initialize());
19 ATH_CHECK(m_segLinkKey.initialize());
20 return StatusCode::SUCCESS;
21 }
22 StatusCode MeasTruthAssocMapProvider::execute(const EventContext& ctx) const {
23 const xAOD::MuonMeasurementContainer* measurements{};
24 ATH_CHECK(SG::get(measurements, m_readKey, ctx));
25 auto assocMap = std::make_unique<ActsTrk::MeasurementToTruthParticleAssociation>(measurements->size());
26 assocMap->setSourceContainer(*measurements, ctx);
27 for (const xAOD::MuonMeasurement* meas : *measurements) {
28 const xAOD::MuonSimHit* assocHit = getTruthMatchedHit(*meas);
29 if (!assocHit) {
30 continue;
31 }
32 const xAOD::TruthParticle* truthPart = getTruthMatchedParticle(*assocHit);
33 if (!truthPart) {
34 continue;
35 }
36 (*assocMap)[meas->index()]= {xAOD::TruthHelpers::getTruthParticle(*truthPart)};
37 }
38 SG::WriteHandle writeHandle{m_writeKey, ctx};
39 ATH_CHECK(writeHandle.record(std::move(assocMap)));
40 return StatusCode::SUCCESS;
41 }
42}
#define ATH_CHECK
Evaluate an expression and check for errors.
Handle class for reading from StoreGate.
Handle class for recording to StoreGate.
size_type size() const noexcept
Returns the number of elements in the collection.
virtual StatusCode execute(const EventContext &ctx) const override final
virtual StatusCode initialize() override final
SG::ReadHandleKey< xAOD::MuonMeasurementContainer > m_readKey
Declare the container for which the Association map shall be built.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthKey
The dependency on the truth particle container.
SG::ReadDecorHandleKey< xAOD::MuonMeasurementContainer > m_linkKey
Declare the dependency on the associated sim hit.
SG::ReadDecorHandleKey< xAOD::TruthParticleContainer > m_segLinkKey
Dependency on the TruthSegment -> TruthParticle association.
SG::WriteHandleKey< ActsTrk::MeasurementToTruthParticleAssociation > m_writeKey
Name of the written association map.
StatusCode record(std::unique_ptr< T > data)
Record a const object to the store.
This header ties the generic definitions in this package.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::MuonMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
const xAOD::TruthParticle * getTruthParticle(const xAOD::IParticle &p)
Return the truthParticle associated to the given IParticle (if any).
MuonMeasurement_v1 MuonMeasurement
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
TruthParticle_v1 TruthParticle
Typedef to implementation.
MuonMeasurementContainer_v1 MuonMeasurementContainer