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
16
17using namespace MuonVal;
18using namespace MuonPRDTest;
19
20namespace{
22 static const SG::ConstAccessor<SegLink_t> acc_truthSegLink{"truthSegmentLink"};
23}
24
25
26namespace MuonValR4{
28 int evOpts{0};
29 if (m_isMC) evOpts |= EventInfoBranch::isMC;
30 m_tree.addBranch(std::make_unique<EventInfoBranch>(m_tree, evOpts));
31
32 auto initSegBranch = [this](const std::string& sgKey, const std::string& outCollName) {
33 if (sgKey.empty()){
34 return;
35 }
36 auto newColl = std::make_unique<SegmentVariables>(m_tree, sgKey, outCollName, msgLevel());
37 if (m_isMC) {
38 newColl->addVariable(std::make_unique<MuonVal::GenericAuxDecorationBranch<unsigned short>>(m_tree,
39 std::format("{:}_truthLink", outCollName),[this](const SG::AuxElement* aux){
40 const auto* seg = static_cast<const xAOD::MuonSegment*>(aux);
42 m_truthTrks->push_back(truthP);
43 return m_truthTrks->find(truthP);
44 }));
45 newColl->addVariable(std::make_unique<MuonVal::GenericAuxDecorationBranch<unsigned short>>(m_tree,
46 std::format("{:}_truthSegLink", outCollName),[this](const SG::AuxElement* aux) -> unsigned short{
47 if (acc_truthSegLink.isAvailable(*aux) && acc_truthSegLink(*aux).isValid()) {
48 const xAOD::MuonSegment* truthSeg {*acc_truthSegLink(*aux)};
49 return m_truthSegs->push_back(*truthSeg);
50 }
51 return -1;
52 }));
53 }
54 m_tree.addBranch(std::move(newColl));
55 };
56
57 initSegBranch(m_legacySegmentKey, "LegacySegments");
58 initSegBranch(m_r4PatternSegmentKey, "HoughSegments");
59 initSegBranch(m_segmentKeyR4, "SegmentsR4");
60
62 if (m_isMC) {
63 m_truthSegs = std::make_unique<SegmentVariables>(m_tree, m_truthSegmentKey.key(), "TruthSegments", msgLevel());
64 m_tree.addBranch(m_truthSegs);
65 }
66
67 ATH_CHECK(m_legacyTrackKey.initialize());
68 ATH_CHECK(m_TrackKeyHoughR4.initialize(m_r4PatternSegmentKey.value().size()));
69 ATH_CHECK(m_TrackKeyR4.initialize());
70 ATH_CHECK(m_spacePointKey.initialize());
71 ATH_CHECK(m_truthKey.initialize(m_isMC));
72
73 m_legacyTrks = std::make_unique<IParticleFourMomBranch>(m_tree, "LegacyMSTrks");
74 m_legacyTrks->addVariable(std::make_unique<TrackChi2Branch>(*m_legacyTrks));
75
76 if (!m_TrackKeyHoughR4.empty()){
77 m_TrksHoughR4 = std::make_unique<IParticleFourMomBranch>(m_tree, "HoughMSTrks");
78 m_TrksHoughR4->addVariable(std::make_unique<TrackChi2Branch>(*m_TrksHoughR4));
79 m_tree.addBranch(m_TrksHoughR4);
80
81 }
82 m_TrksSegmentR4 = std::make_unique<IParticleFourMomBranch>(m_tree, "MSTrksR4");
83 m_TrksSegmentR4->addVariable(std::make_unique<TrackChi2Branch>(*m_TrksSegmentR4));
84
85 m_tree.addBranch(m_legacyTrks);
86 m_tree.addBranch(m_TrksSegmentR4);
87
88 if (m_isMC) {
89 m_trkTruthLinks.emplace_back(m_legacyTrackKey, "truthParticleLink");
90 if (!m_TrackKeyHoughR4.empty()) {
91 m_trkTruthLinks.emplace_back(m_TrackKeyHoughR4, "truthParticleLink");
92 m_trkTruthLinks.emplace_back(std::format("{:}.truthParticleLink", m_r4PatternSegmentKey.value()));
94 return xAOD::TruthHelpers::getTruthParticle(*trk); }, "truth", "HoughMS");
95 }
96 m_trkTruthLinks.emplace_back(m_TrackKeyR4, "truthParticleLink");
97 m_trkTruthLinks.emplace_back(m_truthSegmentKey, "truthParticleLink");
98
99 m_trkTruthLinks.emplace_back(std::format("{:}.truthParticleLink", m_segmentKeyR4.value()));
100
101 m_truthTrks = std::make_unique<IParticleFourMomBranch>(m_tree, "TruthMuons");
103 return xAOD::TruthHelpers::getTruthParticle(*trk); }, "truth", "LegacyMS");
105 return xAOD::TruthHelpers::getTruthParticle(*trk); }, "truth", "MSTrksR4");
106 m_tree.addBranch(m_truthTrks);
107 }
108
109 ATH_CHECK(m_trkTruthLinks.initialize());
110 ATH_CHECK(m_tree.init(this));
111 return StatusCode::SUCCESS;
112 }
114 const StIdx station,
115 MuonVal::ScalarBranch<uint16_t>& outBranch) const{
116 outBranch = std::count_if(spContainer.begin(), spContainer.end(),
117 [station](const MuonR4::SpacePointBucket* bucket){
118 return Muon::MuonStationIndex::toStationIndex(bucket->msSector()->chamberIndex()) == station;
119 });
120 }
121
123
124 const EventContext& ctx{Gaudi::Hive::currentContext()};
125 const xAOD::TrackParticleContainer* legacyTrks{nullptr};
126 ATH_CHECK(SG::get(legacyTrks, m_legacyTrackKey, ctx));
127
128 const xAOD::TrackParticleContainer* trksFromHoughR4{nullptr};
129 ATH_CHECK(SG::get(trksFromHoughR4, m_TrackKeyHoughR4, ctx));
130
131 const xAOD::TrackParticleContainer* trksR4{nullptr};
132 ATH_CHECK(SG::get(trksR4, m_TrackKeyR4, ctx));
133
134 ATH_MSG_DEBUG("Fill reconstructed tracks from "<<m_legacyTrackKey.fullKey());
135 for (const xAOD::TrackParticle* trk : *legacyTrks) {
136 m_legacyTrks->push_back(trk);
137 }
138 ATH_MSG_DEBUG("Fill reconstructed tracks from "<<m_TrackKeyR4.fullKey());
139 for (const xAOD::TrackParticle* trk : *trksR4) {
140 m_TrksSegmentR4->push_back(trk);
141 }
142 ATH_MSG_DEBUG("Fill reconstructed tracks from "<<m_TrackKeyHoughR4.fullKey());
143 if (trksFromHoughR4) {
144 for (const xAOD::TrackParticle* trk : *trksFromHoughR4) {
145 m_TrksHoughR4->push_back(trk);
146 }
147 }
148 if (!m_truthKey.empty()) {
149 const xAOD::TruthParticleContainer* truthCont{nullptr};
150 ATH_CHECK(SG::get(truthCont, m_truthKey, ctx));
151 for (const xAOD::TruthParticle* truth : *truthCont) {
152 m_truthTrks->push_back(truth);
153 }
154 const xAOD::MuonSegmentContainer* truthSeg{nullptr};
155 ATH_CHECK(SG::get(truthSeg, m_truthSegmentKey, ctx));
156 for (const xAOD::MuonSegment* seg : *truthSeg) {
157 m_truthSegs->push_back(*seg);
158 }
159 }
161 const MuonR4::SpacePointContainer* spContainer{nullptr};
162 ATH_CHECK(SG::get(spContainer, m_spacePointKey, ctx));
163 m_nBucket = spContainer->size();
164
165 fillBucketsPerStation(*spContainer, StIdx::BI, m_nBucketBI);
166 fillBucketsPerStation(*spContainer, StIdx::BM, m_nBucketBM);
167 fillBucketsPerStation(*spContainer, StIdx::BO, m_nBucketBO);
168 fillBucketsPerStation(*spContainer, StIdx::BE, m_nBucketBE);
169
170 fillBucketsPerStation(*spContainer, StIdx::EI, m_nBucketEI);
171 fillBucketsPerStation(*spContainer, StIdx::EM, m_nBucketEM);
172 fillBucketsPerStation(*spContainer, StIdx::EO, m_nBucketEO);
173 fillBucketsPerStation(*spContainer, StIdx::EE, m_nBucketEE);
174
175
176 if(!m_tree.fill(ctx)) {
177 return StatusCode::FAILURE;
178 }
179 return StatusCode::SUCCESS;
180 }
182 ATH_CHECK(m_tree.write());
183 return StatusCode::SUCCESS;
184 }
185}
#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.
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() override
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...
Base class for elements of a container that can have aux data.
Definition AuxElement.h:483
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.
ElementLink< MuonR4::SegmentContainer > SegLink_t
Abrivation of the link to the reco segment container.
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
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.