Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
fitConvolution.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_fit
3/// \notebook -js
4/// Tutorial for convolution of two functions
5///
6/// \macro_image
7/// \macro_output
8/// \macro_code
9///
10/// \author Aurelie Flandi
11
12#include <TCanvas.h>
13#include <TRandom.h>
14#include <TF1Convolution.h>
15#include <TF1.h>
16#include <TH1F.h>
17
18void fitConvolution()
19{
20 // Construction of histogram to fit.
21 TH1F *h_ExpGauss = new TH1F("h_ExpGauss", "Exponential convoluted by Gaussian", 100, 0., 5.);
22 for (int i = 0; i < 1e6; i++) {
23 // Gives a alpha of -0.3 in the exp.
24 double x = gRandom->Exp(1. / 0.3);
25 x += gRandom->Gaus(0., 3.);
26 // Probability density function of the addition of two variables is the
27 // convolution of two density functions.
28 h_ExpGauss->Fill(x);
29 }
30
31 TF1Convolution *f_conv = new TF1Convolution("expo", "gaus", -1, 6, true);
32 f_conv->SetRange(-1., 6.);
33 f_conv->SetNofPointsFFT(1000);
34 TF1 *f = new TF1("f", *f_conv, 0., 5., f_conv->GetNpar());
35 f->SetParameters(1., -0.3, 0., 1.);
36
37 // Fit.
38 h_ExpGauss->Fit("f");
39}
#define f(i)
Definition RSha256.hxx:104
R__EXTERN TRandom * gRandom
Definition TRandom.h:62
Class wrapping convolution of two functions.
Int_t GetNpar() const
void SetRange(Double_t a, Double_t b) override
Set the actual range used for the convolution.
void SetNofPointsFFT(Int_t n)
Set the number of points used for the FFT convolution.
1-Dim function class
Definition TF1.h:233
1-D histogram with a float per channel (see TH1 documentation)
Definition TH1.h:623
virtual TFitResultPtr Fit(const char *formula, Option_t *option="", Option_t *goption="", Double_t xmin=0, Double_t xmax=0)
Fit histogram with function fname.
Definition TH1.cxx:3906
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition TH1.cxx:3346
virtual Double_t Gaus(Double_t mean=0, Double_t sigma=1)
Samples a random number from the standard Normal (Gaussian) Distribution with the given mean and sigm...
Definition TRandom.cxx:275
virtual Double_t Exp(Double_t tau)
Returns an exponential deviate.
Definition TRandom.cxx:252
Double_t x[n]
Definition legend1.C:17