This repository was archived by the owner on Sep 15, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 8
This repository was archived by the owner on Sep 15, 2025. It is now read-only.
Conversion from_root fails for non-uniform binning #23
Copy link
Copy link
Closed
Description
I am having issues converting a TH1D into an aghast histogram.
Since I am working with rootpy histograms, the blow example uses 2D histograms and ProjectionX() to return the TH1D. The example includes the patch in #22 (otherwise it will stop there)
Code example
import aghast
import awkward
from rootpy.plotting import Hist2D
import numpy as np
import ROOT
def test_fill():
pileup_bins = [0, 10, 15, 20, 30, 999]
jet_pt_bins = [35, 90, 120]
hist = Hist2D(pileup_bins, jet_pt_bins, name='test')
ets = awkward.fromiter([
np.random.poisson(30, 5),
np.random.poisson(30, 2),
np.random.poisson(30, 3),
])
repeat = ets.stops - ets.starts
weights = np.ones(len(ets))
weights = np.repeat(weights, repeat, axis=0)
pileup = np.random.poisson(50, len(ets))
pileup = np.repeat(pileup, repeat, axis=0)
hist.fill_array(np.vstack((pileup, ets.content)).T, weights)
proX = hist.ProjectionX()
print(type(proX)) # <class 'ROOT.TH1D'>
assert isinstance(proX, (ROOT.TH1D, ROOT.TH2D, ROOT.TH3D))
aghast.from_root(proX) # <-- fails with AssertionError: <class 'ROOT.TArrayD'>Full trace
/software/miniconda/envs/hep_py3/lib/python3.6/site-packages/aghast/__init__.py:31: in from_root
return aghast._connect._root.from_root(obj, collection=collection)
/software/miniconda/envs/hep_py3/lib/python3.6/site-packages/aghast/_connect/_root.py:286: in from_root
sumw2array = getbincontents(sumw2obj)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
obj = <ROOT.TArrayD object at 0x55e5e196d5d0>
def getbincontents(obj):
if isinstance(obj, (ROOT.TH1C, ROOT.TH2C, ROOT.TH3C)):
out = numpy.empty(obj.GetNcells(), dtype=numpy.int8)
arraytype = "char"
elif isinstance(obj, (ROOT.TH1S, ROOT.TH2S, ROOT.TH3S)):
out = numpy.empty(obj.GetNcells(), dtype=numpy.int16)
arraytype = "short"
elif isinstance(obj, (ROOT.TH1I, ROOT.TH2I, ROOT.TH3I)):
out = numpy.empty(obj.GetNcells(), dtype=numpy.int32)
arraytype = "int"
elif isinstance(obj, (ROOT.TH1F, ROOT.TH2F, ROOT.TH3F)):
out = numpy.empty(obj.GetNcells(), dtype=numpy.float32)
arraytype = "float"
elif isinstance(obj, (ROOT.TH1D, ROOT.TH2D, ROOT.TH3D)):
out = numpy.empty(obj.GetNcells(), dtype=numpy.float64)
arraytype = "double"
else:
> raise AssertionError(type(obj))
E
Metadata
Metadata
Assignees
Labels
No labels