`proposal::ContinuousProcess::getMaxStepLength` can return negative lengths
Error description
@riehn found a shower which failed with the following exception, which was thrown by PROPOSAL:
terminate called after throwing an instance of 'MathException'
what(): Root must be bracketed in Bisection method!
To reproduce the error: This is a shower run on the sophia-le-crash
branch, using the corsika.cpp
example where emcut
was set to 50_MeV
, and the script was run with -p 22 -E 1000000 -N 1 -f photon_1PeV_1 -s 1
Cause of error
I backtracked the error. The problem starts with the function proposal::ContinuousProcess::getMaxStepLength
being called with an electron which has an energy of 49.99499 MeV, which is below the emcut
.
The line
auto const energy_lim =
std::max(energy * 0.9, // either 10% relative loss max., or
get_kinetic_energy_propagation_threshold(
code) // energy thresholds globally defined for individual particles
* 0.9999 // need to go slightly below global e-cut to assure removal
// in ParticleCut. This does not matter since at cut-time
// the entire energy is removed.
);
sets the energy_lim
to 49.995 MeV, which is slighty smaller than energy
.
The line
auto grammage =
(c->second).disp->SolveTrackIntegral(energy / 1_MeV, energy_lim / 1_MeV) * 1_g /
square(1_cm);
is now called, basically asking PROPOSAL "Which distance does my electron of an energy 49.99499 MeV travel until it has an energy of 49.995 MeV". PROPOSAL answers this question with -3.5e-6 g/cm^2
, which is technically correct, but also means that getMaxStepLength
now returns a negative distance.
This causes the following algorithm to fail, explicitly in proposal::ContinuousProcess::doContinuous
.
Solution? Or is there something wrong with the algorithm?
The simplest solution from my point of view would be to just catch any negative values that proposal::ContinuousProcess::getMaxStepLength
might return, and setting them to zero instead. From a physical point of view, returning something negative here just doesn't make any sense.
However, I wanted to open this issue to first discuss whether it is already unexpected that a particle below the energy cut is passed to proposal.
Furthermore, we might think about catching all exceptions that PROPOSAL might throw within CORSIKA. But this is something for another issue, and probably something to be discussed in a technical call.