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
rf710_roopoly.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit
3
## \notebook
4
## Taylor expansion of RooFit functions using the taylorExpand function
5
##
6
## \macro_image
7
## \macro_code
8
## \macro_output
9
##
10
## \date November 2021
11
## \author Rahul Balasubramanian
12
13
import
ROOT
14
15
# Create functions
16
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
17
18
x =
ROOT.RooRealVar
(
"x"
,
"x"
, 0.0, -3, 10)
19
20
# RooPolyFunc polynomial
21
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
22
# x ^ 4 - 5x ^ 3 + 5x ^ 2 + 5x - 6
23
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
24
f =
ROOT.RooPolyFunc
(
"f"
,
"f"
,
ROOT.RooArgList
(x))
25
f.addTerm
(+1, x, 4)
26
f.addTerm
(-5, x, 3)
27
f.addTerm
(+5, x, 2)
28
f.addTerm
(+5, x, 1)
29
f.addTerm
(-6, x, 0)
30
31
f =
ROOT.RooFormulaVar
(
"f"
,
"f"
,
"pow(@0,4) -5 * pow(@0,3) +5 * pow(@0,2) + 5 * pow(@0,1) - 6"
, [x])
32
# taylor expand around x0 = 0
33
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -
34
x0 = 2.0
35
taylor_o1 =
ROOT.RooPolyFunc.taylorExpand
(
"taylorfunc_o1"
,
"taylor expansion order 1"
, f, [x], 1, [x0])
36
taylor_o2 =
ROOT.RooPolyFunc.taylorExpand
(
"taylorfunc_o2"
,
"taylor expansion order 2"
, f, [x], 2, [x0])
37
frame =
x.frame
(Title=
"x^{4} - 5x^{3} + 5x^{2} + 5x - 6"
)
38
c =
ROOT.TCanvas
(
"c"
,
"c"
, 400, 400)
39
40
f.plotOn
(frame, Name=
"f"
)
41
taylor_o1.plotOn
(frame, Name=
"taylor_o1"
, LineColor=
"kRed"
, LineStyle=
"kDashed"
)
42
taylor_o2.plotOn
(frame, Name=
"taylor_o2"
, LineColor=
"kRed - 9"
, LineStyle=
"kDotted"
)
43
44
c.cd
()
45
frame.SetMinimum
(-8.0)
46
frame.SetMaximum
(+8.0)
47
frame.SetYTitle
(
"function value"
)
48
frame.Draw
()
49
50
legend =
ROOT.TLegend
(0.53, 0.73, 0.86, 0.87)
51
legend.SetFillColor
(
ROOT.kWhite
)
52
legend.SetLineColor
(
ROOT.kWhite
)
53
legend.SetTextSize
(0.02)
54
legend.AddEntry
(
"taylor_o1"
,
"Taylor expansion upto first order"
,
"L"
)
55
legend.AddEntry
(
"taylor_o2"
,
"Taylor expansion upto second order"
,
"L"
)
56
legend.AddEntry
(
"f"
,
"Polynomial of fourth order"
,
"L"
)
57
legend.Draw
()
58
59
c.Draw
()
60
c.SaveAs
(
"rf710_roopoly.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
rf710_roopoly.py
ROOT v6-32 - Reference Guide Generated on Sun Mar 30 2025 15:10:43 (GVA Time) using Doxygen 1.10.0