Please fill also the fields below. Note that root -b -q will tell you this info, and starting from 6.28/06 upwards, you can call .forum bug from the ROOT prompt to pre-populate a topic.
I need a few hints on how to define and fill branches in a TTree from pyRoot.
Sorry if this is quite elementary, but I have forgotten how to do it right, and didn’t find
my answer in the docs/demos. Maybe I should even not use branches but ntuples?
But would still like to understand how to do it right.
Anyway, here is a small reproducer of the error I am encountering
#!/usr/bin/python
import random
from ROOT import TFile, TTree
#
Nev = 1000
fname = 'test_ttree.root'
f = TFile(fname,'recreate')
#
t = TTree('myTree','uniform rn between -1.o and 1.0')
#
# define variables
#
x = 10.0 # arbitray vaue outside of random range
y = -1.0 # dto
#
# set up branches
#
xB = t.Branch('x',x,'x/D')
yB = t.Branch('y',y,'y/D')
for nev in range(Nev):
x = random.uniform(-1.0,1.0)
y = random.uniform( 0.0,1.0)
xB.Fill()
yB.Fill()
#
f.Write()
f.Close()
Thank you! But this is the C++ example, which indeed I had seen before.
What I needed was its python equivalent, as I couldn’t correctly guess how to
transliterate the C++ into pyROOT. If you know how to modify my non-working
example so that it actually works, that would help me a lot.