Another TTree merging question

Hello,
I have two Trees, t1 and t2 that live in separate TFiles. I would like to create a third TTree, t3 that is almost the concatenation of the t1 and t2 (for which TTree::Merge() would do niceley) The difference is, there is a single branch of doubles in t2 that I would first like to modify before copying it into t3. I’ve been struggling with TTree::CloneTree(), TTree::CopyAddresses(), TTree::GetBranch(“mybranch”)->GetAddress() etc., but to no avail. Can you please provide some guidance? Thanks!
Ed

see example in $ROOTSYS/tutorials/copytree3.C
after the line
oldtree->GetEntry(i);
add your statement(s) modifying the structure in memory. The new data will be taken by the next newtree->Fill()

Rene

Hi Rene,
I understand how to make a copy of a single tree with branch modification as you suggest from the copytree3.C example. However, I want to combine two trees into one, after modifying the second tree. I’ve tried this and numerous variants:

  TFile *f1 = new TFile("old1.root");
  TFile *f2 = new TFile("old2.root");
  TFile *f3 = new TFile("new3.root","recreate")
  TTree *t1 = (TTree *)f1->Get("t1");
  TTree *t2 = (TTree *)f2->Get("t2");
  TTree *t3 = t1->CloneTree(-1); // I'm happy with leaving this intact

// Here's my attempt to modify the second tree before concatenating it  I cannot say
// t3 = t2->Clone(0) - as this will create a new tree, right?  This is what I've 
// tried. sadly, it does not work!

  t2->CopyAddresses(t3);  // set addresses of t3 to those of t2
  double b;
  t2->SetBranchAddress("myBranch",&b); // this is branch I want to modify
  for(int i=0;i<t2->GetEntries();i++)
  {
     t2->GetEntry(i);
     // modify b
     t3->Fill();
  }

I’ve also tried to use

   double *b = (double *)t2->GetBranch("MyBranch")->GetBranchAddress();

but that always returns 0. Any other suggestions? Thanks!
Ed

We do not support horizontal merging. We recommend instead the use of friend trees (see TTree::AddFriend).

Rene