TTree::AddFriend() from TDirectory?

Dear Rooters

I have root files where my trees are stored in different subdirectories.

Is it possible to add the trees from different files and different subdirectories as friends to one tree?

Thank you in advance
Best regards
Christian

[quote]Is it possible to add the trees from different files and different subdirectories as friends to one tree?[/quote]Yes. Just specify the proper location of the file when calling AddFriend.

Cheers,
Philippe

Dear Philippe

I have a method where everything worked when I stored the trees in the root files.
Now I have decided to store the trees in subdirectories and get the error:
Warning in TTree::AddFriend: Cannot add FriendElement Test3-2=Test3-2.cel in file /Users/cs/ROOT/rootcode/xpstest/Test4_cel.root

It seems that storing the proper location of TFile is not sufficient.
The comments to Tree::AddFriend() states:
// This function:
// -opens a file if filename is specified
// -reads a Tree with name treename from the file (current directory)
// -adds the Tree to the list of friends

Does this mean that I have to open each TFile first, then call file->cd(directory)
before calling tree->AddFriend()?

Best regards
Christian

[quote]Does this mean that I have to open each TFile first, then call file->cd(directory) before calling tree->AddFriend()?
[/quote]Now I am a little confused :slight_smile: When you say ‘subdirectory’ are you talking about a file-system sub-directory or a ROOT sub-(T)directory inside a TFile?
For the first oneT->AddFriend("name","directory/filename.root");works. For the laterT->AddFriend("dir/name","filename.root");might work.

Cheers,
Philippe.

Dear Philippe

Thank you very much, T->AddFriend(“dir/name”,“filename.root”) is the solution.

Best regards
Christian