# rf710_roopoly¶

Taylor expansion of RooFit functions using the taylorExpand function

Author: Rahul Balasubramanian
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Sunday, November 27, 2022 at 11:08 AM.

In [1]:
import ROOT

Welcome to JupyROOT 6.27/01


Create functions

In [2]:
x = ROOT.RooRealVar("x", "x", 0.0, -3, 10)


RooPolyFunc polynomial

x ^ 4 - 5x ^ 3 + 5x ^ 2 + 5x - 6

In [3]:
f = ROOT.RooPolyFunc("f", "f", ROOT.RooArgList(x))

f = ROOT.RooFormulaVar("f", "f", "pow(@0,4) -5 * pow(@0,3) +5 * pow(@0,2) + 5 * pow(@0,1) - 6", [x])


taylor expand around x0 = 0

In [4]:
x0 = 2.0
taylor_o1 = ROOT.RooPolyFunc.taylorExpand("taylorfunc_o1", "taylor expansion order 1", f, ROOT.RooArgSet(x), x0, 1)
taylor_o2 = ROOT.RooPolyFunc.taylorExpand("taylorfunc_o2", "taylor expansion order 2", f, ROOT.RooArgSet(x), x0, 2)
frame = x.frame(Title="x^{4} - 5x^{3} + 5x^{2} + 5x - 6")
c = ROOT.TCanvas("c", "c", 400, 400)

f.plotOn(frame, Name="f")
taylor_o1.plotOn(frame, Name="taylor_o1", LineColor="kRed", LineStyle="kDashed")
taylor_o2.plotOn(frame, Name="taylor_o2", LineColor="kRed - 9", LineStyle="kDotted")

c.cd()
frame.SetMinimum(-8.0)
frame.SetMaximum(+8.0)
frame.SetYTitle("function value")
frame.Draw()

legend = ROOT.TLegend(0.53, 0.73, 0.86, 0.87)
legend.SetFillColor(ROOT.kWhite)
legend.SetLineColor(ROOT.kWhite)
legend.SetTextSize(0.02)
legend.AddEntry("taylor_o1", "Taylor expansion upto first order", "L")
legend.AddEntry("taylor_o2", "Taylor expansion upto second order", "L")
legend.AddEntry("f", "Polynomial of fourth order", "L")
legend.Draw()

c.Draw()
c.SaveAs("rf710_roopoly.png")

Info in <TCanvas::Print>: png file rf710_roopoly.png has been created


Draw all canvases

In [5]:
from ROOT import gROOT
gROOT.GetListOfCanvases().Draw()