rf105_funcbinding.C

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'BASIC FUNCTIONALITY' RooFit tutorial macro #105
00004 // 
00005 //  Demonstration of binding ROOT Math functions as RooFit functions
00006 //  and pdfs
00007 //
00008 // 07/2008 - Wouter Verkerke 
00009 // 
00010 /////////////////////////////////////////////////////////////////////////
00011 
00012 #ifndef __CINT__
00013 #include "RooGlobalFunc.h"
00014 #else
00015 // Refer to a class implemented in libRooFit to force its loading
00016 // via the autoloader.
00017 class Roo2DKeysPdf;
00018 #endif
00019 #include "RooRealVar.h"
00020 #include "RooDataSet.h"
00021 #include "RooGaussian.h"
00022 #include "TCanvas.h"
00023 #include "TAxis.h"
00024 #include "RooPlot.h"
00025 #include "TMath.h"
00026 #include "TF1.h"
00027 #include "Math/DistFunc.h"
00028 #ifndef __CINT__
00029 #include "RooCFunction1Binding.h" 
00030 #include "RooCFunction3Binding.h"
00031 #endif
00032 #include "RooTFnBinding.h" 
00033 
00034 using namespace RooFit;
00035 
00036 
00037 void rf105_funcbinding()
00038 {
00039 
00040   // B i n d   T M a t h : : E r f   C   f u n c t i o n
00041   // ---------------------------------------------------
00042 
00043   // Bind one-dimensional TMath::Erf function as RooAbsReal function
00044   RooRealVar x("x","x",-3,3) ;
00045   RooAbsReal* erf = bindFunction("erf",TMath::Erf,x) ;
00046 
00047   // Print erf definition
00048   erf->Print() ;
00049 
00050   // Plot erf on frame 
00051   RooPlot* frame1 = x.frame(Title("TMath::Erf bound as RooFit function")) ;
00052   erf->plotOn(frame1) ;
00053 
00054 
00055   // B i n d   R O O T : : M a t h : : b e t a _ p d f   C   f u n c t i o n
00056   // -----------------------------------------------------------------------
00057 
00058   // Bind pdf ROOT::Math::Beta with three variables as RooAbsPdf function
00059   RooRealVar x2("x2","x2",0,0.999) ;
00060   RooRealVar a("a","a",5,0,10) ;
00061   RooRealVar b("b","b",2,0,10) ;
00062   RooAbsPdf* beta = bindPdf("beta",ROOT::Math::beta_pdf,x2,a,b) ;
00063 
00064   // Perf beta definition
00065   beta->Print() ;
00066 
00067   // Generate some events and fit
00068   RooDataSet* data = beta->generate(x2,10000) ;
00069   beta->fitTo(*data) ;
00070 
00071   // Plot data and pdf on frame
00072   RooPlot* frame2 = x2.frame(Title("ROOT::Math::Beta bound as RooFit pdf")) ;
00073   data->plotOn(frame2) ;
00074   beta->plotOn(frame2) ;
00075 
00076 
00077 
00078   // B i n d   R O O T   T F 1   a s   R o o F i t   f u n c t i o n
00079   // ---------------------------------------------------------------
00080 
00081   // Create a ROOT TF1 function
00082   TF1 *fa1 = new TF1("fa1","sin(x)/x",0,10);
00083   
00084   // Create an observable 
00085   RooRealVar x3("x3","x3",0.01,20) ;
00086 
00087   // Create binding of TF1 object to above observable
00088   RooAbsReal* rfa1 = bindFunction(fa1,x3) ;
00089 
00090   // Print rfa1 definition
00091   rfa1->Print() ;
00092 
00093   // Make plot frame in observable, plot TF1 binding function
00094   RooPlot* frame3 = x3.frame(Title("TF1 bound as RooFit function")) ;
00095   rfa1->plotOn(frame3) ;
00096 
00097 
00098 
00099   TCanvas* c = new TCanvas("rf105_funcbinding","rf105_funcbinding",1200,400) ;
00100   c->Divide(3) ;
00101   c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.6) ; frame1->Draw() ;
00102   c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
00103   c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
00104 
00105 }

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