Introduction to the ROOT data analysis framework

short blurb

Getting ROOT

The ROOT software package is available for use on the desktop cluster as well as on the Tier3 for MSU ATLAS members. It is also available for download on the ROOT website https://root.cern.ch/.

On the desktop cluster

On the desktop cluster the current recommended ROOT version (5.26/00 64-bit) is configured for use by default. Other versions of ROOT can be run by sourcing the setup script for the particular version located in /cern/root/vX.XX.XX/. For example, to setup ROOT version 5.24/00:

source /cern/root/v5.24.00/rootsetup.sh

Please refrain from setting up your own local ROOT version on the desktop cluster. If there is a particular version you would like to use, please contact

On a personal laptop or computer

On a Mac

...

On Windows 10 using the bash shell

If you do not yet have the bash shell for Windiws 10 installed and configured, follow the instructions at WindowsBashShell

From here the steps are identical to installing it on Linux with only a few extra steps in the beginning.

1. Start by installing a full Ubuntu distrobution, the bash shell includes a very basic distro of ubuntu with only the most essential packages, by installing a full distro, you can ensure that you'll have most of the most common packages that you'll need to do your work. Install this by typing:
sudo apt-get update 
sudo apt-get install ubuntu-desktop
 

2. I recommend this step for normal Linux distrobutions as well, but it is nessacary here, install all required packages for ROOT with the following comand
sudo apt-get install git dpkg-dev cmake g++ gcc binutils libx11-dev libxpm-dev \ libxft-dev libxext-dev 

From here, just follow the instructions below
On Linux

Here we will learn how to install ROOT for Ubuntu or similarly

On the Tier3

A simple macro tutorial

Exercises

Use the following exercises to get acquainted with writing ROOT and C++ code. Discuss your results with mentors and other students.

Exercise 1

For the following exercise you will need to look through the ROOT documentation to figure out how to:
  • create a TCanvas, draw objects on it, and save it as a pdf.
  • use TRandom3 to:
    • generate uniform random numbers between 0 and 10.
    • generate Gaussian random numbers with (Mean = 5 and RMS = 1).
  • create and fill a 1D histogram (TH1, TH1D, TH1F).
  • create a TF1 and fit it to a 1D histogram.

tip Google is your new best friend. If you are trying to figure out how to use a TH1 and what methods are available to it, searching "ROOT TH1" on Google is a great way to start.

  1. You need two separate macros.
    1. In the first macro, generate 10000 Uniform random numbers and fill a histogram with these numbers.
    2. In the second macro, generate 10000 Gaussian random numbers and fill a histogram with these numbers.
    3. For both cases, check if the distributions are as expected. tip To check, you will need to fit the distributions with analytical functions.
  2. Make a new macro.
    1. Generate 10000 random numbers in total (Uniform and Gaussian). The generation of Uniform and Gaussian random numbers should be done randomly (without any order).
    2. The ratio between the Gaussian generated numbers to the Uniform generated numbers should be around 1/10.
    3. Create a new histogram and fill these 10000 random numbers.
  3. Repeat step 2, but do it using two macros. warningDon't overwrite your old macros, just make new files.
    1. In the first macro, generate the random numbers and put them in a text file.
    2. In the second macro, read the numbers from the text file and fill a histogram with them. Save the histogram in a root file.
  4. Read the histogram from the root file created in Step 3. Then, with an analytical function, fit this histogram:
    1. using the Fit method in ROOT.
    2. without using the Fit method in ROOT.

Exercise 2

Now that you have had some practice with ROOT and searching through the ROOT documentation, see if you can figure out what you will need to do on your own.

Part 1

For this part, f(x) is the following function: f(x) = - x*x + 4 (use TGraph or TF1 to draw the function).

  1. Calculate analytically the integral of f(x) for x between -2 and +2.
  2. Calculate numerically the integral of f(x) for x between -2 and +2 using the Monte Carlo method. tipThe integral of f(x) between x=a and x=b is the area S between f(x) and the lines x=a, x=b, and y=0.
    1. Define a rectangle containing the area S.
    2. Generate ("Uniform") random points in the rectangle and check the fraction of points in the area S.
    3. Make a plot with the function f(x) and the generated points.
  3. Calculate the same integral numerically by filling the area S with rectangles.
    1. Use a histogram with a given binning (each bin is a rectangle).
    2. Repeat this step with 3 different binnings.
    3. Make 3 different plots: one for each histogram. On each plot, draw f(x).
  4. Explain/Interpret/Analyze the differences between the different results. (Where are the differences coming from? When will they be equal? Why?)

Part 2

For this part, g(x) is the following function: g(x) = pow(x,-3) for x between 0.1 and 10.1

  1. On the same canvas, draw 2 plots of g(x), one on the left and one on the right. On the left keep g(x) in linear scale (default), on the right set the x and y axis to logarithmic scale.
  2. Calculate the integral of g(x) for x between 0.1 and 10.1 with the Monte Carlo method generating only 1000 points (as you did in Part 1). Draw the points on the plots.
  3. Compare the numerical integral with the analytical integral. Can you find a method that generates a more precise numerical result using only 1000 points?

-- EmilyJohnson - 20 Sep 2016
Topic revision: r8 - 31 Oct 2016, JacobFerguson
 

This site is powered by FoswikiCopyright © by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding Foswiki? Send feedback