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 = SG::WriteDecorHandle<PrdCont_t, bool>;
20 using LinkHandle_t = SG::WriteDecorHandle<PrdCont_t, SegLinkVec_t>;
21
22 using WriteDecorKey_t = SG::WriteDecorHandleKey<xAOD::MuonMeasurementContainer>;
23 using namespace DerivationFramework;
24
26 ATH_CHECK(m_segKey.initialize());
27 if (m_measKeys.empty()) {
28 ATH_MSG_FATAL("Please configure the measurement containers to decorate.");
29 return StatusCode::FAILURE;
30 }
31 ATH_CHECK(m_measKeys.initialize());
32 for (const auto& key : m_measKeys) {
33 m_writeMarkKeys.emplace_back(key, m_writeMarker);
34 m_writeSegLinkKeys.emplace_back(key, m_segLink);
35 m_prdLinkKeys.emplace_back(key, m_simLink);
36 }
37 ATH_CHECK(m_prdLinkKeys.initialize());
38 ATH_CHECK(m_writeMarkKeys.initialize());
39 ATH_CHECK(m_writeSegLinkKeys.initialize());
40 return StatusCode::SUCCESS;
41 }
42 StatusCode TruthMeasMarkerAlg::execute(const EventContext& ctx) const {
43 const xAOD::MuonSegmentContainer* segContainer{nullptr};
44 ATH_CHECK(SG::get(segContainer, m_segKey, ctx));
45
46 std::unordered_map<const SG::AuxVectorData*, MarkerHandle_t> markers{};
47 using namespace Muon::MuonStationIndex;
48
50
51 std::array<std::vector<ChamberView_t>,
52 Acts::toUnderlying(TechnologyIndex::TechnologyIndexMax)> techConts{};
53 for (const WriteDecorKey_t& key : m_writeMarkKeys) {
54 const xAOD::MuonMeasurementContainer* measContainer{nullptr};
55 ATH_CHECK(SG::get(measContainer, key.contHandleKey(), ctx));
56 if (measContainer->empty()) {
57 continue;
58 }
59 MarkerHandle_t decor{makeHandle(ctx, key, false)};
60 markers.insert(std::make_pair(measContainer, std::move(decor)));
61 const TechnologyIndex techIdx = m_idHelperSvc->technologyIndex(measContainer->at(0)->identify());
62 techConts[Acts::toUnderlying(techIdx)].emplace_back(ChamberView_t{*measContainer});
63 }
64 std::unordered_map<const SG::AuxVectorData*, LinkHandle_t> links{};
65 for (const WriteDecorKey_t& key : m_writeSegLinkKeys) {
66 const xAOD::MuonMeasurementContainer* measContainer{nullptr};
67 ATH_CHECK(SG::get(measContainer, key.contHandleKey(), ctx));
68 if (measContainer->empty()) {
69 continue;
70 }
71 LinkHandle_t decor{makeHandle(ctx, key,SegLinkVec_t{})};
72 links.insert(std::make_pair(measContainer, std::move(decor)));
73 }
74
75 auto fetchPrd = [&](const xAOD::MuonSimHit* hit) -> std::vector<const xAOD::MuonMeasurement*> {
76 std::vector<const xAOD::MuonMeasurement*> prds{};
77 const IdentifierHash idHash{m_idHelperSvc->detElementHash(hit->identify())};
78 const TechnologyIndex techIdx = m_idHelperSvc->technologyIndex(hit->identify());
79 for (ChamberView_t& prdCont : techConts[Acts::toUnderlying(techIdx)]){
80 if (!prdCont.loadView(idHash)) {
81 continue;
82 }
83 for (const xAOD::MuonMeasurement* prd : prdCont) {
84 if (getTruthMatchedHit(*prd) == hit){
85 ATH_MSG_VERBOSE("Found hit matched to "<<m_idHelperSvc->toString(hit->identify()));
86 prds.emplace_back(prd);
87 }
88 }
89 }
90 return prds;
91 };
92
93 for (const xAOD::MuonSegment* segment : *segContainer) {
94 const auto truthHits{getMatchingSimHits(*segment)};
95
96 SegLink_t segLink{segContainer, segment->index()};
97 for (const xAOD::MuonSimHit* simHit : truthHits) {
98 for (const xAOD::MuonMeasurement* prd : fetchPrd(simHit)) {
99 markers.at(prd->container())(*prd) = true;
100 links.at(prd->container())(*prd).push_back(segLink);
101 }
102 }
103 }
104 return StatusCode::SUCCESS;
105 }
106
107}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_FATAL(x)
#define ATH_MSG_VERBOSE(x)
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
SG::WriteDecorHandle< ContType, dType > makeHandle(const EventContext &ctx, const SG::WriteDecorHandleKey< ContType > &key, const dType &defValue=dType{})
This header ties the generic definitions in this package.
SG::WriteDecorHandle< PrdCont_t, bool > MarkerHandle_t
SG::WriteDecorHandle< 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.
ElementLink< MuonR4::SegmentContainer > SegLink_t
Abrivation of the link to the reco segment container.
std::vector< SegLink_t > SegLinkVec_t
xAOD::UncalibratedMeasurementContainer PrdCont_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