Introductory School to Terascale Physics 2012 - DESY, 5-9 March 2012
ROOT tutorial
Overview
Tutorial
ROOT is a C++ based framework for data analysis that is widely used in High Energy Physics. This tutorial aims to help getting started with ROOT and will introduce ROOT's basic features (histograms, functions, graphs) as well as more complex objects (files, trees). A number of further references and online tutorials are compiled to guide the user during the first steps throughout the rest of the school.
Further references, additional material and a collection of tutorials can be found here.
Introductory slides for this tutorial can be found here.
Prerequisites
Some basic knowledge of C++ is required for the successful completion of the tutorial and the work with ROOT. A short overview and reminder on the basics of C++ can be found in the references.
Structure
The tutorial is split into several exercises:
Steps marked with * are advanced exercises and can be solved if the time allows. A proposal for homework is also given.
Exercises
In the first exercise you open an interactive ROOT session and try some useful objects and methods.
- Open an interactive root session.
- Define a variable x of type double and set it to π/2.
- Calculate sin2(x).
- Create the Lorentz vector of a particle with E=125.9GeV, px=-29.4GeV, py=-26.2GeV, pz=119.6GeV.
- Create a second Lorentz vector of a particle with E=167.8GeV, η=1.82, φ=0.91, pT=53.0GeV.
- Create a third LorentzVector which is the sum of the other two. Calculate the invariant mass. What kind of reaction could have happend?
- * Boost the particle into it's rest frame and calculate the energy. Hint: remember that β=p/E.
- Quit root.
Classes and methods
You will need the following classes and methods for the exercise which we have already seen:
This exercise shows you how to create a histogram and how to work with it. Write a small ROOT macro for the following purposes:
- Create a histogram with 10 bins ranging from 0. to 100. with no title and x-axis label "x"
- Fill the histogram with the following numbers: 11.3, 25.4, 18.1
- Fill the histogram with the square of all integers from 0. to 9. (Hint: A simple loop will save you from typing several lines of code)
- Draw the histogram.
- Calculate the mean value and the standard deviation (σ).
- Calculate the integral of the histogram. Which value did you expect?
- * Identify the bin with the maximum number of entries.
- * Calculate the maximum bin content.
- Set the y-axis label to "entries".
- Set the line color of the histogram to red.
Classes and methods
You will need the following classes and methods for the exercise:
This exercise shows you how to use different canvases and draw histograms into them. Additionally you will add a legend to a canvas.
- Create two histograms with 10 bins ranging from -5. to 5. with no title and two different names.
- Fill the first histogram with a Gaussian distribution by using
hist1->FillRandom("gaus", 500);
- Fill the second histogram with a second order polynomial distribution by using
hist2->FillRandom("pol2", 500);
- Create a new TCanvas with name "c1" and title "gauss" and draw the first histogram.
- Create a new TCanvas with name "c2" and title "poly" and draw the second histogram.
- Set the line color of the first histogram to red (kRed) and the second to blue (kBlue).
- Clone both histograms with new names.
- Scale both cloned histograms by the inverse of their respective integral, i.e. normalise them to unit area.
- Create a third canvas and draw the first cloned histogram. Then draw the second cloned histogram with option "same" to have both histograms in the same plot.
- * Create a legend at position (0.16, 0.63, 0.45, 0.91) and add entries for both histograms to it. Draw the legend.
- * Save the third canvas as a PDF file and open the PDF.
- Save the third canvas as a ROOT file (gaussian-polynomial.root).
Classes and methods
You will need the following classes and methods for the exercise:
A first example on how to use trees. Let's do this exercise interactively at the ROOT prompt.
-
Open the file ntu_8843.root (available for download here).
-
Open the tree "ntu1". It is listed as "ntu1;1" in the ROOT browser, showing its version number 1.
-
Draw the distribution of ene.
-
Draw the distribution ene vs. kpx.
-
Draw the distribution ene vs. kpx for those jets which fulfill y > 0.
-
Draw the distribution sqrt(kpx*kpx+kpy*kpy).
-
* Draw the distribution ene vs. kpz with histogram style "colz" (colored bins with z-axis shown)
instead of the "scatter plot" used by default.
Classes and methods
You will need the following classes and methods for the exercise:
This exercise shows how to use a one dimensional function.
-
Create a one dimensional function f(x)=sin(x)/x+a in the region 0 - 10.
-
Set the parameter a=5.
-
Draw the function.
-
Calculate the function at x = 5.
-
Calculate the integral of the function between 0 and 3.
-
* Calculate the derivative of the function at x = 7.
-
* Set the number of points used to draw the function to 1000. Hint: the number is denoted by Npx.
Classes and methods
You will need the following classes and methods for the exercise:
This exercise shows how to use graphs and errors on graphs.
-
Create a graph with symmetric errors and 5 points.
-
Set the following points: (1.0, 2.1), (2.0, 2.9), (3.0, 4.05), (4.0, 5.2), (5.0, 5.95)
-
Set the errors on x to 0.0 and the errors on y to 0.1.
-
Draw the graph including the axes and error bars.
-
Create a one dimensional function f(x)=mx + b and fit it to the graph.
-
Obtain the two parameters a and b from the function and their estimated uncertainties.
-
* Take again the file gaussian-polynomial.root you created
before and try to fit a Gaussian distribution to the histogram using the FitPanel (right-click on
the histogram to open its context menu and select "FitPanel").
Classes and methods
You will need the following classes and methods for the exercise:
-
Finish the parts which you did not have time to go through during the tutorial.
-
Play around with the histogram decoration using the editor in the menu, e.g., set axis titles, color the graphs, etc.
References
Documentation on ROOT can be found here:
Other tutorials can be found here:
Other useful links and material:
Sebastian Fleischmann