ATLAS Offline Software
Loading...
Searching...
No Matches
TruthMeasMarkerAlg.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3*/
5
12
13namespace MuonR4 {
15 using SegLink_t = ElementLink<xAOD::MuonSegmentContainer>;
16 using SegLinkVec_t = std::vector<SegLink_t>;
17
18 using MarkerHandle_t = SG::WriteDecorHandle<PrdCont_t, bool>;
19 using LinkHandle_t = SG::WriteDecorHandle<PrdCont_t, SegLinkVec_t>;
20
21 using WriteDecorKey_t = SG::WriteDecorHandleKey<xAOD::UncalibratedMeasurementContainer>;
22 using namespace DerivationFramework;
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 std::unordered_map<Muon::MuonStationIndex::TechnologyIndex, std::vector<const PrdCont_t*>> techConts{};
47 for (const WriteDecorKey_t& key : m_writeMarkKeys) {
48 const xAOD::UncalibratedMeasurementContainer* measContainer{nullptr};
49 ATH_CHECK(SG::get(measContainer, key.contHandleKey(), ctx));
50 if (measContainer->empty()) {
51 continue;
52 }
53 MarkerHandle_t decor{makeHandle(ctx, key, false)};
54 markers.insert(std::make_pair(measContainer, std::move(decor)));
56 m_idHelperSvc->technologyIndex(xAOD::identify(measContainer->at(0)));
57 techConts[techIdx].push_back(measContainer);
58 }
59 std::unordered_map<const SG::AuxVectorData*, LinkHandle_t> links{};
60 for (const WriteDecorKey_t& key : m_writeSegLinkKeys) {
61 const xAOD::UncalibratedMeasurementContainer* measContainer{nullptr};
62 ATH_CHECK(SG::get(measContainer, key.contHandleKey(), ctx));
63 if (measContainer->empty()) {
64 continue;
65 }
66 LinkHandle_t decor{makeHandle(ctx, key,SegLinkVec_t{})};
67 links.insert(std::make_pair(measContainer, std::move(decor)));
68 }
69
70 auto fetchPrd = [&techConts,this](const xAOD::MuonSimHit* hit) -> const xAOD::UncalibratedMeasurement*{
71 for (const PrdCont_t* prdCont : techConts[m_idHelperSvc->technologyIndex(hit->identify())]){
72 for (const xAOD::UncalibratedMeasurement* prd : *prdCont) {
73 if (getTruthMatchedHit(*prd) == hit){
74 ATH_MSG_VERBOSE("Found hit matched to "<<m_idHelperSvc->toString(hit->identify()));
75 return prd;
76 }
77 }
78 }
79 ATH_MSG_VERBOSE("Nothing could be matched to "<<m_idHelperSvc->toString(hit->identify()));
80 return nullptr;
81 };
82
83 for (const xAOD::MuonSegment* segment : *segContainer) {
84 const auto truthHits{getMatchingSimHits(*segment)};
85
86 SegLink_t segLink{segContainer, segment->index()};
87 for (const xAOD::MuonSimHit* simHit : truthHits) {
88 const xAOD::UncalibratedMeasurement* prd = fetchPrd(simHit);
89 if (!prd) {
90 continue;
91 }
92 markers.at(prd->container())(*prd) = true;
93 links.at(prd->container())(*prd).push_back(segLink);
94 }
95 }
96 return StatusCode::SUCCESS;
97 }
98
99}
#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.
ServiceHandle< Muon::IMuonIdHelperSvc > m_idHelperSvc
IdHelperSvc to decode the Identifiers.
Gaudi::Property< std::string > m_segLink
Key to indicate the associated MuonSegment link.
virtual StatusCode execute(const EventContext &ctx) const override final
SG::ReadDecorHandleKeyArray< xAOD::UncalibratedMeasurementContainer > m_prdLinkKeys
Dependency on the sim hit decoration.
SG::ReadHandleKeyArray< xAOD::UncalibratedMeasurementContainer > m_measKeys
Key to the prd containers in the event.
SG::WriteDecorHandleKeyArray< xAOD::UncalibratedMeasurementContainer > m_writeMarkKeys
Key to the marker decoration.
SG::WriteDecorHandleKeyArray< xAOD::UncalibratedMeasurementContainer > m_writeSegLinkKeys
Key to the segment link decoration.
Gaudi::Property< std::string > m_simLink
Decoration key of the prd -> simHit association.
virtual StatusCode initialize() override final
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.
const SG::AuxVectorData * container() const
Return the container holding this element.
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.
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::UncalibratedMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
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
ElementLink< MuonR4::SegmentContainer > SegLink_t
Abrivation of the link to the reco segment container.
SG::WriteDecorHandleKey< xAOD::UncalibratedMeasurementContainer > WriteDecorKey_t
std::vector< SegLink_t > SegLinkVec_t
xAOD::UncalibratedMeasurementContainer PrdCont_t
Abrivation to call an uncalibrated measurement container.
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".
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
const Identifier & identify(const UncalibratedMeasurement *meas)
Returns the associated identifier from the muon measurement.
UncalibratedMeasurementContainer_v1 UncalibratedMeasurementContainer
Define the version of the uncalibrated measurement container.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.