Logo ROOT  
Reference Guide
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_fit
3/// \notebook -js
4/// Tutorial for convolution of two functions
6/// \macro_image
7/// \macro_output
8/// \macro_code
10/// \author Aurelie Flandi
12#include <stdio.h>
13#include <TMath.h>
14#include <TCanvas.h>
15#include <iostream>
16#include <TROOT.h>
17#include <TChain.h>
18#include <TObject.h>
19#include <TRandom.h>
20#include <TFile.h>
21#include <math.h>
22#include <TF1Convolution.h>
23#include <TF1.h>
24#include <TH1F.h>
25#include <TGraph.h>
26#include <TStopwatch.h>
28using namespace std;
30void fitConvolution()
32 //construction of histogram to fit
33 TH1F *h_ExpGauss = new TH1F("h_ExpGauss","Exponential convoluted by gaussian",100,0.,5.);
34 for (int i=0;i<1e6;i++)
35 {
36 Double_t x = gRandom->Exp(1./0.3);//gives a alpha of -0.3 in the exp
37 x += gRandom->Gaus(0.,3.);
38 h_ExpGauss->Fill(x);//probability density function of the addition of two variables is the convolution of 2 dens. functions
39 }
41 TF1Convolution *f_conv = new TF1Convolution("expo","gaus",-1,6,true);
42 f_conv->SetRange(-1.,6.);
43 f_conv->SetNofPointsFFT(1000);
44 TF1 *f = new TF1("f",*f_conv, 0., 5., f_conv->GetNpar());
45 f->SetParameters(1.,-0.3,0.,1.);
47 //fit
48 new TCanvas("c","c",800,1000);
49 h_ExpGauss -> Fit("f");
50 h_ExpGauss->Draw();
#define f(i)
Definition: RSha256.hxx:104
double Double_t
Definition: RtypesCore.h:59
R__EXTERN TRandom * gRandom
Definition: TRandom.h:62
The Canvas class.
Definition: TCanvas.h:23
Class wrapping convolution of two functions.
void SetRange(Double_t a, Double_t b)
Int_t GetNpar() const
void SetNofPointsFFT(Int_t n)
1-Dim function class
Definition: TF1.h:213
1-D histogram with a float per channel (see TH1 documentation)}
Definition: TH1.h:575
virtual Int_t Fill(Double_t x)
Increment bin with abscissa X by 1.
Definition: TH1.cxx:3350
virtual void Draw(Option_t *option="")
Draw this histogram with options.
Definition: TH1.cxx:3073
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:274
virtual Double_t Exp(Double_t tau)
Returns an exponential deviate.
Definition: TRandom.cxx:251
Double_t x[n]
Definition: legend1.C:17
TFitResultPtr Fit(FitObject *h1, TF1 *f1, Foption_t &option, const ROOT::Math::MinimizerOptions &moption, const char *goption, ROOT::Fit::DataRange &range)
Definition: HFitImpl.cxx:133