SiLab-Bonn / pylandau

Simple Landau distribution definitions to be used in Python.
GNU Lesser General Public License v2.1
20 stars 4 forks source link

Strange results for convolved Landau/Gauss #1

Closed 153957 closed 8 years ago

153957 commented 8 years ago

When using the langau_pdf with sigma > 10 oscillations appear in the results. In our (HiSPARC) own code we also have an implementation of the Landau PDF and a convolved version: https://github.com/HiSPARC/sapphire/blob/master/sapphire/analysis/landau.py

When I plotted the results for the two convolved Landau/Gauss functions the pyLandau shows oscillations in the result.

Here is the code (requires the script linked above):

from pyLandau import landau
from sapphire.analysis.landau import Scintillator

scin = Scintillator()
x = np.arange(-5, 20, 0.01)

y = scin.conv_landau_for_x(x, gauss_scale=20*scin.xi)
plot(x, y / sum(y))

y = landau.langau_pdf(x / scin.xi - scin._lf0, sigma=20)
plot(x, y / sum(y))

Which results in the following, where blue is pyLandau and black the SAPPHiRE implementation. conv_landau

DavidLP commented 8 years ago

Thank you very much for your nice bug report. I observed that the Gauss/Landau convolution is not stable if eta < 10 * sigma for the number of fixed number of convolution steps done (100). Thus the convolution steps are now increased depending on the eta / sigma ratio. This should give more stable results; especially when fitting is involved.

DavidLP commented 8 years ago

The fix is uploaded to PyPI.