TTree MergeTrees

Dear ROOT experts,

I’m trying to add the contents of two TTrees (that contain different TBranches i.e. different names, types etc.) from the same file into another TTree, so that I can then use MakeClass on the new tree that contains all the branches of the other two.

I’m not sure what’s the best way to do this but I tried to do

[code]

TFile *f = new TFile(“out.root”);

TTree * t1 = (*TTree)f->Get(“GEN”);
TTree * t2 = (*TTree)f->Get(“Analysis”);

TList list;

list.Add(t1);
list.Add(t2);

TFile *f = new TFile(“new.root”);

TTree::MergeTrees(&list)

f->Write();
f->Close();

[\code][/code]

but only the branches from the first tree were present, and a message saying that the first set of branches couldn’t be found appeared when it tried to reaed the second tree.

Is this correct? Or is there a better way to do it?

Cheers,
Chris Boddy

Hi,

The goal of MergeTrees is to concatenate the TTree ‘vertically’, i.e. by adding more entries. By definition it will not add branches. Also by definition of TTree, all the branches should be filled with the same amount of entries [It is ‘possible’ to have unbalanced branches but this ‘breaks’ all the tools (TTree::Draw, TTree::MakeClass, etc…)]

Currently the only way to handle your situation is to (optionally make the 2 TTree friend of each other and) generate 2 MakeClass skeleton and connect them by hand.

Cheers,
Philippe.