Presentation is loading. Please wait.

Presentation is loading. Please wait.

ROOT Root Commands and CINT Functions and Fitting (The Tree Viewer)

Similar presentations


Presentation on theme: "ROOT Root Commands and CINT Functions and Fitting (The Tree Viewer)"— Presentation transcript:

1 ROOT Root Commands and CINT Functions and Fitting (The Tree Viewer)

2 ROOT The ROOT Home: The ROOT Team: Rene Brun & Fons Rademakers

3 Finding Examples The ROOT Tutorials: The ROOT How To's: For on-line help for a particular topic it's very useful to use their facility to search the ROOT site.

4 CINT Basics Last time GUI Today Command Line (CINT) Scripts (CINT) Functions and Fitting TreeViewer

5 Command Line Basics Use up and down arrows to recall commands History file: $HOME/.root_hist Use emacs commands to navigate

6 Command line Environment Settings Command types CINT Commands Global Variables TObject

7 Environment Settings Environment setting file: $ROOTSYS/etc/system.rootrc looks first in current directory for.rootrc second in $HOME/.rootrc third in $ROOTSYS/etc/system.rootrc Find the current settings root[] gEnv->Print()

8 Environment Settings (cont.) The.rootrc file: The Macro Path Unix.*.Root.MacroPath:.:$(HOME)/myRootMacros Options in.rootrc Root.ShowPath: false History File $HOME/.root_hist Automatically Executing Macros rootlogon.C rootlogoff.C rootalias.C

9 Command Line Options > root -/? Usage: root [-l] [-b] [-n] [-q] [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

10 Three Types of Commands 1. CINT commands start with “.” root[0].? this command will list all the CINT commands root[1].X [filename] load [filename] and execute function [filename] root[2].L [filename] load [filename] 2. SHELL commands start with “.!” for example: root[3].! ls

11 Three Types of Commands 3. C++ syntax (almost) root [0] TBrowser *b = new TBrowser() or root [0] TBrowser *b = new TBrowser(); The optional Semicolon: Leave off the semicolon to see the return value of the command. root [0] 23+5 // show return value (int)28 root [1] 23+5; // no return value root [2]

12 Command Line Help Use the Tab feature to get help … root [0] b = new TB root [1] b = new TBrow root [2] b = new TBrowser( Find List of Methods Find Parameter list

13 Coding Conventions Based on Taligent Classes begin with T TTree, TBrowser Non-class types end with _t Int_t Data members begin with ffTree Member functions begin with a capital Loop() Constants begin with k kInitialSize, kRed Static variables begin with g gEnv Static data members begin with fg fgTokenClient

14 CINT Types

15 CINT Extensions to C++ 1. Declaration can be omitted f = new TFile("Example.root") 2. "." notation rather than "->" f.ls() 3. Search for an object by its name TH1F *smallHisto = new TH1F (" small ","fPx 100",100,-5,5); small ->Draw(); Warning: These will not work in compiled code!

16 CINT Commands [expression] evaluates the expression root[3] 3*4 (int)12.files show loaded source files.class [name] show class definition.g prints all objects in the root session.ls ls on current directory.pwdlist the current directory, canvas, and style.

17 Demo on CINT Commands.class root [0].L $ROOTSYS/test/libEvent.so root [1].class Event.g root [2].g... 0x104c7560 Event e, size=56 0x0 private: Int_t fNtrack 0x0 private: Int_t fNseg 0x0 private: Int_t fNvertex...

18 CINT Multi-line Command Start with "{" For example: root [] { end with '}'> Int_t j = 0; end with '}'> for (Int_t i = 0; i < 3; i++) end with '}'> { end with '}'> j= j + i; end with '}'> cout <<"i = " <

19 Global Variables gRandom gRandom->Gaus(1,2) You can replace the random generator with your own: delete gRandom; gRandom = new TRandom2(0); //seed=0 gFile gFile->GetName() gDirectory gDirectory->GetName() gSystem gSystem->HostName()

20 gROOT global ROOT session object gROOT->GetListOf (); gROOT->LoadMacro(); gROOT->Time(); gROOT->ProcessLine()

21 Resetting the Environment gROOT->Reset() Calls destructors of all objects created on the stack Objects on Heap are not deleted, but pointer variable is disassociated

22 TObject: The Mother of all Root objects Defines protocol and default behavior for all objects in ROOT. – I/O – Drawing/Painting – TObjects can be stored in collection classes. – Introspection, Reflection, Runt Time Type Identification

23 Command Line Basics

24 Saving the Canvas The save options: Postscript gif ROOT file Macro Save as a ROOT file: Open the saved ROOT file (c1.root) and draw the canvas root[2] > c1.Draw();

25 Open a File Open a file for reading root [] TFile f("Example.root") Look at the contents of the file root [] f.ls() TFile** Example.root ROOT file TFile* Example.root ROOT file KEY: TTree myTree;1 Example ROOT tree KEY: TH1F totalHistogram;1 Total Distribution KEY: TH1F mainHistogram;1 Main Contributor KEY: TH1F s1Histogram;1 First Signal KEY: TH1F s2Histogram;1 Second Signal

26 Writing Scripts Named Scripts Un-named Scripts

27 Scripts Un-named Script Start with "{" and end with "}" All variables are in the global scope No class definitions No function declarations No parameters Named Script C++ functions Scope rules follow standard C++ Function with the same name as the file is executed with a.x Parameters Class definitions (derived from a compiled class at your own risk)

28 Scripts Examples Un-named Script: hello.C { cout << "Hello" << endl; } Named Script:say.C void say(char * what = "Hello") { cout << what << endl; } Executing the Named Script root [3].x say.C Hello root [4].x say.C("Hi there") Hi there

29 Command Line Basics

30 Functions and Fitting Function Objects (TF1) Three constructors for TF1 User Defined Functions Fitting Fit() Fitting with a user defined function Fitting subranges and combining functions Demonstration of background and signal function

31 Function Objects (TF1) Built in function objects see this link for a full list of built in functions use the Fit Panel Creating your own function objects TF1, TF2, TF3 Three Signatures for the TF1 constructor

32 TF1 Constructors 1. A C++ like expression using x with a fixed set of operators and functions defined in TFormula TF1 *f1 = new TF1("f1", "sin(x)/x",0,10); f1->Draw(); TF1 *f2 = new TF1("f2","f1 * 2",0,10);

33 TF1 Constructors (cont.) 2. Same as the previous TF1 with Parameters Call the constructor with parameter indices TF1 *f1 = new TF1 ("f1","[0] *x*sin( [1] *x)",-3,3); See TFormula for valid expressions Set the parameters explicitly f1->SetParameter(0,10); f1->SetParameter(1,5); f1->Draw();

34 TF1 Constructors (cont.) 3. Use a defined function Define a function Double_t MyFunction(Double_t *x, Double_t *par){ Float_t xx =x[0]; Double_t val= TMath::Abs(par[0]*sin(par[1]*xx)/xx); return val; } TF1 constructor TF1 *f1 = new TF1("f1",MyFunction,0,10,2); NOTE: The 2 is the number of parameters in MyFunction. Set the parameters f1->SetParameters(2,1);

35 Fitting To fit a histogram: TF1 *fn1 = new TF1 ("f1","[0] *x*sin([1]*x)",-3,3); f1->SetParameters(10,5); aHistogram->Fit("f1"); //name aHistogram->Fit(fn1); // pointer

36 Fitting: Example Step 1. Define the function: Double_t MyFunction (Double_t *x, Double_t *par) { Double_t arg= 0; if (par[2]) arg = (x[0] - par[1])/par[2]; Double_t fitval = par[0] * TMath::Exp(-0.5*arg*arg); return fitval; }

37 Fitting (cont.) Step 2. TF1 constructor TF1 *aFunction = new TF1("MyGaus", MyFunction, -5,5,3); Step 3. Set initial value of the parameters aFunction->SetParameters(5000, h->GetMean(), h->GetRMS()); Step 4. Fit and draw the histogram h->Fit("MyGaus");

38 Fitting Sub-Ranges Example $ROOTSYS/tutorials/multifit.C Define the range in the TF1 constructor. TF1 *g1 = new TF1("g1", "gaus", 85,95); By default, TH1::Fit on the defined histogram range. Use "R" option in the Fit() method. h->Fit("g1", "R");

39 Fitting Subranges

40 Fitting Subranges++ Define gaussian functions g1 = new TF1("m1","gaus",85,95); g2 = new TF1("m2","gaus",98,108); g3 = new TF1("m3","gaus",110,121); total = new TF1("mstotal","gaus(0)+gaus(3)+gaus(6)",85,125); From TFormula: gaus(0) is a substitute for : [0]*exp(-0.5*((x-[1])/[2])**2) and (0) means start numbering parameters at 0

41 Fitting Sub-Ranges++ Fit each range and get the parameter for "total" h->Fit(g1,"R"); h->Fit(g2,"R+"); h->Fit(g3,"R+"); g1->GetParameters(&par[0]); g2->GetParameters(&par[3]); g3->GetParameters(&par[6]); total->SetParameters(par); h->Fit(total,"R+")

42 Signal and Background Demo y(E) = a 1 + a 2 E + a 3 E 2 + A P (  / 2  )/( (E-  ) 2 + (  /2) 2 ) backgroundlorenzianPeak par[0] = a 1 par[0] = A P par[1] = a 2 par[1] =  par[2] = a 3 par[2] =  fitFunction = background (x, par ) + lorenzianPeak (x, &par[3]) par[0] = a 1 par[1] = a 2 par[2] = a 3 par[3] = A p par[4] =  par[5] = 

43 Fitting Demo Look at FittingDemo.C Unnamed Macro fitf.C Named Macro Run FittingDemo.C More info on fitting:

44 The Tree Viewer Overview Drawing Histograms Using Cuts Lego Plots Creating new Variables Saving the Canvas

45 The Tree Viewer root[] myTree->StartViewer() Contents: XYZ Cut Scan Expressions Variables (leaves) Draw option Recording commands Histogram Range Selector IList/OList

46 Drawing Two Histograms Double click on one variable Select Superimpose option Double click on another variable

47 Adding Weight Add a Weight: xmain < 0

48 2D Lego Plots Draw xmain vs. xs1 Rotating the lego plot

49 Creating a variable 2. Set the name and expression 3. Double click to draw it 1. Create New Expression

50 More Features Record: 1)Command is recorded in history file ($HOME/root_hist) 2)Is printed on the command line Scan: 1) Drag and drop variables to scan box 2) Redirect output to a file Saving and recovering a Session: 1) Save the current cuts, expressions into treeviewer.C 2) Read session back

51 The ROOT File A TFile is a directory structure like UNIX Object in Memory (OBJ) Object on Disk (KEY)


Download ppt "ROOT Root Commands and CINT Functions and Fitting (The Tree Viewer)"

Similar presentations


Ads by Google