Root -l


Getting Started

To use root remotely: Super-K users may need to ssh -XYC to turn on "trusted x11 forwarding."

To browse .root files and make quick plots with the graphical browser:
TBroswer b
(This creates an instance, b, of class, TBrowser.)
Then double-click to navigate.
Variables (branches) are represented graphically with leaves, and you can double-click them to make a quick histogram.
A .root file can also contain pre-filled histograms, which are represented by little graph icons, which you can also double-click to load.
To save a canvas from the Root Object Browser, select File: Save.

To make quick plots from the command line:
TFile *hfile = new TFile("/disk/upmu/2007jun_officialdataset/ntuple/2007jun_upmu_final_eventsample.root");
h1->Draw("nrun");

To "rootify" a PAW .hbk file: h2root file.hbk file.root [compress] [tolower] [lrecl] [bufsiz] [optcwn]
      if file.root is not given  it will be = file.root
      compress = 1 by default (use 0 for no compression)
      tolower  = 1 by default (use 0 to keep case of column names)
      lrecl =0 by default (must be specified if >8092)
      bufsize = 8000 by default (branch buffer size)
      for cwn ntuple only: optcwn  = 1 (default)
      1-byte int -> char, 2-byte int -> short, (use 0 to keep 4-byte int) 
To quit root: .q
To run a macro: .x macro.C
To run a macro from UNIX (w/o displaying any graphics): root -b -q macro.C
An example macro: pid.C
To execute a UNIX command from within Root: .! rm pid.root
To reset the Root environment: gROOT->Reset();
To clear the memory: gROOT->Clear();
Root related utilities for SK are kept in $ROOTSYS/bin/
Create a .rootlogon.C file, which is run at start-up.
To chain together multiple .root files: chain.C
To save the canvas (default=c1) to a .gif file: c1->Print("pid.gif");

Histograms

To create a histogram using a preexisting SK .root file:
//Read in .root file:
TFile *f1 = new TFile("./rck_Hon03_271.sube.umred.upmu3.root");
//Create histogram:
//TH1F *instance = new TH1F("name", "title",nbins,min,max);
TH1F *Hehit8m = new TH1F("Hehit8m","ehit8m (entry)",40,0,60);
//The instance of TH1F (as well as the name) is "Hehit8m".
//The name and the instance can be different, but that can be a hassle.
//Fill histogram with ehit8m. (The default tree is h1.)
h1->Draw("Um_ehit8m>>Hehit8m");

To superimpose two histograms: define a stack.
THStack hs("hs","stack");
hs.Add(Hohit8mThru);
hs.Add(Hohit8mStop);

To save a histogram/stack/etc. in a .root file:
TFile f("pid.root","new");
hs.Write();

To label the axes: hprof->SetXTitle("run #");

To create a legend:
leg = new TLegend(0.6,0.7,0.89,0.89); //coordinates are fractions of pad 
leg->SetFillColor(0);                 //white background
leg->AddEntry(Hohit8mThru,"Thru");
leg->AddEntry(Hohit8mStop,"Stop");
leg->SetBorderSize(1);                //no shadow
leg->Draw(); 
Graphical attributes:
Hohit8mStop->SetFillColor(2);
Hohit8mStop->SetFillStyle(3013); //hatched fill style

Trees (ntuples)

To create and fill a tree/ntuple from collumned asci data: readData.C
To list all the variables/branches in an tree/ntuple: h1000->Print()
Equivalent to "nt/print 1000" in PAW.

To make a quick scatterplot: h1->Draw("wlen:nrun");
To make a histogram of a scatterplot try using TProfile:
//TProfile(name,title,bins,xmin,xmax,ymin,ymax)
hprof = new TProfile("hprof","",100,30800,32200,60,90);
h1->Draw("wlen/100:nrun>>hprof");

Back to Resources