ATLAS Offline Software
Loading...
Searching...
No Matches
CrossDistancesSeedFinder.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 CrossDistancesSeedFinder.cxx - Description in header file
7*********************************************************************/
8
9//#define CROSSDISTANCESSEEDFINDER_DEBUG
10
12
14#include "TrkTrack/Track.h"
15
19
22#include <cmath>
23
24
25// Would be nice to use something like Amg::distance instead.
26// But that rounds slightly differently.
27// Do it like this so that results are identical with the pre-MT version.
28namespace {
29 inline double square(const double tosquare) {
30 return std::pow(tosquare,2);
31 }
32 double dist(const std::pair<Amg::Vector3D,Amg::Vector3D>& pairofpos) {
33 Amg::Vector3D diff(pairofpos.first-pairofpos.second);
34 return std::sqrt(square(diff.x())+square(diff.y())+square(diff.z()));
35 }
36}
37
38
39namespace Trk
40{
41
42 CrossDistancesSeedFinder::CrossDistancesSeedFinder(const std::string& t, const std::string& n, const IInterface* p) :
43 base_class(t,n,p),
44 m_useweights(true),
45 m_trackdistcutoff(0.020),
51 {
52 declareProperty("useweights",m_useweights);
53 declareProperty("trackdistcutoff",m_trackdistcutoff);
54 declareProperty("trackdistexppower",m_trackdistexppower);
55 declareProperty("constrainttemp",m_constrainttemp);
56 declareProperty("constraintcutoff",m_constraintcutoff);
57 declareProperty("maximumTracksNoCut",m_maximumTracksNoCut);
58 declareProperty("maximumDistanceCut",m_maximumDistanceCut);
59 }
60
61
63 = default;
64
65
67 {
68 ATH_CHECK( m_mode3dfinder.retrieve() );
69 ATH_CHECK( m_distancefinder.retrieve() );
70 return StatusCode::SUCCESS;
71 }
72
73 Amg::Vector3D CrossDistancesSeedFinder::findSeed(const std::vector<const Trk::Track*> & VectorTrk,const xAOD::Vertex * constraint) const {
74
75
76 //create perigees from track list
77 std::vector<const TrackParameters*> perigeeList;
78 for (const auto *iter : VectorTrk) {
79 if (std::isnan(iter->perigeeParameters()->parameters()[Trk::d0])) {
80 continue;
81 }
82 perigeeList.push_back(iter->perigeeParameters());
83 }
84
85 if (perigeeList.size()<2)
86 {
87 return Amg::Vector3D(0.,0.,0.);
88 }
89
90 //create seed from perigee list
91 return findSeed(perigeeList,constraint);
92
93 }
94
95 Amg::Vector3D CrossDistancesSeedFinder::findSeed(const std::vector<const Trk::TrackParameters*> & perigeeList,const xAOD::Vertex * constraint) const {
96
97 bool useCutOnDistance=false;
98 if (perigeeList.size()>m_maximumTracksNoCut)
99 {
100 useCutOnDistance=true;
101 }
102
103 //now implement the code you already had in the standalone code...
104
105
106 //Calculate and cache the covariance matrix for the constraint
107 AmgSymMatrix(3) weightMatrixPositionConstraint;
108 weightMatrixPositionConstraint.setIdentity(); //very arbitrary
109 if (constraint != nullptr) {
110 weightMatrixPositionConstraint = constraint->covariancePosition().inverse();
111 }
112
113 //Prepare the vector of points, on which the 3d mode has later to be calculated
114 std::vector<PositionAndWeight> CrossingPointsAndWeights;
115 std::vector<Amg::Vector3D> CrossingPoints;
116
117 //Implement here SeedPointFinder algorithm, acting with the track vector....
118 const std::vector<const Trk::TrackParameters*>::const_iterator begin=perigeeList.begin();
119 const std::vector<const Trk::TrackParameters*>::const_iterator end=perigeeList.end();
120
121 for (std::vector<const Trk::TrackParameters*>::const_iterator i=begin;i!=end-1;++i) {
122
123 const Trk::Perigee* MyI=dynamic_cast<const Trk::Perigee*>(*i);
124 if (MyI==nullptr) {
125 ATH_MSG_WARNING( "Neutrals not supported for seeding. Rejecting this track..." );
126 continue;
127 }
128
129 for (std::vector<const Trk::TrackParameters*>::const_iterator j=i+1;j!=end;++j) {
130
131 const Trk::Perigee* MyJ=dynamic_cast<const Trk::Perigee*>(*j);
132 if (MyJ==nullptr) {
133 ATH_MSG_WARNING( "Neutrals not supported for seeding. Rejecting this track..." );
134 continue;
135 }
136
137#ifdef CROSSDISTANCESSEEDFINDER_DEBUG
138
139 ATH_MSG_DEBUG( "Track 1 d0: " << MyI->parameters()[Trk::d0] << " Track2 d0: " << MyJ->parameters()[Trk::d0] );
140 ATH_MSG_DEBUG( "Track 1 z0: " << MyI->parameters()[Trk::z0] << "Track2 z0: " << MyJ->parameters()[Trk::z0] );
141#endif
142
143 try {
144
145 std::optional<ITrkDistanceFinder::TwoPoints> result
146 = m_distancefinder->CalculateMinimumDistance(*MyI,*MyJ);
147 if (!result) { ATH_MSG_DEBUG( "Problem with distance finder: THIS POINT WILL BE SKIPPED!" );
148 }
149 else
150 {
151 //Get the points which connect the minimum distance between the two tracks
152 double distance = dist (result.value());
153#ifdef CROSSDISTANCESSEEDFINDER_DEBUG
154 ATH_MSG_DEBUG( "Point 1 x: " << result->first.x() <<
155 " y: " << result->first.y() <<
156 " z: " << result->first.z() );
157 ATH_MSG_DEBUG( "Point 2 x: " << result->second.x() <<
158 " y: " << result->second.y() <<
159 " z: " << result->second.z() );
160 ATH_MSG_DEBUG( "distance is: " << distance );
161#endif
162
163 Amg::Vector3D thepoint((result->first+result->second)/2.);
164
165 if (m_useweights)
166 {
167 PositionAndWeight thispoint(thepoint,
169
170 ATH_MSG_DEBUG( "distance weight: " << 1./pow(m_trackdistcutoff+distance,m_trackdistexppower) );
171
172 if (constraint!=nullptr) {
173
174 Amg::Vector3D DeltaP(thepoint-constraint->position());
175 Amg::Vector3D DeltaPConv;
176 ATH_MSG_DEBUG( "position x: " << DeltaP.x() << "position y: " << DeltaP.y() << "position z: " << DeltaP.z() );
177 DeltaPConv[0]=DeltaP.x();
178 DeltaPConv[1]=DeltaP.y();
179 DeltaPConv[2]=DeltaP.z();
180
181
182 double chi2=DeltaPConv.transpose()*weightMatrixPositionConstraint*DeltaPConv;
183
184 ATH_MSG_DEBUG( " chi: " << chi2
185 << " beam weight " << 1./(1.+exp((chi2-m_constraintcutoff)/m_constrainttemp)) );
186
187 thispoint.second=thispoint.second*1./(1.+exp((chi2-m_constraintcutoff)/m_constrainttemp));
188
189 }
190 if ((!useCutOnDistance || distance<m_maximumDistanceCut) && thispoint.second > 1e-10)
191 {
192 CrossingPointsAndWeights.push_back(thispoint);
193 }
194 }
195 else
196 {
197 const Amg::Vector3D& thispoint(thepoint);
198 if (!useCutOnDistance || distance<m_maximumDistanceCut)
199 {
200 CrossingPoints.push_back(thispoint);
201 }
202 }
203 }
204 } catch (...) {
205 ATH_MSG_ERROR( "Something wrong in distance calculation: please report..." );
206 }
207 }
208 //to be understood...
209 }
210
211 //Now all points have been collected (N*(N-1)/2) and
212 //the mode has to be calculated
213
214 if (CrossingPoints.empty() && CrossingPointsAndWeights.empty())
215 {
216 return Amg::Vector3D(0,0,0);
217 }
218
219 Amg::Vector3D myresult;
220
221 if (m_useweights)
222 {
223 myresult=m_mode3dfinder->getMode(0, 0, CrossingPointsAndWeights);
224 }
225 else
226 {
227 myresult=m_mode3dfinder->getMode(0, 0, CrossingPoints);
228 }
229
230#ifdef CROSSDISTANCESSEEDFINDER_DEBUG
231 ATH_MSG_INFO( "Resulting mean POINT FOUND: x: " << myresult.x() <<
232 " y: " << myresult.y() <<
233 " z: " << myresult.z() );
234#endif
235
236
237 return myresult;
238
239
240
241
242 }
243
244 std::vector<Amg::Vector3D> CrossDistancesSeedFinder::findMultiSeeds(const std::vector<const Trk::Track*>& /* vectorTrk */,const xAOD::Vertex * /* constraint */) const {
245
246 //implemented to satisfy inheritance but this algorithm only supports one seed at a time
247 ATH_MSG_WARNING( "Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds" );
248 return std::vector<Amg::Vector3D>(0);
249
250 }
251
252 std::vector<Amg::Vector3D> CrossDistancesSeedFinder::findMultiSeeds(const std::vector<const Trk::TrackParameters*>& /* perigeeList */,const xAOD::Vertex * /* constraint */) const {
253
254 //implemented to satisfy inheritance but this algorithm only supports one seed at a time
255 ATH_MSG_WARNING( "Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds" );
256 return std::vector<Amg::Vector3D>(0);
257
258 }
259
260
261}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_INFO(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define AmgSymMatrix(dim)
void diff(const Jet &rJet1, const Jet &rJet2, std::map< std::string, double > varDiff)
Difference between jets - Non-Class function required by trigger.
Definition Jet.cxx:631
constexpr int pow(int base, int exp) noexcept
ToolHandle< ITrkDistanceFinder > m_distancefinder
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.
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 ...
ToolHandle< IMode3dFinder > m_mode3dfinder
CrossDistancesSeedFinder(const std::string &t, const std::string &n, const IInterface *p)
virtual StatusCode initialize() override
const Amg::Vector3D & position() const
Returns the 3-pos.
double chi2(TH1 *h0, TH1 *h1)
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
std::pair< Amg::Vector3D, double > PositionAndWeight
ParametersT< TrackParametersDim, Charged, PerigeeSurface > Perigee
@ d0
Definition ParamDefs.h:63
@ z0
Definition ParamDefs.h:64
Vertex_v1 Vertex
Define the latest version of the vertex class.