21#include <initializer_list>
23#include <unordered_map>
30namespace Experimental {
91 class const_iterator:
public std::iterator<std::random_access_iterator_tag, int , int ,
92 const int * , const int & > {
259 return lhs.fCursor < rhs.fCursor;
265 return lhs.fCursor > rhs.fCursor;
271 return lhs.fCursor <= rhs.fCursor;
277 return lhs.fCursor >= rhs.fCursor;
283 return lhs.fCursor == rhs.fCursor;
289 return lhs.fCursor != rhs.fCursor;
412 static double GetInvBinWidth(
int nbinsNoOver,
double lowOrHigh,
double highOrLow)
414 return nbinsNoOver / std::abs(highOrLow - lowOrHigh);
480 static bool CanGrow() noexcept {
return false; }
515 return lhs.GetNBins() == rhs.GetNBins() && lhs.GetMinimum() == rhs.GetMinimum() &&
516 lhs.GetInverseBinWidth() == rhs.GetInverseBinWidth();
608#ifdef R__DO_RANGE_CHECKS
621#ifdef R__DO_RANGE_CHECKS
632#ifdef R__DO_RANGE_CHECKS
645#ifdef R__DO_RANGE_CHECKS
662 auto iNotLess = std::lower_bound(bBegin, bEnd,
x);
663 int rawbin = iNotLess - bBegin;
680 return std::numeric_limits<double>::min();
682 return std::numeric_limits<double>::max();
694 return std::numeric_limits<double>::min();
708 return std::numeric_limits<double>::max();
713 static bool CanGrow() noexcept {
return false; }
744 :
RAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size()))
746 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
752 :
RAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size()))
754 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
768 if (insertResult.second) {
771 insertResult.first->second = idx;
774 return insertResult.first->second;
788 vec.at(kv.second) = kv.first;
797template <RAxisConfig::EKind>
806 return RAxisEquidistant(cfg.GetTitle(), cfg.GetNBinsNoOver(), cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
816 return RAxisGrow(cfg.GetTitle(), cfg.GetNBinsNoOver(), cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
#define R__ERROR_HERE(GROUP)
Random const_iterator through bins.
const_iterator & operator-=(int d) noexcept
const_iterator operator-(int d) noexcept
const_iterator operator++(int) noexcept
i++
friend bool operator>(const_iterator lhs, const_iterator rhs) noexcept
i > j
const_iterator operator+(int d) noexcept
int operator->() const noexcept
int fCursor
Current iteration position.
const_iterator & operator+=(int d) noexcept
const_iterator & operator--() noexcept
–i
const_iterator & operator++() noexcept
++i
const_iterator operator--(int) noexcept
const_iterator(int cursor) noexcept
Initialize a const_iterator with its position.
friend bool operator<=(const_iterator lhs, const_iterator rhs) noexcept
i <= j
const int * operator*() const noexcept
friend bool operator<(const_iterator lhs, const_iterator rhs) noexcept
i < j
friend bool operator>=(const_iterator lhs, const_iterator rhs) noexcept
i >= j
friend bool operator==(const_iterator lhs, const_iterator rhs) noexcept
i == j
friend bool operator!=(const_iterator lhs, const_iterator rhs) noexcept
i != j
Histogram axis base class.
const_iterator begin_with_underflow() const noexcept
Get a const_iterator pointing the underflow bin.
const_iterator end() const noexcept
Get a const_iterator pointing right beyond the last non-overflow bin (i.e.
bool fCanGrow
Whether this axis can grow (and thus has no overflow bins).
int GetNOverflowBins() const noexcept
Get the number of over- and underflow bins: 0 for growable axes, 2 otherwise.
bool IsUnderflowBin(int bin) const noexcept
Whether the bin index is referencing a bin lower than the axis range.
RAxisBase()=default
Default construct a RAxisBase (for use by derived classes for I/O)
RAxisBase(const RAxisBase &)=default
RAxisBase(std::string_view title, int nbinsNoOver, bool canGrow) noexcept
Construct a RAxisBase.
std::string fTitle
Title of this axis, used for graphics / text.
int GetUnderflowBin() const noexcept
Get the bin index for the underflow bin.
const std::string & GetTitle() const
int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
RAxisBase & operator=(RAxisBase &&)=default
const_iterator begin() const noexcept
Get a const_iterator pointing to the first non-underflow bin.
int GetOverflowBin() const noexcept
Get the bin index for the underflow bin (or the next bin outside range if CanGrow()).
static constexpr const int kNOverflowBins[4]
Extra bins for each EAxisOverflow value.
const_iterator end_with_overflow() const noexcept
Get a const_iterator pointing right beyond the overflow bin.
int AdjustOverflowBinNumber(double rawbin) const
Given rawbin (<0 for underflow, >= GetNBinsNoOver() for overflow), determine the actual bin number ta...
static constexpr const int kIgnoreBin
FindBin() returns this bin to signal that the bin number is invalid.
RAxisBase(RAxisBase &&)=default
bool IsOverflowBin(int bin) const noexcept
Whether the bin index is referencing a bin higher than the axis range.
RAxisBase(int nbinsNoOver, bool canGrow) noexcept
Construct a RAxisBase.
int GetNBins() const noexcept
Get the number of bins, including under- and overflow.
EFindStatus
Status of FindBin(x)
unsigned int fNBins
Number of bins including under- and overflow.
RAxisBase & operator=(const RAxisBase &)=default
Objects used to configure the different axis types.
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
std::vector< std::string > fLabels
Bin labels for a RAxisLabels.
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
static constexpr const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
EKind GetKind() const noexcept
Get the axis kind represented by this RAxisConfig.
EKind fKind
The kind of axis represented by this configuration.
RAxisConfig(int nbins, double from, double to)
Represents a RAxisEquidistant with nbins from from to to.
RAxisConfig(std::string_view title, int nbins, double from, double to, EKind kind)
Represents a RAxisEquidistant with nbins from from to to, and axis title.
@ kGrow
represents a RAxisGrow
@ kEquidistant
represents a RAxisEquidistant
@ kIrregular
represents a RAxisIrregular
@ kLabels
represents a RAxisLabels
RAxisConfig(std::string_view title, const std::vector< double > &binborders)
Represents a RAxisIrregular with binborders and title.
RAxisConfig(const std::vector< double > &binborders)
Represents a RAxisIrregular with binborders.
RAxisConfig(std::string_view title, std::vector< double > &&binborders) noexcept
Represents a RAxisIrregular with binborders and title.
RAxisConfig(std::string_view title, Grow_t, int nbins, double from, double to)
Represents a RAxisGrow with nbins from from to to, and axis title.
RAxisConfig(std::vector< std::string > &&labels)
Represents a RAxisLabels with labels.
RAxisConfig(std::string_view title, std::vector< std::string > &&labels)
Represents a RAxisLabels with labels and title.
std::vector< double > fBinBorders
Bin borders of the RAxisIrregular.
RAxisConfig(std::vector< double > &&binborders) noexcept
Represents a RAxisIrregular with binborders.
RAxisConfig(Grow_t, int nbins, double from, double to)
Represents a RAxisGrow with nbins from from to to.
RAxisConfig(const std::vector< std::string_view > &labels)
Represents a RAxisLabels with labels.
RAxisConfig(std::string_view title, const std::vector< std::string_view > &labels)
Represents a RAxisLabels with labels and title.
RAxisConfig(std::string_view title, int nbins, double from, double to)
Represents a RAxisEquidistant with nbins from from to to, and axis title.
Axis with equidistant bin borders.
RAxisEquidistant(std::string_view title, int nbinsNoOver, double low, double high) noexcept
Initialize a RAxisEquidistant.
double GetMinimum() const noexcept
Get the low end of the axis range.
RAxisEquidistant(int nbinsNoOver, double low, double high) noexcept
Initialize a RAxisEquidistant.
double GetBinWidth() const noexcept
Get the width of the bins.
double GetInverseBinWidth() const noexcept
Get the inverse of the width of the bins.
RAxisEquidistant()=default
double GetMaximum() const noexcept
Get the high end of the axis range.
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 ...
double GetBinTo(int bin) const noexcept
Get the high bin border for the given bin index.
int FindBin(double x) const noexcept
Find the bin index for the given coordinate.
RAxisEquidistant(int nbinsNoOver, double low, double high, bool canGrow) noexcept
Initialize a RAxisEquidistant.
double fInvBinWidth
The inverse of the bin width.
RAxisEquidistant(std::string_view title, int nbinsNoOver, double low, double high, bool canGrow) noexcept
Initialize a RAxisEquidistant.
double GetBinFrom(int bin) const noexcept
Get the low bin border for the given bin index.
static double GetInvBinWidth(int nbinsNoOver, double lowOrHigh, double highOrLow)
Determine the inverse bin width.
double GetBinCenter(int bin) const noexcept
Get the bin center for the given bin index.
double fLow
The lower limit of the axis.
static bool CanGrow() noexcept
This axis cannot grow.
An axis that can extend its range, keeping the number of its bins unchanged.
RAxisGrow(std::string_view title, int nbins, double low, double high) noexcept
Initialize a RAxisGrow.
int Grow(int toBin)
Grow this axis to make the "virtual bin" toBin in-range.
bool CanGrow() const
This axis kind can increase its range.
RAxisGrow(int nbins, double low, double high) noexcept
Initialize a RAxisGrow.
An axis with non-equidistant bins (also known as "variable binning").
const std::vector< double > & GetBinBorders() const noexcept
Access to the bin borders used by this axis.
double GetBinTo(int bin) const noexcept
Get the higher bin border for a given bin index.
RAxisIrregular(std::vector< double > &&binborders) noexcept
Construct a RAxisIrregular from a vector of bin borders.
RAxisIrregular(const std::vector< double > &binborders)
Construct a RAxisIrregular from a vector of bin borders.
static bool CanGrow() noexcept
This axis cannot be extended.
std::vector< double > fBinBorders
Bin borders, one more than the number of non-overflow bins.
int FindBin(double x) const noexcept
Find the bin index corresponding to coordinate x.
double GetBinCenter(int bin) const noexcept
Get the bin center of the bin with the given index.
RAxisIrregular(std::string_view title, std::vector< double > &&binborders) noexcept
Construct a RAxisIrregular from a vector of bin borders.
double GetBinFrom(int bin) const noexcept
Get the lower bin border for a given bin index.
RAxisIrregular(std::string_view title, const std::vector< double > &binborders)
Construct a RAxisIrregular from a vector of bin borders.
A RAxisGrow that has a label assigned to each bin and a bin width of 1.
double GetBinCenter(const std::string &label)
Get the center of the bin with label.
RAxisLabels(const std::vector< std::string > &labels)
Construct a RAxisLables from a vector of strings.
RAxisLabels(const std::vector< std::string_view > &labels)
Construct a RAxisLables from a vector of string_views.
std::unordered_map< std::string, int > fLabelsIndex
Map of label (view on fLabels's elements) to bin index.
std::vector< std::string_view > GetBinLabels() const
Build a vector of labels. The position in the vector defines the label's bin.
RAxisLabels(std::string_view title, const std::vector< std::string_view > &labels)
Construct a RAxisLables from a vector of string_views, with title.
RAxisLabels(std::string_view title, const std::vector< std::string > &labels)
Construct a RAxisLables from a vector of strings, with title.
int GetBinIndex(const std::string &label)
Get the bin index with label.
Common view on a RAxis, no matter what its kind.
double GetFrom() const
Get the lower axis limit.
const RAxisIrregular * GetAsIrregular() const
Get the axis as a RAxisIrregular; returns nullptr if it's a RAxisEquidistant.
double GetBinFrom(int i) const noexcept
Get the minimal coordinate of bin index i. Forwards to the underlying axis.
int FindBin(double x) const noexcept
Find the bin containing coordinate x. Forwards to the underlying axis.
const std::string & GetTitle() const
double GetTo() const
Get the upper axis limit.
double GetBinTo(int i) const noexcept
Get the maximal coordinate of bin index i. Forwards to the underlying axis.
const RAxisEquidistant * GetAsEquidistant() const
Get the axis as a RAxisEquidistant; returns nullptr if it's a RAxisIrregular.
RAxisView(const RAxisIrregular &irr)
Construct a view on a RAxisIrregular.
int GetNBins() const noexcept
Get the number of bins. Forwards to the underlying axis.
RAxisView(const RAxisEquidistant &equi)
Construct a view on a RAxisEquidistant, RAxisGrow or RAxisLabel.
const RAxisEquidistant * fEqui
View on a RAxisEquidistant, RAxisGrow or RAxisLabel.
double GetBinCenter(int i) const noexcept
Get the bin center of bin index i. Forwards to the underlying axis.
const RAxisIrregular * fIrr
View on a RAxisIrregular.
basic_string_view< char > string_view
void swap(RDirectoryEntry &e1, RDirectoryEntry &e2) noexcept
EAxisCompatibility CanMap(RAxisEquidistant &target, RAxisEquidistant &source) noexcept
Whether (and how) the source axis can be merged into the target axis.
bool operator>=(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i >= j
bool operator>(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i > j
@ kContains
The source is a subset of bins of the target axis.
@ kIdentical
Source and target axes are identical.
@ kIncompatible
The source axis and target axis have different binning.
@ kSampling
The bins of the source axis have finer granularity, but the bin borders are compatible.
bool operator==(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i == j
bool operator<(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i < j
bool operator<=(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i <= j
bool operator!=(RAxisBase::const_iterator lhs, RAxisBase::const_iterator rhs) noexcept
i != j
Namespace for new ROOT classes and functions.
Axis_t operator()(const RAxisConfig &cfg) noexcept
Axis_t operator()(const RAxisConfig &cfg) noexcept
Axis_t operator()(const RAxisConfig &cfg)
Axis_t operator()(const RAxisConfig &cfg)
Converts a RAxisConfig of whatever kind to the corresponding RAxisBase-derived object.
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...