TTree in pyROOT is not working

ROOT Version: 6.24
Platform: Mac
Compiler: -


Hello,
I have an issue with TTree in PyROOT
I have a simple code that should write TTree to the file with float variables
For some reason, all the variables are 0
What am I doing wrong?
File is attached
test.py (524 Bytes)

#!/usr/bin/env python3
from ROOT import TTree, TFile
from array import array


outfile = TFile( "./store/data_collection_8TeV.root", "RECREATE" )
tree = TTree("tree", "The Tree Title")

# Provide a one-element array, so ROOT can read data from this memory.
var = array('f', [ 0 ])
tree.Branch("branch0", var, "leafname/F")

for iEntry in range(1000):
   var = 0.3 * iEntry
   print(var)
   # Fill the current value of `var` into `branch0`
   tree.Fill()

# Now write the header
tree.Write()
outfile.Write()
outfile.Close()

Cheers Evgeny

Hi @Evgeny_Shulga,

I guess you have to change

to

   var[0] = 0.3 * iEntry

Cheers,
J.

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