Logo ROOT   6.10/09
Reference Guide
rf703_effpdfprod.cxx
Go to the documentation of this file.
1 //////////////////////////////////////////////////////////////////////////
2 //
3 // 'SPECIAL PDFS' RooFit tutorial macro #703
4 //
5 // Using a product of an (acceptance) efficiency and a p.d.f as p.d.f.
6 //
7 //
8 //
9 // 07/2008 - Wouter Verkerke
10 //
11 /////////////////////////////////////////////////////////////////////////
12 
13 #ifndef __CINT__
14 #include "RooGlobalFunc.h"
15 #endif
16 #include "RooRealVar.h"
17 #include "RooDataSet.h"
18 #include "RooGaussian.h"
19 #include "RooExponential.h"
20 #include "RooEffProd.h"
21 #include "RooFormulaVar.h"
22 #include "TCanvas.h"
23 #include "RooPlot.h"
24 using namespace RooFit ;
25 
26 
27 // Elementary operations on a gaussian PDF
28 class TestBasic703 : public RooFitTestUnit
29 {
30 public:
31  TestBasic703(TFile* refFile, Bool_t writeRef, Int_t verbose) : RooFitTestUnit("Efficiency product operator p.d.f",refFile,writeRef,verbose) {} ;
32  Bool_t testCode() {
33 
34  // 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
35  // ---------------------------------------------------------------
36 
37  // Declare observables
38  RooRealVar t("t","t",0,5) ;
39 
40  // Make pdf
41  RooRealVar tau("tau","tau",-1.54,-4,-0.1) ;
42  RooExponential model("model","model",t,tau) ;
43 
44 
45 
46  // D e f i n e e f f i c i e n c y f u n c t i o n
47  // ---------------------------------------------------
48 
49  // Use error function to simulate turn-on slope
50  RooFormulaVar eff("eff","0.5*(TMath::Erf((t-1)/0.5)+1)",t) ;
51 
52 
53 
54  // 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
55  // ---------------------------------------------------------------
56 
57  // Multiply pdf(t) with efficiency in t
58  RooEffProd modelEff("modelEff","model with efficiency",model,eff) ;
59 
60 
61 
62  // P l o t e f f i c i e n c y , p d f
63  // ----------------------------------------
64 
65  RooPlot* frame1 = t.frame(Title("Efficiency")) ;
66  eff.plotOn(frame1,LineColor(kRed)) ;
67 
68  RooPlot* frame2 = t.frame(Title("Pdf with and without efficiency")) ;
69 
70  model.plotOn(frame2,LineStyle(kDashed)) ;
71  modelEff.plotOn(frame2) ;
72 
73 
74 
75  // 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
76  // ------------------------------------------------------------------------------
77 
78  // Generate events. If the input pdf has an internal generator, the internal generator
79  // is used and an accept/reject sampling on the efficiency is applied.
80  RooDataSet* data = modelEff.generate(t,10000) ;
81 
82  // Fit pdf. The normalization integral is calculated numerically.
83  modelEff.fitTo(*data) ;
84 
85  // Plot generated data and overlay fitted pdf
86  RooPlot* frame3 = t.frame(Title("Fitted pdf with efficiency")) ;
87  data->plotOn(frame3) ;
88  modelEff.plotOn(frame3) ;
89 
90 
91  regPlot(frame1,"rf703_plot1") ;
92  regPlot(frame2,"rf703_plot2") ;
93  regPlot(frame3,"rf703_plot3") ;
94 
95 
96  delete data ;
97  return kTRUE ;
98  }
99 } ;
virtual RooPlot * plotOn(RooPlot *frame, const RooCmdArg &arg1=RooCmdArg::none(), const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none(), const RooCmdArg &arg6=RooCmdArg::none(), const RooCmdArg &arg7=RooCmdArg::none(), const RooCmdArg &arg8=RooCmdArg::none()) const
Plot dataset on specified frame.
Definition: RooAbsData.cxx:552
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:56
int Int_t
Definition: RtypesCore.h:41
bool Bool_t
Definition: RtypesCore.h:59
RooCmdArg Title(const char *name)
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t tau
Definition: TRolke.cxx:630
RooCmdArg LineStyle(Style_t style)
Exponential p.d.f.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
bool verbose
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
Definition: RooPlot.h:41
const Bool_t kTRUE
Definition: RtypesCore.h:91