Writing a TBranch (array) to a TTree with pyROOT

Dear experts,

I am experiencing a problem when trying to write a TBranch to a ROOT file using a loop in pyROOT.


myFloats = (array( ‘f’, 100*[ 0.0 ] )
myTree.Branch(“someBranch”, myFloats, “someBranch/F” )

for entry, event in enumerate(myOtherTree, start=1):
values = getattr(event, “anotherBranch”)
for i, val in enumerate(values, start=0):
myFloats[i] =val
myTree.Fill()

Instead of size 100 (for example), the size of each entry is 1 instead, even though when I print the array myFloats all the values are present. I am hoping that this is something trivial.

Cheers,
Alexandros

myTree.Branch(“someBranch”, myFloats, “someBranch[100]/F” )

I will test it now, thanx! Sounds promising.

Since we are at it, is possible to not define the exact size for the array at the step that the branch is created?

Search for “variable size” in the TBranch::TBranch description.

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