I am trying to create new branches (different names) with different data through looping. However, the data keeps adding up in all the branches. I believe it is due to reference argument of TBranch. Here is my code. Please help me out. Thank you.
4 import ROOT
5 import json
6 import array as arr
7
8 jsfile = open('data.json')
9 data = json.load(jsfile)
10
11 rtfile = ROOT.TFile("js2rt.root", "RECREATE")
12 tree = ROOT.TTree("0", "Events")
13
14 for i in range(128):
15 adc = arr.array('f', [0])
16 tree.Branch("chn"+str(i), adc, "leafname/F")
17 for entry in data['signalData'][0]['chn'+str(i)]:
18 adc[0] = entry
19 tree.Fill()
20
21 tree.Write()
22 rtfile.Close()
23 jsfile.close()
I made a mistake in the wording. I do not need branches, just my leaves are not as I am hoping them to be. I am trying to create 128 leaves (from 0 to 127) with 645 entires each. However, I do have 128 leaves but all of them 82650 entries (645 x 128).
Thank you for your reply. I am still having same problems as each leaf (all 128 leaves) have all the entries (128 x 645 = 82650) instead of 645 entries each.
My code:
1 import ROOT
2 import json
3 import array as arr
4
5 jsfile = open('data.json')
6 data = json.load(jsfile)
7
8 rtfile = ROOT.TFile("new.root", "RECREATE")
9 tree = ROOT.TTree("0", "Events")
10
11 for i in range(128):
12 adc = arr.array('f', [0])
13 tree.Branch("chn"+str(i), adc, "leafname/S")
14 for entry in data['signalData'][0]['chn'+str(i)]:
15 adc[0] = entry
16 tree.Fill()
17
18 tree.Write()
19 rtfile.Close()
20 jsfile.close()
Previously I thought it was a reference problem but it was not. I have been working on this for 1 and half day now, still keeps on getting it wrong.
Well, I’ve forgotten about TTree::SetEntries (which is only needed when one fills all branches independently).
Fortunately, it also checks if the numbers of entries in all branches are identical (if not, a warning is issued, which one should not ignore).