ATLAS Offline Software
Loading...
Searching...
No Matches
AdaptiveVertexFitter.cxx
Go to the documentation of this file.
1/*
2 Copyright (C) 2002-2026 CERN for the benefit of the ATLAS collaboration
3*/
4
5
6/***************************************************************************
7 AdaptiveVertexFitter.cxx - Description in header file
8 ***************************************************************************/
9
11
20
21//xAOD includes
22#include "xAODTracking/Vertex.h"
25
26namespace Trk
27{
28
29 AdaptiveVertexFitter::AdaptiveVertexFitter(const std::string& t, const std::string& n, const IInterface* p) :
30 base_class(t,n,p),
33 m_initialError(0.0001),
34 m_onlyzseed(false),
35 m_doSmoothing(true)
36 {
37 declareProperty("MaxIterations", m_maxIterations);
38 declareProperty("MaxDistToLinPoint", m_maxDistToLinPoint);
39 declareProperty("InitialError",m_initialError);
40 declareProperty("onlyzseed",m_onlyzseed);
41 declareProperty("DoSmoothing",m_doSmoothing);
42 declareInterface<IVertexFitter>(this);
43 }
44
46
48 {
49 StatusCode s = AlgTool::initialize();
50 if (s.isFailure())
51 {
52 msg(MSG::FATAL) << "AlgTool::initialize() failed" << endmsg;
53 return StatusCode::FAILURE;
54 }
55 if ( m_SeedFinder.retrieve().isFailure() ) {
56 msg(MSG::FATAL) << "Failed to retrieve tool " << m_SeedFinder << endmsg;
57 return StatusCode::FAILURE;
58 }
59 msg(MSG::INFO) << "Retrieved tool " << m_SeedFinder << endmsg;
60
61
62 if ( m_LinearizedTrackFactory.retrieve().isFailure() ) {
63 msg(MSG::FATAL) << "Failed to retrieve tool " << m_LinearizedTrackFactory << endmsg;
64 return StatusCode::FAILURE;
65 }
66 msg(MSG::INFO) << "Retrieved tool " << m_LinearizedTrackFactory << endmsg;
67
68
69 if ( m_TrackCompatibilityEstimator.retrieve().isFailure() ) {
70 msg(MSG::FATAL) << "Failed to retrieve tool " << m_TrackCompatibilityEstimator << endmsg;
71 return StatusCode::FAILURE;
72 }
73 msg(MSG::INFO) << "Retrieved tool " << m_TrackCompatibilityEstimator << endmsg;
74
75
76 if ( m_ImpactPoint3dEstimator.retrieve().isFailure() ) {
77 msg(MSG::FATAL) << "Failed to retrieve tool " << m_ImpactPoint3dEstimator << endmsg;
78 return StatusCode::FAILURE;
79 }
80 msg(MSG::INFO) << "Retrieved tool " << m_ImpactPoint3dEstimator << endmsg;
81
82
83 if ( m_VertexUpdator.retrieve().isFailure() ) {
84 msg(MSG::FATAL) << "Failed to retrieve tool " << m_VertexUpdator << endmsg;
85 return StatusCode::FAILURE;
86 }
87 msg(MSG::INFO) << "Retrieved tool " << m_VertexUpdator << endmsg;
88
89
90 //loading smoother in case required
92 {
93 if ( m_VertexSmoother.retrieve().isFailure() ) {
94 msg(MSG::FATAL) << "Failed to retrieve tool " << m_VertexSmoother << endmsg;
95 return StatusCode::FAILURE;
96 }
97 msg(MSG::INFO) << "Retrieved tool " << m_VertexSmoother << endmsg;
98
99 }//end of smoothing options
100
101 if ( m_AnnealingMaker.retrieve().isFailure() ) {
102 msg(MSG::FATAL) << "Failed to retrieve tool " << m_AnnealingMaker << endmsg;
103 return StatusCode::FAILURE;
104 }
105 msg(MSG::INFO) << "Retrieved tool " << m_AnnealingMaker << endmsg;
106
107
108 return StatusCode::SUCCESS;
109 }
110
111
112 std::unique_ptr<xAOD::Vertex>
114 const EventContext& ctx,
115 const std::vector<const Trk::TrackParameters*>& perigeeList,
116 const std::vector<const Trk::NeutralParameters*>& neutralPerigeeList,
117 const xAOD::Vertex& constraint, // initialized to xAOD::Vertex()
118 const Amg::Vector3D& startingPoint, // initialized to Amg::Vector3D()
119 bool IsConstraint, // initialized to false
120 bool IsStartingPoint) const // initialized to false
121 {
122
123 //check the number of tracks
124 if ( (perigeeList.size() + neutralPerigeeList.size())<2 && !IsConstraint ) {
125 msg(MSG::WARNING) << "Not enough tracks (>2) to fit in this event (without constraint)." << endmsg;
126 return nullptr;
127 }
128 if ((perigeeList.size() + neutralPerigeeList.size())<1 && IsConstraint) {
129 msg(MSG::WARNING) << "Not enough tracks (>1) to fit in this event (with constraint)." << endmsg;
130 return nullptr;
131 }
132
133
134 Amg::Vector3D SeedPoint;
135 //now find the best point for seeding and linearization of the tracks
136 if (IsStartingPoint) {
137 SeedPoint=startingPoint;
138 } else {
139 if (perigeeList.size()>1) {
140 if (IsConstraint) {
141 SeedPoint=m_SeedFinder->findSeed(perigeeList,&constraint);
142 } else {
143 SeedPoint=m_SeedFinder->findSeed(perigeeList);
144 }
145 }
146 else if (IsConstraint) {
147 SeedPoint=constraint.position();
148 }
149 else {
150 SeedPoint.setZero();
151 }
152 }
153
154 //in case m_onlyzseed is on, just use only the z component given by the seed finder
155 if (m_onlyzseed&&IsConstraint) {
156 SeedPoint=constraint.position();
157 }
158
159
160 //now create a Global Position with the linearized track and the linearization point
161 //which in this case is taken from the found seed for the vertex
162 //use the linPoint to linearize tracks
163
164 std::vector<VxTrackAtVertex> theLinTracks;
165
166 std::vector<const Trk::TrackParameters*>::const_iterator perigeesBegin=perigeeList.begin();
167 std::vector<const Trk::TrackParameters*>::const_iterator perigeesEnd=perigeeList.end();
168
169 ATH_MSG_DEBUG("Inside fitter with track perigee parameters.");
170 ATH_MSG_DEBUG("Seed point: " << SeedPoint);
171 int myDebugNTrk(0);
172
173 for (std::vector<const Trk::TrackParameters*>::const_iterator perigeesIter=perigeesBegin;perigeesIter!=perigeesEnd;++perigeesIter) {
174 // const MeasuredPerigee* castToMP=dynamic_cast<const MeasuredPerigee*>(*perigeesIter);
175 // if (castToMP==0) {
176 // msg << MSG::ERROR << "Cast to MeasuredPerigee not successfull. Treatment of neutrals not supported. Skipping track..." << endmsg;
177 // continue;
178 // }
179
180 ATH_MSG_DEBUG("Track #" << myDebugNTrk++ << ". TrackParameters: x = " << (*perigeesIter)->position().x() << ", y = "<< (*perigeesIter)->position().y() <<", z = "<< (*perigeesIter)->position().z() << ". Covariance: " << *(*perigeesIter)->covariance());
181
182 VxTrackAtVertex* LinTrackToAdd = new VxTrackAtVertex(0., nullptr, nullptr, (*perigeesIter), nullptr); //TODO: Must think now about when to delete this memory! -David S.
183
184 //m_LinearizedTrackFactory->linearize(*LinTrackToAdd,SeedPoint); why linearize it? maybe you don't need it at all!!!!! <19-05-2006>
185 bool success=m_ImpactPoint3dEstimator->addIP3dAtaPlane(ctx,*LinTrackToAdd,SeedPoint);
186 if (!success)
187 {
188 msg(MSG::DEBUG) << "Adding compatibility to vertex information failed. Newton distance finder didn't converge..." << endmsg;
189 }
190
191 theLinTracks.push_back(*LinTrackToAdd);
192
193 delete LinTrackToAdd; //TODO: is here ok?
194
195 }
196
197 std::vector<const Trk::NeutralParameters*>::const_iterator neutralPerigeesBegin=neutralPerigeeList.begin();
198 std::vector<const Trk::NeutralParameters*>::const_iterator neutralPerigeesEnd =neutralPerigeeList.end();
199
200 ATH_MSG_DEBUG("Inside fitter with neutral perigee parameters.");
201 ATH_MSG_DEBUG("Seed point: " << SeedPoint);
202 int myDebugNNeutral(0);
203 for (std::vector<const Trk::NeutralParameters*>::const_iterator neutralPerigeesIter=neutralPerigeesBegin;neutralPerigeesIter!=neutralPerigeesEnd;++neutralPerigeesIter) {
204
205 ATH_MSG_DEBUG("Neutral #" << myDebugNNeutral++ << ". NeutralParameters: x = " << (*neutralPerigeesIter)->position().x() << ", y = "<< (*neutralPerigeesIter)->position().y() <<", z = "<< (*neutralPerigeesIter)->position().z());
206 ATH_MSG_DEBUG(" Covariance: " << *(*neutralPerigeesIter)->covariance());
207 ATH_MSG_DEBUG(" Momentum: x = " << (*neutralPerigeesIter)->momentum().x() << ", y = "<< (*neutralPerigeesIter)->momentum().y() <<", z = "<< (*neutralPerigeesIter)->momentum().z());
208
209 VxTrackAtVertex* LinTrackToAdd = new VxTrackAtVertex(0., nullptr, nullptr, nullptr, (*neutralPerigeesIter) ); //TODO: Must think now about when to delete this memory! -David S.
210
211 bool success = m_ImpactPoint3dEstimator->addIP3dAtaPlane(ctx,*LinTrackToAdd,SeedPoint);
212 if (!success)
213 {
214 msg(MSG::DEBUG) << "Adding compatibility to vertex information failed. Newton distance finder didn't converge..." << endmsg;
215 }
216
217 theLinTracks.push_back(*LinTrackToAdd);
218
219 delete LinTrackToAdd; //TODO: is here ok?
220 }
221
222
223
224 //Initialize the vertex seed with an arbitrary great error matrix (just starting point,
225 //not really prior information in it)
226 if(msgLvl(MSG::VERBOSE))
227 {
228 msg(MSG::VERBOSE) << "Error at the beginning is set to " << m_initialError << endmsg;
229 }
230
231
232
233
234 xAOD::Vertex ConstraintVertex;
235 ConstraintVertex.makePrivateStore();
236 //use the previous prior vertex info for the initial vertex if there
237 if (IsConstraint ) {
238 ConstraintVertex.setPosition( constraint.position() );
239 ConstraintVertex.setCovariancePosition( constraint.covariancePosition() );
240 ConstraintVertex.setFitQuality( 0., 0. );
241 } else {
242 AmgSymMatrix(3) startingCovMatrix;
243 startingCovMatrix.setIdentity();
244 startingCovMatrix = startingCovMatrix / m_initialError;
245 //now initialize with starting position and covariance matrix
246 ConstraintVertex.setPosition( SeedPoint );
247 ConstraintVertex.setCovariancePosition( startingCovMatrix );
248 ConstraintVertex.setFitQuality( 0., -3. );
249 }
250
251 //now put the linearizedtracks into VxTrackAtVertex
252 return dothefit(ctx,ConstraintVertex,SeedPoint,theLinTracks);
253
254
255 }
256
257 std::unique_ptr<xAOD::Vertex>
259 const EventContext& ctx,
260 const std::vector<const Trk::Track*>& VectorTrk,
261 const xAOD::Vertex& constraint, // initialized to xAOD::Vertex()
262 const Amg::Vector3D& startingPoint, // initialized to Amg::Vector3D()
263 bool IsConstraint, // initialized to false
264 bool IsStartingPoint) const
265 { // initialized to false
266
267 ATH_MSG_DEBUG("Called Adaptive vertex with Trk::Track. N. Tracks = " << VectorTrk.size());
268
269 std::vector<const Trk::TrackParameters*> perigeeList;
270 for (const auto *iter : VectorTrk) {
271 if (std::isnan(iter->perigeeParameters()->parameters()[Trk::d0])) {
272 continue;
273 }
274 perigeeList.push_back(iter->perigeeParameters());
275 }
276
277 std::unique_ptr<xAOD::Vertex> FittedVertex = _fit(ctx,perigeeList,constraint,startingPoint,IsConstraint,IsStartingPoint);
278
279 if (FittedVertex==nullptr) {
280 return FittedVertex;
281 }
282
283 //these following lines are really absurd... Why has this to be the case... <19-06-2006>
284 //We need a link which can be dynamically to a Track or a TrackParticle....... )-:
285
286 const std::vector<const Trk::Track*>::const_iterator trkbegin=VectorTrk.begin();
287 const std::vector<const Trk::Track*>::const_iterator trkend=VectorTrk.end();
288
289 const std::vector<VxTrackAtVertex>::iterator vtxbegin=FittedVertex->vxTrackAtVertex().begin();
290 const std::vector<VxTrackAtVertex>::iterator vtxend=FittedVertex->vxTrackAtVertex().end();
291
292 for (std::vector<const Trk::Track*>::const_iterator trkiter=trkbegin;trkiter!=trkend;++trkiter)
293 {
294 for (std::vector<Trk::VxTrackAtVertex>::iterator vtxiter=vtxbegin;vtxiter!=vtxend;++vtxiter)
295 {
296 if(((*trkiter)->perigeeParameters()->momentum() -
297 (*vtxiter).initialPerigee()->momentum()).mag()< 1e-8 &&
298 ((*trkiter)->perigeeParameters()->position() -
299 (*vtxiter).initialPerigee()->position()).mag()< 1e-8)
300 {
301
303 link.setElement(*trkiter);
304 LinkToTrack * linkTT = new LinkToTrack(link);
305 (*vtxiter).setOrigTrack(linkTT);
306 }
307 }
308 }
309
310 //*******************************************************************
311 // TODO: Starting from a vector of Trk::Tracks, can't store
312 // separately from the vxTrackAtVertex vector the links to the
313 // original tracks in xAOD::Vertex (only links to xAOD::TrackParticles and
314 // xAOD::NeutralParticles can be stored)
315 //*******************************************************************
316
317 return FittedVertex;
318 }
319
320 std::unique_ptr<xAOD::Vertex>
322 const EventContext& ctx,
323 const xAOD::Vertex& ConstraintVertex,
324 const Amg::Vector3D& SeedVertex,
325 std::vector<Trk::VxTrackAtVertex>& myLinTracks) const
326 {
327
328 //now reset the annealing maker
330 m_AnnealingMaker->reset(astate);
331
332 //Count the steps for the fit and the number of relinearizations needed in the fit
333 int num_steps(0);
334
335
336 auto ActualVertex = std::make_unique<xAOD::Vertex>();
337 ActualVertex->makePrivateStore(); // xAOD::VertexContainer will take ownership of AuxStore when ActualVertex is added to it
338 ActualVertex->setPosition( ConstraintVertex.position() );
339 ActualVertex->setCovariancePosition( ConstraintVertex.covariancePosition() / m_AnnealingMaker->getWeight(astate, 1.) );
340 ActualVertex->setFitQuality( ConstraintVertex.chiSquared(), ConstraintVertex.numberDoF() );
341 ActualVertex->vxTrackAtVertex() = myLinTracks;
342 ActualVertex->setVertexType(xAOD::VxType::NotSpecified); // to mimic the initialization present in the old EDM constructor
343
344 Amg::Vector3D NewVertex = SeedVertex;
345
346 Amg::Vector3D ActualSeedPosition = SeedVertex;
347
348 if(msgLvl(MSG::VERBOSE))
349 {
350 msg(MSG::VERBOSE) << "Num max of steps is " << m_maxIterations << endmsg;
351 msg(MSG::VERBOSE) << "m_AnnealingMaker->isEquilibrium() is " << m_AnnealingMaker->isEquilibrium(astate) << endmsg;
352 }
353
354 std::vector<Trk::VxTrackAtVertex>::iterator lintracksBegin = ActualVertex->vxTrackAtVertex().begin();
355 std::vector<Trk::VxTrackAtVertex>::iterator lintracksEnd = ActualVertex->vxTrackAtVertex().end();
356
357 std::vector<Trk::VxTrackAtVertex>::iterator iter;
358
359 bool relinearization = false;
360
361 do {
362
363 ActualVertex->setPosition( ConstraintVertex.position() );
364 ActualVertex->setCovariancePosition( ConstraintVertex.covariancePosition() / m_AnnealingMaker->getWeight(astate, 1.) );
365 ActualVertex->setFitQuality( ConstraintVertex.chiSquared(), ConstraintVertex.numberDoF() );
366
367 if(msgLvl(MSG::DEBUG))
368 {
369 msg(MSG::DEBUG) << "Correction applied to constraint weight is: " << m_AnnealingMaker->getWeight(astate, 1.) << endmsg;
370 }
371
372 //To reweight here through an extrapolation is not ideal, but maybe I'll change this in the future...
373 if(msgLvl(MSG::DEBUG))
374 {
375 msg(MSG::DEBUG) << "New fit step: step number " << num_steps << endmsg;
376 }
377
378 //consider relinearization if you are too far away from the old lin point
379
380
381 relinearization=false;
382 if ( (ActualSeedPosition - SeedVertex).perp() > m_maxDistToLinPoint ) {
383 relinearization=true;
384 if(msgLvl(MSG::DEBUG))
385 {
386 msg(MSG::DEBUG) << "Actual vertex too far away from linearization point: have to linearize tracks again" << endmsg;
387 }
388
389 //collect all measured perigees
390
391 for (iter=lintracksBegin;iter!=lintracksEnd;++iter) {
392 //m_LinearizedTrackFactory->linearize(*iter,ActualPosition);
393 bool success=m_ImpactPoint3dEstimator->addIP3dAtaPlane(ctx,*iter,NewVertex);
394 if (!success)
395 {
396 msg(MSG::DEBUG) << "Adding compatibility to vertex information failed. Newton distance finder didn't converge..." << endmsg;
397 }
398 }
399
400 }
401
402
403 lintracksBegin=ActualVertex->vxTrackAtVertex().begin();
404 lintracksEnd=ActualVertex->vxTrackAtVertex().end();
405
406 //now reweight tracks (find chi2 compatibility with actual vertex position)
407 for (iter=lintracksBegin;iter!=lintracksEnd;++iter) {
408
409 //estimate the compatibility of the track to the vertex and store it in iter->linState()->m_vtxCompatibility
410 m_TrackCompatibilityEstimator->estimate(*iter,NewVertex);
411
412 //use the obtained estimate and ask the Annealing Maker what is the corresponding weight at the actual temperature step
413 iter->setWeight( m_AnnealingMaker->getWeight( astate, iter->vtxCompatibility() ) );
414 if(msgLvl(MSG::VERBOSE))
415 {
416 msg(MSG::VERBOSE) << "Before annealing: " << iter->vtxCompatibility() <<
417 " Annealing RESULT is:" << iter->weight() << " at T: " <<
418 m_AnnealingMaker->actualTemp(astate) << endmsg;
419 }
420
421
422 }
423
424 //now update with all the tracks info
425 for (iter=lintracksBegin;iter!=lintracksEnd;++iter) {
426 if(msgLvl(MSG::VERBOSE))
427 {
428 msg(MSG::VERBOSE) << "Updating vertex with a new track" << endmsg;
429 }
430 try {
431
432 if ( iter->weight() > 1e-3 ) {
433 //now take care if linearization has been done at least once
434 //or if vertex has changed so much so that you need relinearization!
435 if ( iter->linState() == nullptr) {
436 //linearization has not been done so far: do it now!
437 if(msgLvl(MSG::VERBOSE))
438 {
439 msg(MSG::VERBOSE) << "Linearizing track for the first time" << endmsg;
440 }
441
442 m_LinearizedTrackFactory->linearize( *iter, ActualVertex->position() );
443 ATH_MSG_DEBUG( "Linearized track to Seed Point. " << *iter );
444 } else if (relinearization) {
445 //do it again in case of updated vertex too far from previous one
446 if(msgLvl(MSG::VERBOSE))
447 {
448 msg(MSG::VERBOSE) << "Relinearizing track " << endmsg;
449 }
450
451 m_LinearizedTrackFactory->linearize( *iter, NewVertex );
452 ActualSeedPosition=NewVertex;
453 ATH_MSG_DEBUG("Linearized track to new seed Point " << NewVertex << ". " << *iter );
454 }
455 m_VertexUpdator->add(*ActualVertex.get(),*iter);
456 } else {
457 if(msgLvl(MSG::VERBOSE))
458 {
459 msg(MSG::VERBOSE) << "Weight lower than 1e-3, so the track will not be considered anymore" << endmsg;
460 }
461
462 }
463 } catch (...) {
464 msg(MSG::WARNING) << "You have just lost a track" << endmsg;
465 }
466 }
467
468 //show some info about the position
469 if(msgLvl(MSG::DEBUG))
470 {
471 msg(MSG::DEBUG) << "New position x: " << ActualVertex->position().x() << " y: " << ActualVertex->position().y()
472 << " z: " << ActualVertex->position().z() << endmsg;
473 }
474
475
476 NewVertex = ActualVertex->position();
477
478 //now go one step down in the annealing process (lower the temperature - single step)
479 if(msgLvl(MSG::VERBOSE))
480 {
481 msg(MSG::VERBOSE) << "Now calling one step of annealing" << endmsg;
482 }
483
484 m_AnnealingMaker->anneal(astate);
485 num_steps+=1;
486
487 //continue to fit until max iteration number has been reached or "thermal equilibrium"
488 //has been obtained in the annealing process
489
490 } while (num_steps<m_maxIterations && !(m_AnnealingMaker->isEquilibrium(astate)) );
491
492 //Here smooth the vertex (refitting of the track)
493
494 //without smoothing... for the moment...
495 if(m_doSmoothing) {
496 m_VertexSmoother->smooth(*ActualVertex);
497 } else {
498 for (iter=lintracksBegin;iter!=lintracksEnd;++iter) {
499 // const MeasuredPerigee* castToMP=dynamic_cast<const MeasuredPerigee*>(iter->initialPerigee());
500 // if (castToMP==0) {
501 // msg(MSG::WARNING) << "Couldn't cast a track to MeasuredPerigee to smooth it. Neutrals not supported. " <<
502 // " Skipping track. .. " << endmsg;
503 // continue;
504 // }
505 if ( iter->initialPerigee() )
506 iter->setPerigeeAtVertex( ( iter->initialPerigee() )->clone() );
507 else if ( iter->initialNeutralPerigee() )
508 iter->setPerigeeAtVertex( ( iter->initialNeutralPerigee() )->clone() );
509 }
510 }
511
512 if(msgLvl(MSG::DEBUG))
513 {
514 msg(MSG::DEBUG) << "chi2: " << ActualVertex->chiSquared()
515 << "the ndf of the vertex is at fit end: " << ActualVertex->numberDoF() << endmsg;
516 }
517
518
519 //Give back all info into the ActualVertex xAOD::Vertex
520 return ActualVertex;
521 }
522
523 std::unique_ptr<xAOD::Vertex>
525 const EventContext& ctx,
526 const std::vector<const Trk::TrackParameters*>& perigeeList,
527 const std::vector<const Trk::NeutralParameters*>& neutralPerigeeList,
528 const Amg::Vector3D& startingPoint) const
529 {
530
531 return _fit(ctx,perigeeList,neutralPerigeeList,xAOD::Vertex(),startingPoint,false,true);
532 }
533
534 std::unique_ptr<xAOD::Vertex>
536 const EventContext& ctx,
537 const std::vector<const Trk::TrackParameters*>& perigeeList,
538 const std::vector<const Trk::NeutralParameters*>& neutralPerigeeList,
539 const xAOD::Vertex& constraint) const
540 {
541 return _fit(ctx,perigeeList,neutralPerigeeList,constraint,Amg::Vector3D::Zero(),true);
542 }
543
544 std::unique_ptr<xAOD::Vertex>
546 const EventContext& ctx,
547 const std::vector<const Trk::TrackParameters*>& perigeeList,
548 const std::vector<const Trk::NeutralParameters*>& neutralPerigeeList,
549 const xAOD::Vertex& constraint,
550 const Amg::Vector3D& startingPoint) const
551 {
552 return _fit(ctx,perigeeList,neutralPerigeeList,constraint,startingPoint,true,true);
553 }
554
555 std::unique_ptr<xAOD::Vertex>
557 const EventContext& ctx,
558 const std::vector<const Trk::TrackParameters*>& perigeeList,
559 const std::vector<const Trk::NeutralParameters*>& neutralPerigeeList) const
560 {
561 return _fit(ctx,perigeeList,neutralPerigeeList,xAOD::Vertex(),Amg::Vector3D(),false,false);
562 }
563
564 std::unique_ptr<xAOD::Vertex>
566 const EventContext& ctx,
567 const std::vector<const Trk::TrackParameters*>& perigeeList,
568 const Amg::Vector3D& startingPoint) const
569 {
570 const std::vector<const Trk::NeutralParameters*> neutralPerigeeList;
571 return fit(ctx, perigeeList, neutralPerigeeList, startingPoint);
572 }
573
574 std::unique_ptr<xAOD::Vertex>
576 const EventContext& ctx,
577 const std::vector<const Trk::TrackParameters*>& perigeeList,
578 const xAOD::Vertex& constraint) const
579 {
580 const std::vector<const Trk::NeutralParameters*> neutralPerigeeList;
581 return fit(ctx, perigeeList, neutralPerigeeList, constraint);
582 }
583
584 std::unique_ptr<xAOD::Vertex>
586 const EventContext& ctx,
587 const std::vector<const Trk::TrackParameters*>& perigeeList,
588 const xAOD::Vertex& constraint,
589 const Amg::Vector3D& startingPoint) const
590 {
591 const std::vector<const Trk::NeutralParameters*> neutralPerigeeList;
592 return fit(ctx, perigeeList, neutralPerigeeList, constraint, startingPoint);
593 }
594
595 std::unique_ptr<xAOD::Vertex>
597 const EventContext& ctx,
598 const std::vector<const Trk::TrackParameters*> & perigeeList) const
599 {
600 const std::vector<const Trk::NeutralParameters*> neutralPerigeeList;
601 return fit(ctx,perigeeList,neutralPerigeeList);
602 }
603
604 std::unique_ptr<xAOD::Vertex>
606 const EventContext& ctx,
607 const std::vector<const Trk::TrackParameters*> & perigeeList,
608 const xAOD::Vertex& constraint,
609 const Amg::Vector3D & startingPoint,
610 bool IsConstraint,
611 bool IsStartingPoint) const
612 {
613 const std::vector<const Trk::NeutralParameters*> neutralPerigeeList;
614 return _fit(ctx, perigeeList, neutralPerigeeList, constraint, startingPoint, IsConstraint, IsStartingPoint);
615 }
616
617//xAOD interfaced methods. Required to un-block the current situation
618// with the xAOD tracking design.
619
620 std::unique_ptr<xAOD::Vertex>
622 const EventContext& ctx,
623 const std::vector<const xAOD::TrackParticle*>& vectorTrk,
624 const std::vector<const xAOD::NeutralParticle*>& vectorNeut,
625 const Amg::Vector3D& startingPoint) const
626 {
627
628 if (vectorTrk.empty()) {
629 msg(MSG::INFO) << "Empty vector of tracks passed" << endmsg;
630 return nullptr;
631 }
632
633 if (vectorNeut.empty()) {
634 msg(MSG::VERBOSE) << "Empty vector of neutrals passed" << endmsg;
635 }
636
637 // making a list of perigee out of the vector of tracks
638 std::vector<const Trk::TrackParameters*> measuredPerigees;
639
640 for (const auto *i : vectorTrk) {
641 const Trk::TrackParameters* tmpMeasPer = &(i->perigeeParameters());
642
643 if (tmpMeasPer != nullptr)
644 measuredPerigees.push_back(tmpMeasPer);
645 else
646 msg(MSG::INFO)
647 << "Failed to dynamic_cast this track parameters to perigee"
648 << endmsg; // TODO: Failed to implicit cast the perigee parameters to
649 // track parameters?
650 }
651
652 // making a list of perigee out of the vector of neutrals
653 std::vector<const Trk::NeutralParameters*> measuredNeutralPerigees;
654
655 for (const auto *i : vectorNeut) {
656 const Trk::NeutralParameters* tmpMeasPer = &(i->perigeeParameters());
657
658 if (tmpMeasPer != nullptr)
659 measuredNeutralPerigees.push_back(tmpMeasPer);
660 else
661 msg(MSG::INFO)
662 << "Failed to dynamic_cast this neutral parameters to perigee"
663 << endmsg; // TODO: Failed to implicit cast the perigee parameters to
664 // neutral parameters?
665 }
666
667 std::unique_ptr<xAOD::Vertex> fittedVertex = _fit(
668 ctx,
669 measuredPerigees,
670 measuredNeutralPerigees,
671 xAOD::Vertex(),
672 startingPoint,
673 false,
674 true);
675
676 // assigning the input tracks to the fitted vertex through VxTrackAtVertices
677 if (fittedVertex == nullptr) {
678 return fittedVertex;
679 }
680
681 if (fittedVertex
682 ->vxTrackAtVertexAvailable()) // TODO: I don't think
683 // vxTrackAtVertexAvailable() does the
684 // same thing as a null pointer check!
685 {
686 if (!fittedVertex->vxTrackAtVertex().empty()) {
687 for (unsigned int i = 0; i < vectorTrk.size(); ++i) {
688
690 const xAOD::TrackParticleContainer* cont =
691 dynamic_cast<const xAOD::TrackParticleContainer*>(
692 vectorTrk[i]->container());
693 if (cont) {
694 if (!linkTT->toIndexedElement(*cont, vectorTrk[i]->index())) {
695 msg(MSG::WARNING)
696 << "Failed to set the EL for this particle correctly" << endmsg;
697 }
698 } else {
699 msg(MSG::WARNING)
700 << "Failed to identify a container for this TP" << endmsg;
701 } // end of the dynamic cast check
702
703 // vxtrackatvertex takes ownership!
704 (fittedVertex->vxTrackAtVertex())[i].setOrigTrack(linkTT);
705 } // end of loop for setting orig tracks in.
706
707 for (unsigned int i = 0; i < vectorNeut.size(); ++i) {
710 dynamic_cast<const xAOD::NeutralParticleContainer*>(
711 vectorNeut[i]->container());
712 if (cont) {
713 if (!linkTT->toIndexedElement(*cont, vectorNeut[i]->index())) {
714 msg(MSG::WARNING)
715 << "Failed to set the EL for this particle correctly" << endmsg;
716 }
717 } else {
718 msg(MSG::WARNING)
719 << "Failed to identify a container for this TP" << endmsg;
720 } // end of the dynamic cast check
721
722 // vxtrackatvertex takes ownership!
723 (fittedVertex->vxTrackAtVertex())[i + vectorTrk.size()].setOrigTrack(
724 linkTT);
725 } // end of loop for setting orig neutrals in.
726
727 } // end of protection against unsuccessfull updates (no tracks were
728 // added)
729 } // end of vector of tracks check
730
731 // now set links to xAOD::TrackParticles directly in the xAOD::Vertex
732 unsigned int VTAVsize = fittedVertex->vxTrackAtVertex().size();
733 for (unsigned int i = 0; i < VTAVsize; ++i) {
734 Trk::VxTrackAtVertex* VTAV = &(fittedVertex->vxTrackAtVertex().at(i));
735 // TODO: Will this pointer really hold 0 if no VxTrackAtVertex is found?
736 if (not VTAV) {
737 ATH_MSG_WARNING(" Trying to set link to xAOD::TrackParticle. The "
738 "VxTrackAtVertex is not found");
739 continue;
740 }
741
742 Trk::ITrackLink* trklink = VTAV->trackOrParticleLink();
743
744 // See if the trklink is to an xAOD::TrackParticle
745 Trk::LinkToXAODTrackParticle* linkToXAODTP =
746 dynamic_cast<Trk::LinkToXAODTrackParticle*>(trklink);
747 if (linkToXAODTP) {
748
749 // Now set the new link to the xAOD vertex
750 fittedVertex->addTrackAtVertex(*linkToXAODTP, VTAV->weight());
751
752 } else {
753
754 // See if the trklink is to an xAOD::NeutralParticle
755 Trk::LinkToXAODNeutralParticle* linkToXAODTPneutral =
756 dynamic_cast<Trk::LinkToXAODNeutralParticle*>(trklink);
757 if (!linkToXAODTPneutral) {
759 "Skipping track. Trying to set link to something else than "
760 "xAOD::TrackParticle or xAOD::NeutralParticle.");
761 } else {
762 // Now set the newlink to the new xAOD vertex
763 fittedVertex->addNeutralAtVertex(*linkToXAODTPneutral,
764 VTAV->weight());
765 }
766 }
767 } // end of loop
768
769 return fittedVertex;
770
771 }//end of the xAOD starting point fit method
772
773 std::unique_ptr<xAOD::Vertex>
775 const EventContext& ctx,
776 const std::vector<const xAOD::TrackParticle*>& vectorTrk,
777 const std::vector<const xAOD::NeutralParticle*>& vectorNeut,
778 const xAOD::Vertex& constraint) const
779 {
780
781 if(vectorTrk.empty())
782 {
783 msg(MSG::INFO)<<"Empty vector of tracks passed"<<endmsg;
784 return nullptr;
785 }
786
787 if(vectorNeut.empty())
788 {
789 msg(MSG::INFO)<<"Empty vector of neutrals passed"<<endmsg;
790 }
791
792 //making a list of perigee out of the vector of tracks
793 std::vector<const Trk::TrackParameters*> measuredPerigees;
794
795 for(const auto *i : vectorTrk)
796 {
797 const Trk::TrackParameters * tmpMeasPer = &(i->perigeeParameters());
798
799 if(tmpMeasPer!=nullptr) measuredPerigees.push_back(tmpMeasPer);
800 else msg(MSG::INFO)<<"Failed to dynamic_cast this track parameters to perigee"<<endmsg; //TODO: Failed to implicit cast the perigee parameters to track parameters?
801 }
802
803 //making a list of perigee out of the vector of neutrals
804 std::vector<const Trk::NeutralParameters*> measuredNeutralPerigees;
805
806 for(const auto *i : vectorNeut)
807 {
808 const Trk::NeutralParameters * tmpMeasPer = &(i->perigeeParameters());
809
810 if(tmpMeasPer!=nullptr) measuredNeutralPerigees.push_back(tmpMeasPer);
811 else msg(MSG::INFO)<<"Failed to dynamic_cast this neutral parameters to perigee"<<endmsg; //TODO: Failed to implicit cast the perigee parameters to neutral parameters?
812 }
813
814
815 std::unique_ptr<xAOD::Vertex> fittedVertex = _fit(ctx, measuredPerigees, measuredNeutralPerigees, constraint, Amg::Vector3D(),true);
816
817
818 //assigning the input tracks to the fitted vertex through VxTrackAtVertices
819 {
820 if( fittedVertex->vxTrackAtVertexAvailable() ) // TODO: I don't think vxTrackAtVertexAvailable() does the same thing as a null pointer check
821 {
822 if(!fittedVertex->vxTrackAtVertex().empty())
823 {
824 for(unsigned int i = 0; i <vectorTrk.size(); ++i)
825 {
826
828 const xAOD::TrackParticleContainer* cont = dynamic_cast< const xAOD::TrackParticleContainer* >( vectorTrk[ i ]->container() );
829 if( cont )
830 {
831 if( ! linkTT->toIndexedElement( *cont, vectorTrk[ i ]->index() ) )
832 {
833 msg(MSG::WARNING)<<"Failed to set the EL for this particle correctly"<<endmsg;
834 }
835 } else {
836 msg(MSG::WARNING)<<"Failed to identify a container for this TP"<<endmsg;
837 }//end of the dynamic cast check
838
839
840 // vxtrackatvertex takes ownership!
841 ( fittedVertex->vxTrackAtVertex() )[i].setOrigTrack(linkTT);
842 }//end of loop for setting orig tracks in.
843
844 for(unsigned int i = 0; i <vectorNeut.size(); ++i)
845 {
847 const xAOD::NeutralParticleContainer* cont = dynamic_cast< const xAOD::NeutralParticleContainer* >( vectorNeut[ i ]->container() );
848 if( cont )
849 {
850 if( ! linkTT->toIndexedElement( *cont, vectorNeut[ i ]->index() ) )
851 {
852 msg(MSG::WARNING)<<"Failed to set the EL for this particle correctly"<<endmsg;
853 }
854 } else {
855 msg(MSG::WARNING)<<"Failed to identify a container for this NP"<<endmsg;
856 }//end of the dynamic cast check
857
858 // vxtrackatvertex takes ownership!
859 ( fittedVertex->vxTrackAtVertex() )[vectorTrk.size()+i].setOrigTrack(linkTT);
860 }//end of loop for setting orig neutrals in.
861
862 }//end of protection against unsuccessfull updates (no tracks were added)
863 }//end of vector of tracks check
864 }
865
866
867 //now set links to xAOD::TrackParticles directly in the xAOD::Vertex
868 unsigned int VTAVsize = fittedVertex->vxTrackAtVertex().size();
869 for (unsigned int i = 0 ; i < VTAVsize ; ++i)
870 {
871 Trk::VxTrackAtVertex* VTAV = &( fittedVertex->vxTrackAtVertex().at(i) );
872 //TODO: Will this pointer really hold 0 if no VxTrackAtVertex is found?
873 if (not VTAV){
874 ATH_MSG_WARNING (" Trying to set link to xAOD::TrackParticle. The VxTrackAtVertex is not found");
875 continue;
876 }
877
878 Trk::ITrackLink* trklink = VTAV->trackOrParticleLink();
879
880 // See if the trklink is to an xAOD::TrackParticle
881 Trk::LinkToXAODTrackParticle* linkToXAODTP = dynamic_cast<Trk::LinkToXAODTrackParticle*>(trklink);
882 if (linkToXAODTP)
883 {
884
885 //Now set the new link to the xAOD vertex
886 fittedVertex->addTrackAtVertex(*linkToXAODTP, VTAV->weight());
887
888 } else {
889
890 // See if the trklink is to an xAOD::NeutralParticle
891 Trk::LinkToXAODNeutralParticle* linkToXAODTPneutral = dynamic_cast<Trk::LinkToXAODNeutralParticle*>(trklink);
892 if (!linkToXAODTPneutral) {
893 ATH_MSG_WARNING ("Skipping track. Trying to set link to something else than xAOD::TrackParticle or xAOD::NeutralParticle.");
894 } else {
895 //Now set the new link to the new xAOD vertex
896 fittedVertex->addNeutralAtVertex(*linkToXAODTPneutral, VTAV->weight());
897 }
898
899 }
900 } //end of loop
901
902 return fittedVertex;
903
904 }//end of the xAOD constrained fit method
905
906
907}//end of namespace Trk definitions
Scalar perp() const
perp method - perpendicular length
#define endmsg
#define ATH_MSG_WARNING(x)
#define ATH_MSG_DEBUG(x)
#define AmgSymMatrix(dim)
std::unique_ptr< xAOD::Vertex > _fit(const EventContext &ctx, const std::vector< const Trk::TrackParameters * > &perigeeList, const std::vector< const Trk::NeutralParameters * > &neutralPerigeeList=std::vector< const Trk::NeutralParameters * >(), const xAOD::Vertex &constraint=xAOD::Vertex(), const Amg::Vector3D &startingPoint=Amg::Vector3D(), bool IsConstraint=false, bool IsStartingPoint=false) const
Internal method for fitting a list of TrackParameters and NeutralParameters, with or without constrai...
virtual ~AdaptiveVertexFitter()
destructor
ToolHandle< Trk::IVertexTrackCompatibilityEstimator > m_TrackCompatibilityEstimator
double m_initialError
Initial error in form of diagonal elements of the inverse of the covariance matrix (name is misleadin...
ToolHandle< Trk::IImpactPoint3dEstimator > m_ImpactPoint3dEstimator
bool m_doSmoothing
True if smoothing after fit iterations has to be performed: otherwise the Smoother AlgoTool provided ...
AdaptiveVertexFitter(const std::string &t, const std::string &n, const IInterface *p)
default constructor due to Athena interface
bool m_onlyzseed
Variable is true if seeding has to be performed only on the z direction.
ToolHandle< Trk::IVertexSmoother > m_VertexSmoother
virtual std::unique_ptr< xAOD::Vertex > fit(const EventContext &ctx, const std::vector< const xAOD::TrackParticle * > &vectorTrk, const std::vector< const xAOD::NeutralParticle * > &vectorNeut, const Amg::Vector3D &startingPoint) const override
Interface for xAOD::TrackParticle with starting point.
std::unique_ptr< xAOD::Vertex > dothefit(const EventContext &ctx, const xAOD::Vertex &ConstraintVertex, const Amg::Vector3D &SeedVertex, std::vector< VxTrackAtVertex > &myLinTracks) const
Internal method, called by the two _fit internal functions, in order to perform the fit,...
virtual StatusCode initialize() override
ToolHandle< Trk::IVertexAnnealingMaker > m_AnnealingMaker
ToolHandle< Trk::IVertexSeedFinder > m_SeedFinder
ToolHandle< Trk::IVertexUpdator > m_VertexUpdator
ToolHandle< Trk::IVertexLinearizedTrackFactory > m_LinearizedTrackFactory
double m_maxDistToLinPoint
Maximum distance of linearization point of track to actual fitted vertex before needing to relineariz...
long int m_maxIterations
Number of maximum iterations.
AUTO - An Undocumented Tracking Object.
Definition LinkToTrack.h:20
Element link to XAOD NeutralParticle.
Element link to XAOD TrackParticle.
The VxTrackAtVertex is a common class for all present TrkVertexFitters The VxTrackAtVertex is designe...
double weight(void) const
Information about the weight of track in fit (given back by annealing): weight=ndf/2.
const ITrackLink * trackOrParticleLink(void) const
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.
float numberDoF() const
Returns the number of degrees of freedom of the vertex fit as float.
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
float chiSquared() const
Returns the of the vertex fit as float.
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, 3, 1 > Vector3D
Ensure that the ATLAS eigen extensions are properly loaded.
ParametersBase< NeutralParametersDim, Neutral > NeutralParameters
@ d0
Definition ParamDefs.h:63
ParametersBase< TrackParametersDim, Charged > TrackParameters
@ NotSpecified
Default value, no explicit type set.
NeutralParticleContainer_v1 NeutralParticleContainer
Definition of the current "NeutralParticle container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.
TrackParticleContainer_v1 TrackParticleContainer
Definition of the current "TrackParticle container version".
MsgStream & msg
Definition testRead.cxx:32