CMS 3D CMS Logo

SaturationFcn.h
Go to the documentation of this file.
1 #ifndef SaturationFcn_h
2 #define SaturationFcn_h
3 
4 #include "Minuit2/FCNBase.h"
5 #include <cmath>
6 #include <vector>
7 
8 
9 using namespace ROOT::Minuit2;
10 
11 class SaturationFcn : public FCNBase{
12 
13  public:
14 
16 
18 
19 
20  void set_data(int N,float *charge_ptr,float *adc_ptr){
21 
22  float x[20],y[20];
23 
24  for(int i=0;i<N;i++){
25  x[i]=charge_ptr[i];
26  y[i]=adc_ptr[i];
27  datx[i]=x[i];
28  daty[i]=y[i];
29  //printf("%d datx daty %f %f \n",i,datx[i],daty[i]);
30  }
31 
32  x3start=(y[4]*x[1]-y[1]*x[4])/(x[1]-x[4]);
33  x0start=daty[13]-x3start;
34  x1start=(y[4]-y[1])/(x[4]-x[1])/x0start;
35  x2start=20.;
36  //printf(" x0-2start %f %f %f %f\n",x0start,x1start,x2start,x3start);
37  }
38 
39  virtual double Up() const {return 1.;}
40 
41  virtual double operator()(const std::vector<double>& x) const {
42  double chisq = 0.0;
43  int N=20;
44  for(int i=0;i<N;i++){
45  double val=1.0+pow(x[1]*datx[i],x[2]);
46  double val2=1.0/x[2];
47  val=x[0]*x[1]*datx[i]/pow(val,val2);
48  double tmp=(daty[i]-x[3]-val);
49  //printf(" dat: %d %f %f %f %f \n",i,datx[i],daty[i]-x[3],val,tmp);
50  chisq=chisq+tmp*tmp;
51  }
52  //printf("x0-3 %f %f %f %f chisq %f \n",x[0],x[1],x[2],x[3],chisq);
53  return chisq;
54  }
55 
56  double x0start;
57  double x1start;
58  double x2start;
59  double x3start;
60 
61  private:
62  double datx[20],daty[20];
63 };
64 
65 #endif
virtual double Up() const
Definition: SaturationFcn.h:39
void set_data(int N, float *charge_ptr, float *adc_ptr)
Definition: SaturationFcn.h:20
virtual double operator()(const std::vector< double > &x) const
Definition: SaturationFcn.h:41
#define N
Definition: blowfish.cc:9
std::vector< std::vector< double > > tmp
Definition: MVATrainer.cc:100
Power< A, B >::type pow(const A &a, const B &b)
Definition: Power.h:40