Nans in Optical Calculation

Issue #168 resolved
Laurie Nevay created an issue

With large numbers of particles, the optical calculations return Nans for sigmas (at least). Beta came out finite, but negative.

I've attached a fodo lattice I was using. With 5k particles, everything is fine, but with 50k, it's bad.

bdsim --file=fodo.gmad --outfile=o1 --batch --ngenerate=50000

rebdsimOptics o1_event.root o1_optics.root

pylab
import pybdsim
d = pybdsim.Data.Load("o2_optics.root")
d.Sigma_x() 
Out[5]:  
array([ nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,  nan,
    nan,  nan])

Comments (2)

  1. Andrey Abramov

    That bug was caused by two separate problems. Both are now addressed

    1. The pow() function in C++ returns NaN for some combinations of negative float bases and float powers (known problem described in their manual). Replaced pow() with std::pow() to ensure correct overloading and avoid implicit conversion of the power to float.

    2. An integer overflow occurs when raising the number of particles to a power. Basic type changed from int to long long int and powers of the number of particles are pre-calculated using doubles

  2. Log in to comment