Introduction of ROOT

23
Introduction of ROOT Yao

description

Introduction of ROOT. Yao. ROOT Development. In the mid 1990's, René Brun and Fons Rademakers, they had lead successful projects such as PAW, PIAF, and GEANT . - PowerPoint PPT Presentation

Transcript of Introduction of ROOT

Page 1: Introduction of ROOT

Introduction of ROOT

Yao

Page 2: Introduction of ROOT

ROOT Development

• In the mid 1990's, René Brun and Fons Rademakers, they had lead successful projects such as PAW, PIAF, and GEANT .

• They knew the twenty-year-old FORTRAN libraries had reached their limits, could not scale up to the challenges offered by the Large Hadron Collider.

• At the same time, computer science had made leaps of progress especially in the area of Object Oriented Design (OOD).

What is ROOT ?

Page 3: Introduction of ROOT

Object-Oriented Design (OOD)

• Modularity• Reusability• Extendibility• Maintenance• Etc…

Page 4: Introduction of ROOT

• Smalltalk: Smalltalk-80• C based : objective-C , C++ , JAVA , C# • LISP based : Flavors , XLISP , LOOPS ,CLOS • PASCAL based : Object Pascal , Turbo Pascal ,

Eiffel , Ada 95

Page 5: Introduction of ROOT

CINT

• CINT is a command line C/C++ interpreter.• The syntax is a bit more forgiving than either

language.

Interpreted languages :• BASIC , Lisp , Perl , Scheme , Python , Ruby ,

Tcl and Tk , Unix Shell , JavaScript , PHP , VBScript

Page 6: Introduction of ROOT

• ROOT is an object-oriented framework aimed at solving the data analysis challenges of high-energy physics ,

• it provides a large selection of HEP specific utilities such as histograms and fitting.

• 2D Graphics, 3D Graphics , etc.

Why do we use ROOT ?

Page 7: Introduction of ROOT

histogram

Page 8: Introduction of ROOT

histograms and fitting

Page 9: Introduction of ROOT

2D Graphics

Page 10: Introduction of ROOT

3D Graphics

Page 11: Introduction of ROOT

Setting the Environment Variables[shyao@ipas012 ~] $ export SOFT="${HOME}/local"[shyao@ipas012 ~] $ export ROOTSYS="${SOFT}/root"[shyao@ipas012 ~] $ export PATH="${SOFT}/root/bin:${PATH}"[shyao@ipas012 ~] $ export LD_LIBRARY_PATH="${SOFT}/root/lib/root:$

{LD_LIBRARY_PATH}”

~/.bashrc

Please note: the syntax is for bash.

How to use ROOT ?

Page 12: Introduction of ROOT

Start and Quit a ROOT Session [shyao@ipas012 ~] $ root**************************************** ** W E L C O M E to R O O T ** ** Version 5.27/02 26 April 2010 ** ** You are welcome to visit our Web site ** http://root.cern.ch ** ****************************************

ROOT 5.27/02 (trunk@33229, Apr 27 2010, 11:38:29 on linux)

CINT/ROOT C/C++ Interpreter version 5.17.00, Dec 21, 2008Type ? for help. Commands must be C++ statements.Enclose multiple statements between { }.root [0] .q[shyao@ipas012 ~] $

Page 13: Introduction of ROOT

help[shyao@ipas012 ~]$ root -?Usage: root [-l] [-b] [-n] [-q] [dir] [[file:]data.root] [file1.C ... fileN.C]Options: -b : run in batch mode without graphics -n : do not execute logon and logoff macros as specified in .rootrc -q : exit after processing command line macro files -l : do not show splash screen dir : if dir is a valid directory cd to it before executing

Page 14: Introduction of ROOT

command line

root[0] 1+sqrt(9)(const double)4.00000000000000000e+00root[1] for (int i = 0; i<4; i++) cout << "Hello " << i << endlHello 0Hello 1Hello 2Hello 3root[2] .q

Page 15: Introduction of ROOT

histogramvoid fith() { // filename double tmp; ifstream fin("./data/rr.txt"); int i=0;

TCanvas *c1 = new TCanvas("c1","fitting Histogram",200,10,700,500); TH1D *h1 = new TH1D( "h1", "hist1", 20, 0, 10 );

while(!fin.eof()){ fin>>tmp; h1->Fill( tmp*1000000. ); } fin.close();

h1->SetTitle("muon lifetime"); h1->SetXTitle("10^{-6}s"); h1->SetYTitle("count"); //******** h1->Draw("E");C1->Print();}

Do not need to include header file that root provide.

Page 16: Introduction of ROOT

Run a script

[shyao@ipas012 ]$ root fith.Corroot [0] .x fith.C

Page 17: Introduction of ROOT

fittingTF1 *t1 = new TF1("t1","[0]+[1]*exp(-x/[2])",0,bin);t1->SetParNames("a","b","lifetime");t1->SetParameter(0,6);t1->SetParLimits(0,0,10);t1->SetParameter(1,1);t1->SetParameter(2,2.2);h1->Fit("t1");

[shyao@ipas012 ]$ root fith.CNO. NAME VALUE ERROR SIZE DERIVATIVE 1 a 2.66609e+00 1.56321e+00 3.68519e-04 4.12958e-04 2 b 1.48634e+02 9.03901e+00 1.18599e-02 1.96484e-05 3 lifetime 2.26596e+00 1.82994e-01 1.49850e-04 1.42577e-03

Page 18: Introduction of ROOT

Scatter Diagramvoid graph() { TCanvas *c1 = new TCanvas("c1","A Simple Graph Example",200,10,700,500);

const Int_t n = 20; Double_t x[n], y[n]; for (Int_t i=0;i<n;i++) { x[i] = i; y[i] = sin(i*0.5); } gr = new TGraph(n,x,y); //****** gr->Draw("AP*");

c1->Update(); c1->Modified();}

Page 19: Introduction of ROOT

[shyao@ipas012 code]$ root graph.C

Page 20: Introduction of ROOT

gr->SetLineColor(2);gr->SetLineWidth(4);gr->SetMarkerColor(4);gr->SetMarkerStyle(21);gr->SetTitle("a simple graph");gr->GetXaxis()->SetTitle("X title");gr->GetYaxis()->SetTitle("Y title");gr->Draw("ACP*");

Page 21: Introduction of ROOT
Page 22: Introduction of ROOT

2D Graphicsvoid graph2d(){ TCanvas *c = new TCanvas("c","Graph2D example",0,0,700,600); Double_t x, y, z, P = 6.; Int_t np = 200; TGraph2D *dt = new TGraph2D(); TRandom *r = new TRandom(); for (Int_t N=0; N<np; N++) { x = 2*P*(r->Rndm(N))-P; y = 2*P*(r->Rndm(N))-P; z = (sin(x)/x)*(sin(y)/y)+0.2; dt->SetPoint(N,x,y,z); } gStyle->SetPalette(1); dt->Draw("surf1");

}

Page 23: Introduction of ROOT