ATLAS Offline Software
InDetTrackZ0SortingTool.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 #include "TrkTrack/Track.h"
7 #include "VxVertex/Vertex.h"
10 
11 namespace InDet
12 {
13 
15  {
16  if ( m_extrapolator.retrieve().isFailure() )
17  {
18  ATH_MSG_ERROR("Failed to retrieve tool " << m_extrapolator);
19  return StatusCode::FAILURE;
20  }
21  ATH_MSG_DEBUG("Retrieved tool " << m_extrapolator);
22 
23  return StatusCode::SUCCESS;
24  }//end of initialize method
25 
26 
27  InDetTrackZ0SortingTool::InDetTrackZ0SortingTool(const std::string& t, const std::string& n, const IInterface* p):
28  AthAlgTool(t,n,p), m_extrapolator("Trk::Extrapolator")
29  {
30 
31  //interface
32  declareInterface<InDetTrackZ0SortingTool>(this);
33 
34  //extrapolator
35  declareProperty("Extrapolator",m_extrapolator);
36 
37  }//end of constructor
38 
39 
41  = default;
42 
43 
44  std::vector<int> InDetTrackZ0SortingTool::sortedIndex(const std::vector<const Trk::Track*>& tracks, const Trk::Vertex * reference )const
45  {
46  const EventContext& ctx = Gaudi::Hive::currentContext();
47  std::map<double, int> mapOfZ0;
48  std::vector<const Trk::Track*>::const_iterator tb = tracks.begin();
49  std::vector<const Trk::Track*>::const_iterator te = tracks.end();
50  unsigned int j=0;
51  for(;tb != te ;++tb)
52  {
53  const Trk::TrackParameters * perigee(nullptr);
54  if(!reference) perigee=(*tb)->perigeeParameters();
55  else
56  {
57 
58  //here we want to make an extrapolation
59  Trk::PerigeeSurface perigeeSurface(reference->position());
60  perigee = m_extrapolator->extrapolateTrack(ctx,
61  **tb,perigeeSurface,
62  Trk::anyDirection, true,
63  Trk::pion).release();
64  }//end of extrapolation block
65 
66  if(perigee)
67  {
68  double trkZ0 =perigee->parameters()[Trk::z0];
69  mapOfZ0.insert(std::map<double, int>::value_type(trkZ0,j));
70  if (reference)
71  {
72  delete perigee;
73  perigee=nullptr;
74  }
75  }
76  else ATH_MSG_WARNING("This track particle has no perigee state. Not egligible for sorting. Will NOT be written to the sorted vector");
77  ++j;
78  }//end of loop over all the tracks
79 
80  //creating an output vector, filling it and returning
81  std::vector<int> result(0);
82  std::map<double, int>::const_iterator mb = mapOfZ0.begin();
83  std::map<double, int>::const_iterator me = mapOfZ0.end();
84  for(;mb!=me;++mb)
85  {
86  result.push_back((*mb).second);
87  }
88  return result;
89  }//end of sorting method
90 
91  std::vector<int> InDetTrackZ0SortingTool::sortedIndex(const std::vector<const xAOD::TrackParticle*>& tracks,const xAOD::Vertex * reference) const
92  {
93  const EventContext& ctx = Gaudi::Hive::currentContext();
94  std::map<double, int> mapOfZ0;
95  std::vector<const xAOD::TrackParticle*>::const_iterator tb = tracks.begin();
96  std::vector<const xAOD::TrackParticle*>::const_iterator te = tracks.end();
97  unsigned int j=0;
98 
99  for(;tb != te ;++tb)
100  {
101  const Trk::TrackParameters * perigee = nullptr;
102 
103  //here we want to make an extrapolation
104  Trk::PerigeeSurface perigeeSurface(reference->position());
105  perigee = m_extrapolator->extrapolate(ctx,
106  (*tb)->perigeeParameters(),
107  perigeeSurface,
108  Trk::anyDirection, true,
109  Trk::pion).release();
110 
111  if(perigee)
112  {
113  double trkZ0 = perigee->parameters()[Trk::z0];
114  mapOfZ0.insert(std::map<double, int>::value_type(trkZ0,j));
115  delete perigee;
116  perigee = nullptr;
117  }else{
118  ATH_MSG_WARNING("This track particle has no perigee state. Not egligible for sorting. Will NOT be written to the sorted vector");
119  }//end of perigee existance check
120  ++j;
121  }//end of loop over all track particle base's
122 
123  //creating an output vector, filling it and returning
124  std::vector<int> result(0);
125 
126  //sorted part
127  std::map<double, int>::const_iterator mb = mapOfZ0.begin();
128  std::map<double, int>::const_iterator me = mapOfZ0.end();
129  for(;mb!=me;++mb) result.push_back((*mb).second);
130 
131  return result;
132  }
133 
134 }
Trk::anyDirection
@ anyDirection
Definition: PropDirection.h:22
Trk::Vertex
Definition: Tracking/TrkEvent/VxVertex/VxVertex/Vertex.h:26
get_generator_info.result
result
Definition: get_generator_info.py:21
python.PerfMonSerializer.p
def p
Definition: PerfMonSerializer.py:743
TrackParameters.h
InDet::InDetTrackZ0SortingTool::initialize
virtual StatusCode initialize() override
Definition: InDetTrackZ0SortingTool.cxx:14
InDet::InDetTrackZ0SortingTool::m_extrapolator
ToolHandle< Trk::IExtrapolator > m_extrapolator
Definition: InDetTrackZ0SortingTool.h:62
Trk::PerigeeSurface
Definition: PerigeeSurface.h:43
AthCommonDataStore< AthCommonMsg< AlgTool > >::declareProperty
Gaudi::Details::PropertyBase & declareProperty(Gaudi::Property< T > &t)
Definition: AthCommonDataStore.h:145
InDet
DUMMY Primary Vertex Finder.
Definition: VP1ErrorUtils.h:36
Trk::z0
@ z0
Definition: ParamDefs.h:70
IExtrapolator.h
InDetTrackZ0SortingTool.h
reference
Definition: hcg.cxx:437
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
Track.h
Execution.tb
tb
Definition: Execution.py:15
ATH_MSG_ERROR
#define ATH_MSG_ERROR(x)
Definition: AthMsgStreamMacros.h:33
beamspotman.n
n
Definition: beamspotman.py:731
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
Trk::pion
@ pion
Definition: ParticleHypothesis.h:29
Trk::ParametersBase
Definition: ParametersBase.h:55
Vertex.h
InDet::InDetTrackZ0SortingTool::~InDetTrackZ0SortingTool
~InDetTrackZ0SortingTool()
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
InDet::InDetTrackZ0SortingTool::InDetTrackZ0SortingTool
InDetTrackZ0SortingTool(const std::string &t, const std::string &n, const IInterface *p)
Definition: InDetTrackZ0SortingTool.cxx:27
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
TRT_PAI_physicsConstants::mb
const double mb
1mb to cm2
Definition: TRT_PAI_physicsConstants.h:15
AthAlgTool
Definition: AthAlgTool.h:26
InDet::InDetTrackZ0SortingTool::sortedIndex
std::vector< int > sortedIndex(const std::vector< const Trk::Track * > &tracks, const Trk::Vertex *reference=0) const
Sorting method itself .
Definition: InDetTrackZ0SortingTool.cxx:44