Rf 1 1 1_Derivatives

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

 pdf = gauss(x,m,s)

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Monday, January 17, 2022 at 09:52 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "RooPlot.h"
In [2]:
%%cpp -d
// This is a workaround to make sure the namespace is used inside functions
using namespace RooFit;

Setup model

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

In [3]:
RooRealVar x("x", "x", -10, 10);
RooRealVar mean("mean", "mean of gaussian", 1, -10, 10);
RooRealVar sigma("sigma", "width of gaussian", 1, 0.1, 10);
RooFit v3.60 -- Developed by Wouter Verkerke and David Kirkby 
                Copyright (C) 2000-2013 NIKHEF, University of California & Stanford University
                All rights reserved, please read http://roofit.sourceforge.net/license.txt

Build gaussian pdf in terms of x,mean and sigma

In [4]:
RooGaussian gauss("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 [5]:
RooAbsReal *dgdx = gauss.derivative(x, 1);

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

In [6]:
RooAbsReal *d2gdx2 = gauss.derivative(x, 2);
RooAbsReal *d3gdx3 = gauss.derivative(x, 3);

Construct plot frame in 'x'

In [7]:
RooPlot *xframe = x.frame(Title("d(Gauss)/dx"));

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

In [8]:
gauss.plotOn(xframe);

Plot derivatives in same frame

In [9]:
dgdx->plotOn(xframe, LineColor(kMagenta));
d2gdx2->plotOn(xframe, LineColor(kRed));
d3gdx3->plotOn(xframe, LineColor(kOrange));

Create and plot derivatives w.r.t. sigma

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

In [10]:
RooAbsReal *dgds = gauss.derivative(sigma, 1);

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

In [11]:
RooAbsReal *d2gds2 = gauss.derivative(sigma, 2);
RooAbsReal *d3gds3 = gauss.derivative(sigma, 3);

Construct plot frame in 'sigma'

In [12]:
RooPlot *sframe = sigma.frame(Title("d(Gauss)/d(sigma)"), Range(0., 2.));

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

In [13]:
gauss.plotOn(sframe);
[#1] INFO:NumericIntegration -- RooRealIntegral::init(gauss_Int[sigma]) using numeric integrator RooIntegrator1D to calculate Int(sigma)

Plot derivatives in same frame

In [14]:
dgds->plotOn(sframe, LineColor(kMagenta));
d2gds2->plotOn(sframe, LineColor(kRed));
d3gds3->plotOn(sframe, LineColor(kOrange));

Draw all frames on a canvas

In [15]:
TCanvas *c = new TCanvas("rf111_derivatives", "rf111_derivatives", 800, 400);
c->Divide(2);
c->cd(1);
gPad->SetLeftMargin(0.15);
xframe->GetYaxis()->SetTitleOffset(1.6);
xframe->Draw();
c->cd(2);
gPad->SetLeftMargin(0.15);
sframe->GetYaxis()->SetTitleOffset(1.6);
sframe->Draw();

Draw all canvases

In [16]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()