Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf111_derivatives.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit_main
3/// \notebook -js
4/// Basic functionality: numerical 1st,2nd and 3rd order derivatives w.r.t. observables and parameters
5///
6/// ```
7/// pdf = gauss(x,m,s)
8/// ```
9///
10/// \macro_image
11/// \macro_code
12/// \macro_output
13///
14/// \date July 2008
15/// \author Wouter Verkerke
16
17#include "RooDerivative.h"
18#include "RooRealVar.h"
19#include "RooDataSet.h"
20#include "RooGaussian.h"
21#include "RooPlot.h"
22
23#include "TCanvas.h"
24#include "TAxis.h"
25
26using namespace RooFit;
27
28void rf111_derivatives()
29{
30 // S e t u p m o d e l
31 // ---------------------
32
33 // Declare variables x,mean,sigma with associated name, title, initial value and allowed range
34 RooRealVar x("x", "x", -10, 10);
35 RooRealVar mean("mean", "mean of gaussian", 1, -10, 10);
36 RooRealVar sigma("sigma", "width of gaussian", 1, 0.1, 10);
37
38 // Build gaussian pdf in terms of x,mean and sigma
39 RooGaussian gauss("gauss", "gaussian PDF", x, mean, sigma);
40
41 // C r e a t e a n d p l o t d e r i v a t i v e s w . r . t . x
42 // ----------------------------------------------------------------------
43
44 // Derivative of normalized gauss(x) w.r.t. observable x
45 RooAbsReal *dgdx = gauss.derivative(x, 1);
46
47 // Second and third derivative of normalized gauss(x) w.r.t. observable x
48 RooAbsReal *d2gdx2 = gauss.derivative(x, 2);
49 RooAbsReal *d3gdx3 = gauss.derivative(x, 3);
50
51 // Construct plot frame in 'x'
52 RooPlot *xframe = x.frame(Title("d(Gauss)/dx"));
53
54 // Plot gauss in frame (i.e. in x)
55 gauss.plotOn(xframe);
56
57 // Plot derivatives in same frame
58 dgdx->plotOn(xframe, LineColor(kMagenta));
59 d2gdx2->plotOn(xframe, LineColor(kRed));
60 d3gdx3->plotOn(xframe, LineColor(kOrange));
61
62 // C r e a t e a n d p l o t d e r i v a t i v e s w . r . t . s i g m a
63 // ------------------------------------------------------------------------------
64
65 // Derivative of normalized gauss(x) w.r.t. parameter sigma
66 RooAbsReal *dgds = gauss.derivative(sigma, 1);
67
68 // Second and third derivative of normalized gauss(x) w.r.t. parameter sigma
69 RooAbsReal *d2gds2 = gauss.derivative(sigma, 2);
70 RooAbsReal *d3gds3 = gauss.derivative(sigma, 3);
71
72 // Construct plot frame in 'sigma'
73 RooPlot *sframe = sigma.frame(Title("d(Gauss)/d(sigma)"), Range(0., 2.));
74
75 // Plot gauss in frame (i.e. in x)
76 gauss.plotOn(sframe);
77
78 // Plot derivatives in same frame
79 dgds->plotOn(sframe, LineColor(kMagenta));
80 d2gds2->plotOn(sframe, LineColor(kRed));
81 d3gds3->plotOn(sframe, LineColor(kOrange));
82
83 // Draw all frames on a canvas
84 TCanvas *c = new TCanvas("rf111_derivatives", "rf111_derivatives", 800, 400);
85 c->Divide(2);
86 c->cd(1);
87 gPad->SetLeftMargin(0.15);
88 xframe->GetYaxis()->SetTitleOffset(1.6);
89 xframe->Draw();
90 c->cd(2);
91 gPad->SetLeftMargin(0.15);
92 sframe->GetYaxis()->SetTitleOffset(1.6);
93 sframe->Draw();
94}
#define c(i)
Definition RSha256.hxx:101
@ kRed
Definition Rtypes.h:67
@ kOrange
Definition Rtypes.h:68
@ kMagenta
Definition Rtypes.h:67
#define gPad
Abstract base class for objects that represent a real value and implements functionality common to al...
Definition RooAbsReal.h:63
Plain Gaussian p.d.f.
Definition RooGaussian.h:24
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
Variable that can be changed from the outside.
Definition RooRealVar.h:37
The Canvas class.
Definition TCanvas.h:23
RooCmdArg LineColor(TColorNumber color)
const Double_t sigma
Double_t x[n]
Definition legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
Definition CodegenImpl.h:67
const char * Title
Definition TXMLSetup.cxx:68
Ta Range(0, 0, 1, 1)