Skip to content
Christophe Delaere edited this page Nov 13, 2015 · 2 revisions

ROOT is a modular scientific software framework. It provides all the functionalities needed to deal with big data processing, statistical analysis, visualization and storage. It is mainly written in C++ but well integrated with other languages such as Python and R. (from the ROOT website)

ROOT are be the main tool used in parts two and three of this lab, and you are encouraged to get familiar with it. Its use is ubiquitous in particle physics, as it is at the core of almost all the experimental analysis frameworks. Here are some basic keys to start using it.

ROOT is simply started by issuing the ROOT command from the directory where you wand to work. The environment has to be set beforehand, in our case by using the cmsenv script in the proper release directory:

cd CMSSW_7_1_1/src
cmsenv
cd ~/analysis
root

You can also directly open a root file or execute a script by passing it to the command line. Passing the -l option removes the splash popup:

root -l  #don't show the splash
root myfile.root  #opens the file directly
root myscript.C  #executes myscript.C directly

Once started, ROOT presents you an interactive shell, where you can issue commands.

We will use ROOT to produce histograms from ntuples (called trees in ROOT), and to do various kinds of fits. A ntuple is a data structure very similar to a table. For each event (row) it contains a set of valyes (columns). One column can also contain a vector of values, and the type of each column (called branch in ROOT) can be different (int, float, char, even custom types).

Here is a typical session:

[cms-opendata@localhost analysis]$ root -l delpheAnalysisZ.root
root [0]
Attaching file delpheAnalysisZ.root as _file0...
root [1] new TBrowser
(class TBrowser*)0xc9b270
root [2] .ls
TFile**         delpheAnalysisZ.root
 TFile*         delpheAnalysisZ.root
  OBJ: TTree    WeakBosonsAnalysis      WeakBosonsAnalysis : 0 at: 0x1812050
  OBJ: TTree    WeakBosonsAnalysis      WeakBosonsAnalysis : 0 at: 0x1900650
  KEY: TTree    WeakBosonsAnalysis;1    WeakBosonsAnalysis
root [3] WeakBosonsAnalysis->Scan()
***********************************************************************************************************************
*    Row   * Instance *    nMuons *   MuonsPt *  MuonsEta *  MuonsPhi * nElectron * Electrons * Electrons * Electrons *
***********************************************************************************************************************
*        0 *        0 *         0 *           *           *           *         1 * 15.572341 * 0.3791305 * -2.803331 *
*        1 *        0 *         0 *           *           *           *         2 * 32.556041 * 2.3843421 * 1.4344033 *
*        1 *        1 *         0 *           *           *           *         2 * 29.342258 * 0.4682755 * -2.499644 *
*        2 *        0 *         0 *           *           *           *         2 * 46.182983 * -0.064993 * -0.630331 *
*        2 *        1 *         0 *           *           *           *         2 * 43.471630 * -0.475959 * 2.2772684 *
*        3 *        0 *         0 *           *           *           *         1 * 13.715698 * -0.248964 * -1.724608 *
*        4 *        0 *         0 *           *           *           *         1 * 35.757526 * -0.108560 * -2.099552 *
*        5 *        0 *         0 *           *           *           *         1 * 11.523519 * -1.868670 * 2.0663385 *
*        6 *        0 *         0 *           *           *           *         2 * 44.405941 * 0.5547180 * -1.455895 *
*        6 *        1 *         0 *           *           *           *         2 * 43.797855 * -0.366821 * 1.8280531 *
*        7 *        0 *         0 *           *           *           *         0 *           *           *           *
*        8 *        0 *         0 *           *           *           *         2 * 22.132816 * -0.105786 * 2.0497729 *
*        8 *        1 *         0 *           *           *           *         2 * 21.133201 * 1.4819486 * -1.283928 *
*        9 *        0 *         0 *           *           *           *         1 * 59.511413 * 1.2132505 * 1.7350055 *
*       10 *        0 *         0 *           *           *           *         2 * 29.598985 * 0.9521472 * -3.116238 *
(...)
Type <CR> to continue or q to quit ==> q    
***********************************************************************************************************************
(Long64_t)25
root [4] new TCanvas
root [5] WeakBosonsAnalysis->Draw("ElectronsPt[0]","nElectrons>=2 && nMuons==0")
root [6] .q

In that example, ROOT is started and one file is opened. A TBrowser is then created, where one can visualize the content of the file and do basic plotting. One then go back to the console and list the content of the file with the .ls command. One sees that the file contains a TTree object, on which we can call the Scan method. This shows the first branches for the first events. We then create a new canvas (a window where to draw), and call the Draw method on the tree, to see the transverse momentum of the first electron, for events where there are at least two electrons but no muon. Finally, we quit ROOT by issuing the .q command.

As already mentioned, commands can either be issued interactively in the console, or assembled in a script (written in C++). Examples of scripts are found in the analysis/examples directory. Many more or less advanced examples can be found on the ROOT website.

In this lab, we do mostly use the following ROOT classes:

Class Use
TFile Manipulate ROOT files (open, create, save, close, ...)
TCanvas Create a window where to draw/plot
TH1F Represents histograms
TF1 Represents functions
TLegend Represents the legend object (optional)
THStack Allows to stack histograms to represent various contributions

Please refer to the ROOT documentation for details on the use of these classes.