Loading [MathJax]/extensions/tex2jax.js
ATLAS Offline Software
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 
26 namespace Trk
27 {
28 
29 //<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>>
30 
32  const std::string& name,
33  const IInterface* parent)
35  {
36  declareInterface<Trk::IPropagator>(this);
37  }
38 
40 = default;
41 
42 //<<<<<< PUBLIC MEMBER FUNCTION DEFINITIONS >>>>>>
43 
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 
64 std::unique_ptr<NeutralParameters>
66  const Surface& surface,
68  const BoundaryCheck& boundsCheck,
69  bool curvilinear) const
70 {
71  return m_linePropagator->propagate(parameters,surface,dir,boundsCheck,curvilinear);
72 }
73 
74 std::unique_ptr<TrackParameters>
75 IntersectorWrapper::propagate (const EventContext& /*ctx*/,
77  const Surface& surface,
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 
91 std::unique_ptr<TrackParameters>
92 IntersectorWrapper::propagate (const EventContext& /*ctx*/,
94  const Surface& surface,
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 
110 std::unique_ptr<TrackParameters>
111 IntersectorWrapper::propagateParameters (const EventContext& /*ctx*/,
113  const Surface& surface,
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 
128 std::unique_ptr<TrackParameters>
129 IntersectorWrapper::propagateParameters (const EventContext& /*ctx*/,
131  const Surface& surface,
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 
146 std::optional<Trk::TrackSurfaceIntersection>
147 IntersectorWrapper::intersect (const EventContext& /*ctx*/,
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 
162 void
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 
188 void
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 
GeV
#define GeV
Definition: PhysicsAnalysis/TauID/TauAnalysisTools/Root/HelperFunctions.cxx:17
StraightLineSurface.h
TrackParameters.h
Trk::IntersectorWrapper::propagateParameters
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...
Definition: IntersectorWrapper.cxx:111
Trk::MagneticFieldProperties
Definition: MagneticFieldProperties.h:31
PerigeeSurface.h
Trk::IntersectorWrapper::Cache::m_position
Amg::Vector3D m_position
Definition: IntersectorWrapper.h:235
Surface.h
Trk::oppositeMomentum
@ oppositeMomentum
Definition: PropDirection.h:21
IntersectorWrapper.h
Trk::IntersectorWrapper::Cache::m_qOverP
double m_qOverP
Definition: IntersectorWrapper.h:232
Trk::IntersectorWrapper::createParameters
void createParameters(Cache &cache, const Surface &surface, const BoundaryCheck &boundsCheck, bool curvilinear) const
Definition: IntersectorWrapper.cxx:163
AthCommonMsg< AlgTool >::msgLvl
bool msgLvl(const MSG::Level lvl) const
Definition: AthCommonMsg.h:30
Trk::IntersectorWrapper::initialize
virtual StatusCode initialize() override final
Definition: IntersectorWrapper.cxx:45
Trk::TrackSurfaceIntersection
Definition: TrackSurfaceIntersection.h:32
Trk::alongMomentum
@ alongMomentum
Definition: PropDirection.h:20
ATH_MSG_VERBOSE
#define ATH_MSG_VERBOSE(x)
Definition: AthMsgStreamMacros.h:28
Trk::IntersectorWrapper::~IntersectorWrapper
~IntersectorWrapper(void)
python.CaloAddPedShiftConfig.type
type
Definition: CaloAddPedShiftConfig.py:42
MagneticFieldProperties.h
Trk::ParticleHypothesis
ParticleHypothesis
Definition: ParticleHypothesis.h:25
Trk::PropDirection
PropDirection
Definition: PropDirection.h:19
Trk::IntersectorWrapper::m_intersector
ToolHandle< IIntersector > m_intersector
Definition: IntersectorWrapper.h:259
Trk::Surface::createUniqueTrackParameters
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.
Trk::IntersectorWrapper::Cache::m_momentum
Amg::Vector3D m_momentum
Definition: IntersectorWrapper.h:236
EL::StatusCode
::StatusCode StatusCode
StatusCode definition for legacy code.
Definition: PhysicsAnalysis/D3PDTools/EventLoop/EventLoop/StatusCode.h:22
ATH_MSG_DEBUG
#define ATH_MSG_DEBUG(x)
Definition: AthMsgStreamMacros.h:29
CylinderSurface.h
test_pyathena.parent
parent
Definition: test_pyathena.py:15
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::IntersectorWrapper::Cache::m_intersection
std::optional< TrackSurfaceIntersection > m_intersection
Definition: IntersectorWrapper.h:233
Trk::IntersectorWrapper::intersect
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...
Definition: IntersectorWrapper.cxx:147
Trk::ParametersBase
Definition: ParametersBase.h:55
beamspotman.dir
string dir
Definition: beamspotman.py:623
Trk::IntersectorWrapper::m_linePropagator
ToolHandle< IPropagator > m_linePropagator
Definition: IntersectorWrapper.h:261
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::IntersectorWrapper::finalize
virtual StatusCode finalize() override final
Definition: IntersectorWrapper.cxx:59
Trk::IntersectorWrapper::findIntersection
void findIntersection(Cache &cache, const TrackParameters &parameters, const Surface &surface, PropDirection dir=Trk::anyDirection) const
Definition: IntersectorWrapper.cxx:189
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
Trk::IntersectorWrapper::Cache::m_parameters
std::unique_ptr< TrackParameters > m_parameters
Definition: IntersectorWrapper.h:234
Trk::IntersectorWrapper::Cache
Definition: IntersectorWrapper.h:230
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::BoundaryCheck
Definition: BoundaryCheck.h:51
PlaneSurface.h
DEBUG
#define DEBUG
Definition: page_access.h:11
DiscSurface.h
physics_parameters.parameters
parameters
Definition: physics_parameters.py:144
Trk::IntersectorWrapper::propagate
virtual std::unique_ptr< NeutralParameters > propagate(const NeutralParameters &, const Surface &, PropDirection, const BoundaryCheck &, bool) const override final
N 0) Neutral parameters method
Definition: IntersectorWrapper.cxx:65
AthAlgTool
Definition: AthAlgTool.h:26
TrackSurfaceIntersection.h
Trk::Surface
Definition: Tracking/TrkDetDescr/TrkSurfaces/TrkSurfaces/Surface.h:75
Trk::IntersectorWrapper::IntersectorWrapper
IntersectorWrapper(const std::string &type, const std::string &name, const IInterface *parent)
Definition: IntersectorWrapper.cxx:31
Trk::TrackingVolume
Definition: TrackingVolume.h:121
Trk::IntersectorWrapper::Cache::m_charge
double m_charge
Definition: IntersectorWrapper.h:231