Introduction to ROOT
What is ROOT?
ROOT is an open-source scientific data analysis framework developed at CERN (the European Organization for Nuclear Research). It is primarily written in C++ and is widely used in experimental high-energy and nuclear physics.
ROOT provides a collection of tools and libraries for storing, processing, analysing and visualising large amounts of scientific data.
Although ROOT was originally developed for particle physics, its functionality can also be applied to other scientific fields that require numerical and statistical data analysis.
ROOT is a framework, not a programming language
ROOT extends the functionality of C++ by providing specialised classes, mathematical functions, statistical methods and data structures designed for scientific computing.
ROOT can also be accessed from Python through PyROOT.
Why do we use ROOT?
Modern particle physics experiments produce enormous amounts of data. Each collision event may contain information about hundreds or thousands of detected particles.
Analysing such datasets requires tools that can efficiently:
- Store and retrieve large datasets.
- Organise event-level and particle-level information.
- Select observations according to physical criteria.
- Calculate physical and statistical quantities.
- Construct and manipulate histograms.
- Fit mathematical models to experimental data.
- Visualise and interpret scientific results.
ROOT provides these capabilities within a unified framework.
The main components of ROOT
ROOT consists of several interconnected components, each designed for a particular aspect of scientific data analysis.
| Component | Purpose | Common classes |
|---|---|---|
| Data storage | Reading and writing scientific data | TFile |
| Data structures | Organising large datasets | TTree, TBranch |
| Histograms | Representing numerical distributions | TH1D, TH2D |
| Visualisation | Displaying scientific results | TCanvas, TGraph |
| Mathematical functions | Evaluating mathematical expressions | TMath, TF1 |
| Statistical analysis | Fitting and analysing distributions | TF1, TFitResult |
| Physics utilities | Representing physical vectors | TVector3, TLorentzVector |
| Random numbers | Generating simulated observations | TRandom3 |
These classes will be introduced gradually throughout this guide.
Your first look at ROOT
The following example demonstrates how a one-dimensional histogram can be created, filled and displayed using ROOT.
#include <TH1D.h>
#include <TCanvas.h>
void introduction()
{
TH1D* hist = new TH1D(
"h_example",
"Example histogram;x;Counts",
10, 0.0, 10.0
);
hist->Fill(2.5);
hist->Fill(4.2);
hist->Fill(4.5);
hist->Fill(7.1);
TCanvas* canvas = new TCanvas(
"c1", "Example", 800, 600
);
hist->Draw();
}
Do not worry if some parts of the code are unfamiliar. Each component will be explained in detail in the following chapters.
What happens in this example?
introduction()function creates, fills and plot a histogramTH1Dobject represents a one-dimensional histogram.Fill()function adds an observation to the histogram.TCanvasobject provides an area for displaying graphical objects.Draw()function displays the histogram on the canvas.
ROOT and C++
ROOT is an object-oriented framework. Its functionality is primarily organised into classes.
A class defines the properties and operations associated with a particular type of object.
For example, the TH1D class defines the structure and behaviour
of a one-dimensional histogram.
TH1D* hist = new TH1D("h", "Histogram", 10, 0, 10);
Here, a histogram object is created using the constructor
of the TH1D class.
The methods associated with this object can subsequently be accessed using the arrow operator:
hist->Fill(3.5);
hist->Draw();