ATLAS Offline Software
SolenoidalIntersector.h
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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;
150 
153 
154  // counters
155  mutable std::atomic<unsigned long long> m_countExtrapolations;
156  mutable std::atomic<unsigned long long> m_countRKSwitches;
157 };
158 
159 // arc length to intersect of 2 circles: circular track and circle at (0,0) with
160 // radius endRadius
162  double endRadius, double radiusOfCurvature, double xCentre, double yCentre,
163  double cosPhi, double sinPhi, double& cosPhiIntersect,
164  double& sinPhiIntersect) const {
165  int trapped = 0;
166  double radiusSquared = xCentre * xCentre + yCentre * yCentre;
167  double term = 0.5 *
168  (radiusSquared + radiusOfCurvature * radiusOfCurvature -
169  endRadius * endRadius) /
170  (radiusSquared * radiusOfCurvature);
171  if (std::abs(xCentre) < std::abs(yCentre)) {
172  double dx2 = yCentre * yCentre * (1. / (radiusSquared * term * term) - 1.);
173  if (dx2 < 0.) {
174  trapped = 1;
175  } else {
176  if (yCentre * term > 0.) {
177  sinPhiIntersect = term * (-xCentre + std::sqrt(dx2));
178  } else {
179  sinPhiIntersect = term * (-xCentre - std::sqrt(dx2));
180  }
181  cosPhiIntersect =
182  (sinPhiIntersect * xCentre + radiusSquared * term) / yCentre;
183  }
184  } else {
185  double dy2 = xCentre * xCentre * (1. / (radiusSquared * term * term) - 1.);
186  if (dy2 < 0.) {
187  trapped = 1;
188  } else {
189  if (xCentre * term > 0.) {
190  cosPhiIntersect = term * (yCentre + std::sqrt(dy2));
191  } else {
192  cosPhiIntersect = term * (yCentre - std::sqrt(dy2));
193  }
194  sinPhiIntersect =
195  (cosPhiIntersect * yCentre - radiusSquared * term) / xCentre;
196  }
197  }
198  if (trapped == 0) {
199  double deltaPhi;
200  double sinDeltaPhi = sinPhiIntersect * cosPhi - cosPhiIntersect * sinPhi;
201  if (std::abs(sinDeltaPhi) > 0.1) {
202  deltaPhi = std::asin(sinDeltaPhi);
203  } else {
204  deltaPhi = sinDeltaPhi * (1. + 0.166667 * sinDeltaPhi * sinDeltaPhi);
205  }
206  return (radiusOfCurvature * deltaPhi);
207  } else {
208  cosPhiIntersect = cosPhi;
209  sinPhiIntersect = sinPhi;
210  return 0.;
211  }
212 }
213 
214 // arc length to intersect of a line to a circle of radius endRadius centred at
215 // (0,0) +ve (-ve) endRadius selects the solution on the same (opposite) side of
216 // (0,0)
218  const TrackSurfaceIntersection& isect, const Constants& com,
219  const double radius2, const double endRadius) const {
220  const Amg::Vector3D& pos = isect.position();
221  const Amg::Vector3D& dir = isect.direction();
222 
223  double arcLength =
224  (-dir.x() * pos.x() - dir.y() * pos.y()) * com.m_oneOverSinTheta;
225  double radiusSquared =
226  endRadius * endRadius - radius2 + arcLength * arcLength;
227  if (radiusSquared > 0.) {
228  if (endRadius > 0.) {
229  arcLength += std::sqrt(radiusSquared);
230  } else {
231  arcLength -= std::sqrt(radiusSquared);
232  }
233  }
234  return arcLength;
235 }
236 
237 inline std::optional<TrackSurfaceIntersection> SolenoidalIntersector::intersection(
238  TrackSurfaceIntersection&& isect, Constants& com,
239  const Surface& surface) const {
240  // Improve the estimate of the intersection by calculating
241  // the straight-line intersection.
242  Intersection SLIntersect = surface.straightLineIntersection(
243  isect.position(), isect.direction(), false, false);
244  if (SLIntersect.valid) {
245  // But first save our current position, so that we can
246  // start from here on the next call.
247  com.m_lastPosition = isect.position();
248  isect.position() = SLIntersect.position;
249  return std::move(isect);
250  }
251 
252  return std::nullopt;
253 }
254 
255 } // namespace Trk
256 
257 #endif // TRKEXSOLENOIDALINTERSECTOR_SOLENOIDALINTERSECTOR_H
258 
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:108
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:351
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:160
Trk::SolenoidalIntersector::m_surfaceTolerance
double m_surfaceTolerance
Definition: SolenoidalIntersector.h:152
Trk::SolenoidalIntersector::Constants::m_sinTheta
double m_sinTheta
Definition: SolenoidalIntersector.h:57
SG::ReadCondHandle::isValid
bool isValid()
Definition: ReadCondHandle.h:206
Trk::SolenoidalIntersector::newIntersection
static std::optional< TrackSurfaceIntersection > newIntersection(const TrackSurfaceIntersection &oldIsect, const SolenoidParametrization &solpar, const double qOverP, Constants *&com)
Definition: SolenoidalIntersector.cxx:395
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:178
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:155
Trk::DiscSurface
Definition: DiscSurface.h:54
Trk::TrackSurfaceIntersection::IIntersectionCache
Base class for cache block.
Definition: TrackSurfaceIntersection.h:36
Trk::SolenoidalIntersector::extrapolateToZ
static bool extrapolateToZ(TrackSurfaceIntersection &isect, Constants &com, const double endZ)
Definition: SolenoidalIntersector.cxx:342
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:250
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:115
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:161
Trk::SolenoidalIntersector::m_deltaPhiTolerance
double m_deltaPhiTolerance
Definition: SolenoidalIntersector.h:151
Trk::SolenoidalIntersector::intersection
std::optional< TrackSurfaceIntersection > intersection(TrackSurfaceIntersection &&isect, Constants &com, const Surface &surface) const
Definition: SolenoidalIntersector.h:237
SolenoidParametrization.h
Trk::TrackSurfaceIntersection::position
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
Definition: TrackSurfaceIntersection.h: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:72
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
Trk::SolenoidalIntersector::initialize
virtual StatusCode initialize() override
Definition: SolenoidalIntersector.cxx:53
beamspotman.dir
string dir
Definition: beamspotman.py:623
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:147
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:122
Trk::SolenoidalIntersector::m_countRKSwitches
std::atomic< unsigned long long > m_countRKSwitches
Definition: SolenoidalIntersector.h:156
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
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:18
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:270
Trk::PlaneSurface
Definition: PlaneSurface.h:64
Trk::SolenoidalIntersector::Constants::m_oneOverSinTheta
double m_oneOverSinTheta
Definition: SolenoidalIntersector.h:58
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
Trk::SolenoidalIntersector::finalize
virtual StatusCode finalize() override
Definition: SolenoidalIntersector.cxx:61
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:422
Trk::SolenoidalIntersector::Constants::m_solPar
const SolenoidParametrization & m_solPar
Definition: SolenoidalIntersector.h:61
Trk::SolenoidalIntersector::linearArcLength
double linearArcLength(const TrackSurfaceIntersection &isect, const Constants &com, const double radius2, const double endRadius) const
Definition: SolenoidalIntersector.h:217
TrackSurfaceIntersection.h
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
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:67