Compare tree 'A' between 2 different root files

Hi, relatively new user here:

I have two root files, both of which contain the same tree ‘A’.

Is it possible that I can load both root files in one ROOT session, and then compare branches of ‘A’ between the two root files?

E.g. tree ‘A’ has branch “momentum”, I would like to scan that branch for both root files in a single session and compare the values side by side.

Thanks so much for any advice!

I believe you want the TTree::AddFriend(TTree * tree, const char* alias) method:

An example:

TFile file1("file1.root");
TTree *tree1 = (TTree*) file1->Get("A");

TFile file2("file2.root");
TTree *tree2 = (TTree*) file2->Get("A");

tree1->AddFriend(tree2, "tree2");


(I haven’t tested this.)

1 Like

Thanks so much! That was really helpful.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.