rf111_derivatives

Basic functionality: numerical 1st, and 3rd order derivatives w.r.t. observables and parameters

pdf = gauss(x,m,s)

Author: Clemens Lange, Wouter Verkerke (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, November 30, 2022 at 11:22 AM.

In [1]:
import ROOT
Welcome to JupyROOT 6.27/01

Set up model

Declare variables x,mean, with associated name, title, value and allowed range

In [2]:
x = ROOT.RooRealVar("x", "x", -10, 10)
mean = ROOT.RooRealVar("mean", "mean of gaussian", 1, -10, 10)
sigma = ROOT.RooRealVar("sigma", "width of gaussian", 1, 0.1, 10)

Build gaussian pdf in terms of x, and sigma

In [3]:
gauss = ROOT.RooGaussian("gauss", "gaussian PDF", x, mean, sigma)

Create and plot derivatives w.r.t. x

Derivative of normalized gauss(x) w.r.t. observable x

In [4]:
dgdx = gauss.derivative(x, 1)

Second and third derivative of normalized gauss(x) w.r.t. observable x

In [5]:
d2gdx2 = gauss.derivative(x, 2)
d3gdx3 = gauss.derivative(x, 3)

Construct plot frame in 'x'

In [6]:
xframe = x.frame(Title="d(Gauss)/dx")

Plot gauss in frame (i.e. in x)

In [7]:
gauss.plotOn(xframe)
Out[7]:
<cppyy.gbl.RooPlot object at 0x9933080>

Plot derivatives in same frame

In [8]:
dgdx.plotOn(xframe, LineColor="m")
d2gdx2.plotOn(xframe, LineColor="r")
d3gdx3.plotOn(xframe, LineColor="kOrange")
Out[8]:
<cppyy.gbl.RooPlot object at 0x9933080>

Create and plot derivatives w.r.t. sigma

Derivative of normalized gauss(x) w.r.t. parameter sigma

In [9]:
dgds = gauss.derivative(sigma, 1)

Second and third derivative of normalized gauss(x) w.r.t. parameter sigma

In [10]:
d2gds2 = gauss.derivative(sigma, 2)
d3gds3 = gauss.derivative(sigma, 3)

Construct plot frame in 'sigma'

In [11]:
sframe = sigma.frame(Title="d(Gauss)/d(sigma)", Range=(0.0, 2.0))

Plot gauss in frame (i.e. in x)

In [12]:
gauss.plotOn(sframe)
Out[12]:
<cppyy.gbl.RooPlot object at 0x9bdd560>
[#1] INFO:NumericIntegration -- RooRealIntegral::init(gauss_Int[sigma]) using numeric integrator RooIntegrator1D to calculate Int(sigma)

Plot derivatives in same frame

In [13]:
dgds.plotOn(sframe, LineColor="m")
d2gds2.plotOn(sframe, LineColor="r")
d3gds3.plotOn(sframe, LineColor="kOrange")
Out[13]:
<cppyy.gbl.RooPlot object at 0x9bdd560>

Draw all frames on a canvas

In [14]:
c = ROOT.TCanvas("rf111_derivatives", "rf111_derivatives", 800, 400)
c.Divide(2)
c.cd(1)
ROOT.gPad.SetLeftMargin(0.15)
xframe.GetYaxis().SetTitleOffset(1.6)
xframe.Draw()
c.cd(2)
ROOT.gPad.SetLeftMargin(0.15)
sframe.GetYaxis().SetTitleOffset(1.6)
sframe.Draw()

c.SaveAs("rf111_derivatives.png")
Info in <TCanvas::Print>: png file rf111_derivatives.png has been created

Draw all canvases

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