Some Root basics

Author: TP, Date: Sep-16-2003

Conversion of old HBook files:

Root comes with the program h2root. Usage:
h2root <filename.rz>
will create the output file <filename.root>.

Interactive Root session

1) Starting Root

Open a terminal and enter root. Root will look for a .rootrc file in the HOME directory. For user nemu this looks like

# root logon script
#
Unix.*.Root.MacroPath: .:~/root:$ROOTSYS/macros
# search path for logon/logoff scripts
Rint.Logon: $HOME/root/rootlogon.C

to define search paths for Root macros and logon/logoff scripts. The logon script rootlogon.C looks like

{
// root logon script
TBrowser browser;
}

It's purpose is to start the Root browser when starting root.

2) Working with a root file

The following shows how to open a Root file - lem02_0067.root in this example, which was created by h2root lem02_0067.rz - and how to plot histograms, Trees (NTuple) etc.:

root [ ] TFile *f = new TFile("lem02_0067.root");
root [ ] f->ls(); // lists the contents
root [ ] h401->Draw(); // plot the histogram h401
root [ ] h1->Dump(); // dumps information about Root Tree h1
root [ ] h1->GetEntries(); // shows the number of entries in h1
root [ ] TH1F *h401_root = new TH1F("h401_root", "lem02_0067", 1000, 0.5, 1000.5);
// creates histogram h401_root with title lem02_0067, 1000 channels, ranging from
// 0.5 to 1000.5
root [ ] h1->Show(11); // shows event 11
root [ ] h1->Draw("Tdc3[0]"); // draws the first entry of Tdc3[8] array
root [ ] h1->Draw("Tdc3[0]>>h401_root", "300<Tdc3[0] && Tdc3[0]<800", "lego", 1000, 100);
// plots Tdc3[0] data in user defined histogram h401_root, applies cuts 300<Tdc3[0]<800,
// do a lego plot, scan 1000 events and start at event 100.
root [ ] h1->Draw("Tdc3[0]:Tdc3[1]"); // 2D plot of Tdc3[0] versus Tdc3[1]
root [ ] h1->StartViewer(); // starts Tree viewer
root [ ] h1->MakeClass("lem02_0067_class"); // very useful to create macros for complex analysis
root [ ] h1->MakeSelector("lem02_0067_sel"); // very useful to create macros for complex analysis
// have a look on contents of lem02_0067_class.C and lem02_0067_sel.C

Directory stuff: if you have more than one file open then:
root [ ] gDirectory->pwd(); // prints current working directory
Rint:/
root [ ] TFile *f = new TFile("lem02_0067.root");
root [ ] gDirectory->pwd(); // prints current working directory
lem02_0067.root:/
root [ ] TFile *f1 = new TFile("lem03_0033.root");
root [ ] gDirectory->pwd(); // prints current working directory
lem03_0033.root:/
root [ ] f->cd(); // changes directory to lem02_0067.root
root [ ] gROOT->cd(); // returns to home directory

3) Fitting, extracting data from histograms etc.

To be continued.