Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
fitConvolution.py File Reference

Detailed Description

View in nbviewer Open in SWAN
Tutorial for convolution of two functions

****************************************
Minimizer is Minuit2 / Migrad
Chi2 = 298.12
NDf = 96
Edm = 5.73699e-07
NCalls = 446
p0 = 7.3286 +/- 0.0370542
p1 = 0.0733035 +/- 0.00243996
p2 = -2.26419 +/- 0.0491459
p3 = 1.12809 +/- 0.0628298
import ROOT
import numpy as np
# Construction of histogram to fit.
h_ExpGauss = ROOT.TH1F("h_ExpGauss", "Exponential convoluted by Gaussian", 100, 0.0, 5.0)
[
# Gives a alpha of -0.3 in the exp.
# Probability density function of the addition of two variables is the
# convolution of two density functions.
ROOT.gRandom.Exp(1.0 / 0.3) + ROOT.gRandom.Gaus(0.0, 3.0)
for _ in range(1000000)
]
)
)
f_conv = ROOT.TF1Convolution("expo", "gaus", -1, 6, True)
f_conv.SetRange(-1.0, 6.0)
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
c1.SaveAs("fitConvolution.png")
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
Author
Jonas Rembser, Aurelie Flandi (C++ version)

Definition in file fitConvolution.py.