20 #include <unordered_map>
65 if (rawbin < 0)
return 0;
82 public std::iterator<std::random_access_iterator_tag,
84 const int* , const int& > {
203 const_iterator
begin() const noexcept {
return const_iterator{1}; }
230 return lhs.fCursor < rhs.fCursor;
236 return lhs.fCursor > rhs.fCursor;
242 return lhs.fCursor <= rhs.fCursor;
248 return lhs.fCursor >= rhs.fCursor;
254 return lhs.fCursor == rhs.fCursor;
260 return lhs.fCursor != rhs.fCursor;
294 int rawbin = (
x -
fLow) * fInvBinWidth;
299 constexpr
static bool CanGrow() noexcept {
return false; }
334 return lhs.GetNBins() == rhs.GetNBins()
335 && lhs.GetMinimum() == rhs.GetMinimum()
336 && lhs.GetInverseBinWidth() == rhs.GetInverseBinWidth();
385 constexpr
bool CanGrow()
const {
return false; }
410 TAxisBase(binborders.size()), fBinBorders(binborders) {
411 #ifdef R__DO_RANGE_CHECKS
412 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
414 #endif // R__DO_RANGE_CHECKS
422 TAxisBase(binborders.size()), fBinBorders(
std::move(binborders)) {
423 #ifdef R__DO_RANGE_CHECKS
424 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
426 #endif // R__DO_RANGE_CHECKS
433 const auto bBegin = fBinBorders.begin();
434 const auto bEnd = fBinBorders.end();
435 auto iNotLess = std::lower_bound(bBegin, bEnd,
x);
436 int rawbin = iNotLess - bBegin;
456 return 0.5 * (fBinBorders[bin - 1] + fBinBorders[bin]);
469 return fBinBorders[bin - 1];
484 constexpr
static bool CanGrow() noexcept {
return false; }
517 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
518 fLabelsIndex[std::string(labels[i])] = i;
524 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
525 fLabelsIndex[labels[i]] = i;
530 auto insertResult = fLabelsIndex.insert({label, -1});
531 if (insertResult.second) {
533 int idx = fLabelsIndex.size() - 1;
534 insertResult.first->second = idx;
537 return insertResult.first->second;
547 std::vector<std::string_view> vec(fLabelsIndex.size());
548 for (
const auto& kv: fLabelsIndex)
549 vec.at(kv.second) = kv.first;
590 fBinBorders({from, to}) { }
595 fBinBorders({from, to}) { }
600 fBinBorders(binborders) { }
605 fBinBorders(
std::move(binborders)) { }
611 fLabels(labels.
begin(), labels.
end()) {}
617 fLabels(labels.
begin(), labels.
end()) {}
639 for (
auto&& lab: labels)
640 fLabels.emplace_back(std::string(lab));
658 template<TAxisConfig::EKind>
667 cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
676 cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
bool operator==(const TKey &lhs, const TKey &rhs)
Histogram axis base class.
const_iterator operator--(int) noexcept
const std::vector< double > & GetBinBorders() const noexcept
Access to the bin borders used by this axis.
TAxisConfig(std::vector< double > &&binborders) noexcept
Represents a TAxisIrregular with binborders.
TAxisView(const TAxisIrregular &irr)
Construct a view on a TAxisIrregular.
bool operator<(const TKey &lhs, const TKey &rhs)
constexpr int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
int GetBinIndex(const std::string &label)
Get the bin index with label.
static Vc_ALWAYS_INLINE int_v min(const int_v &x, const int_v &y)
bool operator<=(const TKey &lhs, const TKey &rhs)
Coordinate could fit after growing the axis.
constexpr bool IsOverflowBin(int bin) const noexcept
Whether the bin index is referencing a bin higher than the axis range.
Objects used to configure the different axis types.
constexpr TAxisBase(int nbins) noexcept
Construct a TAxisBase.
Namespace for new ROOT classes and functions.
constexpr int GetNBins() const noexcept
Get the number of bins, including under- and overflow.
std::unordered_map< std::string, int > fLabelsIndex
Map of label (view on fLabels's elements) to bin index.
Common view on a TAxis, no matter what its kind.
The source is a subset of bins of the target axis.
const TAxisEquidistant * fEqui
View on a TAxisEquidistant, TAxisGrow or TAxisLabel.
bool operator>(const TKey &lhs, const TKey &rhs)
TAxisConfig(const TAxisLabels &ax)
Build a TAxisConfig from a TAxisLabels.
int FindBin(double x) const noexcept
Find the bin containing coordinate x. Forwards to the underlying axis.
int GetNBins() const noexcept
Get the number of bins. Forwards to the underlying axis.
unsigned int fNBinsNoOver
Number of bins excluding under- and overflow.
std::vector< std::string_view > GetBinLabels() const
Build a vector of labels. The position in the vector defines the label's bin.
double GetBinCenter(const std::string &label)
Get the center of the bin with label.
static constexpr const int kIgnoreBin
FindBin() returns this bin to signal that the bin number is invalid.
double GetInverseBinWidth() const noexcept
Get the inverse of the width of the bins.
Converts a TAxisConfig of whatever kind to the corresponding TAxisBase-derived object.
An axis that can extend its range, keeping the number of its bins unchanged.
double fLow
The lower limit of the axis.
std::vector< double > fBinBorders
Bin borders, one more than the number of non-overflow bins.
Axis_t operator()(TAxisConfig cfg)
double GetBinTo(int bin) const noexcept
Get the high bin border for the given bin index.
friend bool operator!=(const_iterator lhs, const_iterator rhs) noexcept
i != j
The source axis and target axis have different binning.
static constexpr bool CanGrow() noexcept
This axis cannot grow.
int Grow(int toBin)
Grow this axis to make the "virtual bin" toBin in-range.
double GetBinCenter(int i) const noexcept
Get the bin center of bin index i. Forwards to the underlying axis.
double GetBinCenter(int bin) const noexcept
Get the bin center of the bin with the given index.
friend bool operator<(const_iterator lhs, const_iterator rhs) noexcept
i < j
double GetBinWidth() const noexcept
Get the width of the bins.
TAxisConfig(const std::vector< double > &binborders)
Represents a TAxisIrregular with binborders.
A TAxisGrow that has a label assigned to each bin and a bin width of 1.
constexpr TAxisEquidistant(int nbins, double low, double high) noexcept
Initialize a TAxisEquidistant.
TAxisBase & operator=(const TAxisBase &)=default
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...
int GetBinIndexForLowEdge(double x) const noexcept
If the coordinate x is a bin low edge (within 1E-6 of the coordinate), return the bin for which this ...
friend bool operator==(const_iterator lhs, const_iterator rhs) noexcept
i == j
EKind fKind
The kind of axis represented by this configuration.
double GetBinFrom(int bin) const noexcept
Get the low bin border for the given bin index.
TAxisConfig(std::vector< std::string > &&labels)
Represents a TAxisLabels with labels.
const int * operator*() const noexcept
represents a TAxisEquidistant
static constexpr const int kNOverflowBins[4]
Extra bins for each EAxisOverflow value.
Axis with equidistant bin borders.
const_iterator begin() const noexcept
Get a const_iterator pointing to the first non-underflow bin.
const_iterator operator-(int d) noexcept
double GetMaximum() const noexcept
Get the high end of the axis range.
Axis_t operator()(TAxisConfig cfg)
TAxisIrregular(std::vector< double > &&binborders) noexcept
Construct a TAxisIrregular from a vector of bin borders.
double GetMinimum() const noexcept
Get the low end of the axis range.
constexpr bool CanGrow() const
This axis kind can increase its range.
constexpr int FindBin(double x) const noexcept
Find the bin index for the given coordinate.
const_iterator end_with_overflow() const noexcept
Get a const_iterator pointing right beyond the overflow bin.
TAxisIrregular(const std::vector< double > &binborders)
Construct a TAxisIrregular from a vector of bin borders.
TAxisEquidistant()=default
const_iterator & operator-=(int d) noexcept
const_iterator & operator--() noexcept
–i
TAxisConfig(const std::vector< std::string_view > &labels)
Represents a TAxisLabels with labels.
int operator->() const noexcept
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
Source and target axes are identical.
int FindBin(double x) const noexcept
Find the bin index corresponding to coordinate x.
EAxisCompatibility CanMap(TAxisEquidistant &target, TAxisEquidistant &source) noexcept
Whether (and how) the source axis can be merged into the target axis.
Axis_t operator()(TAxisConfig cfg) noexcept
double fInvBinWidth
The inverse of the bin width.
const_iterator begin_with_underflow() const noexcept
Get a const_iterator pointing the underflow bin.
std::vector< double > fBinBorders
Bin borders of the TAxisIrregular.
TAxisLabels(const std::vector< std::string_view > &labels)
Construct a TAxisLables from a vector of string_views.
friend bool operator>=(const_iterator lhs, const_iterator rhs) noexcept
i >= j
double GetBinTo(int i) const noexcept
Get the maximal coordinate of bin index i. Forwards to the underlying axis.
const_iterator & operator++() noexcept
++i
Axis_t operator()(TAxisConfig cfg) noexcept
The bins of the source axis have finer granularity, but the bin borders are compatible.
double GetBinTo(int bin) const noexcept
Get the higher bin border for a given bin index.
const_iterator end() const noexcept
Get a const_iterator pointing right beyond the last non-overflow bin (i.e.
const_iterator operator++(int) noexcept
i++
The returned bin index is valid.
const_iterator operator+(int d) noexcept
An axis with non-equidistant bins (also known as "variable binning").
static Vc_ALWAYS_INLINE int_v max(const int_v &x, const int_v &y)
constexpr int GetOverflowBin() const noexcept
Get the bin index for the underflow bin.
const TAxisIrregular * fIrr
View on a TAxisIrregular.
TAxisConfig(const TAxisEquidistant &ax)
Build a TAxisConfig from a TAxisEquidistant.
double GetBinFrom(int i) const noexcept
Get the minimal coordinate of bin index i. Forwards to the underlying axis.
std::vector< std::string > fLabels
Bin labels for a TAxisLabels.
TAxisView(const TAxisEquidistant &equi)
Construct a view on a TAxisEquidistant, TAxisGrow or TAxisLabel.
TAxisLabels(const std::vector< std::string > &labels)
Construct a TAxisLables from a vector of strings.
Random const_iterator through bins.
#define R__ERROR_HERE(GROUP)
EKind GetKind() const noexcept
Get the axis kind represented by this TAxisConfig.
double GetBinCenter(int bin) const noexcept
Get the bin center for the given bin index.
const_iterator & operator+=(int d) noexcept
double GetBinFrom(int bin) const noexcept
Get the lower bin border for a given bin index.
friend bool operator>(const_iterator lhs, const_iterator rhs) noexcept
i > j
constexpr TAxisGrow(int nbins, double low, double high) noexcept
Initialize a TAxisGrow.
constexpr int GetUnderflowBin() const noexcept
Get the bin index for the underflow bin.
EFindStatus
Status of FindBin(x)
represents a TAxisIrregular
constexpr int AdjustOverflowBinNumber(int rawbin) const
Given rawbin (<0 for underflow, >= GetNBinsNoOver() for overflow), determine the actual bin number ta...
static constexpr bool CanGrow() noexcept
This axis cannot be extended.
int fCursor
Current iteration position.
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
friend bool operator<=(const_iterator lhs, const_iterator rhs) noexcept
i <= j
bool operator!=(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i != j
TAxisConfig(Grow_t, int nbins, double from, double to)
Represents a TAxisGrow with nbins from from to to.
TAxisConfig(int nbins, double from, double to)
Represents a TAxisEquidistant with nbins from from to to.
TAxisBase(const TAxisBase &)=default
const_iterator(int cursor) noexcept
Initialize a const_iterator with its position.
static constexpr const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
constexpr bool IsUnderflowBin(int bin) const noexcept
Whether the bin index is referencing a bin lower than the axis range.
bool operator>=(const TKey &lhs, const TKey &rhs)