Hi all,
I am trying to iterate over a tree with branches, which are generated dynamically, i.e., I parse a text file and create branches for fields in this list matching a certain pattern. Thus I do not know which fields will show up in the beginning.
After filling and saving the tree, I would now create a few histograms for values I now are showing up.
However, I am stuck at how to address the branch values properly (CINT equivalent would be SetBranchAdress or so I suppose)
So My steps are
setting up the tree and adding branches
logValues = {}
rootFileName = "./plots/%s.root" % (baseFileName)
rootFile = ROOT.TFile(rootFileName, "RECREATE")
rootTree = ROOT.TTree("jobTree", "jobTree")
for logField,accounting in logInfo.iteritems():
logValues[logField] = array( 'f',[0])
rootTree.Branch("%s" % logField,logValues[logField],"%s/F" % logField)
Then filling a branch after somewhat of text parsing
for...:
if...:
logValues[logField][0] = float(jobSplit[accounting[0]])
which works fine and I can save a root-file with branches+values
Now I want to iterate over the tree and branches and fill values into a histogram (I could fill the histogram while filling the root file, but I would like to avoid that)
canvas = ROOT.TCanvas("canvas","KIT Statistics")
canvas.cd()
histo = ROOT.TH1D("histo",title,int(histoBinning),float(histoStart),float(histoEnd))
nTreeEvents = tree.GetEntries()
value = []
branch = tree.GetBranch(branchName) # <-- where branchName = one of the dynamcally generated
for event in range(nTreeEvents):
tree.GetEntry(event) # <-- ??
##branch.GetEntry(event) # <-- ??
histo.Fill(value) # <-- ??
which is where I am lost how to get the actual value for a given branch of a given event?
Has somebody an idea for me?
Cheers and many thanks,
Thomas