fix mu=-1 bug

This commit is contained in:
2025-03-18 12:15:24 +01:00
parent 51877687b1
commit 88dcafee03
2 changed files with 27 additions and 22 deletions
+7
View File
@@ -70,6 +70,13 @@ 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);
// 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());
}
return (it - pitch_angle_bin_borders_.begin()) - 1;
}
+20 -22
View File
@@ -180,28 +180,6 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
double energy_eV = energy_dist(*engine);
// std::stringstream out;
// if(above) {
// out << "Above: ";
// } else {
// out << "Below: ";
// }
// out << "\n\tEnergyValues: " << energyValues;
// out << "\n\tBinBorders: [";
// for(auto bb : energyBinBorders_)
// out << bb << ", ";
// out << "]";
// out << "\n\tdrawn energy: " << energy_eV;
// out << "\n\tlowerIndexEnergyValues: " << energy_values.lbound();
// out << "\n\tBeginIterator: " << *bordersBeginIterator;
// out << "\n\tEndIterator: " << *(bordersEndIterator - 1);
// out << "\n\tValueBeginIterator: " << *valuesBeginIterator;
// DEBUG_LEVEL_2(out.str());
// if (isnan(energy_eV)) {
// ERROR("energy value is nan!");
// }
// draw pitch angle from DynamicDensityField
blitz::Array<double, 1> pitchAngleValues = density_field_->
@@ -214,6 +192,26 @@ CartesianVector VelocityDistributionFromDensityField::rollVelocity(
double pitchAngle = pitchAngle_dist(*engine);
#ifdef debug
if((std::isnan(pitchAngle)) || (std::isnan(energy_eV))) {
std::stringstream out;
above ? out << "Above" : out << "Below";
out << " threshold bin of " << E_th_bin;
out << "\npitchAngle: " << pitchAngle;
out << "\nenergy value: " << energy_eV;
out << "\nenergy values: " << energyValues;
out << "\npitch angle values: " << pitchAngleValues;
out << "\nenergy bin borders: [ ";
for(auto element : energyBinBorders_) {
out << element << " ";
}
out << "]";
ERROR(out.str());
}
#endif
// construct the velocity
const double theta = theta_distribution_(*engine)*2*M_PI;