Belle II Software light-2406-ragdoll
NewtonFitterGSL.h
1/**************************************************************************
2 * basf2 (Belle II Analysis Software Framework) *
3 * Author: The Belle II Collaboration *
4 * *
5 * Forked from https://github.com/iLCSoft/MarlinKinfit *
6 * *
7 * Further information about the fit engine and the user interface *
8 * provided in MarlinKinfit can be found at *
9 * https://www.desy.de/~blist/kinfit/doc/html/ *
10 * and in the LCNotes LC-TOOL-2009-001 and LC-TOOL-2009-004 available *
11 * from http://www-flc.desy.de/lcnotes/ *
12 * *
13 * See git log for contributors and copyright holders. *
14 * This file is licensed under LGPL-3.0, see LICENSE.md. *
15 **************************************************************************/
16
17#ifndef __NEWTONFITTERGSL_H
18#define __NEWTONFITTERGSL_H
19
20#include "analysis/OrcaKinFit/BaseFitter.h"
21
22#include <gsl/gsl_vector.h>
23#include <gsl/gsl_matrix.h>
24#include <gsl/gsl_permutation.h>
25#include <gsl/gsl_eigen.h>
26
27// Class NewtonFitterGSL
29
30namespace Belle2 {
36 namespace OrcaKinFit {
37
38 class NewtonFitterGSL : public BaseFitter {
39 public:
43 virtual ~NewtonFitterGSL();
44
46 virtual double fit() override;
47
49 virtual int getError() const override;
50
52 virtual double getProbability() const override;
54 virtual double getChi2() const override;
56 virtual int getDoF() const override;
58 virtual int getIterations() const override;
59
61 virtual int getNcon() const;
62
64 virtual int getNsoft() const;
65
67 virtual int getNpar() const;
68
70 virtual int getNunm() const;
71
73 virtual bool initialize() override;
74
76 virtual void setDebug(int debuglevel);
77
78 protected:
80 virtual double calcChi2();
81
83 int calcDx();
84
86 int calcDxSVD();
87
89 void printMy(const double M[], const double y[], int idim);
90
91 bool updateParams(gsl_vector* xnew);
92 void fillxold();
93 void fillperr();
94 int calcM(bool errorpropagation = false);
95 int calcy();
96 int optimizeScale();
97 int invertM();
98
99 void calcCovMatrix();
100
101 double meritFunction(double mu);
102 double meritFunctionDeriv();
103
104 enum {NPARMAX = 50, NCONMAX = 10, NUNMMAX = 10};
105
106 int npar;
107 int ncon;
108 int nsoft;
109 int nunm;
110 int ierr;
111 int nit;
112
113 double fitprob;
114 double chi2;
115
116 static void ini_gsl_permutation(gsl_permutation*& p, unsigned int size);
117 static void ini_gsl_vector(gsl_vector*& v, int unsigned size);
118 static void ini_gsl_matrix(gsl_matrix*& m, int unsigned size1, unsigned int size2);
119
120 static void debug_print(gsl_matrix* m, const char* name);
121 static void debug_print(gsl_vector* v, const char* name);
122
123 private:
124 unsigned int idim;
125 gsl_vector* x;
126 gsl_vector* xold;
127 gsl_vector* xbest;
128 gsl_vector* dx;
129 gsl_vector* dxscal;
130 gsl_vector* grad;
131 gsl_vector* y;
132 gsl_vector* yscal;
133 gsl_vector* perr;
134 gsl_vector* v1;
135 gsl_vector* v2;
136 gsl_vector* Meval;
137
138 gsl_matrix* M;
139 gsl_matrix* Mscal;
140 gsl_matrix* M1;
141 gsl_matrix* M2;
142 gsl_matrix* M3;
143 gsl_matrix* M4;
144 gsl_matrix* M5;
145 gsl_matrix* Mevec;
146 gsl_matrix* CC;
147 gsl_matrix* CC1;
148 gsl_matrix* CCinv;
149
150 gsl_permutation* permM;
151 gsl_eigen_symmv_workspace* ws;
152 unsigned int wsdim;
153
154 double chi2best;
155 double chi2new;
156 double chi2old;
157 double fvalbest;
158 double scale;
159 double scalebest;
160 double stepsize;
161 double stepbest;
162 enum {NITMAX = 100};
163 double scalevals[NITMAX];
164 double fvals[NITMAX];
165
166 int imerit;
167
168 int debug;
169 };
170
171 }// end OrcaKinFit namespace
173} // end Belle2 namespace
174
175#endif // __NEWTONFITTERGSL_H
Abstract base class for fitting engines of kinematic fits.
Definition: BaseFitter.h:47
int ncon
total number of hard constraints
int calcDxSVD()
Calculate the vector dx to update the parameters; returns fail code, 0=OK.
int npar
total number of parameters
virtual double calcChi2()
Calculate the chi2.
void printMy(const double M[], const double y[], int idim)
Print a Matrix M and a vector y of dimension idim.
virtual int getNsoft() const
Get the number of soft constraints of the last fit.
virtual double fit() override
The fit method, returns the fit probability.
virtual bool initialize() override
Initialize the fitter.
virtual int getNcon() const
Get the number of hard constraints of the last fit.
int nsoft
total number of soft constraints
virtual int getError() const override
Get the error code of the last fit: 0=OK, 1=failed.
int nunm
total number of unmeasured parameters
int calcDx()
Calculate the vector dx to update the parameters; returns fail code, 0=OK.
virtual int getNunm() const
Get the number of unmeasured parameters of the last fit.
virtual int getIterations() const override
Get the number of iterations of the last fit.
virtual double getProbability() const override
Get the fit probability of the last fit.
virtual void setDebug(int debuglevel)
Set the Debug Level.
virtual int getDoF() const override
Get the number of degrees of freedom of the last fit.
virtual double getChi2() const override
Get the chi**2 of the last fit.
virtual int getNpar() const
Get the number of all parameters of the last fit.
virtual ~NewtonFitterGSL()
Virtual destructor.
Abstract base class for different kinds of events.
Definition: ClusterUtils.h:24