Skip to content
This repository has been archived by the owner on Mar 31, 2019. It is now read-only.

Commit

Permalink
Merge pull request #51 from clelange/TH2_export
Browse files Browse the repository at this point in the history
add support for exporting to TH2
  • Loading branch information
jpivarski authored Oct 26, 2018
2 parents abe1dc0 + b34b542 commit f0cc5bf
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion histbook/export.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,8 +288,23 @@ def root(self, *axis, **opts):
out.SetBinError(i, rooterrors[i])

elif len(binaxis) == 2:
xaxis = binaxis[0]
yaxis = binaxis[1]

if profile is None:
raise NotImplementedError("TH2")
out = ROOT.TH2D(name, title, xaxis.numbins, xaxis.low, xaxis.high, yaxis.numbins, yaxis.low, yaxis.high)

entries = numpy.zeros((xaxis.numbins + 2, yaxis.numbins + 2), dtype=numpy.float64)
entries[(0 if xaxis.underflow else 1) : (None if xaxis.overflow else -1), (0 if yaxis.underflow else 1) : (None if yaxis.overflow else -1)] = content["count()"][: (-1 if xaxis.nanflow else None), : (-1 if yaxis.nanflow else None)]
for idx, val in numpy.ndenumerate(entries):
out.SetBinContent(idx[0], idx[1], val)
out.SetEntries(entries.sum())

if "err(count())" in content.dtype.names:
errors = numpy.zeros(xaxis.numbins + 2, yaxis.numbins + 2, dtype=numpy.float64)
errors[(0 if xaxis.underflow else 1) : (None if xaxis.overflow else -1), (0 if yaxis.underflow else 1) : (None if yaxis.overflow else -1)] = content["err(count())"][: (-1 if xaxis.nanflow else None), : (-1 if yaxis.nanflow else None)]
for idx, val in numpy.ndenumerate(errors):
out.SetBinError(idx[0], idx[1], val)

else:
raise NotImplementedError("TProfile2D")
Expand Down

0 comments on commit f0cc5bf

Please sign in to comment.