IAP GITLAB

Skip to content
Snippets Groups Projects
Commit 62a8de09 authored by Ralf Ulrich's avatar Ralf Ulrich
Browse files

Merge branch '277-showeraxis-mixes-signed-and-unsigned-int-in-comparison' into 'master'

Resolve "ShowerAxis mixes signed and unsigned int in comparison"

Closes #277

See merge request AirShowerPhysics/corsika!215
parents 1f4fa520 6366ecf9
No related branches found
No related tags found
No related merge requests found
...@@ -18,18 +18,21 @@ GrammageType ShowerAxis::X(LengthType l) const { ...@@ -18,18 +18,21 @@ GrammageType ShowerAxis::X(LengthType l) const {
auto const fractionalBin = l / steplength_; auto const fractionalBin = l / steplength_;
int const lower = fractionalBin; // indices of nearest X support points int const lower = fractionalBin; // indices of nearest X support points
auto const lambda = fractionalBin - lower; auto const lambda = fractionalBin - lower;
int const upper = lower + 1; decltype(X_.size()) const upper = lower + 1;
if (lower < 0) {
throw std::runtime_error("cannot extrapolate to points behind point of injection");
}
if (upper >= X_.size()) { if (upper >= X_.size()) {
std::stringstream errormsg; std::stringstream errormsg;
errormsg << "shower axis too short, cannot extrapolate (l / max_length_ = " errormsg << "shower axis too short, cannot extrapolate (l / max_length_ = "
<< l / max_length_ << ")"; << l / max_length_ << ")";
throw std::runtime_error(errormsg.str().c_str()); throw std::runtime_error(errormsg.str().c_str());
} else if (lower < 0) {
throw std::runtime_error("cannot extrapolate to points behind point of injection");
} }
assert(0 <= lambda && lambda <= 1.); assert(0 <= lambda && lambda <= 1.);
// linear interpolation between X[lower] and X[upper] // linear interpolation between X[lower] and X[upper]
return X_[lower] * lambda + X_[upper] * (1 - lambda); return X_[lower] * lambda + X_[upper] * (1 - lambda);
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment