diff --git a/icarusalg/Utilities/FastAndPoorGauss.h b/icarusalg/Utilities/FastAndPoorGauss.h index ca67ddd..fd17d14 100644 --- a/icarusalg/Utilities/FastAndPoorGauss.h +++ b/icarusalg/Utilities/FastAndPoorGauss.h @@ -13,7 +13,7 @@ // C/C++ standard library #include #include // std::is_integral_v, std::is_signed_v -#include // std::sqrt() +#include // std::sqrt(), std::copysign(), std::abs() #include // std::size_t @@ -103,16 +103,20 @@ class util::FastAndPoorGauss { //@{ /// Returns the Gaussian distributed value corresponding to `u`. - Data_t transform(Data_t const u) const { return fSamples[indexOf(u)]; } + static Data_t transform(Data_t u) + { u -= 0.5; return std::copysign(fSamples[indexOf(std::abs(2*u))], u); } Data_t operator() (Data_t const u) const { return transform(u); } //@} + /// Returns the set of precomputed points. + static std::array const& samples() { return fSamples; } + private: /// Sampled points of inverse Gaussian. static std::array const fSamples; /// Returns the index of the precomputed table serving the value `u`. - std::size_t indexOf(Data_t u) const; + static std::size_t indexOf(Data_t u); /// Fills the pre-sampling table. static std::array makeSamples(); @@ -231,7 +235,7 @@ std::array const util::FastAndPoorGauss::fSamples // ----------------------------------------------------------------------------- template -std::size_t util::FastAndPoorGauss::indexOf(Data_t u) const { +std::size_t util::FastAndPoorGauss::indexOf(Data_t u) { return static_cast(u * NPoints); } // util::FastAndPoorGauss<>::indexOf() @@ -248,7 +252,7 @@ auto util::FastAndPoorGauss::makeSamples() -> std::array util::UniformSequence extract { NPoints }; for(Data_t& value: samples) - value = static_cast(TMath::ErfInverse(extract() * 2.0 - 1.0) * V2); + value = static_cast(TMath::ErfInverse(extract()) * V2); return samples; } // util::FastAndPoorGauss<>::makeSamples() diff --git a/icarusalg/Utilities/SampledFunction.h b/icarusalg/Utilities/SampledFunction.h index f71936f..890560c 100644 --- a/icarusalg/Utilities/SampledFunction.h +++ b/icarusalg/Utilities/SampledFunction.h @@ -64,28 +64,28 @@ namespace util { * _M N_. * * @note Due to the implementation of `gsl::span`, its iterators are valid only - * while the span object is valid as well. - * This means that a construct like: - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} - * for (auto it = sf.subsample(0).begin(); it != sf.subsample(0).end(); ++it) - * // ... - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * will mysteriously fail at run time because `it` refers to a temporary - * span that quickly falls out of scope (and the end iterator refers to - * a different span object, too). The correct pattern is to store the - * subsample result before iterating through it: - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} - * auto const& subsample = sf.subsample(0); - * for (auto it = subsample.begin(); it != subsample.end(); ++it) - * // ... - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * or, if appliable, let the range-for loop di that for us: - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} - * for (auto value: sf.subsample(0)) - * // ... - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * This will not be the case any more with `std::span`, which apparently - * is going to satisfy the `borrowed_range` requirement. + * while the span object is valid as well. + * This means that a construct like: + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} + * for (auto it = sf.subsample(0).begin(); it != sf.subsample(0).end(); ++it) + * // ... + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * will mysteriously fail at run time because `it` refers to a temporary + * span that quickly falls out of scope (and the end iterator refers to + * a different span object, too). The correct pattern is to store the + * subsample result before iterating through it: + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} + * auto const& subsample = sf.subsample(0); + * for (auto it = subsample.begin(); it != subsample.end(); ++it) + * // ... + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * or, if applicable, let the range-for loop di that for us: + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~{.cpp} + * for (auto value: sf.subsample(0)) + * // ... + * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + * This will not be the case any more with `std::span`, which apparently + * is going to satisfy the `borrowed_range` requirement. * */ template diff --git a/icarusalg/Utilities/WaveformOperations.h b/icarusalg/Utilities/WaveformOperations.h index c490d57..c047ea3 100644 --- a/icarusalg/Utilities/WaveformOperations.h +++ b/icarusalg/Utilities/WaveformOperations.h @@ -84,6 +84,7 @@ namespace icarus::waveform_operations { // --- BEGIN --- Operations relative to the baseline --------------------- /// @name Operations relative to the baseline /// @{ + /// Returns the current baseline. Sample_t baseline() const { return fBaseline; }