ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
rf703_effpdfprod.C
Go to the documentation of this file.
1 /// \file
2 /// \ingroup tutorial_roofit
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 /// \macro_code
10 /// \author 07/2008 - Wouter Verkerke
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 "RooConstVar.h"
20 #include "RooExponential.h"
21 #include "RooEffProd.h"
22 #include "RooFormulaVar.h"
23 #include "TCanvas.h"
24 #include "TAxis.h"
25 #include "RooPlot.h"
26 using namespace RooFit ;
27 
28 
29 void rf703_effpdfprod()
30 {
31  // 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
32  // ---------------------------------------------------------------
33 
34  // Declare observables
35  RooRealVar t("t","t",0,5) ;
36 
37  // Make pdf
38  RooRealVar tau("tau","tau",-1.54,-4,-0.1) ;
39  RooExponential model("model","model",t,tau) ;
40 
41 
42 
43  // D e f i n e e f f i c i e n c y f u n c t i o n
44  // ---------------------------------------------------
45 
46  // Use error function to simulate turn-on slope
47  RooFormulaVar eff("eff","0.5*(TMath::Erf((t-1)/0.5)+1)",t) ;
48 
49 
50 
51  // 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
52  // ---------------------------------------------------------------
53 
54  // Multiply pdf(t) with efficiency in t
55  RooEffProd modelEff("modelEff","model with efficiency",model,eff) ;
56 
57 
58 
59  // P l o t e f f i c i e n c y , p d f
60  // ----------------------------------------
61 
62  RooPlot* frame1 = t.frame(Title("Efficiency")) ;
63  eff.plotOn(frame1,LineColor(kRed)) ;
64 
65  RooPlot* frame2 = t.frame(Title("Pdf with and without efficiency")) ;
66 
67  model.plotOn(frame2,LineStyle(kDashed)) ;
68  modelEff.plotOn(frame2) ;
69 
70 
71 
72  // 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
73  // ------------------------------------------------------------------------------
74 
75  // Generate events. If the input pdf has an internal generator, the internal generator
76  // is used and an accept/reject sampling on the efficiency is applied.
77  RooDataSet* data = modelEff.generate(t,10000) ;
78 
79  // Fit pdf. The normalization integral is calculated numerically.
80  modelEff.fitTo(*data) ;
81 
82  // Plot generated data and overlay fitted pdf
83  RooPlot* frame3 = t.frame(Title("Fitted pdf with efficiency")) ;
84  data->plotOn(frame3) ;
85  modelEff.plotOn(frame3) ;
86 
87 
88  TCanvas* c = new TCanvas("rf703_effpdfprod","rf703_effpdfprod",1200,400) ;
89  c->Divide(3) ;
90  c->cd(1) ; gPad->SetLeftMargin(0.15) ; frame1->GetYaxis()->SetTitleOffset(1.4) ; frame1->Draw() ;
91  c->cd(2) ; gPad->SetLeftMargin(0.15) ; frame2->GetYaxis()->SetTitleOffset(1.6) ; frame2->Draw() ;
92  c->cd(3) ; gPad->SetLeftMargin(0.15) ; frame3->GetYaxis()->SetTitleOffset(1.6) ; frame3->Draw() ;
93 
94 }
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:245
RooCmdArg LineColor(Color_t color)
Definition: Rtypes.h:61
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1118
RooCmdArg Title(const char *name)
RooCmdArg LineStyle(Style_t style)
Exponential p.d.f.
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:626
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
TThread * t[5]
Definition: threadsh1.C:13
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
#define gPad
Definition: TVirtualPad.h:288
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:559