Hoi,
the following might be useful in the daily struggle.
// ----------------------------------------------------------------------
// I include this in my rootlogon.C (see e.g. ~ursl/rootlogon.C):
gROOT->SetStyle("Plain");
// ----------------------------------------------------------------------
// axes labelling is 'short' with the following. There is something
// similiar in recoilAnalysis.cc (recoilAnalysis::setTitles)
void SetTitles(TH1 *h, char *sx, char *sy, float size = 0.05,
float xoff = 1.1, float yoff = 1.0,
float lsize = 0.05,
int font = 62) {
h->SetXTitle(sx); h->SetYTitle(sy);
h->SetTitleOffset(xoff, "x"); h->SetTitleOffset(yoff, "y");
h->SetTitleSize(size, "x"); h->SetTitleSize(size, "y");
h->SetLabelSize(lsize, "x"); h->SetLabelSize(lsize, "y");
h->SetNdivisions(508, "X");
// h->SetLabelFont(font, "x"); h->SetLabelFont(font, "y");
// h->GetXaxis()->SetTitleFont(font); h->GetYaxis()->SetTitleFont(font);
}
// ----------------------------------------------------------------------
// For a legend: I usually define in global scope
TLegend *leg;
TLegendEntry *entry;
// and then use in a function (where h1 and h2 are TH1D*):
leg = new TLegend(0.5,0.74,0.9,0.89);
leg->SetFillStyle(0); leg->SetBorderSize(0.); leg->SetTextSize(0.06); leg->SetFillColor(0);
leg->SetHeader("No depletion");
entry = leg->AddEntry(h1," Data","p"); entry->SetTextColor(kBlack);
entry = leg->AddEntry(h2,"Cocktail","f"); entry->SetTextColor(kBlack);
leg->Draw();
// ----------------------------------------------------------------------
// For lines, in global scope:
TLine *pl = new TLine();
// and then usage ad libitum with (x is some float here)
pl->SetLineColor(kRed); pl->SetLineWidth(2); pl->DrawLine(x, -5., x, max);
// ----------------------------------------------------------------------
// For texts, in global scope:
TLatex tl;
// and then, e.g.
char line[100]; sprintf(line, "normalized to %3.1f/fb", scale);
c4->cd(11); tl.SetTextSize(0.1); tl.DrawLatex(0., 0.7, line); tl.SetTextSize(bla);
tl.DrawLatex(0.1, 0.92, "Background Box, no PID, all other cuts");
// you can also include most (many) of the usual LaTex symbols when
// preceded with '#'. If the margin at the bottom of a pad is too
// small, the subscript will not show up. It is (often) necessary,
// to put the exponent into braces: GeV^{2}
// Note: you can set the coordinate system to either 'normalized
// coordinates' (so that a pad extends from 0 .. 1), or to the
// histogram coordinates (so that the values on the axes are taken as
// reference system):
tl.SetNDC(kTRUE); // sets to normalized coordinates
The separation betwen global scope and local scope is useful against
CINT's limitations.
Another useful class if you do not like the verbosity of root is
~ursl/macros/FsxUtil/hpl.cc. Still under development, ...
I tried to remember most of the stumbling blocks, please let me know
if you run into other problems.
Cheers,
--U.
|