Tutorial for convolution of two functions
Author: Aurelie Flandi
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Wednesday, April 17, 2024 at 11:09 AM.
Construction of histogram to fit.
TH1F *h_ExpGauss = new TH1F("h_ExpGauss", "Exponential convoluted by Gaussian", 100, 0., 5.);
for (int i = 0; i < 1e6; i++) {
// Gives a alpha of -0.3 in the exp.
double x = gRandom->Exp(1. / 0.3);
x += gRandom->Gaus(0., 3.);
// Probability density function of the addition of two variables is the
// convolution of two density functions.
h_ExpGauss->Fill(x);
}
TF1Convolution *f_conv = new TF1Convolution("expo", "gaus", -1, 6, true);
f_conv->SetRange(-1., 6.);
f_conv->SetNofPointsFFT(1000);
TF1 *f = new TF1("f", *f_conv, 0., 5., f_conv->GetNpar());
f->SetParameters(1., -0.3, 0., 1.);
Fit.
h_ExpGauss->Fit("f");
**************************************** Minimizer is Minuit2 / Migrad Chi2 = 298.12 NDf = 96 Edm = 1.67196e-06 NCalls = 448 p0 = 7.32861 +/- 0.0370492 p1 = 0.0733018 +/- 0.00243973 p2 = -2.26418 +/- 0.0491372 p3 = 1.12808 +/- 0.0628185
Info in <TCanvas::MakeDefCanvas>: created default TCanvas with name c1
Draw all canvases
%jsroot on
gROOT->GetListOfCanvases()->Draw()