ATLAS Offline Software
Loading...
Searching...
No Matches
IntersectorWrapper.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2025 CERN for the benefit of the ATLAS collaboration
3 */
4
6// wrapper to IIntersector tool to provide IPropagator functionality
7// default configuration wraps the RungeKutta intersector
8// (c) ATLAS Detector software
10
12#include "GaudiKernel/SystemOfUnits.h"
21#include "TrkSurfaces/Surface.h"
22#include <iomanip>
23#include <memory>
24#include <vector>
25
26namespace Trk
27{
28
29//<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>>
30
32 const std::string& name,
33 const IInterface* parent)
34 :AthAlgTool (type, name, parent)
35 {
36 declareInterface<Trk::IPropagator>(this);
37 }
38
40= default;
41
42//<<<<<< PUBLIC MEMBER FUNCTION DEFINITIONS >>>>>>
43
44StatusCode
46 // get the Tools
47
48 ATH_CHECK(m_intersector.retrieve());
49
50 ATH_MSG_VERBOSE( "Retrieved tool " << m_intersector );
51
52 if (!m_linePropagator.empty()) {
53 ATH_CHECK( m_linePropagator.retrieve());
54 }
55 return StatusCode::SUCCESS;
56}
57
58
60{
61 return StatusCode::SUCCESS;
62}
63
64std::unique_ptr<NeutralParameters>
66 const Surface& surface,
67 PropDirection dir,
68 const BoundaryCheck& boundsCheck,
69 bool curvilinear) const
70{
71 return m_linePropagator->propagate(parameters,surface,dir,boundsCheck,curvilinear);
72}
73
74std::unique_ptr<TrackParameters>
75IntersectorWrapper::propagate (const EventContext& /*ctx*/,
76 const TrackParameters& parameters,
77 const Surface& surface,
78 PropDirection dir,
79 const BoundaryCheck& boundsCheck,
80 const MagneticFieldProperties& /*magProperties*/,
81 ParticleHypothesis /*particle*/,
82 bool curvilinear,
83 const TrackingVolume*) const
84{
85 Cache cache{};
86 findIntersection(cache,parameters,surface, dir);
87 createParameters(cache,surface,boundsCheck,curvilinear);
88 return std::move(cache.m_parameters);
89}
90
91std::unique_ptr<TrackParameters>
92IntersectorWrapper::propagate (const EventContext& /*ctx*/,
93 const TrackParameters& parameters,
94 const Surface& surface,
95 PropDirection dir,
96 const BoundaryCheck& boundsCheck,
97 const MagneticFieldProperties& /*magProperties*/,
98 std::optional<TransportJacobian>& /*transportJac*/,
99 double&,
100 ParticleHypothesis /*particle*/,
101 bool curvilinear,
102 const TrackingVolume*) const
103{
104 Cache cache{};
105 findIntersection(cache,parameters,surface,dir);
106 createParameters(cache,surface,boundsCheck,curvilinear);
107 return std::move(cache.m_parameters);
108}
109
110std::unique_ptr<TrackParameters>
111IntersectorWrapper::propagateParameters (const EventContext& /*ctx*/,
112 const TrackParameters& parameters,
113 const Surface& surface,
114 PropDirection dir,
115 const BoundaryCheck& boundsCheck,
116 const MagneticFieldProperties& /*magProperties*/,
117 ParticleHypothesis /*particle*/,
118 bool curvilinear,
119 const TrackingVolume*) const
120{
121
122 Cache cache{};
123 findIntersection(cache,parameters,surface,dir);
124 createParameters(cache,surface,boundsCheck,curvilinear);
125 return std::move(cache.m_parameters);
126}
127
128std::unique_ptr<TrackParameters>
129IntersectorWrapper::propagateParameters (const EventContext& /*ctx*/,
130 const TrackParameters& parameters,
131 const Surface& surface,
132 PropDirection dir,
133 const BoundaryCheck& boundsCheck,
134 const MagneticFieldProperties& /*magProperties*/,
135 std::optional<TransportJacobian>& /*transportJac*/,
136 ParticleHypothesis /*particle*/,
137 bool curvilinear,
138 const TrackingVolume*) const
139{
140 Cache cache{};
141 findIntersection(cache,parameters,surface,dir);
142 createParameters(cache,surface,boundsCheck,curvilinear);
143 return std::move(cache.m_parameters);
144}
145
146std::optional<Trk::TrackSurfaceIntersection>
147IntersectorWrapper::intersect (const EventContext& /*ctx*/,
148 const TrackParameters& parameters,
149 const Surface& surface,
150 const MagneticFieldProperties& /*magProperties*/,
151 ParticleHypothesis /*particle*/,
152 const TrackingVolume*) const
153{
154 Cache cache{};
155 findIntersection(cache,parameters,surface);
156 auto solution = cache.m_intersection;
157 return solution;
158}
159
160//<<<<<< PRIVATE MEMBER FUNCTION DEFINITIONS >>>>>>
161
162void
164 const Surface& surface,
165 const BoundaryCheck& /*boundsCheck*/,
166 bool curvilinear) const
167{
168 cache.m_parameters = nullptr;
169 if (! cache.m_intersection) return;
170
171 // curvilinear special (simple) case
172 if (curvilinear)
173 {
174 cache.m_parameters=std::make_unique<CurvilinearParameters>(cache.m_intersection->position(),
175 cache.m_intersection->direction().phi(),
176 cache.m_intersection->direction().theta(),
177 cache.m_qOverP);
178 return;
179 }
180
181 cache.m_parameters=surface.createUniqueTrackParameters(cache.m_intersection->position(),
182 cache.m_intersection->direction(),
183 cache.m_charge,std::nullopt);
184 // unrecognized Surface
185 if( !cache.m_parameters ) ATH_MSG_WARNING( " Failed to create parameters " );
186}
187
188void
190 const TrackParameters& parameters,
191 const Surface& surface,
192 PropDirection dir) const
193{
194 cache.m_charge = parameters.charge();
195 cache.m_momentum = parameters.momentum();
196 cache.m_parameters= nullptr;
197 cache.m_position = Amg::Vector3D(parameters.position());
198 cache.m_qOverP = 1./cache.m_momentum.mag();
199 cache.m_intersection = std::make_optional<TrackSurfaceIntersection>(cache.m_position,cache.m_momentum*cache.m_qOverP,0.);
200 cache.m_qOverP *= cache.m_charge;
201
202 const TrackSurfaceIntersection oldIntersection = (*cache.m_intersection);
203 cache.m_intersection =
204 m_intersector->intersectSurface(surface, oldIntersection, cache.m_qOverP);
205 if (! cache.m_intersection)
206 {
207 ATH_MSG_DEBUG( " no intersection found " );
208 return;
209 }
210
211 // check for correct propagation direction
212 if ((dir == Trk::alongMomentum && cache.m_intersection->pathlength() < 0.)
213 || (dir == Trk::oppositeMomentum && cache.m_intersection->pathlength() > 0.))
214 {
215 if (msgLvl(MSG::DEBUG))
216 {
217 if (dir == Trk::alongMomentum)
218 {
219 ATH_MSG_DEBUG( " requested alongMomentum, but pathlength "
220 << cache.m_intersection->pathlength() );
221 }
222 else if (dir == Trk::oppositeMomentum)
223 {
224 ATH_MSG_DEBUG( " requested oppositeMomentum, but pathlength "
225 << cache.m_intersection->pathlength() );
226 }
227 }
228 cache.m_intersection=std::nullopt;
229 return;
230 }
231
232 ATH_MSG_DEBUG( std::setiosflags(std::ios::fixed)
233 << " intersection at r,phi,z "
234 << std::setw(10) << std::setprecision(1) << cache.m_intersection->position().perp()
235 << std::setw(9) << std::setprecision(4) << cache.m_intersection->position().phi()
236 << std::setw(10) << std::setprecision(1) << cache.m_intersection->position().z()
237 << " momentum "
238 << std::setw(9) << std::setprecision(3) << 1./std::abs(cache.m_qOverP*Gaudi::Units::GeV) );
239}
240
241} // end of namespace
242
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
AthAlgTool(const std::string &type, const std::string &name, const IInterface *parent)
Constructor with parameters:
bool msgLvl(const MSG::Level lvl) const
The BoundaryCheck class allows to steer the way surface boundaries are used for inside/outside checks...
ToolHandle< IIntersector > m_intersector
virtual std::unique_ptr< TrackParameters > propagateParameters(const EventContext &ctx, const TrackParameters &parm, const Surface &sf, PropDirection dir, const BoundaryCheck &bcheck, const MagneticFieldProperties &mprop, ParticleHypothesis particle=pion, bool returnCurv=false, const TrackingVolume *tVol=nullptr) const override final
Propagation interface without Covariance matrix propagation the pathlength has to be returned for eve...
virtual std::optional< Trk::TrackSurfaceIntersection > intersect(const EventContext &ctx, const TrackParameters &parm, const Surface &sf, const MagneticFieldProperties &mprop, ParticleHypothesis particle=pion, const TrackingVolume *tVol=nullptr) const override final
Intersection interface: The intersection interface might be used by the material service as well to e...
IntersectorWrapper(const std::string &type, const std::string &name, const IInterface *parent)
void findIntersection(Cache &cache, const TrackParameters &parameters, const Surface &surface, PropDirection dir=Trk::anyDirection) const
void createParameters(Cache &cache, const Surface &surface, const BoundaryCheck &boundsCheck, bool curvilinear) const
virtual StatusCode initialize() override final
virtual std::unique_ptr< NeutralParameters > propagate(const NeutralParameters &, const Surface &, PropDirection, const BoundaryCheck &, bool) const override final
N 0) Neutral parameters method .
ToolHandle< IPropagator > m_linePropagator
virtual StatusCode finalize() override final
magnetic field properties to steer the behavior of the extrapolation
Abstract Base Class for tracking surfaces.
Definition Surface.h:79
virtual ChargedTrackParametersUniquePtr createUniqueTrackParameters(double l1, double l2, double phi, double theat, double qop, std::optional< AmgSymMatrix(5)> cov=std::nullopt) const =0
Use the Surface as a ParametersBase constructor, from local parameters - charged.
Full Volume description used in Tracking, it inherits from Volume to get the geometrical structure,...
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
PropDirection
PropDirection, enum for direction of the propagation.
@ oppositeMomentum
@ alongMomentum
ParametersBase< NeutralParametersDim, Neutral > NeutralParameters
TrackSurfaceIntersection(const Amg::Vector3D &pos, const Amg::Vector3D &dir, double path)
Constructor.
ParticleHypothesis
Enumeration for Particle hypothesis respecting the interaction with material.
ParametersBase< TrackParametersDim, Charged > TrackParameters
const IIntersectionCache * cache() const
Retrieve the associated cache block, if it exists.