This works:
TFile* f1 = new TFile("in1.root", "READ");
TFile* f2 = new TFile("in1.root", "READ");
TTree* t1 = (TTree*)f1->Get("tree1");
TTree* t2 = (TTree*)f2->Get("tree1");
TList* l = new TList();
l->Add(t1);
l->Add(t2);
TFile* f3 = new TFile("out.root", "RECREATE");
TTree* t3 = TTree::MergeTrees(l);
t3->Write();
This works (file and tree names changed, rest as above):
TFile* f1 = new TFile("in2.root", "READ");
TFile* f2 = new TFile("in2.root", "READ");
TTree* t1 = (TTree*)f1->Get("tree2");
TTree* t2 = (TTree*)f2->Get("tree2");
TList* l = new TList();
l->Add(t1);
l->Add(t2);
TFile* f3 = new TFile("out.root", "RECREATE");
TTree* t3 = TTree::MergeTrees(l);
t3->Write();
This segfaults (file and tree names changed, rest as above):
TFile* f1 = new TFile("in1.root", "READ");
TFile* f2 = new TFile("in2.root", "READ");
TTree* t1 = (TTree*)f1->Get("tree1");
TTree* t2 = (TTree*)f2->Get("tree2");
TList* l = new TList();
l->Add(t1);
l->Add(t2);
TFile* f3 = new TFile("out.root", "RECREATE");
TTree* t3 = TTree::MergeTrees(l);
t3->Write();
The trees in both files have the same branches, since they are produced by the same code. In fact, if I rename tree1 to tree2, I can hadd the two files just fine, so I don’t see a reason why the code above would not work. What am I doing wrong?