Roofit: Fit RooDataHist with uneven bins

Dear Roofit experts,

I am trying to fit a TH1 defined with uneven binning, with the fitTo() function of RooFit. I attached a minimal example of the code I am using here: test_uneven_binning.C (1.1 KB)

RooAbsPdf *pdf = my_ws.pdf("myPdf");
RooRealVar *obs = my_ws.var("myObs");
TH1D* h_bkg = dynamic_cast<TH1D*>(myHist->Clone("h_bkg")); //myHist is defined with uneven binning  
const Double_t area = h_bkg->Integral();
const Double_t xmin = h_bkg->GetXaxis()->GetXmin();
const Double_t xmax = h_bkg->GetXaxis()->GetXmax(); 
TAxis *xaxis= h_bkg->GetXaxis();
const TArrayD * xarray = xaxis->GetXbins();
const Double_t* bins = xarray->GetArray();
RooBinning edges_bins(xaxis->GetNbins(), bins, "edges_bins");
obs->setRange(xmin, xmax);
obs->setBinning(edges_bins);
RooDataHist dh_bkg("dh_bkg", "dh_bkg", *obs, Import(*h_bkg, kTRUE));
pdf->fitTo(dh_bkg, RooFit::Minos(), RooFit::Save());
my_ws.saveSnapshot("nominal", *pdf->getParameters(dh_bkg));
TH1D *h_nominal = dynamic_cast<TH1D*>(pdf->createHistogram("htmp_nominal", *obs, RooFit::Binning(edges_bins)));
if (h_nominal->Integral()) h_nominal->Scale(area / h_nominal->Integral());

I noticed that the result of the fit is very different from the result if I have with a constant binning, that I obtain with a similar, but different code.
Would it be possible to tell me if there are things I should change in my code, please?

Thank you very much.
Best regards,
Nathan

Hi,
The result should be the same, maybe there is some normalisation factor that needs to be taken into account.
See for example this notebook http://hepcms-hn.umd.edu/~kakw/2020_03_09_RooFit_variablebins.html

and also this post Fitting and plotting variable bins histogram in roofit

Lorenzo

Hi Lorenzo,

Thank you very much for the answer!
Actually I already saw the post that you mention, and I was doing something similar in my code when I use the option:

 Import(*h_bkg, kTRUE)

in the RooDataHist creation.
Indeed, the fit looks good, however, the magnitude of the uncertainties on the fit parameters and the minimized -log(L) values are very different from the ones with constant binning, which indicates that I am doing something wrong.

Nathan

Hi,

Can you then post your code and data so I can run the example and investigate it ?

Cheers
Lorenzo

Hi Lorenzo,

Actually, while I was stetting up the code for you, I think I understood better what was the problem:
I was using Import(*h_bkg, kTRUE) for uneven binning and Import(*h_bkg, kFALSE) for constant binning. So in one case, I was dividing by the bin width and in the other not. So in one case, the errors were scaled down (by ~100), in the same way that the errors are scaled when one use the Scale function of ROOT and in the other, not.
The problem is that, for uneven binning, one should use the kTRUE option, if we want to keep the shape, no?
So my question is: for uneven binning, is it possible to keep the shape unchanged, but without scaling the errors?

Thank you very much,
Nathan

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.