How to merge two root files with different branches togher

I am a theorist and not very familiar with root. I want to merge two related root to one root file, but the branches in two root files are different. Concretely, one root (lep.root) has branches Lep_pt, Lep_eta, and the other has branches Jet_pt , Jet_eta (Jet.root), but the entry number corresponding to the event number are same for these two roots. The variable such as Lep_pt is vector. Please kindly find the attached root files.

I have tried merge.C script , AddFriend, TBranchClone, but I failed. AddFriend [-X is helpful to load the Branch information to cache and good for drawing histogram. But I want to use the merged root file for further analysis. Could anybody help me. Thanks a lot. If you could provide a example, I would be much grateful. [-o<
jet.root (413 KB)
lep.root (39.6 KB)

Hi,

The best solution is to use AddFriend which should work for most circumstances. Merging laterally two files (i.e. was you are looking for) has not yet been implemented as a core feature and thus you would need to do it by hand (i.e. construct a 3rd TTree with the same branches as the other two combined and explicitly set the address of the branches to the same (respectively) addresses and the loop over the tree entries to read and write (i.e. GetEntry and Fill).

Cheers,
Philippe.