ATLAS Offline Software
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 
27 namespace Trk {
28 
29 class SolenoidalIntersector final: public extends<AthAlgTool, IIntersector> {
30 
31  public:
51  Constants(const SolenoidParametrization& solpar,
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",
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 
239 inline std::optional<TrackSurfaceIntersection> SolenoidalIntersector::intersection(
240  TrackSurfaceIntersection&& isect, Constants& com,
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 
Trk::SolenoidalIntersector::approachPerigeeSurface
virtual std::optional< TrackSurfaceIntersection > approachPerigeeSurface(const PerigeeSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : PerigeeSurface.
Definition: SolenoidalIntersector.cxx:99
Trk::Intersection
Definition: Intersection.h:24
SG::ReadCondHandle
Definition: ReadCondHandle.h:44
Trk::SolenoidalIntersector::Constants::m_lastPosition
Amg::Vector3D m_lastPosition
Definition: SolenoidalIntersector.h:62
Trk::SolenoidalIntersector::Constants::m_qOverPt
double m_qOverPt
Definition: SolenoidalIntersector.h:60
Trk::Surface::straightLineIntersection
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
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:352
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
AtlasFieldCacheCondObj.h
xAOD::deltaPhi
setSAddress setEtaMS setDirPhiMS setDirZMS setBarrelRadius setEndcapAlpha setEndcapRadius setInterceptInner setEtaMap setEtaBin setIsTgcFailure setDeltaPt deltaPhi
Definition: L2StandAloneMuon_v1.cxx:161
Trk::SolenoidalIntersector::Constants::m_sinTheta
double m_sinTheta
Definition: SolenoidalIntersector.h:57
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:210
Trk::SolenoidalIntersector::newIntersection
static std::optional< TrackSurfaceIntersection > newIntersection(const TrackSurfaceIntersection &oldIsect, const SolenoidParametrization &solpar, const double qOverP, Constants *&com)
Definition: SolenoidalIntersector.cxx:386
Trk::SolenoidalIntersector::intersectPlaneSurface
virtual std::optional< TrackSurfaceIntersection > intersectPlaneSurface(const PlaneSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : PlaneSurface.
Definition: SolenoidalIntersector.cxx:169
Trk::TrackSurfaceIntersection
Definition: TrackSurfaceIntersection.h:32
Trk::SolenoidalIntersector::m_solenoidParametrizationKey
SG::ReadCondHandleKey< SolenoidParametrization > m_solenoidParametrizationKey
Definition: SolenoidalIntersector.h:147
Trk::SolenoidalIntersector::m_countExtrapolations
std::atomic< unsigned long long > m_countExtrapolations
Definition: SolenoidalIntersector.h:157
Trk::DiscSurface
Definition: DiscSurface.h:54
Trk::TrackSurfaceIntersection::IIntersectionCache
Base class for cache block.
Definition: TrackSurfaceIntersection.h:36
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
Trk::SolenoidalIntersector::extrapolateToZ
static bool extrapolateToZ(TrackSurfaceIntersection &isect, Constants &com, const double endZ)
Definition: SolenoidalIntersector.cxx:333
ReadCondHandle.h
Trk::SolenoidalIntersector::isValid
virtual bool isValid(Amg::Vector3D startPosition, Amg::Vector3D endPosition) const override
IIntersector interface method to check validity of parametrization within extrapolation range.
Definition: SolenoidalIntersector.cxx:241
Trk::SolenoidalIntersector::approachStraightLineSurface
virtual std::optional< TrackSurfaceIntersection > approachStraightLineSurface(const StraightLineSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : StraightLineSurface.
Definition: SolenoidalIntersector.cxx:106
Trk::SolenoidalIntersector::Constants::Constants
Constants(const SolenoidParametrization &solpar, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP)
Definition: SolenoidalIntersector.cxx:22
Trk::SolenoidalIntersector::Constants::clone
virtual std::unique_ptr< IIntersectionCache > clone() const override
Definition: SolenoidalIntersector.h:54
GeoPrimitives.h
Trk::SolenoidalIntersector::circularArcLength
double circularArcLength(double, double, double, double, double, double, double &, double &) const
Definition: SolenoidalIntersector.h:163
Trk::SolenoidalIntersector::intersection
std::optional< TrackSurfaceIntersection > intersection(TrackSurfaceIntersection &&isect, Constants &com, const Surface &surface) const
Definition: SolenoidalIntersector.h:239
SolenoidParametrization.h
Trk::TrackSurfaceIntersection::position
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
Definition: TrackSurfaceIntersection.h:80
python.SystemOfUnits.micrometer
float micrometer
Definition: SystemOfUnits.py:80
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
Trk::CylinderSurface
Definition: CylinderSurface.h:55
AthAlgTool.h
Trk::SolenoidalIntersector::intersectSurface
virtual std::optional< TrackSurfaceIntersection > intersectSurface(const Surface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for general Surface type.
Definition: SolenoidalIntersector.cxx:63
Trk::SolenoidalIntersector
Definition: SolenoidalIntersector.h:29
test_pyathena.parent
parent
Definition: test_pyathena.py:15
Trk::SolenoidParametrization::Parameters
Definition: SolenoidParametrization.h:50
Trk::Intersection::position
Amg::Vector3D position
Definition: Intersection.h:25
columnar::final
CM final
Definition: ColumnAccessor.h:106
Trk::SolenoidalIntersector::initialize
virtual StatusCode initialize() override
Definition: SolenoidalIntersector.cxx:44
beamspotman.dir
string dir
Definition: beamspotman.py:621
ReadCondHandleKey.h
Trk::SolenoidalIntersector::intersectDiscSurface
virtual std::optional< TrackSurfaceIntersection > intersectDiscSurface(const DiscSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : DiscSurface.
Definition: SolenoidalIntersector.cxx:138
Trk::SolenoidalIntersector::~SolenoidalIntersector
virtual ~SolenoidalIntersector()=default
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::SolenoidalIntersector::Constants
Constants of motion and other cached values.
Definition: SolenoidalIntersector.h:50
Trk::SolenoidalIntersector::intersectCylinderSurface
virtual std::optional< TrackSurfaceIntersection > intersectCylinderSurface(const CylinderSurface &surface, const TrackSurfaceIntersection &trackTrackSurfaceIntersection, const double qOverP) const override
IIntersector interface method for specific Surface type : CylinderSurface.
Definition: SolenoidalIntersector.cxx:113
Trk::SolenoidalIntersector::m_countRKSwitches
std::atomic< unsigned long long > m_countRKSwitches
Definition: SolenoidalIntersector.h:158
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:240
Trk::SolenoidalIntersector::getSolenoidParametrization
const SolenoidParametrization * getSolenoidParametrization() const
Definition: SolenoidalIntersector.h:118
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
IIntersector.h
Trk::TrackSurfaceIntersection::direction
const Amg::Vector3D & direction() const
Method to retrieve the direction at the Intersection.
Definition: TrackSurfaceIntersection.h:88
Trk::Intersection::valid
bool valid
Definition: Intersection.h:28
python.LumiBlobConversion.pos
pos
Definition: LumiBlobConversion.py:16
SG::ReadCondHandleKey
Definition: ReadCondHandleKey.h:20
Trk::SolenoidalIntersector::SolenoidalIntersector
SolenoidalIntersector(const std::string &type, const std::string &name, const IInterface *parent)
Definition: SolenoidalIntersector.cxx:38
Trk::SolenoidalIntersector::Constants::m_cotTheta
double m_cotTheta
Definition: SolenoidalIntersector.h:59
Trk::SolenoidalIntersector::extrapolateToR
bool extrapolateToR(TrackSurfaceIntersection &isect, double &radius2, Constants &com, const double endRadius) const
Definition: SolenoidalIntersector.cxx:261
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Trk::SolenoidalIntersector::Constants::m_oneOverSinTheta
double m_oneOverSinTheta
Definition: SolenoidalIntersector.h:58
Trk::SolenoidalIntersector::finalize
virtual StatusCode finalize() override
Definition: SolenoidalIntersector.cxx:52
Trk::qOverP
@ qOverP
perigee
Definition: ParamDefs.h:67
if
if(febId1==febId2)
Definition: LArRodBlockPhysicsV0.cxx:567
Trk::SolenoidalIntersector::throwMissingCondData
void throwMissingCondData() const
Definition: SolenoidalIntersector.cxx:414
Trk::SolenoidalIntersector::Constants::m_solPar
const SolenoidParametrization & m_solPar
Definition: SolenoidalIntersector.h:61
Trk::SolenoidalIntersector::m_surfaceTolerance
DoubleProperty m_surfaceTolerance
Definition: SolenoidalIntersector.h:153
Trk::SolenoidalIntersector::m_deltaPhiTolerance
static constexpr double m_deltaPhiTolerance
Definition: SolenoidalIntersector.h:152
Trk::SolenoidalIntersector::linearArcLength
double linearArcLength(const TrackSurfaceIntersection &isect, const Constants &com, const double radius2, const double endRadius) const
Definition: SolenoidalIntersector.h:219
TrackSurfaceIntersection.h
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:79
checker_macros.h
Define macros for attributes used to control the static checker.
Trk::SolenoidParametrization
Definition: SolenoidParametrization.h:31
Trk::SolenoidalIntersector::Constants::m_solParams
SolenoidParametrization::Parameters m_solParams
Definition: SolenoidalIntersector.h:63
Trk::StraightLineSurface
Definition: StraightLineSurface.h:51
Trk::SolenoidalIntersector::m_rungeKuttaIntersector
ToolHandle< IIntersector > m_rungeKuttaIntersector
Definition: SolenoidalIntersector.h:149
SG::ReadCondHandle::cptr
const_pointer_type cptr()
Definition: ReadCondHandle.h:71