Pyroot read leaves with dot in name

Dear, I have the following example where I read leaves from a tree:

chain = ROOT.TChain()

for iev in chain:
    print(iev.var) # if leaf (=var) has no dots in name = works!
    print(iev.object.var) # if leaf(object.var) has dots in name = Problem!

How should I read the last case correctly in pyroot?

Hi @ROOTer1,

This seems to happen because of Python intrinsic lookup rules; it tries to get the value for an attribute named object (instead of object.var). See Reading nTuple in PyROOT - variables containing '.' for a workaround based on __getattr__().

I am also CC’ing @vpadulan in case he knows of a better approach.


Dear @ROOTer1 ,


I see you are using this for event in chain notation. Note that this is SLOW and you should never use it if you are processing more than 1 GB of data. If possible, use RDataFrame for your analysis.

Back to your question,

Javier is right. only leaf names with standard Python syntax are allowed to be retrieved with the dot notation. This is the most common approach with any Python library (think about what happens if you have the column “object.var” in a pandas dataframe for example).

The correct approach is using something like

getattr(iev, "object.var")

Or you can choose to have only standard nomenclature for your columns (i.e. letters, numbers and the _ character) if you have this possibility.


Thank you very much Vincenzo!