23 , m_nbins(bin_boundaries.size() - 1)
48 throw std::runtime_error(
"VariableBinAxis::bin() -> Error. Wrong index.");
72 throw std::runtime_error(
"VariableBinAxis::findClosestIndex() -> Error! "
73 "VariableBinAxis not correctly initialized");
80 if (*top_limit != value)
88 std::vector<double> result;
89 result.resize(
size(), 0.0);
90 for (
size_t i = 0; i <
size(); ++i)
98 throw std::runtime_error(
"VariableBinAxis::clip() -> Error. "
99 "'lower' should be smaller than 'upper'");
108 const size_t new_nbins = nbin2 - nbin1 + 1;
110 std::vector<double> new_boundaries;
111 for (
size_t i = 0; i < new_nbins + 1; ++i)
120 ostr <<
"VariableBinAxis(\"" <<
axisName() <<
"\", " <<
size() <<
", [";
122 ostr << std::setprecision(std::numeric_limits<double>::digits10 + 2) <<
m_bin_boundaries[i];
133 if (
const auto* p_other_cast =
dynamic_cast<const VariableBinAxis*
>(&other)) {
134 if (
size() != p_other_cast->size())
138 p_other_cast->m_bin_boundaries[i]))
149 std::vector<double> vec_sorted = bin_boundaries;
150 std::sort(vec_sorted.begin(), vec_sorted.end());
151 for (
size_t i = 0; i < bin_boundaries.size(); ++i) {
152 if (vec_sorted[i] != bin_boundaries[i])
153 throw std::runtime_error(
"VariableBinAxis::setBinBoundaries() -> Error. "
154 "Array with bin edges is not sorted.");
157 std::vector<double> vec = bin_boundaries;
158 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
160 if (vec.size() != bin_boundaries.size())
161 throw std::runtime_error(
"VariableBinAxis::setBinBoundaries() -> Error. "
162 "Array with bin edges contains repeating values.");
Defines and implements namespace BaseUtils::algo with some algorithms.
Defines structs Bin1D, Bin1DCVector.
Defines class VariableBinAxis.
Abstract base class for one-dimensional axes.
virtual bool equals(const IAxis &other) const
std::string axisName() const
Returns the label of the axis.
Axis with variable bin size.
double max() const override
Returns value of last point of axis.
bool equals(const IAxis &other) const override
void clip(double lower, double upper) override
Clips this axis to the given values.
std::vector< double > binCenters() const override
void setBinBoundaries(const std::vector< double > &bin_boundaries)
double binCenter(size_t index) const override
double operator[](size_t index) const override
indexed accessor retrieves a sample
Bin1D bin(size_t index) const override
retrieve a 1d bin for the given index
size_t size() const override
Returns the number of bins.
std::vector< double > m_bin_boundaries
vector containing the bin limits
VariableBinAxis * clone() const override
size_t findClosestIndex(double value) const override
find bin index which is best match for given value
double min() const override
Returns value of first point of axis.
VariableBinAxis(const std::string &name, const std::vector< double > &bin_boundaries)
VariableBinAxis constructor.
void print(std::ostream &ostr) const override
bool almostEqual(double a, double b)
Returns true if two doubles agree within machine epsilon.