ATLAS Offline Software
Loading...
Searching...
No Matches
MsTrackTester.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4#include "MsTrackTester.h"
5
15
16#include "Acts/Definitions/Units.hpp"
17
18#include <format>
19
20using namespace MuonVal;
21using namespace MuonPRDTest;
22using namespace MuonR4;
23using namespace Acts::UnitLiterals;
24
25namespace {
26 constexpr double MeVtoGeV = 1.e-3;
27 constexpr double toDeg(const double rad) {
28 return rad / 1._degree;
29 }
30 using Location = MsTrackSeed::Location;
31
32}
33
34namespace MuonValR4 {
35 std::optional<MsTrackSeed> MsTrackTester::makeSeedFromTruth(const ActsTrk::GeometryContext& gctx,
36 const xAOD::TruthParticle& truthMuon) const {
37 std::vector<const xAOD::MuonSegment*> matchedSegs = MuonR4::getTruthSegments(truthMuon);
38 if (matchedSegs.empty() || toLayerIndex(matchedSegs.front()->chamberIndex()) == toLayerIndex(matchedSegs.back()->chamberIndex())) {
39 return std::nullopt;
40 }
41 ExpandedSector sector{matchedSegs[0]->position().phi()};
43 MsTrackSeed barrelSeed{Location::Barrel, sector};
44 MsTrackSeed endcapSeed{Location::Endcap, sector};
45 for (const xAOD::MuonSegment* seg : matchedSegs) {
46 barrelSeed.addSegment(seg);
47 endcapSeed.addSegment(seg);
48 }
49 barrelSeed.setPosition(matchedSegs[0]->position());
50 endcapSeed.setPosition(matchedSegs[0]->position());
51 const auto [barrelLength, barrelTheta] = calcSeedLength(gctx, barrelSeed);
52 const auto [endcapLength, endcapTheta] = calcSeedLength(gctx, endcapSeed);
53 ATH_MSG_VERBOSE(__func__<<"() "<<__LINE__<<" - Constructed new seed from truth muon wih pT:"
54 <<(truthMuon.pt()/ Gaudi::Units::GeV)<<" [GeV], eta: "<<truthMuon.eta()
55 <<", phi: "<<toDeg(truthMuon.phi())<<", q: "<<truthMuon.charge()
56 <<", matchedSeg: "<<matchedSegs.size()<< " barrel (L/theta): "<<barrelLength
57 <<"/"<<barrelTheta<<" - endcap (L/theta): "
58 <<endcapLength<<"/"<<endcapTheta<<"\n"<<barrelSeed);
59 if (barrelLength < 0 && endcapLength < 0) {
60 ATH_MSG_WARNING(__func__<<"() "<<__LINE__<<" - Invalid seed");
61 return std::nullopt;
62 }
63 return barrelLength < 0 || std::abs(endcapLength) < barrelLength
64 ? endcapSeed : barrelSeed;
65 }
66
67 std::pair<double, double> MsTrackTester::calcSeedLength(const ActsTrk::GeometryContext& gctx,
68 const MuonR4::MsTrackSeed& seed) const {
69 double maxL{-1.*Gaudi::Units::km}, minL{1.*Gaudi::Units::km},
70 maxTheta{-181.}, minTheta{181};
71 for (const xAOD::MuonSegment* seg : seed.segments()) {
72 const Amg::Vector2D projPos{m_seedingTool->expressOnCylinder(gctx.context(),*seg, seed.location(), seed.sector())};
73 if (!m_seedingTool->withinBounds(projPos, seed.location())) {
74 continue;
75 }
76 const double projected = projPos[seed.location()==Location::Barrel];
77 const double theta = seg->direction().theta();
78 minL = std::min(minL, projected);
79 maxL = std::max(maxL, projected);
80 minTheta = std::min(minTheta, toDeg(theta));
81 maxTheta = std::max(maxTheta, toDeg(theta));
82 }
83 return std::make_pair(maxL - minL, maxTheta - minTheta);
84 }
87 ATH_CHECK(m_truthKey.initialize(m_isMC));
88
89 ATH_CHECK(m_muonKey.initialize());
90 ATH_CHECK(m_msTrkSeedKey.initialize());
91 ATH_CHECK(m_recoSegmentKey.initialize());
92
93 ATH_CHECK(m_summaryTool.retrieve());
94 ATH_CHECK(m_seedingTool.retrieve());
95 ATH_CHECK(m_geoCtxKey.initialize());
96 ATH_CHECK(m_fieldCacheKey.initialize());
97
98 ATH_CHECK(m_legacyMuonKey.initialize(!m_legacyMuonKey.empty()));
99 ATH_CHECK(m_legacyTrackKey.initialize(!m_legacyMuonKey.empty()));
100 ATH_CHECK(m_legacySegmentKey.initialize(!m_legacyMuonKey.empty()));
101
102 ATH_CHECK(detStore()->retrieve(m_detMgr));
103
104 int evOpts{0};
105
106 m_recoSegs = std::make_unique<SegmentVariables>(m_tree, m_recoSegmentKey.key(), "Segments", msgLevel());
108 "Segments_passSeedQual",[this](const SG::AuxElement* aux){
109 const auto* seg = static_cast<const xAOD::MuonSegment*>(aux);
110 return m_segSelector->passSeedingQuality(Gaudi::Hive::currentContext(),
111 *seg); }));
113 "Segments_passTrackQual",[this](const SG::AuxElement* aux){
114 const auto* seg = static_cast<const xAOD::MuonSegment*>(aux);
115 return m_segSelector->passTrackQuality(Gaudi::Hive::currentContext(),
116 *seg);
117 }));
118
119
120 if (m_isMC) {
121 evOpts |= EventInfoBranch::isMC;
123 "Segments_truthSegLink",[this](const SG::AuxElement* aux){
124 const auto* seg = static_cast<const xAOD::MuonSegment*>(aux);
126 const unsigned linkIdx = truthS ? m_truthSegs->push_back(*truthS) : -1;
128 if (truthS) {
129 m_truthSegToRecoLink.push_back(linkIdx, m_recoSegs->push_back(*seg));
130 const xAOD::TruthParticle* truthMuon = MuonR4::getTruthMatchedParticle(*truthS);
131 if (truthMuon){
132 m_truthTrks->push_back(truthMuon);
133 m_truthMuRecoSegLinks[m_truthTrks->find(truthMuon)].push_back(m_recoSegs->push_back(*seg));
134 }
135 }
136 return linkIdx;
137 }));
138
139 m_truthSegs = std::make_unique<SegmentVariables>(m_tree, m_truthSegmentKey.key(), "TruthSegments", msgLevel());
140
142 "TruthSegments_truthLink",[this](const SG::AuxElement* aux){
143 const auto* seg = static_cast<const xAOD::MuonSegment*>(aux);
145 m_truthTrks->push_back(truthP);
146 unsigned short linkIdx = m_truthTrks->find(truthP);
147 return linkIdx;
148 }));
149 for (auto loc : {Location::Barrel, Location::Endcap}) {
151 std::format("TruthSegments_has{}Proj", loc), [loc, this](const SG::AuxElement* aux) -> unsigned short {
152
153 const auto* seg = static_cast<const xAOD::MuonSegment*>(aux);
154 const ActsTrk::GeometryContext* gctx{};
155 (void) SG::get(gctx, m_geoCtxKey, Gaudi::Hive::currentContext()).isSuccess();
156 ExpandedSector sector{seg->position().phi()};
157 const Amg::Vector2D projPos{m_seedingTool->expressOnCylinder(gctx->context(), *seg, loc, sector)};
158 return m_seedingTool->withinBounds(projPos, loc);
159 }));
160 }
161
162 m_tree.addBranch(m_truthSegs);
163
164 m_truthTrks = std::make_unique<IParticleFourMomBranch>(m_tree, "TruthMuons");
165 m_truthTrks->addVariable<int>(-1, "truthOrigin");
166 m_truthTrks->addVariable<int>(-1, "truthType");
168 m_truthTrks->addVariable(
170 std::vector<unsigned short>>>(m_tree,
171 std::format("{:}_truthSegLinks", m_truthTrks->name()), [&] (const xAOD::TruthParticle& p){
172 std::vector<unsigned short> idx{};
173 for (const xAOD::MuonSegment* truthSeg: getTruthSegments(p)){
174 idx.push_back(m_truthSegs->push_back(*truthSeg));
175 }
176 return idx;
177 }));
179 m_truthTrks->addVariable(
181 std::format("{:}_nTruthSegments", m_truthTrks->name()), [&] (const xAOD::TruthParticle& p) -> unsigned short {
182 return getTruthSegments(p).size();
183 }));
185 auto cone = std::make_shared<VectorBranch<float>>(m_tree,
186 std::format("{}_seedThetaCone", m_truthTrks->name()));
187 auto qTimesP = std::make_shared<VectorBranch<float>>(m_tree,
188 std::format("{}_qTimesP", m_truthTrks->name()));
189
190 m_tree.addBranch(cone);
191 m_tree.addBranch(qTimesP);
192 m_truthTrks->addVariable(
194 std::format("{:}_seedLength", m_truthTrks->name()), [cone, qTimesP, this] (const xAOD::TruthParticle& p) -> float {
195 const ActsTrk::GeometryContext* gctx{};
196 const AtlasFieldCacheCondObj* magCache{nullptr};
197 const EventContext& ctx{Gaudi::Hive::currentContext()};
198 (void) SG::get(gctx, m_geoCtxKey, ctx).isSuccess();
199 (void) SG::get(magCache, m_fieldCacheKey, ctx).isSuccess();
200 MagField::AtlasFieldCache magField{};
201 magCache->getInitializedCache(magField);
202 auto truthSeed = makeSeedFromTruth(*gctx, p);
203 if (!truthSeed) {
204 cone->push_back(-1);
205 qTimesP->push_back(0);
206 return -1.;
207 }
208 auto [length, theta] = calcSeedLength(*gctx, *truthSeed);
209 cone->push_back(theta);
210 qTimesP->push_back(m_seedingTool->estimateQtimesP(gctx->context(), *truthSeed, magField) / Gaudi::Units::GeV);
211
212 return length;
213 }));
214
215 m_tree.addBranch(m_truthTrks);
216 m_trkTruthLinks.emplace_back(m_truthSegmentKey, "truthParticleLink");
217 m_trkTruthLinks.emplace_back(m_truthKey, "truthSegmentLinks");
218 m_trkTruthLinks.emplace_back(m_recoSegmentKey, "truthSegmentLink");
219 m_trkTruthLinks.emplace_back(m_muonKey, "truthParticleLink");
220 }
221
222 m_tree.addBranch(m_recoSegs);
223 m_tree.addBranch(std::make_unique<EventInfoBranch>(m_tree, evOpts));
224
225 static const std::vector<std::string> trackSummaries{
226 // Inner
227 "innerSmallHits", "innerLargeHits", "innerSmallHoles", "innerLargeHoles",
228 "innerClosePrecisionHits",
229 // Middle
230 "middleSmallHits", "middleLargeHits", "middleSmallHoles",
231 "middleLargeHoles", "middleClosePrecisionHits",
232 // Outer
233 "outerSmallHits", "outerLargeHits", "outerSmallHoles", "outerLargeHoles",
234 "outerClosePrecisionHits",
235 // Extended
236 "extendedSmallHits", "extendedLargeHits", "extendedSmallHoles",
237 "extendedLargeHoles", "extendedClosePrecisionHits",
238 "innerTriggerEtaHits", "innerTriggerPhiHits",
239 "middleTriggerEtaHits", "middleTriggerPhiHits",
240 "outerTriggerEtaHits", "outerTriggerPhiHits",
241
242 "innerTriggerEtaHoles", "innerTriggerPhiHoles",
243 "middleTriggerEtaHoles", "middleTriggerPhiHoles",
244 "outerTriggerEtaHoles", "outerTriggerPhiHoles",
245 };
246 if(!m_legacyTrackKey.empty()) {
247 m_legacyTrks = std::make_unique<IParticleFourMomBranch>(m_tree, "LegacyMSTrks");
248 m_legacyTrks->addVariable(std::make_unique<TrackChi2Branch>(*m_legacyTrks));
249 if (m_isMC) {
250 BilateralLinkerBranch::connectCollections(m_legacyTrks, m_truthTrks, [](const xAOD::IParticle* trk){
251 return xAOD::TruthHelpers::getTruthParticle(*trk); }, "truth", "LegacyMS");
252 }
253 for (const auto& summary : trackSummaries) {
254 m_legacyTrks->addVariable<uint8_t>(-1, summary);
255 }
256 m_tree.addBranch(m_legacyTrks);
257 m_legacyRecoSegs = std::make_unique<SegmentVariables>(m_tree, m_legacySegmentKey.key(), "LegacyRecoSegments", msgLevel());
258 m_tree.addBranch(m_legacyRecoSegs);
259 }
260
261 m_seedSummary = std::make_shared<TrackSummaryModule>(m_tree, "MsTrkSeed", m_summaryTool.get());
262 m_muonTrks = std::make_shared<IParticleFourMomBranch>(m_tree, "ActsMuons");
263 m_muonTrks->addVariable(std::make_unique<TrackChi2Branch>(*m_muonTrks));
264 m_muonTrks->addVariable(std::make_unique<TrackFitIterBranch>(*m_muonTrks));
265
266 using TrkType = xAOD::Muon::TrackParticleType;
267 auto dumpTrack = [&](const std::string& trkName,
268 TrkType type) {
269 auto trkColl = std::make_shared<IParticleFourMomBranch>(m_tree, std::format("Acts{:}", trkName));
270 trkColl->addVariable(std::make_unique<TrackChi2Branch>(*trkColl));
271 trkColl->addVariable(std::make_unique<TrackFitIterBranch>(*trkColl));
272 trkColl->addVariable(std::make_unique<MaterialRecorderBranch>(*trkColl));
273 trkColl->addVariable(std::make_unique<EnergyLossBranch>(*trkColl));
274
275 trkColl->addVariable<float>("d0");
276 trkColl->addVariable<float>("z0");
277 for (const auto& summary : trackSummaries) {
278 trkColl->addVariable<uint8_t>(-1, summary);
279 }
280 m_muonTrks->addVariable(std::make_unique<MuonVal::LinkerBranch>(*m_muonTrks, trkColl,
281 [type](const xAOD::IParticle* muonP) -> const xAOD::IParticle* {
282 const auto* muon = dynamic_cast<const xAOD::Muon*>(muonP);
283 if (!muon) {
284 return nullptr;
285 }
286 return muon->trackParticle(type);
287 }, trkName));
288 };
289
290 dumpTrack("MsTrk", TrkType::MuonSpectrometerTrackParticle);
291 dumpTrack("MeTrk", TrkType::ExtrapolatedMuonSpectrometerTrackParticle);
292
293 m_muonTrks->addVariable<uint16_t>("allAuthors");
294 m_muonTrks->addVariable<uint16_t>("author");
296 m_muonTrks->addVariable(std::make_unique<GenericPartDecorBranch<xAOD::Muon,
297 std::vector<unsigned short>>>(m_tree,
298 std::format("{:}_segmentLinks", m_muonTrks->name()), [&] (const xAOD::Muon& p){
299 std::vector<unsigned short> idx{};
300 for (unsigned seg = 0 ; seg < p.nMuonSegments(); ++seg) {
301 idx.push_back(m_recoSegs->push_back(*p.muonSegment(seg)));
302 }
303 return idx;
304 }));
306 m_muonTrks->addVariable(std::make_unique<GenericPartDecorBranch<xAOD::Muon, unsigned short>>(m_tree,
307 std::format("{:}_seedLink", m_muonTrks->name()), [&] (const xAOD::Muon& p) -> unsigned short {
308 using enum xAOD::Muon::TrackParticleType;
309 const xAOD::TrackParticle* msTrack = p.trackParticle(MuonSpectrometerTrackParticle);
310 if (!msTrack) {
311 return -1;
312 }
313 auto actsTrk = ActsTrk::getActsTrack(*msTrack);
314 if (!actsTrk) {
315 THROW_EXCEPTION("Cannot find the associated ms track from the primary track");
316 }
317 return actsTrk->component<std::size_t>("parentSeed");
318 }));
319
320 if (m_isMC) {
321 BilateralLinkerBranch::connectCollections(m_muonTrks, m_truthTrks,
322 [](const xAOD::IParticle* trk) -> const xAOD::TruthParticle* {
324 }, "truth", "ActsMuon");
325 }
326
327 for (const auto& summary : trackSummaries) {
328 m_muonTrks->addVariable<uint8_t>(summary);
329 }
330 m_tree.addBranch(m_muonTrks);
331
332 m_tree.addBranch(m_seedSummary);
333
334 ATH_CHECK(m_trkTruthLinks.initialize());
335 ATH_CHECK(m_tree.init(this));
336 return StatusCode::SUCCESS;
337 }
338 StatusCode MsTrackTester::dumpLegacyTracks(const EventContext& ctx) {
339
340 //This for now is to be able to retrieve the matching between the legacy segments and tracks ...
341 const xAOD::MuonContainer* legacyMuons{nullptr};
342 ATH_CHECK(SG::get(legacyMuons, m_legacyMuonKey, ctx));
343
344 if (!legacyMuons) {
345 return StatusCode::SUCCESS;
346 }
347
348 for (const xAOD::Muon* muon : *legacyMuons) {
349 ATH_MSG_VERBOSE("iMuon " << muon->index() << " pT: "<<(muon->pt() *MeVtoGeV)<<" [GeV], eta: "
350 <<muon->eta() <<", phi: "<<toDeg(muon->phi())<<", q: "<<muon->charge()
351 <<", nSegments: "<<muon->nMuonSegments());
352 const xAOD::TrackParticle* track = muon->trackParticle(xAOD::Muon::TrackParticleType::MuonSpectrometerTrackParticle);
353 if (!track) {
354 continue;
355 }
356 m_summaryTool->copySummary(m_summaryTool->makeSummary(ctx, *track->track()), *track);
357 m_legacyTrks->push_back(track);
358 auto trkIdx = m_legacyTrks->find(track);
359 for (size_t s = 0; s < muon->nMuonSegments(); ++s) {
360 const xAOD::MuonSegment* segment = muon->muonSegment(s);
361 auto segIdx = m_legacyRecoSegs->push_back(*segment);
362 ATH_MSG_VERBOSE(std::format( "Legacy muon-segment link: segment {:} @{:}, eta: {:.2f}, phi {:.2f}",
363 printID(*segment), Amg::toString(segment->position()),
364 segment->direction().eta(), toDeg(segment->direction().phi())));
365 m_legacySegToTrkLinks[segIdx] = trkIdx;
366 }
367 }
368
369 //Dump also legacy segments
370 const xAOD::MuonSegmentContainer* legacyRecoSegs{nullptr};
371 ATH_CHECK(SG::get(legacyRecoSegs, m_legacySegmentKey, ctx));
372
373 if (legacyRecoSegs->size()) {
374 m_legacySegToTrkLinks[legacyRecoSegs->size()-1];
375 for (const xAOD::MuonSegment* seg : *legacyRecoSegs) {
376 //Store all segments
377 m_legacyRecoSegs->push_back(*seg);
378 }
379 }
380
381 const xAOD::TrackParticleContainer* legacyTrks{nullptr};
382 ATH_CHECK(SG::get(legacyTrks, m_legacyTrackKey, ctx));
383
384 for (const xAOD::TrackParticle* track : *legacyTrks) {
385 m_summaryTool->copySummary(m_summaryTool->makeSummary(ctx, *track->track()), *track);
386 m_legacyTrks->push_back(track);
387 }
388
389 return StatusCode::SUCCESS;
390 }
391 StatusCode MsTrackTester::dumpTruthContent(const EventContext& ctx) {
392 if (!m_isMC) {
393 return StatusCode::SUCCESS;
394 }
395 const xAOD::MuonSegmentContainer* truthSegs{nullptr};
396 ATH_CHECK(SG::get(truthSegs, m_truthSegmentKey, ctx));
397
398
399 for (const xAOD::MuonSegment* seg : *truthSegs) {
400 ATH_MSG_VERBOSE("Dump truth segment "<<printID(*seg)<<" @"<<
401 Amg::toString(seg->position())<<", eta: "<<seg->direction().eta()
402 <<", phi: "<<toDeg(seg->direction().phi()));
403 m_truthSegs->push_back(*seg);
404 }
405 if (truthSegs->size()) {
406 m_truthSegToRecoLink[truthSegs->size()-1];
407 }
408
409
410 const xAOD::TruthParticleContainer* truthMuons{nullptr};
411 ATH_CHECK(SG::get(truthMuons, m_truthKey, ctx));
412 const std::size_t nT = truthMuons->size() - 1;
413 if (!truthMuons->empty()) {
418 }
419
420 for (const xAOD::TruthParticle* truth : *truthMuons) {
421 ATH_MSG_DEBUG("Truth muon: pT: "<<(truth->pt() *MeVtoGeV)
422 <<", eta: "<<truth->eta()<<", phi: "<<toDeg(truth->phi())<<", q: "<<truth->charge());
423 m_truthTrks->push_back(*truth);
424 }
425
426 return StatusCode::SUCCESS;
427 }
428 StatusCode MsTrackTester::dumpRecoContent(const EventContext& ctx) {
429 const xAOD::MuonContainer* muons{nullptr};
430 ATH_CHECK(SG::get(muons, m_muonKey, ctx));
432 const xAOD::MuonSegmentContainer* recoSegments{nullptr};
433 ATH_CHECK(SG::get(recoSegments, m_recoSegmentKey, ctx));
434
435 const MuonR4::MsTrackSeedContainer* trkSeeds{nullptr};
436 ATH_CHECK(SG::get(trkSeeds, m_msTrkSeedKey, ctx));
437
438 const ActsTrk::GeometryContext* gctx{nullptr};
439 ATH_CHECK(SG::get(gctx, m_geoCtxKey, ctx));
440
441
442 const AtlasFieldCacheCondObj* magCache{nullptr};
443 ATH_CHECK(SG::get(magCache, m_fieldCacheKey, ctx));
444
445 MagField::AtlasFieldCache magField{};
446 magCache->getInitializedCache(magField);
447 std::unordered_map<const xAOD::TruthParticle*,
448 std::vector<unsigned>> truthToSeedMatchCounter{};
449
450 if (!trkSeeds->empty()) {
451 m_seedTruthLink[trkSeeds->size() -1];
452 }
453
454 for (const MuonR4::MsTrackSeed& seed : *trkSeeds) {
455 unsigned int seedIdx = m_seedPos.size();
456 m_seedPos += seed.position();
457 m_seedType+= Acts::toUnderlying(seed.location());
458 m_seedSector += seed.sector().sector();
459 m_seedSummary->push_back(ctx, seed);
460
461 auto startPars = m_seedingTool->estimateStartParameters(ctx, seed);
462 if (startPars.ok()) {
463 m_seedDir += (*startPars).direction();
464 } else {
465 m_seedDir += Amg::Vector3D::UnitZ();
466 }
467 // m_seedDir
468 ATH_MSG_VERBOSE(" Dump new seed: "<<seed);
469 for (const xAOD::MuonSegment* seg : seed.segments()){
470 m_seedRecoSegMatch[seedIdx].push_back(m_recoSegs->push_back(*seg));
471 if (const xAOD::MuonSegment* truthSeg = MuonR4::getMatchedTruthSegment(*seg);
472 truthSeg != nullptr) {
473 std::vector<unsigned>& matchCounter = truthToSeedMatchCounter[MuonR4::getTruthMatchedParticle(*truthSeg)];
474 if (seedIdx >= matchCounter.size()) {
475 matchCounter.resize(seedIdx +1);
476 }
477 ++matchCounter[seedIdx];
478 }
479 }
480 const auto[seedLength, theta] = calcSeedLength(*gctx, seed);
481 m_seedLength+= seedLength;
483 m_seedQP += m_seedingTool->estimateQtimesP(gctx->context(), seed, magField) / Gaudi::Units::GeV;
484 m_seedGood += startPars.ok();
485 }
487 for (auto& [truthMuon, matches] : truthToSeedMatchCounter) {
488 const unsigned tIndex = m_truthTrks->find(truthMuon);
489 if (tIndex >= m_truthTrks->size()) {
490 continue;
491 }
493 while (std::count_if(matches.begin(), matches.end(),
494 [](const unsigned nMatched){
495 return nMatched > 0;
496 })) {
497 auto bestMatch = std::ranges::max_element(matches);
498 const std::size_t seedIdx = std::distance(matches.begin(), bestMatch);
499 m_truthMuToSeedIdx[tIndex].push_back(seedIdx);
500
501 m_seedTruthLink[seedIdx] = tIndex;
502 m_truthMuToSeedCounter[tIndex].push_back(*bestMatch);
503 (*bestMatch) = 0;
504 }
505 }
506
507 for (const xAOD::Muon* muon : *muons) {
508 m_muonTrks->push_back(muon);
509 }
510
511 for (const xAOD::MuonSegment* seg : *recoSegments) {
512 m_recoSegs->push_back(*seg);
513 }
514
515 return StatusCode::SUCCESS;
516 }
517 StatusCode MsTrackTester::execute(const EventContext& ctx) {
521
522 ATH_CHECK(m_tree.fill(ctx));
523 return StatusCode::SUCCESS;
524 }
526 ATH_CHECK(m_tree.write());
527 return StatusCode::SUCCESS;
528 }
529}
Scalar theta() const
theta method
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
double length(const pvec &v)
if(pathvar)
Handle class for reading from StoreGate.
Acts::GeometryContext context() const
const ServiceHandle< StoreGateSvc > & detStore() const
void getInitializedCache(MagField::AtlasFieldCache &cache) const
get B field cache for evaluation as a function of 2-d or 3-d position.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
Local cache for magnetic field (based on MagFieldServices/AtlasFieldSvcTLS.h).
void addSegment(const xAOD::MuonSegment *seg)
Append a segment to the seed.
Location
Enum defining whether the seed is made in the endcap / barrel.
Definition MsTrackSeed.h:25
void setPosition(Amg::Vector3D &&pos)
set the seed's position
ToolHandle< MuonR4::ITrackSeedingDiagnosticsTool > m_seedingTool
The track seeding tool to construct the seed candidates and to estimate the initial parameters.
const MuonGMR4::MuonDetectorManager * m_detMgr
std::optional< MuonR4::MsTrackSeed > makeSeedFromTruth(const ActsTrk::GeometryContext &gctx, const xAOD::TruthParticle &truthMuon) const
Construct MS track seed from the truth associated segments.
ToolHandle< MuonR4::ITrackSummaryTool > m_summaryTool
Hit summary tool.
StatusCode dumpLegacyTracks(const EventContext &ctx)
Dumps the legacy containers to the TTree.
SegmentKey_t m_legacySegmentKey
Legacy segment container.
MuonVal::VectorBranch< unsigned short > & m_legacySegToTrkLinks
Link of the legacy track to the legacy segment.
ParticleBranchPtr_t m_truthTrks
MuonVal::VectorBranch< int > & m_seedSector
Sector of the seed, even center, odd overlap regions, for details see:
MuonVal::VectorBranch< float > & m_seedThetaCone
Maximum angular difference between the segments part of the seed.
ParticleBranchPtr_t m_legacyTrks
Output branches of the legacy MS tracks.
SegmentBranchPtr_t m_truthSegs
SegmentBranchPtr_t m_legacyRecoSegs
MuonVal::MatrixBranch< unsigned short > & m_truthMuRecoSegLinks
Links from the truth muon to the segments.
MuonVal::MatrixBranch< unsigned short > & m_truthMuToSeedIdx
Links to all MsTrkSeeds that could be matched to the truthMuon, i.e.
TrackKey_t m_legacyTrackKey
Legacy track reconstruction chain.
ActsTrk::GeoContextReadKey_t m_geoCtxKey
Dependency on the geometry alignment.
StatusCode execute(const EventContext &ctx) override final
Execute method.
MuonVal::VectorBranch< char > & m_seedType
Is the seed in the encap or in the barrel chambers.
StatusCode dumpRecoContent(const EventContext &ctx)
Dump the reconstructed information.
SG::ReadHandleKey< xAOD::TruthParticleContainer > m_truthKey
Key to the truth particle collection.
Gaudi::Property< bool > m_isMC
ParticleBranchPtr_t m_muonTrks
Stored muon information from the Acts muon reco chain.
MuonVal::MatrixBranch< unsigned short > & m_truthSegToRecoLink
Link of the truth segments to the matchin reco segments.
SG::ReadCondHandleKey< AtlasFieldCacheCondObj > m_fieldCacheKey
Dependency on the magnetic field.
SegmentBranchPtr_t m_recoSegs
StatusCode dumpTruthContent(const EventContext &ctx)
Dump truth information.
SG::ReadHandleKey< MuonR4::MsTrackSeedContainer > m_msTrkSeedKey
Temporary container write handle to push the seeds to store gate for later efficiency analysis.
StatusCode initialize() override final
MuonVal::MatrixBranch< unsigned short > & m_seedRecoSegMatch
Link of the track seed to the building segment.
MuonVal::VectorBranch< float > & m_seedQP
Estimated momentum times charge from the track seed.
MuonVal::MatrixBranch< unsigned short > & m_truthMuToSeedCounter
Number of matched segments in the seed.
MuonVal::ThreeVectorBranch m_seedPos
Simple seed information.
MuonKey_t m_legacyMuonKey
Legacy muons.
MuonVal::VectorBranch< float > & m_seedLength
Maximum separation between the segments on the reference plane.
MuonVal::UnitThreeVectorBranch m_seedDir
Seed direction vector.
ToolHandle< MuonR4::ISegmentSelectionTool > m_segSelector
Selection tool to quantify the segment candidate quality.
SegmentKey_t m_recoSegmentKey
Primary segment container.
MuonVal::MuonTesterTree m_tree
SegmentKey_t m_truthSegmentKey
Segment from the truth hits.
MuonVal::VectorBranch< char > & m_seedGood
Does the seeding tool construct valid parameters from the seed.
StatusCode finalize() override final
std::shared_ptr< TrackSummaryModule > m_seedSummary
Hit summary on the track seed.
MuonVal::VectorBranch< unsigned short > & m_seedTruthLink
Link to the truth muon.
std::pair< double, double > calcSeedLength(const ActsTrk::GeometryContext &gctx, const MuonR4::MsTrackSeed &seed) const
Calculate the length of the seed and the theta deflection angle The length is defined as the spread o...
MuonKey_t m_muonKey
Dependency on the R4 muon container.
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...
Class providing the definition of the 4-vector interface.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
std::optional< ActsTrk::TrackContainer::ConstTrackProxy > getActsTrack(const xAOD::TrackParticle &trkPart)
Return the proxy to the Acts track from which the track particle was made frome.
Definition Decoration.cxx:9
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
Eigen::Matrix< double, 2, 1 > Vector2D
constexpr float MeVtoGeV
ID3PD * m_tree
Pointer to the ID3PD object used.
for(size_t i=0;i< m_blockFillers.size();i++)
Fill one block.
This header ties the generic definitions in this package.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
std::vector< MsTrackSeed > MsTrackSeedContainer
Definition MsTrackSeed.h:69
std::string printID(const xAOD::MuonSegment &seg)
Print the chamber ID of a segment, e.g.
std::vector< const xAOD::MuonSegment * > getTruthSegments(const xAOD::TruthParticle &truthMuon)
Returns the segments associated to the truth muon.
const xAOD::MuonSegment * getMatchedTruthSegment(const xAOD::MuonSegment &segment)
Returns the truth-matched segment.
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
LayerIndex toLayerIndex(ChIndex index)
convert ChIndex into LayerIndex
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".
Muon_v1 Muon
Reference the current persistent version:
setWord1 uint16_t
MuonContainer_v1 MuonContainer
Definition of the current "Muon container version".
MuonSegment_v1 MuonSegment
Reference the current persistent version:
TruthParticleContainer_v1 TruthParticleContainer
Declare the latest version of the truth particle container.
#define THROW_EXCEPTION(MESSAGE)
Definition throwExcept.h:10