#include <fitUtilities.h>
Public Member Functions | |
double | doGaussFit (MonitorElement *ME) |
double | doGaussFit (TH1F *) |
double | doLanGaussFit (TH1F *) |
double | doLanGaussFit (MonitorElement *ME) |
fitUtilities () | |
double | getFitChi () |
int | getFitnDof () |
double | getGaussPar (std::string s) |
double | getGaussParErr (std::string s) |
double | getLanGaussConv (std::string s) |
double | getLanGaussPar (std::string s) |
double | getLanGaussParErr (std::string s) |
void | init () |
~fitUtilities () | |
Private Attributes | |
double | chi2GausS |
double | epGausS [3] |
double | epLanGausS [4] |
TF1 * | gausFit |
TF1 * | langausFit |
int32_t | nDofGausS |
double | pGausS [3] |
double | pLanConv [2] |
double | pLanGausS [4] |
Definition at line 28 of file fitUtilities.h.
fitUtilities::fitUtilities | ( | ) |
Definition at line 239 of file fitUtilities.h.
References init().
:langausFit(0),gausFit(0){ init(); }
fitUtilities::~fitUtilities | ( | ) |
Definition at line 259 of file fitUtilities.h.
References gausFit, and langausFit.
{ if ( langausFit!=0 ) delete langausFit; if ( gausFit!=0 ) delete gausFit; }
double fitUtilities::doGaussFit | ( | MonitorElement * | ME | ) | [inline] |
Definition at line 39 of file fitUtilities.h.
References doGaussFit(), and MonitorElement::getTH1F().
Referenced by doGaussFit().
{return doGaussFit(ME->getTH1F());}
double fitUtilities::doGaussFit | ( | TH1F * | htoFit | ) |
Definition at line 349 of file fitUtilities.h.
References chi2GausS, epGausS, gausFit, Gauss(), i, init(), langausFit, nDofGausS, and pGausS.
{ init(); if (htoFit->GetEntries()!=0) { // Setting fit range and start values double fr[2]; double sv[3], pllo[3], plhi[3]; fr[0]=htoFit->GetMean()-5*htoFit->GetRMS(); fr[1]=htoFit->GetMean()+5*htoFit->GetRMS(); int32_t imax=htoFit->GetMaximumBin(); double xmax=htoFit->GetBinCenter(imax); double ymax=htoFit->GetBinContent(imax); int32_t i[2]; int32_t iArea[2]; i[0]=htoFit->GetXaxis()->FindBin(fr[0]); i[1]=htoFit->GetXaxis()->FindBin(fr[1]); iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]); iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]); double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],"width"); sv[2]=AreaFWHM/(4*ymax); sv[1]=xmax; sv[0]=htoFit->Integral(i[0],i[1],"width"); plhi[0]=1000000.0; plhi[1]=10.0; plhi[2]=10.; pllo[0]=1.5 ; pllo[1]=0.1; pllo[2]=0.3; Char_t FunName[100]; sprintf(FunName,"FitfcnLG_%s",htoFit->GetName()); gausFit = new TF1(FunName,Gauss,fr[0],fr[1],3); gausFit->SetParameters(sv); gausFit->SetParNames("Constant","GaussPeak","Sigma"); for (int32_t i=0; i<3; i++) { gausFit->SetParLimits(i,pllo[i],plhi[i]); } try{ htoFit->Fit(gausFit,"R0"); gausFit->SetRange(fr[0],fr[1]); gausFit->GetParameters(pGausS); std::memcpy((void*) epGausS, (void*) gausFit->GetParErrors(), 3*sizeof(double)); chi2GausS =langausFit->GetChisquare(); // obtain chi^2 nDofGausS = langausFit->GetNDF();// obtain ndf } catch(...){ edm::LogError("fitUtility") << "problem in fitting " << htoFit->GetTitle() << " \n\tDefault values of the parameters will be used"; pGausS[0]=-9999; pGausS[1]=-9999; pGausS[2]=-9999; epGausS[0]=-9999; epGausS[1]=-9999; epGausS[2]=-9999; chi2GausS=-9999; nDofGausS=-9999; } } else { pGausS[0]=-9999; pGausS[1]=-9999; pGausS[2]=-9999; epGausS[0]=-9999; epGausS[1]=-9999; epGausS[2]=-9999; chi2GausS=-9999; nDofGausS=-9999; } return htoFit->GetEntries(); }
double fitUtilities::doLanGaussFit | ( | MonitorElement * | ME | ) | [inline] |
Definition at line 36 of file fitUtilities.h.
References doLanGaussFit(), and MonitorElement::getTH1F().
Referenced by doLanGaussFit().
{return doLanGaussFit(ME->getTH1F());}
double fitUtilities::doLanGaussFit | ( | TH1F * | htoFit | ) |
Definition at line 267 of file fitUtilities.h.
References chi2GausS, epLanGausS, i, init(), langaufun(), langaupro(), langausFit, nDofGausS, pLanConv, and pLanGausS.
{ init(); if (htoFit->GetEntries()!=0) { edm::LogInfo("fitUtility")<<"Fitting "<< htoFit->GetTitle() <<std::endl; // Setting fit range and start values double fr[2]; double sv[4], pllo[4], plhi[4]; fr[0]=0.5*htoFit->GetMean(); fr[1]=3.0*htoFit->GetMean(); // (EM) parameters setting good for signal only int32_t imax=htoFit->GetMaximumBin(); double xmax=htoFit->GetBinCenter(imax); double ymax=htoFit->GetBinContent(imax); int32_t i[2]; int32_t iArea[2]; i[0]=htoFit->GetXaxis()->FindBin(fr[0]); i[1]=htoFit->GetXaxis()->FindBin(fr[1]); iArea[0]=htoFit->GetXaxis()->FindBin(fr[0]); iArea[1]=htoFit->GetXaxis()->FindBin(fr[1]); double AreaFWHM=htoFit->Integral(iArea[0],iArea[1],"width"); sv[1]=xmax; sv[2]=htoFit->Integral(i[0],i[1],"width"); sv[3]=AreaFWHM/(4*ymax); sv[0]=sv[3]; plhi[0]=25.0; plhi[1]=200.0; plhi[2]=1000000.0; plhi[3]=50.0; pllo[0]=1.5 ; pllo[1]=10.0 ; pllo[2]=1.0 ; pllo[3]= 1.0; Char_t FunName[100]; sprintf(FunName,"FitfcnLG_%s",htoFit->GetName()); langausFit = new TF1(FunName,langaufun,fr[0],fr[1],4); langausFit->SetParameters(sv); langausFit->SetParNames("Width","MP","Area","GSigma"); for (int32_t i=0; i<4; i++) { langausFit->SetParLimits(i,pllo[i],plhi[i]); } try{ htoFit->Fit(langausFit,"R0"); // "R" fit in a range,"0" quiet fit langausFit->SetRange(fr[0],fr[1]); langausFit->GetParameters(pLanGausS); std::memcpy((void*) epLanGausS, (void*) langausFit->GetParErrors(), 4*sizeof(double)); chi2GausS =langausFit->GetChisquare(); // obtain chi^2 nDofGausS = langausFit->GetNDF(); // obtain ndf double sPeak, sFWHM; langaupro(pLanGausS,sPeak,sFWHM); pLanConv[0]=sPeak; pLanConv[1]=sFWHM; edm::LogInfo("fitUtility") << "langaupro: max " << sPeak << std::endl; edm::LogInfo("fitUtility") << "langaupro: FWHM " << sFWHM << std::endl; } catch(...){ edm::LogError("fitUtility") << "problem in fitting " << htoFit->GetTitle() << " \n\tDefault values of the parameters will be used"; pLanGausS[0]=-9999; pLanGausS[1]=-9999; pLanGausS[2]=-9999; pLanGausS[3]=-9999; epLanGausS[0]=-9999; epLanGausS[1]=-9999; epLanGausS[2]=-9999; epLanGausS[3]=-9999; pLanConv[0]=-9999; pLanConv[1]=-9999; chi2GausS=-9999; nDofGausS=-9999; } } else { pLanGausS[0]=-9999; pLanGausS[1]=-9999; pLanGausS[2]=-9999; pLanGausS[3]=-9999; epLanGausS[0]=-9999; epLanGausS[1]=-9999; epLanGausS[2]=-9999; epLanGausS[3]=-9999; pLanConv[0]=-9999; pLanConv[1]=-9999; chi2GausS=-9999; nDofGausS=-9999; } return htoFit->GetEntries(); }
double fitUtilities::getFitChi | ( | ) | [inline] |
int fitUtilities::getFitnDof | ( | ) | [inline] |
double fitUtilities::getGaussPar | ( | std::string | s | ) |
double fitUtilities::getGaussParErr | ( | std::string | s | ) |
double fitUtilities::getLanGaussConv | ( | std::string | s | ) |
double fitUtilities::getLanGaussPar | ( | std::string | s | ) |
double fitUtilities::getLanGaussParErr | ( | std::string | s | ) |
Definition at line 429 of file fitUtilities.h.
References epLanGausS.
{ if(s=="landau_width") return epLanGausS[0]; else if(s=="mpv") return epLanGausS[1]; else if(s=="area") return epLanGausS[2]; else if(s=="gauss_sigma") return epLanGausS[3]; else return -99999; }
void fitUtilities::init | ( | void | ) |
Definition at line 244 of file fitUtilities.h.
References chi2GausS, epGausS, epLanGausS, nDofGausS, pGausS, pLanConv, and pLanGausS.
Referenced by doGaussFit(), doLanGaussFit(), and fitUtilities().
{ pLanGausS[0]=0 ; pLanGausS[1]=0; pLanGausS[2]=0; pLanGausS[3]=0; epLanGausS[0]=0; epLanGausS[1]=0; epLanGausS[2]=0; epLanGausS[3]=0; pGausS[0]=0 ; pGausS[1]=0; pGausS[2]=0; epGausS[0]=0; epGausS[1]=0; epGausS[2]=0; pLanConv[0]=0; pLanConv[1]=0; //if ( langausFit!=0 ) delete langausFit; //if ( gausFit!=0 ) delete gausFit; chi2GausS = -9999.; nDofGausS = -9999; }
double fitUtilities::chi2GausS [private] |
Definition at line 57 of file fitUtilities.h.
Referenced by doGaussFit(), doLanGaussFit(), getFitChi(), and init().
double fitUtilities::epGausS[3] [private] |
Definition at line 55 of file fitUtilities.h.
Referenced by doGaussFit(), getGaussParErr(), and init().
double fitUtilities::epLanGausS[4] [private] |
Definition at line 54 of file fitUtilities.h.
Referenced by doLanGaussFit(), getLanGaussParErr(), and init().
TF1* fitUtilities::gausFit [private] |
Definition at line 60 of file fitUtilities.h.
Referenced by doGaussFit(), and ~fitUtilities().
TF1* fitUtilities::langausFit [private] |
Definition at line 59 of file fitUtilities.h.
Referenced by doGaussFit(), doLanGaussFit(), and ~fitUtilities().
int32_t fitUtilities::nDofGausS [private] |
Definition at line 58 of file fitUtilities.h.
Referenced by doGaussFit(), doLanGaussFit(), getFitnDof(), and init().
double fitUtilities::pGausS[3] [private] |
Definition at line 55 of file fitUtilities.h.
Referenced by doGaussFit(), getGaussPar(), and init().
double fitUtilities::pLanConv[2] [private] |
Definition at line 56 of file fitUtilities.h.
Referenced by doLanGaussFit(), getLanGaussConv(), and init().
double fitUtilities::pLanGausS[4] [private] |
Definition at line 54 of file fitUtilities.h.
Referenced by doLanGaussFit(), getLanGaussPar(), and init().