1

我目前正在尝试用 uproot 读取 ROOT 树,用 boost-histogram 记录和填充直方图,并将它们写回一个新的 ROOT 文件。这似乎对 bin 内容非常有效,但我似乎无法为最终 ROOT 文件中的直方图获得正确的 bin 错误。当我阅读这些直方图时,h.GetBinError(b)似乎等于h.GetBinContent(b),而我想知道通常为 ROOT 直方图产生的熟悉的 sumW2 错误。我的工作流程如下,使用 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))

然后我使用 uproot4.iterate 遍历输入树,为每个“块”生成一个尴尬的数组,在此表示为e

hist.fill(e["pt"], weight=(e["weight"]))
with uproot.recreate(outfilename) as outfile:
   outfile["hist_pt"] = hist.to_numpy()

我不确定如何在构建提升直方图时获得 sumw2 权重,但根据文档,我将直方图定义更改为:

hist = bh.Histogram( bh.axis.Variable(bins), storage=bh.storage.Weight() )

但是,当我运行我的代码时,这会导致该.to_numpy()行出现问题。错误说:“ what = uproot3_methods.convert.towriteable(what)”“ TypeError: cannot perform reduce with flexible type

是否有其他方法可以将 sumW2 样式的错误从 boost-histogram 传播到在 uproot 中创建的 ROOT 文件?或者我对这个变量的理解可能存在错误storage=......任何帮助将不胜感激。

4

0 回答 0