How to merge structures of 2 trees

Hi,
I have 2 trees, tree1 and tree2. Basically, I want to do: use selections in tree2 to get one merged tree of tree1 and tree2. So I think the right way is:

tree1->AddFriend(tree2);
TTree *newtree = tree1->CloneTree(0);
//loop entries 
for () {
...
if ( selection is true )
   newtree->Fill();
...
}

The problem of this approach is the merged tree: newtree only has tree1 although selection is satisfied. What I cannot understand is since I add tree2 as friend of tree1, why the merged tree is only containing tree1? How can I store tree2 with tree1 (I don’t care if tree1 and tree2 are parallel or merged in the new file)?

Cheers,
Zhiyi.

[quote] What I cannot understand is since I add tree2 as friend of tree1, why the merged tree is only containing tree1[/quote]The CloneTree operation currently explicitly ignores the friends (aka does not merge them).

[quote] How can I store tree2 with tree1 [/quote]You need to also clone tree2:tree1->AddFriend(tree2); TTree *newtree = tree1->CloneTree(0); TTree *newtree2 = tree2->CloneTree(0); //loop entries for () { ... if ( selection is true ) newtree->Fill(); newtree2->Fill(); ... }

Cheers,
Philippe