Correct a TTree
is a write-once, read-many time structure.
As summarized here Changing the values in the branch - #2 by Wile_E_Coyote
Your 4 options are:
-
You could apply your “fixes” when you actually analyze the data (e.g., define some alias “corrected_branch = original_branch - corerection_value” and then use the “corrected_branch” in the analysis).
-
You could “copy” your tree to another file, modifying its entries on the fly.
-
You could create a “friend tree” with new branches.
-
You could add new branches to the existing tree.
Where option 3. (using a friend tree) is the most commonly used when option 1. is not possible.
Your example implements option 2. Albeit you should change the name of the branch (and/or first remove the old branches from the newTree
.
Your example can implement option 4 by creating an empty 'newTreerather than cloning the existing tree (and then use the result by calling
TTree::AddFriend`).
Note that you can optionally writing the newTree
in the same file (open the old file with the UPDATE
option) and make the friendship ‘permanent’ (by updating ‘just’ the meta-data of the old TTree).