ROOT
v6-32
Reference Guide
Loading...
Searching...
No Matches
rf101_basics.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit
3
## \notebook
4
## This tutorial illustrates the basic features of RooFit.
5
##
6
## \macro_image
7
## \macro_code
8
## \macro_output
9
##
10
## \date February 2018
11
## \authors Clemens Lange, Wouter Verkerke (C++ version)
12
13
import
ROOT
14
15
# Set up model
16
# ---------------------
17
# Declare variables x,mean,sigma with associated name, title, initial
18
# value and allowed range
19
x =
ROOT.RooRealVar
(
"x"
,
"x"
, -10, 10)
20
mean =
ROOT.RooRealVar
(
"mean"
,
"mean of gaussian"
, 1, -10, 10)
21
sigma =
ROOT.RooRealVar
(
"sigma"
,
"width of gaussian"
, 1, 0.1, 10)
22
23
# Build gaussian pdf in terms of x,mean and sigma
24
gauss =
ROOT.RooGaussian
(
"gauss"
,
"gaussian PDF"
, x, mean, sigma)
25
26
# Construct plot frame in 'x'
27
xframe =
x.frame
(Title=
"Gaussian pdf"
)
# RooPlot
28
29
# Plot model and change parameter values
30
# ---------------------------------------------------------------------------
31
# Plot gauss in frame (i.e. in x)
32
gauss.plotOn
(xframe)
33
34
# Change the value of sigma to 3
35
sigma.setVal
(3)
36
37
# Plot gauss in frame (i.e. in x) and draw frame on canvas
38
gauss.plotOn
(xframe, LineColor=
"r"
)
39
40
# Generate events
41
# -----------------------------
42
# Generate a dataset of 1000 events in x from gauss
43
data =
gauss.generate
({x}, 10000)
# ROOT.RooDataSet
44
45
# Make a second plot frame in x and draw both the
46
# data and the pdf in the frame
47
xframe2 =
x.frame
(Title=
"Gaussian pdf with data"
)
# RooPlot
48
data.plotOn
(xframe2)
49
gauss.plotOn
(xframe2)
50
51
# Fit model to data
52
# -----------------------------
53
# Fit pdf to data
54
gauss.fitTo
(data, PrintLevel=-1)
55
56
# Print values of mean and sigma (that now reflect fitted values and
57
# errors)
58
mean.Print
()
59
sigma.Print
()
60
61
# Draw all frames on a canvas
62
c =
ROOT.TCanvas
(
"rf101_basics"
,
"rf101_basics"
, 800, 400)
63
c.Divide
(2)
64
c.cd
(1)
65
ROOT.gPad.SetLeftMargin
(0.15)
66
xframe.GetYaxis
().SetTitleOffset(1.6)
67
xframe.Draw
()
68
c.cd
(2)
69
ROOT.gPad.SetLeftMargin
(0.15)
70
xframe2.GetYaxis
().SetTitleOffset(1.6)
71
xframe2.Draw
()
72
73
c.SaveAs
(
"rf101_basics.png"
)
TRangeDynCast
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Definition
TCollection.h:358
tutorials
roofit
rf101_basics.py
ROOT v6-32 - Reference Guide Generated on Thu Mar 13 2025 14:14:36 (GVA Time) using Doxygen 1.10.0