I am currently trying to read in a ROOT tree with uproot, book and fill histograms with boost-histogram and write these back out to a new ROOT file.
This seems to work very well for the bin contents, but I can't seem to get the correct bin errors for the histograms in the final ROOT file. When I read these histograms, h.GetBinError(b)
seems to be equal to h.GetBinContent(b)
, while I would like to have the familiar sumW2 errors which are normally produced for a ROOT histogram.
My workflow is as follows, using python 3.8:
import boost_histogram as bh
import uproot3 as uproot
bins = np.array( [1,2,3,4], dtype='d' )
hist = bh.Histogram( bh.axis.Variable(bins))
I then iterate over the input tree using uproot4.iterate, to produce an awkward array for each 'chunk', denoted here by e
:
hist.fill(e["pt"], weight=(e["weight"]))
with uproot.recreate(outfilename) as outfile:
outfile["hist_pt"] = hist.to_numpy()
I am not sure how to get the sumw2 weights in the construction of the boost-histogram, but based on the documentation I changed my histogram definition to:
hist = bh.Histogram( bh.axis.Variable(bins), storage=bh.storage.Weight() )
However, when I run my code, this causes issues with the .to_numpy()
line. The error says:
"what = uproot3_methods.convert.towriteable(what)
"
"TypeError: cannot perform reduce with flexible type
"
Is there some other way to propagate sumW2-style errors from a boost-histogram to a ROOT file created in uproot? Or perhaps there is an error in my understanding of this storage=
variable....
Any help would be greatly appreciated.
question from:
https://stackoverflow.com/questions/65951054/writing-a-boost-histogram-to-a-root-file-created-in-uproot 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…