Belle II Software  release-06-02-00
FitParams.cc
1 /**************************************************************************
2  * basf2 (Belle II Analysis Software Framework) *
3  * Author: The Belle II Collaboration *
4  * External Contributor: Wouter Hulsbergen *
5  * *
6  * See git log for contributors and copyright holders. *
7  * This file is licensed under LGPL-3.0, see LICENSE.md. *
8  **************************************************************************/
9 
10 #include <analysis/VertexFitting/TreeFitter/FitParams.h>
11 #include <analysis/VertexFitting/TreeFitter/FitParameterDimensionException.h>
12 #include <string>
13 
14 namespace TreeFitter {
15 
16 
17  FitParams::FitParams(const int dim)
18  :
19  m_dim(dim),
20  m_chiSquare(1e10),
21  m_nConstraints(0),
22  m_dimensionReduction(0),
23  m_nConstraintsVec(dim, 0),
24  m_globalState(dim),
25  m_globalCovariance(dim, dim)
26  {
29  }
30 
32  {
33  m_globalState = Eigen::Matrix<double, Eigen::Dynamic, 1>::Zero(m_dim);
34  }
35 
37  {
39  Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE >::Zero(m_dim, m_dim);
40 
41  std::fill(m_nConstraintsVec.begin(), m_nConstraintsVec.end(), 0);
42  m_chiSquare = 0;
43  m_nConstraints = 0;
44  }
45 
47  {
48  bool ok = true;
49  for (int row = 0; row < m_dim; ++row) {
50  ok = (m_globalCovariance(row, row) > 0);
51  if (!ok) break;
52  }
53  return ok;
54  }
55 
56  double FitParams::chiSquare() const
57  {
58  return m_chiSquare;
59  }
60 
61  int FitParams::nDof() const
62  {
63  const int nConstr = nConstraints();
64  const int nPars = dim();
65  const int ndf = nConstr - nPars;
66  if (ndf < 1) {
67  const std::string error_string =
68  "Not enough constraints for this fit. Try adding a mass or beam constraint. constraints: " + std::to_string(
69  nConstr) + " parameters to extract: " + std::to_string(nPars) + " ndf: " + std::to_string(ndf);
70  throw FitParameterDimensionException(error_string);
71  }
72  return ndf;
73  }
74 
75 } //TreeFitter namespace
exception template, runtime_error implements what()
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > m_globalState
vector holding all parameters of this fit
Definition: FitParams.h:170
int nConstraints() const
get number of constraints
Definition: FitParams.h:113
int m_dim
dimension of statevector
Definition: FitParams.h:155
FitParams()
constructor
Definition: FitParams.h:150
std::vector< int > m_nConstraintsVec
vector with the number of constraints per parameter
Definition: FitParams.h:167
bool testCovariance() const
test if the covariance makes sense
Definition: FitParams.cc:46
double chiSquare() const
get chi2 of statevector
Definition: FitParams.cc:56
int nDof() const
get numer of degrees of freedom
Definition: FitParams.cc:61
int dim() const
get dimension od statevector
Definition: FitParams.h:107
double m_chiSquare
chi2
Definition: FitParams.h:158
void resetStateVector()
reset the staevector
Definition: FitParams.cc:31
int m_nConstraints
number of conatraints
Definition: FitParams.h:161
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > m_globalCovariance
covariance of the global state
Definition: FitParams.h:173
void resetCovariance()
reset the staevector
Definition: FitParams.cc:36