TWiki> Main Web>WebPreferences>RootIRMMTutorial2013>RootIRMMTutorial2013RooFitExercises (revision 2)~~Edit~~~~Attach~~~~PDF~~

Roofit Exercises
# Fitting using RooFit

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

## Exercise 2: Reading a workspace from a file

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

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.

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.

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.

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.

Topic revision: r2 - 2013-02-28 - LorenzoMoneta

**Webs**

- ABATBEA
- ACPP
- ADCgroup
- AEGIS
- AfricaMap
- AgileInfrastructure
- ALICE
- AliceEbyE
- AliceSPD
- AliceSSD
- AliceTOF
- AliFemto
- ALPHA
- ArdaGrid
- ASACUSA
- AthenaFCalTBAna
- Atlas
- AtlasLBNL
- AXIALPET
- CAE
- CALICE
- CDS
- CENF
- CERNSearch
- CLIC
- Cloud
- CloudServices
- CMS
- Controls
- CTA
- CvmFS
- DB
- DefaultWeb
- DESgroup
- DPHEP
- DM-LHC
- DSSGroup
- EGEE
- EgeePtf
- ELFms
- EMI
- ETICS
- FIOgroup
- FlukaTeam
- Frontier
- Gaudi
- GeneratorServices
- GuidesInfo
- HardwareLabs
- HCC
- HEPIX
- ILCBDSColl
- ILCTPC
- IMWG
- Inspire
- IPv6
- IT
- ItCommTeam
- ITCoord
- ITdeptTechForum
- ITDRP
- ITGT
- ITSDC
- LAr
- LCG
- LCGAAWorkbook
- Leade
- LHCAccess
- LHCAtHome
- LHCb
- LHCgas
- LHCONE
- LHCOPN
- LinuxSupport
- Main
- Medipix
- Messaging
- MPGD
- NA49
- NA61
- NA62
- NTOF
- Openlab
- PDBService
- Persistency
- PESgroup
- Plugins
- PSAccess
- PSBUpgrade
- R2Eproject
- RCTF
- RD42
- RFCond12
- RFLowLevel
- ROXIE
- Sandbox
- SocialActivities
- SPI
- SRMDev
- SSM
- Student
- SuperComputing
- Support
- SwfCatalogue
- TMVA
- TOTEM
- TWiki
- UNOSAT
- Virtualization
- VOBox
- WITCH
- XTCA

Welcome Guest

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

or Ideas, requests, problems regarding TWiki? use Discourse or Send feedback