ROOT   Reference Guide
rf703_effpdfprod.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4///
5/// Special p.d.f.'s: using a product of an (acceptance) efficiency and a p.d.f as p.d.f.
6///
7/// \macro_image
8/// \macro_output
9/// \macro_code
10///
11/// \date 07/2008
12/// \author Wouter Verkerke
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"
24using namespace RooFit;
25
27{
28 // 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
29 // ---------------------------------------------------------------
30
31 // Declare observables
32 RooRealVar t("t", "t", 0, 5);
33
34 // Make pdf
35 RooRealVar tau("tau", "tau", -1.54, -4, -0.1);
36 RooExponential model("model", "model", t, tau);
37
38 // D e f i n e e f f i c i e n c y f u n c t i o n
39 // ---------------------------------------------------
40
41 // Use error function to simulate turn-on slope
42 RooFormulaVar eff("eff", "0.5*(TMath::Erf((t-1)/0.5)+1)", t);
43
44 // 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
45 // ---------------------------------------------------------------
46
47 // Multiply pdf(t) with efficiency in t
48 RooEffProd modelEff("modelEff", "model with efficiency", model, eff);
49
50 // P l o t e f f i c i e n c y , p d f
51 // ----------------------------------------
52
53 RooPlot *frame1 = t.frame(Title("Efficiency"));
54 eff.plotOn(frame1, LineColor(kRed));
55
56 RooPlot *frame2 = t.frame(Title("Pdf with and without efficiency"));
57
58 model.plotOn(frame2, LineStyle(kDashed));
59 modelEff.plotOn(frame2);
60
61 // 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
62 // ------------------------------------------------------------------------------
63
64 // Generate events. If the input pdf has an internal generator, the internal generator
65 // is used and an accept/reject sampling on the efficiency is applied.
66 RooDataSet *data = modelEff.generate(t, 10000);
67
68 // Fit pdf. The normalization integral is calculated numerically.
69 modelEff.fitTo(*data);
70
71 // Plot generated data and overlay fitted pdf
72 RooPlot *frame3 = t.frame(Title("Fitted pdf with efficiency"));
73 data->plotOn(frame3);
74 modelEff.plotOn(frame3);
75
76 TCanvas *c = new TCanvas("rf703_effpdfprod", "rf703_effpdfprod", 1200, 400);
77 c->Divide(3);
78 c->cd(1);
80 frame1->GetYaxis()->SetTitleOffset(1.4);
81 frame1->Draw();
82 c->cd(2);
84 frame2->GetYaxis()->SetTitleOffset(1.6);
85 frame2->Draw();
86 c->cd(3);
88 frame3->GetYaxis()->SetTitleOffset(1.6);
89 frame3->Draw();
90}
#define c(i)
Definition: RSha256.hxx:101
@ kRed
Definition: Rtypes.h:64
@ kDashed
Definition: TAttLine.h:48
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
Calls RooPlot* plotOn(RooPlot* frame, const RooLinkedList& cmdList) const ;.
Definition: RooAbsData.cxx:546
RooDataSet is a container class to hold unbinned data.
Definition: RooDataSet.h:33
The class RooEffProd implements the product of a PDF with an efficiency function.
Definition: RooEffProd.h:20
Exponential PDF.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Definition: RooFormulaVar.h:29
A RooPlot is a plot frame and a container for graphics objects within that frame.
Definition: RooPlot.h:44
TAxis * GetYaxis() const
Definition: RooPlot.cxx:1277
static RooPlot * frame(const RooAbsRealLValue &var, Double_t xmin, Double_t xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition: RooPlot.cxx:277
virtual void Draw(Option_t *options=0)
Draw this plot and all of the elements it contains.
Definition: RooPlot.cxx:712
RooRealVar represents a variable that can be changed from the outside.
Definition: RooRealVar.h:35
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition: TAttAxis.cxx:294
The Canvas class.
Definition: TCanvas.h:27
RooCmdArg LineColor(Color_t color)
RooCmdArg LineStyle(Style_t style)
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
const char * Title
Definition: TXMLSetup.cxx:67