182 std::vector<Trk::ITrackLink*> origTracks=trackVector;
183 std::vector<Trk::ITrackLink*> seedTracks=trackVector;
191 theVertexContainer->setStore( theVertexAuxContainer );
192 const auto invalidResponse = std::make_pair(theVertexContainer, theVertexAuxContainer);
196 ATH_MSG_WARNING( trackVector.size() <<
" tracks - exceeds maximum (" <<
m_maxTracks <<
"), skipping vertexing and returning only dummy..." );
197 return std::make_pair(theVertexContainer, theVertexAuxContainer);
201 unsigned int seedtracknumber=seedTracks.size();
243 seedBegin=seedTracks.begin();
244 seedEnd=seedTracks.end();
246 if (seedtracknumber ==0)
248 ATH_MSG_DEBUG(
" New iteration. No tracks available after track selection for seeding. No finding done." );
257 std::vector<const Trk::TrackParameters*> perigeeList;
259 seedtrkAtVtxIter!=seedEnd;++seedtrkAtVtxIter) {
260 perigeeList.push_back( (*seedtrkAtVtxIter)->parameters() );
269 std::unique_ptr<Trk::IMode3dInfo>
info;
276 std::vector<float> FsmwX, FsmwY, FsmwZ, wght ;
279 double cXY = -9.9, cZ = -9.9 ;
280 info->getCorrelationDistance( cXY, cZ ) ;
287 m_seedX->push_back( seedVertex.x() ) ;
288 m_seedY->push_back( seedVertex.y() ) ;
289 m_seedZ->push_back( seedVertex.z() ) ;
297 looseConstraintCovariance.setIdentity();
298 looseConstraintCovariance = looseConstraintCovariance * 1
e+8;
307 " at y: " << seedVertex.y() <<
308 " at z: " << seedVertex.z() );
311 if ( seedVertex.z()==0. ) {
313 ATH_MSG_DEBUG(
"No seed found: no further vertices in event" );
314 ATH_MSG_DEBUG(
"Number of input tracks: " << perigeeList.size() <<
" but no seed returned." );
330 std::vector<const Trk::TrackParameters*> perigeesToFit;
331 std::vector<const Trk::TrackParameters*> perigeesToFitSplitVertex;
333 int numberOfTracks( perigeeList.size() );
335 std::vector<const Trk::TrackParameters*>::const_iterator perigeeListBegin=perigeeList.begin();
336 std::vector<const Trk::TrackParameters*>::const_iterator perigeeListEnd=perigeeList.end();
339 for (std::vector<const Trk::TrackParameters*>::const_iterator perigeeListIter=perigeeListBegin;
340 perigeeListIter!=perigeeListEnd;++perigeeListIter)
343 if (numberOfTracks<=2)
345 perigeesToFit.push_back(*perigeeListIter);
350 perigeesToFit.push_back(*perigeeListIter);
358 perigeesToFit.push_back(*perigeeListIter);
363 perigeesToFitSplitVertex.push_back(*perigeeListIter);
378 ATH_MSG_WARNING(
" ImpactPoint3dEstimator failed to find minimum distance between track and vertex seed: " <<
err.p );
389 double doe = 99999999.9 ;
392 if( myPerigee && myPerigee->covariance() )
414 perigeesToFit.push_back(*perigeeListIter);
419 perigeesToFitSplitVertex.push_back(*perigeeListIter);
430 ATH_MSG_VERBOSE(
" Considering n. " << perigeesToFit.size() <<
" tracks for the fit. " );
433 ATH_MSG_VERBOSE(
" and n. " << perigeesToFitSplitVertex.size() <<
" tracks for split vertex fit. " );
444 if (perigeesToFit.empty())
447 ATH_MSG_DEBUG(
" No good seed found. Exiting search for vertices..." );
451 theVertexContainer->
push_back( seededxAODVertex );
455 dummyCovariance.setIdentity();
457 seededxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
461 mDecor_mass( *seededxAODVertex ) =
m_v0mass ;
462 mDecor_energy( *seededxAODVertex ) =
m_v0ee ;
463 mDecor_NumTrk( *seededxAODVertex ) =
m_ntracks ;
464 mDecor_HitsFilter( *seededxAODVertex ) =
m_hif ;
465 mDecor_direction( *seededxAODVertex ) =
m_dir ;
466 mDecor_intrk( *seededxAODVertex ) = numberOfTracks ;
481 if ( perigeesToFit.size()>1)
494 bool goodVertex = myxAODVertex !=
nullptr &&
m_ndf >0 &&
m_ntracks >=2 ;
497 ATH_MSG_DEBUG(
" xAOD::Vertex : " << ( myxAODVertex !=
nullptr ? 1 : 0 )
498 <<
", #dof = " <<
m_ndf <<
", #tracks (weight>0.01) = " <<
m_ntracks );
505 ATH_MSG_DEBUG(
" Going to new iteration with: " << seedTracks.size() <<
" seed tracks after BAD VERTEX. " );
514 theVertexContainer->
push_back( myxAODVertex );
515 mDecor_mass( *myxAODVertex ) =
m_v0mass ;
516 mDecor_energy( *myxAODVertex ) =
m_v0ee ;
517 mDecor_NumTrk( *myxAODVertex ) =
m_ntracks ;
518 mDecor_HitsFilter( *myxAODVertex ) =
m_hif ;
519 mDecor_direction( *myxAODVertex ) =
m_dir ;
520 mDecor_intrk( *myxAODVertex ) = numberOfTracks ;
531 theVertexContainer->
push_back( seededxAODVertex );
535 dummyCovariance.setIdentity();
537 seededxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
541 mDecor_mass( *seededxAODVertex ) =
m_v0mass ;
542 mDecor_energy( *seededxAODVertex ) =
m_v0ee ;
543 mDecor_NumTrk( *seededxAODVertex ) =
m_ntracks ;
544 mDecor_HitsFilter( *seededxAODVertex ) =
m_hif ;
545 mDecor_direction( *seededxAODVertex ) =
m_dir ;
546 mDecor_intrk( *seededxAODVertex ) = numberOfTracks ;
556 mDecor_nrobbed( *myxAODVertex ) = 0 ;
561 ATH_MSG_VERBOSE(
" N tracks used for fit before reallocating: " << perigeesToFit.size() );
566 int numberOfAddedTracks=0;
567 const AmgSymMatrix(3) covariance = (&(*myxAODVertex))->covariancePosition() ;
581 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx=(&(*vxIter)->vxTrackAtVertex());
583 if ( ! myVxTracksAtVtx )
continue;
587 const AmgSymMatrix(3) oldcovariance = (*vxIter)->covariancePosition() ;
591 std::
vector<
Trk::VxTrackAtVertex>::const_iterator tracksBegin=myVxTracksAtVtx->
begin();
592 std::
vector<
Trk::VxTrackAtVertex>::const_iterator tracksEnd=myVxTracksAtVtx->
end();
598 for (std::
vector<
Trk::VxTrackAtVertex>::const_iterator tracksIter=tracksBegin;
599 tracksIter!=tracksEnd;)
611 if (trackPerigee==
nullptr)
613 ATH_MSG_ERROR(
" Cast to perigee gives 0 pointer, cannot continue " );
614 return invalidResponse;
618 double chi2_newvtx=
compatibility(*trackPerigee, covariance, position );
619 double chi2_oldvtx=
compatibility(*trackPerigee, oldcovariance, oldposition );
621 double minDist =
VrtVrtDist( myxAODVertex, *vxIter ) ;
625 " to new vtx is: " << chi2_newvtx );
630 if ( chi2_newvtx < chi2_oldvtx
636 ATH_MSG_DEBUG(
" Found track of old vertex (chi2= " << chi2_oldvtx <<
637 ") more compatible to new one (chi2= " << chi2_newvtx <<
")" );
640 perigeesToFit.push_back(trackPerigee);
649 origIter!=origEnd;++origIter)
651 if ( (*origIter)->parameters()==trackPerigee )
654 ATH_MSG_VERBOSE(
" found the old perigee to be re-added to seedTracks in order to be deleted again!" );
657 seedTracks.push_back(*origIter);
664 ATH_MSG_WARNING(
" Cannot find old perigee to re-add back to seed tracks... " );
667 numberOfAddedTracks+=1;
677 tracksIter=myVxTracksAtVtx->erase(tracksIter);
678 tracksBegin=myVxTracksAtVtx->begin();
679 tracksEnd=myVxTracksAtVtx->end();
687 if ( nrobbed > 0 ) mDecor_nrobbed( *(*vxIter) ) ++;
692 ATH_MSG_VERBOSE(
" N tracks used for fit after reallocating: " << perigeesToFit.size() );
698 if ( numberOfAddedTracks > 0 )
701 ATH_MSG_DEBUG(
" refit with additional " << numberOfAddedTracks
702 <<
" from other vertices " );
707 myxAODVertex=
nullptr;
709 if ( perigeesToFit.size()>1)
712 mDecor_nrobbed( *myxAODVertex ) = 0 ;
717 goodVertex = myxAODVertex !=
nullptr &&
m_ndf >0 &&
m_ntracks >=2 ;
720 ATH_MSG_DEBUG(
" Refitted xAODVertex is pointer: " << myxAODVertex <<
721 " #dof = " <<
m_ndf <<
" #tracks (with weight>0.01) " <<
m_ntracks );
731 theVertexContainer->
push_back(myxAODVertex);
734 mDecor_mass( *myxAODVertex ) =
m_v0mass ;
735 mDecor_energy( *myxAODVertex ) =
m_v0ee ;
736 mDecor_HitsFilter( *myxAODVertex ) =
m_hif ;
737 mDecor_direction( *myxAODVertex ) =
m_dir ;
738 mDecor_NumTrk( *myxAODVertex ) =
m_ntracks ;
739 mDecor_intrk( *myxAODVertex ) = numberOfTracks ;
749 ATH_MSG_DEBUG(
" Adding tracks resulted in an invalid vertex. Should be rare... " );
750 ATH_MSG_DEBUG(
" Going to new iteration with " << seedTracks.size()
751 <<
" seed tracks after BAD VERTEX. " );
756 theVertexContainer->
push_back( seededxAODVertex );
759 seededxAODVertex->
vxTrackAtVertex() = std::vector<Trk::VxTrackAtVertex>();
763 mDecor_NumTrk( *seededxAODVertex ) =
m_ntracks ;
764 mDecor_mass( *seededxAODVertex ) =
m_v0mass ;
765 mDecor_energy( *seededxAODVertex ) =
m_v0ee ;
766 mDecor_HitsFilter( *seededxAODVertex ) =
m_hif ;
767 mDecor_direction( *seededxAODVertex ) =
m_dir ;
768 mDecor_intrk( *seededxAODVertex ) = numberOfTracks ;
790 mDecor_HitsFilter( *myxAODVertex ) =
m_hif ;
791 mDecor_direction( *myxAODVertex ) =
m_dir ;
792 mDecor_NumTrk( *myxAODVertex ) =
m_ntracks ;
806 mDecor_mass( *myxAODVertex ) =
m_v0mass ;
807 mDecor_energy( *myxAODVertex ) =
m_v0ee ;
808 mDecor_intrk( *myxAODVertex ) = numberOfTracks ;
821 * groomed = * myxAODVertex ;
832 delete myxAODVertex ;
840 bool goodgroom = false ;
842 if ( perigeesToFit.size() >= 2 )
849 goodgroom = ( groomed !=
nullptr &&
m_ndf > 0 && ngroom >= 2 ) ;
852 if ( perigeesToFit.size() < 2 || ! goodgroom )
855 theVertexContainer->
push_back(myxAODVertex);
857 if ( perigeesToFit.size() < 2 || ngroom < 1 )
862 mDecor_HitsFilter( *myxAODVertex ) =
m_hif ;
863 mDecor_NumTrk( *myxAODVertex ) =
m_ntracks ;
877 * myxAODVertex = * groomed ;
883 ATH_MSG_DEBUG(
" new vertex after grooming with reminded tracks : " << ngroom
904 mDecor_mass( *myxAODVertex ) =
m_v0mass ;
905 mDecor_energy( *myxAODVertex ) =
m_v0ee ;
906 mDecor_intrk( *myxAODVertex ) = numberOfTracks ;
908 mDecor_HitsFilter( *myxAODVertex ) =
m_hif ;
909 mDecor_direction( *myxAODVertex ) =
m_dir ;
910 mDecor_NumTrk( *myxAODVertex ) = ngroom ;
918 <<
" with VxType : " << myxAODVertex->
vertexType() );
922 mDecor_HitsFilter( *myxAODVertex ) =
m_hif ;
933 ATH_MSG_VERBOSE(
"Number of seeds after removal of outliers: " << seedTracks.size() );
938 theVertexContainer->
push_back(myxAODVertex);
967 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx = &((*vxIter)->vxTrackAtVertex());
968 if ( !myVxTracksAtVtx )
974 int nrobbed = mDecor_nrobbed (**vxIter);
981 std::vector<Trk::VxTrackAtVertex>::const_iterator tracksBegin=myVxTracksAtVtx->begin();
982 std::vector<Trk::VxTrackAtVertex>::const_iterator tracksEnd=myVxTracksAtVtx->end();
984 std::vector<const Trk::TrackParameters*> perigeesToFit ;
985 std::vector<Trk::ITrackLink*> nullseedTracks ;
987 for (std::vector<Trk::VxTrackAtVertex>::const_iterator tracksIter=tracksBegin;
988 tracksIter!=tracksEnd;++tracksIter)
990 for (std::vector<Trk::ITrackLink*>::const_iterator origtrkiter=origtrkbegin;
991 origtrkiter!=origtrkend;++origtrkiter)
993 if ((*origtrkiter)->parameters()==(*tracksIter).initialPerigee())
996 nullseedTracks.push_back( *origtrkiter ) ;
997 perigeesToFit.push_back( (*origtrkiter)->parameters() ) ;
1003 QxAODVertex =
m_iVertexFitter->fit( perigeesToFit, (*vxIter)->position() );
1004 if ( QxAODVertex ==
nullptr )
1012 float chi2dof1 = (*vxIter)->chiSquared()/(*vxIter)->numberDoF() ;
1016 if ( mDecor_HitsFilter.isAvailable (**vxIter) )
1017 oldhf = mDecor_HitsFilter (**vxIter);
1018 if ( chi2dof2 >= chi2dof1 )
1024 int nit = mDecor_intrk (**vxIter);
1025 *(*vxIter) = *QxAODVertex ;
1028 mDecor_mass( *(*vxIter) ) =
m_v0mass ;
1029 mDecor_energy( *(*vxIter) ) =
m_v0ee ;
1030 mDecor_intrk( *(*vxIter) ) = nit ;
1035 mDecor_HitsFilter( *(*vxIter) ) = oldhf ;
1036 mDecor_direction( *(*vxIter) ) =
m_dir ;
1037 mDecor_NumTrk( *(*vxIter) ) = ntrk ;
1043 vxIter = theVertexContainer->
erase( vxIter ) ;
1044 vxBegin=theVertexContainer->
begin();
1045 vxEnd=theVertexContainer->
end();
1052 delete QxAODVertex ;
1061 ATH_MSG_DEBUG(
" filled " << nv <<
" 'th vertex : x= " << (*vxIter)->position().x() <<
" , y= "
1062 << (*vxIter)->position().y() <<
" , z= " << (*vxIter)->position().z()
1063 <<
" vxType = " << (*vxIter)->vertexType() ) ;
1065 std::vector<float> trkWght ;
1067 std::vector<Trk::VxTrackAtVertex>* myVxTracksAtVtx = &((*vxIter)->vxTrackAtVertex());
1069 if ( ! myVxTracksAtVtx )
1072 mDecor_trkDOE( *(*vxIter) ) = trkWght ;
1073 mDecor_trkWght( *(*vxIter) ) = trkWght ;
1074 mDecor_sumPt2( *(*vxIter) ) = -99.9 ;
1075 mDecor_nrobbed( *(*vxIter) ) = 0 ;
1081 std::vector<float> xdoe ;
1087 tracksIter!=tracksEnd;++tracksIter)
1089 bool found = false ;
1091 trkWght.push_back( (*tracksIter).weight() ) ;
1095 origtrkiter!=origtrkend;++origtrkiter)
1098 if ((*origtrkiter)->parameters()==(*tracksIter).initialPerigee())
1111 pt2 +=
pt*
pt*0.000001 ;
1117 std::unique_ptr<Trk::PlaneSurface> mySurface=
1127 if( svperigee->covariance() )
1136 (*tracksIter).setOrigTrack (*origtrkiter );
1144 (*vxIter)->addTrackAtVertex(*linkToXAODTP, (*tracksIter).weight());
1148 origTracks.erase(origtrkiter);
1149 origtrkbegin=origTracks.begin();
1150 origtrkend=origTracks.end();
1157 ATH_MSG_ERROR(
" Cannot find vector element to fix links (step 4)! " );
1167 mDecor_trkWght( *vtx ) = trkWght ;
1168 mDecor_trkDOE( *vtx ) = xdoe ;
1171 mDecor_sumPt2( *vtx ) = pt2 ;
1175 ATH_MSG_DEBUG(
" #Vtx "<< theVertexContainer->
size() <<
" with track-vertex association fixed " );
1178 for (
unsigned int i = 0 ;
i < theVertexContainer->
size() ;
i++)
1182 " x= " << (*theVertexContainer)[
i]->position().
x() <<
1183 " y= " << (*theVertexContainer)[
i]->position().
y() <<
1184 " z= " << (*theVertexContainer)[
i]->position().
z() <<
1185 " ntracks= " << (*theVertexContainer)[
i]->vxTrackAtVertex().
size() <<
1186 " chi2= " << (*theVertexContainer)[
i]->
chiSquared() <<
1187 " #dof = " << (*theVertexContainer)[
i]->numberDoF() );
1191 origtrkiter!=origtrkend;++origtrkiter)
1193 if ((*origtrkiter)!=0) {
1194 delete *origtrkiter;
1203 return std::make_pair(theVertexContainer, theVertexAuxContainer);