I am sure this might have been answered, but I cannot find the thread.
I have a root file (lets say file1.root) that contains some TTrees:
each of those with several branches.
I want to create another root file (lets say file2.root) with the same trees, but with different names, like:
I have tried several things, but i finally got here…
sorry if this is trivial, but this is really taking me now a lot of time.
What did you try exactly?
The tutorial ‘tutorials/tree/copytree.C’ shows an example how to do it. By default all branches are copied.
You can change the name of the new tree with newtree->SetName(“newname”) before writing it out to the new file. also, CloneTree accepts an option fast to avoid uncompressing the tree during copy.
Something like this should do it:
TFile *file = TFile::Open("file.root");
TTree *tree = (TTree*)file->Get("name");
// Create a new file, clone tree in new file, change name
TFile *newfile = TFile::Open("newfile.root","recreate");
TTree *newtree = tree->CloneTree(-1, "fast");
thanks for the reply.
The step that I was missing was:
I actually managed to do it. Thanks for your answer ayway.