Sie sind auf Seite 1von 48


and pyROOT (1)

Introduction of ROOT
Meet the Histogram:
Meet the Tree:
Try to fit a histogram with Gaussian function

I use this material from CERN summer school
Environment and source code
ROOT version: 6.09(lastest), recommend 6.08 or 5.34
Environment: linux (recommend), macos, windows
Download page:
My code is at
or you can download as below
Sorry, or you can use usb disk to copy from me.
Introduction of ROOT
Todays target
Start from PyROOT
PYTHON interactive prompt can be used as an
advanced calculator! ROOT has advanced
mathematical functions, which live in the
TMath namespace.

ps. ROOT also has an interactive prompt. just type root and enter it!!! (.q to quit)
Lets step forward for
variables of single value and example of single value
example of list


TMath.Power(x,y): #
I prepared a pyROOT version of
this example. (
Please use plot that is from h1.Draw(pe)
Try to use the TF1 to fit.
Here, python file (.py) or interactive python interface

TH1D(name, hist title;x-axis title;y-axis title, n_bins, min, max)
TH2F(name, title,n_xbin, xmin,xmax,n_ybin,ymin,ymax)
Save the histogram that you created!!
Open a TFile to save into file.
After opening file,
use Write() function to save what you want
Close the TFile

CREATE: create a new file

READ: read a existed file
RECREATE: create a file again regardless if the file is existed or not
Read the histogram that you saved in root file!!

Open the TFile that is saving a

After opening file, ls() to look
whats inside
Use Get(name) function to obtain
the histogram

Try in Draw()
1. add selection:y>3.0, z<2
2. draw x vs y (2D plot)
3. draw x vs z (2D plot)
option (C++ version)
Open the file in the TBrowser (in interactive interface of python)
Create plots clicking on the leaves
Read contents in the tree or try
Read contents in the tree
or try
Other resources
official course: