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
419
424 }
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) {
551 delete myxAODVertex;
552 myxAODVertex = nullptr;
553
558 }
559
561 ntracks = 0;
563
564 goodVertex = myxAODVertex != nullptr &&
567
569 << myxAODVertex << " ndf = " << ndf
570 << " ntracks (with weight>0.01) " << ntracks
571 << " beam constraint "
573
574 if (!goodVertex) {
576 ATH_MSG_DEBUG(
" Adding tracks resulted in an invalid vertex. "
577 "Should be rare. ");
578 }
579 }
580 }
581
582
583 if (goodVertex) {
585 }
586 }
587
588 bool goodSplitVertex = false;
589
591 goodSplitVertex = myxAODSplitVertex != nullptr && ndfSplitVertex > 0 &&
592 ntracksSplitVertex >= 2;
593
595 << myxAODSplitVertex << " ndf = " << ndfSplitVertex
596 << " ntracks (with weight>0.01) " << ntracksSplitVertex);
597
598 if (!goodSplitVertex) {
600 } else {
602 myxAODSplitVertex, perigeesToFitSplitVertex, seedTracks);
603
604 }
605 }
606
608 if (goodVertex) {
609 theVertexContainer->
push_back(myxAODVertex);
610 } else {
611 if (myxAODVertex) {
612 delete myxAODVertex;
613 myxAODVertex = nullptr;
614 }
615 }
616 } else {
617 if (goodVertex) {
618
620 theVertexContainer->
push_back(myxAODVertex);
621 } else {
622 if (myxAODVertex) {
623 delete myxAODVertex;
624 myxAODVertex = nullptr;
625 }
626
629 dummyxAODVertex);
630
633 beamSpot->beamVtx().covariancePosition());
635 std::vector<Trk::VxTrackAtVertex>();
637 }
638 if (goodSplitVertex) {
639
641 theVertexContainer->
push_back(myxAODSplitVertex);
642 } else {
643 if (myxAODSplitVertex) {
644 delete myxAODSplitVertex;
645 myxAODSplitVertex = nullptr;
646 }
647
650 dummyxAODVertex);
651
654 beamSpot->beamVtx().covariancePosition());
656 std::vector<Trk::VxTrackAtVertex>();
658 }
659 }
660
661 ++iterations;
662 }
while (seedTracks.size() > 1 && iterations <
m_maxVertices);
663
665 ATH_MSG_DEBUG(
"Reached maximum iterations, have "<<iterations<<
" vertices");
666 }
669 }
670
671
672
673
674
676 if (!theVertexContainer->
empty()) {
682 dummyxAODVertex);
683
686 primaryVtx->covariancePosition());
688 std::vector<Trk::VxTrackAtVertex>();
690 } else {
692 }
693 }
694
695
696 else if (theVertexContainer->
empty()) {
699 dummyxAODVertex);
700
703 beamSpot->beamVtx().covariancePosition());
704 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
706 }
707
708
709 for (
unsigned int i = 0;
i < theVertexContainer->
size() - 1;
i++) {
710
712 " Vtx: " << i <<
" x= " << (*theVertexContainer)[i]->position().
x()
713 <<
" y= " << (*theVertexContainer)[i]->position().
y() <<
" z= "
714 << (*theVertexContainer)[i]->position().
z() <<
" ntracks= "
715 << (*theVertexContainer)[i]->vxTrackAtVertex().
size()
716 <<
" chi2= " << (*theVertexContainer)[i]->
chiSquared()
717 << " ndf = " << (*theVertexContainer)[i]->numberDoF());
718 if (i > 0) {
720 }
721 }
722 }
723
726
727
728 std::vector<Trk::ITrackLink*>::iterator origtrkbegin = origTracks.begin();
729 std::vector<Trk::ITrackLink*>::iterator origtrkend = origTracks.end();
730
732 ++vxIter) {
733 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx =
734 &((*vxIter)->vxTrackAtVertex());
735
736 if (!myVxTracksAtVtx)
737 continue;
738
739 std::vector<Trk::VxTrackAtVertex>::iterator tracksBegin =
740 myVxTracksAtVtx->begin();
741 std::vector<Trk::VxTrackAtVertex>::iterator tracksEnd =
742 myVxTracksAtVtx->end();
743
745
746 for (std::vector<Trk::VxTrackAtVertex>::iterator tracksIter = tracksBegin;
747 tracksIter != tracksEnd;
748 ++tracksIter) {
749
750
751 for (std::vector<Trk::ITrackLink*>::iterator origtrkiter = origtrkbegin;
752 origtrkiter != origtrkend;
753 ++origtrkiter) {
754 if ((*origtrkiter)->parameters() == (*tracksIter).initialPerigee()) {
756
757
758
759 (*tracksIter).setOrigTrack(*origtrkiter);
760
761
762 Trk::LinkToXAODTrackParticle* linkToXAODTP = nullptr;
763 Trk::ITrackLink* tmpLink = (*tracksIter).trackOrParticleLink();
765 linkToXAODTP = static_cast<Trk::LinkToXAODTrackParticle*>(tmpLink);
766 }
767
768
769 if (linkToXAODTP) {
770 (*vxIter)->addTrackAtVertex(*linkToXAODTP, (*tracksIter).weight());
771 }
772
773 origTracks.erase(origtrkiter);
774 origtrkbegin = origTracks.begin();
775 origtrkend = origTracks.end();
776 break;
777 }
778 }
779 if (!found) {
780 ATH_MSG_ERROR(
" Cannot find vector element to fix links (step 4)! ");
781 }
782 }
783 }
784
785 for (std::vector<Trk::ITrackLink*>::iterator origtrkiter = origtrkbegin;
786 origtrkiter != origtrkend;
787 ++origtrkiter) {
788 if ((*origtrkiter) != 0) {
789 delete *origtrkiter;
790 *origtrkiter = 0;
791 }
792 }
793
794 return std::make_pair(theVertexContainer, theVertexAuxContainer);
795}
#define ATH_MSG_WARNING(x)
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)
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.