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

Slides:



Advertisements
Similar presentations
REPORTER 9.2. back to contents Contents Introduction to Reporter User interface – menu layout Creating a template – first steps Text Editing objects Variables.
Advertisements

Joe Foster Visualizing Data with ROOT Joe Foster University of Manchester.
Lecture 15.1 Static Methods and Variables. © 2006 Pearson Addison-Wesley. All rights reserved Static Methods In Java it is possible to declare.
Why ROOT?. ROOT ROOT: is an object_oriented frame work aimed at solving the data analysis challenges of high energy physics Object _oriented: by encapsulation,
A Guide to Unix Using Linux Fourth Edition
Debugging What can debuggers do? Run programs Make the program stops on specified places or on specified conditions Give information about current variables’
Postgraduate Computing Lectures ROOT 1 What is ROOT? Tool and a Framework for OO Data Analysis As a Tool –Enter commands to display and manipulate data.
CS Lecture 03 Outline Sed and awk from previous lecture Writing simple bash script Assignment 1 discussion 1CS 311 Operating SystemsLecture 03.
IT PUTS THE ++ IN C++ Object Oriented Programming.
Ch 71 Using ATTRIB, SUBST, XCOPY, DOSKEY, and the Text Editor.
Sept 11, 2003ROOT Day1, Suzanne Panacek39 ROOT An object oriented HEP analysis framework. Day 1.
ROOT An object oriented HEP analysis framework.. Computing in Physics Physics = experimental science =>Experiments (e.g. at CERN) Planning phase Physics.
Overview of Previous Lesson(s) Over View  OOP  A class is a data type that you define to suit customized application requirements.  A class can be.
Tutorial 11 Using and Writing Visual Basic for Applications Code
Chapter 3 Mastering Editors
V0.05 ROOT 102 ROOT is an object oriented HEP analysis framework.
09-Jun-2005J. Adamczewski1 C++ course 2005 The ROOT framework 2.
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.
®® Microsoft Windows 7 for Power Users Tutorial 13 Using the Command-Line Environment.
21-Apr-2005J. Adamczewski1 DVEE C++ course 2005 The ROOT framework 1: Introduction.
Chapter Three The UNIX Editors. 2 Lesson A The vi Editor.
Chapter 4 UNIX Common Shells Commands By C. Shing ITEC Dept Radford University.
Linux Operations and Administration
ROOT Tutorial An object oriented HEP data analysis framework Presented by Dimitri Bourilkov University of Florida UltraLight Workshop, June 2005, FIU,
10/31/2015PHYS 3446 DØ Data Analysis with ROOT Venkat (for Dr.Yu)
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes.
Introduction to ROOT Practical Part Jan Fiete Grosse-Oetringhaus, CERN PH/ALICE Summer Student Lectures th July.
Mixing integer and floating point numbers in an arithmetic operation.
Chapter Three The UNIX Editors.
 2003 Prentice Hall, Inc. All rights reserved. 1 IS 0020 Program Design and Software Tools Preprocessor Midterm Review Lecture 7 Feb 17, 2004.
ASP (COMPONENTS) Active Server Pages (cont..) 1. global.asa file The Global.asa file is an optional file that can contain declarations of objects, variables,
9/28/2005Philippe Canal, ROOT Workshop TTree / SQL Philippe Canal (FNAL) 2005 Root Workshop.
Postgraduate Computing Lectures PAW 1 PAW: Physicist Analysis Workstation What is PAW? –A tool to display and manipulate data. Learning PAW –See ref. in.
LCG AA Meeting 31 October 2007 The new dynamically and extensively customizable ROOT browser Bertrand Bellenot.
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
Creating FunctionstMyn1 Creating Functions Function can be divided into two groups: –Internal (built in) functions –User-defined functions.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
CSE 303 Concepts and Tools for Software Development Richard C. Davis UW CSE – 10/11/2006 Lecture 7 – Introduction to C.
Go4 Workshop J.Adamczewski-Musch, S.Linev Go4 advanced features.
Chapter 12: Pointers, Classes, Virtual Functions, Abstract Classes, and Lists.
Joe Foster 1 This talk extends the one I gave in 2006 called Visualizing Data with ROOT. –
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
HYDRA Framework. Setup of software environment Setup of software environment Using the documentation Using the documentation How to compile a program.
V0.02 The ROOT Collection Classes. V Collection Classes Group of related objects TObjects or descendants from TObject Abstract base class TCollection.
ROOT – úvodní přednáška a cvičení Jiří Chudoba,
ROOT1 Hands-on Sami Kama. S.Kama ROOT1 Hands-On ISTAPP2011 Dogus Univ.07/02/ Download root file from indico.
1 CS 192 Lecture 4 Winter 2003 December 8-9, 2003 Dr. Shafay Shamail.
UNIX To do work for the class, you will be using the Unix operating system. Once connected to the system, you will be presented with a login screen. Once.
Test 2 Review Outline.
ROOT: Functions & Fitting
Introduction to ROOT Practical Part
Guide To UNIX Using Linux Third Edition
An Introduction to Computers and Visual Basic
Tutorial of Unix Command & shell scriptS 5027
Tutorial of Unix Command & shell scriptS 5027
ROOT Class Day 1 An Object Oriented Data Analysis Framework
ROOT Class Day 2 An Object Oriented Data Analysis Framework Lecture 2
Chapter 12: Pointers, Classes, Virtual Functions, and Abstract Classes
Chapter 15 Pointers, Dynamic Data, and Reference Types
The Boolean (logical) data type boolean
Tutorial of Unix Command & shell scriptS 5027
Chapter 15 Pointers, Dynamic Data, and Reference Types
Makoto Asai (SLAC) Geant4 Tutorial Course
Tonga Institute of Higher Education
An Introduction to Computers and Visual Basic
Stata Basic Course Lab 2.
Zooming on ROOT files and Containers
Introduction to ROOT (2/2) Practical Part
Types of Computer Languages
The ROOT framework 1: Introduction
Presentation transcript:

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

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

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.

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

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

Command line Environment Settings Command types CINT Commands Global Variables TObject

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()

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

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

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

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]

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

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

CINT Types

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!

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.

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...

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 = " <<i<<", j = " <<j<<endl; end with '}'> } i = 0, j = 0 i = 1, j = 1 i = 2, j = 3

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()

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

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

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

Command Line Basics

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();

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

Writing Scripts Named Scripts Un-named Scripts

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)

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

Command Line Basics

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

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

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);

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();

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);

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

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; }

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");

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");

Fitting Subranges

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

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+")

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] = 

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

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

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

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

Adding Weight Add a Weight: xmain < 0

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

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

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

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