ATLAS Offline Software
Loading...
Searching...
No Matches
MuonRecoChainTester.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4// Framework includes
6
15
16using namespace MuonVal;
17using namespace MuonPRDTest;
18
19namespace{
21 static const SG::ConstAccessor<SegLink_t> acc_truthSegLink{"truthSegmentLink"};
22}
23
24
25namespace MuonValR4{
27 int evOpts{0};
28 if (m_isMC) evOpts |= EventInfoBranch::isMC;
29 m_tree.addBranch(std::make_unique<EventInfoBranch>(m_tree, evOpts));
30
31 auto initSegBranch = [this](const std::string& sgKey, const std::string& outCollName) {
32 if (sgKey.empty()){
33 return;
34 }
35 auto newColl = std::make_unique<SegmentVariables>(m_tree, sgKey, outCollName, msgLevel());
36 if (m_isMC) {
37 newColl->addVariable(std::make_unique<MuonVal::GenericAuxDecorationBranch<unsigned short>>(m_tree,
38 std::format("{:}_truthLink", outCollName),[this](const SG::AuxElement* aux){
39 const auto* seg = static_cast<const xAOD::MuonSegment*>(aux);
41 m_truthTrks->push_back(truthP);
42 return m_truthTrks->find(truthP);
43 }));
44 newColl->addVariable(std::make_unique<MuonVal::GenericAuxDecorationBranch<unsigned short>>(m_tree,
45 std::format("{:}_truthSegLink", outCollName),[this](const SG::AuxElement* aux) -> unsigned short{
46 if (acc_truthSegLink.isAvailable(*aux) && acc_truthSegLink(*aux).isValid()) {
47 const xAOD::MuonSegment* truthSeg {*acc_truthSegLink(*aux)};
48 return m_truthSegs->push_back(*truthSeg);
49 }
50 return -1;
51 }));
52 }
53 m_tree.addBranch(std::move(newColl));
54 };
55
56 initSegBranch(m_legacySegmentKey, "LegacySegments");
57 initSegBranch(m_r4PatternSegmentKey, "HoughSegments");
58 initSegBranch(m_segmentKeyR4, "SegmentsR4");
59
61 if (m_isMC) {
62 m_truthSegs = std::make_unique<SegmentVariables>(m_tree, m_truthSegmentKey.key(), "TruthSegments", msgLevel());
63 m_tree.addBranch(m_truthSegs);
64 }
65
66 ATH_CHECK(m_legacyTrackKey.initialize());
67 ATH_CHECK(m_TrackKeyHoughR4.initialize(m_r4PatternSegmentKey.value().size()));
68 ATH_CHECK(m_TrackKeyR4.initialize());
69 ATH_CHECK(m_spacePointKey.initialize());
70 ATH_CHECK(m_truthKey.initialize(m_isMC));
71
72 m_legacyTrks = std::make_unique<IParticleFourMomBranch>(m_tree, "LegacyMSTrks");
73 m_legacyTrks->addVariable(std::make_unique<TrackChi2Branch>(*m_legacyTrks));
74
75 if (!m_TrackKeyHoughR4.empty()){
76 m_TrksHoughR4 = std::make_unique<IParticleFourMomBranch>(m_tree, "HoughMSTrks");
77 m_TrksHoughR4->addVariable(std::make_unique<TrackChi2Branch>(*m_TrksHoughR4));
78 m_tree.addBranch(m_TrksHoughR4);
79
80 }
81 m_TrksSegmentR4 = std::make_unique<IParticleFourMomBranch>(m_tree, "MSTrksR4");
82 m_TrksSegmentR4->addVariable(std::make_unique<TrackChi2Branch>(*m_TrksSegmentR4));
83
84 m_tree.addBranch(m_legacyTrks);
85 m_tree.addBranch(m_TrksSegmentR4);
86
87 if (m_isMC) {
88 m_trkTruthLinks.emplace_back(m_legacyTrackKey, "truthParticleLink");
89 if (!m_TrackKeyHoughR4.empty()) {
90 m_trkTruthLinks.emplace_back(m_TrackKeyHoughR4, "truthParticleLink");
91 m_trkTruthLinks.emplace_back(std::format("{:}.truthParticleLink", m_r4PatternSegmentKey.value()));
93 return xAOD::TruthHelpers::getTruthParticle(*trk); }, "truth", "HoughMS");
94 }
95 m_trkTruthLinks.emplace_back(m_TrackKeyR4, "truthParticleLink");
96 m_trkTruthLinks.emplace_back(m_truthSegmentKey, "truthParticleLink");
97
98 m_trkTruthLinks.emplace_back(std::format("{:}.truthParticleLink", m_segmentKeyR4.value()));
99
100 m_truthTrks = std::make_unique<IParticleFourMomBranch>(m_tree, "TruthMuons");
101 m_truthTrks->addVariable<int>(-1, "truthOrigin");
102 m_truthTrks->addVariable<int>(-1, "truthType");
103
105 return xAOD::TruthHelpers::getTruthParticle(*trk); }, "truth", "LegacyMS");
107 return xAOD::TruthHelpers::getTruthParticle(*trk); }, "truth", "MSTrksR4");
108 m_tree.addBranch(m_truthTrks);
109 }
110
111 ATH_CHECK(m_trkTruthLinks.initialize());
112 ATH_CHECK(m_tree.init(this));
113 return StatusCode::SUCCESS;
114 }
116 const StIdx station,
117 MuonVal::ScalarBranch<uint16_t>& outBranch) const{
118 outBranch = std::count_if(spContainer.begin(), spContainer.end(),
119 [station](const MuonR4::SpacePointBucket* bucket){
120 return Muon::MuonStationIndex::toStationIndex(bucket->msSector()->chamberIndex()) == station;
121 });
122 }
123
124 StatusCode MuonRecoChainTester::execute(const EventContext& ctx) {
125
126 const xAOD::TrackParticleContainer* legacyTrks{nullptr};
127 ATH_CHECK(SG::get(legacyTrks, m_legacyTrackKey, ctx));
128
129 const xAOD::TrackParticleContainer* trksFromHoughR4{nullptr};
130 ATH_CHECK(SG::get(trksFromHoughR4, m_TrackKeyHoughR4, ctx));
131
132 const xAOD::TrackParticleContainer* trksR4{nullptr};
133 ATH_CHECK(SG::get(trksR4, m_TrackKeyR4, ctx));
134
135 ATH_MSG_DEBUG("Fill reconstructed tracks from "<<m_legacyTrackKey.fullKey());
136 for (const xAOD::TrackParticle* trk : *legacyTrks) {
137 m_legacyTrks->push_back(trk);
138 }
139 ATH_MSG_DEBUG("Fill reconstructed tracks from "<<m_TrackKeyR4.fullKey());
140 for (const xAOD::TrackParticle* trk : *trksR4) {
141 m_TrksSegmentR4->push_back(trk);
142 }
143 ATH_MSG_DEBUG("Fill reconstructed tracks from "<<m_TrackKeyHoughR4.fullKey());
144 if (trksFromHoughR4) {
145 for (const xAOD::TrackParticle* trk : *trksFromHoughR4) {
146 m_TrksHoughR4->push_back(trk);
147 }
148 }
149 if (!m_truthKey.empty()) {
150 const xAOD::TruthParticleContainer* truthCont{nullptr};
151 ATH_CHECK(SG::get(truthCont, m_truthKey, ctx));
152 for (const xAOD::TruthParticle* truth : *truthCont) {
153 m_truthTrks->push_back(truth);
154 }
155 const xAOD::MuonSegmentContainer* truthSeg{nullptr};
156 ATH_CHECK(SG::get(truthSeg, m_truthSegmentKey, ctx));
157 for (const xAOD::MuonSegment* seg : *truthSeg) {
158 m_truthSegs->push_back(*seg);
159 }
160 }
162 const MuonR4::SpacePointContainer* spContainer{nullptr};
163 ATH_CHECK(SG::get(spContainer, m_spacePointKey, ctx));
164 m_nBucket = spContainer->size();
165
166 fillBucketsPerStation(*spContainer, StIdx::BI, m_nBucketBI);
167 fillBucketsPerStation(*spContainer, StIdx::BM, m_nBucketBM);
168 fillBucketsPerStation(*spContainer, StIdx::BO, m_nBucketBO);
169 fillBucketsPerStation(*spContainer, StIdx::BE, m_nBucketBE);
170
171 fillBucketsPerStation(*spContainer, StIdx::EI, m_nBucketEI);
172 fillBucketsPerStation(*spContainer, StIdx::EM, m_nBucketEM);
173 fillBucketsPerStation(*spContainer, StIdx::EO, m_nBucketEO);
174 fillBucketsPerStation(*spContainer, StIdx::EE, m_nBucketEE);
175
176
177 if(!m_tree.fill(ctx)) {
178 return StatusCode::FAILURE;
179 }
180 return StatusCode::SUCCESS;
181 }
183 ATH_CHECK(m_tree.write());
184 return StatusCode::SUCCESS;
185 }
186}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_DEBUG(x)
DataVector adapter that acts like it holds const pointers.
Handle class for reading from StoreGate.
ElementLink< xAOD::MuonSegmentContainer > SegLink_t
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
size_type size() const noexcept
Returns the number of elements in the collection.
: The muon space point bucket represents a collection of points that will bre processed together in t...
Gaudi::Property< std::string > m_segmentKeyR4
Segments made from the R4 segment maker.
MuonVal::ScalarBranch< uint16_t > & m_nBucketEE
number of buckets in the EE
SG::ReadHandleKey< MuonR4::SpacePointContainer > m_spacePointKey
Key to the space point container.
MuonVal::ScalarBranch< uint16_t > & m_nBucketBM
number of buckets in the BM
SegmentKey_t m_truthSegmentKey
Segment from the truth hits.
virtual StatusCode execute(const EventContext &ctx) override
Execute method.
void fillBucketsPerStation(const MuonR4::SpacePointContainer &spContainer, const StIdx station, MuonVal::ScalarBranch< uint16_t > &outBranch) const
Counts how many buckets are in a particular station.
MuonVal::ScalarBranch< uint16_t > & m_nBucket
number of buckets in the entire MS
MuonVal::ScalarBranch< uint16_t > & m_nBucketBO
number of buckets in the BO
Gaudi::Property< std::string > m_legacySegmentKey
Keys to the segment collections.
SG::ReadDecorHandleKeyArray< SG::AuxVectorBase > m_trkTruthLinks
Decoration dependency to the MS truth track links.
MuonVal::ScalarBranch< uint16_t > & m_nBucketBI
number of buckets in the BI
Muon::MuonStationIndex::StIndex StIdx
virtual StatusCode initialize() override
MuonVal::ScalarBranch< uint16_t > & m_nBucketEO
number of buckets in the BO
virtual StatusCode finalize() override
Gaudi::Property< std::string > m_r4PatternSegmentKey
Segments seeded from the R4 pattern but made with the legacy segment maker.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthKey
Key to the truth particle collection.
MuonVal::ScalarBranch< uint16_t > & m_nBucketEI
number of buckets in the BI
MuonVal::ScalarBranch< uint16_t > & m_nBucketEM
number of buckets in the BM
MuonVal::ScalarBranch< uint16_t > & m_nBucketBE
number of buckets in the BE
static bool connectCollections(ParticleBranch_ptr primColl, ParticleBranch_ptr secondColl, Linker_t fromPrimToSec, const std::string &altPrimName="", const std::string &altSecName="")
@ isMC
Flag determining whether the branch is simulation.
Generic branch object where the information is evaluated by a std::function instead reading it from t...
Helper class to provide constant type-safe access to aux data.
Class providing the definition of the 4-vector interface.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
DataVector< SpacePointBucket > SpacePointContainer
Abrivation of the space point container type.
Lightweight algorithm to read xAOD MDT sim hits and (fast-digitised) drift circles from SG and fill a...
Class to store array like branches into the n-tuples.
Definition HitValAlg.cxx:19
AuxElement(SG::AuxVectorData *container, size_t index)
Base class for elements of a container that can have aux data.
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).
MuonSegmentContainer_v1 MuonSegmentContainer
Definition of the current "MuonSegment container version".
TrackParticle_v1 TrackParticle
Reference the current persistent version:
TruthParticle_v1 TruthParticle
Typedef to implementation.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
MuonSegment_v1 MuonSegment
Reference the current persistent version:
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.