Writing a boost-histogram to a root file created in uproot (with proper sum-of-weights errors) #787
Unanswered
special-kay-0
asked this question in
Q&A
Replies: 2 comments
-
Hi @special-kay-0, the key issue here is calling
|
Beta Was this translation helpful? Give feedback.
0 replies
-
Why are you using uproot 3? Uproot 4 will natively take a boost-histogram or Hist object (as in the other answer). |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I am copying a question I posted on stackoverflow a while ago, since this seems like a better place to ask: https://stackoverflow.com/questions/65951054/writing-a-boost-histogram-to-a-root-file-created-in-uproot
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 toh.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:I then iterate over the input tree using uproot4.iterate, to produce an awkward array for each 'chunk', denoted here by e:
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.
Perhaps my question is now outdated... is there some better way to efficiently convert data from an awkward array in uproot, which can then be saved as a histogram to a root file?
Beta Was this translation helpful? Give feedback.
All reactions