You are here

ROOT trees

A ROOT tree is a collection of branches (i.e. instances of the TBranch class), where a single class is usually associated to a given branch. Branches may also be written to different files. When reading a variable from a tree stored into a TFile, ROOT only reads the branch containing it, to achieve the maximum performance.

The TTree::Fill(...) method loops over all branches invoking TBranch::Fill(...). A branch may contain:

  • a collection of simple variables;
  • objects of any class inheriting from TObject;
  • objects of the TClonesArray class (a specialized collection of objects of the same class);
  • a STL vector, list, deque, set or multiset containing pointers to objects.

Reading from a tree is very fast, because one usually needs only a small subset of all variables at the same time. Data in different branches are written in separate buffers on file, so that one is usually reading only one or very few buffers when looping over all events, without the need to scan the full tree.

If the data size is huge, saving everything in a single file is not a good solution (and might even be impossible on a given machine). However, from a logical point of view one can still have a unique tree, even if split among different files. The TChain class, inheriting from TTree, represents a collection of files containing TTree objects that will be chained into a single logical tree. When looping over events contained by this logical entity, ROOT takes care of fetching the data from the correct file. An example can be found in the How to use chains document.