tudo-astroparticlephysics / PROPOSAL

Monte Carlo Simulation propagating charged Leptons through Media as C++ Library
GNU Lesser General Public License v3.0
35 stars 21 forks source link

Protect Moliere evaluation from negative x #369

Closed Jean1995 closed 1 year ago

Jean1995 commented 1 year ago

When MoliereInterpol creates the interpolation tables, it evaluates the function at negative x. This becomes a problem if floating point exceptions are caught. This simple patch protects the function from evaluation of the square root at negative x.

maxnoe commented 1 year ago

When MoliereInterpol creates the interpolation tables, it evaluates the function at negative x.

Why? Would that be avoidable?

Wouldn't a better fix be avoiding calling the function with improper input instead of coercing all negative values to 0?

Jean1995 commented 1 year ago

When MoliereInterpol creates the interpolation tables, it evaluates the function at negative x.

Why? Would that be avoidable?

Wouldn't a better fix be avoiding calling the function with improper input instead of coercing all negative values to 0?

I believe this is the interpolation routine evaluating the function around x=0, probably to calculate the differential. But I can investigate this a bit more.

Jean1995 commented 1 year ago

When MoliereInterpol creates the interpolation tables, it evaluates the function at negative x.

Why? Would that be avoidable? Wouldn't a better fix be avoiding calling the function with improper input instead of coercing all negative values to 0?

I believe this is the interpolation routine evaluating the function around x=0, probably to calculate the differential. But I can investigate this a bit more.

I've looked at this, and indeed this comes from the fact that the cubic interpolation calculates the derivative at the edges of the definition regime. I am not sure whether this is intrinsic to the cubic interpolation algorithm. But if it is a bug, this is a bug of the cubic interpolation package.