Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Add support for the Univeral Histogram Interface (UHI) #17111

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

LukasBreitwieser
Copy link
Contributor

Current Status

Working implementation for TH1 including basic tests

Access

v = h[2]
v = h[ROOT.underflow]        # return the bin contents of underflow
v = h[ROOT.overflow]4        # return the bin contents of overflow
v = h[ROOT.loc(1.4)]         # return the bin content of the bin that stores the value 1.4 (data coordinates) 
v = h[ROOT.loc(1.4) + 1]     # return the bin content of the next bin that stores the value 1.4 (data coordinates) 
v = h[ROOT.loc(1.4) - 1]     # return the bin content of the previous bin that stores the value 1.4 (data coordinates) 

Setting

h[2]
h[ROOT.underflow] = 3         # set the content of the underflow bin
h[ROOT.overflow] = 4          # set the content of the overflow bin
h[ROOT.loc(1.4)] = 5.0        # set the bin contents in data coordinates 
h[ROOT.loc(1.4) + 1] = 7.0
h[ROOT.loc(1.4) - 1] = 9.0

Slicing, rebinning, reduction

h == h[:]             # Slice over everything
h2 = h[::rebin(2)]    # Modification operations (rebin)
v2 = h[::sum]         # Projection operations # (name may change)

Unsupported by UHI, and therefore raising exceptions:

h[1.0]                # Indexing with a float is disallowed
v2 = h[::sum]         # Projection operations # (name may change)

Currently not supported due to missing slicing funcionality on the cpp side

h2 = h[a:b]           # Slice of histogram (includes flow bins)
h2 = h[:b]            # Leaving out endpoints is okay

This applies also to derivatives, like:

If slicing is implemented, the following list will work too.

h2 = h[loc(v):]       # Slices can be in data coordinates, too
h2 = h[a:b:rebin(2)]  # Modifications can combine with slices
v2 = h[a:b:sum]       # Adding endpoints to projection operations
v2 = h[0:len:sum]     #   removes under or overflow from the calculation
h2 = h[v, a:b]        #   A single value v is like v:v+1:sum
h2 = h[a:b, ...]      # Ellipsis work just like normal numpy

TODO

  • Generalize to multiple dimensions
  • Implement dictionary of slices on specific axes
h[{0: slice(None, None, bh.rebin(2))}] # rebin axis 0 by two
  • Implement Ellipsis
h[...] = array(...)
  • Implement
h[:] = np.ones(10)
  • Dig deeper to clarify some questions about the API. Open questions like: When is a copy returned, when are the modifications done in-place? ...
  • Add more error checks
  • Improve testing coverage

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant