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>
16
17namespace {
19 using SimHitLink_t = ElementLink<xAOD::MuonSimHitContainer>;
21
22 using PrdLinkVec_t = std::vector<PrdLink_t>;
23 using SimHitLinkVec_t = std::vector<SimHitLink_t>;
24 using SegLinkVec_t = std::vector<SegLink_t>;
25
26}
27
28namespace MuonR4 {
30 static const SG::ConstAccessor<SimHitLink_t> acc("simHitLink");
31 if (acc.isAvailable(prdHit)){
32 const SimHitLink_t& link{acc(prdHit)};
33 if (link.isValid()) {
34 return (*link);
35 }
36 }
37 return nullptr;
38 }
39
40 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const xAOD::MuonSegment& segment) {
41
42 static const SG::ConstAccessor<SimHitLinkVec_t> acc_simLink{"simHitLinks"};
43 static const SG::ConstAccessor<PrdLinkVec_t> acc_prdLink{"prdLinks"};
44 std::unordered_set<const xAOD::MuonSimHit*> hits{};
45 if (acc_simLink.isAvailable(segment)){
46 hits.reserve(acc_simLink(segment).size());
47 for (const SimHitLink_t& link : acc_simLink(segment)) {
48 if (link.isValid()) {
49 hits.insert(*link);
50 }
51 }
52 } else if (acc_prdLink.isAvailable(segment)){
53 for (const PrdLink_t& link : acc_prdLink(segment)) {
54 if(!link.isValid()){
55 continue;
56 }
57 const auto* prdHit = dynamic_cast<const xAOD::MuonMeasurement*>(*link);
58 if (!prdHit) {
59 continue;
60 }
61
62 std::vector<const xAOD::MuonMeasurement*> prds{prdHit};
63
64 // The segment links the eta & phi prds of a gas gap through a combined strip
65 // This is necessary e.g for sTGC as the simHitLink decoration takes places on the original prd container, whereas CombinedMuonStrip is built later in the segment conversion
66 if (const auto* cmb = dynamic_cast<const xAOD::CombinedMuonStrip*>(prdHit)) {
67 prds = {cmb->primaryStrip(), cmb->secondaryStrip()};
68 }
69
70 for (const xAOD::MuonMeasurement* prd : prds) {
71 const xAOD::MuonSimHit* hit = prd ? getTruthMatchedHit(*prd) : nullptr;
72 if (hit) {
73 hits.insert(hit);
74 }
75 }
76 }
77 }
78 return hits;
79 }
80
81 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const SpacePoint*>& spacePoints) {
82 std::unordered_set<const xAOD::MuonSimHit*> hits{};
83 for (const SpacePoint* sp : spacePoints) {
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
96 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const CalibratedSpacePoint*>& measurements) {
97 std::unordered_set<const xAOD::MuonSimHit*> hits{};
98 for (const CalibratedSpacePoint* meas : measurements) {
99 const SpacePoint* sp = meas->spacePoint();
100 if (!sp) continue;
101 const xAOD::MuonSimHit* primHit{getTruthMatchedHit(*sp->primaryMeasurement())};
102 const xAOD::MuonSimHit* secHit{sp->dimension() == 2 ? getTruthMatchedHit(*sp->secondaryMeasurement()) : nullptr};
103 if(primHit){
104 hits.insert(primHit);
105 }
106 if (secHit && secHit != primHit) {
107 hits.insert(secHit);
108 }
109 }
110 return hits;
111 }
112 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const Segment& segment) {
113 std::vector<const CalibratedSpacePoint*> calibSps{};
114 calibSps.reserve(segment.measurements().size());
115 std::ranges::transform(segment.measurements(), std::back_inserter(calibSps), [](const auto& meas){return meas.get();});
116 return getMatchingSimHits(calibSps);
117 }
118 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SpacePointBucket& bucket) {
119 std::vector<const SpacePoint*> spacePoints{};
120 spacePoints.reserve(bucket.size());
121 std::ranges::transform(bucket, std::back_inserter(spacePoints), [](const SpacePointBucket::value_type& sp){return sp.get();});
122 return getMatchingSimHits(spacePoints);
123 }
124 std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SegmentSeed& seed) {
125 return getMatchingSimHits(seed.getHitsInMax());
126 }
129 static const SG::ConstAccessor<TruthLink_t> acc{"truthParticleLink"};
130 if (acc.isAvailable(segment)){
131 const TruthLink_t& link {acc(segment)};
132 if (link.isValid()) {
133 return *link;
134 }
135 }
136 return nullptr;
137 }
139 static const SG::ConstAccessor<SegLink_t> acc{"truthSegmentLink"};
140 if (acc.isAvailable(segment)) {
141 const SegLink_t& link{acc(segment)};
142 if (link.isValid()){
143 return *link;
144 }
145 }
146 return nullptr;
147 }
148
150 static const SG::ConstAccessor<SegLink_t> acc{"truthSegmentLink"};
151 if (acc.isAvailable(hit)) {
152 const SegLink_t& link{acc(hit)};
153 if (link.isValid()){
154 return *link;
155 }
156 }
157 return nullptr;
158 }
161 return truthSeg ? getTruthMatchedParticle(*truthSeg) : nullptr;
162 }
163
164 std::vector<const xAOD::MuonSegment*> getTruthSegments(const xAOD::TruthParticle& truthMuon) {
165 static const SG::ConstAccessor<SegLinkVec_t> acc{"truthSegmentLinks"};
166 std::vector<const xAOD::MuonSegment*> segments{};
167
168 if (!acc.isAvailable(truthMuon)) {
169 return segments;
170 }
171 for (const SegLink_t& link : acc(truthMuon)) {
172 segments.emplace_back(*link);
173 }
174 return segments;
175 }
176}
177
178
bool hit(const Container &ids, int pdgId)
static Double_t sp
size_t size() const
Number of registered mappings.
ElementLink< xAOD::TruthParticleContainer > TruthLink_t
ElementLink< xAOD::MuonSegmentContainer > SegLink_t
std::vector< SegLink_t > SegLinkVec_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.
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
ElementLink< PrdCont_t > PrdLink_t
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.
std::vector< PrdLink_t > PrdLinkVec_t
ElementLink< xAOD::MuonSegmentContainer > SegLink_t
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:
CombinedMuonStrip_v1 CombinedMuonStrip