Belle II Software  release-05-01-25
FitParams.cc
1 /**************************************************************************
2  * BASF2 (Belle Analysis Framework 2) *
3  * Copyright(C) 2018 - Belle II Collaboration *
4  * *
5  * Author: The Belle II Collaboration *
6  * Contributor: Wouter Hulsbergen, Francesco Tenchini, Jo-Frederik Krohn *
7  * *
8  * This software is provided "as is" without any warranty. *
9  **************************************************************************/
10 
11 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
12 #include <analysis/VertexFitting/TreeFitter/FitParameterDimensionException.h>
13 #include <string>
14 
15 namespace TreeFitter {
16 
17 
18  FitParams::FitParams(const int dim)
19  :
20  m_dim(dim),
21  m_chiSquare(1e10),
22  m_nConstraints(0),
23  m_dimensionReduction(0),
24  m_nConstraintsVec(dim, 0),
25  m_globalState(dim),
26  m_globalCovariance(dim, dim)
27  {
28  resetStateVector();
29  resetCovariance();
30  }
31 
33  {
34  m_globalState = Eigen::Matrix<double, Eigen::Dynamic, 1>::Zero(m_dim);
35  }
36 
38  {
40  Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE >::Zero(m_dim, m_dim);
41 
42  std::fill(m_nConstraintsVec.begin(), m_nConstraintsVec.end(), 0);
43  m_chiSquare = 0;
44  m_nConstraints = 0;
45  }
46 
47  bool FitParams::testCovariance() const
48  {
49  bool ok = true;
50  for (int row = 0; row < m_dim; ++row) {
51  ok = (m_globalCovariance(row, row) > 0);
52  if (!ok) break;
53  }
54  return ok;
55  }
56 
57  double FitParams::chiSquare() const
58  {
59  return m_chiSquare;
60  }
61 
62  int FitParams::nDof() const
63  {
64  const int nConstr = nConstraints();
65  const int nPars = dim();
66  const int ndf = nConstr - nPars;
67  if (ndf < 1) {
68  const std::string error_string =
69  "Not enough constraints for this fit. Try adding a mass or beam cosntraint. constraints: " + std::to_string(
70  nConstr) + " parameters to extract: " + std::to_string(nPars) + " ndf: " + std::to_string(ndf);
71  throw FitParameterDimensionException(error_string);
72  }
73  return ndf;
74  }
75 
76 } //TreeFitter namespace
TreeFitter::FitParams::nDof
int nDof() const
get numer of degrees of freedom
Definition: FitParams.cc:70
TreeFitter::FitParams::nConstraints
int nConstraints() const
get number of constraints
Definition: FitParams.h:122
TreeFitter::FitParams::resetStateVector
void resetStateVector()
reset the staevector
Definition: FitParams.cc:40
TreeFitter::FitParams::chiSquare
double chiSquare() const
get chi2 of statevector
Definition: FitParams.cc:65
TreeFitter::FitParams::m_nConstraintsVec
std::vector< int > m_nConstraintsVec
vector with the number of constraints per parameter
Definition: FitParams.h:176
TreeFitter::FitParams::m_chiSquare
double m_chiSquare
chi2
Definition: FitParams.h:167
TreeFitter::FitParams::m_globalCovariance
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > m_globalCovariance
covariance of the global state
Definition: FitParams.h:182
TreeFitter::FitParameterDimensionException
exception template, runtime_error implements what()
Definition: FitParameterDimensionException.h:22
TreeFitter::FitParams::m_globalState
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > m_globalState
vector holding all parameters of this fit
Definition: FitParams.h:179
TreeFitter::FitParams::dim
int dim() const
get dimension od statevector
Definition: FitParams.h:116
TreeFitter::FitParams::FitParams
FitParams()
constructor
Definition: FitParams.h:159
TreeFitter::FitParams::m_dim
int m_dim
dimension of statevector
Definition: FitParams.h:164
TreeFitter::FitParams::testCovariance
bool testCovariance() const
test if the covariance makes sense
Definition: FitParams.cc:55
TreeFitter::FitParams::m_nConstraints
int m_nConstraints
number of conatraints
Definition: FitParams.h:170
TreeFitter::FitParams::resetCovariance
void resetCovariance()
reset the staevector
Definition: FitParams.cc:45