22 const std::vector<double>& bin_boundaries)
23 :
IAxis(name), m_nbins(nbins)
25 if (
m_nbins != bin_boundaries.size() - 1)
27 "VariableBinAxis::VariableBinAxis() -> Error! "
28 "The size of bin_boundaries should be of size [nbins+1].");
34 :
IAxis(name), m_nbins(nbins)
77 "VariableBinAxis::findClosestIndex() -> Error! "
78 "VariableBinAxis not correctly initialized");
81 }
else if (value >=
getMax()) {
85 std::vector<double>::const_iterator top_limit =
87 if (*top_limit != value)
95 std::vector<double> result;
96 result.resize(
size(), 0.0);
97 for (
size_t i = 0; i <
size(); ++i) {
108 "'left'' should be smaller than 'right'");
118 size_t new_nbins = nbin2 - nbin1 + 1;
119 std::vector<double> new_boundaries;
120 for (
size_t i = 0; i < new_nbins + 1; ++i) {
129 throw std::runtime_error(
"VariableBinAxis::pyString not yet implemented");
134 ostr <<
"VariableBinAxis(\"" <<
getName() <<
"\", " <<
size() <<
", [";
136 ostr << std::setprecision(std::numeric_limits<double>::digits10 + 2) <<
m_bin_boundaries[i];
148 if (
size() != p_other_cast->size())
163 std::vector<double> vec_sorted = bin_boundaries;
164 std::sort(vec_sorted.begin(), vec_sorted.end());
165 for (
size_t i = 0; i < bin_boundaries.size(); ++i) {
166 if (vec_sorted[i] != bin_boundaries[i])
168 "Array with bin edges is not sorted.");
171 std::vector<double> vec = bin_boundaries;
172 vec.erase(std::unique(vec.begin(), vec.end()), vec.end());
174 if (vec.size() != bin_boundaries.size())
176 "Array with bin edges contains repeating values.");
Defines and implements namespace algo with some algorithms.
Defines many exception classes in namespace Exceptionss.
Defines class VariableBinAxis.
Interface for one-dimensional axes.
virtual bool equals(const IAxis &other) const
std::string getName() const
retrieve the label of the axis
Axis with variable bin size.
double getMax() const
Returns value of last point of axis.
double getBinCenter(size_t index) const
size_t size() const
retrieve the number of bins
void setBinBoundaries(const std::vector< double > &bin_boundaries)
double operator[](size_t index) const
indexed accessor retrieves a sample
std::vector< double > getBinCenters() const
virtual bool equals(const IAxis &other) const
Bin1D getBin(size_t index) const
retrieve a 1d bin for the given index
double getMin() const
Returns value of first point of axis.
VariableBinAxis(const std::string &name, size_t nbins, const std::vector< double > &bin_boundaries)
VariableBinAxis constructor.
std::vector< double > m_bin_boundaries
vector containing the bin limits
virtual VariableBinAxis * createClippedAxis(double left, double right) const
Creates a new clipped axis.
size_t findClosestIndex(double value) const
find bin index which is best match for given value
virtual void print(std::ostream &ostr) const
std::string pyString(const std::string &units, size_t offset) const final
VariableBinAxis * clone() const
clone function
bool almostEqual(double a, double b)
Returns true if two doubles agree within machine epsilon.
double getMidPoint() const