# rf208_convolution¶

Addition and convolution: one-dimensional numeric convolution

pdf = landau(t) (x) gauss(t)

This tutorial requires FFT3 to be enabled.

Author: Wouter Verkerke
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Sunday, November 27, 2022 at 11:06 AM.

In [1]:
%%cpp -d
#include "RooRealVar.h"
#include "RooDataSet.h"
#include "RooGaussian.h"
#include "RooLandau.h"
#include "RooFFTConvPdf.h"
#include "RooPlot.h"
#include "TCanvas.h"
#include "TAxis.h"
#include "TH1.h"
using namespace RooFit;


## Setup component pdfs¶

Construct observable

In [2]:
RooRealVar t("t", "t", -10, 30);


Construct landau(t,ml,sl) ;

In [3]:
RooRealVar ml("ml", "mean landau", 5., -20, 20);
RooRealVar sl("sl", "sigma landau", 1, 0.1, 10);
RooLandau landau("lx", "lx", t, ml, sl);


Construct gauss(t,mg,sg)

In [4]:
RooRealVar mg("mg", "mg", 0);
RooRealVar sg("sg", "sg", 2, 0.1, 10);
RooGaussian gauss("gauss", "gauss", t, mg, sg);


## Construct convolution pdf¶

Set #bins to be used for FFT sampling to 10000

In [5]:
t.setBins(10000, "cache");


Construct landau (x) gauss

In [6]:
RooFFTConvPdf lxg("lxg", "landau (X) gauss", t, landau, gauss);


## Sample, fit and plot convoluted pdf¶

Sample 1000 events in x from gxlx

In [7]:
RooDataSet *data = lxg.generate(t, 10000);

input_line_55:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration
RooDataSet *data = lxg.generate(t, 10000);
^


Fit gxlx to data

In [8]:
lxg.fitTo(*data);

input_line_56:2:13: error: reference to 'data' is ambiguous
lxg.fitTo(*data);
^
input_line_55:2:14: note: candidate found by name lookup is '__cling_N526::data'
RooDataSet *data = lxg.generate(t, 10000);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^


Plot data, landau pdf, landau (X) gauss pdf

In [9]:
RooPlot *frame = t.frame(Title("landau (x) gauss convolution"));
data->plotOn(frame);
lxg.plotOn(frame);
landau.plotOn(frame, LineStyle(kDashed));

input_line_57:3:1: error: reference to 'data' is ambiguous
data->plotOn(frame);
^
input_line_55:2:14: note: candidate found by name lookup is '__cling_N526::data'
RooDataSet *data = lxg.generate(t, 10000);
^
/usr/include/c++/9/bits/range_access.h:318:5: note: candidate found by name lookup is 'std::data'
data(initializer_list<_Tp> __il) noexcept
^
/usr/include/c++/9/bits/range_access.h:289:5: note: candidate found by name lookup is 'std::data'
data(_Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:299:5: note: candidate found by name lookup is 'std::data'
data(const _Container& __cont) noexcept(noexcept(__cont.data()))
^
/usr/include/c++/9/bits/range_access.h:309:5: note: candidate found by name lookup is 'std::data'
data(_Tp (&__array)[_Nm]) noexcept
^


Draw frame on canvas

In [10]:
new TCanvas("rf208_convolution", "rf208_convolution", 600, 600);
frame->GetYaxis()->SetTitleOffset(1.4);
frame->Draw();

input_line_59:2:3: error: use of undeclared identifier 'frame'
(frame->GetYaxis()->SetTitleOffset(1.3999999999999999))
^
Error in <HandleInterpreterException>: Error evaluating expression (frame->GetYaxis()->SetTitleOffset(1.3999999999999999))
Execution of your code was aborted.


Draw all canvases

In [11]:
%jsroot on
gROOT->GetListOfCanvases()->Draw()