ROOT: An object-orientated analysis framework

Similar documents
Lecture I: Basics REU Root Duke Jen Raaf

ROOT. Introduction. Spring 2010 Lecture 5. S. Lehti and V.Karimäki. COMPUTING METHODS IN HIGH ENERGY PHYSICS (page 1)

Introduction to ROOT and application to data analysis at the LHC

ROOT TUTORIAL. Dirk Krücker, Kelly Beernaert, Ilya Bobovnikov.

ROOT for beginners. First Day Discovering the graphical environment

ROOT Trips & Tricks. Ole Hansen. Jefferson Lab. Hall A & C Analysis Workshop June 26 27, 2017

Getting Started with ROOT

Introduction to ROOT. M. Eads PHYS 474/790B. Friday, January 17, 14

HEP data analysis using ROOT

Data Analysis Frameworks

Introduction to ROOT. Sebastian Fleischmann. 06th March 2012 Terascale Introductory School PHYSICS AT THE. University of Wuppertal TERA SCALE SCALE

INTRODUCTION TUTORIAL

ROOT Course. Vincenzo Vitale, Dip. Fisica and INFN Roma 2

Computational Physics Operating systems

What is ROOT? Why do we use it? Answer: ROOT does what physicists do: It makes plots.

ROOT Analysis Framework (I) Introduction. Qipeng Hu March 15 th, 2015

Root programming and data analysis

PAW: Physicist Analysis Workstation

An Introduction to Root I/O

INTRODUCTION TO ROOT & BASIC APPLICATIONS

HEP data analysis using ROOT

Multiple variables data sets visualization in ROOT

P445/515 Data Analysis using PAW

Excel R Tips. is used for multiplication. + is used for addition. is used for subtraction. / is used for division

Learning from Data Introduction to Matlab

ROOT5. L. Peter Alonzi III. November 10, University of Virginia

What is ROOT? Why do we use it? Answer: ROOT does what physicists do: It makes plots.

Distributed object monitoring for ROOT analyses with Go4 v.3

Appendix A. Introduction to MATLAB. A.1 What Is MATLAB?

Data Analysis R&D. Jim Pivarski. February 5, Princeton University DIANA-HEP

rootpy: Pythonic ROOT

Lecture 7. Simulations and Event Generators. KVI Root-course, April Gerco Onderwater, KVI p.1/18

ROOT Analysis FrameWork (II) Basics. Qipeng Hu March 22, 2015

Professor Stephen Sekula

MEASUREMENT OF A DOUBLE-SPIN ASYMMETRY FROM INCLUSIVE ELECTRON-PROTON SCATTERING IN THE CLAS EG4 EXPERIMENT

Choose the file menu, and select Open. Input to be typed at the Maple prompt. Output from Maple. An important tip.

An introduction to plotting data

Introduction to Matlab

Thursday, February 16, More C++ and root

An Introduction to ROOT

AODstats. Guide to using the Victorian data maps. Powered by StatPlanet

: Intro Programming for Scientists and Engineers Assignment 1: Turtle Graphics

Monte Carlo Techniques. Professor Stephen Sekula Guest Lecture PHY 4321/7305 Sep. 3, 2014

Survey of Math: Excel Spreadsheet Guide (for Excel 2016) Page 1 of 9

Maple Quick Start. Maplesoft, a division of Waterloo Maple Inc.

C++ Support Classes (Data and Variables)

Dr Richard Greenaway

Introduction To Inkscape Creating Custom Graphics For Websites, Displays & Lessons

SAS Visual Analytics 8.2: Working with Report Content

An Introduction to ROOT

LECTURE 0: Introduction and Background

Module 10A Lecture - 20 What is a function? Why use functions Example: power (base, n)

Objectives. 1 Running, and Interface Layout. 2 Toolboxes, Documentation and Tutorials. 3 Basic Calculations. PS 12a Laboratory 1 Spring 2014

Objectives. 1 Basic Calculations. 2 Matrix Algebra. Physical Sciences 12a Lab 0 Spring 2016

Expressing Parallelism with ROOT

W7 DATA ANALYSIS 2. Your graph should look something like that in Figure W7-2. It shows the expected bell shape of the Gaussian distribution.

Practical Programming, Third Edition

ARTIFICIAL INTELLIGENCE AND PYTHON

Iteration. # a and b are now equal # a and b are no longer equal Multiple assignment

Before submitting the file project5.py, check carefully that the header above is correctly completed:

Computer Components. Software{ User Programs. Operating System. Hardware

PART 1 PROGRAMMING WITH MATHLAB

EP578 Computing for Physicists

easel Manager Danielle Crosswell dac2182 Language Guru Tyrus Cukavac thc2125 System Architect Yuan-Chao Chou yc3211 Tester Xiaofei Chen xc2364

GRETL FOR TODDLERS!! CONTENTS. 1. Access to the econometric software A new data set: An existent data set: 3

Creating a basic Mind Map using Inspiration 9.0

1 Introduction to Using Excel Spreadsheets

The Run 2 ATLAS Analysis Event Data Model

CSC 110 Final Exam. ID checked

There are two ways to use the python interpreter: interactive mode and script mode. (a) open a terminal shell (terminal emulator in Applications Menu)

Getting Started with MATLAB

Homework 4: Clustering, Recommenders, Dim. Reduction, ML and Graph Mining (due November 19 th, 2014, 2:30pm, in class hard-copy please)

Histograms And N-tuples

Introduction to Matlab

Basic Data Analysis Using ROOT

Contents Object Ownership

cling Axel Naumann (CERN), Philippe Canal (Fermilab), Paul Russo (Fermilab), Vassil Vassilev (CERN)

Big Data Software in Particle Physics

Creating a Basic Chart in Excel 2007

PyPlot. The plotting library must be imported, and we will assume in these examples an import statement similar to those for numpy and math as

Name: Dr. Fritz Wilhelm Lab 1, Presentation of lab reports Page # 1 of 7 5/17/2012 Physics 120 Section: ####

Dr Richard Greenaway

MATLAB INTRODUCTION. Matlab can be used interactively as a super hand calculator, or, more powerfully, run using scripts (i.e., programs).

ENGI Parametric & Polar Curves Page 2-01

Introduction to MATLAB

HO-1: INTRODUCTION TO FIREWORKS

lab MS Excel 2010 active cell

PROGRAMMING IN HASKELL. Chapter 2 - First Steps

Solution Notes. COMP 151: Terms Test

Bar Graphs with Two Grouping Variables 1

Open a new Excel workbook and look for the Standard Toolbar.

Intro to Programming. Unit 7. What is Programming? What is Programming? Intro to Programming

MOVING FROM CELL TO CELL

CSCD 255 HW 2. No string (char arrays) or any other kinds of array variables are allowed

HippoDraw and Python

Introduction to Programming in C Department of Computer Science and Engineering. Lecture No. #29 Arrays in C

B. List An Introduction to C++ Page 1

PyROOT Automatic Python bindings for ROOT. Enric Tejedor, Stefan Wunsch, Guilherme Amadio for the ROOT team ROOT. Data Analysis Framework

Algebra of Sets (Mathematics & Logic A)

GOALS [HTDP/2e Chapters 1 through 3.5]

Transcription:

C++ programming for physicists ROOT: An object-orientated analysis framework PD Dr H Kroha, Dr J Dubbert, Dr M Flowerdew 1 Kroha, Dubbert, Flowerdew 14/04/11

What is ROOT? An object-orientated framework aimed at solving the data analysis challenges of high-energy physics Project started in the 1990's particularly aimed at the Large Hadron Collider experiments Designed for large-scale data analysis parallel processing of multi- Terabyte datasets Main components: C++ core classes CINT command-line interpreter PROOF, the Parallel ROOT Facility PyROOT, a python interface (recommended, but learn python first!) ROOT User's Guide 2 Kroha, Dubbert, Flowerdew 14/04/11

Links ROOT home page: http://root.cern.ch User's guide (pdf): http://root.cern.ch/drupal/content/users-guide ROOT reference guide: http://root.cern.ch/root/html/index.html Type a class or method name into the search box RootTalk forum (user help): http://root.cern.ch/phpbb3 Extra statistics packages: https://twiki.cern.ch/twiki/bin/view/roostats/webhome Some alternatives to ROOT (for non-hep physicists) are listed here: http://www.insectnation.org/howto/academic-software 3 Kroha, Dubbert, Flowerdew 14/04/11

Core C++ classes The main data types (classes) you will deal with are: TFile: database-like file, with.root suffix TTree and TNtuple: event-by-event record of variables TH1: binned histogram summary of data TF1: representation of a mathematical function TBrowser and TCanvas: Interactive graphical interfaces to the above TVector3 and TLorentzVector: 3- and 4-dimensional vectors (Nearly) any ROOT object can be saved in a TFile ROOT classes have a complex (and controversial) inheritance structure All histograms inherit from TH1 THnX = n-dimensional histogram of type X (eg TH1D, TH2I, TH3F, ) Functions TF2 and TF3 similarly inherit from TF1 The ROOT libraries can be used in your C++ program, but we will use ROOT interactively today 4 Kroha, Dubbert, Flowerdew 14/04/11

Initial setup Try to run ROOT: > root If you get this output, ROOT is not fully set up on your system: > root bash: root: command not found To fix it, use the alias command: > alias root=/opt/cern/root/bin/root Note: This is not the best solution, just the fastest 5 Kroha, Dubbert, Flowerdew 14/04/11

CINT, the C/C++ Interpreter Commands you run are in yellow Open a ROOT file on the command line: > root -l block_test.root root [0] Attaching file block_test.root as _file0... root [1] _ -l (ell, not one!) avoids splash screen CINT takes commands that look like C++ Not all valid C++ statements are supported Many illegal C++ statements are allowed Eg semi-colons at end of line is optional Some non-c++ commands exist to make your life easier root [1].ls TFile** block_test.root TFile* block_test.root KEY: TNtuple Ntuple;1 Block-N-Tuple root [2].q > _ List contents of TDirectory Exit ROOT 6 Kroha, Dubbert, Flowerdew 14/04/11

What's in a name? Look again at the file listing: root [1].ls TFile** block_test.root TFile* block_test.root KEY: TNtuple Ntuple;1 Block-N-Tuple These give the class names This is an instance name This is an instance title Most ROOT objects have a name (a C-string). In terms of class structure, this is a private class variable, and it is set when the object was first created. CINT uses the name as an identifier Pseudo-code: TNtuple* Ntuple = new TNtuple(...) Titles are human-readable descriptions of a particular instance 7 Kroha, Dubbert, Flowerdew 14/04/11

The interactive browser > root -l block_test.root root [0] Attaching file block_test.root as _file0... root [1] groot->setstyle( Plain ) root [2] TBrowser *b = new TBrowser Gets rid of nasty grey canvas background Note: Screenshots use ROOT version 5.28 + ATLAS style Older versions (eg 5.26) look different: try File New Browser if you want the new one 8 Kroha, Dubbert, Flowerdew 14/04/11

An ntuple In the browser, double-click on the file name (under ROOT Files ) and then the ntuple name This shows the structure of your saved TNtuple object The TFile object The TNtuple object Branches (or leaves ) of the ntuple The branches are filled for each event A TNtuple only holds float variables. A TTree can hold other types, including classes 9 Kroha, Dubbert, Flowerdew 14/04/11

First histogram On the CINT command line, type root [1] Ntuple->Draw( x_out ) Alternatively, double-click the variable in an open TBrowser Frequency Variable name Tip: The canvas is interactive try dragging and right-clicking different things 10 Kroha, Dubbert, Flowerdew 14/04/11

The draw panel Right click on the histogram itself Make sure to get the histogram, not the canvas! The first menu line says the name of the class and instance to help you In the menu, select the Draw Panel Here, you can easily change the display properties of the histogram Colour and size of the line and markers Display statistical errors on each point Modify the binning and axis range 11 Kroha, Dubbert, Flowerdew 14/04/11

Controlling the plot To choose a specific histogram binning: root [1] Ntuple->Draw( x_out>>h(50,-100,100) ) Two dimensional (scatter) plot: root [1] Ntuple->Draw( x_out:z_out ) Two dimensional histogram: Improve the colour palette: Histogram name Number of bins Minimum x x var Maximum x root [1] Ntuple->Draw( x_out:z_out>>h2(50,0,40, 50,-3,3,, COLZ ) root [2] gstyle->setpalette(1) root [3] h2->draw( COLZ ) 12 Kroha, Dubbert, Flowerdew 14/04/11 y var y var x var Histogram name Number of x bins Minimum x Etc... Invalid C++! (Why?)

Advanced plotting Functions of variables can also be drawn: root [1] Ntuple->Draw( E_out - E_in ) Apply a selection using the second argument: root [1] Ntuple->Draw( x_out, abs(z_out-40.0) < 0.001 ) Some obvious functions are implemented: abs, sqrt, cos, sin, Set some histogram properties: root [1] Ntuple->Draw( x_out:z_out>>h2(50,0,40, 50,- 3,3,, COLZ ) root [2] h2->getxaxis()->settitle( z position [mm] ) root [3] h2->getyaxis()->settitle( x position [mm] ) root [4] h2->draw( COLZ ) 13 Kroha, Dubbert, Flowerdew 14/04/11

The result Go to File Save As to save the image Output formats:.ps (postscript).eps.pdf.gif.jpg.png.c (CINT script).root 14 Kroha, Dubbert, Flowerdew 14/04/11

One more for fun 3- or even 4-dimensional plots are possible (note: your ntuples don't have y_out) root [1] Ntuple->Draw( x_out:y_out:z_out:e_in ) Colour is the fourth dimension (E_in) 15 Kroha, Dubbert, Flowerdew 14/04/11

TTree::Draw() TNtuple is derived from TTree, which defines this method: virtual long int TTree::Draw(const char * varexp, const char * selection =, const char * option =, long int nentries = 1000000000, long int firstentry = 0); NB: This is simplified for clarity ROOT has its own types for portable integers and C-strings Note that this means we can control which entries we plot too: root [1] Ntuple->Draw( x_out,,, 500, 1000) (Plot entries from 1000-1499 inclusive) 16 Kroha, Dubbert, Flowerdew 14/04/11

Fitting a histogram If we think a histogram has a certain shape (eg a Gaussian), we can try fitting it with a test function Right click on the histogram line and select Fit Panel Select the fit function to try Default gaus is a Gaussian More details on this and other options at http://root.cern.ch/root/html/tf1.html The fit range is usually important too A similar effect can be achieved on the command line: root [1] h1->fit( gaus,,, -1.5, 1.5) Gaussian fit for -1.5 x < 1.5 17 Kroha, Dubbert, Flowerdew 14/04/11

More on fitting Here is shown a Gaussian fit to this histogram: root [1] Ntuple->Draw( x_out, abs(z_out-40.0) < 0.001 ) The thick black line represents a TF1 object, which you can also manipulate in the canvas, like a histogram Always remember to ask if the fit looks reasonable, and if not, why not 18 Kroha, Dubbert, Flowerdew 14/04/11

Now over to you... What energy do the particles have... At the start? (z = 0) At the exit of each layer of material? What is the distribution of x at each point? Can you see the finite steps in z? Does the step size vary? Try plotting z_out with a cut on z_out Can you plot the path of just one particle? Hint: Remember you can control the first and last event plotted On a sample with lots of particles: can you understand your results in terms of the multiple scattering equations? S 1 2 d θ E, where θ E has a mean of zero and a standard deviation of θ 0 = 13.6 MeV E q d X 0 19 Kroha, Dubbert, Flowerdew 14/04/11