Example of Root macro to copy a subset of a Tree to a new Tree, selecting entries.
Only selected entries are copied to the new Tree. The input file has been generated by the program in $ROOTSYS/test/Event with Event 1000 1 99 1
#ifdef ACTUAL_RUN
void run()
{
TFile oldfile(
"tree108.root");
oldfile.GetObject("t4", oldtree);
TFile newfile(
"tree112.root",
"recreate");
if (event->GetNtrack() > 605)
newtree->Fill();
event->Clear();
}
newfile.Write();
}
#else
void tree112_copy()
{
gROOT->ProcessLine(
".L " + tutdir +
"/io/tree/Event.cxx+");
gROOT->ProcessLine(
"#define ACTUAL_RUN yes");
gROOT->ProcessLine(
"#include \"" __FILE__
"\"");
gROOT->ProcessLine(
"run()");
}
#endif
A file, usually with extension .root, that stores data and code in the form of serialized objects in ...
A TTree represents a columnar dataset.
virtual Int_t SetBranchAddress(const char *bname, void *add, TBranch **ptr, TClass *realClass, EDataType datatype, bool isptr, bool suppressMissingBranchError)
virtual Int_t GetEntry(Long64_t entry, Int_t getall=0)
Read all branches of entry and return total number of bytes read.
void Print(Option_t *option="") const override
Print a summary of the tree contents.
virtual Long64_t GetEntries() const
virtual TTree * CloneTree(Long64_t nentries=-1, Option_t *option="")
Create a clone of this tree and copy nentries.
- Author
- Rene Brun
Definition in file tree112_copy.C.