23 :
IAxis(name), m_nbins(nbins), m_start(start), m_end(end)
38 double step = (m_end - m_start) / m_nbins;
39 return m_start + (index + 0.5) * step;
47 double step = (m_end - m_start) / m_nbins;
48 Bin1D result(m_start + step * index, m_start + step * (index + 1));
56 }
else if (value >=
getMax()) {
60 double step = (m_end - m_start) / m_nbins;
61 return int((value - m_start) / step);
64 std::vector<double> FixedBinAxis::getBinCenters()
const
66 std::vector<double> result;
67 result.resize(
size(), 0.0);
68 for (
size_t i = 0; i <
size(); ++i) {
69 result[i] =
getBin(i).getMidPoint();
74 std::vector<double> FixedBinAxis::getBinBoundaries()
const
76 std::vector<double> result;
77 result.resize(
size() + 1, 0.0);
78 for (
size_t i = 0; i <
size(); ++i) {
89 "'left' should be smaller than 'right'");
92 left =
getBin(0).getMidPoint();
103 void FixedBinAxis::print(std::ostream& ostr)
const
105 ostr <<
"FixedBinAxis(\"" <<
getName() <<
"\", " <<
size() <<
", "
106 << std::setprecision(std::numeric_limits<double>::digits10 + 2) <<
getMin() <<
", "
110 bool FixedBinAxis::equals(
const IAxis& other)
const
112 if (!IAxis::equals(other))
115 if (
size() != otherAxis->size())
126 std::string FixedBinAxis::pyString(
const std::string& units,
size_t)
const
128 std::ostringstream result;
129 result <<
"ba.FixedBinAxis(" << pyfmt::printString(
getName()) <<
", " <<
size() <<
", "
130 << pyfmt::printValue(
getMin(), units) <<
", " << pyfmt::printValue(
getMax(), units)
Defines and implements namespace algo with some algorithms.
Defines many exception classes in namespace Exceptionss.
Defines class FixedBinAxis.
Defines functions in namespace pyfmt.
Axis with fixed bin size.
FixedBinAxis * createClippedAxis(double left, double right) const
Creates a new clipped axis.
double operator[](size_t index) const
indexed accessor retrieves a sample
size_t findClosestIndex(double value) const
find bin index which is best match for given value
double getMax() const
Returns value of last point of axis.
FixedBinAxis * clone() const
clone function
double getMin() const
Returns value of first point of axis.
FixedBinAxis(const std::string &name, size_t nbins, double start, double end)
FixedBinAxis constructor.
size_t size() const
retrieve the number of bins
Bin1D getBin(size_t index) const
retrieve a 1d bin for the given index
Interface for one-dimensional axes.
std::string getName() const
retrieve the label of the axis
bool almostEqual(double a, double b)
Returns true if two doubles agree within machine epsilon.
double m_upper
upper bound of the bin
double m_lower
lower bound of the bin