ATLAS Offline Software
Loading...
Searching...
No Matches
IndexedCrossDistancesSeedFinder.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
3*/
4//Author: Lianyou Shan <lianyou.shan@cern.ch>
5/*********************************************************************
6 IndexedCrossDistancesSeedFinder.cxx - Description in header file
7*********************************************************************/
8
9//#define CROSSDISTANCESSEEDFINDER_DEBUG
10
13#include "TrkTrack/Track.h"
14
18
21#include <cmath>
22
23
24namespace Trk
25{
26
27 IndexedCrossDistancesSeedFinder::IndexedCrossDistancesSeedFinder(const std::string& t, const std::string& n, const IInterface* p) :
28 base_class(t,n,p),
29 m_useweights(true),
30 m_trackdistcutoff(0.020),
36 {
37 declareProperty("useweights",m_useweights);
38 declareProperty("trackdistcutoff",m_trackdistcutoff);
39 declareProperty("trackdistexppower",m_trackdistexppower);
40 declareProperty("constrainttemp",m_constrainttemp);
41 declareProperty("constraintcutoff",m_constraintcutoff);
42 declareProperty("maximumTracksNoCut",m_maximumTracksNoCut);
43 declareProperty("maximumDistanceCut",m_maximumDistanceCut);
44 }
45
46
48 = default;
49
50
52 {
53 ATH_CHECK( m_mode3dfinder.retrieve() );
54 ATH_CHECK( m_distancefinder.retrieve() );
55 return StatusCode::SUCCESS;
56 }
57
58
60 IndexedCrossDistancesSeedFinder::findSeed(const std::vector<const Trk::Track*> & /*VectorTrk*/,
61 const xAOD::Vertex * /*constraint*/) const
62 {
63 ATH_MSG_ERROR ("Need to supply a primary vertex.");
64 return Amg::Vector3D(0.,0.,0.);
65 }
66
67
69 IndexedCrossDistancesSeedFinder::findSeed(const std::vector<const Trk::TrackParameters*> & /*perigeeList*/,
70 const xAOD::Vertex * /*constraint*/) const
71 {
72 ATH_MSG_ERROR ("Need to supply a primary vertex.");
73 return Amg::Vector3D(0.,0.,0.);
74 }
75
76
79 const double vy,
80 const std::vector<const Trk::TrackParameters*>& perigeeList,
81 const xAOD::Vertex* constraint) const
82 {
83 std::unique_ptr<Trk::IMode3dInfo> info;
84 return findSeed (vx, vy, info, perigeeList, constraint);
85 }
86
87
90 const double vy,
91 std::unique_ptr<Trk::IMode3dInfo>& info,
92 const std::vector<const Trk::TrackParameters*>& perigeeList,
93 const xAOD::Vertex* constraint) const
94 {
95 ATH_MSG_DEBUG( " Enter IndexedCrossDistancesSeedFinder " );
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 //Calculate and cache the covariance matrix for the constraint
106 AmgSymMatrix(3) weightMatrixPositionConstraint;
107 weightMatrixPositionConstraint.setIdentity(); //very arbitrary
108 if (constraint != nullptr) {
109 weightMatrixPositionConstraint = constraint->covariancePosition().inverse();
110 }
111
112 //Prepare the vector of points, on which the 3d mode has later to be calculated
113 std::vector<PositionAndWeight> CrossingPointsAndWeights;
114 std::vector<Amg::Vector3D> CrossingPoints;
115
116 //Implement here SeedPointFinder algorithm, acting with the track vector....
117 const std::vector<const Trk::TrackParameters*>::const_iterator begin=perigeeList.begin();
118 const std::vector<const Trk::TrackParameters*>::const_iterator end=perigeeList.end();
119
120 ATH_MSG_DEBUG( " Loop pairs of TrackParameters for modes " );
121
122 std::vector< std::pair <int, int> > trkidx ;
123 int idx_i = 0 ;
124 for (std::vector<const Trk::TrackParameters*>::const_iterator i=begin;i!=end-1;++i)
125 {
126 idx_i ++ ;
127 const Trk::Perigee* MyI=dynamic_cast<const Trk::Perigee*>(*i);
128 if (MyI==nullptr) {
129 ATH_MSG_WARNING( "Neutrals not supported for seeding. Rejecting this track..." );
130 continue;
131 }
132
133 int idx_j = idx_i ; // 1 has been added to idx_i
134 for (std::vector<const Trk::TrackParameters*>::const_iterator j=i+1;j!=end;++j++) {
135
136 idx_j ++ ;
137 const Trk::Perigee* MyJ=dynamic_cast<const Trk::Perigee*>(*j);
138
139 if (MyJ==nullptr) {
140 ATH_MSG_WARNING( "Neutrals not supported for seeding. Rejecting this track..." );
141 continue;
142 }
143
144
145 try {
146
147 std::optional<ITrkDistanceFinder::TwoPoints> result
148 = m_distancefinder->CalculateMinimumDistance(*MyI,*MyJ);
149 if (!result) {ATH_MSG_DEBUG("Problem with distance finder: THIS POINT WILL BE SKIPPED!");
150 }
151 else
152 {
153 //Get the points which connect the minimum distance between the two tracks
154 double distance = Amg::distance (result->first, result->second);
155#ifdef CROSSDISTANCESSEEDFINDER_DEBUG
156 ATH_MSG_DEBUG("Point 1 x: " << result->first.x() <<
157 " y: " << result->first.y() <<
158 " z: " << result->first.z() );
159 ATH_MSG_DEBUG("Point 2 x: " << result->second.x() <<
160 " y: " << result->second.y() <<
161 " z: " << result->second.z() );
162 ATH_MSG_DEBUG("distance is: " << distance );
163#endif
164
165 Amg::Vector3D thepoint((result->first+result->second)/2.);
166
167 if (m_useweights)
168 {
169 PositionAndWeight thispoint(thepoint,
171
172 ATH_MSG_VERBOSE("distance weight: " << 1./pow(m_trackdistcutoff+distance,m_trackdistexppower) );
173
174 if (constraint!=nullptr) {
175
176 Amg::Vector3D DeltaP(thepoint-constraint->position());
177 Amg::Vector3D DeltaPConv;
178 ATH_MSG_DEBUG("position x: " << DeltaP.x() << "position y: " << DeltaP.y() << "position z: " << DeltaP.z() );
179 DeltaPConv[0]=DeltaP.x();
180 DeltaPConv[1]=DeltaP.y();
181 DeltaPConv[2]=DeltaP.z();
182
183
184 double chi2=DeltaPConv.transpose()*weightMatrixPositionConstraint*DeltaPConv;
185
186 ATH_MSG_DEBUG(" chi: " << chi2 <<
187 " beam weight " << 1./(1.+exp((chi2-m_constraintcutoff)/m_constrainttemp)) );
188
189 thispoint.second=thispoint.second*1./(1.+exp((chi2-m_constraintcutoff)/m_constrainttemp));
190
191 }
192
193 if ((!useCutOnDistance || distance<m_maximumDistanceCut) && thispoint.second > 1e-10)
194 {
195 CrossingPointsAndWeights.push_back( thispoint );
196
197 trkidx.emplace_back( idx_i - 1 , idx_j - 1 );
198
199 ATH_MSG_VERBOSE( " crossing with track pair : " << idx_i - 1 <<" "
200 << MyI->parameters()[Trk::d0] <<" "<< idx_j - 1 <<" "
201 << MyJ->parameters()[Trk::d0] );
202
203 }
204 }
205 else
206 {
207 const Amg::Vector3D& thispoint(thepoint);
208 if ( !useCutOnDistance || distance<m_maximumDistanceCut )
209 {
210 CrossingPoints.push_back( thispoint );
211 }
212 }
213 }
214 } catch (...) {
215 ATH_MSG_ERROR("Something wrong in distance calculation: please report..." );
216 }
217 }
218 //to be understood...
219 }
220
221 //Now all points have been collected (N*(N-1)/2) and
222 //the mode has to be calculated
223
224 if ( ( CrossingPoints.empty() && ! m_useweights )
225 || ( m_useweights && CrossingPointsAndWeights.empty() ) )
226 {
227 return Amg::Vector3D(0,0,0);
228 }
229
230 ATH_MSG_DEBUG(" crossing points prepared : " << CrossingPointsAndWeights.size() );
231
232 Amg::Vector3D myresult;
233
234 if (m_useweights)
235 {
236 myresult=m_mode3dfinder->getMode(vx, vy, CrossingPointsAndWeights, info);
237 }
238 else
239 {
240 myresult=m_mode3dfinder->getMode(vx, vy, CrossingPoints, info);
241 }
242
243 info->setTrkidx (std::move (trkidx));
244 ATH_MSG_DEBUG(" 3D modes found ! " );
245
246 return myresult;
247
248 }
249
250
252 const std::vector<const Trk::Track*>& /* vectorTrk */,const xAOD::Vertex * /* constraint */) const
253{
254
255 //implemented to satisfy inheritance but this algorithm only supports one seed at a time
256 ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds" );
257 return std::vector<Amg::Vector3D>(0);
258}
259
261 const std::vector<const Trk::TrackParameters*>& /* perigeeList */,const xAOD::Vertex * /* constraint */) const
262{
263
264 //implemented to satisfy inheritance but this algorithm only supports one seed at a time
265 ATH_MSG_WARNING("Multi-seeding requested but seed finder not able to operate in that mode, returning no seeds" );
266 return std::vector<Amg::Vector3D>(0);
267
268}
269
270
271}
#define ATH_CHECK
Evaluate an expression and check for errors.
#define ATH_MSG_ERROR(x)
#define ATH_MSG_VERBOSE(x)
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define AmgSymMatrix(dim)
constexpr int pow(int base, int exp) noexcept
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.
IndexedCrossDistancesSeedFinder(const std::string &t, const std::string &n, const IInterface *p)
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 ...
const Amg::Vector3D & position() const
Returns the 3-pos.
double chi2(TH1 *h0, TH1 *h1)
float distance(const Amg::Vector3D &p1, const Amg::Vector3D &p2)
calculates the distance between two point in 3D space
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
Vertex_v1 Vertex
Define the latest version of the vertex class.