Pyroot, Acessing a leaf nested in a branch

Hello,

I am having trouble accessing a leaf within a branch using pyroot(see attached snapshot to see the tree structure). The current way I am attempting to access the leaf is by the following syntax:

tree = ifile.Get(‘tree’)
nentries = tree.GetEntries()
for ientry in range(nentries):
tree.GetEntry(ientry)
val = tree.gg_plus_ZH125_highZpt.Nominal

Where gg_plus_ZH125_highZpt is a branch and Nominal is the nested leaf in the branch.

I recieve the error: tree has no method gg_plus_ZH125_highZpt. All other branches which do not have further nesting can be accessed in this way just fine.

Thanks


Is gg_plus_ZH125_highZpt a scalar structure of a container? Because if it is a container then you need to iterate on it.

tree = ifile.Get('tree')
nentries = tree.GetEntries()
for ientry in range(nentries):
  tree.GetEntry(ientry)
  for p in tree.gg_plus_ZH125_highZpt:
    val = p.Nominal

Hi,

Thanks for the reply. I attempted accessing the nested leaf as you suggest:

for p in tree.gg_plus_ZH125_highZpt:
val = p.Nominal

But I recieve the error: “tree has no attributet gg_plus_ZH125_highZpt”.
I’ve double checked that the input tree does have a branch called gg_plus_ZH125_highZpt. Any ideas why this syntax does not work?

thanks,

Try the following:

tree = ifile.Get('tree')
for entry in tree:
  print entry.gg_plus_ZH125_highZpt.Nominal

Hi Again,

Sorry the delayed reply, and thanks for the help. If this topic is too old now I will create a new one. I tried the last advice from you:

tree = ifile.Get(‘tree’)
for entry in tree:
print entry.gg_plus_ZH125_highZpt.Nominal

But still see the same error:
AttributeError: ‘TTree’ object has no attribute ‘gg_plus_ZH125_highZpt’

Just to verify I made a print out of the tree contents and we can see I do have the branch:

*Br 1596 :gg_plus_ZH125_highZpt : Nominal:JER_Up:JER_Down:PileUpDataMC_Up: *

  •     | PileUpDataMC_Down:PileUpPtRef_Up:PileUpPtRef_Down:PileUpPtBB_Up: *
    
  •     | PileUpPtBB_Down:PileUpPtEC1_Up:PileUpPtEC1_Down:                 *
    
  •     | RelativeJEREC1_Up:RelativeJEREC1_Down:RelativeFSR_Up:            *
    
  •     | RelativeFSR_Down:RelativeStatFSR_Up:RelativeStatFSR_Down:        *
    
  •     | RelativeStatEC_Up:RelativeStatEC_Down:RelativePtBB_Up:           *
    
  •     | RelativePtBB_Down:RelativePtEC1_Up:RelativePtEC1_Down:           *
    
  •     | AbsoluteScale_Up:AbsoluteScale_Down:AbsoluteMPFBias_Up:          *
    
  •     | AbsoluteMPFBias_Down:AbsoluteStat_Up:AbsoluteStat_Down:          *
    
  •     | SinglePionECAL_Up:SinglePionECAL_Down:SinglePionHCAL_Up:         *
    
  •     | SinglePionHCAL_Down:Fragmentation_Up:Fragmentation_Down:         *
    
  •     | TimePtEta_Up:TimePtEta_Down:FlavorQCD_Up:FlavorQCD_Down/F        *
    

*Entries : 557187 : Total Size= 87015672 bytes File Size = 11427355 *
*Baskets : 536 : Basket Size= 192000 bytes Compression= 7.61 *

Thanks again