-
Notifications
You must be signed in to change notification settings - Fork 25
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
First commit of hist2root.py #292
base: main
Are you sure you want to change the base?
Conversation
for more information, see https://pre-commit.ci
@slehti Hi, thanks for this pr. Could you add some python type annotations to pass GitHub Ci? And it would be good if you can give tests or a notebook for this feature. |
I can help with type annotations and setting up ROOT in the tests. I'll review soon. |
import math | ||
|
||
import ROOT | ||
from coffea import processor |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would hope hist would be a dependency of coffea, not depending on coffea. This should be done a different way - either optionally importing it, or better yet, if it could be done via a Protocol (check for methods and call if they exist, basically). I'll go through and do a bit of CI / type annotations, then we can revisit this part.
Did you test this implementation by hand? Static typing revealed
|
Also, please always make a new branch for making a PR. It's a bit more irritating to have to write |
name = hist.label | ||
if len(name) > 0: | ||
name = hname |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is confusing. If this has an empty hist.label
, then it uses that. If it's not empty, then it uses the passed name instead, even if that is empty. I really don't think that's what you intended. Instead of this structure, which is easy to get wrong, try this:
name = hist.label | |
if len(name) > 0: | |
name = hname | |
name = hname or hist.label |
That will set hname
if not empty, otherwise it will try to use hist.label
. Or maybe you meant the reverse, and hname
was a fallback - in that case, name = hist.label or hname
.
A general point: we should split up PyROOT and coffea conversion. Most users will be converting PyROOT and won't care about coffea. I'll also have to look at coffea a bit more to see how that's set up. So I'd focus on PyROOT for now. I'd then call the file pyroot.py, so We should soon be able to save boost-histogram and Hist to files without using PyROOT at all, but using uproot4 instead. That's part of the reason for adding "py" to the name here. Thanks for the PR! Please address what you can (especially things where I'm not sure the original intent), and ideally try to make sure it runs locally on something (pick some random use case). Then I'll help with whatever you can't do (just will be a little slower getting done, most likely). |
Convert 1-dimensional or 2-dimensional hist object into ROOT:TH1D or ROOT.TH2D object, convert counter into a ROOT.TH1D object.