Sunday, July 3, 2011

ROOT after a little bit of C++

I made a recent revision for Malik's excellent book about C++. This time I made it up to chapter 14 where I learned a lot about pointers. It turns out that this concept is heavily used in ROOT. For example here is a snippet of a code I am using to create plots of publication quality:

#include
#include "TInterpreter.h"
#include "TCanvas.h"
#include "TLatex.h"
#include "TROOT.h"
#include "TH2F.h"
#include "TGraphErrors.h"
#include "TLegend.h"
#include "TPad.h"


These are preprocessor statements to include libraries and header files. the <> symbol is doe standard libraries. and the ones between quotes "" is for libraries made.
void readRFPAS2RHWZ2() {



This starts the function of the type void called readRFPAS2RHWZ2()




float x = 0.446127; //The coordinate of 900GeV labe (t1d, t2d, etc)
float y = 0.190389;
float x1 = 0.2000; //The coordinates for the legends.
float y1 = 0.326465;
float x2 = 0.50275;
float y2 = 0.551054;

Simple variable declaration.

 TInterpreter::Instance() -> LoadMacro("tdrstyle.C");
This is a bit odd as an expression. I am not sure how to interpret it but here is a try. There is a space TInterpreter with an class Instance that has an object LoadMacro. it is called as a pointer:

(*TInterpreter::Instance).LodMacro = tdrstyle.C

What this does is to ask our code to use that macro.
 gROOT -> Reset();

Basically calling another pointer.
(*gROOT).Reset();
 TInterpreter::Instance() -> Execute ("setTDRStyle","");

Same as above.

 TCanvas *c1 = new TCanvas("c1","different scales hists",600,600);

new means we are creating a dynamic variable. in this case of the type TCanvas. it is assigned to the pointer c1.

 c1->Range(-100,-100,10,10);

now c1 points to another object in TCanvas.
(*c1).Range = (-100,-100,10,10);

 TH1F *Dist_Nch_pT20_ = new TH1F("Dist_Nch_pT20_","title",100,-0.5,30);

also TH1F is a data type. with the pointer Dist_Nch_pT20_ is set with the address of the class named Dist_Nch_pT20_  with the parameters needed. next we assign the objects:
 Dist_Nch_pT20_->SetXTitle("N_{ch}");

etc.

So we conclude it is nothing but a bunch of dynamic classes assigned by pointers.

No comments: