Logo ROOT   6.10/09
Reference Guide
copytree.C File Reference

Detailed Description

View in nbviewer Open in SWAN Copy a subset of a Tree to a new Tree

The input file has been generated by the program in $ROOTSYS/test/Event with Event 1000 1 1 1.

R__LOAD_LIBRARY($ROOTSYS/test/libEvent.so)
void copytree() {
//Get old file, old tree and set top branch address
TFile *oldfile;
TString dir = "$ROOTSYS/test/Event.root";
if (!gSystem->AccessPathName(dir))
{oldfile = new TFile("$ROOTSYS/test/Event.root");}
else {oldfile = new TFile("./Event.root");}
TTree *oldtree = (TTree*)oldfile->Get("T");
Event *event = new Event();
oldtree->SetBranchAddress("event",&event);
oldtree->SetBranchStatus("*",0);
oldtree->SetBranchStatus("event",1);
oldtree->SetBranchStatus("fNtrack",1);
oldtree->SetBranchStatus("fNseg",1);
oldtree->SetBranchStatus("fH",1);
//Create a new file + a clone of old tree in new file
TFile *newfile = new TFile("small.root","recreate");
TTree *newtree = oldtree->CloneTree();
newtree->Print();
newfile->Write();
delete oldfile;
delete newfile;
}
Author
Rene Brun

Definition in file copytree.C.