21 #include <initializer_list> 23 #include <unordered_map> 30 namespace Experimental {
91 class const_iterator:
public std::iterator<std::random_access_iterator_tag, int , int ,
92 const int * , const int & > {
164 const int *
operator*() const noexcept {
return &fCursor; }
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;
318 :
TAxisBase(title, nbins, kind == kGrow), fKind(kind), fBinBorders(2)
323 fBinBorders[0] = from;
340 :
TAxisConfig(title, nbins, from, to, kEquidistant)
356 :
TAxisBase(title, binborders.size() - 1, false ), fKind(kIrregular), fBinBorders(binborders)
364 :
TAxisBase(title, binborders.size() - 1,
false ), fKind(kIrregular),
365 fBinBorders(std::move(binborders))
373 :
TAxisBase(title, labels.size(), true ), fKind(kLabels), fLabels(labels.
begin(), labels.
end())
381 :
TAxisBase(title, labels.size(), true ), fKind(kLabels), fLabels(
std::move(labels))
391 const std::vector<double> &
GetBinBorders() const noexcept {
return fBinBorders; }
394 const std::vector<std::string> &
GetBinLabels() const noexcept {
return fLabels; }
406 double fInvBinWidth = 0.;
412 static double GetInvBinWidth(
int nbinsNoOver,
double lowOrHigh,
double highOrLow)
414 return nbinsNoOver / std::abs(highOrLow - lowOrHigh);
426 :
TAxisBase(title, nbinsNoOver, canGrow), fLow(low), fInvBinWidth(GetInvBinWidth(nbinsNoOver, low, high))
475 double rawbin = (
x - fLow) * fInvBinWidth;
480 static bool CanGrow() noexcept {
return false; }
497 double GetBinCenter(
int bin)
const noexcept {
return fLow + (bin - 0.5) / fInvBinWidth; }
502 double GetBinFrom(
int bin)
const noexcept {
return fLow + (bin - 1) / fInvBinWidth; }
507 double GetBinTo(
int bin)
const noexcept {
return GetBinFrom(bin + 1); }
509 int GetBinIndexForLowEdge(
double x)
const noexcept;
515 return lhs.GetNBins() == rhs.GetNBins() && lhs.GetMinimum() == rhs.GetMinimum() &&
516 lhs.GetInverseBinWidth() == rhs.GetInverseBinWidth();
606 :
TAxisBase(binborders.size() - 1, CanGrow()), fBinBorders(binborders)
608 #ifdef R__DO_RANGE_CHECKS 609 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
611 #endif // R__DO_RANGE_CHECKS 619 :
TAxisBase(binborders.size() - 1, CanGrow()), fBinBorders(std::move(binborders))
621 #ifdef R__DO_RANGE_CHECKS 622 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
624 #endif // R__DO_RANGE_CHECKS 630 :
TAxisBase(title, binborders.size() - 1, CanGrow()), fBinBorders(binborders)
632 #ifdef R__DO_RANGE_CHECKS 633 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
635 #endif // R__DO_RANGE_CHECKS 643 :
TAxisBase(title, binborders.size() - 1, CanGrow()), fBinBorders(std::move(binborders))
645 #ifdef R__DO_RANGE_CHECKS 646 if (!std::is_sorted(fBinBorders.begin(), fBinBorders.end()))
648 #endif // R__DO_RANGE_CHECKS 659 const auto bBegin = fBinBorders.begin();
660 const auto bEnd = fBinBorders.end();
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();
683 return 0.5 * (fBinBorders[bin - 1] + fBinBorders[bin]);
694 return std::numeric_limits<double>::min();
697 return fBinBorders[bin - 1];
708 return std::numeric_limits<double>::max();
709 return GetBinFrom(bin + 1);
713 static bool CanGrow() noexcept {
return false; }
716 const std::vector<double> &
GetBinBorders() const noexcept {
return fBinBorders; }
744 :
TAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size()))
746 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
747 fLabelsIndex[std::string(labels[i])] = i;
752 :
TAxisGrow(title, labels.size(), 0., static_cast<double>(labels.size()))
754 for (
size_t i = 0,
n = labels.size(); i <
n; ++i)
755 fLabelsIndex[labels[i]] = i;
767 auto insertResult = fLabelsIndex.insert({label, -1});
768 if (insertResult.second) {
770 int idx = fLabelsIndex.size() - 1;
771 insertResult.first->second = idx;
774 return insertResult.first->second;
780 return GetBinIndex(label) - 0.5;
786 std::vector<std::string_view> vec(fLabelsIndex.size());
787 for (
const auto &kv: fLabelsIndex)
788 vec.at(kv.second) = kv.first;
797 template <TAxisConfig::EKind>
806 return TAxisEquidistant(cfg.GetTitle(), cfg.GetNBinsNoOver(), cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
816 return TAxisGrow(cfg.GetTitle(), cfg.GetNBinsNoOver(), cfg.GetBinBorders()[0], cfg.GetBinBorders()[1]);
870 double GetFrom()
const {
return GetBinFrom(1); }
double GetFrom() const
Get the lower axis limit.
TAxisView(const TAxisEquidistant &equi)
Construct a view on a TAxisEquidistant, TAxisGrow or TAxisLabel.
TAxisBase(std::string_view title, int nbinsNoOver, bool canGrow) noexcept
Construct a TAxisBase.
TAxisBase()=default
Default construct a TAxisBase (for use by derived classes for I/O)
TAxisConfig(std::vector< double > &&binborders) noexcept
Represents a TAxisIrregular with binborders.
const_iterator operator+(int d) noexcept
Namespace for new ROOT classes and functions.
TAxisLabels(std::string_view title, const std::vector< std::string > &labels)
Construct a TAxisLables from a vector of strings, with title.
TAxisBase & operator=(const TAxisBase &)=default
const_iterator begin() const noexcept
Get a const_iterator pointing to the first non-underflow bin.
double GetMinimum() const noexcept
Get the low end of the axis range.
double GetBinCenter(int i) const noexcept
Get the bin center of bin index i. Forwards to the underlying axis.
TAxisConfig(const std::vector< double > &binborders)
Represents a TAxisIrregular with binborders.
const_iterator operator++(int) noexcept
i++
void swap(TDirectoryEntry &e1, TDirectoryEntry &e2) noexcept
double GetBinTo(int bin) const noexcept
Get the higher bin border for a given bin index.
TAxisLabels(const std::vector< std::string > &labels)
Construct a TAxisLables from a vector of strings.
const std::vector< double > & GetBinBorders() const noexcept
Get the bin borders; non-empty if the GetKind() == kIrregular.
Axis_t operator()(const TAxisConfig &cfg)
const_iterator & operator--() noexcept
–i
double GetInverseBinWidth() const noexcept
Get the inverse of the width of the bins.
TAxisEquidistant(std::string_view title, int nbinsNoOver, double low, double high, bool canGrow) noexcept
Initialize a TAxisEquidistant.
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 containing coordinate x. Forwards to the underlying axis.
Common view on a TAxis, no matter what its kind.
int GetNBinsNoOver() const noexcept
Get the number of bins, excluding under- and overflow.
Axis with equidistant bin borders.
double GetBinFrom(int bin) const noexcept
Get the lower bin border for a given bin index.
double GetTo() const
Get the upper axis limit.
TAxisConfig(Grow_t, int nbins, double from, double to)
Represents a TAxisGrow with nbins from from to to.
EFindStatus
Status of FindBin(x)
std::vector< double > fBinBorders
Bin borders of the TAxisIrregular.
const int * operator*() const noexcept
int FindBin(double x) const noexcept
Find the bin index corresponding to coordinate x.
const_iterator end_with_overflow() const noexcept
Get a const_iterator pointing right beyond the overflow bin.
The bins of the source axis have finer granularity, but the bin borders are compatible.
std::vector< double > fBinBorders
Bin borders, one more than the number of non-overflow bins.
static constexpr const int kNOverflowBins[4]
Extra bins for each EAxisOverflow value.
double GetBinFrom(int i) const noexcept
Get the minimal coordinate of bin index i. Forwards to the underlying axis.
represents a TAxisEquidistant
const_iterator begin_with_underflow() const noexcept
Get a const_iterator pointing the underflow bin.
int GetUnderflowBin() const noexcept
Get the bin index for the underflow bin.
const std::vector< double > & GetBinBorders() const noexcept
Access to the bin borders used by this axis.
const TAxisIrregular * GetAsIrregular() const
Get the axis as a TAxisIrregular; returns nullptr if it's a TAxisEquidistant.
TAxisEquidistant(int nbinsNoOver, double low, double high) noexcept
Initialize a TAxisEquidistant.
An axis that can extend its range, keeping the number of its bins unchanged.
EAxisCompatibility CanMap(TAxisEquidistant &target, TAxisEquidistant &source) noexcept
Whether (and how) the source axis can be merged into the target axis.
double GetBinFrom(int bin) const noexcept
Get the low bin border for the given bin index.
TAxisConfig(const std::vector< std::string_view > &labels)
Represents a TAxisLabels with labels.
bool operator>=(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i >= j
TAxisIrregular(std::string_view title, std::vector< double > &&binborders) noexcept
Construct a TAxisIrregular from a vector of bin borders.
double GetBinCenter(const std::string &label)
Get the center of the bin with label.
TAxisBase(int nbinsNoOver, bool canGrow) noexcept
Construct a TAxisBase.
bool operator<(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i < j
const std::vector< std::string > & GetBinLabels() const noexcept
Get the bin labels; non-empty if the GetKind() == kLabels.
EKind fKind
The kind of axis represented by this configuration.
TAxisConfig(std::string_view title, int nbins, double from, double to)
Represents a TAxisEquidistant with nbins from from to to, and axis title.
Objects used to configure the different axis types.
unsigned int fNBins
Number of bins including under- and overflow.
TAxisConfig(std::string_view title, const std::vector< double > &binborders)
Represents a TAxisIrregular with binborders and title.
TAxisGrow(std::string_view title, int nbins, double low, double high) noexcept
Initialize a TAxisGrow.
Random const_iterator through bins.
TAxisIrregular(std::string_view title, const std::vector< double > &binborders)
Construct a TAxisIrregular from a vector of bin borders.
double GetBinCenter(int bin) const noexcept
Get the bin center for the given bin index.
TAxisConfig(int nbins, double from, double to)
Represents a TAxisEquidistant with nbins from from to to.
int GetNOverflowBins() const noexcept
Get the number of over- and underflow bins: 0 for growable axes, 2 otherwise.
const_iterator & operator++() noexcept
++i
const_iterator operator--(int) noexcept
represents a TAxisIrregular
Axis_t operator()(const TAxisConfig &cfg)
TAxisConfig(std::string_view title, int nbins, double from, double to, EKind kind)
Represents a TAxisEquidistant with nbins from from to to, and axis title.
int GetBinIndex(const std::string &label)
Get the bin index with label.
Tag type signalling that an axis should be able to grow; used for calling the appropriate constructor...
static constexpr const int kIgnoreBin
FindBin() returns this bin to signal that the bin number is invalid.
TAxisConfig(std::vector< std::string > &&labels)
Represents a TAxisLabels with labels.
int AdjustOverflowBinNumber(double rawbin) const
Given rawbin (<0 for underflow, >= GetNBinsNoOver() for overflow), determine the actual bin number ta...
bool operator==(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i == j
int GetNBins() const noexcept
Get the number of bins, including under- and overflow.
int GetOverflowBin() const noexcept
Get the bin index for the underflow bin (or the next bin outside range if CanGrow()).
std::vector< std::string_view > GetBinLabels() const
Build a vector of labels. The position in the vector defines the label's bin.
bool operator>(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i > j
The returned bin index is valid.
TAxisEquidistant(int nbinsNoOver, double low, double high, bool canGrow) noexcept
Initialize a TAxisEquidistant.
TAxisConfig(std::string_view title, std::vector< double > &&binborders) noexcept
Represents a TAxisIrregular with binborders and title.
std::string fTitle
Title of this axis, used for graphics / text.
TAxisGrow(int nbins, double low, double high) noexcept
Initialize a TAxisGrow.
bool CanGrow() const
This axis kind can increase its range.
const_iterator operator-(int d) noexcept
An axis with non-equidistant bins (also known as "variable binning").
TAxisView(const TAxisIrregular &irr)
Construct a view on a TAxisIrregular.
basic_string_view< char > string_view
int operator->() const noexcept
bool IsUnderflowBin(int bin) const noexcept
Whether the bin index is referencing a bin lower than the axis range.
bool operator!=(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i != j
TAxisEquidistant(std::string_view title, int nbinsNoOver, double low, double high) noexcept
Initialize a TAxisEquidistant.
const TAxisEquidistant * GetAsEquidistant() const
Get the axis as a TAxisEquidistant; returns nullptr if it's a TAxisIrregular.
double GetBinTo(int i) const noexcept
Get the maximal coordinate of bin index i. Forwards to the underlying axis.
static bool CanGrow() noexcept
This axis cannot be extended.
EKind GetKind() const noexcept
Get the axis kind represented by this TAxisConfig.
static double GetInvBinWidth(int nbinsNoOver, double lowOrHigh, double highOrLow)
Determine the inverse bin width.
The source is a subset of bins of the target axis.
TAxisLabels(const std::vector< std::string_view > &labels)
Construct a TAxisLables from a vector of string_views.
const_iterator(int cursor) noexcept
Initialize a const_iterator with its position.
const std::string & GetTitle() const
const_iterator end() const noexcept
Get a const_iterator pointing right beyond the last non-overflow bin (i.e.
Converts a TAxisConfig of whatever kind to the corresponding TAxisBase-derived object.
double GetBinWidth() const noexcept
Get the width of the bins.
std::unordered_map< std::string, int > fLabelsIndex
Map of label (view on fLabels's elements) to bin index.
double GetBinCenter(int bin) const noexcept
Get the bin center of the bin with the given index.
TAxisIrregular(std::vector< double > &&binborders) noexcept
Construct a TAxisIrregular from a vector of bin borders.
Histogram axis base class.
TAxisConfig(std::string_view title, std::vector< std::string > &&labels)
Represents a TAxisLabels with labels and title.
const_iterator & operator-=(int d) noexcept
TAxisConfig(std::string_view title, Grow_t, int nbins, double from, double to)
Represents a TAxisGrow with nbins from from to to, and axis title.
A TAxisGrow that has a label assigned to each bin and a bin width of 1.
Source and target axes are identical.
int GetNBins() const noexcept
Get the number of bins. Forwards to the underlying axis.
static constexpr const Grow_t Grow
Tag signalling that an axis should be able to grow; used for calling the appropriate constructor like...
Axis_t operator()(const TAxisConfig &cfg) noexcept
The source axis and target axis have different binning.
Coordinate could fit after growing the axis.
bool IsOverflowBin(int bin) const noexcept
Whether the bin index is referencing a bin higher than the axis range.
const bool fCanGrow
Whether this axis can grow (and thus has no overflow bins).
static bool CanGrow() noexcept
This axis cannot grow.
double GetMaximum() const noexcept
Get the high end of the axis range.
int FindBin(double x) const noexcept
Find the bin index for the given coordinate.
TAxisIrregular(const std::vector< double > &binborders)
Construct a TAxisIrregular from a vector of bin borders.
TAxisLabels(std::string_view title, const std::vector< std::string_view > &labels)
Construct a TAxisLables from a vector of string_views, with title.
const_iterator & operator+=(int d) noexcept
#define R__ERROR_HERE(GROUP)
std::vector< std::string > fLabels
Bin labels for a TAxisLabels.
const std::string & GetTitle() const
bool operator<=(TAxisBase::const_iterator lhs, TAxisBase::const_iterator rhs) noexcept
i <= j
Axis_t operator()(const TAxisConfig &cfg) noexcept
TAxisConfig(std::string_view title, const std::vector< std::string_view > &labels)
Represents a TAxisLabels with labels and title.