ATLAS Offline Software
Loading...
Searching...
No Matches
TrackingHelpers.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
5
12
13namespace{
15 using PrdLinkVec_t = std::vector<PrdLink_t>;
16 static const SG::ConstAccessor<PrdLinkVec_t> acc_prdLinks{"prdLinks"};
17 static const SG::ConstAccessor<std::vector<char>> acc_prdState{"prdState"};
18}
19
20namespace MuonR4{
21
22 std::string printID(const xAOD::MuonSegment& seg) {
23 using namespace Muon::MuonStationIndex;
24 return std::format("{:}{:}{:}{:}", chName(seg.chamberIndex()),
25 std::abs(seg.etaIndex()),
26 seg.etaIndex() > 0 ? 'A' : 'C',
27 seg.sector());
28 }
29 std::string printSegment(const xAOD::MuonSegment& seg) {
30 std::ostringstream oss;
31 using namespace SegmentFit;
32 oss <<"Segment "<<printID(seg)
33 <<", Dir theta/phi: "<<(seg.direction().theta() /Gaudi::Units::degree)
34 <<" / "<<(seg.direction().phi() /Gaudi::Units::degree)
35 <<", Pos theta/phi: "<<(seg.position().theta() / Gaudi::Units::degree)
36 <<" / "<<(seg.position().phi() / Gaudi::Units::degree)
37 <<", R: "<<Acts::fastHypot(seg.x(), seg.y()) <<", Z: "<<seg.z()
38 <<", chi2: "<<(seg.chiSquared() / std::max(seg.numberDoF(), 1.f))
39 <<", localPars: "<<toString(localSegmentPars(seg))
40 <<", nPrec: "<<static_cast<int>(seg.nPrecisionHits())
41 <<", nPhi: "<<static_cast<int>(seg.nPhiLayers())
42 <<", nTrigEta: "<<static_cast<int>(seg.nTrigEtaLayers());
43 return oss.str();
44 }
47 static const SG::ConstAccessor<SegLink_t> acc{"parentSegment"};
48 if (acc.isAvailable(seg)){
49 const SegLink_t& link{acc(seg)};
50 if (link.isValid()){
51 return *link;
52 }
53 }
54 return nullptr;
55 }
56
57 std::size_t nMeasurements(const xAOD::MuonSegment& segment) {
58 return acc_prdLinks.isAvailable(segment) ? acc_prdLinks(segment).size() : 0;
59 }
61 const std::size_t n) {
62 if (!acc_prdLinks.isAvailable(segment)) {
63 return nullptr;
64 }
65 assert(n < nMeasurements(segment));
66 const PrdLink_t& link{acc_prdLinks(segment)[n]};
67 return link.isValid() ? *link : nullptr;
68 }
70 const std::size_t n) {
71 if(!acc_prdState.isAvailable(segment)) {
72 return false;
73 }
74 assert (n < acc_prdState(segment).size());
75 return acc_prdState(segment)[n] != Acts::toUnderlying(CalibratedSpacePoint::State::Valid);
76 }
77 std::vector<const xAOD::UncalibratedMeasurement*> collectMeasurements(const xAOD::MuonSegment& segment,
78 bool skipOutlier) {
79 std::vector<const xAOD::UncalibratedMeasurement*> out{};
80 const PrdLinkVec_t& links{acc_prdLinks(segment)};
81 out.reserve(links.size());
82 for (std::size_t l = 0 ; l < links.size(); ++l) {
83 const PrdLink_t& link{links[l]};
84 if (!skipOutlier || !isOutlierMeasurement(segment, l)) {
85 out.push_back(*link);
86 }
87 }
88 return out;
89 }
90 Acts::GeometryIdentifier volumeId(const Acts::Surface& surface) {
91 return surface.geometryId().withSensitive(0).withBoundary(0);
92 }
93
95 const bool skipOutlier) {
96 const std::size_t n = nMeasurements(segment);
97 for (std::size_t i = 0; i < n ; ++i) {
98 if (!skipOutlier || !isOutlierMeasurement(segment, i)) {
99 return getMeasurement(segment, i);
100 }
101 }
102 return nullptr;
103 }
104
105 Amg::Vector3D atFirstSurface(const Acts::GeometryContext& gctx,
106 const xAOD::MuonSegment& segment,
107 const bool skipOutlier) {
108 const xAOD::UncalibratedMeasurement* meas{firstMeasurement(segment, skipOutlier)};
109 assert(meas != nullptr);
110 const Acts::Surface& surface = xAOD::muonSurface(meas);
111
112 const Acts::MultiIntersection isect = surface.intersect(gctx,
113 segment.position(),
114 segment.direction(),
115 Acts::BoundaryTolerance::Infinite());
116 return isect.closest().position();
117 }
118
120 const xAOD::IParticle* b) const {
121
122 if (const float dPt = a->pt() - b->pt();
123 std::abs(dPt) > std::numeric_limits<float>::epsilon()) {
124 return dPt < 0.;
125 }
126 if (const float dEta = a->eta() - b->eta();
127 std::abs(dEta) > std::numeric_limits<float>::epsilon()) {
128 return dEta < 0.;
129 }
130 const float dPhi = xAOD::P4Helpers::deltaPhi(a, b);
131 return dPhi < 0.;
132 }
133}
Scalar phi() const
phi method
Scalar theta() const
theta method
static Double_t a
size_t size() const
Number of registered mappings.
Placeholder for what will later be the muon segment EDM representation.
Helper class to provide constant type-safe access to aux data.
Class providing the definition of the 4-vector interface.
float y() const
Returns the x position.
std::uint8_t nTrigEtaLayers() const
Returns the number of trigger eta hits.
float numberDoF() const
Returns the numberDoF.
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
float chiSquared() const
std::uint8_t nPrecisionHits() const
Returns the number of precision hits.
::Muon::MuonStationIndex::ChIndex chamberIndex() const
Returns the chamber index.
Amg::Vector3D position() const
Returns the position as Amg::Vector.
int etaIndex() const
Returns the eta index, which corresponds to stationEta in the offline identifiers (and the ).
std::uint8_t nPhiLayers() const
Returns the number of trigger phi hits.
float z() const
Returns the y position.
Eigen::Matrix< double, 3, 1 > Vector3D
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
std::string toString(const Parameters &pars)
Dumps the parameters into a string with labels in front of each number.
This header ties the generic definitions in this package.
std::string printID(const xAOD::MuonSegment &seg)
Print the chamber ID of a segment, e.g.
ElementLink< PrdCont_t > PrdLink_t
const xAOD::UncalibratedMeasurement * getMeasurement(const xAOD::MuonSegment &segment, const std::size_t n)
Returns the n-th uncalibrated measurement.
std::string printSegment(const xAOD::MuonSegment &seg)
Print the details of a segment.
std::size_t nMeasurements(const xAOD::MuonSegment &segment)
Returns the number of associated Uncalibrated measurements.
std::vector< const xAOD::UncalibratedMeasurement * > collectMeasurements(const xAOD::MuonSegment &segment, bool skipOutlier=true)
Helper function to extract the measurements from the segment.
Acts::GeometryIdentifier volumeId(const Acts::Surface &surface)
Returns the identifier of the volume in which the surface is embedded.
bool isOutlierMeasurement(const xAOD::MuonSegment &segment, const std::size_t n)
Returns whether the n-the uncalibrated measurement is an outlier.
const xAOD::UncalibratedMeasurement * firstMeasurement(const xAOD::MuonSegment &segment, const bool skipOutlier=true)
Retrieves the first measurement associated with the segment.
Amg::Vector3D atFirstSurface(const Acts::GeometryContext &gctx, const xAOD::MuonSegment &segment, const bool skipOutlier=true)
Expresses the segment position on the surface of the first measurement.
std::vector< PrdLink_t > PrdLinkVec_t
ElementLink< xAOD::MuonSegmentContainer > SegLink_t
const Segment * detailedSegment(const xAOD::MuonSegment &seg)
Helper function to navigate from the xAOD::MuonSegment to the MuonR4::Segment.
const std::string & chName(ChIndex index)
convert ChIndex into a string
double deltaPhi(double phiA, double phiB)
delta Phi in range [-pi,pi[
UncalibratedMeasurement_v1 UncalibratedMeasurement
Define the version of the uncalibrated measurement class.
MuonSegment_v1 MuonSegment
Reference the current persistent version:
const Acts::Surface & muonSurface(const UncalibratedMeasurement *meas)
Returns the associated Acts surface to the measurement.
bool operator()(const xAOD::IParticle *a, const xAOD::IParticle *b) const