Last time and todayy
Last time we took a quick look at LATEX
Today we will start the second half of the
course course
ROOT
A basic introduction.
We start with really using ROOT next time when
What is ROOT?
ROOT i d t l i k
ROOT is a data analysis package
It contains many useful tools
Data analysisy Histograms Fitting Plotting Mathematical libraries D t t Data storage Data formats
ROOT and C++
ROOT i itt i C
ROOT is written in C++
It uses fully object oriented code.
ROOT can be though of as a collection of g
libraries in C++
These can be used in your C++ code to do y
analysis tasks.
ROOT input is in C++
It uses a C++ interpreter call CINT It uses a C interpreter call CINT
Long long ago in a ………
g
g g
Before ROOT there came PAW
This is part of CernLib
This did a similar jobThis did a similar job
Data Analysis Data Formats Data Storage
It was written in FORTRAN
Root is the extension of PAW into the object
orientated world and is much more powerful.
o e a ed o d a d s uc o e po e u
Documentation
As with everything in this course there is
good documentation on the WEB good documentation on the WEB.
In the case of ROOT there is one specific
place place.
http://root.cern.ch
Thi i th l t d l d t f
This is the place to download root from
should you need it.
There is lots of documentation and examples. I recommend you work through the tutorials y g
that cover the material covered in these lectures.
Example root files.
p
For this section of the course I have prepared
some sample root files.
These can be found in …..
There are the following files.
atlas_z0.root Z0 events in ATLAS.
Starting with root
g
You need to have the environment variable
ROOTSYS set to the root install directory.
This will typically be /usr/local/rootyp y
But you (or your experiment) may have your own version of
root installed.
You will need to set ROOTSYS accordingly.
You may also need to use LD_LIBRARY_PATH
This tells programs where to look for libraries For vanilla root you shouldn’t need to use this
F d d i ith i t t
For expanded version as with many experiment extra
libraries may need to be specified
Launching and Quiting Root.
g
Q
g
To launch root just type:
$ROOTSYS/bin/root
You may want to add $ROOTSYS/bin to your
path path.
You should see a splash screen appear, and
th t t t i t i l then root start up in your terminal.
To quit use:
Loading a file
g
To load a file you type.
TFile f (“my root tree.root”)TFile f ( my_root_tree.root )
This creates a TFile object called f This creates a TFile object called f.
The object f is attached to the file my_root_tree.root
f i l bj t d th f ll f th
f is a real object and therefore you can use all of the
TFile member functions.
f >Cl () l th fil
f->Close() close the file.
Browsing a file.
g
To easily browse a file we use TBrowser.
TBrowser b
This makes a TBroswer object called bj
Lets now take a quick look at TBrowser in
Lets now take a quick look at TBrowser in
CINT and Macros
CINT is somewhat loose in it’s C++syntax.
You can use either f.Close() or f->Close(). You’ll be better off if you use the correct structure
anyway anyway.
When typing in root you don’t need the ;
A macro is set of CINT instr ctions enclosed
A macro is set of CINT instructions enclosed
in { } at. These are at the start and end of the file
file.
You now need ;
R b C
Run a macro by .x my_macro.C
.rootlogon.C
g
Th fil tl C i h di t b
The file .rootlogon.C in your home directory can be
used to configure root to your liking.
This can be used to set the system to what ever
defaults you want defaults you want.
We can return to these when we know what a few of We can return to these when we know what a few of
these things are.
It works just like any other root macro and uses the
Data Storage in ROOT
g
There are a number of ways to store and
present data in ROOT:
Graphs
A bit like EXCEL: plot x vs yp y Hisograms
Binned data Ntuples
Tables Trees
Ntuples
p
→
Trees
Nt l th t d d f t i
Ntuples were the standard way of storing
data in PAW
Each entry was an “event”
Each event was a collection of variables In paw all floating point.
The same variables for each event. Not generalizable
Not generalizable.
In root you can use a TNtuple class.
A tree is a generalization of an ntuple A tree is a generalization of an ntuple.
Trees, Branches and Leaves
,
A Tree is a collection of branches.
Each branch corresponds to a variables, or
collection of variables.
Generally independent variables on different branches. Like variables (eg position x,y,z) on the same branch.
Using a object such as a TVector3.
The data on the branches are called Leaves These can be floating point, integer …
Or any object (with it’s own member functions) you
Accessing my data inside a Tree.
g y
You need to know how to access the data
inside your tree.
Generally you will loop through the tree in a Generally you will loop through the tree in a
macro.
We will talk about this in a basic way today y y
Loading the root tree
g
First you need to load the file.
You then setup a pointer to the tree in the file p p
and attach it to the tree you want.
This gives you a TTree object This gives you a TTree object.
Load the file into object f
TFile f (“mytree.root”);
TTree *inTree = (TTree*)f.Get(“MyTree”);( ) ( y );
Create a pointer to a TTree object.
Name of the Tree j
Getting to the data.
g
Say the data is in a variable energy and it’s
double precision.
You need to define that variable, and then
point it to the variable in the tree point it to the variable in the tree.
Define the variable
The address of
Double_t energy;
inTree->SetBranchAddress(“energy” &energy);
The address of my variable.
inTree >SetBranchAddress( energy ,&energy);
The name in the tree. Point it to my variable
Looping through the Tree.
p g
g
You can now loop through the Tree You can now loop through the Tree.
Loop index Use TTree member function GetEntries() to get loop limit
for (Int t indx=0;indx<inTree->GetEntries();indx++){
p
GetEntries() to get loop limit
( _ ; (); ){
inTree->GetEntry(indx);
Load the current event.
cout << energy << endl;
} You can now access i bl
TTree::Print and TTree::Scan
Y th P i t th d t i t t th
You can use the Print method to print out the
variables in a tree.
Tree->Print();
This will show each branch and how much data is
t d th
stored there.
The scan method will show the value of the
ifi d i bl f h t specified variables for each event.
Tree->Scan(“var1:var2:var3”);
Useful if you want to see what’s going on event by
TTree::Draw( )
( )
O h i t t t
Once you have a pointer to your tree you can
also directly plot variables.
inTree->Draw(“var1”);( );
inTree->Draw(“var1:var2”);
inTree->Draw(“var1” ”var2>10”); inTree->Draw( var1 , var2>10 );
inTree->Draw(“var1”,”var2>10”,options);
Th ti f hi t d ’ll
The options are as for histograms and we’ll cover
Exercises
Make sure you can run root.
Load it and quit.
Take a look at the standard root files for the Take a look at the standard root files for the
course with TBrowser to see what type of d t h
data we have.
Try and plot some variables using