TTree friend branches with same name

Hi all,

I have a question about the TTree friend mechanism. I have two trees with the same name, and a branch with the same name. I want to add one tree as a friend to the other and be able to access the branches seperately. Here is the relevant code:

To create the tree and add the friend:

  TFile * f = new TFile("/data1/elplatt/col1.root", "READ");
  TTree * tree = f->Get("CMSJetTree");
  tree->SetDirectory(0); // So tree isn't deleted when file is closed
  f->Close();
  tree->AddFriend("CMSJetTree2 = CMSJetTree", "/data1/elplatt/col2.root");

To set the branch addresses:

  fTree->SetBranchAddress("Jets", &fJet1);
  fTree->SetBranchAddress("CMSJetTree2.Jets", &fJet2);

It seems that both branches are combined and placed into the “Jets” branch and the
"CMSJetTree2.Jets" results in a segmentation violation when GetEntry() is called.
What should I be doing instead?

tree->SetDirectory(0); // So tree isn't deleted when file is closed f->Close();This means that only the first basket (i.e. the first few entries of the tree) are available. Hence you should be able to read fJet2 but not fJet1 (also are those pointers as they should?).
So remove those 2 lines and it should work.

Cheers,
Philippe.