Don't display Poisson error bars for empty bins

Hi,

is there a way have SetBinErrorOption(ROOT.TH1.kPoisson) enabled, but avoid displaying error bars for empty bins?

I found this thread on the same question

but kPoisson0 doesn’t seem to be implemented
https://root.cern.ch/doc/v608/classTH1.html#ac6e38c12259ab72c0d574614ee5a61c7

Thanks!
Riccardo

Can you provide a small example reproducing the problem ?

Hi,

here’s a minimal example

import ROOT
import numpy as np

histo = ROOT.TH1F('histo', 'histo', 20, -5, 5)

histo.SetBinErrorOption(ROOT.TH1.kPoisson)

for i in range(10):
    histo.Fill(np.random.normal())

histo.SetMarkerStyle(8)
histo.Draw('E0')

and this is what I get

while, if I don’t use Poisson error bars (by removing histo.SetBinErrorOption(ROOT.TH1.kPoisson)), I obtain the desired behaviour for the empty bins (but I don’t get Poisson bars of course :wink: )

Thanks,
Riccardo

If I do:

{
   auto histo = new TH1F("histo", "histo", 20, -5, 5);

   histo->SetBinErrorOption(TH1::kPoisson);

   histo->FillRandom("gaus", 10);

   histo->SetMarkerStyle(8);
   histo->Draw("E");
}

I get the following picture which seems not too bad…

ah, interesting!
I tried your snippet, verbatim, from within a ROOT session and I still see the bars.

Perhaps my ROOT is not recent enough?
I’m using 6.11/02

I am running the 6.16 … the important part is to use E and not E0 … try in your python script

it’s still the same, even if I use ‘E’ instead of ‘E0’.
And it is still the same, but different from yours, even if I copy your snippet (as in my previous message).

I think i did the wrong post … sorry … I get the bad plot on my Mac too… let me check closer.

Indeed that’s not a graphics issue. When you paint a histogram with any of the E option, if an error is present on a bin then the error bar is drawn for that bin… That sounds logical… The Poisson option add error on bins with 0 content. Errors are there … they are painted.

May be @moneta can give more details why the bins with 0 content have errors with the Poisson option.

Thanks for following up on this!

In general, I think it would be good to have both options and let the user decide whether display error bars for empty bins or not. I’ve received “editorial requests” in both directions, depending on the analysis.

We can decide to not draw the empty bins with option E even if they have errors. The option E0 would allow to draw them if needed. But meanwhile here is a very simple workaround:

{
   auto histo = new TH1F("histo", "histo", 20, -5, 5);

   histo->SetBinErrorOption(TH1::kPoisson);
   histo->GetYaxis()->SetRangeUser(0.00001,6.5);
   histo->FillRandom("gaus", 10);

   histo->SetMarkerStyle(8);
   histo->Draw("E");
}

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