26 double floorMult(
double value,
double factor)
27 {
return factor * std::floor(value / factor); }
31 (
double lower,
double upper,
double width)
34 { floorMult(lower, width), upper, width };
44 (
double lower,
double upper,
double width)
47 , fNBins{ NBinsFor(fLower, upper, fWidth) }
48 , fUpper{ fLower + fNBins * fWidth }
50 assert(lower <= upper);
52 assert(fLower <= lower);
53 assert(fUpper >= upper);
59 {
return static_cast<int>(std::floor((value -
lower()) /
binWidth())); }
66 double const low = lower() + binWidth() * iBin;
67 return {
low, low + binWidth() };
73 (
double lower,
double upper,
double width)
74 {
return static_cast<unsigned long>(std::ceil((upper - lower) / width)); }
81 double lower,
double upper,
double width,
82 std::initializer_list<double> hints ,
88 std::move(hints), allowedStretch
90 return makeBinningAlignedTo0(lower, upper, finalWidth);
97 double lower,
double upper,
unsigned long nBins,
98 std::initializer_list<double> hints ,
103 lower, upper, (upper - lower) / nBins, nBins,
104 std::move(hints), allowedStretch
106 return makeBinningAlignedTo0(lower, upper, finalWidth);
113 BinningSpecs const& binning,
double boundary,
bool extendCoverage
116 int const iBin = binning.
binWith(boundary);
117 std::pair<double, double>
const binBorders = binning.binBorders(iBin);
119 double const shift { boundary - (
120 ((boundary - binBorders.first) <= (binBorders.second - boundary))
122 : boundary - binBorders.second
126 double const width = binning.binWidth();
127 double lower = binning.lower() +
shift;
128 double upper = binning.upper() +
shift;
129 if (extendCoverage && (
shift != 0.0)) {
130 if (
shift > 0.0) lower -= width;
141 double lower,
double upper,
142 double width,
unsigned long nBins,
143 std::initializer_list<double> hints ,
144 double allowedStretch
147 assert(allowedStretch > 0.0);
149 assert(lower <= upper);
153 double const order = std::pow(10.0, std::floor(std::log10(width)));
155 double span = upper - lower;
159 using Quality_t = std::pair<double, double>;
161 double best_w = width;
162 Quality_t best_d { allowedStretch, 0.0 };
163 for (
double const factor: hints) {
164 double const w = order * factor;
169 if (d >= best_d)
continue;
int binWith(double value) const
Simple utility for human-friendly binning.
BinningSpecs(double lower, double upper, double width)
Constructor: all fields specified, no adjustment performed.
double lower() const
Returns the value of the lower end of the first bin.
double chooseBinningWidth(double lower, double upper, double width, unsigned long nBins, std::initializer_list< double > hints=DefaultBinningHints, double allowedStretch=DefaultAllowedBinningStretch)
Returns the "optimal" bin width for the requested parameters.
standard_dbscan3dalg useful for diagnostics hits not in a line will not be clustered on on only for track like only for track like on on the smaller the less shower like tracks low
BinningSpecs alignBinningTo(BinningSpecs const &binning, double boundary, bool extendCoverage=true)
Returns a binning shifted to align with the specified boundary.
Data structure holding binning information.
double binWidth() const
Returns the width of the bins (all bins have the same width).
std::pair< double, double > binBorders(int iBin) const
Returns the lower and upper borders of the bin with the specified index.
static unsigned long NBinsFor(double lower, double upper, double width)
Returns a number of bins large enough to cover the specified range.
BinningSpecs makeBinningFromNBins(double lower, double upper, unsigned long nBins, std::initializer_list< double > hints=DefaultBinningHints, double allowedStretch=DefaultAllowedBinningStretch)
Returns the "optimal" binning for the requested parameters.
BinningSpecs makeBinningFromBinWidth(double lower, double upper, double width, std::initializer_list< double > hints=DefaultBinningHints, double allowedStretch=DefaultAllowedBinningStretch)
Returns the "optimal" binning for the requested parameters.