21 namespace TrackFindingCDC {
23 template <
class AResultType =
double>
24 std::vector<AResultType> linspace(
double start,
27 const std::function<AResultType(
double)>& map)
29 std::vector<AResultType> result;
31 result.push_back(map(start));
32 for (std::size_t i = 1; i < n - 1; ++i) {
33 result.push_back(map((start * (n - 1 - i) +
final * i) / (n - 1)));
35 result.push_back(map(
final));
36 assert(result.size() == n);
41 template <
class AResultType =
double>
42 std::vector<AResultType> linspace(
double start,
double final, std::size_t n)
44 auto map = [](
const double in) -> AResultType {
return AResultType(in);};
45 return linspace<AResultType>(start,
final, n, map);
49 template<
class T =
double>
66 ,
m_values(linspace(lowerBound, upperBound, nBins + 1, map))
75 if (not std::isfinite(x))
return m_values.back();
76 const int iMax =
m_values.size() - 2;
79 int i = std::min(std::max(0,
static_cast<int>(iBin)), iMax);
86 if (not std::isfinite(x))
return m_values.back();
87 const int iMax =
m_values.size() - 2;
89 int i = std::min(std::max(0, iBin), iMax);
94 const T&
at(
int i)
const
96 const int iMax =
m_values.size() - 2;
97 i = std::min(std::max(0, i), iMax);
Class which holds precomputed values of a function.
int getNBins() const
Return the number of bins in this lookup table.
const T & at(int i) const
Return the value at the given index.
const T & nearest(double x) const
Return the precomputed value at the position closest to the given value.
double m_lowerBound
Lower bound of the precomputed range.
int getNPoints() const
Return the number of finite sampling points in this lookup table.
double m_binWidth
Distance between two precomputed positions.
T operator()(double x) const
Evaluate as piecewise linear interpolation.
std::vector< T > m_values
Precomputed value.
LookupTable(const std::function< T(double)> &map, std::size_t nBins, double lowerBound, double upperBound)
Constructs a look up table for the given function The function is sampled at nBins + 1 equally spaced...
double m_upperBound
Upper bound of the precomputed range.
Abstract base class for different kinds of events.