9#include <analysis/VertexFitting/RaveInterface/RaveKinematicVertexFitter.h>
10#include <analysis/VertexFitting/RaveInterface/RaveSetup.h>
13#include <Math/ProbFunc.h>
15#include <rave/TransientTrackKinematicParticle.h>
16#include <rave/impl/RaveBase/Converters/interface/RaveStreamers.h>
18#include <rave/KinematicTreeFactory.h>
19#include <rave/KinematicConstraint.h>
20#include <rave/KinematicConstraintBuilder.h>
21#include <rave/VertexFactory.h>
33using namespace analysis;
38 m_massConstFit(false), m_vertFit(true)
41 B2FATAL(
"RaveSetup::initialize was not called. It has to be called before RaveSetup or RaveKinematicVertexFitter are used");
70 rave::Vector7D raveState(aParticlePtr->
getX(), aParticlePtr->
getY(), aParticlePtr->
getZ(), aParticlePtr->
getPx(),
75 for (
int i = 0; i < 7; i++) {
76 for (
int j = 0; j < 7; j++) {
77 if (i < 3 && j < 3) covE(i, j) = covP(i + 4, j + 4);
78 if (i > 2 && j > 2) covE(i, j) = covP(i - 3, j - 3);
79 if (i < 3 && j > 2) covE(i, j) = covP(i + 4, j - 3);
80 if (i > 2 && j < 3) covE(i, j) = covP(i - 3, j + 4);
86 rave::Covariance7D raveCov(cov(0, 0), cov(0, 1), cov(0, 2),
87 cov(1, 1), cov(1, 2), cov(2, 2),
88 cov(0, 3), cov(0, 4), cov(0, 5),
89 cov(1, 3), cov(1, 4), cov(1, 5),
90 cov(2, 3), cov(2, 4), cov(2, 5),
91 cov(3, 3), cov(3, 4), cov(3, 5),
92 cov(4, 4), cov(4, 5), cov(5, 5),
93 cov(0, 6), cov(1, 6), cov(2, 6),
94 cov(3, 6), cov(4, 6), cov(5, 6),
97 rave::TransientTrackKinematicParticle aRaveParticle(raveState, raveCov, rave::Charge(aParticlePtr->
getCharge()), 1, 1);
107 vector<Particle*> daughters = aMotherParticlePtr->
getDaughters();
109 int nDaughters = daughters.size();
110 for (
int i = 0; i not_eq nDaughters; ++i) {
115 auto* tmp =
const_cast<Particle*
>(aMotherParticlePtr);
123 auto* tmp =
const_cast<Particle*
>(aMotherParticlePtr);
137 int nOfVertices = -100;
141 const rave::Covariance3D bsCovRave(bsCov(0, 0), bsCov(0, 1), bsCov(0, 2), bsCov(1, 1), bsCov(1, 2), bsCov(2, 2));
148 rave::KinematicConstraint cs2 = rave::KinematicConstraintBuilder().createMultiTrackMassKinematicConstraint(
176 rave::Vector7D raveState(aParticlePtr->
getX(), aParticlePtr->
getY(), aParticlePtr->
getZ(), aParticlePtr->
getPx(),
184 for (
int i = 0; i < 7; i++) {
185 for (
int j = 0; j < 7; j++) {
186 if (i < 3 && j < 3) covE(i, j) = covP(i + 4, j + 4);
187 if (i > 2 && j > 2) covE(i, j) = covP(i - 3, j - 3);
188 if (i < 3 && j > 2) covE(i, j) = covP(i + 4, j - 3);
189 if (i > 2 && j < 3) covE(i, j) = covP(i - 3, j + 4);
195 rave::Covariance7D raveCov(cov(0, 0), cov(0, 1), cov(0, 2),
196 cov(1, 1), cov(1, 2), cov(2, 2),
197 cov(0, 3), cov(0, 4), cov(0, 5),
198 cov(1, 3), cov(1, 4), cov(1, 5),
199 cov(2, 3), cov(2, 4), cov(2, 5),
200 cov(3, 3), cov(3, 4), cov(3, 5),
201 cov(4, 4), cov(4, 5), cov(5, 5),
202 cov(0, 6), cov(1, 6), cov(2, 6),
203 cov(3, 6), cov(4, 6), cov(5, 6),
206 rave::TransientTrackKinematicParticle aRaveParticle(raveState, raveCov, rave::Charge(aParticlePtr->
getCharge()), chi2, ndf);
208 std::vector< rave::KinematicParticle > parts; parts.push_back(aRaveParticle);
210 rave::KinematicConstraint constraint = rave::KinematicConstraintBuilder().createMassKinematicConstraint(
216 constraint,
"ppf:lppf");
221 B2ERROR(
"[RaveKinematicVertexFitter]: VertexException saying ParentParticleFitter::error inverting covariance matrix occurred");
234 rave::Vector7D fittedState;
235 rave::Covariance7D fittedCov;
249 if (nOfVertices == 0) {
254 rave::KinematicVertex fittedVertex =
m_fittedResult.currentDecayVertex();
259 m_fittedPos.SetXYZ(fittedVertex.position().x(), fittedVertex.position().y(), fittedVertex.position().z());
269 m_fitted4Vector.SetXYZT(fittedState.p4().p3().x(), fittedState.p4().p3().y(), fittedState.p4().p3().z(), fittedState.p4().energy());
273 TMatrixDSym fitted7CovM(7);
275 fitted7CovM(3, 6) = fittedCov.dpxm(); fitted7CovM(6, 3) = fitted7CovM(3, 6);
276 fitted7CovM(4, 6) = fittedCov.dpym(); fitted7CovM(6, 4) = fitted7CovM(4, 6);
277 fitted7CovM(5, 6) = fittedCov.dpzm(); fitted7CovM(6, 5) = fitted7CovM(5, 6);
278 fitted7CovM(6, 6) = fittedCov.dmm(); fitted7CovM(6, 6) = fitted7CovM(6, 6);
279 fitted7CovM(0, 6) = fittedCov.dxm(); fitted7CovM(6, 0) = fitted7CovM(0, 6);
280 fitted7CovM(1, 6) = fittedCov.dym(); fitted7CovM(6, 1) = fitted7CovM(1, 6);
281 fitted7CovM(2, 6) = fittedCov.dzm(); fitted7CovM(6, 2) = fitted7CovM(2, 6);
283 fitted7CovM(3, 3) = fittedCov.dpxpx(); fitted7CovM(3, 3) = fitted7CovM(3, 3);
284 fitted7CovM(3, 4) = fittedCov.dpxpy(); fitted7CovM(4, 3) = fitted7CovM(3, 4);
285 fitted7CovM(3, 5) = fittedCov.dpxpz(); fitted7CovM(5, 3) = fitted7CovM(3, 5);
286 fitted7CovM(3, 0) = fittedCov.dxpx(); fitted7CovM(0, 3) = fitted7CovM(3, 0);
287 fitted7CovM(3, 1) = fittedCov.dypx(); fitted7CovM(1, 3) = fitted7CovM(3, 1);
288 fitted7CovM(3, 2) = fittedCov.dzpx(); fitted7CovM(2, 3) = fitted7CovM(3, 2);
290 fitted7CovM(4, 4) = fittedCov.dpypy(); fitted7CovM(4, 4) = fitted7CovM(4, 4);
291 fitted7CovM(4, 5) = fittedCov.dpypz(); fitted7CovM(5, 4) = fitted7CovM(4, 5);
292 fitted7CovM(4, 0) = fittedCov.dxpy(); fitted7CovM(0, 4) = fitted7CovM(4, 0);
293 fitted7CovM(4, 1) = fittedCov.dypy(); fitted7CovM(1, 4) = fitted7CovM(4, 1);
294 fitted7CovM(4, 2) = fittedCov.dzpy(); fitted7CovM(2, 4) = fitted7CovM(4, 2);
296 fitted7CovM(5, 5) = fittedCov.dpzpz(); fitted7CovM(5, 5) = fitted7CovM(5, 5);
297 fitted7CovM(5, 0) = fittedCov.dxpz(); fitted7CovM(0, 5) = fitted7CovM(5, 0);
298 fitted7CovM(5, 1) = fittedCov.dypz(); fitted7CovM(1, 5) = fitted7CovM(5, 1);
299 fitted7CovM(5, 2) = fittedCov.dzpz(); fitted7CovM(2, 5) = fitted7CovM(5, 2);
301 fitted7CovM(0, 0) = fittedCov.dxx(); fitted7CovM(0, 0) = fitted7CovM(0, 0);
302 fitted7CovM(0, 1) = fittedCov.dxy(); fitted7CovM(1, 0) = fitted7CovM(0, 1);
303 fitted7CovM(0, 2) = fittedCov.dxz(); fitted7CovM(2, 0) = fitted7CovM(0, 2);
305 fitted7CovM(1, 1) = fittedCov.dyy(); fitted7CovM(1, 1) = fitted7CovM(1, 1);
306 fitted7CovM(1, 2) = fittedCov.dyz(); fitted7CovM(2, 1) = fitted7CovM(1, 2);
308 fitted7CovM(2, 2) = fittedCov.dzz(); fitted7CovM(2, 2) = fitted7CovM(2, 2);
312 for (
int i = 0; i < 7; i++) {
313 for (
int j = 0; j < 7; j++) {
314 if (i < 4 && j < 4)
m_fitted7Cov(i, j) = fitted7CovE(i + 3, j + 3);
315 if (i > 3 && j > 3)
m_fitted7Cov(i, j) = fitted7CovE(i - 4, j - 4);
316 if (i < 4 && j > 3)
m_fitted7Cov(i, j) = fitted7CovE(i + 3, j - 4);
317 if (i > 3 && j < 4)
m_fitted7Cov(i, j) = fitted7CovE(i - 4, j + 3);
333 std::vector< rave::KinematicParticle > rDau =
m_fittedResult.daughterParticles();
335 if (rDau.size() == bDau.size()) {
336 for (
unsigned ii = 0; ii < bDau.size(); ii++) {
337 rave::Vector7D fittedState;
338 rave::Covariance7D fittedCov;
339 fittedState = rDau[ii].fullstate();
340 fittedCov = rDau[ii].fullerror();
342 ROOT::Math::PxPyPzEVector p4(fittedState.p4().p3().x(), fittedState.p4().p3().y(), fittedState.p4().p3().z(),
343 fittedState.p4().energy());
345 ROOT::Math::XYZVector x3(fittedState.x(), fittedState.y(), fittedState.z());
348 TMatrixDSym fitted7CovM(7);
349 fitted7CovM(3, 6) = fittedCov.dpxm(); fitted7CovM(6, 3) = fitted7CovM(3, 6);
350 fitted7CovM(4, 6) = fittedCov.dpym(); fitted7CovM(6, 4) = fitted7CovM(4, 6);
351 fitted7CovM(5, 6) = fittedCov.dpzm(); fitted7CovM(6, 5) = fitted7CovM(5, 6);
352 fitted7CovM(6, 6) = fittedCov.dmm(); fitted7CovM(6, 6) = fitted7CovM(6, 6);
353 fitted7CovM(0, 6) = fittedCov.dxm(); fitted7CovM(6, 0) = fitted7CovM(0, 6);
354 fitted7CovM(1, 6) = fittedCov.dym(); fitted7CovM(6, 1) = fitted7CovM(1, 6);
355 fitted7CovM(2, 6) = fittedCov.dzm(); fitted7CovM(6, 2) = fitted7CovM(2, 6);
357 fitted7CovM(3, 3) = fittedCov.dpxpx(); fitted7CovM(3, 3) = fitted7CovM(3, 3);
358 fitted7CovM(3, 4) = fittedCov.dpxpy(); fitted7CovM(4, 3) = fitted7CovM(3, 4);
359 fitted7CovM(3, 5) = fittedCov.dpxpz(); fitted7CovM(5, 3) = fitted7CovM(3, 5);
360 fitted7CovM(3, 0) = fittedCov.dxpx(); fitted7CovM(0, 3) = fitted7CovM(3, 0);
361 fitted7CovM(3, 1) = fittedCov.dypx(); fitted7CovM(1, 3) = fitted7CovM(3, 1);
362 fitted7CovM(3, 2) = fittedCov.dzpx(); fitted7CovM(2, 3) = fitted7CovM(3, 2);
364 fitted7CovM(4, 4) = fittedCov.dpypy(); fitted7CovM(4, 4) = fitted7CovM(4, 4);
365 fitted7CovM(4, 5) = fittedCov.dpypz(); fitted7CovM(5, 4) = fitted7CovM(4, 5);
366 fitted7CovM(4, 0) = fittedCov.dxpy(); fitted7CovM(0, 4) = fitted7CovM(4, 0);
367 fitted7CovM(4, 1) = fittedCov.dypy(); fitted7CovM(1, 4) = fitted7CovM(4, 1);
368 fitted7CovM(4, 2) = fittedCov.dzpy(); fitted7CovM(2, 4) = fitted7CovM(4, 2);
370 fitted7CovM(5, 5) = fittedCov.dpzpz(); fitted7CovM(5, 5) = fitted7CovM(5, 5);
371 fitted7CovM(5, 0) = fittedCov.dxpz(); fitted7CovM(0, 5) = fitted7CovM(5, 0);
372 fitted7CovM(5, 1) = fittedCov.dypz(); fitted7CovM(1, 5) = fitted7CovM(5, 1);
373 fitted7CovM(5, 2) = fittedCov.dzpz(); fitted7CovM(2, 5) = fitted7CovM(5, 2);
375 fitted7CovM(0, 0) = fittedCov.dxx(); fitted7CovM(0, 0) = fitted7CovM(0, 0);
376 fitted7CovM(0, 1) = fittedCov.dxy(); fitted7CovM(1, 0) = fitted7CovM(0, 1);
377 fitted7CovM(0, 2) = fittedCov.dxz(); fitted7CovM(2, 0) = fitted7CovM(0, 2);
379 fitted7CovM(1, 1) = fittedCov.dyy(); fitted7CovM(1, 1) = fitted7CovM(1, 1);
380 fitted7CovM(1, 2) = fittedCov.dyz(); fitted7CovM(2, 1) = fitted7CovM(1, 2);
382 fitted7CovM(2, 2) = fittedCov.dzz(); fitted7CovM(2, 2) = fitted7CovM(2, 2);
386 TMatrixDSym fitted7CovDauM(7);
387 for (
int i = 0; i < 7; i++) {
388 for (
int j = 0; j < 7; j++) {
389 if (i < 4 && j < 4) fitted7CovDauM(i, j) = fitted7CovE(i + 3, j + 3);
390 if (i > 3 && j > 3) fitted7CovDauM(i, j) = fitted7CovE(i - 4, j - 4);
391 if (i < 4 && j > 3) fitted7CovDauM(i, j) = fitted7CovE(i + 3, j - 4);
392 if (i > 3 && j < 4) fitted7CovDauM(i, j) = fitted7CovE(i - 4, j + 3);
396 float pValDau = rDau[ii].chi2();
398 bDau[ii]->updateMomentum(p4, x3, fitted7CovDauM, pValDau);
402 }
else B2ERROR(
"Error in Daughters update");
438 TMatrixDSym posErr(3);
457 for (
int i = 0; i < 7; i++) {
458 for (
int j = 0; j < 7; j++) {
459 if (i == j) jac(i, j) = 1;
463 jac(6, 3) = p4.Px() / p4.E();
464 jac(6, 4) = p4.Py() / p4.E();
465 jac(6, 5) = p4.Pz() / p4.E();
466 jac(6, 6) = p4.M() / p4.E();
469 TMatrix jact(7, 7); jact.Transpose(jac);
470 TMatrix EnergyErrPart(7, 7); EnergyErrPart.Mult(jac, MassErr);
471 TMatrix EnergyErrTemp(7, 7); EnergyErrTemp.Mult(EnergyErrPart, jact);
473 TMatrixDSym EnergyErr(7);
474 for (
int i = 0; i < 7; i++) {
475 for (
int j = 0; j < 7; j++) {
476 EnergyErr(i, j) = EnergyErrTemp(i, j);
487 for (
int i = 0; i < 7; i++) {
488 for (
int j = 0; j < 7; j++) {
489 if (i == j) jac(i, j) = 1;
493 jac(6, 3) = -1 * p4.Px() / p4.M();
494 jac(6, 4) = -1 * p4.Py() / p4.M();
495 jac(6, 5) = -1 * p4.Pz() / p4.M();
496 jac(6, 6) = p4.E() / p4.M();
498 TMatrix jact(7, 7); jact.Transpose(jac);
499 TMatrix MassErrPart(7, 7); MassErrPart.Mult(jac, EnergyErr);
500 TMatrix MassErrTemp(7, 7); MassErrTemp.Mult(MassErrPart, jact);
502 TMatrixDSym MassErr(7);
503 for (
int i = 0; i < 7; i++) {
504 for (
int j = 0; j < 7; j++) {
505 MassErr(i, j) = MassErrTemp(i, j);
DataType Z() const
access variable Z (= .at(2) without boundary check)
DataType X() const
access variable X (= .at(0) without boundary check)
DataType Y() const
access variable Y (= .at(1) without boundary check)
Simple RAII guard for output interceptor.
Capture stdout and stderr and convert into log messages.
@ c_Debug
Debug: for code development.
Class to store reconstructed particles.
double getPx() const
Returns x component of momentum.
double getPz() const
Returns z component of momentum.
double getX() const
Returns x component of vertex position.
double getPy() const
Returns y component of momentum.
std::vector< Belle2::Particle * > getDaughters() const
Returns a vector of pointers to daughter particles.
double getZ() const
Returns z component of vertex position.
double getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
double getCharge(void) const
Returns particle charge.
ROOT::Math::PxPyPzEVector get4Vector() const
Returns Lorentz vector.
double getY() const
Returns y component of vertex position.
void updateMomentum(const ROOT::Math::PxPyPzEVector &p4, const ROOT::Math::XYZVector &vertex, const TMatrixFSym &errMatrix, double pValue)
Sets Lorentz vector, position, 7x7 error matrix and p-value.
TMatrixFSym getMomentumVertexErrorMatrix() const
Returns 7x7 error matrix.
double getMass() const
Returns invariant mass (= nominal for FS particles)
std::vector< Particle * > m_belleDaughters
Belle Particle pointers input.
TMatrixDSym ErrorMatrixEnergyToMass(const ROOT::Math::PxPyPzEVector &p4, const TMatrixDSym &EnergyErr)
Convert the error matrix from P-E to P-M.
void updateMother()
update the mother particle
IOIntercept::InterceptorScopeGuard< IOIntercept::OutputToLogMessages > captureOutput()
Start capturing the output of rave and divert it to log messages.
ROOT::Math::PxPyPzEVector m_fitted4Vector
4 momentum of the mother particle after the fit
TMatrixFSym m_fitted7Cov
7x7 error matrix of the mother particle after the fit
TMatrixDSym getCov()
get the covariance matrix (7x7).
rave::KinematicParticle m_fittedParticle
Particle fit output.
bool m_useBeamSpot
flag determines if the beam spot will be used or not.
void addMother(const Particle *aMotherParticlePtr)
All daughters of the argument of this function will be used as input for the vertex fit.
ROOT::Math::XYZVector getPos()
get the position of the fitted vertex.
~RaveKinematicVertexFitter()
Destructor.
void addTrack(const Particle *aParticlePtr)
add a track (in the format of a Belle2::Particle) to set of tracks that should be fitted to a vertex
bool m_massConstFit
flag determines if the mass fit is performed
TMatrixDSym ErrorMatrixMassToEnergy(const ROOT::Math::PxPyPzEVector &p4, const TMatrixDSym &MassErr)
Convert the error matrix from P-M to P-E.
void setMother(const Particle *aMotherParticlePtr)
Set Mother particle for Vertex/momentum update.
RaveKinematicVertexFitter()
The default constructor checks if RaveSetup was initialized and will set the attributes of RaveKinema...
rave::KinematicTree m_fittedResult
the output of the kinematic fit
int fit()
do the kinematic vertex fit with all tracks previously added with the addTrack or addMother function.
double m_fittedPValue
Pvalue of the fit result.
Particle * m_motherParticlePtr
pointer to the mother particle who's daughters will be used in the fit.
void setVertFit(bool isVertFit=true)
Set vertex fit: set false in case of mass fit only.
void setMassConstFit(bool isConstFit=true)
Set mass constrained fit
Particle * getMother()
returns a pointer to the mother particle
double m_fittedChi2
chi^2 of the vertex fit
double getPValue()
get the p value of the fitted vertex.
TMatrixDSym getVertexErrorMatrix()
get the covariance matrix (3x3) of the of the fitted vertex position.
double m_fittedNdf
Ndf of the vertex fit.
double getChi2()
get the χ² of the fitted vertex.
std::vector< rave::KinematicParticle > m_inputParticles
input particles for vertex fit in rave format
double getNdf()
get the number of degrees of freedom (NDF) of the fitted vertex.
bool m_vertFit
flag determines if the vertex fit is performed
void updateDaughters()
update the Daughters particles
ROOT::Math::XYZVector m_fittedPos
Fitted vertex position.
TMatrixDSym m_beamSpotCov
beam spot position covariance matrix.
rave::KinematicTreeFactory * m_raveKinematicTreeFactory
< The RAVE Kinematic Tree factory is the principal interface offered by the RAVE for kinematic vertex...
bool m_useBeamSpot
flag determines if beam spot information should be used for vertex fit.
static RaveSetup * getRawInstance()
Same as getInstance(), but no check if the instance is initialised.
B2Vector3D m_beamSpot
beam spot position.
rave::VertexFactory * m_raveVertexFactory
The RAVE vertex factory is the principal interface offered by the RAVE vertex fitting library.
InterceptorScopeGuard< T > start_intercept(T &interceptor)
Convenience wrapper to simplify use of InterceptorScopeGuard<T>.
Abstract base class for different kinds of events.