Modifying a TTree on file

Right, I know how to create a tree, fill it, write it to file and read it back.
But what if I want to modify some of the objects in the tree that is already on file?
What do I have to do?
Also, what if I want to completely remove some of the objects already in the tree on file?
I can not find any clear documentation or examples for these two cases.
Please help.

Thank you.

See TTree documentation at
look at section “Adding a Branch to an Existing Tree”


Yes, yes I know about adding a new branch.
But I do not want to add a new branch, I want to change the contents of a branch I already filled.
Here is an example:

// Create a tree with a branch of MyClass objects and write it to file.
TFile* file = new TFile(“test.root”, “UPDATE”);
TTree* tree = new TTree(“tree”, “some tree”);
MyClass* obj = NULL;
tree->Branch(“mybranch”, “MyClass”, &obj);
obj = new MyClass();
delete file;

// Now open the same file to modify the object added to the tree.
TFile* file = new TFile(“test.root”, “UPDATE”);
TTree* tree = (TTree*) file->Get(“tree”);
MyClass* obj = NULL;
tree->SetBranchAddess(“mybranch”, &obj);
obj->Modify(); // Do my modifications…
// Now what? Are the changes already applied in the tree?
// Do I call Fill again? will that not just add another object?
// What if I want to delete the object from the tree, how do I do that?


TTree is designed as a write-once, read-many times container. The updating of existing object in a TTree is not supported.
As an alternative you can Clone (and modify) an existing TTree object (see TTree::CloneTree).