Optimize TChain friends

Hi,

I have a set of root files containing 2 separate TTrees. I’d like to chain all the trees and connect them as friends. I’m not sure what’s the most optimal way to do that. I currently have something like:

[code]// first chain
TChain *C1 = new TChain(“tree1”);
C1->AddFile(file1.root);
C1->AddFile(file2.root);

// second chain
TChain *C2 = new TChain(“tree2”);
C2->AddFile(file1.root);
C2->AddFile(file2.root);

// make friends
C1->AddFriend(C2);[/code]

As you can see file1.root and file2.root are read twice. I have the feeling this is not optimal when looping over the tree entries.

Any better idea?
Thank you

I do not see why it should not be optimal. Does it work ?

Hi,

Yes, it works, but it is slow to loop over all the events in chain. I was suspecting that in my case, the IO was not optimal as the 2 TTrees are in the same file.

I did some speed tests where I activate/de-activate the branch status. I see a real difference when I de-activate all the branches of one chain.