ATLAS Offline Software
Loading...
Searching...
No Matches
SolenoidalIntersector.h
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3*/
4
6// SolenoidalIntersector.h, (c) ATLAS Detector software
8
9#ifndef TRKEXSOLENOIDALINTERSECTOR_SOLENOIDALINTERSECTOR_H
10#define TRKEXSOLENOIDALINTERSECTOR_SOLENOIDALINTERSECTOR_H
11
12#include <cmath>
13#include <mutex>
14
17#include "GaudiKernel/ContextSpecificPtr.h"
18#include "GaudiKernel/ToolHandle.h"
26
27namespace Trk {
28
29class SolenoidalIntersector final: public extends<AthAlgTool, IIntersector> {
30
31 public:
52 const TrackSurfaceIntersection& trackTrackSurfaceIntersection,
53 const double qOverP);
54 virtual std::unique_ptr<IIntersectionCache> clone() const override {
55 return std::unique_ptr<IIntersectionCache>(new Constants(*this));
56 }
57 double m_sinTheta;
59 double m_cotTheta;
60 double m_qOverPt;
64 };
65 SolenoidalIntersector(const std::string& type, const std::string& name,
66 const IInterface* parent);
67 virtual ~SolenoidalIntersector() = default;
68
69 virtual StatusCode initialize() override;
70 virtual StatusCode finalize() override;
71
73 virtual std::optional<TrackSurfaceIntersection> intersectSurface(
74 const Surface& surface,
75 const TrackSurfaceIntersection& trackTrackSurfaceIntersection,
76 const double qOverP) const override;
77
79 virtual std::optional<TrackSurfaceIntersection> approachPerigeeSurface(
80 const PerigeeSurface& surface,
81 const TrackSurfaceIntersection& trackTrackSurfaceIntersection,
82 const double qOverP) const override;
83
86 virtual std::optional<TrackSurfaceIntersection> approachStraightLineSurface(
87 const StraightLineSurface& surface,
88 const TrackSurfaceIntersection& trackTrackSurfaceIntersection,
89 const double qOverP) const override;
90
93 virtual std::optional<TrackSurfaceIntersection> intersectCylinderSurface(
94 const CylinderSurface& surface,
95 const TrackSurfaceIntersection& trackTrackSurfaceIntersection,
96 const double qOverP) const override;
97
99 virtual std::optional<TrackSurfaceIntersection> intersectDiscSurface(
100 const DiscSurface& surface,
101 const TrackSurfaceIntersection& trackTrackSurfaceIntersection,
102 const double qOverP) const override;
103
105 virtual std::optional<TrackSurfaceIntersection> intersectPlaneSurface(
106 const PlaneSurface& surface,
107 const TrackSurfaceIntersection& trackTrackSurfaceIntersection,
108 const double qOverP) const override;
109
112 virtual bool isValid(Amg::Vector3D startPosition,
113 Amg::Vector3D endPosition) const override;
114
115
116 private:
117 void throwMissingCondData() const;
121 if (!handle.isValid()) {
123 }
124 return handle.cptr();
125 }
126
127 double circularArcLength(double, double, double, double, double, double,
128 double&, double&) const;
129 double linearArcLength(const TrackSurfaceIntersection& isect,
130 const Constants& com, const double radius2,
131 const double endRadius) const;
132 bool extrapolateToR(TrackSurfaceIntersection& isect, double& radius2,
133 Constants& com, const double endRadius) const;
134
135 static bool extrapolateToZ(TrackSurfaceIntersection& isect, Constants& com,
136 const double endZ);
137
138 std::optional<TrackSurfaceIntersection> intersection(
139 TrackSurfaceIntersection&& isect, Constants& com,
140 const Surface& surface) const;
141
142 static std::optional<TrackSurfaceIntersection> newIntersection(
143 const TrackSurfaceIntersection& oldIsect,
144 const SolenoidParametrization& solpar, const double qOverP,
145 Constants*& com);
146
148 this, "SolenoidParameterizationKey", "SolenoidParametrization", ""};
149 ToolHandle<IIntersector> m_rungeKuttaIntersector{this, "RungeKuttaIntersector",
150 "Trk::RungeKuttaIntersector/RungeKuttaIntersector"};
151
152 static constexpr double m_deltaPhiTolerance = 0.01; // upper limit for small angle approx
153 DoubleProperty m_surfaceTolerance{this, "SurfaceTolerance",
154 2.0 * Gaudi::Units::micrometer};
155
156 // counters
157 mutable std::atomic<unsigned long long> m_countExtrapolations = 0;
158 mutable std::atomic<unsigned long long> m_countRKSwitches = 0;
159};
160
161// arc length to intersect of 2 circles: circular track and circle at (0,0) with
162// radius endRadius
164 double endRadius, double radiusOfCurvature, double xCentre, double yCentre,
165 double cosPhi, double sinPhi, double& cosPhiIntersect,
166 double& sinPhiIntersect) const {
167 int trapped = 0;
168 double radiusSquared = xCentre * xCentre + yCentre * yCentre;
169 double term = 0.5 *
170 (radiusSquared + radiusOfCurvature * radiusOfCurvature -
171 endRadius * endRadius) /
172 (radiusSquared * radiusOfCurvature);
173 if (std::abs(xCentre) < std::abs(yCentre)) {
174 double dx2 = yCentre * yCentre * (1. / (radiusSquared * term * term) - 1.);
175 if (dx2 < 0.) {
176 trapped = 1;
177 } else {
178 if (yCentre * term > 0.) {
179 sinPhiIntersect = term * (-xCentre + std::sqrt(dx2));
180 } else {
181 sinPhiIntersect = term * (-xCentre - std::sqrt(dx2));
182 }
183 cosPhiIntersect =
184 (sinPhiIntersect * xCentre + radiusSquared * term) / yCentre;
185 }
186 } else {
187 double dy2 = xCentre * xCentre * (1. / (radiusSquared * term * term) - 1.);
188 if (dy2 < 0.) {
189 trapped = 1;
190 } else {
191 if (xCentre * term > 0.) {
192 cosPhiIntersect = term * (yCentre + std::sqrt(dy2));
193 } else {
194 cosPhiIntersect = term * (yCentre - std::sqrt(dy2));
195 }
196 sinPhiIntersect =
197 (cosPhiIntersect * yCentre - radiusSquared * term) / xCentre;
198 }
199 }
200 if (trapped == 0) {
201 double deltaPhi;
202 double sinDeltaPhi = sinPhiIntersect * cosPhi - cosPhiIntersect * sinPhi;
203 if (std::abs(sinDeltaPhi) > 0.1) {
204 deltaPhi = std::asin(sinDeltaPhi);
205 } else {
206 deltaPhi = sinDeltaPhi * (1. + 0.166667 * sinDeltaPhi * sinDeltaPhi);
207 }
208 return (radiusOfCurvature * deltaPhi);
209 } else {
210 cosPhiIntersect = cosPhi;
211 sinPhiIntersect = sinPhi;
212 return 0.;
213 }
214}
215
216// arc length to intersect of a line to a circle of radius endRadius centred at
217// (0,0) +ve (-ve) endRadius selects the solution on the same (opposite) side of
218// (0,0)
220 const TrackSurfaceIntersection& isect, const Constants& com,
221 const double radius2, const double endRadius) const {
222 const Amg::Vector3D& pos = isect.position();
223 const Amg::Vector3D& dir = isect.direction();
224
225 double arcLength =
226 (-dir.x() * pos.x() - dir.y() * pos.y()) * com.m_oneOverSinTheta;
227 double radiusSquared =
228 endRadius * endRadius - radius2 + arcLength * arcLength;
229 if (radiusSquared > 0.) {
230 if (endRadius > 0.) {
231 arcLength += std::sqrt(radiusSquared);
232 } else {
233 arcLength -= std::sqrt(radiusSquared);
234 }
235 }
236 return arcLength;
237}
238
239inline std::optional<TrackSurfaceIntersection> SolenoidalIntersector::intersection(
241 const Surface& surface) const {
242 // Improve the estimate of the intersection by calculating
243 // the straight-line intersection.
244 Intersection SLIntersect = surface.straightLineIntersection(
245 isect.position(), isect.direction(), false, false);
246 if (SLIntersect.valid) {
247 // But first save our current position, so that we can
248 // start from here on the next call.
249 com.m_lastPosition = isect.position();
250 isect.position() = SLIntersect.position;
251 return std::move(isect);
252 }
253
254 return std::nullopt;
255}
256
257} // namespace Trk
258
259#endif // TRKEXSOLENOIDALINTERSECTOR_SOLENOIDALINTERSECTOR_H
260
Scalar deltaPhi(const MatrixBase< Derived > &vec) const
Define macros for attributes used to control the static checker.
const_pointer_type cptr()
Class for a CylinderSurface in the ATLAS detector.
Class for a DiscSurface in the ATLAS detector.
Definition DiscSurface.h:54
Class describing the Line to which the Perigee refers to.
Class for a planaer rectangular or trapezoidal surface in the ATLAS detector.
SG::ReadCondHandleKey< SolenoidParametrization > m_solenoidParametrizationKey
virtual std::optional< TrackSurfaceIntersection > intersectDiscSurface(const DiscSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : DiscSurface.
std::optional< TrackSurfaceIntersection > intersection(TrackSurfaceIntersection &&isect, Constants &com, const Surface &surface) const
virtual std::optional< TrackSurfaceIntersection > approachPerigeeSurface(const PerigeeSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : PerigeeSurface.
ToolHandle< IIntersector > m_rungeKuttaIntersector
static bool extrapolateToZ(TrackSurfaceIntersection &isect, Constants &com, const double endZ)
static constexpr double m_deltaPhiTolerance
virtual StatusCode finalize() override
virtual std::optional< TrackSurfaceIntersection > intersectSurface(const Surface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for general Surface type.
virtual bool isValid(Amg::Vector3D startPosition, Amg::Vector3D endPosition) const override
IIntersector interface method to check validity of parametrization within extrapolation range.
static std::optional< TrackSurfaceIntersection > newIntersection(const TrackSurfaceIntersection &oldIsect, const SolenoidParametrization &solpar, const double qOverP, Constants *&com)
virtual std::optional< TrackSurfaceIntersection > intersectPlaneSurface(const PlaneSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : PlaneSurface.
virtual StatusCode initialize() override
bool extrapolateToR(TrackSurfaceIntersection &isect, double &radius2, Constants &com, const double endRadius) const
virtual std::optional< TrackSurfaceIntersection > approachStraightLineSurface(const StraightLineSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : StraightLineSurface.
double linearArcLength(const TrackSurfaceIntersection &isect, const Constants &com, const double radius2, const double endRadius) const
std::atomic< unsigned long long > m_countExtrapolations
virtual std::optional< TrackSurfaceIntersection > intersectCylinderSurface(const CylinderSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : CylinderSurface.
const SolenoidParametrization * getSolenoidParametrization() const
double circularArcLength(double, double, double, double, double, double, double &, double &) const
std::atomic< unsigned long long > m_countRKSwitches
virtual ~SolenoidalIntersector()=default
SolenoidalIntersector(const std::string &type, const std::string &name, const IInterface *parent)
Class for a StraightLineSurface in the ATLAS detector to describe dirft tube and straw like detectors...
Abstract Base Class for tracking surfaces.
Intersection straightLineIntersection(const T &pars, bool forceDir=false, const Trk::BoundaryCheck &bchk=false) const
fst straight line intersection schema - templated for charged and neutral parameters
An intersection with a Surface is given by.
const Amg::Vector3D & direction() const
Method to retrieve the direction at the Intersection.
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
@ qOverP
perigee
Definition ParamDefs.h:67
Amg::Vector3D position
Constants of motion and other cached values.
virtual std::unique_ptr< IIntersectionCache > clone() const override
Constants(const SolenoidParametrization &solpar, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP)
const SolenoidParametrization & m_solPar
SolenoidParametrization::Parameters m_solParams