Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions icarusalg/Utilities/FastAndPoorGauss.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// C/C++ standard library
#include <array>
#include <type_traits> // std::is_integral_v, std::is_signed_v
#include <cmath> // std::sqrt()
#include <cmath> // std::sqrt(), std::copysign(), std::abs()
#include <cstddef> // std::size_t


Expand Down Expand Up @@ -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<Data_t, N> const& samples() { return fSamples; }

private:
/// Sampled points of inverse Gaussian.
static std::array<Data_t, N> 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<Data_t, NPoints> makeSamples();
Expand Down Expand Up @@ -231,7 +235,7 @@ std::array<T, N> const util::FastAndPoorGauss<N, T>::fSamples

// -----------------------------------------------------------------------------
template <std::size_t N, typename T>
std::size_t util::FastAndPoorGauss<N, T>::indexOf(Data_t u) const {
std::size_t util::FastAndPoorGauss<N, T>::indexOf(Data_t u) {
return static_cast<std::size_t>(u * NPoints);
} // util::FastAndPoorGauss<>::indexOf()

Expand All @@ -248,7 +252,7 @@ auto util::FastAndPoorGauss<N, T>::makeSamples() -> std::array<Data_t, NPoints>
util::UniformSequence<Data_t> extract { NPoints };

for(Data_t& value: samples)
value = static_cast<Data_t>(TMath::ErfInverse(extract() * 2.0 - 1.0) * V2);
value = static_cast<Data_t>(TMath::ErfInverse(extract()) * V2);

return samples;
} // util::FastAndPoorGauss<>::makeSamples()
Expand Down
44 changes: 22 additions & 22 deletions icarusalg/Utilities/SampledFunction.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename XType = double, typename YType = XType>
Expand Down
1 change: 1 addition & 0 deletions icarusalg/Utilities/WaveformOperations.h
Original file line number Diff line number Diff line change
Expand Up @@ -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; }

Expand Down