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()
>>> data.weightError()
>>> histo.GetBinContent(11)
>>> histo.GetBinError(11)

or more noticeable:

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

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


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++):


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.


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