{ auto f = new TFile("test.root", "recreate"); auto t1 = new TTree("t1", "t1"); int id1 = 0; t1->Branch("id", &id1, "id/I"); t1->Fill(); t1->Write(); auto t2 = new TTree("t2", "t2"); int id2 = 0; t2->Branch("id", &id2, "id/I"); t2->Fill(); t2->Write(); id1=1; t1->Fill(); t1->Write(); id2=1; t2->Fill(); t2->AddFriend(t1); t2->Write(); f->Close(); auto f1 = new TFile("test.root", "read"); auto t1_1 = (TTree*)f1->Get("t1"); auto t2_1 = (TTree*)f1->Get("t2"); for(int i=0; iGetEntries(); i++) { t2_1->GetEntry(i); //cout << t2_1id << " " << t1_1.id << endl; } cout << "Closing" << endl; f1->Close(); }