diff --git a/src/simulation/energy_binning.cpp b/src/simulation/energy_binning.cpp index f7769e3..16cfc28 100755 --- a/src/simulation/energy_binning.cpp +++ b/src/simulation/energy_binning.cpp @@ -69,17 +69,24 @@ PitchAngleBinning::PitchAngleBinning(int num_bins) : pitch_angle_bin_borders_(generateLinearBinBorders(-1, 1, num_bins)) {} int PitchAngleBinning::bin(double pitch_angle) const { - auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(), - pitch_angle_bin_borders_.end(), - pitch_angle); + // auto const it = std::lower_bound(pitch_angle_bin_borders_.begin(), + // pitch_angle_bin_borders_.end(), + // pitch_angle); + int bin = static_cast((pitch_angle + 1)/2 * numBins()); // otherwise the valid mu-value of -1 is assigned to the underflow // bin which can lead to a segfault in the drawing of the pitch // angle in "velocity_distribution.cpp" - if(!(pitch_angle < pitch_angle_bin_borders_.front()) && - (it == pitch_angle_bin_borders_.begin())) { - return (it - pitch_angle_bin_borders_.begin()); + // if(!(pitch_angle < pitch_angle_bin_borders_.front()) && + // (it == pitch_angle_bin_borders_.begin())) { + // return (it - pitch_angle_bin_borders_.begin()); + // } + // return (it - pitch_angle_bin_borders_.begin()) - 1; + // exclude mu=1 from the overflow bin + if (bin == numBins() && pitch_angle <= 1) { + bin--; } - return (it - pitch_angle_bin_borders_.begin()) - 1; + + return bin; } int PitchAngleBinning::numBins() const {