import ROOT
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)
gauss = ROOT.RooGaussian("gauss", "gaussian PDF", x, mean, sigma)
dgdx = gauss.derivative(x, 1)
d2gdx2 = gauss.derivative(x, 2)
d3gdx3 = gauss.derivative(x, 3)
xframe = x.frame(ROOT.RooFit.Title("d(Gauss)/dx"))
gauss.plotOn(xframe)
dgdx.plotOn(xframe, ROOT.RooFit.LineColor(ROOT.kMagenta))
d2gdx2.plotOn(xframe, ROOT.RooFit.LineColor(ROOT.kRed))
d3gdx3.plotOn(xframe, ROOT.RooFit.LineColor(ROOT.kOrange))
dgds = gauss.derivative(sigma, 1)
d2gds2 = gauss.derivative(sigma, 2)
d3gds3 = gauss.derivative(sigma, 3)
sframe = sigma.frame(ROOT.RooFit.Title(
"d(Gauss)/d(sigma)"), ROOT.RooFit.Range(0., 2.))
gauss.plotOn(sframe)
dgds.plotOn(sframe, ROOT.RooFit.LineColor(ROOT.kMagenta))
d2gds2.plotOn(sframe, ROOT.RooFit.LineColor(ROOT.kRed))
d3gds3.plotOn(sframe, ROOT.RooFit.LineColor(ROOT.kOrange))
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")