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', )
for event in roottree_in:
arr_br = 2.71828
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.
A helpful thread: Cloning tree and changing contents in the new tree