CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch2/src/OnlineDB/CSCCondDB/interface/SaturationFit.h

Go to the documentation of this file.
00001 #include "Minuit2/VariableMetricMinimizer.h"
00002 #include "Minuit2/FunctionMinimum.h"
00003 #include "Minuit2/MnPrint.h"
00004 
00005 #include <vector>
00006 #include <cmath>
00007 #include "OnlineDB/CSCCondDB/interface/SaturationFcn.h"
00008 
00009 class SaturationFit{ 
00010 
00011  public:
00012 
00013   SaturationFit(int N,float *charge_ptr,float *adc_ptr, float *u0_ptr, float *u1_ptr, float *u2_ptr, float*u3_ptr){
00014    double u[3],sigma[3],chisq;
00015    VariableMetricMinimizer* pMinimizer=new VariableMetricMinimizer() ; 
00016    SaturationFcn* pFcn=new SaturationFcn();
00017    pFcn->set_data(N,charge_ptr,adc_ptr);
00018    std::vector<double> par(4,0);
00019    std::vector<double> err(4,0);
00020    //printf(" about to fill pars \n");
00021    par[0]=pFcn->x0start;
00022    par[1]=pFcn->x1start;
00023    par[2]=pFcn->x2start;
00024    par[3]=pFcn->x3start;
00025    //printf(" pars: %f %f %f %f \n",par[0],par[1],par[2],par[3]);
00026    err[0]=20.0;
00027    err[1]=0.0001;
00028    err[2]=1.0;
00029    err[3]=20.0;
00030    FunctionMinimum fmin = pMinimizer->Minimize(*pFcn, par, err, 1, 5000, 0.01);
00031    if( !fmin.IsValid()){
00032      printf(" minuit did not converge \n");
00033    } else {
00034      std::cout<<"fit succeeded... results: "<<fmin<<std::endl;
00035     chisq = fmin.Fval();
00036     u[0]     = fmin.UserParameters().Value( static_cast<unsigned int>(0) );
00037     *u0_ptr=u[0];
00038     sigma[0] = fmin.UserParameters().Error( static_cast<unsigned int>(0) );
00039     u[1]     = fmin.UserParameters().Value( static_cast<unsigned int>(1) );
00040     *u1_ptr=u[1];
00041     sigma[1] = fmin.UserParameters().Error( static_cast<unsigned int>(1) );
00042     u[2]     = fmin.UserParameters().Value( static_cast<unsigned int>(2) );
00043     *u2_ptr=u[2];
00044     sigma[2] = fmin.UserParameters().Error( static_cast<unsigned int>(2) );
00045     u[3]     = fmin.UserParameters().Value( static_cast<unsigned int>(3) );
00046     *u3_ptr=u[3];
00047     sigma[3] = fmin.UserParameters().Error( static_cast<unsigned int>(3) );
00048     //std::cout<<"fitresults: "<<u[0]<<" "<<u[1]<<" "<<u[2]<<" "<<u[3]<<std::endl;
00049     
00050    }
00051  }
00052 
00053  ~SaturationFit(){}
00054 
00055  private:
00056  
00057 };