43 void CreateParentTree() {
46 TFile *f =
new TFile(
"treeparent.root",
"recreate");
47 TTree *T =
new TTree(
"T",
"test friend trees");
48 T->Branch(
"Run",&Run,
"Run/I");
49 T->Branch(
"Event",&Event,
"Event/I");
50 T->Branch(
"x",&x,
"x/F");
51 T->Branch(
"y",&y,
"y/F");
52 T->Branch(
"z",&z,
"z/F");
54 for (Int_t i=0;i<10000;i++) {
55 if (i < 5000) Run = 1;
67 void CreateFriendTree() {
74 TFile *f =
new TFile(
"treeparent.root");
75 TTree *T = (TTree*)f->Get(
"T");
76 TFile *ff =
new TFile(
"treefriend.root",
"recreate");
77 TTree *TF = T->CopyTree(
"z<10");
79 TF->BuildIndex(
"Run",
"Event");
90 TFile *f =
new TFile(
"treeparent.root");
91 TTree *T = (TTree*)f->Get(
"T");
92 TFile *ff =
new TFile(
"treefriend.root");
93 TTree *TF = (TTree*)ff->Get(
"TF");
96 T->SetBranchAddress(
"Run",&Run);
97 T->SetBranchAddress(
"Event",&Event);
98 T->SetBranchAddress(
"x",&x);
99 T->SetBranchAddress(
"y",&y);
100 T->SetBranchAddress(
"z",&z);
101 TF->SetBranchAddress(
"Run",&fRun);
102 TF->SetBranchAddress(
"Event",&fEvent);
103 TF->SetBranchAddress(
"x",&fx);
104 TF->SetBranchAddress(
"y",&fy);
105 TF->SetBranchAddress(
"z",&fz);
108 Long64_t nentries = T->GetEntries();
110 for (Long64_t i=0;i<nentries;i++) {
112 if (fRun == Run && fEvent==Event && x==fx && y==fy &&z==fz) {
115 if (TF->GetEntryWithIndex(Run,Event) > 0) {
116 if (i <100) printf(
"i=%lld, Run=%d, Event=%d, x=%g, y=%g, z=%g, : fRun=%d, fEvent=%d, fx=%g, fy=%g, fz=%g\n",i,Run,Event,x,y,z,fRun,fEvent,fx,fy,fz);
120 printf(
"nok = %d, fentries=%lld\n",nok,TF->GetEntries());
131 TFile *f = TFile::Open(
"treeparent.root");
132 TTree *T = (TTree*)f->Get(
"T");
133 T->AddFriend(
"TF",
"treefriend.root");