ATLAS Offline Software
Loading...
Searching...
No Matches
TruthMeasMarkerAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
13
14namespace MuonR4 {
16 using SegLink_t = ElementLink<xAOD::MuonSegmentContainer>;
17 using SegLinkVec_t = std::vector<SegLink_t>;
18
19 using MarkerHandle_t = xAOD::ContainerDecorator<PrdCont_t, std::uint8_t>;
20 using LinkHandle_t = xAOD::ContainerDecorator<PrdCont_t, SegLinkVec_t>;
21
22 using WriteDecorKey_t = SG::WriteDecorHandleKey<xAOD::MuonMeasurementContainer>;
23
25 ATH_CHECK(m_segKey.initialize());
26 if (m_measKeys.empty()) {
27 ATH_MSG_FATAL("Please configure the measurement containers to decorate.");
28 return StatusCode::FAILURE;
29 }
30 ATH_CHECK(m_measKeys.initialize());
31 for (const auto& key : m_measKeys) {
32 m_writeMarkKeys.emplace_back(key, m_writeMarker);
33 m_writeSegLinkKeys.emplace_back(key, m_segLink);
34 m_prdLinkKeys.emplace_back(key, m_simLink);
35 }
36 ATH_CHECK(m_prdLinkKeys.initialize());
37 ATH_CHECK(m_writeMarkKeys.initialize());
38 ATH_CHECK(m_writeSegLinkKeys.initialize());
39 return StatusCode::SUCCESS;
40 }
41 StatusCode TruthMeasMarkerAlg::execute(const EventContext& ctx) const {
42 const xAOD::MuonSegmentContainer* segContainer{nullptr};
43 ATH_CHECK(SG::get(segContainer, m_segKey, ctx));
44
45 std::unordered_map<const SG::AuxVectorData*, MarkerHandle_t> markers{};
46 using namespace Muon::MuonStationIndex;
47
49
50 std::array<std::vector<ChamberView_t>,
51 Acts::toUnderlying(TechnologyIndex::TechnologyIndexMax)> techConts{};
52 for (const WriteDecorKey_t& key : m_writeMarkKeys) {
53 const xAOD::MuonMeasurementContainer* measContainer{nullptr};
54 ATH_CHECK(SG::get(measContainer, key.contHandleKey(), ctx));
55 if (measContainer->empty()) {
56 continue;
57 }
58 markers.insert(std::make_pair(measContainer, MarkerHandle_t{key, ctx}));
59 const TechnologyIndex techIdx = m_idHelperSvc->technologyIndex(measContainer->at(0)->identify());
60 techConts[Acts::toUnderlying(techIdx)].emplace_back(ChamberView_t{*measContainer});
61 }
62 std::unordered_map<const SG::AuxVectorData*, LinkHandle_t> links{};
63 for (const WriteDecorKey_t& key : m_writeSegLinkKeys) {
64 const xAOD::MuonMeasurementContainer* measContainer{nullptr};
65 ATH_CHECK(SG::get(measContainer, key.contHandleKey(), ctx));
66 if (measContainer->empty()) {
67 continue;
68 }
69 links.insert(std::make_pair(measContainer, LinkHandle_t{key, ctx}));
70 }
71
72 auto fetchPrd = [&](const xAOD::MuonSimHit* hit) -> std::vector<const xAOD::MuonMeasurement*> {
73 std::vector<const xAOD::MuonMeasurement*> prds{};
74 const IdentifierHash idHash{m_idHelperSvc->detElementHash(hit->identify())};
75 const TechnologyIndex techIdx = m_idHelperSvc->technologyIndex(hit->identify());
76 for (ChamberView_t& prdCont : techConts[Acts::toUnderlying(techIdx)]){
77 if (!prdCont.loadView(idHash)) {
78 continue;
79 }
80 for (const xAOD::MuonMeasurement* prd : prdCont) {
81 if (getTruthMatchedHit(*prd) == hit){
82 ATH_MSG_VERBOSE("Found hit matched to "<<m_idHelperSvc->toString(hit->identify()));
83 prds.emplace_back(prd);
84 }
85 }
86 }
87 return prds;
88 };
89
90 for (const xAOD::MuonSegment* segment : *segContainer) {
91 const auto truthHits{getMatchingSimHits(*segment)};
92
93 SegLink_t segLink{segContainer, segment->index()};
94 for (const xAOD::MuonSimHit* simHit : truthHits) {
95 for (const xAOD::MuonMeasurement* prd : fetchPrd(simHit)) {
96 markers.at(prd->container())(*prd) = true;
97 links.at(prd->container())(*prd).push_back(segLink);
98 }
99 }
100 }
101 return StatusCode::SUCCESS;
102 }
103
104}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
bool hit(const Container &ids, int pdgId)
Handle class for reading a decoration on an object.
Handle class for reading from StoreGate.
Handle class for adding a decoration to an object.
const T * at(size_type n) const
Access an element, as an rvalue.
bool empty() const noexcept
Returns true if the collection is empty.
This is a "hash" representation of an Identifier.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
Gaudi::Property< std::string > m_segLink
Key to indicate the associated MuonSegment link.
SG::ReadHandleKeyArray< xAOD::MuonMeasurementContainer > m_measKeys
Key to the prd containers in the event.
SG::WriteDecorHandleKeyArray< xAOD::MuonMeasurementContainer > m_writeSegLinkKeys
Key to the segment link decoration.
SG::WriteDecorHandleKeyArray< xAOD::MuonMeasurementContainer > m_writeMarkKeys
Key to the marker decoration.
virtual StatusCode execute(const EventContext &ctx) const override final
Gaudi::Property< std::string > m_simLink
Decoration key of the prd -> simHit association.
virtual StatusCode initialize() override final
SG::ReadDecorHandleKeyArray< xAOD::MuonMeasurementContainer > m_prdLinkKeys
Dependency on the sim hit decoration.
SG::ReadHandleKey< xAOD::MuonSegmentContainer > m_segKey
Key to the primary muon container to select the muon from.
Gaudi::Property< std::string > m_writeMarker
Key that's decorated to mark the uncalibrated measurement.
int markers[6]
Definition computils.cxx:47
This header ties the generic definitions in this package.
xAOD::ContainerDecorator< PrdCont_t, SegLinkVec_t > LinkHandle_t
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::MuonMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
std::vector< SegLink_t > SegLinkVec_t
ElementLink< xAOD::MuonSegmentContainer > SegLink_t
xAOD::UncalibratedMeasurementContainer PrdCont_t
xAOD::ContainerDecorator< PrdCont_t, std::uint8_t > MarkerHandle_t
SG::WriteDecorHandleKey< xAOD::UncalibratedMeasurementContainer > WriteDecorKey_t
TechnologyIndex
enum to classify the different layers in the muon spectrometer
const T * get(const ReadCondHandleKey< T > &key, const EventContext &ctx)
Convenience function to retrieve an object given a ReadCondHandleKey.
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
MuonMeasurement_v1 MuonMeasurement
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
MuonSegment_v1 MuonSegment
Reference the current persistent version:
MuonMeasurementContainer_v1 MuonMeasurementContainer