10 #ifndef ICARUSALG_GALLERY_DETECTORACTIVITYRATEPLOTS_BINNER_H
11 #define ICARUSALG_GALLERY_DETECTORACTIVITYRATEPLOTS_BINNER_H
26 std::ostream& operator<< (std::ostream&, Binner<T>
const&);
78 using Step_t = decltype(std::declval<Data_t>() - std::declval<Data_t>());
149 {
return static_cast<int>(std::floor(
relative(value))); }
156 {
return std::clamp(
bin(value), min, max); }
207 template <
typename T>
211 , fNBins(static_cast<unsigned int>(
std::ceil((upper - lower) / step)))
212 , fUpper(lowerEdge(fNBins))
213 { assert(lower <= upper); }
217 template <
typename T>
218 std::ostream& util::operator<< (std::ostream& out, Binner<T>
const& binner) {
220 out <<
"[ " << binner.lower() <<
" -- " << binner.upper() <<
" ] ("
221 << binner.nBins() <<
"x " << binner.step() <<
")";
229 #endif // ICARUSALG_GALLERY_DETECTORACTIVITYRATEPLOTS_BINNER_H
int cappedBin(Data_t value, int min, int max) const
Returns a bin number for value clamped between min and max included.
int cappedBin(Data_t value) const
Returns a valid bin index, capping if value is out of range.
double std(const std::vector< short > &wf, const double ped_mean, size_t start, size_t nsample)
Helper class binning values in a range.
bool contains(Data_t value) const
Returns if value is in the range.
simulation_time Data_t
Type of values on the binning axis.
int cappedBinWithOverflows(Data_t value) const
Returns a valid bin index or -1 for underflow or nBins() for overflow.
Data_t binCenter(int iBin) const
Returns the center of the bin with the specified index iBin.
int bin(Data_t value) const
Returns bin number for value (unbound).
Step_t fStep
Width of the bins.
Data_t lowerEdge(int iBin) const
Returns the lower edge of the bin with the specified index iBin.
Binner(Data_t lower, Data_t upper, Step_t step)
Constructor: covers the range from lower to upper or above.
double relative(Data_t value) const
Returns value relative to the range (lower = 0, upper = 1).
Data_t fUpper
Upper bound of the covered range.
Data_t fLower
Lower bound of the covered range.
unsigned int fNBins
Number of bins in the range.
Data_t upperEdge(int iBin) const
Returns the upper edge of the bin with the specified index iBin.
Data_t upper() const
Returns the upper limit of the range.
Step_t step() const
Returns the step size.
int operator()(Data_t value) const
decltype(std::declval< Data_t >()-std::declval< Data_t >()) Step_t
Type of difference between binning axis values.
unsigned int nBins() const
Returns the number of bins in the range.