ROOT
Version v6.32
master
v6.34
v6.30
v6.28
v6.26
v6.24
v6.22
v6.20
v6.18
v6.16
v6.14
v6.12
v6.10
v6.08
v6.06
Reference Guide
►
ROOT
•
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Modules
Pages
Loading...
Searching...
No Matches
rf111_derivatives.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit
3
## \notebook
4
## Basic functionality: numerical 1st, and 3rd order derivatives w.r.t. observables and parameters
5
##
6
## ```
7
## pdf = gauss(x,m,s)
8
## ```
9
##
10
## \macro_image
11
## \macro_code
12
## \macro_output
13
##
14
## \date February 2018
15
## \authors Clemens Lange, Wouter Verkerke (C++ version)
16
17
import
ROOT
18
19
# Set up model
20
# ---------------------
21
22
# Declare variables x,mean, with associated name, title, value and allowed
23
# range
24
x =
ROOT.RooRealVar
(
"x"
,
"x"
, -10, 10)
25
mean =
ROOT.RooRealVar
(
"mean"
,
"mean of gaussian"
, 1, -10, 10)
26
sigma =
ROOT.RooRealVar
(
"sigma"
,
"width of gaussian"
, 1, 0.1, 10)
27
28
# Build gaussian pdf in terms of x, and sigma
29
gauss =
ROOT.RooGaussian
(
"gauss"
,
"gaussian PDF"
, x, mean, sigma)
30
31
# Create and plot derivatives w.r.t. x
32
# ----------------------------------------------------------------------
33
34
# Derivative of normalized gauss(x) w.r.t. observable x
35
dgdx =
gauss.derivative
(x, 1)
36
37
# Second and third derivative of normalized gauss(x) w.r.t. observable x
38
d2gdx2 =
gauss.derivative
(x, 2)
39
d3gdx3 =
gauss.derivative
(x, 3)
40
41
# Construct plot frame in 'x'
42
xframe =
x.frame
(Title=
"d(Gauss)/dx"
)
43
44
# Plot gauss in frame (i.e. in x)
45
gauss.plotOn
(xframe)
46
47
# Plot derivatives in same frame
48
dgdx.plotOn
(xframe, LineColor=
"m"
)
49
d2gdx2.plotOn
(xframe, LineColor=
"r"
)
50
d3gdx3.plotOn
(xframe, LineColor=
"kOrange"
)
51
52
# Create and plot derivatives w.r.t. sigma
53
# ------------------------------------------------------------------------------
54
55
# Derivative of normalized gauss(x) w.r.t. parameter sigma
56
dgds =
gauss.derivative
(sigma, 1)
57
58
# Second and third derivative of normalized gauss(x) w.r.t. parameter sigma
59
d2gds2 =
gauss.derivative
(sigma, 2)
60
d3gds3 =
gauss.derivative
(sigma, 3)
61
62
# Construct plot frame in 'sigma'
63
sframe =
sigma.frame
(Title=
"d(Gauss)/d(sigma)"
, Range=(0.0, 2.0))
64
65
# Plot gauss in frame (i.e. in x)
66
gauss.plotOn
(sframe)
67
68
# Plot derivatives in same frame
69
dgds.plotOn
(sframe, LineColor=
"m"
)
70
d2gds2.plotOn
(sframe, LineColor=
"r"
)
71
d3gds3.plotOn
(sframe, LineColor=
"kOrange"
)
72
73
# Draw all frames on a canvas
74
c =
ROOT.TCanvas
(
"rf111_derivatives"
,
"rf111_derivatives"
, 800, 400)
75
c.Divide
(2)
76
c.cd
(1)
77
ROOT.gPad.SetLeftMargin
(0.15)
78
xframe.GetYaxis
().SetTitleOffset(1.6)
79
xframe.Draw
()
80
c.cd
(2)
81
ROOT.gPad.SetLeftMargin
(0.15)
82
sframe.GetYaxis
().SetTitleOffset(1.6)
83
sframe.Draw
()
84
85
c.SaveAs
(
"rf111_derivatives.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
rf111_derivatives.py
ROOT v6-32 - Reference Guide Generated on Fri Mar 21 2025 05:17:58 (GVA Time) using Doxygen 1.10.0