EditAttachPDF
Roofit Exercises

# Fitting using RooFit

Welcome to the hands-on session dedicated on fitting using RooFit. The aim is just to start familiarizing with RooFit and to understand the basic syntax of creating models using the workspace factory.

## Exercise 1: Gaussian model and fit it to random generated data

We will start with a similar exercise we did for Root fitting. We will create a Gaussian model, generate a pseudo-data set and then fit this data set.

Start, following the syntax shown in the lecture sildes to create a `RooWorkspace`, then using the factory method create a Gaussian p.d.f. With parameters mu=1 and sigma=2.

Using the `generate()` method of a `RooAbsPdf` generate 1000 events.

Try to plot the data set using `RooPlot`.

After, fit the model to the data and show the resulting fitted function.

Save the model in a Root file.

factory.

## Exercise 2: Reading a workspace from a file

Open the file you have just created in the previous exercise and get the `RooWorkspace` object ffrom the file. Get a pointer to the p.d.f describing your model, and a pointer to the data. Re-fit the data, but this time in the range [0,10] and plot the result.

## Exercise 3: Fitting the spectrum histogram with background and gaussian peaks

We are now to re-use the sub-histogram we have created with the IRMM data yesterday. We need first to import the histogram in a RooFit data object, the `RooDataHist`. See the lecture slide 13 on how to do this.

For fitting, we need to build the background plus signal model. We need first to build the single pdf for the signal (Gaussian) and then the p.d.f for the background (Polynomial). It is reccomended to use the Chebyshev polynomial, which are orthogonal and make the fit more robust (see slide 24 on how to do it). Again is better to fit the single components first and then the overall model. Note that the parameters in RooFit are shared between all the functions in the workspace. After fitting a single component p.d.f you don't need to set the parameters in the big sum p.d.f.

Roofit automatically parametrizes also the pdf as normalized ones, so the number of peak signal events is always fitted from the data.

Compare what you obtain in terms of signal events with what we obtain in exercise 1 yesterday.

Edit | Attach | Watch | Print version |  | Backlinks | Raw View | Raw edit | More topic actions...
Topic revision: r2 - 2013-02-28 - LorenzoMoneta

Webs

Welcome Guest

 Cern Search TWiki Search Google Search Main All webs
Copyright &© 2008-2021 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback