Tutorial for convolution of two functions
Author: Jonas Rembser, Aurelie Flandi (C++ version)
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, March 19, 2024 at 07:08 PM.
import ROOT
Construction of histogram to fit.
h_ExpGauss = ROOT.TH1F("h_ExpGauss", "Exponential convoluted by Gaussian", 100, 0.0, 5.0)
for i in range(1000000):
# Gives a alpha of -0.3 in the exp.
x = ROOT.gRandom.Exp(1.0 / 0.3)
x += ROOT.gRandom.Gaus(0.0, 3.0)
# Probability density function of the addition of two variables is the
# convolution of two density functions.
h_ExpGauss.Fill(x)
f_conv = ROOT.TF1Convolution("expo", "gaus", -1, 6, True)
f_conv.SetRange(-1.0, 6.0)
f_conv.SetNofPointsFFT(1000)
f = ROOT.TF1("f", f_conv, 0.0, 5.0, f_conv.GetNpar())
f.SetParameters(1.0, -0.3, 0.0, 1.0)
c1 = ROOT.TCanvas("c1", "c1", 800, 1000)
Fit and draw result of the fit
h_ExpGauss.Fit("f")
c1.SaveAs("fitConvolution.png")
**************************************** 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::Print>: png file fitConvolution.png has been created
Draw all canvases
from ROOT import gROOT
gROOT.GetListOfCanvases().Draw()