uproot5: Drawing of histograms created in uproot fails in ROOT
When saving a histogram in a ROOT file using Uproot, if the content of the last bin in the histogram is negative, ROOT will fail to plot it. The error message is
TCanvas::ResizePad:0: RuntimeWarning: Inf/NaN propagated to the pad. Check drawn objects.
TCanvas::ResizePad:0: RuntimeWarning: Canvas_1 height changed from 0 to 10
If the last bin’s content is non-negative, plotting works.
To reproduce, create the histogram
import numpy as np
import uproot
with uproot.recreate("test.root") as f:
f["hist_fail"] = (np.asarray([-3, -2, -1]), np.asarray([0, 1, 2, 3]))
f["hist_pass"] = (np.asarray([-3, -2, +1]), np.asarray([0, 1, 2, 3]))
Opening test.root
using rootbrowser
(or just root
, getting the histograms, and plotting them using Draw()
) results in the hist_pass
being drawn, while hist_fail
won’t be.
Furthermore, even the hist_pass
isn’t drawn properly - the y-axis starts at 0. When creating the same histogram in ROOT, the range includes all the events.
I think the issue is caused by the errors of the histogram bins - ROOT initializes them as sqrt(abs(content))
while uproot uses sqrt(content)
, leading to nan
s for negative numbers. Not sure what is special about the last bin, though.
Uproot 4.3.4 ROOT 6.26/04
About this issue
- Original URL
- State: closed
- Created 2 years ago
- Comments: 17 (10 by maintainers)
@jpivarski can we even write in the sumw2 information from
uproot
? because that’s needed, and right now it’s wrong