Using python to access a branch called "E.id"

Hi there!

I have a ROOT file (let it be named “file.root”), which contains a TTree called “Event”. This TTree contains a leaf called “E.id”.

I want to access the information in E.id, but when I do the script:

import ROOT

f = ROOT.TFile(“file.root”)
tree=f.Get(“Event”)

for it in tree:
print (it.E.id)

It says that ‘TTree’ object has no attribute ‘E’. This is due to the dot in E.id, but the file.root is not mine and I can not change the branches names.

Do you know how can I manage to read the data in the E.id leaf?

Thanks in advance!

Yes a “.” in a tree variable name is not a good practice.
Can you ask the author of this tree how he/she access this “dotted” variable ?
Otherwise @pcanal might have an idea.

This seems to be the best option. I will try to ask him!

Thanks for your answer!

1 Like

Just to make sure, attach the output of: tree.Print()

1 Like

In fact the branch is called E.run_id, but it’s the same problem.

Indeed, in the case of this tree, you should ask the author to change “E.” into, e.g., “E_”.

1 Like

Exactly …
And may be also ask the author what is the purpose of a variable you cannot access ?
Has he ever tried to access it himself ? It looks like a bug, a design mistake…

And it is not only E.run_id but also E.frame_index and E.trigger_counter

1 Like

@couet I guess, you can access these variables, if you use the standard TTree::SetBranchAddress way.

1 Like

You can also try

for it in tree:
    print(getattr(it, "E.id"))
1 Like

That worked perfectly, thanks a lot!