53 declareInterface<IVertexFinder>(
this);
62 ATH_MSG_FATAL(
" Split vertices cannot be obtained if beam spot constraint "
63 "is true! Change settings...");
64 return StatusCode::FAILURE;
70 return StatusCode::FAILURE;
75 return StatusCode::FAILURE;
80 return StatusCode::FAILURE;
85 return StatusCode::FAILURE;
92 return StatusCode::FAILURE;
99 return StatusCode::SUCCESS;
103 struct xAODVertex_pair
118 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
124 " Number of input tracks before track selection: " << trackTES->
size());
129 std::vector<Trk::ITrackLink*> selectedTracks;
133 bool selectionPassed;
134 for (TrackDataVecIter itr = (*trackTES).begin(); itr != (*trackTES).end();
140 static_cast<bool>(
m_trkFilter->accept(**itr, &beamPosition));
143 selectionPassed =
static_cast<bool>(
m_trkFilter->accept(**itr, &
null));
145 if (selectionPassed) {
150 selectedTracks.push_back(linkTT);
155 <<
" survived the preselection.");
157 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
158 returnContainers =
findVertex(ctx, selectedTracks);
160 return returnContainers;
163 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
165 const EventContext& ctx,
168 ATH_MSG_DEBUG(
" Number of input tracks before track selection: "
169 << trackParticles->
size());
174 std::vector<Trk::ITrackLink*> selectedTracks;
176 using TrackParticleDataVecIter =
179 bool selectionPassed;
180 for (TrackParticleDataVecIter itr = trackParticles->
begin();
181 itr != trackParticles->
end();
189 beamSpot->beamVtx().covariancePosition());
191 static_cast<bool>(
m_trkFilter->accept(**itr, &beamPosition));
198 vertexError.setZero();
199 null.setCovariancePosition(vertexError);
200 selectionPassed =
static_cast<bool>(
m_trkFilter->accept(**itr, &
null));
203 if (selectionPassed) {
209 selectedTracks.push_back(linkTT);
214 << selectedTracks.size()
215 <<
" survived the preselection.");
217 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
218 returnContainers =
findVertex(ctx, selectedTracks);
220 return returnContainers;
223 std::pair<xAOD::VertexContainer*, xAOD::VertexAuxContainer*>
225 const EventContext& ctx,
226 const std::vector<Trk::ITrackLink*>& trackVector)
const
234 std::vector<Trk::ITrackLink*> origTracks = trackVector;
235 std::vector<Trk::ITrackLink*> seedTracks = trackVector;
238 std::vector<xAODVertex_pair> myxAODVertices;
243 theVertexContainer->setStore(theVertexAuxContainer);
251 <<
"), skipping vertexing and returning only dummy...");
258 beamSpot->beamVtx().covariancePosition());
259 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
261 return std::make_pair(theVertexContainer, theVertexAuxContainer);
265 unsigned int seedtracknumber = seedTracks.size();
276 seedBegin = seedTracks.begin();
277 seedEnd = seedTracks.end();
279 if (seedtracknumber == 0) {
280 ATH_MSG_DEBUG(
" New iteration. No tracks available after track selection "
281 "for seeding. No finding done.");
289 std::vector<const Trk::TrackParameters*> perigeeList;
291 seedtrkAtVtxIter != seedEnd;
292 ++seedtrkAtVtxIter) {
293 perigeeList.push_back((*seedtrkAtVtxIter)->parameters());
302 beamSpot->beamVtx().covariancePosition());
304 beamSpot->beamVtx().fitQuality().chiSquared(),
305 beamSpot->beamVtx().fitQuality().doubleNumberDoF());
306 actualVertex =
m_SeedFinder->findSeed(perigeeList, &theconstraint);
310 looseConstraintCovariance.setIdentity();
311 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
320 <<
" at y: " << actualVertex.y()
321 <<
" at z: " << actualVertex.z() <<
endmsg;
324 if (actualVertex.z() == 0.) {
329 std::vector<const Trk::TrackParameters*> perigeesToFit;
330 std::vector<const Trk::TrackParameters*> perigeesToFitSplitVertex;
332 int numberOfTracks(perigeeList.size());
334 std::vector<const Trk::TrackParameters*>::const_iterator perigeeListBegin =
336 std::vector<const Trk::TrackParameters*>::const_iterator perigeeListEnd =
341 for (std::vector<const Trk::TrackParameters*>::const_iterator
342 perigeeListIter = perigeeListBegin;
343 perigeeListIter != perigeeListEnd;
345 if (numberOfTracks <= 2) {
346 perigeesToFit.push_back(*perigeeListIter);
349 perigeesToFit.push_back(*perigeeListIter);
355 perigeesToFit.push_back(*perigeeListIter);
358 perigeesToFitSplitVertex.push_back(*perigeeListIter);
364 std::unique_ptr<Trk::PlaneSurface> mySurface =
366 *perigeeListIter, &actualVertex,
distance);
368 msg(MSG::WARNING) <<
" ImpactPoint3dEstimator failed to find minimum "
369 "distance between track and vertex seed: "
375 <<
" Distance between track and seed vtx is negative: " <<
distance
384 if (myPerigee && myPerigee->covariance()) {
397 perigeesToFit.push_back(*perigeeListIter);
400 perigeesToFitSplitVertex.push_back(*perigeeListIter);
407 if (perigeesToFit.empty()) {
408 ATH_MSG_DEBUG(
" No good seed found. Exiting search for vertices...");
433 double ndfSplitVertex = 0.;
434 int ntracksSplitVertex = 0;
437 bool goodVertex = myxAODVertex !=
nullptr &&
442 msg(
MSG::DEBUG) <<
" xAOD::Vertex is pointer: " << myxAODVertex
443 <<
" ndf = " <<
ndf <<
" ntracks (with weight>0.01) "
444 << ntracks <<
" beam constraint "
455 int numberOfAddedTracks = 0;
466 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx =
467 (&(*vxIter)->vxTrackAtVertex());
469 if (!myVxTracksAtVtx)
473 myVxTracksAtVtx->begin();
475 myVxTracksAtVtx->end();
479 tracksIter != tracksEnd;) {
482 if ((*tracksIter).weight() > 0.01) {
488 (*tracksIter).initialPerigee();
490 if (trackPerigee ==
nullptr) {
491 msg(MSG::ERROR) <<
" Cast to perigee gives 0 pointer " <<
endmsg;
494 double chi2_newvtx =
compatibility(*trackPerigee, *myxAODVertex);
495 double chi2_oldvtx =
compatibility(*trackPerigee, *(*vxIter));
499 if (chi2_newvtx < chi2_oldvtx) {
502 <<
") more compatible to new one (chi2= "
503 << chi2_newvtx <<
")");
505 perigeesToFit.push_back(trackPerigee);
508 bool isFound =
false;
518 if ((*origIter)->parameters() == trackPerigee) {
520 seedTracks.push_back(*origIter);
529 numberOfAddedTracks += 1;
537 tracksIter = myVxTracksAtVtx->erase(tracksIter);
538 tracksBegin = myVxTracksAtVtx->begin();
539 tracksEnd = myVxTracksAtVtx->end();
549 if (numberOfAddedTracks > 0) {
551 myxAODVertex =
nullptr;
563 goodVertex = myxAODVertex !=
nullptr &&
568 << myxAODVertex <<
" ndf = " <<
ndf
569 <<
" ntracks (with weight>0.01) " << ntracks
570 <<
" beam constraint "
575 ATH_MSG_DEBUG(
" Adding tracks resulted in an invalid vertex. "
587 bool goodSplitVertex =
false;
590 goodSplitVertex = myxAODSplitVertex !=
nullptr && ndfSplitVertex > 0 &&
591 ntracksSplitVertex >= 2;
594 << myxAODSplitVertex <<
" ndf = " << ndfSplitVertex
595 <<
" ntracks (with weight>0.01) " << ntracksSplitVertex);
597 if (!goodSplitVertex) {
601 myxAODSplitVertex, perigeesToFitSplitVertex, seedTracks);
608 theVertexContainer->
push_back(myxAODVertex);
612 myxAODVertex =
nullptr;
619 theVertexContainer->
push_back(myxAODVertex);
623 myxAODVertex =
nullptr;
632 beamSpot->beamVtx().covariancePosition());
634 std::vector<Trk::VxTrackAtVertex>();
637 if (goodSplitVertex) {
640 theVertexContainer->
push_back(myxAODSplitVertex);
642 if (myxAODSplitVertex) {
643 delete myxAODSplitVertex;
644 myxAODSplitVertex =
nullptr;
653 beamSpot->beamVtx().covariancePosition());
655 std::vector<Trk::VxTrackAtVertex>();
661 }
while (seedTracks.size() > 1 && iterations <
m_maxVertices);
664 ATH_MSG_DEBUG(
"Reached maximum iterations, have "<<iterations<<
" vertices");
677 if (!theVertexContainer->
empty()) {
687 primaryVtx->covariancePosition());
689 std::vector<Trk::VxTrackAtVertex>();
697 else if (theVertexContainer->
empty()) {
704 beamSpot->beamVtx().covariancePosition());
705 dummyxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
710 for (
unsigned int i = 0;
i < theVertexContainer->
size() - 1;
i++) {
713 " Vtx: " <<
i <<
" x= " << (*theVertexContainer)[
i]->position().
x()
714 <<
" y= " << (*theVertexContainer)[
i]->position().
y() <<
" z= "
715 << (*theVertexContainer)[
i]->position().
z() <<
" ntracks= "
716 << (*theVertexContainer)[
i]->vxTrackAtVertex().
size()
717 <<
" chi2= " << (*theVertexContainer)[
i]->
chiSquared()
718 <<
" ndf = " << (*theVertexContainer)[
i]->numberDoF());
734 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx =
735 &((*vxIter)->vxTrackAtVertex());
737 if (!myVxTracksAtVtx)
741 myVxTracksAtVtx->begin();
743 myVxTracksAtVtx->end();
748 tracksIter != tracksEnd;
753 origtrkiter != origtrkend;
755 if ((*origtrkiter)->parameters() == (*tracksIter).initialPerigee()) {
760 (*tracksIter).setOrigTrack(*origtrkiter);
771 (*vxIter)->addTrackAtVertex(*linkToXAODTP, (*tracksIter).weight());
774 origTracks.erase(origtrkiter);
775 origtrkbegin = origTracks.begin();
776 origtrkend = origTracks.end();
781 ATH_MSG_ERROR(
" Cannot find vector element to fix links (step 4)! ");
787 origtrkiter != origtrkend;
789 if ((*origtrkiter) != 0) {
795 return std::make_pair(theVertexContainer, theVertexAuxContainer);
801 return StatusCode::SUCCESS;
827 myLinearizedTrack->expectedCovarianceAtPCA().block<2, 2>(0, 0);
830 (myLinearizedTrack->positionJacobian() *
831 (
vertex.covariancePosition() *
832 myLinearizedTrack->positionJacobian().transpose()))
835 weightReduced += errorVertexReduced;
837 weightReduced = weightReduced.
inverse().eval();
839 myLinearizedTrack->expectedParametersAtPCA().block<2, 1>(0, 0);
840 double returnValue = trackParameters2D.
dot(weightReduced * trackParameters2D);
843 myLinearizedTrack =
nullptr;
851 std::
vector<
Trk::ITrackLink*>& seedTracks)
const
859 perigeesToFit.begin();
865 perigeesToFitIter != perigeesToFitEnd;
866 ++perigeesToFitIter) {
873 if ((*seedIter)->parameters() == *perigeesToFitIter) {
875 seedTracks.erase(seedIter);
876 seedBegin = seedTracks.begin();
877 seedEnd = seedTracks.end();
883 " Cannot find vector element to delete when removing BAD vertex! ");
896 std::vector<Trk::VxTrackAtVertex> myVxTracksAtVtx =
900 myVxTracksAtVtx.begin();
902 myVxTracksAtVtx.end();
905 tracksIter != tracksEnd;
907 if ((*tracksIter).weight() > 0.01) {
917 std::vector<const Trk::TrackParameters*>& perigeesToFit,
918 std::vector<Trk::ITrackLink*>& seedTracks)
const
923 std::vector<Trk::VxTrackAtVertex>* tracksAtVertex =
926 std::vector<Trk::VxTrackAtVertex>::const_iterator tracksAtVertexBegin =
927 tracksAtVertex->begin();
928 std::vector<Trk::VxTrackAtVertex>::const_iterator tracksAtVertexEnd =
929 tracksAtVertex->end();
935 perigeesToFit.begin();
939 for (std::vector<Trk::VxTrackAtVertex>::const_iterator tracksAtVertexIter =
941 tracksAtVertexIter != tracksAtVertexEnd;
942 ++tracksAtVertexIter) {
949 if ((*seedIter)->parameters() == (*tracksAtVertexIter).initialPerigee()) {
951 if ((*tracksAtVertexIter).weight() > 0.01) {
952 seedTracks.erase(seedIter);
953 seedBegin = seedTracks.begin();
954 seedEnd = seedTracks.end();
961 ATH_MSG_ERROR(
" Cannot find vector element to delete (step 1)! ");
967 perigeesToFitIter != perigeesToFitEnd;
968 ++perigeesToFitIter) {
969 if (*perigeesToFitIter == (*tracksAtVertexIter).initialPerigee()) {
971 if ((*tracksAtVertexIter).weight() > 0.01) {
972 perigeesToFit.erase(perigeesToFitIter);
973 perigeesToFitBegin = perigeesToFit.begin();
974 perigeesToFitEnd = perigeesToFit.end();
981 ATH_MSG_ERROR(
" Cannot find vector element to delete (step 2)! ");
985 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVertex =
989 myVxTracksAtVertex->begin();
991 myVxTracksAtVertex->end();
995 perigeesToFitIter != perigeesToFitEnd;
996 ++perigeesToFitIter) {
1004 if (myPerigee ==
nullptr) {
1016 seedIter != seedEnd;
1018 if ((*seedIter)->parameters() == *perigeesToFitIter) {
1020 seedTracks.erase(seedIter);
1021 seedBegin = seedTracks.begin();
1022 seedEnd = seedTracks.end();
1028 ATH_MSG_ERROR(
" Cannot find vector element to delete (step 3)! ");
1034 tracksIter != tracksEnd;
1036 if ((*tracksIter).initialPerigee() == *perigeesToFitIter) {
1040 myVxTracksAtVertex->erase(tracksIter);
1041 tracksBegin = myVxTracksAtVertex->begin();
1042 tracksEnd = myVxTracksAtVertex->end();