Skip to content
This repository has been archived by the owner on Jan 27, 2023. It is now read-only.

Status bits for a TH1? #99

Closed
gipert opened this issue Jun 3, 2021 · 5 comments
Closed

Status bits for a TH1? #99

gipert opened this issue Jun 3, 2021 · 5 comments

Comments

@gipert
Copy link

gipert commented Jun 3, 2021

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
Copy link
Member

jpivarski commented Jun 3, 2021

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
Copy link
Author

gipert commented Jun 3, 2021

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
Copy link
Member

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

@jpivarski
Copy link
Member

jpivarski commented Jun 3, 2021

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
Copy link
Author

gipert commented Jun 3, 2021

Great, thanks a lot for looking into this!

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

No branches or pull requests

2 participants