ATLAS Offline Software
IntersectorWrapper.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2023 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"
22 #include "TrkSurfaces/Surface.h"
23 #include <iomanip>
24 #include <memory>
25 #include <vector>
26 
27 namespace Trk
28 {
29 
30 //<<<<<< CLASS STRUCTURE INITIALIZATION >>>>>>
31 
33  const std::string& name,
34  const IInterface* parent)
36  m_intersector ("Trk::RungeKuttaIntersector/RungeKuttaIntersector"),
37  m_linePropagator ("")
38  {
39  declareInterface<Trk::IPropagator>(this);
40  declareProperty("Intersector", m_intersector);
41  declareProperty("LinePropagator", m_linePropagator);
42  }
43 
45 = default;
46 
47 //<<<<<< PUBLIC MEMBER FUNCTION DEFINITIONS >>>>>>
48 
51  // get the Tools
52 
53  ATH_CHECK(m_intersector.retrieve());
54 
55  ATH_MSG_VERBOSE( "Retrieved tool " << m_intersector );
56 
57  if (!m_linePropagator.empty()) {
58  ATH_CHECK( m_linePropagator.retrieve());
59  }
60  return StatusCode::SUCCESS;
61 }
62 
63 
65 {
66  return StatusCode::SUCCESS;
67 }
68 
69 std::unique_ptr<NeutralParameters>
71  const Surface& surface,
73  const BoundaryCheck& boundsCheck,
74  bool curvilinear) const
75 {
76  return m_linePropagator->propagate(parameters,surface,dir,boundsCheck,curvilinear);
77 }
78 
79 std::unique_ptr<TrackParameters>
80 IntersectorWrapper::propagate (const EventContext& /*ctx*/,
82  const Surface& surface,
84  const BoundaryCheck& boundsCheck,
85  const MagneticFieldProperties& /*magProperties*/,
86  ParticleHypothesis /*particle*/,
87  bool curvilinear,
88  const TrackingVolume*) const
89 {
90  Cache cache{};
91  findIntersection(cache,parameters,surface, dir);
92  createParameters(cache,surface,boundsCheck,curvilinear);
93  return std::move(cache.m_parameters);
94 }
95 
96 std::unique_ptr<TrackParameters>
97 IntersectorWrapper::propagate (const EventContext& /*ctx*/,
99  const Surface& surface,
101  const BoundaryCheck& boundsCheck,
102  const MagneticFieldProperties& /*magProperties*/,
103  std::optional<TransportJacobian>& /*transportJac*/,
104  double&,
105  ParticleHypothesis /*particle*/,
106  bool curvilinear,
107  const TrackingVolume*) const
108 {
109  Cache cache{};
110  findIntersection(cache,parameters,surface,dir);
111  createParameters(cache,surface,boundsCheck,curvilinear);
112  return std::move(cache.m_parameters);
113 }
114 
115 std::unique_ptr<TrackParameters>
116 IntersectorWrapper::propagateParameters (const EventContext& /*ctx*/,
118  const Surface& surface,
120  const BoundaryCheck& boundsCheck,
121  const MagneticFieldProperties& /*magProperties*/,
122  ParticleHypothesis /*particle*/,
123  bool curvilinear,
124  const TrackingVolume*) const
125 {
126 
127  Cache cache{};
128  findIntersection(cache,parameters,surface,dir);
129  createParameters(cache,surface,boundsCheck,curvilinear);
130  return std::move(cache.m_parameters);
131 }
132 
133 std::unique_ptr<TrackParameters>
134 IntersectorWrapper::propagateParameters (const EventContext& /*ctx*/,
136  const Surface& surface,
138  const BoundaryCheck& boundsCheck,
139  const MagneticFieldProperties& /*magProperties*/,
140  std::optional<TransportJacobian>& /*transportJac*/,
141  ParticleHypothesis /*particle*/,
142  bool curvilinear,
143  const TrackingVolume*) const
144 {
145  Cache cache{};
146  findIntersection(cache,parameters,surface,dir);
147  createParameters(cache,surface,boundsCheck,curvilinear);
148  return std::move(cache.m_parameters);
149 }
150 
151 std::optional<Trk::TrackSurfaceIntersection>
152 IntersectorWrapper::intersect (const EventContext& /*ctx*/,
154  const Surface& surface,
155  const MagneticFieldProperties& /*magProperties*/,
156  ParticleHypothesis /*particle*/,
157  const TrackingVolume*) const
158 {
159  Cache cache{};
160  findIntersection(cache,parameters,surface);
161  auto solution = cache.m_intersection;
162  return solution;
163 }
164 
165 //<<<<<< PRIVATE MEMBER FUNCTION DEFINITIONS >>>>>>
166 
167 void
169  const Surface& surface,
170  const BoundaryCheck& /*boundsCheck*/,
171  bool curvilinear) const
172 {
173  cache.m_parameters = nullptr;
174  if (! cache.m_intersection) return;
175 
176  // curvilinear special (simple) case
177  if (curvilinear)
178  {
179  cache.m_parameters=std::make_unique<CurvilinearParameters>(cache.m_intersection->position(),
180  cache.m_intersection->direction().phi(),
181  cache.m_intersection->direction().theta(),
182  cache.m_qOverP);
183  return;
184  }
185 
186  cache.m_parameters=surface.createUniqueTrackParameters(cache.m_intersection->position(),
187  cache.m_intersection->direction(),
188  cache.m_charge,std::nullopt);
189  // unrecognized Surface
190  if( !cache.m_parameters ) ATH_MSG_WARNING( " Failed to create parameters " );
191 }
192 
193 void
196  const Surface& surface,
197  PropDirection dir) const
198 {
199  cache.m_charge = parameters.charge();
200  cache.m_momentum = parameters.momentum();
201  cache.m_parameters= nullptr;
202  cache.m_position = Amg::Vector3D(parameters.position());
203  cache.m_qOverP = 1./cache.m_momentum.mag();
204  cache.m_intersection = std::make_optional<TrackSurfaceIntersection>(cache.m_position,cache.m_momentum*cache.m_qOverP,0.);
205  cache.m_qOverP *= cache.m_charge;
206 
207  const TrackSurfaceIntersection oldIntersection = (*cache.m_intersection);
208  cache.m_intersection =
209  m_intersector->intersectSurface(surface, oldIntersection, cache.m_qOverP);
210  if (! cache.m_intersection)
211  {
212  ATH_MSG_DEBUG( " no intersection found " );
213  return;
214  }
215 
216  // check for correct propagation direction
217  if ((dir == Trk::alongMomentum && cache.m_intersection->pathlength() < 0.)
218  || (dir == Trk::oppositeMomentum && cache.m_intersection->pathlength() > 0.))
219  {
220  if (msgLvl(MSG::DEBUG))
221  {
222  if (dir == Trk::alongMomentum)
223  {
224  ATH_MSG_DEBUG( " requested alongMomentum, but pathlength "
225  << cache.m_intersection->pathlength() );
226  }
227  else if (dir == Trk::oppositeMomentum)
228  {
229  ATH_MSG_DEBUG( " requested oppositeMomentum, but pathlength "
230  << cache.m_intersection->pathlength() );
231  }
232  }
233  cache.m_intersection=std::nullopt;
234  return;
235  }
236 
237  ATH_MSG_DEBUG( std::setiosflags(std::ios::fixed)
238  << " intersection at r,phi,z "
239  << std::setw(10) << std::setprecision(1) << cache.m_intersection->position().perp()
240  << std::setw(9) << std::setprecision(4) << cache.m_intersection->position().phi()
241  << std::setw(10) << std::setprecision(1) << cache.m_intersection->position().z()
242  << " momentum "
243  << std::setw(9) << std::setprecision(3) << 1./std::abs(cache.m_qOverP*Gaudi::Units::GeV) );
244 }
245 
246 } // end of namespace
247 
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:116
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
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
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:168
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:50
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)
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:152
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:260
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:64
Trk::IntersectorWrapper::findIntersection
void findIntersection(Cache &cache, const TrackParameters &parameters, const Surface &surface, PropDirection dir=Trk::anyDirection) const
Definition: IntersectorWrapper.cxx:194
name
std::string name
Definition: Control/AthContainers/Root/debug.cxx:228
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
IIntersector.h
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
python.CaloScaleNoiseConfig.type
type
Definition: CaloScaleNoiseConfig.py:78
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:70
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:32
Trk::TrackingVolume
Definition: TrackingVolume.h:121
Trk::IntersectorWrapper::Cache::m_charge
double m_charge
Definition: IntersectorWrapper.h:231