12.07.2015 Views

ROOT for beginners - LinkSCEEM

ROOT for beginners - LinkSCEEM

ROOT for beginners - LinkSCEEM

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

<strong>ROOT</strong> <strong>for</strong> <strong>beginners</strong>First DayDiscovering thegraphical environment


Welcome to <strong>ROOT</strong> !Today's menu:Handling <strong>ROOT</strong> filesPlotting 1-D spectraHandling canvasesDecorating a figureFitting a 1-D spectrumOperations on 2-D spectraSaving figuresWe present a guided tour ofbasic use of <strong>ROOT</strong> in order toplot spectra and make prettypictures !For further in<strong>for</strong>mation, youshould consult the "User'sGuide" at http://root.cern.ch


Handling <strong>ROOT</strong> files


TBrowser – the <strong>ROOT</strong> navigator• You just need to know one command in order tostart the <strong>ROOT</strong> file/spectra browser :root [0] new TBrowserOr you could do:TBrowser totoorTBrowser *tata = new TBrowserExplanations tomorrow (Day 2)!http://caeinfo.in2p3.fr/root/Formation/en/Day1/hsimple.root


Open a <strong>ROOT</strong> file withTBrowser• In the File menu of TBrowser, select"Open…"• Select a file in the dialogue box whichappears:1. Select thefile


Open a <strong>ROOT</strong> file withTBrowser• In the File menu of TBrowser, select"Open…"• Select a file in the dialogue box whichappears:2. Click"Open"


Looking at <strong>ROOT</strong> file contents• The file has been added to the list of open <strong>ROOT</strong>files - to see it, you have to display the list1. Double clickon <strong>ROOT</strong>Files


Looking at <strong>ROOT</strong> file contents• Next click on the file to see its contents:2. Click the file


Looking at <strong>ROOT</strong> file contents• You see (if you choose the right options) alist of spectra with their titles3. Choose option"detailed list"


Looking at <strong>ROOT</strong> file contents• Icons represent the different types of spectra:– profile, 1-D histogram, 2-D histogram, N-tuple…


Plotting spectraFirst of all, 1-D spectra


Plotting a spectrum• To plot a 1-D histogram, nothing could besimpler: double-click it!1. Double-clickhistogram "hpx"


Discovering the canvas(TCanvas)• A new window appears - the canvas


The canvas objects• This canvas contains many objects whichwe can manipulate:SpectrumtitleThe histogramStatisticsbox withname ofhistogram"Y" axisDisplayframeCanvas"X" axis


What is this object ?• To see the identity of every object themouse passes over, activate the "EventStatus" bar in the "View" menu :The bar appears belowthe canvas:Object titleObjectnameMouse positionin pixel units(0,0)=top leftcornerPosition in"spectrum"units+ bin contents& partial integral<strong>for</strong> spectra


What is this object ?• Or, you can"right-click" onan object andaccess itscontext menu:Object type (class)::object nameRight-click onhistogram"hpx":


The canvas objects (again)• So we can identify the type (class) of everyobject used in the canvas:Spectrumtitle(TPaveText)"Y" axis(TAxis)The canvas(TCanvas)Histogram(TH1F)Statistics boxwith name ofhistogram(TPaveStats)Displayframe(TFrame)"X" axis (TAxis)


Manipulating objects• Use the mouse to move and resize objects…With the left buttonof the mouse you canreposition andredimension allobjects in the canvas


Activate the canvas editor• To change colours, line widths, etc. we usethe canvas editorActivate theeditor by selecting"Editor" in the"View" menu


Canvas editor• The editor appears to the left of the canvas• It displays/modifies the characteristics of the lastobject selected with the mouse (careful!)Name & type (class)of last-clickedobjectE.g. Tick here tomake all spectrascales on this canvaslogarithmic


Canvas editor• The editor appears to the left of the canvas• It displays/modifies the characteristics of the lastobject selected with the mouse (careful!)Like this !


Changing the look of a spectrum• or "the art of clicking in the right place at the right time"…1. Check you haveselected the rightobject


Changing the look of a spectrum• or "the art of clicking in the right place at the right time"…2. Click the linecolourbox tothe palette


Changing the look of a spectrum• or "the art of clicking in the right place at the right time"…3. Choose a fillstyle…


Changing the look of a spectrum• or "the art of clicking in the right place at the right time"…4. …and a colour inorder to activate it


Changing the look of a spectrum• or "the art of clicking in the right place at the right time"…5. And why notchange the titlewhile we're at it ?


Changing the look of a spectrum• or "the art of clicking in the right place at the right time"…On the second tabyou can change thebinning……as well as therange of displayedaxis values


Handling the canvas**without smudging the artwork


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


Canvas manipulation• To wipe the canvas clean:Wipe only the active(sub-)pad…Wipe the WHOLEcanvas (careful!)


Manipulating the canvas• To refresh the canvas display:Sometimes, the resultof a modification is notvisible straight away.To <strong>for</strong>ce an update of allthe objects on the canvas,option "Refresh" can help**(and reduce stress levelsand anxiety…)


Manipulating the canvas• Some useful options:In the "Options" menu ofthe canvas we also controlwhether or not to show :statistics boxeshistogram titlefit parameters


Manipulating the canvas• Dividing the canvas to display severalspectra at once:Open the context menu ofthe canvas (right-click onthe canvas)Select "Divide"


Fill in the <strong>for</strong>m,e.g. to have 2x2 pads:Manipulating the canvas• Dividing the canvas to display severalspectra at once:Number of columnsNumber of rowsMargins between padsPad colourAnd click "OK"


Manipulating the canvas• Dividing the canvas to display severalspectra at once:Next, choose the padwhere you want to displayyour spectrum(click with middle button)WARNING!The first sub-pad is notautomatically selected


Exercise


Decorating a figureMaking pretty pictures


Adding objects to the canvas• Open the toolbarSelect "Toolbar" in the"View" menu


Adding objects to the canvas• Open the toolbarWith the buttons we candraw all sorts ofgraphical objects on thecanvas…


Adding objects to the canvas• Open the toolbar…arc/circle, line,arrow, diamond, ellipse,rectangle, …


Adding object to the canvas• Open the toolbar…polyline, "curly line","curly arc", …


Adding objects to the canvas• Open the toolbar…marker, closed contour(graphical cut selection- Day 4!)


Add a pad to the canvas• Spectra within spectra within…Why add a pad ?=> Easy way to have an'insert' showing e.g. azoomPad = mini-canvas insidea canvas (or a pad… etc.etc.)


Adding a pad• Spectra within spectra within…Draw the pad, thenclick on it with themiddle button to makeit active(yellow border)**(true <strong>for</strong> all pads/canvases)


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)


Adding text• To make the figure self-explanatory, add alegend…Several choices areavailable <strong>for</strong> addingtext, do you want justtext ('L' button)* ortext in a box ?*(it's 'L' <strong>for</strong> 'LaTeX')


Adding text• …using LaTeX (well, almost)Example of a'TPaveLabel'Raw text entered:-4#leq p_{x}#leq 4To change font, size,colour of text, use thecanvas editor


ExerciseTip:it's the 2-Dspectrum'hpxpy' drawnwith option"lego" (use the'Options' dropdownmenu inthe browser)


Fitting a 1-D spectrum


Fits• Simple fitting can easily be done using thegraphical interfaceDraw spectrum'hpx' and open itscontext menuSelect "FitPanel"


Fits• Simple fitting can easily be done using thegraphical interfaceChoose a function:polN = N th order polynomialuser = user-defined function(Day 3)


Fits• Simple fitting can easily be done using thegraphical interfaceChange the range of the fit


Fits• Simple fitting can easily be done using thegraphical interfaceClick 'Fit' and the fitwill be per<strong>for</strong>med, theresult appears in theactive pad/canvas(unless you choose option"N")To see the fitparameters :menu "Options","Fit Parameters"


Exercise


Working with 2-D spectra


Displaying 2-D spectra• Several options are available <strong>for</strong> 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 drawnNot very nice (butsometimes useful)…


Displaying 2-D spectra• Several options are available <strong>for</strong> displaying2-D histograms: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"…


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 ?


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 ?*You might need toupdate the browser:"View"->"Refresh"Why does 'hpxpy' appeartwice in the list ? *(Maybe it's not the only one)


An instructive little workedexample• Can't get the same spectrum to appear in 2pads at the same time ?Names ending in ";1" or ";N"(N>=1) * are the objects inthe file (on disk)*the 'N' is a versionor 'cycle' numberThey cannot be modified(we opened the file in "ReadOnly" mode).


An instructive little workedexample• Can't get the same spectrum to appear in 2pads at the same time ?Names without ";" are memoryresidentcopies of the spectra:these we can modify.A new copy is made every timeyou double-click a disk-residentobject.The previous copy is destroyed !


An instructive little workedexample• Disk-resident vs. memory-resident objectsSo 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


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.


Operations on 2-D spectra• It's easy to generate projections or profilehistograms* from 2-D spectra*i.e. plot the mean ands.d. of one of the twovariables versus the other


Operations on 2-D spectra• It's easy to generate projections or profilehistograms from 2-D spectraRight-click to open thecontext menuThen select e.g. ProjectionX


Operations on 2-D spectra• It's easy to generate projections or profilehistograms from 2-D spectraYou can give a name <strong>for</strong>the new projection.By default (if you leave"_px") the name will be"hpxpy_px".


Operations on 2-D spectra• It's easy to generate projections or profilehistograms from 2-D spectraYou can limit the rangeof bins included in theprojection.By default, as here, allbins are included.


Operations on 2-D spectra• It's easy to generate projections or profilehistograms from 2-D spectraOptions:"d" - plot in active canvas/pad"e" - calculate errors"[cut]" - use named graphicalcut to select bins (Day 4!)


Operations on 2-D spectra• It's easy to generate projections or profilehistograms from 2-D spectraBy default, the projectionis not displayed, but shouldbe present in the browser(after a "Refresh")


Exercise


Saving your figuresIt'd be a pity to lose everything…


Saving a masterpiece• Be<strong>for</strong>e saving, we'll remove the yellow border of theactive canvas - otherwise it'll be in the figureIn the canvas' contextmenu selectSetBorderModechange the value:"0" = no border


Saving a masterpiece• Open the menu "File", sub-menu "Save"You can save an image ofyour figure in many popular<strong>for</strong>mats (PS, PDF, GIF, JPG)with the name c1.xxx bydefault**With "Save As…" you can even choose the name you want


Saving a masterpiece• What if I want to change the figure later ?Two choices:create some code ('c1.C')orsave the objects ('c1.root')


Save the objects ???• 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:It seems the file only containsone object, c1.But double-click it and…


Save the objects ???• 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:…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…


Create some code ?• By choosing "c1.C" in the menu, a file iscreated which contains all the (C++)instructions necessary to recreate our figureYou can look atthe result in anytext editor…


Create some code ?• Tomorrow we will see how to use this kindof code to create analysis scripts, etc.Now this won'thurt a bit…

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!