Physics 564 - Introductory Particle Physics
Using the ROOT class libraries
The ROOT software package is frequently
used to analyse and present results in high energy physics. We will use it
to create and display histograms, generate random numbers and fit
distributions. In what follows, it is assumed that you have been able to
log into amdahl.physics.purdue.edu and can pop up X-windows on your
screen.
Getting the examples
First, if you have not already done so, create a directory in which to
store your work:
jones105@amdahl:~$ mkdir phys564
jones105@amdahl:~$ cd phys564
Next, copy the examples from my directory into yours:
jones105@amdahl:~/phys564$ cp -r ~jones105/phys564/examples .
jones105@amdahl:~/phys564$ cd examples
jones105@amdahl:~/phys564/examples$ ls -l
total 330
-rw-r--r-- 1 jones105 phys 926 Sep 1 09:51 DrawHistograms.C
-rw-r--r-- 1 jones105 phys 699 Sep 1 09:54 DrawRandom.C
-rw-r--r-- 1 jones105 phys 287 Sep 1 09:38 Makefile
-rwxr-xr-x 1 jones105 phys 138751 Sep 1 09:49 histograms
-rw-r--r-- 1 jones105 phys 2375 Sep 1 09:48 histograms.cc
-rw-r--r-- 1 jones105 phys 7215 Sep 1 09:49 histograms.root
-rwxr-xr-x 1 jones105 phys 136635 Sep 1 09:47 random
-rw-r--r-- 1 jones105 phys 1452 Sep 1 09:47 random.cc
-rw-r--r-- 1 jones105 phys 20802 Sep 1 09:54 random.ps
-rw-r--r-- 1 jones105 phys 4934 Sep 1 09:47 random.root
jones105@amdahl:~/phys564/examples$
Compiling the examples
The file called Makefile is a convenient way to compile the programs
histograms.cc and random.cc. When you write your own
programs you can keep adding them to your Makefile. To compile
the programs you just do this:
jones105@amdahl:~/phys564/examples$ rm histograms random
jones105@amdahl:~/phys564/examples$ make histograms
g++ -g -o histograms histograms.cc `root-config --cflags` `root-config --libs`
jones105@amdahl:~/phys564/examples$ make random
g++ -g -o random random.cc `root-config --cflags` `root-config --libs`
jones105@amdahl:~/phys564/examples$
Running the examples
Once you have compiled the examples you can run them:
jones105@amdahl:~/phys564/examples$ ./random
Generating event 0/1000000
Generating event 100000/1000000
Generating event 200000/1000000
Generating event 300000/1000000
Generating event 400000/1000000
Generating event 500000/1000000
Generating event 600000/1000000
Generating event 700000/1000000
Generating event 800000/1000000
Generating event 900000/1000000
jones105@amdahl:~/phys564/examples$ ./histograms
Generating event 0/1000000
Generating event 100000/1000000
Generating event 200000/1000000
Generating event 300000/1000000
Generating event 400000/1000000
Generating event 500000/1000000
Generating event 600000/1000000
Generating event 700000/1000000
Generating event 800000/1000000
Generating event 900000/1000000
Number of events = 1000000
Pi = 3.14388 +- 0.0035462
Deviation from true value = 0.00228335
jones105@amdahl:~/phys564/examples$
Looking at the histograms
These programs create and fill histograms that are stored in the files
histograms.root and random.root. To display these results,
you can invoke an interactive ROOT session
and run the scripts DrawHistograms.C and DrawRandom.C.
These read the files created by the programs and display the histograms:
jones105@amdahl:~/phys564/examples$ root
*******************************************
* *
* W E L C O M E to R O O T *
* *
* Version 4.00/04 28 January 2005 *
* *
* You are welcome to visit our Web site *
* http://root.cern.ch *
* *
*******************************************
FreeType Engine v2.1.3 used to render TrueType fonts.
Compiled for linuxdeb with thread support.
CINT/ROOT C/C++ Interpreter version 5.15.133, Apr 18 2004
Type ? for help. Commands must be C++ statements.
Enclose multiple statements between { }.
root [0] .x DrawRandom.C
Info in <TCanvas::Print>: ps file random.ps has been created
root [1] .x DrawHistograms.C
Info in <TCanvas::Print>: ps file histograms.ps has been created
root [2]
This should create plots that look something like these:
The examples are well commented and you should look at the programs and the
scripts to see what each line does. These make use of several commonly
used ROOT classes. There is online documentation on the ROOT web pages
for these. Here are some direct links to the most commonly used classes:
- TFile. . . Used to store histograms in a file
- TRandom. . . Generates random numbers
- TH1. . . One-dimensional histograms
There are also tutorials,
a user's guide
and HOWTO's available on
the ROOT web page.