20 #include <unordered_map> 65 if (rawbin < 0)
return 0;
82 public std::iterator<std::random_access_iterator_tag,
84 const int* , const int& > {
108 const_iterator old(*
this);
134 const_iterator ret(*
this);
147 const int*
operator*() const noexcept {
return &fCursor; }
153 friend bool operator<=(const_iterator lhs, const_iterator rhs) noexcept;
154 friend bool operator>=(const_iterator lhs, const_iterator rhs) noexcept;
155 friend bool operator==(const_iterator lhs, const_iterator rhs) noexcept;
156 friend bool operator!=(const_iterator lhs, const_iterator rhs) noexcept;
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;
274 double fInvBinWidth = 0.;
288 fInvBinWidth(
nbins / (high - low)) { }
294 int rawbin = (
x - fLow) * fInvBinWidth;
299 constexpr
static bool CanGrow() noexcept {
return false; }
315 return fLow + (bin + 0.5) / fInvBinWidth;
320 return fLow + bin / fInvBinWidth;
325 return GetBinFrom(bin + 1);
328 int GetBinIndexForLowEdge(
double x)
const noexcept;
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];
480 return GetBinFrom(bin + 1);
484 constexpr
static bool CanGrow() noexcept {
return false; }
487 const std::vector<double>&
GetBinBorders() const noexcept {
return fBinBorders; }
516 TAxisGrow(labels.size(), 0., static_cast<double>(labels.size())) {
517 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
518 fLabelsIndex[std::string(labels[i])] = i;
523 TAxisGrow(labels.size(), 0., static_cast<double>(labels.size())) {
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;
542 return GetBinIndex(label) - 0.5;
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}) { }
599 TAxisBase(binborders.size()), fKind(kIrregular),
600 fBinBorders(binborders) { }
604 TAxisBase(binborders.size()), fKind(kIrregular),
605 fBinBorders(
std::move(binborders)) { }
611 fLabels(labels.
begin(), labels.
end()) {}
617 fLabels(labels.
begin(), labels.
end()) {}
633 TAxisBase(ax), fKind(kIrregular), fBinBorders(ax.GetBinBorders()) {}
639 for (
auto&& lab: labels)
640 fLabels.emplace_back(std::string(lab));
648 const std::vector<double> &
GetBinBorders() const noexcept {
return fBinBorders; }
650 const std::vector<std::string> &
GetBinLabels() const noexcept {
return fLabels; }
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
TAxisConfig(std::vector< double > &&binborders) noexcept
Represents a TAxisIrregular with binborders.
TAxisView(const TAxisIrregular &irr)
Construct a view on a TAxisIrregular.
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
bool operator<(const TKey &lhs, const TKey &rhs)
int GetBinIndex(const std::string &label)
Get the bin index with label.
const std::vector< double > & GetBinBorders() const noexcept
Access to the bin borders used by this axis.
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.
Objects used to configure the different axis types.
constexpr TAxisBase(int nbins) noexcept
Construct a TAxisBase.
Namespace for new ROOT classes and functions.
int FindBin(double x) const noexcept
Find the bin containing coordinate x. Forwards to the underlying axis.
std::unordered_map< std::string, int > fLabelsIndex
Map of label (view on fLabels's elements) to bin index.
constexpr bool IsOverflowBin(int bin) const noexcept
Whether the bin index is referencing a bin higher than the axis range.
Common view on a TAxis, no matter what its kind.
The source is a subset of bins of the target axis.
bool operator>(const TKey &lhs, const TKey &rhs)
TAxisConfig(const TAxisLabels &ax)
Build a TAxisConfig from a TAxisLabels.
double GetMinimum() const noexcept
Get the low end of the axis range.
constexpr int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
const int * operator*() const noexcept
double GetBinCenter(int i) const noexcept
Get the bin center of bin index i. Forwards to the underlying axis.
double GetBinFrom(int bin) const noexcept
Get the low bin border for the given bin index.
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.
constexpr int GetUnderflowBin() const noexcept
Get the bin index for the underflow bin.
double GetInverseBinWidth() const noexcept
Get the inverse of the width of the bins.
static constexpr const int kIgnoreBin
FindBin() returns this bin to signal that the bin number is invalid.
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.
const_iterator begin() const noexcept
Get a const_iterator pointing to the first non-underflow bin.
std::vector< double > fBinBorders
Bin borders, one more than the number of non-overflow bins.
Axis_t operator()(TAxisConfig cfg)
The source axis and target axis have different binning.
static constexpr bool CanGrow() noexcept
This axis cannot grow.
TAxisConfig(const std::vector< double > &binborders)
Represents a TAxisIrregular with binborders.
const_iterator begin_with_underflow() const noexcept
Get a const_iterator pointing the underflow bin.
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.
const_iterator end_with_overflow() const noexcept
Get a const_iterator pointing right beyond the overflow bin.
TAxisBase & operator=(const TAxisBase &)=default
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...
constexpr int GetOverflowBin() const noexcept
Get the bin index for the underflow bin.
int GetNBins() const noexcept
Get the number of bins. Forwards to the underlying axis.
EKind fKind
The kind of axis represented by this configuration.
double GetBinFrom(int i) const noexcept
Get the minimal coordinate of bin index i. Forwards to the underlying axis.
TAxisConfig(std::vector< std::string > &&labels)
Represents a TAxisLabels with labels.
represents a TAxisEquidistant
double GetBinTo(int bin) const noexcept
Get the high bin border for the given bin index.
static constexpr const int kNOverflowBins[4]
Extra bins for each EAxisOverflow value.
Axis with equidistant bin borders.
const_iterator operator-(int d) noexcept
Axis_t operator()(TAxisConfig cfg)
TAxisIrregular(std::vector< double > &&binborders) noexcept
Construct a TAxisIrregular from a vector of bin borders.
constexpr bool CanGrow() const
This axis kind can increase its range.
EKind GetKind() const noexcept
Get the axis kind represented by this TAxisConfig.
TAxisIrregular(const std::vector< double > &binborders)
Construct a TAxisIrregular from a vector of bin borders.
double GetBinCenter(int bin) const noexcept
Get the bin center of the bin with the given index.
const_iterator & operator-=(int d) noexcept
const_iterator & operator--() noexcept
–i
TAxisConfig(const std::vector< std::string_view > &labels)
Represents a TAxisLabels with labels.
Source and target axes are identical.
double GetBinFrom(int bin) const noexcept
Get the lower bin border for a given bin index.
constexpr bool IsUnderflowBin(int bin) const noexcept
Whether the bin index is referencing a bin lower than the axis range.
EAxisCompatibility CanMap(TAxisEquidistant &target, TAxisEquidistant &source) noexcept
Whether (and how) the source axis can be merged into the target axis.
int FindBin(double x) const noexcept
Find the bin index corresponding to coordinate x.
Axis_t operator()(TAxisConfig cfg) noexcept
std::vector< double > fBinBorders
Bin borders of the TAxisIrregular.
constexpr int GetNBins() const noexcept
Get the number of bins, including under- and overflow.
double GetBinCenter(int bin) const noexcept
Get the bin center for the given bin index.
TAxisLabels(const std::vector< std::string_view > &labels)
Construct a TAxisLables from a vector of string_views.
int operator->() const noexcept
double GetBinTo(int bin) const noexcept
Get the higher bin border for a given bin index.
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 GetMaximum() const noexcept
Get the high end of the axis range.
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)
TAxisConfig(const TAxisEquidistant &ax)
Build a TAxisConfig from a TAxisEquidistant.
std::vector< std::string > fLabels
Bin labels for a TAxisLabels.
TAxisView(const TAxisEquidistant &equi)
Construct a view on a TAxisEquidistant, TAxisGrow or TAxisLabel.
double GetBinWidth() const noexcept
Get the width of the bins.
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)
const_iterator & operator+=(int d) noexcept
TAxisConfig(const TAxisGrow &ax)
Build a TAxisConfig from a TAxisGrow.
constexpr TAxisGrow(int nbins, double low, double high) noexcept
Initialize a TAxisGrow.
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.
constexpr int FindBin(double x) const noexcept
Find the bin index for the given coordinate.
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.
TAxisConfig(const TAxisIrregular &ax)
Build a TAxisConfig from a TAxisIrregular.
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
const_iterator end() const noexcept
Get a const_iterator pointing right beyond the last non-overflow bin (i.e.
bool operator>=(const TKey &lhs, const TKey &rhs)