scikit-hep / uproot3-methods

Pythonic behaviors for non-I/O related ROOT classes.
BSD 3-Clause "New" or "Revised" License
21 stars 28 forks source link

Status bits for a TH1? #99

Closed gipert closed 3 years ago

gipert commented 3 years ago

Hi! I was wondering if there is there any way to get status bits for a TH1? I'm particularly interested in the value of kIsAverage. Thanks!

jpivarski commented 3 years ago

In Uproot 3, check all of the attributes that start with _f in dir(histogram).

In Uproot 4 (which wouldn't be using uproot3-methods), look in histogram.all_members (a dict).

There are no convenience methods for accessing these bits (because no one has asked before). uproot3-methods and Uproot 4 behaviors provide convenience methods for the data that are in the _f attributes or all_members.

kIsAverage might be in something named "flags".

gipert commented 3 years ago

Uhm I cannot find anything meaningful:

>>> h._
h._arraymethods     h._fContour         h._fMinimum         h._fXaxis           h._methods
h._bases            h._fEntries         h._fName            h._fYaxis           h._postprocess(
h._classname        h._fFillColor       h._fNcells          h._fZaxis           h._pycode
h._classversion     h._fFillStyle       h._fNormFactor      h._fields           h._readinto(
h._copycontext      h._fFunctions       h._fOption          h._format           h._recarray(
h._dtype            h._fLineColor       h._fStatOverflows   h._format1          h._recarray_dtype(
h._dtype1           h._fLineStyle       h._fSumw2           h._format2          h._trymemo(
h._fBarOffset       h._fLineWidth       h._fTitle           h._format3          h._versions
h._fBarWidth        h._fMarkerColor     h._fTsumw           h._format4          
h._fBinStatErrOpt   h._fMarkerSize      h._fTsumw2          h._hasreadobjany    
h._fBuffer          h._fMarkerStyle     h._fTsumwx          h._int32            
h._fBufferSize      h._fMaximum         h._fTsumwx2         h._members(

I'm not sure I completely understand how these bits are managed in ROOT, are them a more general TObject property?

jpivarski commented 3 years ago

Is it a bit of _fOption or is it in the axis (_fXaxis)?

jpivarski commented 3 years ago

Reading this:

https://root.cern.ch/doc/master/classTH1.html#operations-on-histograms

it appears that the kIsAverage is assigned with SetBit, which is a TObject method (not a histogram-specific thing, as I had supposed). That's the fBits member of TObject, and I just checked, Uproot 3 doesn't save these anywhere (never knew that they were used for anything):

https://github.com/scikit-hep/uproot3/blob/54f5151fb7c686c3a161fbe44b9f299e482f346b/uproot3/rootio.py#L458-L467

In Uproot 4, the fBits would be in the all_members dict with key name "@fBits" (the @ is used to skip it when presenting it in pretty-prints).

>>> import uproot   # Uproot 4
>>> f = uproot.open("histograms.root")
>>> f.classnames()
{'one;1': 'TH1F', 'two;1': 'TH1F', 'three;1': 'TH1F'}
>>> f["one"]
<TH1F (version 2) at 0x7fd7d1e632e0>
>>> f["one"].all_members["@fBits"]
50331656
>>> f["one"].member("@fBits")
50331656
>>> f["one"].member("@fBits") & (2**18)   # my histogram is not an average, apparently
0

where kIsAverage is defined as BIT(18):

https://github.com/root-project/root/blob/6832151a556172150d53ba13c89e5ae77a80483a/hist/hist/inc/TH1.h#L170

So it would be possible to get this information in Uproot 4, but it is impossible to get it in Uproot 3. (Uproot 4's approach is more inclusive, less hacky, so I didn't just drop data I didn't know what to do with.)

gipert commented 3 years ago

Great, thanks a lot for looking into this!