ATLAS Offline Software
Loading...
Searching...
No Matches
SegmentFitterEventData.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
5
10#include <GaudiKernel/PhysicalConstants.h>
11
12#include "Acts/Surfaces/PlaneSurface.hpp"
13#include "Acts/Definitions/Units.hpp"
14#include "Acts/Utilities/UnitVectors.hpp"
15
16
17#include <sstream>
18#include <format>
19using namespace Acts;
20using namespace Acts::UnitLiterals;
21
22namespace {
23 constexpr double straightQoverP = 1. / 20._TeV;
24 constexpr double inDeg(const double rad) { return rad / 1._degree; }
25}
26
27namespace MuonR4{
28 double houghTanBeta(const Amg::Vector3D& v){
29 constexpr double eps = std::numeric_limits<float>::epsilon();
30 return v.y() / ( std::abs(v.z()) > eps ? v.z() : eps);
31 }
32 double houghTanAlpha(const Amg::Vector3D& v){
33 constexpr double eps = std::numeric_limits<float>::epsilon();
34 return v.x() / ( std::abs(v.z()) > eps ? v.z() : eps);
35 }
36 namespace SegmentFit {
37 constexpr std::size_t N = Acts::toUnderlying(ParamDefs::nPars);
38
39 inline std::optional<Acts::BoundMatrix>
41 std::optional<Covariance>&& localCov,
42 const Amg::Transform3D& localToGlobal) {
43 if (!localCov) {
44 return std::nullopt;
45 }
46 const SeedingAux::Line_t line{locSegPars};
47
48 Acts::Matrix<3,2> basisTrf{};
49 basisTrf.block<3,1>(0,1) = line.gradient(SeedingAux::Line_t::ParIndex::theta);
50 basisTrf.block<3,1>(0,0) = line.gradient(SeedingAux::Line_t::ParIndex::phi);
51
52 BoundMatrix jacobian{BoundMatrix::Identity()};
53 jacobian.block<2,2>(Acts::eBoundPhi, Acts::eBoundPhi) = basisTrf.transpose() *
54 localToGlobal.linear() *
55 basisTrf;
56 BoundMatrix cov{BoundMatrix::Identity()};
57 cov.block<N,N>(0,0) = std::move(*localCov);
58 BoundMatrix translator{BoundMatrix::Zero()};
59 translator( Acts::toUnderlying(ParamDefs::x0), Acts::eBoundLoc0) =
60 translator( Acts::toUnderlying(ParamDefs::y0), Acts::eBoundLoc1) =
61 translator( Acts::toUnderlying(ParamDefs::theta), Acts::eBoundTheta) =
62 translator( Acts::toUnderlying(ParamDefs::phi), Acts::eBoundPhi) =
63 translator( Acts::toUnderlying(ParamDefs::t0), Acts::eBoundTime) =
64 translator( Acts::toUnderlying(ParamDefs::nPars), Acts::eBoundQOverP) = 1.;
65 translator = jacobian * translator;
66 return translator.transpose() * cov * translator;
67 }
68
69 std::pair<Amg::Vector3D, Amg::Vector3D> makeLine(const Parameters& pars) {
70 using enum ParamDefs;
71 return std::make_pair(Amg::Vector3D{pars[Acts::toUnderlying(x0)],
72 pars[Acts::toUnderlying(y0)],0.},
73 Acts::makeDirectionFromPhiTheta(pars[Acts::toUnderlying(phi)],
74 pars[Acts::toUnderlying(theta)]));
75 }
77 static const xAOD::PosAccessor<N> acc{"localSegPars"};
78 Parameters segPars{};
79 for (std::size_t p =0 ; p < N; ++p) {
80 segPars[p] = acc(seg)[p];
81 }
82 return segPars;
83 }
84 std::optional<Covariance> localSegmentCov(const xAOD::MuonSegment& seg) {
85 static const xAOD::PosAccessor<Acts::sumUpToN(N)> acc{"localSegCov"};
86 if (!acc.isAvailable(seg)) {
87 return std::nullopt;
88 }
89 Covariance cov{Covariance::Zero()};
90 const auto& covVec{acc(seg)};
91 for (std::size_t i = 0 ; i < covVec.size(); ++i) {
92 const auto [p, p1] = Acts::symMatIndices<N>(i);
93 cov(p,p1) = cov(p1,p) = covVec[i];
94 }
95 return cov;
96 }
97
98 Parameters localSegmentPars(const Acts::GeometryContext& tgContext,
99 const Segment& segment) {
100 return localSegmentPars(*tgContext.get<const ActsTrk::GeometryContext*>(), segment);
101 }
102
104 const Segment& segment) {
105 Parameters pars{};
106 const Amg::Transform3D globToLoc = segment.msSector()->globalToLocalTransform(gctx);
107 const Amg::Vector3D locPos = globToLoc * segment.position();
108 const Amg::Vector3D locDir = globToLoc.linear() * segment.direction();
109 pars[Acts::toUnderlying(ParamDefs::x0)] = locPos.x();
110 pars[Acts::toUnderlying(ParamDefs::y0)] = locPos.y();
111 pars[Acts::toUnderlying(ParamDefs::theta)] = locDir.theta();
112 pars[Acts::toUnderlying(ParamDefs::phi)] = locDir.phi();
113 pars[Acts::toUnderlying(ParamDefs::t0)] = segment.segementT0();
114 return pars;
115 }
116
117 std::string makeLabel(const Parameters&pars) {
118 std::stringstream sstr{};
119 sstr<<std::format("x_{{0}}={:.2f}", pars[Acts::toUnderlying(ParamDefs::x0)])<<", ";
120 sstr<<std::format("y_{{0}}={:.2f}", pars[Acts::toUnderlying(ParamDefs::y0)])<<", ";
121 sstr<<std::format("#theta={:.2f}^{{#circ}}",inDeg(pars[Acts::toUnderlying(ParamDefs::theta)]))<<", ";
122 sstr<<std::format("#phi={:.2f}^{{#circ}}", inDeg(pars[Acts::toUnderlying(ParamDefs::phi)]))<<", ";
123 sstr<<std::format("t_{{0}}={:.1f}", pars[Acts::toUnderlying(ParamDefs::t0)]);
124 return sstr.str();
125 }
126 std::string toString(const Parameters& pars) {
127 std::stringstream sstr{};
128 sstr<< std::format("{}={:.2f}, ",toString(ParamDefs::x0), pars[Acts::toUnderlying(ParamDefs::x0)]);
129 sstr<< std::format("{}={:.2f}, ",toString(ParamDefs::y0), pars[Acts::toUnderlying(ParamDefs::y0)]);
130 sstr<< std::format("{}={:.2f}, ",toString(ParamDefs::theta), inDeg(pars[Acts::toUnderlying(ParamDefs::theta)]));
131 sstr<< std::format("{}={:.2f}, ",toString(ParamDefs::phi), inDeg(pars[Acts::toUnderlying(ParamDefs::phi)]));
132 sstr<< std::format("{}={:.2f}",toString(ParamDefs::t0), pars[Acts::toUnderlying(ParamDefs::t0)]);
133 return sstr.str();
134 }
135 std::string toString(const ParamDefs a) {
136 return SeedingAux::parName(a);
137 }
138
139 Acts::BoundTrackParameters boundSegmentPars(const Acts::GeometryContext& tgContext,
140 const MuonGMR4::MuonDetectorManager& detMgr,
141 const xAOD::MuonSegment& segment,
142 const Acts::ParticleHypothesis hypot) {
143 return boundSegmentPars(*tgContext.get<const ActsTrk::GeometryContext*>(),
144 detMgr, segment, hypot);
145 }
146 Acts::BoundTrackParameters boundSegmentPars(const ActsTrk::GeometryContext& gctx,
147 const MuonGMR4::MuonDetectorManager& detMgr,
148 const xAOD::MuonSegment& segment,
149 const Acts::ParticleHypothesis hypot) {
150
151 const auto* msSector = detMgr.getSectorEnvelope(segment.chamberIndex(),
152 segment.sector(),
153 segment.etaIndex());
154
155 const Parameters locSegPars = localSegmentPars(segment);
156 const Amg::Vector3D globDir = segment.direction();
157
158 Acts::BoundVector boundPars{};
159 boundPars[Acts::eBoundLoc0] = locSegPars[Acts::toUnderlying(ParamDefs::x0)];
160 boundPars[Acts::eBoundLoc1] = locSegPars[Acts::toUnderlying(ParamDefs::y0)];
161 boundPars[Acts::eBoundPhi] = globDir.phi();
162 boundPars[Acts::eBoundTheta] = globDir.theta();
163 boundPars[Acts::eBoundQOverP] = straightQoverP;
164 boundPars[Acts::eBoundTime] = ActsTrk::timeToActs(segment.position().mag() / Gaudi::Units::c_light + segment.t0());
165
166 // std::optional<Acts::BoundMatrix> cov = translateCovariance(localSegmentPars()
167 return Acts::BoundTrackParameters{msSector->surface().getSharedPtr(),
168 std::move(boundPars),
169 translateCovariance(locSegPars, localSegmentCov(segment),
170 msSector->localToGlobalTransform(gctx)), hypot};
171 }
172 Acts::BoundTrackParameters boundSegmentPars(const ActsTrk::GeometryContext& gctx,
173 const Segment& segment,
174 const Acts::ParticleHypothesis hypot) {
175
176 const Amg::Vector3D locPos = segment.msSector()->globalToLocalTransform(gctx) * segment.position();
177 Acts::BoundVector boundPars{};
178 boundPars[Acts::eBoundLoc0] = locPos.x();
179 boundPars[Acts::eBoundLoc1] = locPos.y();
180 boundPars[Acts::eBoundPhi] = segment.direction().phi();
181 boundPars[Acts::eBoundTheta] = segment.direction().theta();
182 boundPars[Acts::eBoundQOverP] = straightQoverP;
183 boundPars[Acts::eBoundTime] = ActsTrk::timeToActs(segment.position().mag() / Gaudi::Units::c_light +
184 segment.segementT0());
185
186 return Acts::BoundTrackParameters{segment.msSector()->surface().getSharedPtr(),
187 std::move(boundPars),
189 segment.covariance(),
190 segment.msSector()->localToGlobalTransform(gctx)), hypot};
191 }
192
193 }
194}
Scalar phi() const
phi method
Scalar theta() const
theta method
static Double_t a
constexpr float inDeg(const float rad)
const SpectrometerSector * getSectorEnvelope(const Identifier &channelId) const
Retrieves the spectrometer envelope enclosing the channel's readout element.
const Amg::Transform3D & localToGlobalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the local -> global tarnsformation from the sector.
Amg::Transform3D globalToLocalTransform(const ActsTrk::GeometryContext &gctx) const
Returns the global -> local transformation from the ATLAS global.
const Acts::PlaneSurface & surface() const
Returns the associated surface.
Placeholder for what will later be the muon segment EDM representation.
double segementT0() const
Returns the fitted segment time, if there's any.
const SegmentFit::Covariance & covariance() const
Returns the uncertainties of the defining parameters.
const MuonGMR4::SpectrometerSector * msSector() const
Returns the associated MS sector.
const Amg::Vector3D & position() const
Returns the global segment position.
const Amg::Vector3D & direction() const
Returns the global segment direction.
float t0() const
Amg::Vector3D direction() const
Returns the direction as Amg::Vector.
::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 ).
constexpr auto timeToActs(T athenaT)
Converts a time unit from Athena to Acts units.
Eigen::Affine3d Transform3D
Eigen::Matrix< double, 3, 1 > Vector3D
Acts::Experimental::CompositeSpacePointLineFitter::CovMat_t Covariance
constexpr std::size_t N
std::optional< Covariance > localSegmentCov(const xAOD::MuonSegment &seg)
Returns the localCovariance decoration from a xAOD::MuonSegment.
Acts::BoundTrackParameters boundSegmentPars(const ActsTrk::GeometryContext &gctx, const MuonGMR4::MuonDetectorManager &detMgr, const xAOD::MuonSegment &segment, const Acts::ParticleHypothesis hypot=Acts::ParticleHypothesis::muon())
Returns the segment parameters as boundTrackParameters.
SeedingAux::FitParIndex ParamDefs
Use the same parameter indices as used by the CompSpacePointAuxiliaries.
Parameters localSegmentPars(const xAOD::MuonSegment &seg)
Returns the localSegPars decoration from a xAODMuon::Segment.
std::pair< Amg::Vector3D, Amg::Vector3D > makeLine(const Parameters &pars)
Returns the parsed parameters into an Eigen line parametrization.
Acts::Experimental::CompositeSpacePointLineFitter::ParamVec_t Parameters
std::optional< Acts::BoundMatrix > translateCovariance(const Parameters &locSegPars, std::optional< Covariance > &&localCov, const Amg::Transform3D &localToGlobal)
std::string makeLabel(const Parameters &pars)
Dumps the parameters into a string in the form of TLatex.
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.
double houghTanBeta(const Amg::Vector3D &v)
Returns the hough tanBeta [y] / [z].
double houghTanAlpha(const Amg::Vector3D &v)
: Returns the hough tanAlpha [x] / [z]
constexpr float inDeg(const float rad)
SG::AuxElement::Accessor< std::array< float, N > > PosAccessor
xAOD Accessor to the position
MuonSegment_v1 MuonSegment
Reference the current persistent version: