Top Banner
ROOT for beginners First Day Discovering the graphical environment
78

ROOT for Beginners Day1

Nov 07, 2014

Download

Documents

xzenislevx

ROOT Tutorial
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: ROOT for Beginners Day1

ROOT for beginners

First DayDiscovering the

graphical environment

Page 2: ROOT for Beginners Day1

Welcome to ROOT !Today's menu:

We present a guided tour ofbasic use of ROOT in order toplot spectra and make prettypictures ! For further information, you

should consult the "User'sGuide" at http://root.cern.ch

Handling ROOT filesPlotting 1-D spectraHandling canvases

Decorating a figureFitting a 1-D spectrum

Operations on 2-D spectraSaving figures

Page 3: ROOT for Beginners Day1

Handling ROOT files

Page 4: ROOT for Beginners Day1

TBrowser – the ROOT navigator• You just need to know one command in order to

start the ROOT file/spectra browser :root [0] new TBrowser

Or you could do:TBrowser totoorTBrowser *tata = new TBrowser

Explanations tomorrow (Day 2)!

http://caeinfo.in2p3.fr/root/Formation/en/Day1/hsimple.root

Page 5: ROOT for Beginners Day1

Open a ROOT file withTBrowser

• In the File menu of TBrowser, select"Open…"

• Select a file in the dialogue box whichappears:

1. Select thefile

Page 6: ROOT for Beginners Day1

Open a ROOT file withTBrowser

2. Click"Open"

• In the File menu of TBrowser, select"Open…"

• Select a file in the dialogue box whichappears:

Page 7: ROOT for Beginners Day1

Looking at ROOT file contents

• The file has been added to the list of open ROOTfiles - to see it, you have to display the list

1. Double clickon ROOTFiles

Page 8: ROOT for Beginners Day1

Looking at ROOT file contents

• Next click on the file to see its contents:

2. Click the file

Page 9: ROOT for Beginners Day1

Looking at ROOT file contents

• You see (if you choose the right options) alist of spectra with their titles

3. Choose option"detailed list"

Page 10: ROOT for Beginners Day1

Looking at ROOT file contents

• Icons represent the different types of spectra:– profile, 1-D histogram, 2-D histogram, N-tuple…

Page 11: ROOT for Beginners Day1

Plotting spectra

First of all, 1-D spectra

Page 12: ROOT for Beginners Day1

Plotting a spectrum

• To plot a 1-D histogram, nothing could besimpler: double-click it!

1. Double-clickhistogram "hpx"

Page 13: ROOT for Beginners Day1

Discovering the canvas(TCanvas)

• A new window appears - the canvas

Page 14: ROOT for Beginners Day1

The canvas objects• This canvas contains many objects which

we can manipulate:

Spectrumtitle

Statisticsbox withname ofhistogram

Displayframe

"Y" axis

"X" axis

The histogram

Canvas

Page 15: ROOT for Beginners Day1

What is this object ?• To see the identity of every object the

mouse passes over, activate the "EventStatus" bar in the "View" menu :

The bar appears belowthe canvas:

Object title

Objectname

Mouse positionin pixel units(0,0)=top leftcorner

Position in"spectrum"

units+ bin contents

& partial integralfor spectra

Page 16: ROOT for Beginners Day1

What is this object ?• Or, you can

"right-click" onan object andaccess itscontext menu:

Right-click onhistogram"hpx":

Object type (class)::object name

Page 17: ROOT for Beginners Day1

The canvas objects (again)• So we can identify the type (class) of every

object used in the canvas:

Spectrumtitle(TPaveText)

Statistics boxwith name ofhistogram(TPaveStats)

Displayframe(TFrame)

"Y" axis(TAxis)

"X" axis (TAxis)

Histogram(TH1F)

The canvas(TCanvas)

Page 18: ROOT for Beginners Day1

Manipulating objects• Use the mouse to move and resize objects…

With the left buttonof the mouse you canreposition andredimension allobjects in the canvas

Page 19: ROOT for Beginners Day1

Activate the canvas editor• To change colours, line widths, etc. we use

the canvas editor

Activate theeditor by selecting"Editor" in the"View" menu

Page 20: ROOT for Beginners Day1

Canvas editor• The editor appears to the left of the canvas• It displays/modifies the characteristics of the last

object selected with the mouse (careful!)Name & type (class)of last-clickedobject

E.g. Tick here tomake all spectrascales on this canvaslogarithmic

Page 21: ROOT for Beginners Day1

Canvas editor

Like this !

• The editor appears to the left of the canvas• It displays/modifies the characteristics of the last

object selected with the mouse (careful!)

Page 22: ROOT for Beginners Day1

Changing the look of a spectrum

1. Check you haveselected the rightobject

• or "the art of clicking in the right place at the right time"…

Page 23: ROOT for Beginners Day1

Changing the look of a spectrum

2. Click the line-colour box tothe palette

• or "the art of clicking in the right place at the right time"…

Page 24: ROOT for Beginners Day1

Changing the look of a spectrum

3. Choose a fillstyle…

• or "the art of clicking in the right place at the right time"…

Page 25: ROOT for Beginners Day1

Changing the look of a spectrum

4. …and a colour inorder to activate it

• or "the art of clicking in the right place at the right time"…

Page 26: ROOT for Beginners Day1

Changing the look of a spectrum

5. And why notchange the titlewhile we're at it ?

• or "the art of clicking in the right place at the right time"…

Page 27: ROOT for Beginners Day1

Changing the look of a spectrum

…as well as therange of displayedaxis values

On the second tabyou can change thebinning…

• or "the art of clicking in the right place at the right time"…

Page 28: ROOT for Beginners Day1

Handling the canvas*

*without smudging the artwork

Page 29: ROOT for Beginners Day1

Canvas manipulation• If you want a new canvas:

Using an existingone…

Using the browser…WARNING !Double-click on aspectrum and it will bedrawn on the activecanvas, replacing anyprevious content

Page 30: ROOT for Beginners Day1

Canvas manipulation• To wipe the canvas clean:

Wipe only the active(sub-)pad…

Wipe the WHOLEcanvas (careful!)

Page 31: ROOT for Beginners Day1

Manipulating the canvas• To refresh the canvas display:

Sometimes, the resultof a modification is notvisible straight away.

To force an update of allthe objects on the canvas,option "Refresh" can help*

*(and reduce stress levelsand anxiety…)

Page 32: ROOT for Beginners Day1

Manipulating the canvas• Some useful options:

In the "Options" menu ofthe canvas we also controlwhether or not to show :

statistics boxes

histogram title

fit parameters

Page 33: ROOT for Beginners Day1

Manipulating the canvas• Dividing the canvas to display several

spectra at once:

Open the context menu ofthe canvas (right-click onthe canvas)

Select "Divide"

Page 34: ROOT for Beginners Day1

Manipulating the canvas

Number of columns

Number of rows

Margins between pads

Pad colour

Fill in the form,e.g. to have 2x2 pads:

And click "OK"

• Dividing the canvas to display severalspectra at once:

Page 35: ROOT for Beginners Day1

Next, choose the padwhere you want to displayyour spectrum(click with middle button)

WARNING!The first sub-pad is notautomatically selected

Manipulating the canvas• Dividing the canvas to display several

spectra at once:

Page 36: ROOT for Beginners Day1

Exercise

Page 37: ROOT for Beginners Day1

Decorating a figure

Making pretty pictures

Page 38: ROOT for Beginners Day1

Adding objects to the canvas

• Open the toolbar

Select "Toolbar" in the"View" menu

Page 39: ROOT for Beginners Day1

Adding objects to the canvas

• Open the toolbar

With the buttons we candraw all sorts ofgraphical objects on thecanvas…

Page 40: ROOT for Beginners Day1

Adding objects to the canvas

• Open the toolbar

…arc/circle, line,arrow, diamond, ellipse,rectangle, …

Page 41: ROOT for Beginners Day1

Adding object to the canvas

• Open the toolbar

…polyline, "curly line","curly arc", …

Page 42: ROOT for Beginners Day1

Adding objects to the canvas

• Open the toolbar

…marker, closed contour(graphical cut selection- Day 4!)

Page 43: ROOT for Beginners Day1

Add a pad to the canvas

• Spectra within spectra within…

Why add a pad ?

=> Easy way to have an'insert' showing e.g. azoom

Pad = mini-canvas insidea canvas (or a pad… etc.etc.)

Page 44: ROOT for Beginners Day1

Adding a pad

• Spectra within spectra within…

Draw the pad, thenclick on it with themiddle button to makeit active(yellow border)*

*(true for all pads/canvases)

Page 45: ROOT for Beginners Day1

Adding a pad

• Spectra within spectra within…

Then the next spectrumwe display will be drawnin the active (yellow)pad*

*(this is always true,even with severalwindows)

Page 46: ROOT for Beginners Day1

Adding text• To make the figure self-explanatory, add a

legend…

Several choices areavailable for addingtext, do you want justtext ('L' button)* ortext in a box ?

*(it's 'L' for 'LaTeX')

Page 47: ROOT for Beginners Day1

Adding text• …using LaTeX (well, almost)

Example of a'TPaveLabel'

Raw text entered:-4#leq p_{x}#leq 4

To change font, size,colour of text, use thecanvas editor

Page 48: ROOT for Beginners Day1

Exercise

Tip:it's the 2-Dspectrum'hpxpy' drawnwith option"lego" (use the'Options' drop-down menu inthe browser)

Page 49: ROOT for Beginners Day1

Fitting a 1-D spectrum

Page 50: ROOT for Beginners Day1

Fits

• Simple fitting can easily be done using thegraphical interface

Draw spectrum'hpx' and open itscontext menu

Select "FitPanel"

Page 51: ROOT for Beginners Day1

Fits

Choose a function:

polN = Nth order polynomial

user = user-defined function(Day 3)

• Simple fitting can easily be done using thegraphical interface

Page 52: ROOT for Beginners Day1

Fits

Change the range of the fit

• Simple fitting can easily be done using thegraphical interface

Page 53: ROOT for Beginners Day1

Fits

Click 'Fit' and the fitwill be performed, theresult appears in theactive pad/canvas(unless you choose option"N")

To see the fitparameters :menu "Options","Fit Parameters"

• Simple fitting can easily be done using thegraphical interface

Page 54: ROOT for Beginners Day1

Exercise

Page 55: ROOT for Beginners Day1

Working with 2-D spectra

Page 56: ROOT for Beginners Day1

Displaying 2-D spectra

• Several options are available for displaying2-D histograms:

Divide a new canvas in 4.In the browser,double-click the spectrum"hpxpy" of file"hsimple.root"

By default, a "scatter-plot"is drawn

Not very nice (butsometimes useful)…

Page 57: ROOT for Beginners Day1

Displaying 2-D spectra

The "Option" drop-down menu of thebrowser can be used to choose adisplay option: "box", "lego", "colz" *

*Actually, there aremore of them -"surf", "lego2","arrow"…

• Several options are available for displaying2-D histograms:

Page 58: ROOT for Beginners Day1

An instructive little workedexample

• Let's use our 2x2 canvas & the browser todisplay the 2-D histo "hpxpy" with 4different plotting options:

Can you do it using whatyou have learned so far ?

Page 59: ROOT for Beginners Day1

An instructive little workedexample

• Can't get the same spectrum to appear in 2pads at the same time ?

Look at the spectrum list inthe browser.

Does something seem alittle strange ?

Why does 'hpxpy' appeartwice in the list ? *

(Maybe it's not the only one)*You might need toupdate the browser:"View"->"Refresh"

Page 60: ROOT for Beginners Day1

An instructive little workedexample

Names ending in ";1" or ";N"(N>=1) * are the objects inthe file (on disk)

They cannot be modified(we opened the file in "ReadOnly" mode).

*the 'N' is a versionor 'cycle' number

• Can't get the same spectrum to appear in 2pads at the same time ?

Page 61: ROOT for Beginners Day1

An instructive little workedexample

Names without ";" are memory-resident copies of the spectra:these we can modify.

A new copy is made every timeyou double-click a disk-residentobject.

The previous copy is destroyed !

• Can't get the same spectrum to appear in 2pads at the same time ?

Page 62: ROOT for Beginners Day1

An instructive little workedexample

• Disk-resident vs. memory-resident objects

So to get the right result,you have to make sure to alwaysclick on 'hpxpy' (copy inmemory) and not 'hpxpy;1'(disk-resident).

To remove thestatistics box, usethe 'Options' menu

Page 63: ROOT for Beginners Day1

An instructive little workedexample

• Tip: nice colours if you can get them…

With option 'col'/'colz', thedefault colours are not veryattractive.

This will make a greatimprovement:root [0] gStyle->SetPalette(1)

Then update the canvas(menu "Options"->"Refresh")or click on the histogram.

Page 64: ROOT for Beginners Day1

Operations on 2-D spectra• It's easy to generate projections or profile

histograms* from 2-D spectra

*i.e. plot the mean ands.d. of one of the twovariables versus the other

Page 65: ROOT for Beginners Day1

Right-click to open thecontext menu

Then select e.g. ProjectionX

• It's easy to generate projections or profilehistograms from 2-D spectra

Operations on 2-D spectra

Page 66: ROOT for Beginners Day1

You can give a name forthe new projection.

By default (if you leave"_px") the name will be"hpxpy_px".

• It's easy to generate projections or profilehistograms from 2-D spectra

Operations on 2-D spectra

Page 67: ROOT for Beginners Day1

You can limit the rangeof bins included in theprojection.

By default, as here, allbins are included.

• It's easy to generate projections or profilehistograms from 2-D spectra

Operations on 2-D spectra

Page 68: ROOT for Beginners Day1

Options:"d" - plot in active canvas/pad"e" - calculate errors"[cut]" - use named graphicalcut to select bins (Day 4!)

• It's easy to generate projections or profilehistograms from 2-D spectra

Operations on 2-D spectra

Page 69: ROOT for Beginners Day1

By default, the projectionis not displayed, but shouldbe present in the browser(after a "Refresh")

• It's easy to generate projections or profilehistograms from 2-D spectra

Operations on 2-D spectra

Page 70: ROOT for Beginners Day1

Exercise

Page 71: ROOT for Beginners Day1

Saving your figures

It'd be a pity to lose everything…

Page 72: ROOT for Beginners Day1

Saving a masterpiece• Before saving, we'll remove the yellow border of the

active canvas - otherwise it'll be in the figure

In the canvas' contextmenu selectSetBorderModechange the value:"0" = no border

Page 73: ROOT for Beginners Day1

Saving a masterpiece

• Open the menu "File", sub-menu "Save"

You can save an image ofyour figure in many popularformats (PS, PDF, GIF, JPG)with the name c1.xxx bydefault*

*With "Save As…" you can even choose the name you want

Page 74: ROOT for Beginners Day1

Saving a masterpiece

• What if I want to change the figure later ?

Two choices:create some code ('c1.C')orsave the objects ('c1.root')

Page 75: ROOT for Beginners Day1

Save the objects ???• By choosing ".root" in menu "Save", a file

'c1.root' is created.• In order to display the image later, you need to

open this file, e.g. with the browser:

It seems the file only containsone object, c1.But double-click it and…

Page 76: ROOT for Beginners Day1

Save the objects ???

…the figure is displayed.

In fact, a canvas is a sort of list ofobjects to display on the screen.The command "Draw" just adds anobject to this list…

• By choosing ".root" in menu "Save", a file'c1.root' is created.

• In order to display the image later, you need toopen this file, e.g. with the browser:

Page 77: ROOT for Beginners Day1

Create some code ?• By choosing "c1.C" in the menu, a file is

created which contains all the (C++)instructions necessary to recreate our figure

You can look atthe result in anytext editor…

Page 78: ROOT for Beginners Day1

Create some code ?• Tomorrow we will see how to use this kind

of code to create analysis scripts, etc.

Now this won'thurt a bit…