40 declareInterface< JetFitterHelper >(
this) ;
44 JetFitterHelper::~JetFitterHelper() =
default;
47 void JetFitterHelper::addTracksOfFirstVertexToSecondVertex(
const VxVertexOnJetAxis &
first,VxVertexOnJetAxis &
second)
const {
55 std::vector<VxTrackAtVertex*> tracksOfSecondVertex(
second.getTracksAtVertex());
57 const std::vector<VxTrackAtVertex*>& tracksOfFirstVertex(
first.getTracksAtVertex());
59 const std::vector<VxTrackAtVertex*>::const_iterator tracksBegin=tracksOfFirstVertex.begin();
60 const std::vector<VxTrackAtVertex*>::const_iterator tracksEnd=tracksOfFirstVertex.end();
62 for (std::vector<VxTrackAtVertex*>::const_iterator tracksIter=tracksBegin;
63 tracksIter!=tracksEnd;
66 if (*tracksIter!=
nullptr) {
68 tracksOfSecondVertex.push_back(*tracksIter);
71 ATH_MSG_WARNING(
" addTracksOfFirstVertexToSecondVertex method found an empty pointer for a track of the first vertex. Skipping it..." );
77 second.setTracksAtVertex(std::move(tracksOfSecondVertex));
81 void JetFitterHelper::performKalmanConstraintToBePrimaryVertex(RecVertexPositions & positionToUpdate,
82 const VxVertexOnJetAxis & vertexToConstraint)
const {
85 const Amg::VectorX position(positionToUpdate.position());
86 const Amg::MatrixX Ckm1(positionToUpdate.covariancePosition());
88 if (position.rows()!=Ckm1.rows()) {
89 ATH_MSG_WARNING (
"Error in performKalmanConstraintToBePrimaryVertex method:" <<
90 " covariance matrix of size " << Ckm1.rows() <<
91 " and vector of VertexPositions do not match. Not performing " <<
92 "any constraint... ");
96 int numbRow(numRow(vertexToConstraint.getNumVertex()));
105 if(Rk_km1.determinant()==0) {
106 ATH_MSG_WARNING (
"The Rk_k-1 matrix inversion will fail - det(Rk)=0 detected."
107 " Constraint to primary vertex failed...");
117 ConstraintInOldPosition(0)=position[numbRow];
119 Amg::
VectorX newPosition=position-Kk*ConstraintInOldPosition;
121 Amg::
MatrixX newCovPosition=Ckm1-Kk*(2*Gk*Ckm1-Rk_km1*Kk.transpose());
125 double newNDF=positionToUpdate.
fitQuality().numberDoF()+1;
137 const Amg::VectorX & position(positionToUpdate.position());
138 const Amg::MatrixX & Ckm1(positionToUpdate.covariancePosition());
140 if (position.rows()!=Ckm1.rows()) {
141 ATH_MSG_WARNING(
"Error in performKalmanConstraintToBePrimaryVertex method: " <<
142 "covariance matrix dim " << Ckm1.rows() <<
" and vector of " <<
143 "VertexPositions dim " << position.rows() <<
" do not match."<<
144 " Not performing any constraint... ");
148 int numbRow1(numRow(vertexToConstraint1.getNumVertex()));
149 int numbRow2(numRow(vertexToConstraint2.getNumVertex()));
159 if(Rk_km1.determinant() ==0) {
160 ATH_MSG_WARNING (
"The Rk_k-1 matrix inversion will fail - Rk_k=0 detected."
161 " Constraint to primary vertex failed...");
167 Amg::
MatrixX Kk=Ckm1*Gk.transpose()*Rk_km1_inverse;
171 ConstraintInOldPosition(0)=position[numbRow1]-position[numbRow2];
173 Amg::
VectorX newPosition=position-Kk*ConstraintInOldPosition;
175 Amg::
MatrixX newCovPosition=Ckm1-Kk*(2*Gk*Ckm1-Rk_km1*Kk.transpose());
178 double newNDF=positionToUpdate.
fitQuality().numberDoF()+1;
187 if (&vertex1==myJetCandidate.getPrimaryVertex()) {
188 mergeVertexToPrimaryInJetCandidate(vertex2,myJetCandidate);
189 return *myJetCandidate.getPrimaryVertex();
191 if (&vertex2 == myJetCandidate.getPrimaryVertex()) {
192 mergeVertexToPrimaryInJetCandidate(vertex1, myJetCandidate);
193 return *myJetCandidate.getPrimaryVertex();
196 addTracksOfFirstVertexToSecondVertex(vertex2,vertex1);
200 const Amg::VectorX & recPosition=myJetCandidate.getRecVertexPositions().position();
201 Amg::VectorX linPosition=myJetCandidate.getLinearizationVertexPositions().position();
202 const Amg::VectorX & constraintPosition=myJetCandidate.getConstraintVertexPositions().position();
203 const Amg::MatrixX & covPosition=myJetCandidate.getRecVertexPositions().covariancePosition();
204 const Amg::MatrixX & covConstraintPosition=myJetCandidate.getConstraintVertexPositions().covariancePosition();
207 int numbVertex2=numRow(vertex2.getNumVertex());
210 int numbVertex1=numRow(vertex1.getNumVertex());
211 if (covPosition(numbVertex1,numbVertex1)!=0&&covPosition(numbVertex2,numbVertex2)!=0) {
212 linPosition(numbVertex1)=(recPosition(numbVertex1)/covPosition(numbVertex1,numbVertex1)+
213 recPosition(numbVertex2)/covPosition(numbVertex2,numbVertex2))/
214 (1./covPosition(numbVertex1,numbVertex1)+1./covPosition(numbVertex2,numbVertex2));
216 ATH_MSG_WARNING (
"one of the vertices to merge has error on position 0. should not happen, however: --> proceeding...");
220 Amg::VectorX reducedRecPositions=deleteRowFromVector(recPosition,numbVertex2);
221 Amg::VectorX reducedLinPositions=deleteRowFromVector(linPosition,numbVertex2);
222 Amg::VectorX reducedConstraintPositions=deleteRowFromVector(constraintPosition,numbVertex2);
223 Amg::MatrixX reducedCovPositions=deleteRowFromSymMatrix(covPosition,numbVertex2);
224 Amg::MatrixX reducedConstraintCovPositions=deleteRowFromSymMatrix(covConstraintPosition,numbVertex2);
226 myJetCandidate.setRecVertexPositions(RecVertexPositions(reducedRecPositions,
229 myJetCandidate.setConstraintVertexPositions(RecVertexPositions(reducedConstraintPositions,
230 reducedConstraintCovPositions,
234 myJetCandidate.setLinearizationVertexPositions(VertexPositions(reducedLinPositions));
238 std::vector<VxVertexOnJetAxis*> copyOfVerticesAtJetCandidate=myJetCandidate.getVerticesOnJetAxis();
246 if ((*VerticesIter)==&vertex2) {
247 delete *VerticesIter;
248 VerticesIter=copyOfVerticesAtJetCandidate.erase(VerticesIter);
249 VerticesEnd=copyOfVerticesAtJetCandidate.end();
257 ATH_MSG_WARNING (
"Could not find second vertex from which a cluster was created to delete it... Very strange... Check!!! ");
261 myJetCandidate.setVerticesOnJetAxis(copyOfVerticesAtJetCandidate);
268 void JetFitterHelper::mergeVertexToPrimaryInJetCandidate(VxVertexOnJetAxis &
vertex,VxJetCandidate & myJetCandidate)
const {
270 VxVertexOnJetAxis* primaryVertexPtr(myJetCandidate.getPrimaryVertex());
272 if (primaryVertexPtr==
nullptr) {
273 ATH_MSG_WARNING (
"Pointer to the primary vertex is 0. No merging with primary vertex possible.");
277 VxVertexOnJetAxis primaryVertex(*primaryVertexPtr);
279 addTracksOfFirstVertexToSecondVertex(
vertex,primaryVertex);
283 const Amg::VectorX & recPosition=myJetCandidate.getRecVertexPositions().position();
284 Amg::VectorX linPosition=myJetCandidate.getLinearizationVertexPositions().position();
285 const Amg::VectorX & constraintPosition=myJetCandidate.getConstraintVertexPositions().position();
286 const Amg::MatrixX & covPosition=myJetCandidate.getRecVertexPositions().covariancePosition();
287 const Amg::MatrixX & covConstraintPosition=myJetCandidate.getConstraintVertexPositions().covariancePosition();
289 int numbVertex2=numRow(
vertex.getNumVertex());
292 Amg::VectorX reducedRecPositions=deleteRowFromVector(recPosition,numbVertex2);
293 Amg::VectorX reducedLinPositions=deleteRowFromVector(linPosition,numbVertex2);
294 Amg::VectorX reducedConstraintPositions=deleteRowFromVector(constraintPosition,numbVertex2);
295 Amg::MatrixX reducedCovPositions=deleteRowFromSymMatrix(covPosition,numbVertex2);
296 Amg::MatrixX reducedConstraintCovPositions=deleteRowFromSymMatrix(covConstraintPosition,numbVertex2);
301 myJetCandidate.setConstraintVertexPositions(
RecVertexPositions(reducedConstraintPositions,
302 reducedConstraintCovPositions,
305 myJetCandidate.setLinearizationVertexPositions(
VertexPositions(reducedLinPositions));
309 std::vector<VxVertexOnJetAxis*> copyOfVerticesAtJetCandidate=myJetCandidate.getVerticesOnJetAxis();
317 if ((*VerticesIter)==&
vertex) {
318 delete *VerticesIter;
319 VerticesIter=copyOfVerticesAtJetCandidate.erase(VerticesIter);
320 VerticesEnd=copyOfVerticesAtJetCandidate.end();
328 ATH_MSG_WARNING (
"Could not find second vertex from which a cluster with the primary vertex was created to delete it... Very strange... Check!!! ");
332 myJetCandidate.setVerticesOnJetAxis(copyOfVerticesAtJetCandidate);
333 myJetCandidate.setPrimaryVertex(&primaryVertex);