From 8425535f9d8fc9162c98d05b04bdc3bd514a72ef Mon Sep 17 00:00:00 2001 From: csendlinger Date: Thu, 2 Oct 2025 11:14:38 +0200 Subject: [PATCH] improved pitchangle binning bin() function --- src/simulation/energy_binning.cpp | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) 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 {