Merging two files with same TTree name and different Branche

Hello

What I want to do, is to merge two files which have the same TTree names and events but different Branches in each TTree . If I

hadd output.root 1.root 2.root

it returns

Warning in TChain::CopyAddresses: Could not find branch named ‘MCparticles’ in tree named ‘eventTree’

where the MCparticles Branch exists in the 2.root but not in the 1.root file

and what I get as output, is the Branches of the 1.root files with twice the initial events, and ofcourse half of them are zeros…

I guess , this could be trivial, but…how to proceed? Using 5.18

Thanks in advance

What I am trying to do , like in the copytree’s examples is this

TFile * f1 = new TFile ("f1.root")
TTree *t1 = (TTree*)f1->Get("eventTree");

TFile * f2 = new TFile ("f2.root")
TTree *t2 = (TTree*)f2->Get("eventTree");

t1->SetBranchStatus("*", 0)
t2->SetBranchStatus("*", 0)

TChain * ch = new TChain();

t1->SetBranchStatus("Jets",1)

t2->SetBranchStatus("MC",1)

ch->Add("f1.root/eventTree")
ch->Add("f2.root/eventTree")

TFile * fout_ = new TFile ("output.root" , "RECREATE")
TTree * newtree = ch->CloneTree(0);
newtree->CopyEntries(t1);
newtree->CopyEntries(t2);

but unfortunatelly, this does not give the desired result , ie a new file with e TTree containing both branches t1 , t2

How to proceed from this point on? Could really use any help!

Thanks in advance

Alex

Hello again… I would really could use your help on this still unanswered topic…

Thanks in advance

A

[quote]What I want to do, is to merge two files which have the same TTree names and events but different Branches in each TTree[/quote]What is the expected result? Should the resulting tree have the same number of entries as both TTree (and what happens if they do not have the same number of entries) or should it be the sum?

I.e. What is the semantic of ‘merge’ here?

The usual semantic is to serialize the input TTrees into a single TTree. If one of the TTree does not have the same branches as the others then the question is what values should the missing entries have for the missing branches?

Cheers,
Philippe.