ROOT   Reference Guide
rf211_paramconv.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_roofit
3/// \notebook
4///
5/// Addition and convolution: working with a p.d.f. with a convolution operator in terms of a parameter
6///
7/// This tutorial requires FFT3 to be enabled.
8///
9/// \macro_image
10/// \macro_output
11/// \macro_code
12///
13/// \date 04/2009
14/// \author Wouter Verkerke
15
16#include "RooRealVar.h"
17#include "RooDataHist.h"
18#include "RooGaussian.h"
19#include "RooGenericPdf.h"
20#include "RooFormulaVar.h"
21#include "RooFFTConvPdf.h"
22#include "RooPlot.h"
23#include "TCanvas.h"
24#include "TAxis.h"
25#include "TH2.h"
26using namespace RooFit;
27
28void rf211_paramconv()
29{
30 // S e t u p c o m p o n e n t p d f s
31 // ---------------------------------------
32
33 // Gaussian g(x ; mean,sigma)
34 RooRealVar x("x", "x", -10, 10);
35 RooRealVar mean("mean", "mean", -3, 3);
36 RooRealVar sigma("sigma", "sigma", 0.5, 0.1, 10);
37 RooGaussian modelx("gx", "gx", x, mean, sigma);
38
39 // Block function in mean
40 RooRealVar a("a", "a", 2, 1, 10);
41 RooGenericPdf model_mean("model_mean", "abs(mean)<a", RooArgList(mean, a));
42
43 // Convolution in mean parameter model = g(x,mean,sigma) (x) block(mean)
44 x.setBins(1000, "cache");
45 mean.setBins(50, "cache");
46 RooFFTConvPdf model("model", "model", mean, modelx, model_mean);
47
48 // Configure convolution to construct a 2-D cache in (x,mean)
49 // rather than a 1-d cache in mean that needs to be recalculated
50 // for each value of x
51 model.setCacheObservables(x);
52 model.setBufferFraction(1.0);
53
54 // Integrate model over mean projModel = Int model dmean
55 RooAbsPdf *projModel = model.createProjection(mean);
56
57 // Generate 1000 toy events
58 RooDataHist *d = projModel->generateBinned(x, 1000);
59
60 // Fit p.d.f. to toy data
61 projModel->fitTo(*d, Verbose());
62
63 // Plot data and fitted p.d.f.
64 RooPlot *frame = x.frame(Bins(25));
65 d->plotOn(frame);
66 projModel->plotOn(frame);
67
68 // Make 2d histogram of model(x;mean)
69 TH1 *hh = model.createHistogram("hh", x, Binning(50), YVar(mean, Binning(50)), ConditionalObservables(mean));
70 hh->SetTitle("histogram of model(x|mean)");
72
73 // Draw frame on canvas
74 TCanvas *c = new TCanvas("rf211_paramconv", "rf211_paramconv", 800, 400);
75 c->Divide(2);
76 c->cd(1);
78 frame->GetYaxis()->SetTitleOffset(1.4);
79 frame->Draw();
80 c->cd(2);
82 hh->GetZaxis()->SetTitleOffset(2.5);
83 hh->Draw("surf");
84}
#define d(i)
Definition: RSha256.hxx:102
#define c(i)
Definition: RSha256.hxx:101
@ kBlue
Definition: Rtypes.h:64
virtual RooDataHist * generateBinned(const RooArgSet &whatVars, Double_t nEvents, const RooCmdArg &arg1, const RooCmdArg &arg2=RooCmdArg::none(), const RooCmdArg &arg3=RooCmdArg::none(), const RooCmdArg &arg4=RooCmdArg::none(), const RooCmdArg &arg5=RooCmdArg::none()) const
As RooAbsPdf::generateBinned(const RooArgSet&, const RooCmdArg&,const RooCmdArg&, const RooCmdArg&,...
Definition: RooAbsPdf.h:104
virtual RooFitResult * fitTo(RooAbsData &data, 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())
Fit PDF to given dataset.
Definition: RooAbsPdf.cxx:1254
virtual RooAbsPdf * createProjection(const RooArgSet &iset)
Return a p.d.f that represent a projection of this p.d.f integrated over given observables.
Definition: RooAbsPdf.cxx:3342
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 RooCmdArg &arg9=RooCmdArg::none(), const RooCmdArg &arg10=RooCmdArg::none()) const
Definition: RooAbsPdf.h:118
RooArgList is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgList.h:21
The RooDataHist is a container class to hold N-dimensional binned data.
Definition: RooDataHist.h:40
PDF for the numerical (FFT) convolution of two PDFs.
Definition: RooFFTConvPdf.h:25
Plain Gaussian p.d.f.
Definition: RooGaussian.h:25
RooGenericPdf is a concrete implementation of a probability density function, which takes a RooArgLis...
Definition: RooGenericPdf.h:25
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
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
virtual void SetLineColor(Color_t lcolor)
Set the line color.
Definition: TAttLine.h:40
The Canvas class.
Definition: TCanvas.h:27
The TH1 histogram class.
Definition: TH1.h:56
virtual void SetTitle(const char *title)
Definition: TH1.cxx:6345
TAxis * GetZaxis()
Definition: TH1.h:318
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:2998
RooCmdArg YVar(const RooAbsRealLValue &var, const RooCmdArg &arg=RooCmdArg::none())
RooCmdArg Bins(Int_t nbin)
RooCmdArg ConditionalObservables(const RooArgSet &set)
RooCmdArg Verbose(Bool_t flag=kTRUE)
RooCmdArg Binning(const RooAbsBinning &binning)
const Double_t sigma
Double_t x[n]
Definition: legend1.C:17
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...
auto * a
Definition: textangle.C:12