ATLAS Offline Software
Loading...
Searching...
No Matches
TrackMatchingUtils.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
6
8#include "Acts/Surfaces/Surface.hpp"
9#include "Acts/Surfaces/CylinderBounds.hpp"
10#include "Acts/Surfaces/DiscBounds.hpp"
11#include "Acts/Definitions/Units.hpp"
13
14using namespace P4Helpers;
15using namespace Acts::UnitLiterals;
16
17namespace MuonCombinedR4 {
18
19 std::optional<Acts::BoundTrackParameters>
20 makeDiffParameters(const Acts::GeometryContext& tgContext,
21 const Acts::BoundTrackParameters& idParameters,
22 const Acts::BoundTrackParameters& msParameters,
23 const Acts::Logger& logger,
24 const double boundTolerance) {
25
26 ACTS_VERBOSE(__func__<<"() "<<__LINE__<<" - Calculate difference parameters between \n"
27 <<idParameters<<"\n\n and \n\n"<<msParameters);
28 Acts::BoundVector diffPars = msParameters.parameters() -idParameters.parameters();
29
30 const Acts::Surface& idSurf{idParameters.referenceSurface()};
31 const Acts::Surface& msSurf{msParameters.referenceSurface()};
32
33 std::optional<Acts::BoundMatrix> msCov{msParameters.covariance()};
34 const std::optional<Acts::BoundMatrix>& idCov{idParameters.covariance()};
35
36 if (idSurf.geometryId() != msSurf.geometryId() ||
37 (idSurf.geometryId() == Acts::GeometryIdentifier{} &&
38 idSurf.getSharedPtr() != msSurf.getSharedPtr())) {
39 switch (msSurf.type()) {
40 using enum Acts::Surface::SurfaceType;
41 case Disc:{
42 if (static_cast<const Acts::DiscBounds&>(msSurf.bounds()).rMax() - msParameters.get<Acts::eBoundLoc0>() > boundTolerance) {
43 ACTS_VERBOSE(__func__<<"() "<<__LINE__<<" - The parameters are too far apart from the bounds ");
44 return std::nullopt;
45 }
46 break;
47 } case Cylinder : {
48 using enum Acts::CylinderBounds::BoundValues;
49 if (static_cast<const Acts::CylinderBounds&>(msSurf.bounds()).get(eHalfLengthZ) -
50 std::abs(msParameters.get<Acts::eBoundLoc1>()) > boundTolerance) {
51 ACTS_VERBOSE(__func__<<"() "<<__LINE__<<" - The parameters are too far apart from the bounds ");
52 return std::nullopt;
53 }
54 break;
55 } default: {
56 ACTS_WARNING(__func__<<"() "<<__LINE__<<" - Surface type "<<msSurf.type()<<" is not implemented");
57 break;
58 }
59 }
61 const Acts::Intersection3D idIsect = idSurf.intersect(tgContext,
62 msParameters.position(tgContext),
63 msParameters.direction(),
64 Acts::BoundaryTolerance::Infinite()).closest();
65 if (!idIsect.isValid()) {
66 ACTS_WARNING(__func__<<"() "<<__LINE__<<" - The propgation of "<<msParameters<<" to "
67 <<idSurf.geometryId()<<", "<<idSurf.bounds()<<" failed.");
68 return std::nullopt;
69 }
70 auto locPos = idSurf.globalToLocal(tgContext, idIsect.position(), msParameters.direction());
71 if (!locPos.ok()) {
72 ACTS_WARNING(__func__<<"() "<<__LINE__<<" - Local to global of "<<Amg::toString(idIsect.position())
73 <<" is not on "<<idSurf.geometryId()<<", "<<idSurf.bounds()<<".");
74 return std::nullopt;
75 }
77 diffPars[Acts::eBoundLoc0] = (*locPos)[Acts::eX] - idParameters.get<Acts::eBoundLoc0>();
78 diffPars[Acts::eBoundLoc1] = (*locPos)[Acts::eY] - idParameters.get<Acts::eBoundLoc1>();
80 if (msCov) {
81 (*msCov) = idSurf.freeToBoundJacobian(tgContext, idIsect.position(), msParameters.direction()) *
82 msSurf.boundToFreeJacobian(tgContext, msParameters.position(tgContext),
83 msParameters.direction()) * (*msCov);
84 }
85 }
86 std::optional<Acts::BoundMatrix> diffCov{};
87 if (idCov || msCov) {
88 diffCov = idCov.value_or(Acts::BoundMatrix::Zero()) +
89 msCov.value_or(Acts::BoundMatrix::Zero());
90 }
92 if (idSurf.type() == Acts::Surface::SurfaceType::Disc) {
93 diffPars[Acts::eBoundLoc1] = deltaPhi(msParameters.get<Acts::eBoundLoc1>(),
94 idParameters.get<Acts::eBoundLoc1>());
95 } else if (idSurf.type() == Acts::Surface::SurfaceType::Cylinder) {
96 using enum Acts::CylinderBounds::BoundValues;
98 const double R = static_cast<const Acts::CylinderBounds&>(idSurf.bounds()).get(eR);
99 diffPars[Acts::eBoundLoc0] = deltaPhi(msParameters.get<Acts::eBoundLoc0>() / R,
100 idParameters.get<Acts::eBoundLoc0>() / R) * R;
101 }
102 Acts::BoundTrackParameters retPars{idSurf.getSharedPtr(),
103 /*Ensure that theta remains positive otherwise
104 the constructor flips the direction */
105 Acts::copySign(diffPars, diffPars[Acts::eBoundTheta]),
106 diffCov, msParameters.particleHypothesis()};
107 ACTS_VERBOSE(__func__<<"() "<<__LINE__<<" - Successfully created \n"<<retPars);
108 return retPars;
109 }
110
111 double longitudinalParam(const Acts::BoundTrackParameters& pars,
112 const Acts::Logger& logger) {
113 switch (pars.referenceSurface().type()) {
114 using enum Acts::Surface::SurfaceType;
115 case Disc:
116 return pars.get<Acts::eBoundLoc0>();
117 case Cylinder:
118 return pars.get<Acts::eBoundLoc1>();
119 default:
120 ACTS_WARNING(__func__<<"() "<<__LINE__<<" Surface type "<<pars.referenceSurface().type()
121 <<" is not implemented");
122 break;
123 }
124 return -1._km;
125 }
126
128 double localPolarAngle(const Acts::BoundTrackParameters& pars,
129 const Acts::Logger& logger) {
130 switch (pars.referenceSurface().type()) {
131 using enum Acts::Surface::SurfaceType;
132 case Disc:
133 return pars.get<Acts::eBoundLoc1>();
134 case Cylinder: {
135 using enum Acts::CylinderBounds::BoundValues;
136 const double R = static_cast<const Acts::CylinderBounds&>(pars.referenceSurface().bounds()).get(eR);
137 return pars.get<Acts::eBoundLoc0>() / R;
138 } default:
139 ACTS_WARNING(__func__<<"() "<<__LINE__<<" Surface type "<<pars.referenceSurface().type()
140 <<" is not implemented");
141 break;
142 }
143 return 360._degree;
144 }
145
146
147}
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
static Root::TMsgLogger logger("iLumiCalc")
std::string toString(const Translation3D &translation, int precision=4)
GeoPrimitvesToStringConverter.
std::optional< Acts::BoundTrackParameters > makeDiffParameters(const Acts::GeometryContext &tgContext, const Acts::BoundTrackParameters &idParameters, const Acts::BoundTrackParameters &msParameters, const Acts::Logger &logger, const double boundTolerance=Acts::UnitConstants::km)
Calculates the difference parameters between the ID and the MS If the parameters are expressed on dif...
double localPolarAngle(const Acts::BoundTrackParameters &pars, const Acts::Logger &logger)
Returns the local angular polar angle of the track parameter.
double longitudinalParam(const Acts::BoundTrackParameters &pars, const Acts::Logger &logger)
Returns the longitudinal local track parameter which is defined as.
P4Helpers provides static helper functions for kinematic calculation on objects deriving from I4Momen...
Definition P4Helpers.h:32