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 auto* prdHit = dynamic_cast<const xAOD::MuonMeasurement*>(*link);
56 if (!prdHit) {
57 continue;
58 }
59 const xAOD::MuonSimHit* hit = getTruthMatchedHit(*prdHit);
60 if (hit){
61 hits.insert(hit);
62 }
63 }
64 }
65 return hits;
66 }
67
68 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const SpacePoint*>& spacePoints) {
69 std::unordered_set<const xAOD::MuonSimHit*> hits{};
70 for (const SpacePoint* sp : spacePoints) {
71 const xAOD::MuonSimHit* primHit{getTruthMatchedHit(*sp->primaryMeasurement())};
72 const xAOD::MuonSimHit* secHit{sp->dimension() == 2 ? getTruthMatchedHit(*sp->secondaryMeasurement()) : nullptr};
73 if(primHit){
74 hits.insert(primHit);
75 }
76 if (secHit && secHit != primHit) {
77 hits.insert(secHit);
78 }
79 }
80 return hits;
81 }
82
83 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const CalibratedSpacePoint*>& measurements) {
84 std::unordered_set<const xAOD::MuonSimHit*> hits{};
85 for (const CalibratedSpacePoint* meas : measurements) {
86 const SpacePoint* sp = meas->spacePoint();
87 if (!sp) continue;
88 const xAOD::MuonSimHit* primHit{getTruthMatchedHit(*sp->primaryMeasurement())};
89 const xAOD::MuonSimHit* secHit{sp->dimension() == 2 ? getTruthMatchedHit(*sp->secondaryMeasurement()) : nullptr};
90 if(primHit){
91 hits.insert(primHit);
92 }
93 if (secHit && secHit != primHit) {
94 hits.insert(secHit);
95 }
96 }
97 return hits;
98 }
99 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const Segment& segment) {
100 std::vector<const CalibratedSpacePoint*> calibSps{};
101 calibSps.reserve(segment.measurements().size());
102 std::ranges::transform(segment.measurements(), std::back_inserter(calibSps), [](const auto& meas){return meas.get();});
103 return getMatchingSimHits(calibSps);
104 }
105 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SpacePointBucket& bucket) {
106 std::vector<const SpacePoint*> spacePoints{};
107 spacePoints.reserve(bucket.size());
108 std::ranges::transform(bucket, std::back_inserter(spacePoints), [](const SpacePointBucket::value_type& sp){return sp.get();});
109 return getMatchingSimHits(spacePoints);
110 }
111 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SegmentSeed& seed) {
112 return getMatchingSimHits(seed.getHitsInMax());
113 }
116 static const SG::ConstAccessor<TruthLink_t> acc{"truthParticleLink"};
117 if (acc.isAvailable(segment)){
118 const TruthLink_t& link {acc(segment)};
119 if (link.isValid()) {
120 return *link;
121 }
122 }
123 return nullptr;
124 }
126 static const SG::ConstAccessor<SegLink_t> acc{"truthSegmentLink"};
127 if (acc.isAvailable(segment)) {
128 const SegLink_t& link{acc(segment)};
129 if (link.isValid()){
130 return *link;
131 }
132 }
133 return nullptr;
134 }
135
137 static const SG::ConstAccessor<SegLink_t> acc{"truthSegmentLink"};
138 if (acc.isAvailable(hit)) {
139 const SegLink_t& link{acc(hit)};
140 if (link.isValid()){
141 return *link;
142 }
143 }
144 return nullptr;
145 }
147 const xAOD::MuonSegment* truthSeg = getMatchedTruthSegment(hit);
148 return truthSeg ? getTruthMatchedParticle(*truthSeg) : nullptr;
149 }
150
151 std::vector<const xAOD::MuonSegment*> getTruthSegments(const xAOD::TruthParticle& truthMuon) {
152 static const SG::ConstAccessor<SegLinkVec_t> acc{"truthSegmentLinks"};
153 std::vector<const xAOD::MuonSegment*> segments{};
154
155 if (!acc.isAvailable(truthMuon)) {
156 return segments;
157 }
158 for (const SegLink_t& link : acc(truthMuon)) {
159 segments.emplace_back(*link);
160 }
161 return segments;
162 }
163}
164
165
static Double_t sp
size_t size() const
Number of registered mappings.
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.
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::MuonMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
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.
MuonMeasurement_v1 MuonMeasurement
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: