ATLAS Offline Software
TrackDensitySeedFinder.cxx
Go to the documentation of this file.
1 /*
2  Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3 */
4 
5 /*********************************************************************
6  TrackDensitySeedFinder.cxx - Description in header file
7 *********************************************************************/
8 
10 
12 
14 #include "TrkTrack/Track.h"
16 
17 //Amg
19 
20 #include <algorithm>
21 
22 namespace Trk
23 {
24 
25  TrackDensitySeedFinder::TrackDensitySeedFinder(const std::string& t, const std::string& n, const IInterface* p) :
26  base_class(t,n,p)
27  {
28  }
29 
30 
32  = default;
33 
34 
36  {
38  ATH_MSG_DEBUG("Initialize successful");
39  return StatusCode::SUCCESS;
40  }
41 
43  {
44  ATH_MSG_DEBUG("Finalize successful");
45  return StatusCode::SUCCESS;
46  }
47 
48  Amg::Vector3D TrackDensitySeedFinder::findSeed(const std::vector<const Trk::Track*> & VectorTrk,
49  const xAOD::Vertex * constraint) const
50  {
51 
52  //create perigees from track list
53  std::vector<const TrackParameters*> perigeeList;
54 
55  std::vector<const Trk::Track*>::const_iterator begin=VectorTrk.begin();
56  std::vector<const Trk::Track*>::const_iterator end=VectorTrk.end();
57 
58  for (std::vector<const Trk::Track*>::const_iterator iter=begin;
59  iter!=end;++iter)
60  {
61  perigeeList.push_back((*iter)->perigeeParameters());
62  }
63 
64  //create seed from perigee list
65  return findSeed(perigeeList,constraint);
66  }
67 
68  Amg::Vector3D TrackDensitySeedFinder::findSeed(const std::vector<const Trk::TrackParameters*> & perigeeList,
69  const xAOD::Vertex * constraint) const
70  {
71  double zResult {0.};
72  if ( !perigeeList.empty() )
73  {
74  zResult = m_densityEstimator->globalMaximum (perigeeList);
75  ATH_MSG_DEBUG("Highest density Z position found: " << zResult);
76  }
77  else
78  {
79  ATH_MSG_DEBUG("No tracks with sufficient weight; return z position = 0");
80  }
81 
82  if (constraint)
83  {
84  return Amg::Vector3D(constraint->position().x(), constraint->position().y(), zResult + constraint->position().z());
85  }
86  else
87  {
88  return Amg::Vector3D(0.,0.,zResult);
89  }
90  }
91 
92  // testing find seed with width
93  std::pair<Amg::Vector3D,Amg::MatrixX> TrackDensitySeedFinder::findAnalyticSeed(const std::vector<const Trk::TrackParameters*>& perigeeList, const xAOD::Vertex * constraint ) const{
94  std::pair<double,double> zResult {0.,0.};
95  if ( !perigeeList.empty() )
96  {
97  zResult = m_densityEstimator->globalMaximumWithWidth (perigeeList);
98  ATH_MSG_DEBUG("Highest density Z position found: " << zResult.first << "with width: " << zResult.second);
99  }
100  else
101  {
102  ATH_MSG_DEBUG("No tracks with sufficient weight; return z position = 0");
103  }
104 
105  if (constraint)
106  {
107  Amg::Vector3D positionVector = Amg::Vector3D(constraint->position().x(), constraint->position().y(), zResult.first + constraint->position().z());
108  Amg::MatrixX covarianceMatrix = constraint->covariancePosition() ;
109 
110  ATH_MSG_DEBUG("The vertex seed width is " << zResult.second);
111 
112  // if no seed is found, we get a NaN here.
113  // This should not propagate through the vertex fit.
114  // The upstream code aborts if position[z] == 0, which we need to ensure.
115  // In this case, the cov matrix will not be used.
116  if(std::isnan(zResult.second)){
117  positionVector[2] = 0.;
118  }
119  else covarianceMatrix.fillSymmetric(2,2,std::pow(zResult.second,2.));
120 
121  return std::make_pair(positionVector,covarianceMatrix) ;
122  }
123  else
124  {
125  Amg::Vector3D positionVector = Amg::Vector3D(0.,0.,zResult.first);
126  Amg::MatrixX covarianceMatrix;
127  for(const auto i : {0,1,2} ){
128  for(const auto j : {0,1,2}){
129  covarianceMatrix(i,j)=0;
130  }
131  }
132  return {positionVector,covarianceMatrix};
133  }
134 }
135 
136  std::vector<Amg::Vector3D> TrackDensitySeedFinder::findMultiSeeds(const std::vector<const Trk::Track*>& /* vectorTrk */,
137  const xAOD::Vertex * /* constraint */) const
138  {
139  //implemented to satisfy inheritance but this algorithm only supports one seed at a time
140  ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds");
141  return std::vector<Amg::Vector3D>(0);
142  }
143 
144  std::vector<Amg::Vector3D> TrackDensitySeedFinder::findMultiSeeds(const std::vector<const Trk::TrackParameters*>& /* perigeeList */,
145  const xAOD::Vertex * /* constraint */) const
146  {
147  //implemented to satisfy inheritance but this algorithm only supports one seed at a time
148  ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds");
149  return std::vector<Amg::Vector3D>(0);
150  }
151 
152 
153 }
Trk::TrackDensitySeedFinder::m_densityEstimator
ToolHandle< IVertexTrackDensityEstimator > m_densityEstimator
Definition: TrackDensitySeedFinder.h:92
Amg::MatrixX
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
Definition: EventPrimitives.h:27
TrackParameters.h
PlotCalibFromCool.begin
begin
Definition: PlotCalibFromCool.py:94
Trk::TrackDensitySeedFinder::findMultiSeeds
virtual std::vector< Amg::Vector3D > findMultiSeeds(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds full vector of linearization points from a vector of tracks and returns it as an Amg::Vector3D ...
Definition: TrackDensitySeedFinder.cxx:138
xAOD::Vertex_v1::position
const Amg::Vector3D & position() const
Returns the 3-pos.
read_hist_ntuple.t
t
Definition: read_hist_ntuple.py:5
ParamDefs.h
Trk::TrackDensitySeedFinder::findAnalyticSeed
virtual std::pair< Amg::Vector3D, Amg::MatrixX > findAnalyticSeed(const std::vector< const Trk::TrackParameters * > &perigeeList, const xAOD::Vertex *constraint=0) const override final
Definition: TrackDensitySeedFinder.cxx:95
mergePhysValFiles.end
end
Definition: DataQuality/DataQualityUtils/scripts/mergePhysValFiles.py:93
Track.h
GeoPrimitives.h
Trk::TrackDensitySeedFinder::finalize
virtual StatusCode finalize() override
Definition: TrackDensitySeedFinder.cxx:44
python.utils.AtlRunQueryDQUtils.p
p
Definition: AtlRunQueryDQUtils.py:210
lumiFormat.i
int i
Definition: lumiFormat.py:85
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
ATH_CHECK
#define ATH_CHECK
Definition: AthCheckMacros.h:40
Trk::TrackDensitySeedFinder::~TrackDensitySeedFinder
virtual ~TrackDensitySeedFinder()
Trk
Ensure that the ATLAS eigen extensions are properly loaded.
Definition: FakeTrackBuilder.h:9
SeedFinderParamDefs.h
Amg::Vector3D
Eigen::Matrix< double, 3, 1 > Vector3D
Definition: GeoPrimitives.h:47
TrackDensitySeedFinder.h
xAOD::Vertex_v1
Class describing a Vertex.
Definition: Vertex_v1.h:42
ATH_MSG_WARNING
#define ATH_MSG_WARNING(x)
Definition: AthMsgStreamMacros.h:32
Trk::TrackDensitySeedFinder::initialize
virtual StatusCode initialize() override
Definition: TrackDensitySeedFinder.cxx:37
Trk::TrackDensitySeedFinder::TrackDensitySeedFinder
TrackDensitySeedFinder(const std::string &t, const std::string &n, const IInterface *p)
Definition: TrackDensitySeedFinder.cxx:27
pow
constexpr int pow(int base, int exp) noexcept
Definition: ap_fixedTest.cxx:15
Trk::TrackDensitySeedFinder::findSeed
virtual Amg::Vector3D findSeed(const std::vector< const Trk::Track * > &vectorTrk, const xAOD::Vertex *constraint=0) const override final
Finds a linearization point out of a vector of tracks and returns it as an Amg::Vector3D object.
Definition: TrackDensitySeedFinder.cxx:50