Branch names starting with a digit in python

Dear experts,
To loop over tree entries in a python script I use

tr = file.Get(‘treename’)
for ev in tr:
print ev.LeptonPt

where LeptonPt is the name of the Branch(“LeptonPt”,…)
python object names should start with a letter. Question: how do I read the branch that is called ‘1stjetpt’?

There is no possibility to change the name of the branch.

Kind regards,
Denys

Unfortunately, since the branch name starts with a number, it breaks the automatic tooling.
However, you can probably still access it if you use an explicit assignment with a call to GetBranch. That is:

firstjetpt = tr.GetBranch("1stjetpt")  

You may also be able to rename the branch on the fly by using TDataFrame’s Define and/or Snapshot actions.

1 Like

getattr(ev, ‘1stjetpt’)

Thank you, anadio and wlaw! I went for GetBranch()

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.