ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf111_derivatives.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// 'BASIC FUNCTIONALITY' RooFit tutorial macro #111
4 ///
5 /// Numerical 1st,2nd and 3rd order derivatives w.r.t. observables and parameters
6 ///
7 /// pdf = gauss(x,m,s)
8 ///
9 ///
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 
14 #ifndef __CINT__
15 #include "RooGlobalFunc.h"
16 #endif
17 #include "RooRealVar.h"
18 #include "RooDataSet.h"
19 #include "RooGaussian.h"
20 #include "TCanvas.h"
21 #include "TAxis.h"
22 #include "RooPlot.h"
23 using namespace RooFit ;
24 
25 
26 void rf111_derivatives()
27 {
28  // S e t u p m o d e l
29  // ---------------------
30 
31  // Declare variables x,mean,sigma with associated name, title, initial value and allowed range
32  RooRealVar x("x","x",-10,10) ;
33  RooRealVar mean("mean","mean of gaussian",1,-10,10) ;
34  RooRealVar sigma("sigma","width of gaussian",1,0.1,10) ;
35 
36  // Build gaussian p.d.f in terms of x,mean and sigma
37  RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;
38 
39 
40  // 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
41  // ----------------------------------------------------------------------
42 
43  // Derivative of normalized gauss(x) w.r.t. observable x
44  RooAbsReal* dgdx = gauss.derivative(x,1) ;
45 
46  // Second and third derivative of normalized gauss(x) w.r.t. observable x
47  RooAbsReal* d2gdx2 = gauss.derivative(x,2) ;
48  RooAbsReal* d3gdx3 = gauss.derivative(x,3) ;
49 
50  // Construct plot frame in 'x'
51  RooPlot* xframe = x.frame(Title("d(Gauss)/dx")) ;
52 
53  // Plot gauss in frame (i.e. in x)
54  gauss.plotOn(xframe) ;
55 
56  // Plot derivatives in same frame
57  dgdx->plotOn(xframe,LineColor(kMagenta)) ;
58  d2gdx2->plotOn(xframe,LineColor(kRed)) ;
59  d3gdx3->plotOn(xframe,LineColor(kOrange)) ;
60 
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 
84 
85  // Draw all frames on a canvas
86  TCanvas* c = new TCanvas("rf111_derivatives","rf111_derivatives",800,400) ;
87  c->Divide(2) ;
88  c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.6) ; xframe->Draw() ;
89  c->cd(2) ; gPad->SetLeftMargin(0.15) ; sframe->GetYaxis()->SetTitleOffset(1.6) ; sframe->Draw() ;
90 
91 
92 }
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title Offset is a correction factor with respect to the "s...
Definition: TAttAxis.cxx:245
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg(), const RooCmdArg &arg2=RooCmdArg(), const RooCmdArg &arg3=RooCmdArg(), const RooCmdArg &arg4=RooCmdArg(), const RooCmdArg &arg5=RooCmdArg(), const RooCmdArg &arg6=RooCmdArg(), const RooCmdArg &arg7=RooCmdArg(), const RooCmdArg &arg8=RooCmdArg(), const RooCmdArg &arg9=RooCmdArg(), const RooCmdArg &arg10=RooCmdArg()) const
Plot (project) PDF on specified frame.
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:61
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
RooCmdArg Title(const char *name)
RooCmdArg Range(const char *rangeName, Bool_t adjustNorm=kTRUE)
Double_t x[n]
Definition: legend1.C:17
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
const Double_t sigma
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
#define gPad
Definition: TVirtualPad.h:288
RooDerivative * derivative(RooRealVar &obs, Int_t order=1, Double_t eps=0.001)
Return function representing first, second or third order derivative of this function.
RooAbsMoment * mean(RooRealVar &obs)
Definition: RooAbsReal.h:297
Definition: Rtypes.h:62
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559