Can not treat TH1D as TArrayD in root_numpy.array
alibenn opened this issue · 4 comments
alibenn commented
Using LCG 96 the attached 6 line snippet runs but fails to properly generate the array.
Expected result an array with 1000 entries which are all zero.
Obtained result an empty array.
alibenn commented
import ROOT
import root_numpy
h = ROOT.TH1D("test","test",1000,0,1)
print isinstance(h,ROOT.TArrayD)
a = root_numpy.array(h)
print a
alibenn commented
The output is simply:
True
[]
kratsg commented
@alibenn , not a bug.
>>> import ROOT
>>> h = ROOT.TH1D("test","test",1000,0,1)
>>> h.GetEntries()
0.0
Please read the ROOT documentation. You're just defining a ROOT histogram with 1000 bins from 0 to 1. If you want 1000 entries, then run the following (because also, C++ bindings)
>>> import ROOT
>>> import root_numpy
>>> h = ROOT.TH1D("test","test",1000,0,1)
>>> ignore = [h.Fill(0) for i in range(1000)]
>>> root_numpy.array(ROOT.TArrayD(h))
kratsg commented
Additionally, please start using uproot instead - as this project is not maintained anymore; https://uproot.readthedocs.io/en/latest/