1

根除文档中提供的用于将 TH1 直方图写入文件的示例root效果很好。TH2也可以做同样的事情吗?如果是,是否可以提供一个示例,并可能包含在文档中?

编辑:

我现在已经做了一个类似自述部分的课程,但这次是 TH2:

import types
import uproot
import uproot_methods.classes.TH2
import numpy as np

class MyTH2(uproot_methods.classes.TH2.Methods, list):
    def __init__(self, xlow, xhigh, xnbins, ylow, yhigh, ynbins, values, title=""):
        self._fXaxis = types.SimpleNamespace()
        self._fXaxis._fNbins = xnbins
        self._fXaxis._fXmin = xlow
        self._fXaxis._fXmax = xhigh
        self._fYaxis = types.SimpleNamespace()
        self._fYaxis._fNbins = ynbins
        self._fYaxis._fXmin = ylow
        self._fYaxis._fXmax = yhigh
        for x in values:
            self.append(float(x))
        self._fTitle = title
        self._classname = "TH2F"

th2 = MyTH2(-5, 5, 6, -8, 8, 4, np.random.rand(24), title='')
file = uproot.recreate("tmp_th2.root", compression=uproot.ZLIB(4))
file["th2"] = th2

仍然没有成功。任何想法我做错了什么?

4

0 回答 0