ROOT
master
Reference Guide
Loading...
Searching...
No Matches
rf710_roopoly.py
Go to the documentation of this file.
1
## \file
2
## \ingroup tutorial_roofit_main
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
ROOT.SetOwnership
(taylor_o1,
True
)
37
taylor_o2 =
ROOT.RooPolyFunc.taylorExpand
(
"taylorfunc_o2"
,
"taylor expansion order 2"
, f, [x], 2, [x0])
38
ROOT.SetOwnership
(taylor_o2,
True
)
39
frame =
x.frame
(Title=
"x^{4} - 5x^{3} + 5x^{2} + 5x - 6"
)
40
c =
ROOT.TCanvas
(
"c"
,
"c"
, 400, 400)
41
42
f.plotOn
(frame, Name=
"f"
)
43
taylor_o1.plotOn
(frame, Name=
"taylor_o1"
, LineColor=
"kRed"
, LineStyle=
"kDashed"
)
44
taylor_o2.plotOn
(frame, Name=
"taylor_o2"
, LineColor=
"kRed-9"
, LineStyle=
"kDotted"
)
45
46
c.cd
()
47
frame.SetMinimum
(-8.0)
48
frame.SetMaximum
(+8.0)
49
frame.SetYTitle
(
"function value"
)
50
frame.Draw
()
51
52
legend =
ROOT.TLegend
(0.53, 0.73, 0.86, 0.87)
53
legend.SetFillColor
(
"w"
)
54
legend.SetLineColor
(
"w"
)
55
legend.SetTextSize
(0.02)
56
legend.AddEntry
(
"taylor_o1"
,
"Taylor expansion upto first order"
,
"L"
)
57
legend.AddEntry
(
"taylor_o2"
,
"Taylor expansion upto second order"
,
"L"
)
58
legend.AddEntry
(
"f"
,
"Polynomial of fourth order"
,
"L"
)
59
legend.Draw
()
60
61
c.Draw
()
62
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
roofit
rf710_roopoly.py
ROOT master - Reference Guide Generated on Fri May 16 2025 16:28:12 (GVA Time) using Doxygen 1.10.0