You are on page 1of 48

ROOT

and pyROOT (1)



2017,03,25
Outline
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


https://indico.cern.ch/event/395198/attachments/791523/1084984/ROOT_Summer_Student_Tutorial_2015.pdf
Environment and source code
ROOT version: 6.09(lastest), recommend 6.08 or 5.34
Environment: linux (recommend), macos, windows
Download page: https://root.cern.ch/downloading-root
My code is at https://www.dropbox.com/home/root_basic
or you can download as below
wget http://www-he.scphys.kyoto-u.ac.jp/member/khuang/html/code.zip
Sorry, or you can use usb disk to copy from me.
Introduction of ROOT
PyROOT
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
list.
example of list

TMath.Sqrt(x):

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

Hint:
TH1D(name, hist title;x-axis title;y-axis title, n_bins, min, max)
TRandom.Poisson(mean)
.SetFillColor(..)
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


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

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)
Run maketree.py
Open the file in the TBrowser (in interactive interface of python)
Create plots clicking on the leaves
Read contents in the tree
tree_dump1.py or try tree_dump2.py
Read contents in the tree
or try tree_dump2.py
Other resources
official course: https://root.cern.ch/courses

You might also like