ATLAS Offline Software
Loading...
Searching...
No Matches
MuonSimHitHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
13#include <AthLinks/ElementLink.h>
14
15namespace {
17 using SimHitLink_t = ElementLink<xAOD::MuonSimHitContainer>;
19
20 using PrdLinkVec_t = std::vector<PrdLink_t>;
21 using SimHitLinkVec_t = std::vector<SimHitLink_t>;
22 using SegLinkVec_t = std::vector<SegLink_t>;
23
24}
25
26namespace MuonR4 {
28 static const SG::ConstAccessor<SimHitLink_t> acc("simHitLink");
29 if (acc.isAvailable(prdHit)){
30 const SimHitLink_t& link{acc(prdHit)};
31 if (link.isValid()) {
32 return (*link);
33 }
34 }
35 return nullptr;
36 }
37
38 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const xAOD::MuonSegment& segment) {
39
40 static const SG::ConstAccessor<SimHitLinkVec_t> acc_simLink{"simHitLinks"};
41 static const SG::ConstAccessor<PrdLinkVec_t> acc_prdLink{"prdLinks"};
42 std::unordered_set<const xAOD::MuonSimHit*> hits{};
43 if (acc_simLink.isAvailable(segment)){
44 hits.reserve(acc_simLink(segment).size());
45 for (const SimHitLink_t& link : acc_simLink(segment)) {
46 if (link.isValid()) {
47 hits.insert(*link);
48 }
49 }
50 } else if (acc_prdLink.isAvailable(segment)){
51 for (const PrdLink_t& link : acc_prdLink(segment)) {
52 if(!link.isValid()){
53 continue;
54 };
55 const xAOD::MuonSimHit* hit = getTruthMatchedHit(**link);
56 if (hit){
57 hits.insert(hit);
58 }
59 }
60 }
61 return hits;
62 }
63
64 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const SpacePoint*>& spacePoints) {
65 std::unordered_set<const xAOD::MuonSimHit*> hits{};
66 for (const SpacePoint* sp : spacePoints) {
67 const xAOD::MuonSimHit* primHit{getTruthMatchedHit(*sp->primaryMeasurement())};
68 const xAOD::MuonSimHit* secHit{sp->dimension() == 2 ? getTruthMatchedHit(*sp->secondaryMeasurement()) : nullptr};
69 if(primHit){
70 hits.insert(primHit);
71 }
72 if (secHit && secHit != primHit) {
73 hits.insert(secHit);
74 }
75 }
76 return hits;
77 }
78
79 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const CalibratedSpacePoint*>& measurements) {
80 std::unordered_set<const xAOD::MuonSimHit*> hits{};
81 for (const CalibratedSpacePoint* meas : measurements) {
82 const SpacePoint* sp = meas->spacePoint();
83 if (!sp) continue;
84 const xAOD::MuonSimHit* primHit{getTruthMatchedHit(*sp->primaryMeasurement())};
85 const xAOD::MuonSimHit* secHit{sp->dimension() == 2 ? getTruthMatchedHit(*sp->secondaryMeasurement()) : nullptr};
86 if(primHit){
87 hits.insert(primHit);
88 }
89 if (secHit && secHit != primHit) {
90 hits.insert(secHit);
91 }
92 }
93 return hits;
94 }
95 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const Segment& segment) {
96 std::vector<const CalibratedSpacePoint*> calibSps{};
97 calibSps.reserve(segment.measurements().size());
98 std::ranges::transform(segment.measurements(), std::back_inserter(calibSps), [](const auto& meas){return meas.get();});
99 return getMatchingSimHits(calibSps);
100 }
101 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SpacePointBucket& bucket) {
102 std::vector<const SpacePoint*> spacePoints{};
103 spacePoints.reserve(bucket.size());
104 std::ranges::transform(bucket, std::back_inserter(spacePoints), [](const SpacePointBucket::value_type& sp){return sp.get();});
105 return getMatchingSimHits(spacePoints);
106 }
107 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SegmentSeed& seed) {
108 return getMatchingSimHits(seed.getHitsInMax());
109 }
112 static const SG::ConstAccessor<TruthLink_t> acc{"truthParticleLink"};
113 if (acc.isAvailable(segment)){
114 const TruthLink_t& link {acc(segment)};
115 if (link.isValid()) {
116 return *link;
117 }
118 }
119 return nullptr;
120 }
122 static const SG::ConstAccessor<SegLink_t> acc{"truthSegmentLink"};
123 if (acc.isAvailable(segment)) {
124 const SegLink_t& link{acc(segment)};
125 if (link.isValid()){
126 return *link;
127 }
128 }
129 return nullptr;
130 }
131 std::vector<const xAOD::MuonSegment*> getTruthSegments(const xAOD::TruthParticle& truthMuon) {
132 static const SG::ConstAccessor<SegLinkVec_t> acc{"truthSegmentLinks"};
133 std::vector<const xAOD::MuonSegment*> segments{};
134
135 if (!acc.isAvailable(truthMuon)) {
136 return segments;
137 }
138 for (const SegLink_t& link : acc(truthMuon)) {
139 segments.emplace_back(*link);
140 }
141 return segments;
142 }
143}
144
145
static Double_t sp
ElementLink< xAOD::TruthParticleContainer > TruthLink_t
The calibrated Space point is created during the calibration process.
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition SegmentSeed.h:14
Placeholder for what will later be the muon segment EDM representation.
const MeasVec & measurements() const
Returns the associated measurements.
: The muon space point bucket represents a collection of points that will bre processed together in t...
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
Helper class to provide constant type-safe access to aux data.
bool isAvailable(const ELT &e) const
Test to see if this variable exists in the store.
This header ties the generic definitions in this package.
std::vector< PrdLink_t > PrdLinkVec_t
Abrivation of a collection of Prd links.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::UncalibratedMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
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.
ElementLink< MuonR4::SegmentContainer > SegLink_t
Abrivation of the link to the reco segment container.
std::vector< SegLink_t > SegLinkVec_t
ElementLink< PrdCont_t > PrdLink_t
Abrivation to call the link to an element inside an uncalibrated measurement container.
MuonSimHit_v1 MuonSimHit
Defined the version of the MuonSimHit.
Definition MuonSimHit.h:12
TruthParticle_v1 TruthParticle
Typedef to implementation.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.