1#ifndef TTTRLIB_HISTOGRAMAXIS_H
2#define TTTRLIB_HISTOGRAMAXIS_H
12inline void linspace(
double start,
double stop, T *bin_edges,
int n_bins){
13 double bin_width = (stop - start) / n_bins;
14 for(
int i=0; i<n_bins; i++){
15 bin_edges[i] = start + ((T) i) * bin_width;
21inline void logspace(
double start,
double stop, T *bin_edges,
int n_bins){
22 linspace(std::log(start), std::log(stop), bin_edges, n_bins);
23 for(
int i=0; i<n_bins; i++){
24 bin_edges[i] = std::pow(10.0, bin_edges[i]);
47 if ((value < bin_edges[0]) || (value > bin_edges[n_bins - 2])) {
55 if (value > bin_edges[m]) {
60 }
while ((value < bin_edges[m]) || (value >= bin_edges[m + 1]));
76 return ((value - begin) / bin_width);
88 std::vector<T> bin_edges;
97 bin_edges.resize(n_bins);
98 switch (HistogramAxis::axis_type){
101 bin_width = (end - begin) / n_bins;
102 linspace(begin, end, bin_edges.data(), bin_edges.size());
106 bin_width = (log(end) - log(begin)) / n_bins;
107 logspace(begin, end, bin_edges.data(), bin_edges.size());
113 if(axis_type ==
"log10")
114 HistogramAxis::axis_type = 1;
115 if(axis_type ==
"lin")
116 HistogramAxis::axis_type = 0;
130 return calc_bin_idx(begin, bin_width, std::log10(value));
137 return bin_edges.data();
141 for(
int i = 0; i < n_bins; i++){
142 bin_edges[i] = this->bin_edges[i];
151 HistogramAxis::name = name;
160 std::string axis_type
170 HistogramAxis::begin = begin;
171 HistogramAxis::end = end;
172 HistogramAxis::n_bins = n_bins;
174 HistogramAxis::name = name;
int search_bin_idx(T value, T *bin_edges, int n_bins)
Definition HistogramAxis.h:43
void logspace(double start, double stop, T *bin_edges, int n_bins)
Definition HistogramAxis.h:21
void linspace(double start, double stop, T *bin_edges, int n_bins)
Definition HistogramAxis.h:12
int calc_bin_idx(T begin, T bin_width, T value)
Definition HistogramAxis.h:75
Definition HistogramAxis.h:80
void setAxisType(const std::string &axis_type)
Definition HistogramAxis.h:112
const std::string & getName() const
Definition HistogramAxis.h:146
int getNumberOfBins()
Definition HistogramAxis.h:119
HistogramAxis(std::string name, T begin, T end, int n_bins, std::string axis_type)
Definition HistogramAxis.h:155
void getBins(T *bin_edges, int n_bins)
Definition HistogramAxis.h:140
void setName(const std::string &name)
Definition HistogramAxis.h:150
void update()
Definition HistogramAxis.h:96
T * getBins()
Definition HistogramAxis.h:136
int getBinIdx(T value)
Definition HistogramAxis.h:123