Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
rf703_effpdfprod.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook -js
4/// Special pdf's: using a product of an (acceptance) efficiency and a pdf as pdf
5///
6/// \macro_image
7/// \macro_code
8/// \macro_output
9///
10/// \date July 2008
11/// \author Wouter Verkerke
12
13#include "RooRealVar.h"
14#include "RooDataSet.h"
15#include "RooGaussian.h"
16#include "RooConstVar.h"
17#include "RooExponential.h"
18#include "RooEffProd.h"
19#include "RooFormulaVar.h"
20#include "TCanvas.h"
21#include "TAxis.h"
22#include "RooPlot.h"
23using namespace RooFit;
24
26{
27 // 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
28 // ---------------------------------------------------------------
29
30 // Declare observables
31 RooRealVar t("t", "t", 0, 5);
32
33 // Make pdf
34 RooRealVar tau("tau", "tau", -1.54, -4, -0.1);
35 RooExponential model("model", "model", t, tau);
36
37 // D e f i n e e f f i c i e n c y f u n c t i o n
38 // ---------------------------------------------------
39
40 // Use error function to simulate turn-on slope
41 RooFormulaVar eff("eff", "0.5*(TMath::Erf((t-1)/0.5)+1)", t);
42
43 // 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
44 // ---------------------------------------------------------------
45
46 // Multiply pdf(t) with efficiency in t
47 RooEffProd modelEff("modelEff", "model with efficiency", model, eff);
48
49 // P l o t e f f i c i e n c y , p d f
50 // ----------------------------------------
51
52 RooPlot *frame1 = t.frame(Title("Efficiency"));
53 eff.plotOn(frame1, LineColor(kRed));
54
55 RooPlot *frame2 = t.frame(Title("Pdf with and without efficiency"));
56
57 model.plotOn(frame2, LineStyle(kDashed));
58 modelEff.plotOn(frame2);
59
60 // 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
61 // ------------------------------------------------------------------------------
62
63 // Generate events. If the input pdf has an internal generator, the internal generator
64 // is used and an accept/reject sampling on the efficiency is applied.
65 std::unique_ptr<RooDataSet> data{modelEff.generate(t, 10000)};
66
67 // Fit pdf. The normalization integral is calculated numerically.
68 modelEff.fitTo(*data, PrintLevel(-1));
69
70 // Plot generated data and overlay fitted pdf
71 RooPlot *frame3 = t.frame(Title("Fitted pdf with efficiency"));
72 data->plotOn(frame3);
73 modelEff.plotOn(frame3);
74
75 TCanvas *c = new TCanvas("rf703_effpdfprod", "rf703_effpdfprod", 1200, 400);
76 c->Divide(3);
77 c->cd(1);
78 gPad->SetLeftMargin(0.15);
79 frame1->GetYaxis()->SetTitleOffset(1.4);
80 frame1->Draw();
81 c->cd(2);
82 gPad->SetLeftMargin(0.15);
83 frame2->GetYaxis()->SetTitleOffset(1.6);
84 frame2->Draw();
85 c->cd(3);
86 gPad->SetLeftMargin(0.15);
87 frame3->GetYaxis()->SetTitleOffset(1.6);
88 frame3->Draw();
89}
#define c(i)
Definition RSha256.hxx:101
@ kRed
Definition Rtypes.h:66
@ kDashed
Definition TAttLine.h:48
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
#define gPad
The class RooEffProd implements the product of a PDF with an efficiency function.
Definition RooEffProd.h:19
Exponential PDF.
A RooFormulaVar is a generic implementation of a real-valued object, which takes a RooArgList of serv...
Plot frame and a container for graphics objects within that frame.
Definition RooPlot.h:43
static RooPlot * frame(const RooAbsRealLValue &var, double xmin, double xmax, Int_t nBins)
Create a new frame for a given variable in x.
Definition RooPlot.cxx:185
TAxis * GetYaxis() const
Definition RooPlot.cxx:1224
void Draw(Option_t *options=nullptr) override
Draw this plot and all of the elements it contains.
Definition RooPlot.cxx:597
Variable that can be changed from the outside.
Definition RooRealVar.h:37
virtual void SetTitleOffset(Float_t offset=1)
Set distance between the axis and the axis title.
Definition TAttAxis.cxx:298
The Canvas class.
Definition TCanvas.h:23
RooCmdArg PrintLevel(Int_t code)
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...
Definition CodegenImpl.h:64
const char * Title
Definition TXMLSetup.cxx:68