uproot question: The full TTree structure I can see in a TBrowser is not appearing in uproot

463 Views Asked by At

Summary: TTree branches seem to go missing when running the uproot tutorial.

I have a root file that contains a TTree called 'prod' which has a complicated set of jagged leaves and branches which I can see in the TBrowser in ROOT. I started the uproot tutorial using this root file as the input and receive the following error at the beginning of an interactive session:

>>>import uproot as up
>>> file = up.open('small.root')
>>> file
<ROOTDirectory b'small.root' at 0x025b5e3477c0>
>>> file.keys()
[b'prod;1']
>>> file.classnames()
Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    file.classnames()
AttributeError: 'ROOTDirectory' object has no attribute 'classnames'
>>> file['prod']
<TTree b'prod' at 0x025b5dd15d00>

Why am I getting an error when trying to get the class names?

Ignoring this and moving on. The next problem is when I try to see what is in the TTree prod

>>> tree = file['prod']
>>> tree.keys()
[b'COSMIC', b'COSMICRES', b'COTNBC', b'COTTIME', b'GLB', b'LUM', b'MET', b'MU', b'PHOTON', b'RESIDUALS', b'TRACK', b'TRKDET', b'VERTEX', b'ZVTX', b'MOM_ntk', b'MOM_pt', b'MOM_px', b'MOM_py', b'MOM_pz']
>>> branches = tree.arrays(namedecode='utf-8')
>>> branches.keys()
dict_keys(['MET', 'MOM_ntk', 'MOM_pt', 'MOM_px', 'MOM_py', 'MOM_pz'])

The uproot tutorial implies that I should get all the branches, but clearly I am missing quite a few of them. In particular, the only branches that were transferred over were the ones that were what I would call 'simple' in the sense that they only had numerical data members.

The other branches contain further items within them. For example, the 'MU' branch has properties of every muon in the event. First the number of such muons and then a further branch of each one of those muon's attributes like it's quality and the track-number associated with it. 'MET', 'MOM_ntk', 'MOM_pt', 'MOM_px', 'MOM_py', and 'MOM_pz' all contain only lists of floating point numbers. MOM_ntk has only one number per event (call it 'alpha'), and the other MOM branches will have 'alpha' numbers in each of them.

The file only has 1000 events and is only about 5MB in total size.

I am wondering where all the other Branches have gone! Where are my friends 'COTNBC' or 'GLB' (that one should have all the run and event numbers in it).

Any advice or help would be appreciated!


Windows 10 PC with 32GB RAM Intel(R) Core(TM) i7-8700 CPU @ 3.20GHz x64 processor

1

There are 1 best solutions below

7
On

Based on what you're trying to do and the outputs you're getting, it looks like you're expecting Uproot 4, but you have Uproot 3. Until Uproot 4 has feature-parity with Uproot 3, it will be in a package named uproot4 (pip install uproot4 and import uproot4). That lets you use both during this transition.

One of those differences is that Uproot 3's keys() methods did not recurse through subbranches of branches, but Uproot 4's does. (There's a recurse=True/False parameter in both, but the default changed for exactly the reason you're seeing.)

The name change (uproot4uproot and uprootuproot3) will happen before the end of the year. Uproot 4 only needs file-writing before that can happen.