18x = ROOT.RooRealVar(
"x",
"x", 0.0, -3, 10)
24f = ROOT.RooPolyFunc(
"f",
"f", ROOT.RooArgList(x))
31f = ROOT.RooFormulaVar(
"f",
"f",
"pow(@0,4) -5 * pow(@0,3) +5 * pow(@0,2) + 5 * pow(@0,1) - 6", [x])
35taylor_o1 = ROOT.RooPolyFunc.taylorExpand(
"taylorfunc_o1",
"taylor expansion order 1", f, [x], 1, [x0])
36ROOT.SetOwnership(taylor_o1,
True)
37taylor_o2 = ROOT.RooPolyFunc.taylorExpand(
"taylorfunc_o2",
"taylor expansion order 2", f, [x], 2, [x0])
38ROOT.SetOwnership(taylor_o2,
True)
39frame = x.frame(Title=
"x^{4} - 5x^{3} + 5x^{2} + 5x - 6")
40c = ROOT.TCanvas(
"c",
"c", 400, 400)
42f.plotOn(frame, Name=
"f")
43taylor_o1.plotOn(frame, Name=
"taylor_o1", LineColor=
"kRed", LineStyle=
"kDashed")
44taylor_o2.plotOn(frame, Name=
"taylor_o2", LineColor=
"kRed - 9", LineStyle=
"kDotted")
49frame.SetYTitle(
"function value")
52legend = ROOT.TLegend(0.53, 0.73, 0.86, 0.87)
53legend.SetFillColor(ROOT.kWhite)
54legend.SetLineColor(ROOT.kWhite)
55legend.SetTextSize(0.02)
56legend.AddEntry(
"taylor_o1",
"Taylor expansion upto first order",
"L")
57legend.AddEntry(
"taylor_o2",
"Taylor expansion upto second order",
"L")
58legend.AddEntry(
"f",
"Polynomial of fourth order",
"L")
62c.SaveAs(
"rf710_roopoly.png")