MarlinKinfit  0.4.0
NewtonFitterGSL.h
Go to the documentation of this file.
1 
34 #ifndef __NEWTONFITTERGSL_H
35 #define __NEWTONFITTERGSL_H
36 
37 #include "BaseFitter.h"
38 
39 #include <gsl/gsl_vector.h>
40 #include <gsl/gsl_matrix.h>
41 #include <gsl/gsl_permutation.h>
42 #include <gsl/gsl_eigen.h>
43 
44 // Class NewtonFitterGSL
46 
47 class NewtonFitterGSL : public BaseFitter {
48  public:
52  virtual ~NewtonFitterGSL();
53 
55  virtual double fit();
56 
58  virtual int getError() const;
59 
61  virtual double getProbability() const;
63  virtual double getChi2() const;
65  virtual int getDoF() const;
67  virtual int getIterations() const;
68 
70  virtual int getNcon() const;
71 
73  virtual int getNsoft() const;
74 
76  virtual int getNpar() const;
77 
79  virtual int getNunm() const;
80 
82  virtual bool initialize();
83 
85  virtual void setDebug (int debuglevel);
86 
87  protected:
89  virtual double calcChi2();
90 
92  int calcDx ();
93 
95  int calcDxSVD ();
96 
98  void printMy (double M[], double y[], int idim);
99 
100  bool updateParams (gsl_vector *xnew);
101  void fillxold();
102  void fillperr();
103  int calcM (bool errorpropagation = false);
104  int calcy();
105  int optimizeScale();
106  int invertM();
107 
108  void calcCovMatrix();
109 
110  double meritFunction(double mu);
111  double meritFunctionDeriv(double mu);
112 
113  enum {NPARMAX=50, NCONMAX=10, NUNMMAX=10};
114 
115  int npar;
116  int ncon;
117  int nsoft;
118  int nunm;
119  int ierr;
120  int nit;
121 
122  double fitprob;
123  double chi2;
124 
125  static void ini_gsl_permutation (gsl_permutation *&p, unsigned int size);
126  static void ini_gsl_vector (gsl_vector *&v, int unsigned size);
127  static void ini_gsl_matrix (gsl_matrix *&m, int unsigned size1, unsigned int size2);
128 
129  static void debug_print (gsl_matrix *m, const char *name);
130  static void debug_print (gsl_vector *v, const char *name);
131 
132  private:
133  unsigned int idim;
134  gsl_vector *x;
135  gsl_vector *xold;
136  gsl_vector *xbest;
137  gsl_vector *dx;
138  gsl_vector *dxscal;
139  gsl_vector *grad;
140  gsl_vector *y;
141  gsl_vector *yscal;
142  gsl_vector *perr;
143  gsl_vector *v1;
144  gsl_vector *v2;
145  gsl_vector *Meval;
146 
147  gsl_matrix *M;
148  gsl_matrix *Mscal;
149  gsl_matrix *M1;
150  gsl_matrix *M2;
151  gsl_matrix *M3;
152  gsl_matrix *M4;
153  gsl_matrix *M5;
154  gsl_matrix *Mevec;
155  gsl_matrix *CC;
156  gsl_matrix *CC1;
157  gsl_matrix *CCinv;
158 
159  gsl_permutation *permM;
160  gsl_eigen_symmv_workspace *ws;
161  unsigned int wsdim;
162 
163  double chi2best;
164  double chi2new;
165  double chi2old;
166  double fvalbest;
167  double scale;
168  double scalebest;
169  double stepsize;
170  double stepbest;
171  enum {NITMAX = 100};
172  double scalevals[NITMAX];
173  double fvals[NITMAX];
174 
175  int imerit;
176 
177  int debug;
178 };
179 
180 #endif // __NEWTONFITTERGSL_H
virtual int getNunm() const
Get the number of unmeasured parameters of the last fit.
Definition: NewtonFitterGSL.cc:697
A kinematic fitter using the Newton-Raphson method to solve the equations.
Definition: NewtonFitterGSL.h:47
int calcDx()
Calculate the vector dx to update the parameters; returns fail code, 0=OK.
Definition: NewtonFitterGSL.cc:490
int nit
Number of iterations.
Definition: NewtonFitterGSL.h:120
virtual int getNsoft() const
Get the number of soft constraints of the last fit.
Definition: NewtonFitterGSL.cc:696
int npar
total number of parameters
Definition: NewtonFitterGSL.h:115
Abstract base class for fitting engines of kinematic fits.
Definition: BaseFitter.h:63
int calcDxSVD()
Calculate the vector dx to update the parameters; returns fail code, 0=OK.
Definition: NewtonFitterGSL.cc:536
void printMy(double M[], double y[], int idim)
Print a Matrix M and a vector y of dimension idim.
Definition: NewtonFitterGSL.cc:476
int ncon
total number of hard constraints
Definition: NewtonFitterGSL.h:116
virtual double getChi2() const
Get the chi**2 of the last fit.
Definition: NewtonFitterGSL.cc:486
NewtonFitterGSL()
Constructor.
Definition: NewtonFitterGSL.cc:80
virtual double getProbability() const
Get the fit probability of the last fit.
Definition: NewtonFitterGSL.cc:485
int ierr
Error status.
Definition: NewtonFitterGSL.h:119
virtual int getNcon() const
Get the number of hard constraints of the last fit.
Definition: NewtonFitterGSL.cc:695
virtual double calcChi2()
Calculate the chi2.
Definition: NewtonFitterGSL.cc:461
Declares class BaseFitter.
virtual int getError() const
Get the error code of the last fit: 0=OK, 1=failed.
Definition: NewtonFitterGSL.cc:484
double chi2
final chi2
Definition: NewtonFitterGSL.h:123
virtual double fit()
The fit method, returns the fit probability.
Definition: NewtonFitterGSL.cc:127
virtual bool initialize()
Initialize the fitter.
Definition: NewtonFitterGSL.cc:381
double fitprob
fit probability
Definition: NewtonFitterGSL.h:122
int nunm
total number of unmeasured parameters
Definition: NewtonFitterGSL.h:118
virtual ~NewtonFitterGSL()
Virtual destructor.
Definition: NewtonFitterGSL.cc:96
virtual int getIterations() const
Get the number of iterations of the last fit.
Definition: NewtonFitterGSL.cc:488
virtual void setDebug(int debuglevel)
Set the Debug Level.
Definition: NewtonFitterGSL.cc:1025
int nsoft
total number of soft constraints
Definition: NewtonFitterGSL.h:117
virtual int getDoF() const
Get the number of degrees of freedom of the last fit.
Definition: NewtonFitterGSL.cc:487
virtual int getNpar() const
Get the number of all parameters of the last fit.
Definition: NewtonFitterGSL.cc:698