A confusing question about the parameters of fitConvolution.C example


ROOT Version: Not Provided
Platform: Not Provided
Compiler: Not Provided


Hello,
I have a question about the example in the tutorials, the link is here ,

https://root.cern.ch/doc/v608/fitConvolution_8C.html

We can see that this is a bad fit, I modifided this example,

my code is following:

  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 <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>
 27
 28 using namespace std;
 29
 30 void fitConvolution()
 31 {
 32    //create a file
 33    TFile *file = new TFile("../data/Convolution.root","RECREATE");
 34    //construction of histogram to fit
 35    TH1F *h_ExpGauss = new TH1F("h_ExpGauss","Exponential convoluted by gaussian",100,-3.,5.);
 36    for (int i=0;i<1e7;i++)
 37    {
 38       Double_t x = gRandom->Exp(1.);//gives a lamda of 1 in the exp
 39       x += gRandom->Gaus(0.,1.);
 40       h_ExpGauss->Fill(x);//probability density function of the addition of two variables is the convolution of 2 dens. functions
 41    }
 42    Double_t a=-4.,b=100.0;
 43    TF1Convolution *f_conv = new TF1Convolution("expo","gaus",a,b,true);
 44    f_conv->SetRange(a,b);
 45    f_conv->SetNofPointsFFT(1000);
 46    TF1   *f = new TF1("f",*f_conv, -3., 5., f_conv->GetNpar());
 47    f->SetParameters(1.,-1.,0.,1.);
 48
 49    //fit
 50    new TCanvas("c","c",800,1000);
 51    h_ExpGauss -> Fit("f");
 52    h_ExpGauss->Draw();
 53    //save
 54    h_ExpGauss->Write();
 55    f->Write();
 56
 57 }

and my result is:

it looks better,
but the consult is a little strange,

EXT PARAMETER STEP FIRST
NO. NAME VALUE ERROR SIZE DERIVATIVE
1 p0 8.61769e+00 3.99072e-03 4.10923e-06 -1.50531e+00
2 p1 -1.00138e+00 1.15067e-03 4.77497e-07 5.23984e+00
3 p2 4.10369e+00 9.60443e-04 1.95679e-06 4.07934e-02
4 p3 1.00088e+00 5.63015e-04 1.10599e-06 -4.43134e-01

p[0],p[1],p[4]can be understood, but p[3] is too strange, cause it should be 0.0, but it turns out to be ~4. Could anybody explain this?
Thanks.

Hi,
The problem is that the exponential distribution needs to be truncated for values x<0, otherwise the convolution will not work. So one cannot go to negative x values in the convolution.
This needs to be defined in the given exponential function. Also the generation is instead done for only x values larger than zero.

So, this is not maybe a very good example. I will upload a new tutorial fixing this.

Thank you for finding this problem

Lorenzo

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.