CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
SaturationFit.h
Go to the documentation of this file.
1 #include "Minuit2/VariableMetricMinimizer.h"
2 #include "Minuit2/FunctionMinimum.h"
3 #include "Minuit2/MnPrint.h"
4 
5 #include <vector>
6 #include <cmath>
8 
9 class SaturationFit{
10 
11  public:
12 
13  SaturationFit(int N,float *charge_ptr,float *adc_ptr, float *u0_ptr, float *u1_ptr, float *u2_ptr, float*u3_ptr){
14  double u[3],sigma[3],chisq;
15  VariableMetricMinimizer* pMinimizer=new VariableMetricMinimizer() ;
16  SaturationFcn* pFcn=new SaturationFcn();
17  pFcn->set_data(N,charge_ptr,adc_ptr);
18  std::vector<double> par(4,0);
19  std::vector<double> err(4,0);
20  //printf(" about to fill pars \n");
21  par[0]=pFcn->x0start;
22  par[1]=pFcn->x1start;
23  par[2]=pFcn->x2start;
24  par[3]=pFcn->x3start;
25  //printf(" pars: %f %f %f %f \n",par[0],par[1],par[2],par[3]);
26  err[0]=20.0;
27  err[1]=0.0001;
28  err[2]=1.0;
29  err[3]=20.0;
30  FunctionMinimum fmin = pMinimizer->Minimize(*pFcn, par, err, 1, 5000, 0.01);
31  if( !fmin.IsValid()){
32  printf(" minuit did not converge \n");
33  } else {
34  std::cout<<"fit succeeded... results: "<<fmin<<std::endl;
35  chisq = fmin.Fval();
36  u[0] = fmin.UserParameters().Value( static_cast<unsigned int>(0) );
37  *u0_ptr=u[0];
38  sigma[0] = fmin.UserParameters().Error( static_cast<unsigned int>(0) );
39  u[1] = fmin.UserParameters().Value( static_cast<unsigned int>(1) );
40  *u1_ptr=u[1];
41  sigma[1] = fmin.UserParameters().Error( static_cast<unsigned int>(1) );
42  u[2] = fmin.UserParameters().Value( static_cast<unsigned int>(2) );
43  *u2_ptr=u[2];
44  sigma[2] = fmin.UserParameters().Error( static_cast<unsigned int>(2) );
45  u[3] = fmin.UserParameters().Value( static_cast<unsigned int>(3) );
46  *u3_ptr=u[3];
47  sigma[3] = fmin.UserParameters().Error( static_cast<unsigned int>(3) );
48  //std::cout<<"fitresults: "<<u[0]<<" "<<u[1]<<" "<<u[2]<<" "<<u[3]<<std::endl;
49 
50  }
51  }
52 
54 
55  private:
56 
57 };
void set_data(int N, float *charge_ptr, float *adc_ptr)
Definition: SaturationFcn.h:16
SaturationFit(int N, float *charge_ptr, float *adc_ptr, float *u0_ptr, float *u1_ptr, float *u2_ptr, float *u3_ptr)
Definition: SaturationFit.h:13
tuple cout
Definition: gather_cfg.py:41
const double par[8 *NPar][4]