Binned fit using ROOT::Fit::PoissonLLFunction

Hello,

I am trying to use ROOT::Fit::PoissonLLFunction to fit some low statistics histograms. Using directly TH1::Fit is not an options since I need to do a combined (simultaneous) fit of many of such histograms. However, I must be attempting to use ROOT::Fit::PoissonLLFunction not correctly, since I get too large errors (by a factor of ~1.5); while if I use TH1::Fit (on a single histogram), the results look reasonable.

Here is a simplified example of how I use ROOT::Fit::PoissonLLFunction (a full macro is attached as well):

 // h1 is a histogram with 100 events with Gaus(2,20) distribution
 // f1 is a Gaus function
 // xMin = -100.0, xMax = +100.0
 ROOT::Fit::Fitter fitter;
 const int nPar = f1->GetNpar();
 fitter.Config().SetParamsSettings(nPar, f1->GetParameters());
 fitter.Config().ParSettings(0).SetLimits(0.0, 20.0*nEvents);
 fitter.Config().ParSettings(1).SetLimits(xMin, xMax);
 fitter.Config().ParSettings(2).SetLimits(xMin, xMax);
 fitter.Config().MinimizerOptions().SetPrintLevel(2);
 fitter.Config().SetMinimizer("Minuit2", "Migrad");

 TF1 * fitFun = new TF1("fitFun", Gaus, xMin, xMax, nFitFunPar);
 ROOT::Math::WrappedMultiTF1 * wf = new ROOT::Math::WrappedMultiTF1(*fitFun, 1);
 ROOT::Fit::DataOptions opt;
 opt.fUseEmpty = true;
 ROOT::Fit::DataRange range;
 range.SetRange(xMin, xMax);
 ROOT::Fit::BinData * data = new ROOT::Fit::BinData(opt, range);
 ROOT::Fit::FillData(*data, h1);

 const bool chi2Fit = false;
 ROOT::Math::FitMethodFunction * localFitFun = new ROOT::Fit::PoissonLLFunction(*data, *wf);
 // also tried to set explicitly weight=0/1 and extended=true/false

 fitter.FitFCN(fitter.Config().NPar(), *localFitFun, 0, data->Size(), chi2Fit);
 const ROOT::Fit::FitResult result = fitter.Result();
 result.Print(cout);

I would really appreciate if somebody could help me to understand how to use PoissonLLFunction correctly.

Thank you,
Siarhei.

TestPLLFit.C (4.06 KB)

Hi,

Since this is a likelihood fit, you should define the correct level for the error (it is 0.5 instead of 1 as in a least square fit).

fitter.Config().MinimizerOptions().SetErrorDef(0.5); 

Best Regards

Lorenzo

Dear Lorenzo (or anybody who knows the answer),

Could you please help me to figure out what I should do to be able to use ROOT::Fit::PoissonLLFunction on weighted histograms (i.e. to make the fit to be equivalent to the fit option “WL” of a direct fit with a TF1)?

Thank you very much for your help!!!
Siarhei.

Hi,

You need to create the ROOT::Fit::PoissonLLFunction class passing in the constructor the option that is a weighted fit,

ROOT::Math::FitMethodFunction * localFitFun = new ROOT::Fit::PoissonLLFunction(*data, *wf, true);

Then after having minimiser the function you need to apply a correction for the error using the square of the weights when building the likelihood.

// minimise first the likelihood
fitter.FitFCN(fitter.Config().NPar(), *localFitFun, 0, data->Size(), chi2Fit);
// apply the correction
localFitFun->UseSumOfWeightSquare();
fitter.ApplyWeightCorrection(*localFitFun);

This should work. You can look also at the relevant code in the implementation of the Fitter class

Best Regards

Lorenzo

Dear Lorenzo,

Could you please let me know if the code of ROOT::Fit::PoissonLLFunction multithread safe?

Thank you very much for your help!!!
Siarhei.