Belle II Software  release-06-02-00
FitParams.h
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 #pragma once
10 
11 #include <analysis/VertexFitting/TreeFitter/EigenStackConfig.h>
12 #include <Eigen/Core>
13 #include <vector>
14 
15 namespace TreeFitter {
16 
17  class ParticleBase;
18 
20  class FitParams {
21 
22  public:
23 
25  explicit FitParams(const int dim);
26 
28  ~FitParams() {};
29 
31  FitParams(const FitParams& toCopy)
32  : m_dim(toCopy.m_dim),
33  m_chiSquare(toCopy.m_chiSquare),
36  m_globalState(Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > (toCopy.m_globalState)),
37  m_globalCovariance(Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > (toCopy.m_globalCovariance))
38  { }
39 
42  {
43  m_dim = other.m_dim;
44  m_chiSquare = other.m_chiSquare;
49  return *this;
50  }
51 
53  Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
54  {
55  return m_globalCovariance;
56  }
57 
59  const Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance() const
60  {
61  return m_globalCovariance;
62  }
63 
65  Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector() {return m_globalState;}
66 
68  const Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector() const
69  {
70  return m_globalState;
71  }
72 
74  double& getRefToElementOfStateVec(int row) { return m_globalState(row, 0); }
75 
77  const double& getRefToElementOfStateVec(int row) const { return m_globalState(row, 0); }
78 
80  double getCovDiaElement(int counter) { return m_globalCovariance(counter, counter); }
81 
83  void resetStateVector();
84 
86  void resetCovariance();
87 
89  void resizeAndResetStateAndCov(int newdim);
90 
92  int getDimensionOfState() const {return m_dim;};
93 
96 
98  bool testCovariance() const;
99 
101  int& incrementNConstraintsVec(int row) { return m_nConstraintsVec[row];}
102 
104  int& nConstraintsVec(int row) { return m_nConstraintsVec[row - 1]; }
105 
107  int dim() const { return m_dim; }
108 
110  double chiSquare() const;
111 
113  int nConstraints() const { return m_nConstraints; }
114 
116  int nDof() const;
117 
119  void resize(int newdim);
120 
122  void resetPar();
123 
125  bool testCov() const;
126 
128  void addNConstraint(int value) { m_nConstraints += value; }
129 
131  void addChiSquare(double chisq, int nconstraints)
132  {
133  m_chiSquare += chisq;
134  m_nConstraints += nconstraints;
135  }
136 
139  {
140  m_chiSquare = 0;
141  m_nConstraints = 0;
142  }
143 
145  typedef std::vector< std::pair<const ParticleBase*, int> > indexmap;
146 
147  protected:
148 
151 
152  private:
153 
155  int m_dim;
156 
158  double m_chiSquare;
159 
162 
165 
167  std::vector<int> m_nConstraintsVec;
168 
170  Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > m_globalState;
171 
173  Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > m_globalCovariance;
174 
175  };
176 }
Class to store and manage fitparams (statevector)
Definition: FitParams.h:20
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > m_globalState
vector holding all parameters of this fit
Definition: FitParams.h:170
~FitParams()
Destructor.
Definition: FitParams.h:28
double getCovDiaElement(int counter)
get an covaraince diagonal element
Definition: FitParams.h:80
int getNConstraints()
get dimension sum of constraints
Definition: FitParams.h:95
const double & getRefToElementOfStateVec(int row) const
get a const reference to an element of the state vector todo replace by setter?
Definition: FitParams.h:77
void addChiSquare(double chisq, int nconstraints)
increment global chi2
Definition: FitParams.h:131
int nConstraints() const
get number of constraints
Definition: FitParams.h:113
int m_dim
dimension of statevector
Definition: FitParams.h:155
void resizeAndResetStateAndCov(int newdim)
resize and reset statevec and its covariance
void resetPar()
set statevector elements to 0
int & incrementNConstraintsVec(int row)
increment nconstraints vec
Definition: FitParams.h:101
FitParams()
constructor
Definition: FitParams.h:150
double & getRefToElementOfStateVec(int row)
get a reference to an element of the state vector todo replace by setter?
Definition: FitParams.h:74
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
Definition: FitParams.h:53
int & nConstraintsVec(int row)
returns a reference(!) to the number of constraints for rows parameter.
Definition: FitParams.h:104
void resize(int newdim)
resize (enlarge!) the statevector
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
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
Definition: FitParams.h:65
double chiSquare() const
get chi2 of statevector
Definition: FitParams.cc:56
void addNConstraint(int value)
some constraints are special the geometric for example
Definition: FitParams.h:128
FitParams & operator=(const FitParams &other)
Assignment operator.
Definition: FitParams.h:41
const Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance() const
const getter for the states covariance
Definition: FitParams.h:59
int nDof() const
get numer of degrees of freedom
Definition: FitParams.cc:61
int getDimensionOfState() const
get the states dimension
Definition: FitParams.h:92
const Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector() const
const getter for the fit parameters/statevector
Definition: FitParams.h:68
int dim() const
get dimension od statevector
Definition: FitParams.h:107
int m_dimensionReduction
reduce the ndf used in the chi2 by this count
Definition: FitParams.h:164
double m_chiSquare
chi2
Definition: FitParams.h:158
bool testCov() const
check if global cov makes sense
std::vector< std::pair< const ParticleBase *, int > > indexmap
index map
Definition: FitParams.h:145
void resetStateVector()
reset the staevector
Definition: FitParams.cc:31
void resetChiSquare()
reset chi2
Definition: FitParams.h:138
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
FitParams(const FitParams &toCopy)
copy constructor
Definition: FitParams.h:31