I have a tree containing a TBranch called Event inside which some leaves of which one is called weight.
I would like to reset this variabel weight to a correct value and leave all the other leaves and branches intact.
See maybe this: http://root.cern.ch/root/html/TTree.html#TTree:CloneTree and the “copytree3.C” tutorial: http://root.cern.ch/root/html/tutorials/tree/index.html
Note: in general, you can read an entry from the original tree (from an old, existing, root file), you can then modify its leafs in RAM, and then you can write that modified entry to a new “cloned” tree (to a newly created root file), and so on in a loop for all entries in the original tree.
You can modify the values of leafs in RAM for the entry “i” right after you “MyTree->GetEntry(i);” (and before you actually use them in your analysis). No need to save the modified values in a new root file, of course, but you will need to repeat this procedure each time you read this entry again from your root file.
Just to make it clear -> there is no way to modify these values in your old, existing, root files.
You can not (at least not in any easy way) add a leaf to a branch inside an existing file. If you really need this feature (humm … why?), you would need to create a brand new TTree object which the right branch and leaf structure and copy the data over from the old one to the new one.