Illustrates how to use Tree friends:
- create a simple TTree
- Copy a subset of this TTree to a new TTree
- Create a Tree Index
- Make a friend TTree
- compare two TTrees
- Draw a variable from the first tree versus a variable in the friend Tree
You can run this tutorial with:
root > .x treefriend.C (interpreted
via Cling)
root > .x treefriend.C+ (executed
via ACLIC & the native
compiler)
or, variants like:
root > .L treefriend.C+
root > CreateParentTree();
root > CreateFriendTree();
root > CompareTrees();
root > DrawFriend();
void CreateParentTree() {
TFile *f =
new TFile(
"treeparent.root",
"recreate");
T->
Branch(
"Run",&Run,
"Run/I");
T->
Branch(
"Event",&Event,
"Event/I");
for (
Int_t i=0;i<10000;i++) {
if (i < 5000) Run = 1;
else Run = 2;
Event = i;
}
}
void CreateFriendTree() {
TFile *ff =
new TFile(
"treefriend.root",
"recreate");
delete ff;
}
void CompareTrees() {
if (fRun == Run && fEvent==Event && x==fx && y==fy &&z==fz) {
nok++;
} else {
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);
}
}
}
delete ff;
}
void DrawFriend() {
}
void treefriend() {
CreateParentTree();
CreateFriendTree();
CompareTrees();
DrawFriend();
}
- Author
- Rene Brun
Definition in file treefriend.C.