Hello,
The most efficient way to do this would be to use RDataFrame:
With RDataFrame
, the loop would happen in C++, and therefore the performance would be better than to have it in Python.
As for what you want to do, the way to proceed would be to create an RDataFrame from your initial tree stored in your ROOT file. From that tree, you can define new columns (branches) based on the information contained in the initial tree. Finally, you can Snapshot
(store in a file) the derived trees.
In particular, this RDataFrame tutorial:
might be useful.
Please let us know if you need further assistance to develop this code with RDataFrame.