Fitting histogram with TF1Convolution fails

Hi, ROOTers.
I am trying to fit scintillation curve with two exponents convolved with gaussian.
Here is my code

Fitting function

Part of interest is between #ifdef CONV and #endif directives.

#include <TFile.h>
#include <TTree.h>
#include <TH1F.h>
#include <TStyle.h>
#include <TF1.h>
#include <TAxis.h>
#include <TF1Convolution.h>

#include "Tau.h"

#define CONV

void FitWaveform()
{
    TFile* file = TFile::Open( "../draw_waveforms/TotalWaveforms.root" );
    TH1F*  hist = (TH1F*)file->Get( "totalWaveform" );

    const double x0 = 250;//start of fitting
    const double xMax = hist->GetXaxis()->GetXmax();
    const double xMin = hist->GetXaxis()->GetXmin();
    const double length = xMax - xMin;
    const double yMin = hist->GetMinimum();

    TF1* twoExpos = new TF1( "twoExpos", TwoExponents, x0, xMax, 6 );
    twoExpos->SetParameters( yMin*0.8,
                             0.1*length,
                             x0,
                             yMin*0.2,
                             0.5*length,
                             x0 );
    twoExpos->SetParNames( "A1", "tau1", "x0", "A2", "tau2", "x0" );
    twoExpos->SetParLimits( 1, 0, length);
    twoExpos->SetParLimits( 4, 0, length );
    twoExpos->SetParLimits( 2, x0, x0);
    twoExpos->SetParLimits( 5, x0, x0);

    TF1* gaus = new TF1( "gaus", "gaus", -10, 10 );

    #ifdef CONV
    TF1Convolution* expoGaus = new TF1Convolution( twoExpos, gaus, false );//FFTW not available
    expoGaus->SetRange( x0, xMax );
    TF1* fit = new TF1( "fit", *expoGaus, x0, xMax, expoGaus->GetNpar() );
    fit->SetParameters( yMin*0.8,
                        0.1*length,
                        x0,
                        yMin*0.2,
                        0.5*length,
                        x0,
                        1.0,
                        0.,
                        1.0 );
    fit->SetParLimits( 1, 0, length );
    fit->SetParLimits( 4, 0, length );
    fit->SetParLimits( 2, x0, x0);
    fit->SetParLimits( 5, x0, x0);
    fit->SetParLimits( 6, 1.0, 1.0 );
    fit->SetParLimits( 7, 0., 0. );
    fit->SetParLimits( 8, 1.0, 1.0 );

    hist->Fit( fit, "R" );
    #else
    hist->Fit( twoExpos, "R" );
    #endif

    gStyle->SetOptFit(1111);
}

TwoExponents function

It’s just sum of two exponents. No surprise.
Here is the code.

#include <TMath.h>

double Exponent( double* x, double* par )
{
    double A = par[0];
    double tau = par[1];
    double x0 = par[2];

    double arg = 0.;
    if( tau > 0. )
    {
        arg = -(x[0] - x0) / tau;
    }

    return A * TMath::Exp( arg );
}


double TwoExponents( double* x, double* par )
{
    return Exponent( x, par ) + Exponent( x, &par[3] );
}

Problem

Fit fails. What am I doing wrong?
1538986618_1516_08102018_663x313

NOTES

Firstly, if I fit it with just two exponents it fits well.

sumOfWaveformsFit.pdf (53.8 KB)

Secondly, bin’s content of the histogram is DOUBLE numbers not INT.

Thirdly, here is the root file TotalWaveforms.root (18.4 KB)


ROOT Version: 6.15/01
Platform: Ubuntu 16.04


Hi,

In order to reproduce the problem, it might be helpful to have access to your TotalWaveforms.root data file. Would it be possible to share it for instance through a CERNBox link? I’m no expert in fitting myself but perhaps @moneta can help.

Cheers,
Jakob

I have added the file.

Many thanks! I can reproduce and confirm your output but as to why it fails I’d refer to @moneta

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