Wrong errors in RooDataHist

Hi all

I am seeing a weird behavoir in RooDataHist and I want to make sure I am not doing something wrong. I am using RooFit to take a TH1 histogram, fit it and then do some stat studies. Because I am getting unexpected results, I started looking into the smallest details of my code.
In short, I have a TH1 histogram with data, where the errors should be just sqrt(N), load it into a RooDataHist, defining a Pdf, and then do fitTo that RooDataHist.
The problem is that if I check at the errors of that RooDataHist, they are not the same as the TH1 (nor sqrt(N)). This is how I am checking this:

>>> file = ROOT.TFile("Rootfiles/jetObservables_histograms_JetHT2017ALL.root")
>>> histo = file.Get("jetObservables/recoJet2_mass_nom_AK8PFJet450_dijetSel")
>>> msd = ROOT.RooRealVar('msd', 'msd', 125., 0, 400)
>>> data = ROOT.RooDataHist( 'data', 'data', ROOT.RooArgList(msd), histo)
[#1] INFO:DataHandling -- RooDataHist::adjustBinning(data): fit range of variable msd expanded to nearest bin boundaries: [0,200] --> [0,200]
>>> data.get(10)
<ROOT.RooArgSet object at 0x474a088>
>>> data.weight()
23884.0
>>> data.weightError()
154.54530080206314
>>> histo.GetBinContent(11)
23884.0
>>> histo.GetBinError(11)
154.544491975612

or more noticeable:

>>> data.get(34)
<ROOT.RooArgSet object at 0x47ba198>
>>> data.weight()
12.0
>>> data.weightError()
3.987542525845706
>>> histo.GetBinContent(35)
12.0
>>> histo.GetBinError(35)
3.4641016151377544

Am I doing this correct?
Please let me know if you have any further questions

cheers,

I guess @moneta has an explanation for this

Hi @alefisico,

indeed, the errors in RooDataHist are defined different than in TH1, but it doesn’t mean that it’s wrong :slight_smile:

RooDataHist::weightError (link to documentation) gives you the mean of the asymmetric Poisson errors by default, while TH1 gives you sqrt(n). This makes a difference in particular for low counts, as you already noticed.

If you want to really use the square root of the sum of weights as the error, you can still do so with the ErrorType parameter (example in C++):

data.weightError(RooDataHist::SumW2)

But keep in mid that RooDataHist uses the asymmetric Poisson errors by default for good reasons (see for example this blogpost on histogram uncertainties).

Hi @jonas

thanks for the reply. I didn’t know that RooDataHist was using asymmetric Poisson errors by default. (Thanks also for the link!)
I think it is more clear now.

cheers,

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