fitting procedure using root department of high energy physics nekrasov m. dmitriy

17
Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Upload: cuthbert-fields

Post on 17-Dec-2015

213 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Fitting procedure using ROOT

Department of High Energy Physics

Nekrasov M. Dmitriy

Page 2: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Contents

Why ROOT (brief review) The Fit Panel The Fit Method Fit with the Predefined Function Combining Functions References

Page 3: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Why ROOT?

Having had many years of experience in developing the

interactive data analysis systems like PAW and the

simulation package GEANT, we realized that the growth

and maintainability of these products, written in FORTRAN

and using some 20 year old libraries, had reached its limit.

Although still very popular, these systems do not scale up

to the challenges offered by the LHC, where the amount

of data to be simulated and analyzed is a few orders of

magnitude larger than anything seen before.

Page 4: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Started ROOT

It became time to re-think our approach to large scale data analysis and simulation and at the same time we had to profit from the progress made in computer science over the past 15 to 20 years. Especially in the area of Object-Oriented design and development. Thus was born ROOT. We started the ROOT project in the context of the NA49 experiment at CERN. NA49 generates an impressive amount of data,about 10 Terabytes of raw data per run. This data rate is of the same order of magnitude as the rates expected to be recorded by the LHC experiments. Therefore, NA49 is an ideal environment to develop andtest the next generation data analysis tools and to study the problems related to the organization and analysis of such large amounts of data.

Page 5: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

With ROOT we try to provide a basic framework that offers a common set of features and tools for all domains shown in the figure below

Page 6: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

ROOT: Executive Summary

The ROOT system provides a set of OO frameworks with all the functionality needed to handle and analyse large amounts of data in a very efficient way. Having the data defined as a set of objects, specialised storage methods are used to get direct access to the separate attributes of the selected objects, without having to touch the bulk of the data. Included are: histograming methods in 1, 2 and 3 dimensions, curve fitting, function evaluation, minimisation, graphics and visualization classes to allow the easy setup of an analysis system that can query and process the data interactively or in batch mode.

Page 7: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

The Fit Panel

The first sets of buttons are the predefined functions

of ROOT that can be used to fit the histogram.

You have a choice of several polynomials, a Gaussian,

a landau, and an exponential function. You can also define

a function and call it "user". It will be linked to the user

button on this panel. You have the option to specify Quiet or Verbose

This is the amount of feedback printed on the root

command line on the result of the fit. When a fit is

executed the image of the function is drawn on the

current pad. By default the image of the histogram

is replaced with the image of the function. Select

Same Picture to see the function drawn and the

histogram on the same picture.

Page 8: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Fit Panel (continue)

Select W: Set all weights to 1, to set all errors to 1. Select E: Compute best errors, to compute best errors. When fitting a histogram, the function is attached to the histogram's list of functions. By default the previouslyfitted function is deleted and replaced with the most recent one, so the list only contains one function. You can select + : Add to list of functions to add the newly fitted function to the existing list of functions for the histogram. Select N: Do not store/draw function to avoid adding the function to the histogram and to avoid drawing it. Select 0: Do not draw function to avoid drawing the result of the fit. Select L: Log Likelihood to use log likelihood method (default is chisquare method).

Page 9: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Fit Panel (end)

The slider at the bottom of the panel allows you to set

a range for the fit. Drag the edges of the slider towards the

center to narrow the range.

Draw the entire range to change the beginning and end.

To returns to the original setting, you need to press

Defaults. To apply the fit, press the Fit button.

Page 10: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

To fit a histogram programmatically, you can use the TH1::Fit method. Here is thesignature of TH1::Fit and an explanation of the parameters:

void Fit(const char *fname ,Option_t *option,Option_t *goption,Axis_t xxmin,Axis_t xxmax)*fname: The name of the fitted function (the model) is passed as the first parameter. Thisname may be one of ROOT pre-defined function names or a user-defined function.The following functions are predefined, and can be used with the TH1::Fit method. • gaus: A Gaussian function with 3 parameters:f(x) = p0*exp(-0.5*((x-p1)/p2)^2)) • expo: An exponential with 2 parameters:f(x) = exp(p0+p1*x). • polN: A polynomial of degree N:f(x) = p0 + p1*x + p2*x^2 +... • landau: A Landau function with mean and sigma. This function has been adaptedfrom the CERNLIB. *option: The second parameter is the fitting option. Here is the list of fitting options:- "W" Set all errors to 1- "I" Use integral of function in bin instead of value at bin center- "L" Use log likelihood method (default is chi-square method)- "U" Use a user specified fitting algorithm-etc. Fourth and fifth parameters specify the range over which to apply the fit.By default, the fitting function object is added to the histogram and is drawn in the current pad

The Fit Method

Page 11: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Fit with a Predefined Function

To fit a histogram with a predefined function, simply pass

the name of the function in the first parameter of

TH1::Fit.

For example, this line fits histogram object hist with a

Gaussian.

root[] hist.Fit("gaus");

For pre-defined functions, there is no need to set initial

values for the parameters, it is done automatically.

Page 12: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Fit with a User-Defined Function

You can create a TF1 object and use it in the call the

TH1::Fit.

The parameter in to the fit method is the NAME of the

TF1 object.

Page 13: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Combining Functions

You can combine functions to fit a histogram with their sum.We have a function that is the combination of a background and lorenzian peak. Each function contributes 3 parameters.y(E) = a1 + a2E + a3E2 + AP (G / 2 p)/( (E-m)2 + (G/2)2)background lorenzianPeakpar[0] = a1 par[0] = APpar[1] = a2 par[1] = Gpar[2] = a3 par[2] = mThe combination function (fitFunction) has six parameters:fitFunction = background (x, par ) + lorenzianPeak (x, &par[3])par[0] = a1par[1] = a2par[2] = a3par[3] = Appar[4] = Gpar[5] = m

Page 14: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Result:

Page 15: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

Fitting Example

Page 16: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

References

www.root.cern.ch

Page 17: Fitting procedure using ROOT Department of High Energy Physics Nekrasov M. Dmitriy

// gROOT->Reset(); c1 = new TCanvas("c1","The Fit Canvas",200,10,700,500); c1->SetGridx(); c1->SetGridy(); c1->GetFrame()->SetFillColor(21); c1->GetFrame()->SetBorderMode(-1); c1->GetFrame()->SetBorderSize(5); gBenchmark->Start("fit1"); // // We connect the ROOT file generated in a previous tutorial // (see Filling histograms with random numbers from a functon) // TFile fill("fillrandom.root"); // // The function "ls()" lists the directory contents of this file // fill.ls(); // // Get object "sqroot" from the file. Undefined objects are searched // for using gROOT->FindObject("xxx"), e.g.: // TF1 sqroot = (TF1*) gROOT.FindObject("sqroot") // sqroot->Print();// // Now fit histogram h1f with the function sqroot // h1f->SetFillColor(45); h1f->Fit("sqroot"); // We now annotate the picture by creating a PaveText object // and displaying the list of commands in this macro // fitlabel = new TPaveText(0.6,0.3,0.9,0.80,"NDC"); fitlabel->SetTextAlign(12); fitlabel->SetFillColor(42); fitlabel->ReadFile("fit1_C.C"); fitlabel->Draw(); c1->Update();gBenchmark->Show("fit1");