11 #include <analysis/dataobjects/Particle.h>
13 #include <framework/logging/Logger.h>
14 #include <framework/gearbox/Const.h>
16 #include <analysis/VertexFitting/TreeFitter/FitManager.h>
17 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
18 #include <analysis/VertexFitting/TreeFitter/DecayChain.h>
19 #include <analysis/VertexFitting/TreeFitter/ParticleBase.h>
21 namespace TreeFitter {
27 const bool useReferencing
30 m_decaychain(nullptr),
35 m_updateDaugthers(updateDaughters),
38 m_useReferencing(useReferencing),
57 if (part->hasExtraInfo(name)) {
58 part->setExtraInfo(name, value);
60 part->addExtraInfo(name, value);
67 const int nitermax = 100;
68 const int maxndiverging = 3;
69 double dChisqConv =
m_prec;
73 if (
m_status == VertexStatus::UnFitted) {
82 bool finished =
false;
100 if ((std::abs(deltachisq) /
m_chiSquare < dChisqConv)) {
105 }
else if (deltachisq > 0 && ++ndiverging >= maxndiverging) {
107 m_status = VertexStatus::NonConverged;
110 }
else if (deltachisq > 0) {
113 if (deltachisq < 0) {
121 m_status = VertexStatus::NonConverged;
129 if (
m_status == VertexStatus::Success) {
138 return (
m_status == VertexStatus::Success);
165 Eigen::Matrix<double, Eigen::Dynamic, Eigen::Dynamic> cov =
m_fitparams->
getCovariance().selfadjointView<Eigen::Lower>();
168 if (posindex < 0 && pb->mother()) {
175 for (
int row = 0; row < 4; ++row) {
176 for (
int col = 0; col < 4; ++col) {
177 returncov(row, col) = cov(momindex + row, momindex + col);
181 for (
int row = 0; row < 3; ++row) {
182 for (
int col = 0; col < 3; ++col) {
183 returncov(row + 4, col + 4) = cov(posindex + row, posindex + col);
188 Eigen::Matrix<double, 6, 6> cov6 =
189 Eigen::Matrix<double, 6, 6>::Zero(6, 6);
191 for (
int row = 0; row < 3; ++row) {
192 for (
int col = 0; col < 3; ++col) {
193 cov6(row, col) = cov(momindex + row, momindex + col);
194 cov6(row + 3, col + 3) = cov(posindex + row, posindex + col);
199 Eigen::Matrix<double, 3, 1> momVec =
202 double energy2 = momVec.transpose() * momVec;
203 energy2 += mass * mass;
204 double energy = sqrt(energy2);
206 Eigen::Matrix<double, 7, 6> jacobian =
207 Eigen::Matrix<double, 7, 6>::Zero(7, 6);
209 for (
int col = 0; col < 3; ++col) {
210 jacobian(col, col) = 1;
212 jacobian(col + 4, col + 3) = 1;
215 Eigen::Matrix<double, 7, 7> cov7
216 = jacobian * cov6.selfadjointView<Eigen::Lower>() * jacobian.transpose();
218 for (
int row = 0; row < 7; ++row) {
219 for (
int col = 0; col < 7; ++col) {
220 returncov(row, col) = cov7(row, col);
234 return pb !=
nullptr;
241 if (posindex < 0 && pb.
mother()) {
255 setExtraInfo(&cand,
"modifiedPValue", TMath::Prob(fitparchi2, 3));
260 if (motherPosIndex >= 0) {
279 p.SetE(std::sqrt(p.Vect()*p.Vect() + mass * mass));
282 TMatrixFSym cov7b2(7);
289 std::tuple<double, double>life =
getLifeTime(cand);
290 setExtraInfo(&cand, std::string(
"decayLength"), std::get<0>(tau));
291 setExtraInfo(&cand, std::string(
"decayLengthErr"), std::get<1>(tau));
292 setExtraInfo(&cand, std::string(
"lifeTime"), std::get<0>(life));
293 setExtraInfo(&cand, std::string(
"lifeTimeErr"), std::get<1>(life));
299 const bool updateableMother =
updateCand(cand, isTreeHead);
301 if (updateableMother and not cand.
hasExtraInfo(
"bremsCorrected")) {
303 for (
int i = 0; i < ndaughters; i++) {
315 const int momindex = pb->
momIndex();
320 Eigen::Matrix<double, 4, 4> comb_cov = Eigen::Matrix<double, 4, 4>::Zero(4, 4);
324 const double lenErr = std::get<1>(lenTuple);
325 comb_cov(0, 0) = lenErr * lenErr;
330 comb_cov.block<3, 3>(1, 1) = mom_cov;
332 const double mass = pb->
pdgMass();
334 const double mom = mom_vec.norm();
335 const double mom3 = mom * mom * mom;
337 const double len = std::get<0>(lenTuple);
338 const double t = len / mom * mBYc;
340 Eigen::Matrix<double, 1, 4> jac = Eigen::Matrix<double, 1, 4>::Zero();
341 jac(0) = 1. / mom * mBYc;
342 jac(1) = -1. * len * mom_vec(0) / mom3 * mBYc;
343 jac(2) = -1. * len * mom_vec(1) / mom3 * mBYc;
344 jac(3) = -1. * len * mom_vec(2) / mom3 * mBYc;
346 const double tErr2 = jac * comb_cov.selfadjointView<Eigen::Lower>() * jac.transpose();
348 return std::make_tuple(t, std::sqrt(tErr2));
350 return std::make_tuple(-999, -999);
362 const int tauindex = pb->
tauIndex();
364 const double lenErr2 = fitparams.
getCovariance()(tauindex, tauindex);
365 return std::make_tuple(len, std::sqrt(lenErr2));
367 return std::make_tuple(-999, -999);
372 std::tuple<double, double> rc = std::make_tuple(-999, -999);
static const double speedOfLight
[cm/ns]
Class to store reconstructed particles.
void set4Vector(const TLorentzVector &p4)
Sets Lorentz vector.
void setPValue(float pValue)
Sets chi^2 probability of fit.
std::string getName() const override
Return name of this particle.
void setVertex(const TVector3 &vertex)
Sets position (decay vertex)
float getPDGMass(void) const
Returns uncertainty on the invariant mass (requires valid momentum error matrix)
bool hasExtraInfo(const std::string &name) const
Return whether the extra info with the given name is set.
unsigned getNDaughters(void) const
Returns number of daughter particles.
void setMomentumVertexErrorMatrix(const TMatrixFSym &errMatrix)
Sets 7x7 error matrix.
const Particle * getDaughter(unsigned i) const
Returns a pointer to the i-th daughter particle.
const std::vector< int > m_massConstraintListPDG
list of pdg codes to mass constrain
this class does a lot of stuff: Build decaytree structure allowing to index particles and handle the ...
ErrCode initialize(FitParams &par)
initialize the chain
const ParticleBase * cand()
get candidate
const ParticleBase * locate(Belle2::Particle *bc) const
convert Belle2::particle into particle base(fitter base particle)
int momIndex(Belle2::Particle *bc) const
get momentum index of the particle in the state vector
int dim() const
get dimension
ErrCode filterWithReference(FitParams &par, const FitParams &ref)
filter with respect to a previous iteration for better stability
int tauIndex(Belle2::Particle *bc) const
get tau (i.e.
ErrCode filter(FitParams &par)
filter down the chain
int posIndex(Belle2::Particle *bc) const
get the vertex index of the particle in state vector
abstract errorocode be aware that the default is success
bool failure() const
returns true if errorcode is error
void reset()
reset the errorcode to default (success!)
int momIndex(Belle2::Particle *particle) const
getter for the index of the momentum in the state vector
const ConstraintConfiguration m_config
config container
DecayChain * m_decaychain
the decay tree
int posIndex(Belle2::Particle *particle) const
getter for the index of the vertex position in the state vector
int tauIndex(Belle2::Particle *particle) const
getter for the index of tau, the lifetime in the statevector
void setExtraInfo(Belle2::Particle *part, const std::string &name, const double value) const
add extrainfo to particle
ErrCode m_errCode
errorcode
int nDof() const
getter for degrees of freedom of the fitparameters
void getCovFromPB(const ParticleBase *pb, TMatrixFSym &returncov) const
extract cov from particle base
void updateTree(Belle2::Particle &particle, const bool isTreeHead) const
update the Belle2::Particles with the fit results
FitParams * m_fitparams
parameters to be fitted
const bool m_updateDaugthers
if this is set all daughters will be updated otherwise only the head of the tree
~FitManager()
destructor does stuff
int m_ndf
number of degrees of freedom for this topology
double m_prec
precision that is needed for status:converged (delta chi2)
bool fit()
main fit function that uses the kalman filter
int m_status
status of the current iteration
Belle2::Particle * particle()
getter for the head of the tree
Belle2::Particle * m_particle
head of the tree
int m_niter
iteration index
double m_chiSquare
chi2 of the current iteration
bool m_useReferencing
use referencing
VertexStatus
status flag of the fit-itereation (the step in the newton method)
std::tuple< double, double > getLifeTime(Belle2::Particle &cand) const
get lifetime
std::tuple< double, double > getDecayLength(const ParticleBase *pb) const
get decay length
bool updateCand(Belle2::Particle &particle, const bool isTreeHead) const
update particles parameters with the fit results
Class to store and manage fitparams (statevector)
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
bool testCovariance() const
test if the covariance makes sense
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
double chiSquare() const
get chi2 of statevector
int nDof() const
get numer of degrees of freedom
base class for all particles
virtual int dim() const =0
get dimension of constraint
virtual void forceP4Sum(FitParams &) const
force p4 sum conservation all along the tree
virtual int posIndex() const
get vertex index (in statevector!)
virtual int momIndex() const
get momentum index
virtual bool hasEnergy() const
get momentum dimension
virtual int tauIndex() const
get tau index
const ParticleBase * mother() const
getMother() / hasMother()
double pdgMass() const
get pdg mass