240 likes | 375 Views
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 .
E N D
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 ?
Object-Oriented Design (OOD) • Modularity • Reusability • Extendibility • Maintenance • Etc…
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
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
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 ?
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 ?
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, 2008 Type ? for help. Commands must be C++ statements. Enclose multiple statements between { }. root [0] .q [shyao@ipas012 ~] $
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
command line root[0] 1+sqrt(9) (const double)4.00000000000000000e+00 root[1] for (int i = 0; i<4; i++) cout << "Hello " << i << endl Hello 0 Hello 1 Hello 2 Hello 3 root[2] .q
histogram Do not need to include header file that root provide. void 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(); }
Run a script [shyao@ipas012 ]$ root fith.C or root [0] .x fith.C
fitting TF1 *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.C NO. 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
Scatter Diagram void 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(); }
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*");
2D Graphics void 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"); }