Merging Branches from two TFiles into one tree

Hey Everyone,

I have two .root TFiles with the same tree name. However, each tree have a different branch. Is there away to append the two branch into one tree in a new .root file?

For example I currently have.

Set1.root w/tree Total containing a branch called V1
Set2.root w/tree Total containing a branch called V2

I wanted to create a new TFile with a tree containing branch V1 and V2 from their respected ROOT file.

I’m not sure how the coding would go for this one. If anyone can please assist me.

Thanks :smiley:

Dear kTrinh,

Declaring the second tree as friend of the first one you can get a unified view of the two trees keeping the file separated. See root.cern.ch/doc/master/treefriend_8C.html .

Otherwise you have to create a new tree filling it with the information read from the existing two. See tutorials root.cern.ch/doc/master/copytree_8C.html for reading a tree.

G Ganis