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:
gROOT->SetStyle("Plain");
gStyle->SetMarkerStyle(20);To create an x-y plot reading data from an ascii file seperated by spaces user the following three lines:
t = new TTree
t->ReadFile("fitresults.txt","run:mean:mean_error:sigma:sigma_error")
t->Draw("sigma/mean:mean")There automatically created a TCanvas object named c1 and a histogramm of type TH1F named htemp.
You want to set the labels properly?
htemp->GetXaxis()->SetTitle("Energy");
htemp->GetYaxis()->SetTitle("Sigma");
htemp->Paint();The last statement is necessary to update the histogram.
When setting the title of the histogram itself no Paint() is necessay:
htemp->SetTitle("myPlot");OK, now save a copy, e.g. as Postscript or PNG file:
c1->Print("myPlot.ps");
c1->Print("myPlot.png");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.ps 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.ReadFile(infile,"m:me:s:se:chi2:ndf:run:energy");
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());
g->Draw("ap");
Retrieve auto-created histogram
t->Draw("blub>>hsqrt");
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:
.s |
go stepwise (which means more or less linewise) through the script |
.S |
Step over a loop (if you don't want to enter '.s' 10000 times |
.c <line> |
continue to line <line> |
.e |
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:
Load script with '.L <file name>'
- Set breakpoints (if you want)
Run script with '<main function name>()' (up to first breakpoint) or '.s <main function name>()' (stepwise)
ROOT bloody ROOT (you know this song by Sepultura?)
