#ifndef DPlotFitter_h #define DPlotFitter_h #include #include #include #include #include #include #include "TH1D.h" #include "TList.h" #include "TGraphErrors.h" #include "TMatrixDSym.h" #include "TObject.h" #include "TFitResult.h" #include "TProofServ.h" #include "DFitControl.h" #include "DFitUtilities.h" using namespace std; TProofServ* gProofServ; //must define: else get "undefined symbol" error when loading library class DPlotFitter : public TObject { public: DPlotFitter(bool locQuietFitFlag = true) : dQuietFitFlag(locQuietFitFlag){} //Perform Fit int Fit_Hist(TH1* locHist, DFitControl* locFitControl) const; int Fit_Graph(TGraph* locGraph, DFitControl* locFitControl) const; bool dQuietFitFlag; private: template int Fit_Object(DType* locFitObject, DFitControl* locFitControl, string locFitArgument) const; ClassDef(DPlotFitter, 1) }; int DPlotFitter::Fit_Hist(TH1* locHist, DFitControl* locFitControl) const { //set fit argument string locFitArgument = "BRN+S"; if(dQuietFitFlag) locFitArgument += "Q"; if(locFitControl->dLogLikelihoodFlag) locFitArgument += "L"; if(!DFitUtilities::Check_ValidFitRange(locHist, locFitControl->dFitRangeMin, locFitControl->dFitRangeMax)) { locFitControl->Create_TotalFunction(locHist->GetName()); locFitControl->Create_FinalFunctions(locHist->GetName()); locFitControl->Add_FitFunctions(locHist); locFitControl->dFitStatus = -1; return -1; } return Fit_Object(locHist, locFitControl, locFitArgument); } int DPlotFitter::Fit_Graph(TGraph* locGraph, DFitControl* locFitControl) const { //set fit argument string locFitArgument = "B0RN+SEX"; if(dQuietFitFlag) locFitArgument += "Q"; if(locFitControl->dLogLikelihoodFlag) locFitArgument += "L"; return Fit_Object(locGraph, locFitControl, locFitArgument); } template int DPlotFitter::Fit_Object(DType* locFitObject, DFitControl* locFitControl, string locFitArgument) const { TF1* locFunc = locFitControl->Create_TotalFunction(locFitObject->GetName()); //FIT //http://root.cern.ch/root/html534/ROOT__Fit__FitResult.html TFitResultPtr locFitResultPtr = locFitObject->Fit(locFunc, locFitArgument.c_str()); //ERROR CODES: http://wiki.hugonweb.com/doku.php?id=minuit locFitControl->dFitStatus = locFitResultPtr->Status(); //create & add other functions locFitControl->Create_FinalFunctions(locFitObject->GetName()); locFitControl->Add_FitFunctions(locFitObject); //set covariance matrices //CovMatrixStatus(): =0 not calculated, =1 approximated, =2 made pos def , =3 accurate if(locFitResultPtr->CovMatrixStatus() != 0) locFitControl->Set_CovarianceMatrices(locFitResultPtr->GetCovarianceMatrix()); return locFitControl->dFitStatus; } #endif