Dear experts,
I’m using pyroot installed by conda. I am trying to add a new branch to an existing root file, and write it to a new .root
file.
So, I wrote
old_Tree= TChain("tree")
old_Tree.Add(inputfile) # Contain 1 million events , with the storage of 1.3 GB
Outputfile =TFile(inputfile,"RECREATE")
Outputfile.cd()
Efficiency = get_eff() # a function to get a weigt factor event-by-event , and return a numpy object
new_Tree=old_Tree.CloneTree(0)
newBranches={
"Eff" : array.array('f', [0]) ,
}
for key, val in newBranches.items():
newTree.Branch(key, val, f"{key}/F")
Then, I looped over the old tree to fill the new tree, and write it to a file
''' Method #1 '''
evt_i = 0
for evt in old_Tree:
newBranches["Eff"][0] = Efficiency[evt_i]
newTree.Fill()
evt_i += 1
newTree.Write()
Outputfile.Close()
But it raised an Error saying
Error in <TBufferFile::WriteByteCount>: bytecount too large (more than 1073741822)
Error in <TBufferFile::WriteByteCount>: bytecount too large (more than 1073741822)
Error in <TList::Clear>: A list is accessing an object (0x7ffc5f02b080) already deleted (list name = TList)
And I tried another way to loop over the tree via
''' Method #2 '''
for evt_i in range(old_Tree.GetEntries()):
Input_Chain.GetEntry(evt_i)
newBranches["Eff"][0] = Efficiency[evt_i]
newTree.Fill()
newTree.Write()
Outputfile.Close()
At this time, no error raised by the TBufferFile
Could anyone tell me what’s the difference between such two method when looping a TTree
in pyroot
ROOT Version: 6.28/04
Platform: centos7