26 size_t n = binParams.size();
28 throw std::invalid_argument(
"BinFinder: not enough bin parameters.");
30 throw std::invalid_argument(
"BinFinder: the number of bin parameters should be odd.");
32 for (
size_t i = 0; i <
n / 2; i++) {
34 double min = binParams[i * 2];
35 double max = binParams[i * 2 + 2];
41 double step = binParams[i * 2 + 1];
44 throw std::invalid_argument(
"BinFinder: step size of 0.");
45 if ((step < 0) && (min <= 0))
46 throw std::invalid_argument(
"BinFinder: logarithmic binning with 0.0 starting bin.");
48 throw std::invalid_argument(
"BinFinder: final bin must be > starting bin boundary.");
54 double log_step = log1p(
fabs(step));
60 numBins =
static_cast<int>(ceil((log(max) - log(min)) / log_step));
64 double nextToLastValue = min * pow(1.0 +
fabs(step), numBins - 1);
65 double nextToNextToLastValue = min * pow(1.0 +
fabs(step), numBins - 2);
66 double lastBinSize = max - nextToLastValue;
67 double nextToLastBinSize = nextToLastValue - nextToNextToLastValue;
68 if (lastBinSize < nextToLastBinSize * 0.25)
80 numBins =
static_cast<int>(ceil((max - min) / step));
84 double lastBinSize = max - ((numBins - 1) * step + min);
85 if (lastBinSize < step * 0.25)
92 int startBinIndex = 0;
128 if ((
x >= min) && (
x < max))
139 index =
static_cast<int>((
x - min) / step);
155 double log_x = log(
x);
158 index =
static_cast<int>((log_x - log_min) / log_step);
std::map< DeltaEMode::Type, std::string > index
std::vector< double > boundaries
Boundaries between binning regions.
std::vector< double > logSteps
Log of the step size (used by log binning)
std::vector< double > logBoundaries
Log of the boundary (used by log binning)
std::vector< double > stepSizes
Step sizes in binning regions; 1 smaller than boundaries.
int lastBinIndex()
Returns the last bin boundary index, which should be == to the size of the X axis.
int bin(double x)
Find the bin index for a value.
BinFinder(const std::vector< double > &binParams)
Constructor.
int numRegions
How many regions?
std::vector< int > endBinIndex
Index of the last boundary in the bins.