61 m_initializationHelper(
"Trk::JetFitterInitializationHelper", this),
62 m_helper(
"Trk::JetFitterHelper", this),
63 m_updator(
"Trk::KalmanVertexOnJetAxisUpdator", this),
64 m_smoother(
"Trk::KalmanVertexOnJetAxisSmoother", this),
65 m_minDistanceFinder(
"Trk::TrkDistanceFinderNeutralCharged/TrkDistanceFinderNeutralCharged", this),
66 m_minDistanceFinderNeutral(
"Trk::TrkDistanceFinderNeutralNeutral/TrkDistanceFinderNeutralNeutral", this),
69 m_noPrimaryVertexRefit(false),
73 declareProperty(
"KalmanVertexOnJetAxisUpdator",m_updator);
74 declareProperty(
"KalmanVertexOnJetAxisSmoother",m_smoother);
75 declareProperty(
"JetFitterHelper",m_helper);
76 declareProperty(
"JetFitterInitializationHelper",m_initializationHelper);
77 declareProperty(
"JetFitterMinimumDistanceFinder",m_minDistanceFinder);
78 declareProperty(
"JetFitterMinimumDistanceFinderNeutral",m_minDistanceFinderNeutral);
79 declareProperty(
"ID_maxR",m_maxR);
80 declareProperty(
"ID_maxZ",m_maxZ);
81 declareInterface< JetFitterRoutines >(
this) ;
82 declareProperty(
"BeFast",m_fast);
83 declareProperty(
"maxDRshift",m_maxDRshift);
84 declareProperty(
"noPrimaryVertexRefit",m_noPrimaryVertexRefit);
90 JetFitterRoutines::~JetFitterRoutines() =
default;
96 ATH_CHECK( m_fieldCacheCondObjInputKey.initialize() );
101 ATH_CHECK( m_initializationHelper.retrieve() );
103 ATH_CHECK( m_minDistanceFinder.retrieve() );
105 ATH_CHECK( m_minDistanceFinderNeutral.retrieve() );
111 return StatusCode::SUCCESS;
115 void JetFitterRoutines::initializeToMinDistancesToJetAxis(
VxJetCandidate* myJetCandidate)
const {
117 ATH_MSG_DEBUG (
"initializingToMinDistancesToJetAxis is now implemented! Will converge faster!!! Neutrals are fully supported...");
135 auto const absRecJetTheta = std::abs(recPosition[
Trk::jet_theta]);
136 auto const abssinRecJetTheta = std::abs(sinRecJetTheta);
137 auto const abscosRecJetTheta = std::abs(cosRecJetTheta);
140 sinRecJetPhi*sinRecJetTheta,
146 const std::vector<VxVertexOnJetAxis*> & associatedVertices=myJetCandidate->
getVerticesOnJetAxis();
148 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxBegin=associatedVertices.begin();
149 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxEnd=associatedVertices.end();
151 if (associatedVertices.empty()) {
154 if (!readHandle.isValid()) {
155 std::stringstream
msg;
156 msg <<
"Failed to retrieve magmnetic field conditions data " << m_fieldCacheCondObjInputKey.key() <<
".";
157 throw std::runtime_error(
msg.str());
160 fieldCondObj->getInitializedCache (fieldCache);
161 for (std::vector<VxVertexOnJetAxis*>::const_iterator VtxIter=VtxBegin;VtxIter!=VtxEnd;++VtxIter) {
162 VxVertexOnJetAxis* myVertex=(*VtxIter);
163 if (myVertex!=
nullptr) {
165 const std::vector<VxTrackAtVertex*> & tracksAtVertex=myVertex->getTracksAtVertex();
166 if (tracksAtVertex.size()>1) {
167 ATH_MSG_DEBUG(
"Warning in JetFitterInitializationHelper.Number of tracks at vertex is bigger than one, "
168 <<
"even during initialization phase. Skipping this vertex (already initialized)..." );
170 else if (tracksAtVertex.empty())
172 ATH_MSG_WARNING(
"No track at vertex. Internal fitter error. Contact author (GP) ... " );
178 ATH_MSG_VERBOSE(
" pointer to initialPerigee: " << tracksAtVertex[0]->initialPerigee() );
185 double distOnAxis=-999.;
186 std::pair<Amg::Vector3D,double>
result;
188 result=m_minDistanceFinder->getPointAndDistance(myJetAxis,*
ptr,distOnAxis, fieldCache);
190 double R=distOnAxis*sinRecJetTheta;
191 double Z=distOnAxis*cosRecJetTheta;
193 if (std::abs(
R)>m_maxR)
196 if (absRecJetTheta>1
e-8)
198 ATH_MSG_DEBUG(
" Closest distance of track to jet axis is outside ID envelope, R=" <<
R <<
", setting to R= " << m_maxR );
199 distOnAxis=m_maxR /abssinRecJetTheta;
203 Z=distOnAxis*cosRecJetTheta;
204 if (std::abs(
Z)>m_maxZ)
206 if (abscosRecJetTheta>1
e-8)
208 ATH_MSG_DEBUG(
" Closest distance of track to jet axis is outside ID envelope, Z=" <<
Z <<
", setting to Z= " << m_maxZ );
209 distOnAxis=m_maxZ / cosRecJetTheta;
213 linPositions[numRow(myVertex->getNumVertex())]=distOnAxis;
216 }
catch (Error::NewtonProblem
e) {
221 ATH_MSG_DEBUG (
"initializingToMinDistancesToJetAxis for vertex number... " <<
222 myVertex->getNumVertex() <<
" to distance " << distOnAxis <<
223 " distance to axis " <<
result.second);
226 else if (
dynamic_cast<const Trk::NeutralPerigee*
>((tracksAtVertex[0]->initialPerigee()))!=
nullptr)
228 double distOnAxis=-999.;
229 std::pair<Amg::Vector3D,double>
result;
234 NeutralTrack myNeutralTrack(neutralTrack->position(),neutralTrack->momentum());
236 result=m_minDistanceFinderNeutral->getPointAndDistance(myJetAxis,myNeutralTrack,distOnAxis);
238 double R=distOnAxis*sinRecJetTheta;
239 double Z=distOnAxis*cosRecJetTheta;
241 if (std::abs(
R)>m_maxR)
244 if (absRecJetTheta>1
e-8)
246 ATH_MSG_DEBUG(
" Closest distance of track to jet axis is outside ID envelope, R=" <<
R <<
", setting to R= " << m_maxR );
247 distOnAxis=m_maxR / abssinRecJetTheta;
251 Z=distOnAxis*cosRecJetTheta;
252 if (std::abs(
Z)>m_maxZ)
254 if (abscosRecJetTheta>1
e-8)
256 ATH_MSG_DEBUG(
" Closest distance of track to jet axis is outside ID envelope, Z=" <<
Z <<
", setting to Z= " << m_maxZ );
257 distOnAxis=m_maxZ / cosRecJetTheta;
261 linPositions[numRow(myVertex->getNumVertex())]=distOnAxis;
262 ATH_MSG_DEBUG(
"initializingToMinDistancesToJetAxis for vertex from NEUTRAL number... " <<
263 myVertex->getNumVertex() <<
" to distance " <<
264 distOnAxis <<
" distance to axis " <<
result.second );
269 ATH_MSG_WARNING(
"Could not cast to neither CHARGED or NEUTRAL! This error is not FATAL" );
273 ATH_MSG_WARNING(
"Warning in JetFitterInitializationHelper.Inconsistency found. Pointer to VxVertexOnJetAxis should be different from zero. Skipping track..." );
274 throw (
"Warning in JetFitterInitializationHelper.Inconsistency found. Pointer to VxVertexOnJetAxis should be different from zero. Skipping track...");
281 ATH_MSG_DEBUG (
"No Associated Vertices found! no initialization to minimum distance is possible.");
285 void JetFitterRoutines::performTheFit(VxJetCandidate* myJetCandidate,
286 int num_maxiterations,
287 bool treat_sign_flip,
288 int num_signflip_maxiterations,
289 double deltachi2_convergence)
const {
291 bool isInitialized=this->checkJetCandidate(myJetCandidate);
293 if (!isInitialized) {
294 ATH_MSG_DEBUG (
"JetFitter found the candidate was not correctly initialized. Not proceeding with the fitt...");
302 int num_iteration_signflip=0;
303 double lastchi2=-99.;
304 bool converged=
false;
306 if (treat_sign_flip) {
309 myJetCandidate->setRecVertexPositions(
RecVertexPositions(myJetCandidate->getConstraintVertexPositions()));
314 m_initializationHelper->linearizeAllTracks(myJetCandidate,
true);
317 updateAllVertices(myJetCandidate);
323 num_iteration_signflip+=1;
331 auto const absActLastChi2 = std::abs(actualchi2-lastchi2);
333 #ifdef JetFitterRoutines_DEBUG
334 ATH_MSG_DEBUG(
" last chi2 " << lastchi2 <<
" actual chi2 " << actualchi2 <<
" difference " <<
335 absActLastChi2<<
" < " << deltachi2_convergence <<
" ? " <<
" ndf " << myFitQuality.
numberDoF() );
338 if (absActLastChi2<deltachi2_convergence) {
343 copyRecoPositionsToLinearizationPositions(*myJetCandidate);
349 }
while ((!converged)&&num_iteration_signflip<num_signflip_maxiterations);
353 ATH_MSG_VERBOSE(
" For sign flip treatment there was convergence after " << num_iteration_signflip );
358 #ifdef JetFitterRoutines_DEBUG
359 ATH_MSG_DEBUG(
"JetFitterRoutines: after convergence with sign flip treatment: " << myJetCandidate->getRecVertexPositions() );
370 myJetCandidate->setRecVertexPositions(
RecVertexPositions(myJetCandidate->getConstraintVertexPositions()));
374 m_initializationHelper->linearizeAllTracks(myJetCandidate,
false);
377 updateAllVertices(myJetCandidate);
387 ATH_MSG_VERBOSE(
" num_iteration (full fit): " << num_iteration <<
" det " << myRecPosition.
covariancePosition().determinant() <<
" recVertex " << myJetCandidate->getRecVertexPositions() );
392 auto const absActLastChi2 = std::abs(actualchi2-lastchi2);
395 #ifdef JetFitterRoutines_DEBUG
396 ATH_MSG_DEBUG(
" without sign flip: last chi2 " << lastchi2 <<
" actual chi2 " << actualchi2 <<
" difference " <<
397 absActLastChi2 <<
" < " << deltachi2_convergence <<
" ? " <<
" ndf " << myFitQuality.
numberDoF() );
401 if (absActLastChi2<deltachi2_convergence) {
406 copyRecoPositionsToLinearizationPositions(*myJetCandidate);
411 }
while ((!converged)&&num_iteration<num_maxiterations);
414 ATH_MSG_VERBOSE(
" Fit without sign flip treatment there was convergence after " << num_iteration );
418 #ifdef JetFitterRoutines_DEBUG
419 ATH_MSG_DEBUG(
"JetFitterRoutines: after convergence without sign flip treatment: " << myJetCandidate->getRecVertexPositions() );
422 if (num_iteration>=num_maxiterations)
424 ATH_MSG_DEBUG(
"There wasn't convergence in JetFitter after: " << num_maxiterations );
429 smoothAllVertices(myJetCandidate);
432 if (myDebugInfo!=
nullptr) {
435 myDebugInfo=
new VxJetFitterDebugInfo();
442 void JetFitterRoutines::updateAllVertices(VxJetCandidate* myJetCandidate)
const {
449 if (!m_noPrimaryVertexRefit) {
451 VxVertexOnJetAxis* myPrimary=myJetCandidate->getPrimaryVertex();
452 const std::vector<VxTrackAtVertex*> & primaryVectorTracks=myPrimary->getTracksAtVertex();
454 const std::vector<VxTrackAtVertex*>::const_iterator primaryVectorTracksBegin=primaryVectorTracks.begin();
455 const std::vector<VxTrackAtVertex*>::const_iterator primaryVectorTracksEnd=primaryVectorTracks.end();
457 for (std::vector<VxTrackAtVertex*>::const_iterator primaryVectorIter=primaryVectorTracksBegin;
458 primaryVectorIter!=primaryVectorTracksEnd;++primaryVectorIter) {
460 ATH_MSG_VERBOSE(
" RecVertexPositions before update " << myJetCandidate->getRecVertexPositions() );
463 m_updator->add(*primaryVectorIter,myPrimary,myJetCandidate);
465 m_updator->addWithFastUpdate(*primaryVectorIter,myPrimary,myJetCandidate);
470 ATH_MSG_VERBOSE(
" Determinant after PRIMARY VTX update: " << n_iteration <<
" det: " << myRecPosition.
covariancePosition().determinant() <<
" recVertex " << myJetCandidate->getRecVertexPositions() );
478 const std::vector<VxVertexOnJetAxis*> & associatedVertices=myJetCandidate->getVerticesOnJetAxis();
480 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxBegin=associatedVertices.begin();
481 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxEnd=associatedVertices.end();
483 for (std::vector<VxVertexOnJetAxis*>::const_iterator VtxIter=VtxBegin;VtxIter!=VtxEnd;++VtxIter) {
487 const std::vector<VxTrackAtVertex*> & tracksAtVertex=(*VtxIter)->getTracksAtVertex();
489 const std::vector<VxTrackAtVertex*>::const_iterator TracksBegin=tracksAtVertex.begin();
490 const std::vector<VxTrackAtVertex*>::const_iterator TracksEnd=tracksAtVertex.end();
492 for (std::vector<VxTrackAtVertex*>::const_iterator TrackVectorIter=TracksBegin;
493 TrackVectorIter!=TracksEnd;++TrackVectorIter) {
495 ATH_MSG_VERBOSE(
" RecVertexPositions before update " << myJetCandidate->getRecVertexPositions() );
498 m_updator->add(*TrackVectorIter,*VtxIter,myJetCandidate);
500 m_updator->addWithFastUpdate(*TrackVectorIter,*VtxIter,myJetCandidate);
505 const RecVertexPositions & myRecPosition=myJetCandidate->getRecVertexPositions();
507 ATH_MSG_VERBOSE(
" Determinant after sec update: " << n_iteration <<
" det: " << myRecPosition.covariancePosition().determinant() <<
" recVertex " << myJetCandidate->getRecVertexPositions() );
511 myJetCandidate->getRecVertexPositions().finalizePosition();
514 void JetFitterRoutines::smoothAllVertices(VxJetCandidate* myJetCandidate)
const {
516 VxVertexOnJetAxis* myPrimary=myJetCandidate->getPrimaryVertex();
519 m_smoother->update(myPrimary,myJetCandidate);
521 m_smoother->fastUpdate(myPrimary,myJetCandidate);
524 const std::vector<VxVertexOnJetAxis*> & associatedVertices=myJetCandidate->getVerticesOnJetAxis();
526 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxBegin=associatedVertices.begin();
527 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxEnd=associatedVertices.end();
529 for (std::vector<VxVertexOnJetAxis*>::const_iterator VtxIter=VtxBegin;VtxIter!=VtxEnd;++VtxIter) {
531 m_smoother->update(*VtxIter,myJetCandidate);
533 m_smoother->fastUpdate(*VtxIter,myJetCandidate);
541 bool JetFitterRoutines::checkJetCandidate(VxJetCandidate* myJetCandidate)
const {
546 const VxVertexOnJetAxis* myPrimary=myJetCandidate->getPrimaryVertex();
547 if (myPrimary==
nullptr) {
548 ATH_MSG_WARNING(
"No primary vertex found in VxJetCandidate class. Initialization was not done correctly..." );
553 if (myPrimary->getNumVertex() != -10) {
555 ATH_MSG_WARNING(
"Numvertex of primary vertex not correctly initialized. "
556 "Not proceeding with the fit!");
559 const std::vector<VxTrackAtVertex*>& primaryVectorTracks =
560 myPrimary->getTracksAtVertex();
562 sizeprimary = primaryVectorTracks.size();
564 ok = (
std::find(primaryVectorTracks.begin(),
565 primaryVectorTracks.end(),
566 nullptr) == primaryVectorTracks.end());
569 "proceeding with the fit!");
578 const std::vector<VxVertexOnJetAxis*>& tracksOfVertex =
579 myJetCandidate->getVerticesOnJetAxis();
581 auto badVertex = [](VxVertexOnJetAxis* pVertex) {
582 return (pVertex ==
nullptr) or (pVertex->getNumVertex() < 0);
585 (std::find_if(tracksOfVertex.begin(), tracksOfVertex.end(), badVertex) ==
586 tracksOfVertex.end());
589 "One of the VxTrackAtVertex is a null pointer or uninitialized. Not "
590 "proceeding with the fit!");
598 if (tracksOfVertex.empty()&&sizeprimary==0) {
599 ATH_MSG_DEBUG(
"No tracks at primary, no tracks on jet axis. Not proceeding with the fit!" );
608 if (
static_cast<unsigned int>(tracksOfVertex.size()+5)!=
static_cast<unsigned int>(myPosition.rows())) {
610 <<
" components while " << tracksOfVertex.size()+5
611 <<
" are expected. Not proceeding with the fit " );
617 if (myPosition.rows()!=myErrorMatrix.rows()) {
618 ATH_MSG_WARNING (
"The dimension of the position vector and the covariance matrix does not match. Not performing fit...");
623 for (
int i=0;
i<myPosition.rows();
i++) {
624 if (std::abs(myErrorMatrix(
i,
i))<1
e-20) {
625 ATH_MSG_WARNING (
"Value of cov matrix component n. " <<
i <<
" has a value smaller than 1e-8. Not considered as possible. Not performing fit...");
637 std::pair<double,bool> JetFitterRoutines::fastProbabilityOfMerging(
const VxVertexOnJetAxis* firstVertex,
638 const VxVertexOnJetAxis* secondVertex,
639 const VxJetCandidate* myJetCandidate)
const {
643 const VxVertexOnJetAxis * PrimaryVertex=myJetCandidate->getPrimaryVertex();
645 if (firstVertex==PrimaryVertex) {
646 return fastProbabilityOfMergingWithPrimary(secondVertex,myJetCandidate);
648 if (secondVertex==PrimaryVertex) {
649 return fastProbabilityOfMergingWithPrimary(firstVertex,myJetCandidate);
652 return fastProbabilityOfMergingNoPrimary(firstVertex,secondVertex,myJetCandidate);
657 std::pair<double,bool> JetFitterRoutines::fastProbabilityOfMergingWithPrimary(
const VxVertexOnJetAxis* otherVertex,
665 double oldchi2=copyOfRecVertexPositions.fitQuality().chiSquared();
666 double oldndf=copyOfRecVertexPositions.fitQuality().numberDoF();
669 const Amg::VectorX & positionVector=copyOfRecVertexPositions.position();
670 const Amg::MatrixX & positionCov=copyOfRecVertexPositions.covariancePosition();
677 m_helper->performKalmanConstraintToBePrimaryVertex(copyOfRecVertexPositions,
683 std::pow((phinew-phiold)/phierr,2)+
std::pow((thetanew-thetaold)/thetaerr,2)>m_maxDRshift*m_maxDRshift;
687 copyOfRecVertexPositions.fitQuality().chiSquared()-oldchi2;
689 double ndf = copyOfRecVertexPositions.fitQuality().numberDoF()-oldndf +
694 ATH_MSG_WARNING (
" In the compatibility estimation chi2: " <<
chi2 <<
" ndf " <<
ndf <<
" giving back 0 prob ");
695 return std::pair<double,bool>(0,isshifted);
698 return std::pair<double,bool>(TMath::Prob(
chi2,(
int)std::floor(
ndf+0.5)),isshifted);
702 std::pair<double,bool> JetFitterRoutines::fastProbabilityOfMergingNoPrimary(
const VxVertexOnJetAxis* firstVertex,
703 const VxVertexOnJetAxis* secondVertex,
704 const VxJetCandidate* myJetCandidate)
const {
707 RecVertexPositions copyOfRecVertexPositions(myJetCandidate->getRecVertexPositions());
708 const FitQuality & copyOfRecVertexQuality=copyOfRecVertexPositions.fitQuality();
710 double oldchi2=copyOfRecVertexQuality.chiSquared();
711 double oldndf=copyOfRecVertexQuality.numberDoF();
714 const Amg::VectorX & positionVector=copyOfRecVertexPositions.position();
715 const Amg::MatrixX & positionCov=copyOfRecVertexPositions.covariancePosition();
723 m_helper->performKalmanConstraintToMergeVertices(copyOfRecVertexPositions,
729 bool isshifted=
std::pow((phinew-phiold)/phierr,2)+
std::pow((thetanew-thetaold)/thetaerr,2)>m_maxDRshift* m_maxDRshift;
731 double chi2 = firstVertex->fitQuality().chiSquared() +
732 secondVertex->fitQuality().chiSquared() +
733 copyOfRecVertexPositions.fitQuality().chiSquared()-oldchi2;
736 double ndf = copyOfRecVertexPositions.fitQuality().numberDoF()-oldndf +
737 firstVertex->fitQuality().numberDoF()+
738 secondVertex->fitQuality().numberDoF();
741 ATH_MSG_WARNING (
"In the compatibility estimation chi2: " <<
chi2 <<
" ndf " <<
ndf <<
" giving back 0 prob");
742 return std::pair<double,bool>(0,isshifted);
745 return std::pair<double,bool>(TMath::Prob(
chi2,(
int)std::floor(
ndf+0.5)),isshifted);
750 double JetFitterRoutines::fullProbabilityOfMerging(
const VxVertexOnJetAxis* firstVertex,
751 const VxVertexOnJetAxis* secondVertex,
752 const VxJetCandidate* myJetCandidate,
753 int num_maxiterations,
754 bool treat_sign_flip,
755 int num_signflip_maxiterations,
756 double deltachi2_convergence)
const {
759 if (firstVertex==
nullptr||secondVertex==
nullptr||myJetCandidate==
nullptr) {
760 ATH_MSG_WARNING (
"zero pointer given to the full probability estimation. No estimation performed, zero prob returned ");
770 std::map<const VxVertexOnJetAxis*,VxVertexOnJetAxis*> oldToNewVtxPointers;
773 const std::vector<VxVertexOnJetAxis*> vectorOfOldJetCand=myJetCandidate->getVerticesOnJetAxis();
774 const std::vector<VxVertexOnJetAxis*> vectorOfNewJetCand=newJetCandidate.getVerticesOnJetAxis();
779 if (primaryOfFirst==
nullptr||primaryOfSecond==
nullptr) {
780 ATH_MSG_WARNING (
"Empty primary vertex found when estimating fullProbOfMerging. 0 prob returned.");
784 oldToNewVtxPointers[primaryOfFirst]=primaryOfSecond;
786 unsigned int sizeOfVertices=vectorOfOldJetCand.size();
787 if (vectorOfNewJetCand.size()!=sizeOfVertices) {
788 ATH_MSG_WARNING (
"Old and new track of vertices do not match during fullProbOfMerging. 0 prob returned.");
792 for (
unsigned int s=0;
s<sizeOfVertices;
s++) {
793 const VxVertexOnJetAxis* pointer1=vectorOfOldJetCand[
s];
794 VxVertexOnJetAxis* pointer2=vectorOfNewJetCand[
s];
795 if (pointer1==
nullptr||pointer2==
nullptr) {
796 ATH_MSG_WARNING (
"One of the pointers of the original or copied vector of vertices is empty during fullProbOfMerging. Skipping it...");
798 oldToNewVtxPointers[pointer1]=pointer2;
803 VxVertexOnJetAxis* newFirstVertex=oldToNewVtxPointers[firstVertex];
804 VxVertexOnJetAxis* newSecondVertex=oldToNewVtxPointers[secondVertex];
806 if (newFirstVertex==
nullptr||newSecondVertex==
nullptr) {
807 ATH_MSG_WARNING (
"No correspondence to the given firstVertex or secondVertex in fullProbOfMerging. Returning 0 prob.");
811 VxVertexOnJetAxis & commonVertex=m_helper->mergeVerticesInJetCandidate(*newFirstVertex,
816 m_initializationHelper->updateTrackNumbering(&newJetCandidate);
818 performTheFit(&newJetCandidate,num_maxiterations,
820 num_signflip_maxiterations,
821 deltachi2_convergence);
825 #ifdef JetFitterRoutines_DEBUG
826 ATH_MSG_DEBUG(
" End estimating full prob of merging... chi2 " << commonVertex.fitQuality().chiSquared() <<
" ndf " << commonVertex.fitQuality().numberDoF() );
829 return (
double)TMath::Prob(commonVertex.fitQuality().chiSquared(),
830 (
int)std::floor(commonVertex.fitQuality().numberDoF()+0.5));
834 void JetFitterRoutines::fillTableWithFullProbOfMerging(VxJetCandidate* myJetCandidate,
835 int num_maxiterations,
836 bool treat_sign_flip,
837 int num_signflip_maxiterations,
838 double deltachi2_convergence,
839 double threshold_probability)
const {
840 fillTableWithProbOfMerging(myJetCandidate,
844 num_signflip_maxiterations,
845 deltachi2_convergence,
846 threshold_probability);
849 void JetFitterRoutines::fillTableWithFastProbOfMerging(
VxJetCandidate* myJetCandidate)
const {
850 fillTableWithProbOfMerging(myJetCandidate,
false);
854 void JetFitterRoutines::fillTableWithProbOfMerging(
VxJetCandidate* myJetCandidate,
855 bool fullcomputation,
856 int num_maxiterations,
857 bool treat_sign_flip,
858 int num_signflip_maxiterations,
859 double deltachi2_convergence,
860 double threshold_probability)
const {
862 if (myJetCandidate==
nullptr) {
863 ATH_MSG_WARNING(
"VxJetCandidate provided is a zero pointer. No compatibility table calculated." );
869 if (clusteringTablePtr!=
nullptr) {
870 delete clusteringTablePtr;
874 double highestprobability(0.);
878 if (primaryVertex==
nullptr) {
879 ATH_MSG_WARNING(
"VxJetCandidate provided has no primary vertex. No compatibility table calculated." );
888 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxBegin=tracksOnJetAxis.begin();
889 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxEnd=tracksOnJetAxis.end();
891 for (std::vector<VxVertexOnJetAxis*>::const_iterator VtxIter=VtxBegin;
892 VtxIter!=VtxEnd;++VtxIter) {
894 std::pair<double,bool> fastProbabilityAndNonLinearity=fastProbabilityOfMerging(primaryVertex,
900 (*VtxIter)->getNumVertex() <<
" is " << fastProbabilityAndNonLinearity.first);
902 #ifdef JetFitterRoutines_DEBUG2
903 ATH_MSG_DEBUG(
"Fast probability of merging between primary and " <<
904 (*VtxIter)->getNumVertex() <<
" is " << fastProbabilityAndNonLinearity.first <<
" and is max DR " <<
905 fastProbabilityAndNonLinearity.second );
908 if (fullcomputation) {
909 if (fastProbabilityAndNonLinearity.first>threshold_probability) {
910 if (fastProbabilityAndNonLinearity.first>highestprobability/100.&&fastProbabilityAndNonLinearity.second) {
912 double fullProbability=fullProbabilityOfMerging(primaryVertex,*VtxIter,
913 myJetCandidate,num_maxiterations,
915 num_signflip_maxiterations,
916 deltachi2_convergence);
919 #ifdef JetFitterRoutines_DEBUG2
920 ATH_MSG_DEBUG(
"Full probability of merging with primary is " << fullProbability );
923 ATH_MSG_DEBUG (
"Full probability of merging with primary is " << fullProbability);
927 clusteringTablePtr->setCompatibilityOfTo(PairOfVxVertexOnJetAxis(primaryVertex,*VtxIter),fullProbability);
928 if (fullProbability>highestprobability) {
929 highestprobability=fullProbability;
931 (*VtxIter)->setCompatibilityToPrimaryVtx(fullProbability);
933 clusteringTablePtr->setCompatibilityOfTo(PairOfVxVertexOnJetAxis(primaryVertex,*VtxIter),fastProbabilityAndNonLinearity.first);
934 (*VtxIter)->setCompatibilityToPrimaryVtx(fastProbabilityAndNonLinearity.first);
937 (*VtxIter)->setCompatibilityToPrimaryVtx(fastProbabilityAndNonLinearity.first);
940 if (fastProbabilityAndNonLinearity.first>threshold_probability) {
941 clusteringTablePtr->setCompatibilityOfTo(PairOfVxVertexOnJetAxis(primaryVertex,*VtxIter),fastProbabilityAndNonLinearity.first);
942 if (fastProbabilityAndNonLinearity.first>highestprobability) {
943 highestprobability=fastProbabilityAndNonLinearity.first;
946 (*VtxIter)->setCompatibilityToPrimaryVtx(fastProbabilityAndNonLinearity.first);
952 for (std::vector<Trk::VxVertexOnJetAxis*>::const_iterator VtxIter2=VtxBegin;
953 VtxIter2!=VtxEnd;++VtxIter2) {
954 for (std::vector<Trk::VxVertexOnJetAxis*>::const_iterator VtxIter1=VtxBegin;
955 VtxIter1!=VtxIter2;++VtxIter1) {
957 std::pair<double,bool> fastProbabilityAndNonLinearity=fastProbabilityOfMerging(*VtxIter1,
963 ATH_MSG_VERBOSE (
"Fast probability of merging between vtx n " << (*VtxIter1)->getNumVertex()<<
964 " and " << (*VtxIter2)->getNumVertex() <<
" is " <<
965 fastProbabilityAndNonLinearity.first <<
" and is max DR " <<
966 fastProbabilityAndNonLinearity.second);
968 #ifdef JetFitterRoutines_DEBUG2
969 ATH_MSG_DEBUG(
"Fast probability of merging between vtx n " << (*VtxIter1)->getNumVertex() <<
" and " <<
970 (*VtxIter2)->getNumVertex() <<
" is " << fastProbabilityAndNonLinearity.first <<
" and is max DR " <<
971 fastProbabilityAndNonLinearity.second );
973 if (fullcomputation) {
974 if (fastProbabilityAndNonLinearity.first>threshold_probability) {
975 if (fastProbabilityAndNonLinearity.first>highestprobability/100.&&fastProbabilityAndNonLinearity.second) {
976 double fullProbability=fullProbabilityOfMerging(*VtxIter1,*VtxIter2,
977 myJetCandidate,num_maxiterations,
979 num_signflip_maxiterations,
980 deltachi2_convergence);
983 #ifdef JetFitterRoutines_DEBUG2
984 ATH_MSG_DEBUG(
"Full probability of merging is " << fullProbability );
987 ATH_MSG_VERBOSE (
"Full probability of merging is " << fullProbability);
991 clusteringTablePtr->setCompatibilityOfTo(PairOfVxVertexOnJetAxis(*VtxIter1,*VtxIter2),fullProbability);
992 if (fullProbability>highestprobability) {
993 highestprobability=fullProbability;
996 clusteringTablePtr->setCompatibilityOfTo(PairOfVxVertexOnJetAxis(*VtxIter1,*VtxIter2),fastProbabilityAndNonLinearity.first);
1000 if (fastProbabilityAndNonLinearity.first>threshold_probability) {
1001 clusteringTablePtr->setCompatibilityOfTo(PairOfVxVertexOnJetAxis(*VtxIter1,*VtxIter2),fastProbabilityAndNonLinearity.first);
1002 if (fastProbabilityAndNonLinearity.first>highestprobability) {
1003 highestprobability=fastProbabilityAndNonLinearity.first;
1012 void JetFitterRoutines::deleteVertexFromJetCandidate(VxVertexOnJetAxis* vertexToDelete,
1013 VxJetCandidate* myJetCandidate)
const {
1014 if (vertexToDelete==myJetCandidate->getPrimaryVertex()) {
1015 ATH_MSG_WARNING (
"YOU ARE deleting the primary vertex. This is not possible... ");
1021 const Amg::VectorX & recPosition=myJetCandidate->getRecVertexPositions().position();
1022 const Amg::VectorX & linPosition=myJetCandidate->getLinearizationVertexPositions().position();
1023 const Amg::VectorX & constraintPosition=myJetCandidate->getConstraintVertexPositions().position();
1024 const Amg::MatrixX & covPosition=myJetCandidate->getRecVertexPositions().covariancePosition();
1025 const Amg::MatrixX & covConstraintPosition=myJetCandidate->getConstraintVertexPositions().covariancePosition();
1027 int numbVertex=numRow(vertexToDelete->getNumVertex());
1029 Amg::VectorX reducedRecPositions=deleteRowFromVector(recPosition,numbVertex);
1030 Amg::VectorX reducedLinPositions=deleteRowFromVector(linPosition,numbVertex);
1031 Amg::VectorX reducedConstraintPositions=deleteRowFromVector(constraintPosition,numbVertex);
1032 Amg::MatrixX reducedCovPositions=deleteRowFromSymMatrix(covPosition,numbVertex);
1033 Amg::MatrixX reducedConstraintCovPositions=deleteRowFromSymMatrix(covConstraintPosition,numbVertex);
1036 reducedCovPositions,
1038 myJetCandidate->setConstraintVertexPositions(
RecVertexPositions(reducedConstraintPositions,
1039 reducedConstraintCovPositions,
1041 myJetCandidate->setLinearizationVertexPositions(
VertexPositions(reducedLinPositions));
1048 std::vector<VxTrackAtVertex*>* tracksAtJetCandidate(myJetCandidate->vxTrackAtVertex());
1054 const std::vector<VxTrackAtVertex*> & tracksAtVtx(vertexToDelete->getTracksAtVertex());
1056 const std::vector<VxTrackAtVertex*>::const_iterator TracksAtVtxBegin=tracksAtVtx.begin();
1057 const std::vector<VxTrackAtVertex*>::const_iterator TracksAtVtxEnd=tracksAtVtx.end();
1059 int numberOfTracksBefore=tracksAtJetCandidate->size();
1060 int numberOfTracksToDelete=tracksAtVtx.size();
1062 for (std::vector<VxTrackAtVertex*>::const_iterator TracksAtVtxIter=TracksAtVtxBegin;
1063 TracksAtVtxIter!=TracksAtVtxEnd;
1064 ++TracksAtVtxIter) {
1071 if (*TracksIter==*TracksAtVtxIter) {
1073 TracksIter=tracksAtJetCandidate->erase(TracksIter);
1076 TracksEnd=tracksAtJetCandidate->end();
1084 if (numberOfTracksBefore-numberOfTracksToDelete!=(
int)myJetCandidate->vxTrackAtVertex()->size()) {
1085 ATH_MSG_DEBUG(
" MISMATCH in JetFitterRoutines: the jetcandidate had: " << numberOfTracksBefore <<
" tracks " <<
1086 " and " << numberOfTracksToDelete <<
" to delete = " << myJetCandidate->vxTrackAtVertex()->size() <<
" tracks left! " );
1092 std::vector<VxVertexOnJetAxis*> copyOfVerticesAtJetCandidate=myJetCandidate->getVerticesOnJetAxis();
1103 if ((*VerticesIter)==vertexToDelete) {
1104 delete *VerticesIter;
1105 VerticesIter=copyOfVerticesAtJetCandidate.erase(VerticesIter);
1106 VerticesEnd=copyOfVerticesAtJetCandidate.end();
1115 ATH_MSG_WARNING(
"Could not find the vertex to delete... Very strange... Check!!! " );
1119 myJetCandidate->setVerticesOnJetAxis(copyOfVerticesAtJetCandidate);
1122 m_initializationHelper->updateTrackNumbering(myJetCandidate);
1126 void JetFitterRoutines::copyRecoPositionsToLinearizationPositions(VxJetCandidate & myJetCandidate)
const
1129 const VertexPositions & newLinVertexPositions=myJetCandidate.getRecVertexPositions();
1130 Amg::VectorX linPositions=newLinVertexPositions.position();
1132 const std::vector<VxVertexOnJetAxis*> & associatedVertices=myJetCandidate.getVerticesOnJetAxis();
1133 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxBegin=associatedVertices.begin();
1134 const std::vector<VxVertexOnJetAxis*>::const_iterator VtxEnd=associatedVertices.end();
1136 for (std::vector<VxVertexOnJetAxis*>::const_iterator VtxIter=VtxBegin;VtxIter!=VtxEnd;++VtxIter) {
1137 VxVertexOnJetAxis* myVertex=(*VtxIter);
1138 if (myVertex!=
nullptr) {
1140 double distOnAxis=linPositions[numRow(myVertex->getNumVertex())];
1145 auto const absLinJetTheta = std::abs(linPositions[
Trk::jet_theta]);
1146 auto const abssinLinJetTheta = std::abs(sinLinJetTheta);
1147 auto const abscosLinJetTheta = std::abs(cosLinJetTheta);
1149 double R=distOnAxis*sinLinJetTheta;
1150 double Z=distOnAxis*cosLinJetTheta;
1151 if (std::abs(
R)>m_maxR)
1153 if (absLinJetTheta>1
e-8)
1155 ATH_MSG_DEBUG (
" Closest distance of track to jet axis is outside ID envelope, R=" <<
R <<
", setting to R= " << m_maxR);
1156 distOnAxis=m_maxR / abssinLinJetTheta;
1160 Z=distOnAxis*cosLinJetTheta;
1161 if (std::abs(
Z)>m_maxZ)
1163 if (abscosLinJetTheta>1
e-8)
1165 ATH_MSG_DEBUG(
" Closest distance of track to jet axis is outside ID envelope, Z=" <<
Z <<
", setting to Z= " << m_maxZ );
1166 distOnAxis=m_maxZ / cosLinJetTheta;
1170 linPositions[numRow(myVertex->getNumVertex())]=distOnAxis;
1174 VertexPositions & linVertexPositions=myJetCandidate.getLinearizationVertexPositions();