Belle II Software  release-05-02-19
FitParams.h
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 #pragma once
11 
12 #include <analysis/VertexFitting/TreeFitter/EigenStackConfig.h>
13 #include <Eigen/Core>
14 #include <vector>
15 
16 namespace TreeFitter {
17 
18  class ParticleBase;
19 
21  class FitParams {
22 
23  public:
24 
26  explicit FitParams(const int dim);
27 
29  ~FitParams() {};
30 
32  FitParams(const FitParams& toCopy)
33  : m_dim(toCopy.m_dim),
34  m_chiSquare(toCopy.m_chiSquare),
37  m_globalState(Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > (toCopy.m_globalState)),
38  m_globalCovariance(Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > (toCopy.m_globalCovariance))
39  { }
40 
42  FitParams& operator =(const FitParams& other)
43  {
44  m_dim = other.m_dim;
45  m_chiSquare = other.m_chiSquare;
46  m_nConstraints = other.m_nConstraints;
47  m_dimensionReduction = other.m_dimensionReduction;
48  m_globalState = other.m_globalState;
49  m_globalCovariance = other.m_globalCovariance;
50  return *this;
51  }
52 
54  Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
55  {
56  return m_globalCovariance;
57  }
58 
60  const Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance() const
61  {
63  }
64 
66  Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector() {return m_globalState;}
67 
69  const Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector() const
70  {
71  return m_globalState;
72  }
73 
75  double& getRefToElementOfStateVec(int row) { return m_globalState(row, 0); }
76 
78  const double& getRefToElementOfStateVec(int row) const { return m_globalState(row, 0); }
79 
81  double getCovDiaElement(int counter) { return m_globalCovariance(counter, counter); }
82 
84  void resetStateVector();
85 
87  void resetCovariance();
88 
90  void resizeAndResetStateAndCov(int newdim);
91 
93  int getDimensionOfState() const {return m_dim;};
94 
96  int getNConstraints() {return m_nConstraints;}
97 
99  bool testCovariance() const;
100 
102  int& incrementNConstraintsVec(int row) { return m_nConstraintsVec[row];}
103 
105  int& nConstraintsVec(int row) { return m_nConstraintsVec[row - 1]; }
106 
108  int dim() const { return m_dim; }
109 
111  double chiSquare() const;
112 
114  int nConstraints() const { return m_nConstraints; }
115 
117  int nDof() const;
118 
120  void resize(int newdim);
121 
123  void resetPar();
124 
126  bool testCov() const;
127 
129  void addNConstraint(int value) { m_nConstraints += value; }
130 
132  void addChiSquare(double chisq, int nconstraints)
133  {
134  m_chiSquare += chisq;
135  m_nConstraints += nconstraints;
136  }
137 
139  void resetChiSquare()
140  {
141  m_chiSquare = 0;
142  m_nConstraints = 0;
143  }
144 
146  typedef std::vector< std::pair<const ParticleBase*, int> > indexmap;
147 
148  protected:
149 
151  FitParams() {}
152 
153  private:
154 
156  int m_dim;
157 
159  double m_chiSquare;
160 
162  int m_nConstraints;
163 
166 
168  std::vector<int> m_nConstraintsVec;
169 
171  Eigen::Matrix < double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > m_globalState;
172 
174  Eigen::Matrix < double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > m_globalCovariance;
175 
176  };
177 }
TreeFitter::FitParams::nDof
int nDof() const
get numer of degrees of freedom
Definition: FitParams.cc:70
TreeFitter::FitParams::resetChiSquare
void resetChiSquare()
reset chi2
Definition: FitParams.h:147
TreeFitter::FitParams::incrementNConstraintsVec
int & incrementNConstraintsVec(int row)
increment nconstraints vec
Definition: FitParams.h:110
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::getDimensionOfState
int getDimensionOfState() const
get the states dimension
Definition: FitParams.h:101
TreeFitter::FitParams::resizeAndResetStateAndCov
void resizeAndResetStateAndCov(int newdim)
resize and reset statevec and its covariance
TreeFitter::FitParams::testCov
bool testCov() const
check if global cov makes sense
TreeFitter::FitParams::chiSquare
double chiSquare() const
get chi2 of statevector
Definition: FitParams.cc:65
TreeFitter::FitParams::getCovariance
Eigen::Matrix< double, -1, -1, 0, MAX_MATRIX_SIZE, MAX_MATRIX_SIZE > & getCovariance()
getter for the states covariance
Definition: FitParams.h:62
TreeFitter::FitParams::getRefToElementOfStateVec
double & getRefToElementOfStateVec(int row)
get a reference to an element of the state vector todo replace by setter?
Definition: FitParams.h:83
TreeFitter::FitParams::resize
void resize(int newdim)
resize (enlarge!) the statevector
TreeFitter::FitParams
Class to store and manage fitparams (statevector)
Definition: FitParams.h:29
TreeFitter::FitParams::indexmap
std::vector< std::pair< const ParticleBase *, int > > indexmap
index map
Definition: FitParams.h:154
TreeFitter::FitParams::m_nConstraintsVec
std::vector< int > m_nConstraintsVec
vector with the number of constraints per parameter
Definition: FitParams.h:176
TreeFitter::FitParams::getNConstraints
int getNConstraints()
get dimension sum of constraints
Definition: FitParams.h:104
TreeFitter::FitParams::m_chiSquare
double m_chiSquare
chi2
Definition: FitParams.h:167
TreeFitter::FitParams::getStateVector
Eigen::Matrix< double, -1, 1, 0, MAX_MATRIX_SIZE, 1 > & getStateVector()
getter for the fit parameters/statevector
Definition: FitParams.h:74
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::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::addNConstraint
void addNConstraint(int value)
some constraints are special the geometric for example
Definition: FitParams.h:137
TreeFitter::FitParams::resetPar
void resetPar()
set statevector elements to 0
TreeFitter::FitParams::~FitParams
~FitParams()
Destructor.
Definition: FitParams.h:37
TreeFitter::FitParams::nConstraintsVec
int & nConstraintsVec(int row)
returns a reference(!) to the number of constraints for rows parameter.
Definition: FitParams.h:113
TreeFitter::FitParams::getCovDiaElement
double getCovDiaElement(int counter)
get an covaraince diagonal element
Definition: FitParams.h:89
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::m_dimensionReduction
int m_dimensionReduction
reduce the ndf used in the chi2 by this count
Definition: FitParams.h:173
TreeFitter::FitParams::addChiSquare
void addChiSquare(double chisq, int nconstraints)
increment global chi2
Definition: FitParams.h:140
TreeFitter::FitParams::operator=
FitParams & operator=(const FitParams &other)
Assignment operator.
Definition: FitParams.h:50
TreeFitter::FitParams::resetCovariance
void resetCovariance()
reset the staevector
Definition: FitParams.cc:45