rf703_effpdfprod.cxx

Go to the documentation of this file.
00001 //////////////////////////////////////////////////////////////////////////
00002 //
00003 // 'SPECIAL PDFS' RooFit tutorial macro #703
00004 // 
00005 // Using a product of an (acceptance) efficiency and a p.d.f as p.d.f.
00006 //
00007 //
00008 //
00009 // 07/2008 - Wouter Verkerke 
00010 // 
00011 /////////////////////////////////////////////////////////////////////////
00012 
00013 #ifndef __CINT__
00014 #include "RooGlobalFunc.h"
00015 #endif
00016 #include "RooRealVar.h"
00017 #include "RooDataSet.h"
00018 #include "RooGaussian.h"
00019 #include "RooExponential.h"
00020 #include "RooEffProd.h"
00021 #include "RooFormulaVar.h"
00022 #include "TCanvas.h"
00023 #include "RooPlot.h"
00024 using namespace RooFit ;
00025 
00026 
00027 // Elementary operations on a gaussian PDF
00028 class TestBasic703 : public RooFitTestUnit
00029 {
00030 public: 
00031   TestBasic703(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Efficiency product operator p.d.f",refFile,writeRef,verbose) {} ;
00032   Bool_t testCode() {
00033 
00034   // D e f i n e   o b s e r v a b l e s   a n d   d e c a y   p d f
00035   // ---------------------------------------------------------------
00036 
00037   // Declare observables
00038   RooRealVar t("t","t",0,5) ;
00039 
00040   // Make pdf
00041   RooRealVar tau("tau","tau",-1.54,-4,-0.1) ;
00042   RooExponential model("model","model",t,tau) ;
00043 
00044 
00045 
00046   // D e f i n e   e f f i c i e n c y   f u n c t i o n
00047   // ---------------------------------------------------
00048   
00049   // Use error function to simulate turn-on slope
00050   RooFormulaVar eff("eff","0.5*(TMath::Erf((t-1)/0.5)+1)",t) ;
00051 
00052 
00053 
00054   // D e f i n e   d e c a y   p d f   w i t h   e f f i c i e n c y 
00055   // ---------------------------------------------------------------
00056 
00057   // Multiply pdf(t) with efficiency in t
00058   RooEffProd modelEff("modelEff","model with efficiency",model,eff) ;
00059 
00060   
00061 
00062   // P l o t   e f f i c i e n c y ,   p d f  
00063   // ----------------------------------------
00064 
00065   RooPlot* frame1 = t.frame(Title("Efficiency")) ;
00066   eff.plotOn(frame1,LineColor(kRed)) ;
00067 
00068   RooPlot* frame2 = t.frame(Title("Pdf with and without efficiency")) ;
00069 
00070   model.plotOn(frame2,LineStyle(kDashed)) ;
00071   modelEff.plotOn(frame2) ;
00072 
00073 
00074 
00075   // G e n e r a t e   t o y   d a t a ,   f i t   m o d e l E f f   t o   d a t a
00076   // ------------------------------------------------------------------------------
00077 
00078   // Generate events. If the input pdf has an internal generator, the internal generator
00079   // is used and an accept/reject sampling on the efficiency is applied. 
00080   RooDataSet* data = modelEff.generate(t,10000) ;
00081 
00082   // Fit pdf. The normalization integral is calculated numerically. 
00083   modelEff.fitTo(*data) ;
00084 
00085   // Plot generated data and overlay fitted pdf
00086   RooPlot* frame3 = t.frame(Title("Fitted pdf with efficiency")) ;
00087   data->plotOn(frame3) ;
00088   modelEff.plotOn(frame3) ;
00089 
00090   
00091   regPlot(frame1,"rf703_plot1") ;
00092   regPlot(frame2,"rf703_plot2") ;
00093   regPlot(frame3,"rf703_plot3") ;
00094 
00095 
00096   delete data ;
00097   return kTRUE ;
00098   }
00099 } ;

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