User Tools

Site Tools


root:chain

How to use chains in ROOT

Idea

A chain is sort of a container for trees. A chain can contain an arbitrary number of trees and can be used the same way as a tree, as the class chain inherits from the class tree.

Adding Files

A simple example is the following:

TChain* myChain = new TChain("DecayTree");
myChain->Add("myRootFile.root");

Note the following:

  • You have to add files, not trees to the chain
  • All your files need to have the same structure (subdirectories, branches,…)
  • If your trees are in a subdirectory, you have to specify it in the constructor. For example: If your tree DecayTree is in the subdirectory mySubdirectory in the root file myRootFile.root, call the constructor with:
TChain* myChain = new TChain("mySubdirectory/DecayTree");

Accessing the chain

All the trees in the chain can be accessed the same way as it is done with trees, for example:

myChain->Draw("B_M");

to make a histogram with the B-mass.

Note: The first time you access the chain in a ROOT session, it takes a little longer, as the file has to be checked (there is a way around this, but it hasn't worked out yet…)

root/chain.txt · Last modified: 2009/06/22 10:07 by decianm