ATLAS Offline Software
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 
15 namespace {
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 
26 namespace 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  const xAOD::MuonSimHit* hit = getTruthMatchedHit(**link);
53  if (hit){
54  hits.insert(hit);
55  }
56  }
57  }
58  return hits;
59  }
60 
61  std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const SpacePoint*>& spacePoints) {
62  std::unordered_set<const xAOD::MuonSimHit*> hits{};
63  for (const SpacePoint* sp : spacePoints) {
64  const xAOD::MuonSimHit* primHit{getTruthMatchedHit(*sp->primaryMeasurement())};
65  const xAOD::MuonSimHit* secHit{sp->dimension() == 2 ? getTruthMatchedHit(*sp->secondaryMeasurement()) : nullptr};
66  if(primHit){
67  hits.insert(primHit);
68  }
69  if (secHit && secHit != primHit) {
70  hits.insert(secHit);
71  }
72  }
73  return hits;
74  }
75 
76  std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const std::vector<const CalibratedSpacePoint*>& measurements) {
77  std::unordered_set<const xAOD::MuonSimHit*> hits{};
78  for (const CalibratedSpacePoint* meas : measurements) {
79  const SpacePoint* sp = meas->spacePoint();
80  if (!sp) continue;
82  const xAOD::MuonSimHit* secHit{sp->dimension() == 2 ? getTruthMatchedHit(*sp->secondaryMeasurement()) : nullptr};
83  if(primHit){
84  hits.insert(primHit);
85  }
86  if (secHit && secHit != primHit) {
87  hits.insert(secHit);
88  }
89  }
90  return hits;
91  }
92  std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const Segment& segment) {
93  std::vector<const CalibratedSpacePoint*> calibSps{};
94  calibSps.reserve(segment.measurements().size());
95  std::ranges::transform(segment.measurements(), std::back_inserter(calibSps), [](const auto& meas){return meas.get();});
96  return getMatchingSimHits(calibSps);
97  }
98  std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SpacePointBucket& bucket) {
99  std::vector<const SpacePoint*> spacePoints{};
100  spacePoints.reserve(bucket.size());
101  std::ranges::transform(bucket, std::back_inserter(spacePoints), [](const SpacePointBucket::value_type& sp){return sp.get();});
103  }
104  std::unordered_set<const xAOD::MuonSimHit*> getMatchingSimHits(const SegmentSeed& seed) {
105  return getMatchingSimHits(seed.getHitsInMax());
106  }
109  static const SG::ConstAccessor<TruthLink_t> acc{"truthParticleLink"};
110  if (acc.isAvailable(segment)){
111  const TruthLink_t& link {acc(segment)};
112  if (link.isValid()) {
113  return *link;
114  }
115  }
116  return nullptr;
117  }
119  static const SG::ConstAccessor<SegLink_t> acc{"truthSegmentLink"};
120  if (acc.isAvailable(segment)) {
121  const SegLink_t& link{acc(segment)};
122  if (link.isValid()){
123  return *link;
124  }
125  }
126  return nullptr;
127  }
128  std::vector<const xAOD::MuonSegment*> getTruthSegments(const xAOD::TruthParticle& truthMuon) {
129  static const SG::ConstAccessor<SegLinkVec_t> acc{"truthSegmentLinks"};
130  std::vector<const xAOD::MuonSegment*> segments{};
131 
132  if (!acc.isAvailable(truthMuon)) {
133  return segments;
134  }
135  for (const SegLink_t& link : acc(truthMuon)) {
136  segments.emplace_back(*link);
137  }
138  return segments;
139  }
140 }
141 
142 
MuonSimHitHelpers.h
xAOD::MuonSimHit_v1
Definition: MuonSimHit_v1.h:18
TRTCalib_Extractor.hits
hits
Definition: TRTCalib_Extractor.py:35
MuonR4::SpacePointBucket
: The muon space point bucket represents a collection of points that will bre processed together in t...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePointContainer.h:21
MuonR4::getTruthMatchedParticle
const xAOD::TruthParticle * getTruthMatchedParticle(const xAOD::MuonSegment &segment)
Returns the particle truth-matched to the segment.
Definition: MuonSimHitHelpers.cxx:107
TruthParticleContainer.h
MuonR4::PrdLink_t
ElementLink< PrdCont_t > PrdLink_t
Abrivation to call the link to an element inside an uncalibrated measurement container.
Definition: xAODSegmentCnvAlg.cxx:24
MuonR4::Segment
Placeholder for what will later be the muon segment EDM representation.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:19
MuonR4::Segment::measurements
const MeasVec & measurements() const
Returns the associated measurements.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonPatternEvent/MuonPatternEvent/Segment.h:49
xAOD::MuonSegment_v1
Class describing a MuonSegment.
Definition: MuonSegment_v1.h:33
MuonR4::getMatchedTruthSegment
const xAOD::MuonSegment * getMatchedTruthSegment(const xAOD::MuonSegment &segment)
Returns the truth-matched segment.
Definition: MuonSimHitHelpers.cxx:118
SpacePoint.h
MuonR4::SpacePoint::secondaryMeasurement
const xAOD::UncalibratedMeasurement * secondaryMeasurement() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:78
SG::ConstAccessor
Helper class to provide constant type-safe access to aux data.
Definition: ConstAccessor.h:55
MuonSegmentContainer.h
MuonR4::SpacePoint::primaryMeasurement
const xAOD::UncalibratedMeasurement * primaryMeasurement() const
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:75
CalibratedSpacePoint.h
python.setupRTTAlg.size
int size
Definition: setupRTTAlg.py:39
MuonR4::getTruthSegments
std::vector< const xAOD::MuonSegment * > getTruthSegments(const xAOD::TruthParticle &truthMuon)
Returns the segments associated to the truth muon.
Definition: MuonSimHitHelpers.cxx:128
xAOD::UncalibratedMeasurement_v1
Definition: UncalibratedMeasurement_v1.h:13
xAOD::TruthParticle_v1
Class describing a truth particle in the MC record.
Definition: TruthParticle_v1.h:37
UncalibratedMeasurementContainer.h
MuonR4::PrdLinkVec_t
std::vector< PrdLink_t > PrdLinkVec_t
Abrivation of a collection of Prd links.
Definition: xAODSegmentCnvAlg.cxx:26
Amg::transform
Amg::Vector3D transform(Amg::Vector3D &v, Amg::Transform3D &tr)
Transform a point from a Trasformation3D.
Definition: GeoPrimitivesHelpers.h:156
AthenaPoolTestRead.acc
acc
Definition: AthenaPoolTestRead.py:16
MuonSimHitContainer.h
MuonR4::SegLink_t
ElementLink< MuonR4::SegmentContainer > SegLink_t
Abrivation of the link to the reco segment container
Definition: xAODSegmentCnvAlg.cxx:19
F600IntegrationConfig.spacePoints
spacePoints
Definition: F600IntegrationConfig.py:122
MuonR4::SpacePoint
The muon space point is the combination of two uncalibrated measurements one of them measures the eta...
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/MuonSpacePoint/SpacePoint.h:24
python.TruthMuonD3PDObject.truthMuon
truthMuon
Definition: TruthMuonD3PDObject.py:51
MuonR4
This header ties the generic definitions in this package.
Definition: HoughEventData.h:16
MuonR4::SegLinkVec_t
std::vector< SegLink_t > SegLinkVec_t
Definition: MeasurementMarkerAlg.cxx:15
MuonR4::CalibratedSpacePoint
The calibrated Space point is created during the calibration process.
Definition: CalibratedSpacePoint.h:14
MuonR4::SpacePoint::dimension
unsigned dimension() const
Is the space point a 1D or combined 2D measurement.
Definition: MuonSpectrometer/MuonPhaseII/Event/MuonSpacePoint/src/SpacePoint.cxx:107
MuonR4::SegmentSeed
Representation of a segment seed (a fully processed hough maximum) produced by the hough transform.
Definition: SegmentSeed.h:14
MuonR4::getTruthMatchedHit
const xAOD::MuonSimHit * getTruthMatchedHit(const xAOD::UncalibratedMeasurement &prdHit)
Returns the MuonSimHit, if there's any, matched to the uncalibrated muon measurement.
Definition: MuonSimHitHelpers.cxx:27
Segment.h
MuonR4::getMatchingSimHits
std::unordered_set< const xAOD::MuonSimHit * > getMatchingSimHits(const xAOD::MuonSegment &segment)
: Returns all sim hits matched to a xAOD::MuonSegment
Definition: MuonSimHitHelpers.cxx:38