{
"cells": [
{
"cell_type": "markdown",
"id": "620150ba",
"metadata": {},
"source": [
"# fitConvolution\n",
"Tutorial for convolution of two functions\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Aurelie Flandi \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:24 PM."
]
},
{
"cell_type": "markdown",
"id": "e83fb8e5",
"metadata": {},
"source": [
"Construction of histogram to fit."
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6f325984",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:24:45.881894Z",
"iopub.status.busy": "2026-05-19T20:24:45.881781Z",
"iopub.status.idle": "2026-05-19T20:24:46.587681Z",
"shell.execute_reply": "2026-05-19T20:24:46.586941Z"
}
},
"outputs": [],
"source": [
"TH1F *h_ExpGauss = new TH1F(\"h_ExpGauss\", \"Exponential convoluted by Gaussian\", 100, 0., 5.);\n",
"for (int i = 0; i < 1e6; i++) {\n",
" // Gives a alpha of -0.3 in the exp.\n",
" double x = gRandom->Exp(1. / 0.3);\n",
" x += gRandom->Gaus(0., 3.);\n",
" // Probability density function of the addition of two variables is the\n",
" // convolution of two density functions.\n",
" h_ExpGauss->Fill(x);\n",
"}\n",
"\n",
"TF1Convolution *f_conv = new TF1Convolution(\"expo\", \"gaus\", -1, 6, true);\n",
"f_conv->SetRange(-1., 6.);\n",
"f_conv->SetNofPointsFFT(1000);\n",
"TF1 *f = new TF1(\"f\", *f_conv, 0., 5., f_conv->GetNpar());\n",
"f->SetParameters(1., -0.3, 0., 1.);"
]
},
{
"cell_type": "markdown",
"id": "c32091af",
"metadata": {},
"source": [
"Fit."
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "6677188a",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:24:46.594796Z",
"iopub.status.busy": "2026-05-19T20:24:46.594662Z",
"iopub.status.idle": "2026-05-19T20:24:46.925445Z",
"shell.execute_reply": "2026-05-19T20:24:46.925082Z"
}
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"****************************************\n",
"Minimizer is Minuit2 / Migrad\n",
"Chi2 = 298.12\n",
"NDf = 96\n",
"Edm = 1.60212e-06\n",
"NCalls = 448\n",
"p0 = 7.32861 +/- 0.0370515 \n",
"p1 = 0.0733017 +/- 0.0024398 \n",
"p2 = -2.26418 +/- 0.0491398 \n",
"p3 = 1.12807 +/- 0.0628225 \n"
]
},
{
"name": "stderr",
"output_type": "stream",
"text": [
"Info in : created default TCanvas with name c1\n"
]
}
],
"source": [
"h_ExpGauss->Fit(\"f\");"
]
},
{
"cell_type": "markdown",
"id": "91e5a55d",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "c46672c4",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:24:46.932253Z",
"iopub.status.busy": "2026-05-19T20:24:46.932058Z",
"iopub.status.idle": "2026-05-19T20:24:47.158066Z",
"shell.execute_reply": "2026-05-19T20:24:47.157466Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"%jsroot on\n",
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}