227{
228 SG::ReadCondHandle<InDet::BeamSpotData> beamSpotHandle{
m_beamSpotKey, ctx };
229 const InDet::BeamSpotData*
beamSpot = *beamSpotHandle;
230
231
232
233
234 std::vector<Trk::ITrackLink*> origTracks = trackVector;
235 std::vector<Trk::ITrackLink*> seedTracks = trackVector;
236
237
238 std::vector<xAODVertex_pair> myxAODVertices;
239
243 theVertexContainer->setStore(theVertexAuxContainer);
244
245
246
247
251 << "), skipping vertexing and returning only dummy...");
254 dummyxAODVertex);
255
258 beamSpot->beamVtx().covariancePosition());
259 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
261 return std::make_pair(theVertexContainer, theVertexAuxContainer);
262 }
263
264 int iterations = 0;
265 unsigned int seedtracknumber = seedTracks.size();
266
267
269
270
271 std::vector<Trk::ITrackLink*>::iterator seedBegin;
272 std::vector<Trk::ITrackLink*>::iterator seedEnd;
273
274 do {
275
276 seedBegin = seedTracks.begin();
277 seedEnd = seedTracks.end();
278
279 if (seedtracknumber == 0) {
280 ATH_MSG_DEBUG(
" New iteration. No tracks available after track selection "
281 "for seeding. No finding done.");
282 break;
283 }
284
286
287
288
289 std::vector<const Trk::TrackParameters*> perigeeList;
290 for (std::vector<Trk::ITrackLink*>::iterator seedtrkAtVtxIter = seedBegin;
291 seedtrkAtVtxIter != seedEnd;
292 ++seedtrkAtVtxIter) {
293 perigeeList.push_back((*seedtrkAtVtxIter)->parameters());
294 }
295
298 theconstraint =
302 beamSpot->beamVtx().covariancePosition());
304 beamSpot->beamVtx().fitQuality().chiSquared(),
305 beamSpot->beamVtx().fitQuality().doubleNumberDoF());
306 actualVertex =
m_SeedFinder->findSeed(perigeeList, &theconstraint);
307 } else {
310 looseConstraintCovariance.setIdentity();
311 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
316 }
317
319 msg(MSG::DEBUG) <<
" seed at x: " << actualVertex.x()
320 << " at y: " << actualVertex.y()
321 <<
" at z: " << actualVertex.z() <<
endmsg;
322 }
323
324 if (actualVertex.z() == 0.) {
325 break;
326 }
327
328
329 std::vector<const Trk::TrackParameters*> perigeesToFit;
330 std::vector<const Trk::TrackParameters*> perigeesToFitSplitVertex;
331
332 int numberOfTracks(perigeeList.size());
333
334 std::vector<const Trk::TrackParameters*>::const_iterator perigeeListBegin =
335 perigeeList.begin();
336 std::vector<const Trk::TrackParameters*>::const_iterator perigeeListEnd =
337 perigeeList.end();
338
340
341 for (std::vector<const Trk::TrackParameters*>::const_iterator
342 perigeeListIter = perigeeListBegin;
343 perigeeListIter != perigeeListEnd;
344 ++perigeeListIter) {
345 if (numberOfTracks <= 2) {
346 perigeesToFit.push_back(*perigeeListIter);
349 perigeesToFit.push_back(*perigeeListIter);
353
355 perigeesToFit.push_back(*perigeeListIter);
357 } else {
358 perigeesToFitSplitVertex.push_back(*perigeeListIter);
360 }
361 } else {
363 try {
364 std::unique_ptr<Trk::PlaneSurface> mySurface =
366 *perigeeListIter, &actualVertex, distance);
367 } catch (error::ImpactPoint3dEstimatorProblem err) {
368 msg(MSG::WARNING) <<
" ImpactPoint3dEstimator failed to find minimum "
369 "distance between track and vertex seed: "
371 }
372
373 if (distance < 0) {
375 <<
" Distance between track and seed vtx is negative: " <<
distance
377 }
378
380
381
383
384 if (myPerigee && myPerigee->covariance()) {
387 }
388
389 if (error == 0.) {
392 }
393
397 perigeesToFit.push_back(*perigeeListIter);
399 } else {
400 perigeesToFitSplitVertex.push_back(*perigeeListIter);
402 }
403 }
404 }
405 }
406
407 if (perigeesToFit.empty()) {
408 ATH_MSG_DEBUG(
" No good seed found. Exiting search for vertices...");
409 break;
410 }
411
412
413
414
415
416
417 std::unique_ptr<xAOD::Vertex> myxAODVertex;
418 std::unique_ptr<xAOD::Vertex> myxAODSplitVertex;
419
421 myxAODVertex =
m_iVertexFitter->fit(ctx, perigeesToFit, theconstraint);
424 }
426 myxAODSplitVertex =
m_iVertexFitter->fit(ctx, perigeesToFitSplitVertex);
427 }
428
430 int ntracks = 0;
432
433 double ndfSplitVertex = 0.;
434 int ntracksSplitVertex = 0;
436
437 bool goodVertex = myxAODVertex != nullptr &&
440
442 msg(MSG::DEBUG) <<
" xAOD::Vertex is pointer: " << myxAODVertex
443 <<
" ndf = " <<
ndf <<
" ntracks (with weight>0.01) "
444 << ntracks << " beam constraint "
446 }
447
448 if (!goodVertex) {
450 } else {
452
453
454
455 int numberOfAddedTracks = 0;
456
457
458
461
463 ++vxIter) {
464
465
466 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx =
467 (&(*vxIter)->vxTrackAtVertex());
468
469 if (!myVxTracksAtVtx)
470 continue;
471
472 std::vector<Trk::VxTrackAtVertex>::iterator tracksBegin =
473 myVxTracksAtVtx->begin();
474 std::vector<Trk::VxTrackAtVertex>::iterator tracksEnd =
475 myVxTracksAtVtx->end();
476
477 for (std::vector<Trk::VxTrackAtVertex>::iterator tracksIter =
478 tracksBegin;
479 tracksIter != tracksEnd;) {
480
481
482 if ((*tracksIter).weight() > 0.01) {
483 ++tracksIter;
484 continue;
485 }
486
488 (*tracksIter).initialPerigee();
489
490 if (trackPerigee == nullptr) {
492 return std::make_pair(theVertexContainer, theVertexAuxContainer);
493 }
494
495 double chi2_newvtx =
compatibility(*trackPerigee, *myxAODVertex);
496 double chi2_oldvtx =
compatibility(*trackPerigee, *(*vxIter));
497
499
500 if (chi2_newvtx < chi2_oldvtx) {
502 << chi2_oldvtx
503 << ") more compatible to new one (chi2= "
504 << chi2_newvtx << ")");
505
506 perigeesToFit.push_back(trackPerigee);
507
508
509 bool isFound = false;
510
511 std::vector<Trk::ITrackLink*>::iterator origBegin =
512 origTracks.begin();
513 std::vector<Trk::ITrackLink*>::iterator origEnd =
514 origTracks.end();
515
516 for (std::vector<Trk::ITrackLink*>::iterator origIter = origBegin;
517 origIter != origEnd;
518 ++origIter) {
519 if ((*origIter)->parameters() == trackPerigee) {
520 isFound = true;
521 seedTracks.push_back(*origIter);
522 break;
523 }
524 }
525 if (!isFound) {
527 "seed tracks... ");
528 }
529
530 numberOfAddedTracks += 1;
531
533 }
534
535 if (remove) {
536
537
538 tracksIter = myVxTracksAtVtx->erase(tracksIter);
539 tracksBegin = myVxTracksAtVtx->begin();
540 tracksEnd = myVxTracksAtVtx->end();
541 } else {
542 ++tracksIter;
543 }
544 }
545 }
546
547
548
549
550 if (numberOfAddedTracks > 0) {
552 myxAODVertex =
m_iVertexFitter->fit(ctx, perigeesToFit, theconstraint);
555 }
556
558 ntracks = 0;
560
561 goodVertex = myxAODVertex != nullptr &&
564
566 << myxAODVertex << " ndf = " << ndf
567 << " ntracks (with weight>0.01) " << ntracks
568 << " beam constraint "
570
571 if (!goodVertex) {
573 ATH_MSG_DEBUG(
" Adding tracks resulted in an invalid vertex. "
574 "Should be rare. ");
575 }
576 }
577 }
578
579
580 if (goodVertex) {
582 }
583 }
584
585 bool goodSplitVertex = false;
586
588 goodSplitVertex = myxAODSplitVertex != nullptr && ndfSplitVertex > 0 &&
589 ntracksSplitVertex >= 2;
590
592 << myxAODSplitVertex << " ndf = " << ndfSplitVertex
593 << " ntracks (with weight>0.01) " << ntracksSplitVertex);
594
595 if (!goodSplitVertex) {
597 } else {
599 myxAODSplitVertex.get(), perigeesToFitSplitVertex, seedTracks);
600
601 }
602 }
603
605 if (goodVertex) {
606 theVertexContainer->
push_back(std::move(myxAODVertex));
607 }
608 } else {
609 if (goodVertex) {
610
612 theVertexContainer->
push_back(std::move(myxAODVertex));
613 } else {
616 dummyxAODVertex);
617
620 beamSpot->beamVtx().covariancePosition());
622 std::vector<Trk::VxTrackAtVertex>();
624 }
625 if (goodSplitVertex) {
626
628 theVertexContainer->
push_back(std::move(myxAODSplitVertex));
629 } else {
632 dummyxAODVertex);
633
636 beamSpot->beamVtx().covariancePosition());
638 std::vector<Trk::VxTrackAtVertex>();
640 }
641 }
642
643 ++iterations;
644 }
while (seedTracks.size() > 1 && iterations <
m_maxVertices);
645
647 ATH_MSG_DEBUG(
"Reached maximum iterations, have "<<iterations<<
" vertices");
648 }
651 }
652
653
654
655
656
658 if (!theVertexContainer->
empty()) {
664 dummyxAODVertex);
665
668 primaryVtx->covariancePosition());
670 std::vector<Trk::VxTrackAtVertex>();
672 } else {
674 }
675 }
676
677
678 else if (theVertexContainer->
empty()) {
681 dummyxAODVertex);
682
685 beamSpot->beamVtx().covariancePosition());
686 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
688 }
689
690
691 for (
unsigned int i = 0;
i < theVertexContainer->
size() - 1;
i++) {
692
694 " Vtx: " << i <<
" x= " << (*theVertexContainer)[i]->
position().
x()
695 <<
" y= " << (*theVertexContainer)[i]->
position().
y() <<
" z= "
696 << (*theVertexContainer)[i]->
position().
z() <<
" ntracks= "
697 << (*theVertexContainer)[i]->vxTrackAtVertex().
size()
698 <<
" chi2= " << (*theVertexContainer)[i]->
chiSquared()
699 << " ndf = " << (*theVertexContainer)[i]->numberDoF());
700 if (i > 0) {
702 }
703 }
704 }
705
708
709
710 std::vector<Trk::ITrackLink*>::iterator origtrkbegin = origTracks.begin();
711 std::vector<Trk::ITrackLink*>::iterator origtrkend = origTracks.end();
712
714 ++vxIter) {
715 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx =
716 &((*vxIter)->vxTrackAtVertex());
717
718 if (!myVxTracksAtVtx)
719 continue;
720
721 std::vector<Trk::VxTrackAtVertex>::iterator tracksBegin =
722 myVxTracksAtVtx->begin();
723 std::vector<Trk::VxTrackAtVertex>::iterator tracksEnd =
724 myVxTracksAtVtx->end();
725
727
728 for (std::vector<Trk::VxTrackAtVertex>::iterator tracksIter = tracksBegin;
729 tracksIter != tracksEnd;
730 ++tracksIter) {
731
732
733 for (std::vector<Trk::ITrackLink*>::iterator origtrkiter = origtrkbegin;
734 origtrkiter != origtrkend;
735 ++origtrkiter) {
736 if ((*origtrkiter)->parameters() == (*tracksIter).initialPerigee()) {
738
739
740
741 (*tracksIter).setOrigTrack(*origtrkiter);
742
743
744 Trk::LinkToXAODTrackParticle* linkToXAODTP = nullptr;
745 Trk::ITrackLink* tmpLink = (*tracksIter).trackOrParticleLink();
747 linkToXAODTP = static_cast<Trk::LinkToXAODTrackParticle*>(tmpLink);
748 }
749
750
751 if (linkToXAODTP) {
752 (*vxIter)->addTrackAtVertex(*linkToXAODTP, (*tracksIter).weight());
753 }
754
755 origTracks.erase(origtrkiter);
756 origtrkbegin = origTracks.begin();
757 origtrkend = origTracks.end();
758 break;
759 }
760 }
761 if (!found) {
762 ATH_MSG_ERROR(
" Cannot find vector element to fix links (step 4)! ");
763 }
764 }
765 }
766
767 for (std::vector<Trk::ITrackLink*>::iterator origtrkiter = origtrkbegin;
768 origtrkiter != origtrkend;
769 ++origtrkiter) {
770 if ((*origtrkiter) != 0) {
771 delete *origtrkiter;
772 *origtrkiter = 0;
773 }
774 }
775
776 return std::make_pair(theVertexContainer, theVertexAuxContainer);
777}
#define ATH_MSG_WARNING(x)
size_t size() const
Number of registered mappings.
bool msgLvl(const MSG::Level lvl) const
value_type push_back(value_type pElem)
Add an element to the end of the collection.
DataModel_detail::iterator< DataVector > iterator
const_iterator end() const noexcept
Return a const_iterator pointing past the end of the collection.
const_iterator begin() const noexcept
Return a const_iterator pointing at the beginning of the collection.
const T * front() const
Access the first element in the collection as an rvalue.
size_type size() const noexcept
Returns the number of elements in the collection.
bool empty() const noexcept
Returns true if the collection is empty.
virtual ITrackLinkType type() const =0
return the type
void setCovariancePosition(const AmgSymMatrix(3)&covariancePosition)
Sets the vertex covariance matrix.
void setVertexType(VxType::VertexType vType)
Set the type of the vertex.
void setPosition(const Amg::Vector3D &position)
Sets the 3-position.
void setFitQuality(float chiSquared, float numberDoF)
Set the 'Fit Quality' information.
const Amg::Vector3D & position() const
Returns the 3-pos.
Eigen::Matrix< double, Eigen::Dynamic, Eigen::Dynamic > MatrixX
Dynamic Matrix - dynamic allocation.
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
float chiSquared(const U &p)
const Amg::Vector3D & position() const
Method to retrieve the position of the Intersection.
ParametersBase< TrackParametersDim, Charged > TrackParameters
AthConfigFlags beamSpot(AthConfigFlags flags, str instanceName, str recoMode)
@ NoVtx
Dummy vertex. TrackParticle was not used in vertex fit.
VertexAuxContainer_v1 VertexAuxContainer
Definition of the current jet auxiliary container.
VertexContainer_v1 VertexContainer
Definition of the current "Vertex container version".
Vertex_v1 Vertex
Define the latest version of the vertex class.