Logo ROOT   6.14/05
Reference Guide
rf703_effpdfprod.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
3 /// \notebook -js
4 /// 'SPECIAL PDFS' RooFit tutorial macro #703
5 ///
6 /// Using a product of an (acceptance) efficiency and a p.d.f as p.d.f.
7 ///
8 /// \macro_image
9 /// \macro_output
10 /// \macro_code
11 /// \author 07/2008 - Wouter Verkerke
12 
13 
14 #include "RooRealVar.h"
15 #include "RooDataSet.h"
16 #include "RooGaussian.h"
17 #include "RooConstVar.h"
18 #include "RooExponential.h"
19 #include "RooEffProd.h"
20 #include "RooFormulaVar.h"
21 #include "TCanvas.h"
22 #include "TAxis.h"
23 #include "RooPlot.h"
24 using namespace RooFit ;
25 
26 
27 void rf703_effpdfprod()
28 {
29  // 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
30  // ---------------------------------------------------------------
31 
32  // Declare observables
33  RooRealVar t("t","t",0,5) ;
34 
35  // Make pdf
36  RooRealVar tau("tau","tau",-1.54,-4,-0.1) ;
37  RooExponential model("model","model",t,tau) ;
38 
39 
40 
41  // D e f i n e e f f i c i e n c y f u n c t i o n
42  // ---------------------------------------------------
43 
44  // Use error function to simulate turn-on slope
45  RooFormulaVar eff("eff","0.5*(TMath::Erf((t-1)/0.5)+1)",t) ;
46 
47 
48 
49  // 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
50  // ---------------------------------------------------------------
51 
52  // Multiply pdf(t) with efficiency in t
53  RooEffProd modelEff("modelEff","model with efficiency",model,eff) ;
54 
55 
56 
57  // P l o t e f f i c i e n c y , p d f
58  // ----------------------------------------
59 
60  RooPlot* frame1 = t.frame(Title("Efficiency")) ;
61  eff.plotOn(frame1,LineColor(kRed)) ;
62 
63  RooPlot* frame2 = t.frame(Title("Pdf with and without efficiency")) ;
64 
65  model.plotOn(frame2,LineStyle(kDashed)) ;
66  modelEff.plotOn(frame2) ;
67 
68 
69 
70  // 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
71  // ------------------------------------------------------------------------------
72 
73  // Generate events. If the input pdf has an internal generator, the internal generator
74  // is used and an accept/reject sampling on the efficiency is applied.
75  RooDataSet* data = modelEff.generate(t,10000) ;
76 
77  // Fit pdf. The normalization integral is calculated numerically.
78  modelEff.fitTo(*data) ;
79 
80  // Plot generated data and overlay fitted pdf
81  RooPlot* frame3 = t.frame(Title("Fitted pdf with efficiency")) ;
82  data->plotOn(frame3) ;
83  modelEff.plotOn(frame3) ;
84 
85 
86  TCanvas* c = new TCanvas("rf703_effpdfprod","rf703_effpdfprod",1200,400) ;
87  c->Divide(3) ;
88  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
89  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
90  c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
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:294
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1117
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:568
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:59
TVirtualPad * cd(Int_t subpadnumber=0)
Set current canvas & pad.
Definition: TCanvas.cxx:688
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
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
The Canvas class.
Definition: TCanvas.h:31
virtual void Divide(Int_t nx=1, Int_t ny=1, Float_t xmargin=0.01, Float_t ymargin=0.01, Int_t color=0)
Automatic pad generation by division.
Definition: TPad.cxx:1162
#define gPad
Definition: TVirtualPad.h:285
#define c(i)
Definition: RSha256.hxx:101
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:558