• No results found

Introduction to ROOT

N/A
N/A
Protected

Academic year: 2021

Share "Introduction to ROOT"

Copied!
23
0
0

Loading.... (view fulltext now)

Full text

(1)
(2)

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

(3)

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

(4)

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

(5)

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

(6)

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.

(7)

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.

(8)

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

(9)

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:

(10)

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.

(11)

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

(12)

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

(13)

.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

(14)

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

(15)

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.

(16)

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

(17)

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

(18)

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

(19)

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

(20)

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

(21)

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

(22)

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

(23)

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

References

Related documents

amount of contrast. If people are present they should be in brightly coloured clothes, preferably red or a very bright blue: both these colours lift the photo and give a good

Accounting considerations ► Captive Reinsurers should not be used to avoid statutory accounting rules NAIC t f t k f t d l ibl l ti f i d d d i. ► NAIC to form new task force to

In case of early uplift of Asia Miles Time Deposit, the Bank will at its sole discretion either forfeit the relevant offers (including the Asia Miles entitlement)

Financial instruments include cash and cash equivalents, student receivables, other accounts receivable, student loans, beneficial interests and contributions receivable,

Moreover, the correlation analysis of SNARE genetic polymorphism with metabolic biochemical risk factors for IHD evidenced the presence of a significant higher level of TyG index in

F d l ki t t t i l d ith t li it ti t t t di th ’ l l Forward-looking statements include without limitation, statements regarding the company’s plans, goal or objectives and

Place fully cooked chicken from warm plate back into skillet for 2-3 minutes spooning sauce over chicken to reheat.

Introduction about your account has the gm supervisors inform the form is mr for you i to obliged, food program by publishing company obliged to improve your language which i am