ROOT tips & tricks

quick'n'dirty ascii plot

Just some style issues: directly after starting ROOT you might want to do the following to have some nicer looking plots:


To create an x-y plot reading data from an ascii file seperated by spaces user the following three lines:

t = new TTree

There automatically created a TCanvas object named c1 and a histogramm of type TH1F named htemp.

You want to set the labels properly?


The last statement is necessary to update the histogram.

When setting the title of the histogram itself no Paint() is necessay:


OK, now save a copy, e.g. as Postscript or PNG file:


If you want some high quality PNG file with a transparent background, on the shell use convert from ImageMagick:

convert -density 100 -trim -transparent \#ffffff test.png

This sets all white color to transparent, so it only works when you set the background to white.

quick'n'dirty xy plot with errorbars from ascii file

TTree t;
t.Draw("s/m * 100:energy:sqrt((se/s)**2 + (me/m)**2)*s/m","","goff");

TGraphErrors *g = new TGraphErrors(t.GetSelectedRows(),t.GetV2(),t.GetV1(),0,t.GetV3());

Retrieve auto-created histogram

TH1F *hsqrt = (TH1F*)gDirectory->Get("hsqrt");

Debugging your ROOT script with CINT

There are some well-hidden debugging functions. See User's guide 5.26, page 91 for an example and the online help of cint (enter "?" in the ROOT prompt) for a full list of commands. Here an excerpt with some additional remarks:


go stepwise (which means more or less linewise) through the script


Step over a loop (if you don't want to enter '.s' 10000 times ;) )

.c <line>

continue to line <line>


run until end of current function

.b <function name>

set breakpoint at beginning of function (setting breakpoints in arbitrary lines not implemented)

.p <variable name>

print out value of variable (works also for things like tree->GetEntries() )

plainly pressing ENTER

continue running (up to next breakpoint (?))

To start debugging:

ROOT bloody ROOT (you know this song by Sepultura?)

ROOTtips (last edited 2012-01-25 15:29:22 by MoritzBeckmann)