improved pitchangle binning bin() function

This commit is contained in:
2025-10-02 11:14:38 +02:00
parent de2c3618e3
commit 8425535f9d
+14 -7
View File
@@ -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<int>((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 {