Home | News | Documentation | Download

Error Integral is too large?

Hello all,
I fit my histogram using Gaussian and asymmetric Lorentzian function.
I would like to obtain the Integral and Integralerror of the fit using the covariance matrix which I obtain from the fit.
The result seems fine but I got the following message.
“TF1Helper::IntegralError:0: RuntimeWarning: numerical error from integration is too large. Integral error = 1.28333 +/- 10.7145 - eps = 0.01”

Can someone explain what is the issue here and why I get this message?

My code Here:


def VoigtAsymmB(x, par):
    #//Fit parameters:
    #//par[0]=Amp of Gaussian
    #//par[1]=mean of Gaussian
    #//par[2]=width (sigma) of Gaussian
    #//par[3]=relative amplitude of left-side Lorentzian
    #//par[4]=left-side Lorentzian width
    #//par[5]=right-side Lorentzian width
    #//Lamp=amplitude of Lorentzian

    xx=x[0];
    if xx > par[1]:
        width = par[5]
        Lamp=par[3]*par[5]*par[5]/(par[4]*par[4])
    else:
        width = par[4]
        Lamp = par[3]

    # Define Gaussian
    arg1 = ROOT.pow(((xx-par[1])/par[2]),2)
    gaus = ROOT.exp(-0.5*arg1)

    #Define Lorentzian
    arg2 = ROOT.pow((xx-par[1]),2)
    loren = 1./(width*width+arg2)
    
    return par[0]*(gaus+Lamp*loren)

fit = TF1('fit', VoigtAsymmB, y_fit_range[0], y_fit_range[1], 6)
            fit.SetParameters(fit_par[0], fit_par[1], fit_par[2], fit_par[3], fit_par[4], fit_par[5]) # mean, sigma1, sigma2, amp
            fit.SetLineWidth(1)
            fit.SetParName(0,"AmpG");
            fit.SetParName(1,"meanG");
            fit.SetParName(2,"widthG");
            fit.SetParName(3,"AL");
            fit.SetParName(4,"widthLL");
            fit.SetParName(5,"widthLR");
            
            hist_fit = histos.get(title_det, default_histo).Fit(fit,"LRS")

            # # # get cov Matrix to find error
            covMatrix = hist_fit.GetCovarianceMatrix()

            N_hist = histos.get(title_det, default_histo).Integral()
            N_histErr = ROOT.sqrt(N_hist)

            
            N_tot = (abs(fit.Integral(y_fit_range[0], y_fit_range[1])))/histos.get(title_det, default_histo).GetBinWidth(1)
            N_totErr = (fit.IntegralError(y_fit_range[0], y_fit_range[1], hist_fit.GetParams(), covMatrix.GetMatrixArray()))/histos.get(title_det, default_histo).GetBinWidth(1)

            label.DrawLatex(0.55, 0.40, 'hist = {0:6.4f} +/- {1:6.4f}'.format(N_hist, N_histErr))
            label.DrawLatex(0.55, 0.30, 'fit Yield = {0:6.4f} +/- {1:6.4f}'.format(N_tot, N_totErr))
            print(' N_tot  = ', N_tot, ' +/- ',  N_totErr)
            print(' N_hist = ', N_hist, ' +/- ', N_histErr)


Please read tips for efficient and successful posting and posting code

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


Maybe:

Sorry, I forget to upload the result of fitting.
fit_GausAsymmLorentzian_fit_exp.pdf (19.0 KB)

Thank for quick replay. Ayn idea of how do I solve the problem "Unsupported operand type(s) for -: ‘float’ and ‘tuple’ "?

N_totErr = (fit.IntegralError(y_fit_range[0], y_fit_range[1], hist_fit.GetParams(), covMatrix.GetMatrixArray()), 1e-6)/histos.get(title_det, default_histo).GetBinWidth(1)
TypeError: unsupported operand type(s) for /: ‘tuple’ and ‘float’

Hello Wile_E_Coyote,
Even when I replace eps to 1e-6, I still see the same warning
(TF1Helper::IntegralError:0: RuntimeWarning: numerical error from integration is too large. Integral error = 1.28591 +/- 0.00816594 - eps = 1e-06)

‘’’

        binwidth = histos.get(title_det, default_histo).GetBinWidth(1)
     
        N_tot = (abs(fit.Integral(y_fit_range[0], y_fit_range[1])))/binwidth
        N_totErr = (fit.IntegralError(y_fit_range[0], y_fit_range[1], hist_fit.GetParams(), covMatrix.GetMatrixArray(), 1e-6))/binwidth

‘’’
@moneta

HI,
I think there is a small issue in computing the desired accurancy needed to compute the integral in TF1::IntegralError. You can probably ignore the warning. I will provide a fix for this soon

Lorenzo

In general however I would not use TF1::IntegralError since it does not take care correctly of the correlations of the fit parameters. You should fit directly the normalizations, for example using the TF1NormSum class. See the tutorial ROOT: tutorials/fit/fitNormSum.C File Reference.

Lorenzo