TChain * chain = new TChain("tree");
chain->Add("file1.root");
chain->Add("file2.root");
TTree * tree = chain;
//make some trees that are friends of tree
Then I would like to save tree and its friends to a file and draw histograms of their variables. How do you recommend doing that? When I save a tree to a file, do its friends automatically get saved as well?
[quote] When I save a tree to a file, do its friends automatically get saved as well?[/quote]No.
[quote]Then I would like to save tree and its friends to a file and draw histograms of their variables[/quote]Why? Is there creating TChain objects as needed sufficient? If not, why?
The direct answer to you question that you should use for each chain (and each of the friend (chain)), CloneTree.
See $ROOTSYS/tutorials/tree/copytree* for some example.TChain * chain = new TChain("tree");
chain->Add("file1.root");
chain->Add("file2.root");
TFile *file = TFile::Open("output","RECREATE");
chain->CloneTree(-1,"fast");
file->Write();
delete file.
ok when I use clonetree, does the new tree have the same friends as the old tree? if not, is there some way to clone a tree so that the new tree has the same friends as the old tree?
When using CloneTree, the resulting TTree will have the same friend as the first TTree (of the TChain). (No friend will be copied from the TChain object itself).
The genuine question is still:[quote] Why? Isn’t creating TChain objects as needed sufficient? If not, why?[/quote]It seems that you making the problem more complex for no real gain …