Horizontally merging two TTrees

Hi @harshjaluka ,

for a simple horizonal join in which you process every entry of the two trees in lockstep (entry 1 of tree A with entry 1 of tree B, then entry 2 of tree A with entry 2 of tree B), it’s enough to use mainTree->AddFriend(auxTree) and loop over mainTree. Docs are here and you can also search the forum or the ROOT tutorials for example usages. Friend trees are also described in the manual: Trees - ROOT .

For more complex joins over a common column value (e.g. EventNumber), TTree offers “indexed friend trees”. Here’s an example of how to build that relation: Merging two TTrees with different variables but 1 common key . Docs are here. For every entry in the main tree, the entry in the friend tree with the same value for the index column will be loaded, even if it’s out of order and even if the relation is many to one.

Cheers,
Enrico