I’m trying to read out a TTree and write it to a new TFile, but with one branch changed, say all numbers multiplied by 3. There’s a tutorial example how to do that in C++, but I cannot translate that to Python. I tried using SetBranchAddress(), AddressOf(), Branch() or setattr(). But the values written to the TFile are always the same. How can I achieve this functionality in pyROOT?
Ah, I have it. Not sure if that’s the canonical way, but it is working:
arr_br = array('f', [0])
roottree_out.SetBranchAddress(branch, arr_br)
for event in roottree_in:
arr_br[0] = 2.71828
roottree_out.Fill()
roottree_out.Write()
It’s important to have the type of the array the same as the branch. While this sounds obvious, it took me a few hours to realize why my code wasn’t producing the expected output.