In uproot the example provided in the docs for writing a TH1 histogram to a root
file works very well. Is it possible to do the same thing with TH2 as well? If yes, would it be possible to provide an example, and possibly include in the docs?
EDIT:
I have now made a similar class like in the readme section, but this time with 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
still no success. Any ideas what I am doing wrong?