#include "Math/IFunction.h" #include "TBackCompFitter.h" #include "TH2.h" #include "TF2.h" // example of doing a chi2 scan in 2 parametrs struct Chi2Func2D { Chi2Func2D(ROOT::Math::IMultiGenFunction * f, const double * fitParameterValues) : fFunc(f), fParams(fitParameterValues, fitParameterValues+f->NDim()) {} double operator() ( const double * x, const double *) { // mu is parametr =1 and sigma is parameter =2 fParams[1] = x[0]; fParams[2] = x[1]; return (*fFunc)( &fParams[0]); } ROOT::Math::IMultiGenFunction * fFunc; std::vector fParams; }; void Scan2D() { TH1D * h1 = new TH1D("h1","h1",100,-5,5); h1->FillRandom("gaus"); h1->Fit("gaus"); TBackCompFitter * fitter = (TBackCompFitter*) TVirtualFitter::GetFitter(); // get the chi2 function as f( params) ROOT::Math::IMultiGenFunction * chi2func = fitter->GetObjFunction(); // now we want to make a function of only two parameters (e.g mu and sigma) Chi2Func2D chi2D(chi2func, fitter->GetFitResult().GetParams() ); // make a function in the range mu [-0.3, 0.3] and sigma[0.8,1.2]. TF2 * f2 = new TF2("chi2",&chi2D, -0.3, 0.3, 0.8, 1.2, 0, "Chi2Func2D"); TH2 * h2 = (TH2*) f2->GetHistogram(); //h2->Draw("LEGO"); h2->Draw("COLZ"); }