Logo ROOT   6.10/00
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
fitConvolution.C File Reference

Detailed Description

Tutorial for convolution of two functions.

pict1_fitConvolution.C.png
Processing /builddir/build/BUILD/root-6.10.00/tutorials/fit/fitConvolution.C...
FCN=298.12 FROM MIGRAD STATUS=CONVERGED 448 CALLS 449 TOTAL
EDM=1.27481e-06 STRATEGY= 1 ERROR MATRIX ACCURATE
EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 7.32861e+00 3.70662e-02 1.23435e-05 -4.89569e-01
2 p1 7.33024e-02 2.44032e-03 3.62162e-06 -2.20831e+00
3 p2 -2.26418e+00 4.91596e-02 5.24294e-05 -1.05682e-01
4 p3 1.12808e+00 6.28517e-02 1.94751e-05 -3.04912e-01
#include <stdio.h>
#include <TMath.h>
#include <TCanvas.h>
#include <iostream>
#include <TROOT.h>
#include <TChain.h>
#include <TObject.h>
#include <TRandom.h>
#include <TFile.h>
#include <math.h>
#include <TF1Convolution.h>
#include <TF1.h>
#include <TH1F.h>
#include <TGraph.h>
#include <TStopwatch.h>
using namespace std;
void fitConvolution()
{
//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++)
{
Double_t x = gRandom->Exp(1./0.3);//gives a alpha of -0.3 in the exp
x += gRandom->Gaus(0.,3.);
h_ExpGauss->Fill(x);//probability density function of the addition of two variables is the convolution of 2 dens. functions
}
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
new TCanvas("c","c",800,1000);
h_ExpGauss -> Fit("f");
h_ExpGauss->Draw();
}
Author
Aurelie Flandi

Definition in file fitConvolution.C.