rf111_derivatives.C

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #111
00004 // 
00005 // Numerical 1st,2nd and 3rd order derivatives w.r.t. observables and parameters
00006 //
00007 // pdf = gauss(x,m,s) 
00008 //
00009 //
00010 // 07/2008 - Wouter Verkerke 
00011 // 
00012 /////////////////////////////////////////////////////////////////////////
00013 
00014 #ifndef __CINT__
00015 #include "RooGlobalFunc.h"
00016 #endif
00017 #include "RooRealVar.h"
00018 #include "RooDataSet.h"
00019 #include "RooGaussian.h"
00020 #include "TCanvas.h"
00021 #include "TAxis.h"
00022 #include "RooPlot.h"
00023 using namespace RooFit ;
00024 
00025 
00026 void rf111_derivatives()
00027 {
00028   // S e t u p   m o d e l 
00029   // ---------------------
00030 
00031   // Declare variables x,mean,sigma with associated name, title, initial value and allowed range
00032   RooRealVar x("x","x",-10,10) ;
00033   RooRealVar mean("mean","mean of gaussian",1,-10,10) ;
00034   RooRealVar sigma("sigma","width of gaussian",1,0.1,10) ;
00035 
00036   // Build gaussian p.d.f in terms of x,mean and sigma
00037   RooGaussian gauss("gauss","gaussian PDF",x,mean,sigma) ;  
00038 
00039 
00040   // 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 
00041   // ----------------------------------------------------------------------
00042   
00043   // Derivative of normalized gauss(x) w.r.t. observable x
00044   RooAbsReal* dgdx = gauss.derivative(x,1) ;  
00045   
00046   // Second and third derivative of normalized gauss(x) w.r.t. observable x
00047   RooAbsReal* d2gdx2 = gauss.derivative(x,2) ;  
00048   RooAbsReal* d3gdx3 = gauss.derivative(x,3) ;  
00049 
00050   // Construct plot frame in 'x'
00051   RooPlot* xframe = x.frame(Title("d(Gauss)/dx")) ;
00052   
00053   // Plot gauss in frame (i.e. in x) 
00054   gauss.plotOn(xframe) ;
00055 
00056   // Plot derivatives in same frame
00057   dgdx->plotOn(xframe,LineColor(kMagenta)) ;
00058   d2gdx2->plotOn(xframe,LineColor(kRed)) ;
00059   d3gdx3->plotOn(xframe,LineColor(kOrange)) ;
00060 
00061 
00062   // 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 
00063   // ------------------------------------------------------------------------------
00064   
00065   // Derivative of normalized gauss(x) w.r.t. parameter sigma
00066   RooAbsReal* dgds = gauss.derivative(sigma,1) ;  
00067   
00068   // Second and third derivative of normalized gauss(x) w.r.t. parameter sigma
00069   RooAbsReal* d2gds2 = gauss.derivative(sigma,2) ;  
00070   RooAbsReal* d3gds3 = gauss.derivative(sigma,3) ;  
00071 
00072   // Construct plot frame in 'sigma'
00073   RooPlot* sframe = sigma.frame(Title("d(Gauss)/d(sigma)"),Range(0.,2.)) ;
00074   
00075   // Plot gauss in frame (i.e. in x) 
00076   gauss.plotOn(sframe) ;
00077 
00078   // Plot derivatives in same frame
00079   dgds->plotOn(sframe,LineColor(kMagenta)) ;
00080   d2gds2->plotOn(sframe,LineColor(kRed)) ;
00081   d3gds3->plotOn(sframe,LineColor(kOrange)) ;
00082 
00083 
00084 
00085   // Draw all frames on a canvas
00086   TCanvas* c = new TCanvas("rf111_derivatives","rf111_derivatives",800,400) ;
00087   c->Divide(2) ;
00088   c->cd(1) ; gPad->SetLeftMargin(0.15) ; xframe->GetYaxis()->SetTitleOffset(1.6) ; xframe->Draw() ;
00089   c->cd(2) ; gPad->SetLeftMargin(0.15) ; sframe->GetYaxis()->SetTitleOffset(1.6) ; sframe->Draw() ;
00090   
00091  
00092 }

Generated on Tue Jul 5 15:45:01 2011 for ROOT_528-00b_version by  doxygen 1.5.1