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 Tuesday, March 19, 2024 at 07:15 PM.
%%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;
Construct observable
RooRealVar t("t", "t", -10, 30);
Construct landau(t,ml,sl) ;
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)
RooRealVar mg("mg", "mg", 0);
RooRealVar sg("sg", "sg", 2, 0.1, 10);
RooGaussian gauss("gauss", "gauss", t, mg, sg);
Set #bins to be used for FFT sampling to 10000
t.setBins(10000, "cache");
Construct landau (x) gauss
RooFFTConvPdf lxg("lxg", "landau (X) gauss", t, landau, gauss);
Sample 1000 events in x from gxlx
std::unique_ptr<RooDataSet> data{lxg.generate(t, 10000)};
input_line_53:2:2: warning: 'data' shadows a declaration with the same name in the 'std' namespace; use '::data' to reference this declaration std::unique_ptr<RooDataSet> data{lxg.generate(t, 10000)}; ^
Fit gxlx to data
lxg.fitTo(*data, PrintLevel(-1));
input_line_54:2:13: error: reference to 'data' is ambiguous lxg.fitTo(*data, PrintLevel(-1)); ^ input_line_53:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<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
RooPlot *frame = t.frame(Title("landau (x) gauss convolution"));
data->plotOn(frame);
lxg.plotOn(frame);
landau.plotOn(frame, LineStyle(kDashed));
input_line_55:3:1: error: reference to 'data' is ambiguous data->plotOn(frame); ^ input_line_53:2:30: note: candidate found by name lookup is 'data' std::unique_ptr<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
new TCanvas("rf208_convolution", "rf208_convolution", 600, 600);
gPad->SetLeftMargin(0.15);
frame->GetYaxis()->SetTitleOffset(1.4);
frame->Draw();
input_line_57: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
%jsroot on
gROOT->GetListOfCanvases()->Draw()