ATLAS Offline Software
SeedNewtonTrkDistanceFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2024 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*********************************************************************
6  SeedNewtonTrkDistanceFinder.cxx - Description in header file
7 *********************************************************************/
8 
9 //#define SEEDNEWTONTRKDISTANCEFINDER_DEBUG
10 
11 
16 #include "TrkTrack/Track.h"
20 #include <cmath>
21 
22 
23 namespace Trk
24 {
25 
26 
27  SeedNewtonTrkDistanceFinder::SeedNewtonTrkDistanceFinder(const std::string& t, const std::string& n, const IInterface* p) :
28  base_class(t,n,p),
29  m_2ddistanceseeder("Trk::Trk2dDistanceSeeder"),
30  m_distancefinder("Trk::NewtonTrkDistanceFinder"),
31  m_numberOfMinimizationFailures(0)
32  {
33  declareProperty("Trk2dDistanceSeeder", m_2ddistanceseeder);
34  declareProperty("TrkDistanceFinderImplementation", m_distancefinder);
35  }
36 
38 
40  {
41 
42  //initialize number of failures to 0
44 
46  ATH_CHECK( m_2ddistanceseeder.retrieve() );
47  ATH_CHECK( m_distancefinder.retrieve() );
48  ATH_MSG_DEBUG( "Initialize successful" );
49  return StatusCode::SUCCESS;
50  }
51 
53  {
54 
55  ATH_MSG_DEBUG( "Finalize successful. Number of failed minimizations: " << m_numberOfMinimizationFailures << ". Few per events is OK!" );
56  return StatusCode::SUCCESS;
57  }
58 
59 
62  std::optional<ITrkDistanceFinder::TwoPoints>
64  const Trk::Perigee & b) const
65  {
66  //defragmenting the meory: local variable instead of private data member
67  std::pair<PointOnTrack,PointOnTrack> minpoints;
68 
69  //try first to get the minimum directly with the Newton method
70  auto ret = m_distancefinder->GetClosestPoints(a,b);
71  if (std::holds_alternative<TwoPoints>(ret)) {
72  return std::get<TwoPoints>(ret);
73  }
74  ATH_MSG_DEBUG( "Problem with Newton finder: " <<
75  std::get<std::string>(ret) );
76  minpoints = m_2ddistanceseeder->GetSeed(TwoTracks(a,b));
77  ret = m_distancefinder->GetClosestPoints(minpoints);
78  if (std::holds_alternative<TwoPoints>(ret)) {
79  return std::get<TwoPoints>(ret);
80  }
81  ATH_MSG_DEBUG( "Problem with Newton finder, even after 2d seeder: no minimum between tracks found" << std::get<std::string>(ret));
83 
84  return std::nullopt;
85  }
86 
87 
89  std::optional<ITrkDistanceFinder::TwoPoints>
91  const Trk::Track & b) const
92  {
93  if (std::isnan(a.perigeeParameters()->parameters()[Trk::d0])||std::isnan(b.perigeeParameters()->parameters()[Trk::d0])) {
94  ATH_MSG_ERROR( "Nan parameters in tracks. Cannot use them" );
95  return std::nullopt;
96  }
97 
98  return CalculateMinimumDistance(*(a.perigeeParameters()),*(b.perigeeParameters()));
99 
100  }
101 
102 } // namespace Trk
Trk::SeedNewtonTrkDistanceFinder::SeedNewtonTrkDistanceFinder
SeedNewtonTrkDistanceFinder(const std::string &t, const std::string &n, const IInterface *p)
Definition: SeedNewtonTrkDistanceFinder.cxx:29
TrackParameters.h
Trk::SeedNewtonTrkDistanceFinder::m_2ddistanceseeder
ToolHandle< Trk2dDistanceSeeder > m_2ddistanceseeder
Definition: SeedNewtonTrkDistanceFinder.h:66
Trk::Track
The ATLAS Track class.
Definition: Tracking/TrkEvent/TrkTrack/TrkTrack/Track.h:73
Trk::SeedNewtonTrkDistanceFinder::CalculateMinimumDistance
virtual std::optional< TwoPoints > CalculateMinimumDistance(const Trk::Perigee &, const Trk::Perigee &) const override final
method to do the calculation starting from two Perigees
Definition: SeedNewtonTrkDistanceFinder.cxx:65
Trk::ParametersT
Dummy class used to allow special convertors to be called for surfaces owned by a detector element.
Definition: EMErrorDetail.h:25
initialize
void initialize()
Definition: run_EoverP.cxx:894
TrackParticleBase.h
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Trk::SeedNewtonTrkDistanceFinder::finalize
virtual StatusCode finalize() override
Definition: SeedNewtonTrkDistanceFinder.cxx:54
ParamDefs.h
SeedNewtonTrkDistanceFinder.h
Track.h
Trk::SeedNewtonTrkDistanceFinder::initialize
virtual StatusCode initialize() override
Definition: SeedNewtonTrkDistanceFinder.cxx:41
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
Trk2dDistanceSeeder.h
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
NewtonTrkDistanceFinder.h
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::SeedNewtonTrkDistanceFinder::~SeedNewtonTrkDistanceFinder
virtual ~SeedNewtonTrkDistanceFinder()
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
Trk::d0
@ d0
Definition: ParamDefs.h:63
plotBeamSpotMon.b
b
Definition: plotBeamSpotMon.py:77
SeedFinderParamDefs.h
a
TList * a
Definition: liststreamerinfos.cxx:10
Trk::SeedNewtonTrkDistanceFinder::m_distancefinder
ToolHandle< NewtonTrkDistanceFinder > m_distancefinder
Definition: SeedNewtonTrkDistanceFinder.h:67
Trk::SeedNewtonTrkDistanceFinder::m_numberOfMinimizationFailures
std::atomic< int > m_numberOfMinimizationFailures
Definition: SeedNewtonTrkDistanceFinder.h:68
Trk::TwoTracks
Definition: TwoTracks.h:15