Template based pdf fit has problem with RooAdaptiveGaussKronrodIntegrator

Hey RooFit experts,

my problem is that I wonder why some of my fits need so much time, mostly because the RooAdaptiveGaussKronrodIntegrator1D gives outputs like

[#0] ERROR:Integration -- RooAdaptiveGaussKronrodIntegrator1D::integral() ERROR: cannot reach tolerance because of roundoff error
or similar messages due to maximum number of iterations is reached and so on.
Basically the fits work, but in my understanding, since I’m doing template based fits, it shouldn’t take so much time and I really hope that there is something that I can change to make it faster.

I attached a working minimal code example which is basically what my code does (if someone don’t want to download it, it is also available in my public dropbox https://www.dropbox.com/s/w9jyy4699fy7kzl/myRooFit_minimalExample.cc?dl=0),
but I will try to explain it in my own words too.

So what I’m doing is the following:

  • I have a bunch of data (invariant two-electron-mass from a Z decay) and want to fit background and signal on that data.
  • I construct a signal-only template from monte carlo and a background template using a different method on data
  • Now I use the gaussian adaptive kernel density estimator to create a background p.d.f.
  • For the signal I use histogram based 2nd order interpolation and additionally convolve it with a gaussian
  • My complete model is signal+background

Now my floating fit parameters are Nsig, Nbkg and the mean and width of the gaussian.

In the code example the initial signal toy MC data are generated based on a breit wigner convolved with gaussian.
Now in this little example it works well, but on my machine I already get the integration error mentioned above. In my real data, its far worse - even in relatively small datasets (I bin the data in several variables) the fit sometimes takes 20 minutes, constantly giving errors and then sometimes the result is crap.

In my understanding, this is because RooFit tries to make sure, that after each minimization step the resulting p.d.f. is still normalizable. But since the initial constructed p.d.f.s are of course normalizable and the fit routine only makes a shape based fit of these two p.d.f.s, it should be a relatively fast thing to do.

I’m sorry for this long problem, but I would be very happy if someone could give me a hint or has any idea.
Thanks a lot
myRooFit_minimalExample.cc (5.54 KB)


Looking at your example I see that is slow because it performs an integral of an integral. You need to integrate the signal pdf to get the right normalisation in the given range, and the signal pdf is already a numerical convoluted integral.
I would suggest you trying use the FFT based convolution (RooFFTConvPdf class), which is much faster

Best Regards


Hi Lorenzo,

much thanks for your answer, you exactly nailed it.
I already figured this out yesterday in the evening that the numerical convolution is the critical algorithm which makes it slow and wanted to answer the question for my own today. With the Fourier Transformation based convolution it works much better.
Thanks a lot, I will mark it as solved.


PS: just for completeness, a working version of the example code above but using Fourier Transformation based convolution is attached.
myRooFit_minimalExample1.cc (5.69 KB)