diff --git a/Environment/ShowerAxis.cc b/Environment/ShowerAxis.cc index 3ae28638aa8871c04704de5264bdfd42788fe276..f67cfb42f8473729a9d679338f8a264150240d0e 100644 --- a/Environment/ShowerAxis.cc +++ b/Environment/ShowerAxis.cc @@ -18,18 +18,21 @@ GrammageType ShowerAxis::X(LengthType l) const { auto const fractionalBin = l / steplength_; int const lower = fractionalBin; // indices of nearest X support points 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()) { std::stringstream errormsg; errormsg << "shower axis too short, cannot extrapolate (l / max_length_ = " << l / max_length_ << ")"; 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.); + // linear interpolation between X[lower] and X[upper] return X_[lower] * lambda + X_[upper] * (1 - lambda); }