Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
fitConvolution.py
Go to the documentation of this file.
1## \file
2## \ingroup tutorial_fit
3## \notebook
4## Tutorial for convolution of two functions
5##
6## \macro_image
7## \macro_output
8## \macro_code
9##
10## \author Jonas Rembser, Aurelie Flandi (C++ version)
11
12import ROOT
13
14# Construction of histogram to fit.
15h_ExpGauss = ROOT.TH1F("h_ExpGauss", "Exponential convoluted by Gaussian", 100, 0.0, 5.0)
16for i in range(1000000):
17 # Gives a alpha of -0.3 in the exp.
18 x = ROOT.gRandom.Exp(1.0 / 0.3)
19 x += ROOT.gRandom.Gaus(0.0, 3.0)
20 # Probability density function of the addition of two variables is the
21 # convolution of two density functions.
22 h_ExpGauss.Fill(x)
23
24f_conv = ROOT.TF1Convolution("expo", "gaus", -1, 6, True)
25f_conv.SetRange(-1.0, 6.0)
26f_conv.SetNofPointsFFT(1000)
27f = ROOT.TF1("f", f_conv, 0.0, 5.0, f_conv.GetNpar())
28f.SetParameters(1.0, -0.3, 0.0, 1.0)
29
30c1 = ROOT.TCanvas("c1", "c1", 800, 1000)
31
32# Fit and draw result of the fit
33h_ExpGauss.Fit("f")
34
35c1.SaveAs("fitConvolution.png")