1#ifndef TTTRLIB_HISTOGRAM_H
2#define TTTRLIB_HISTOGRAM_H
22 std::map<size_t , HistogramAxis<T>> axes;
27 size_t getAxisDimensions(){
33 void update(T *data,
int n_rows_data,
int n_cols_data){
36 int global_bin_offset;
38 int current_bin_idx, current_n_bins;
43 for(
const auto& p : axes){
53 for(
const auto& p : axes){
56 n_total_bins *= axes[axis_index].getNumberOfBins();
59 histogram = (T*) malloc(
sizeof(T) * (n_total_bins));
60 for(global_bin_idx=0; global_bin_idx < n_total_bins; global_bin_idx++){
61 histogram[global_bin_idx] = 0.0;
68 for(
int i_row=0; i_row<n_rows_data; i_row++){
70 global_bin_offset = 0;
72 for(
const auto& p : axes){
74 current_axis = &axes[axis_index];
76 data_value = data[i_row*n_axis + axis_index];
77 current_bin_idx = current_axis->
getBinIdx(data_value);
80 if( (current_bin_idx < 0) || (current_bin_idx >= current_n_bins) ){
84 global_bin_offset = current_bin_idx + current_n_bins * global_bin_offset;
87 histogram[global_bin_offset] += 1.0;
98 axes[data_column] = new_axis;
104 T begin, T end,
int n_bins,
105 std::string axis_type
112 return axes[axis_index];
122void bincount1D(
int *data,
int n_data,
int *bins,
int n_bins);
143 double *weights,
int n_weights,
144 T *bin_edges,
int n_bins,
145 double *hist,
int n_hist,
146 const char *axis_type,
151 T lower, upper, bin_width;
152 bool is_log10 = !strcmp(axis_type,
"log10");
153 bool is_lin = !strcmp(axis_type,
"lin");
155 if (is_lin || is_log10) {
157 lower = std::log10(bin_edges[0]);
158 upper = std::log10(bin_edges[n_bins - 1]);
160 lower = bin_edges[0];
161 upper = bin_edges[n_bins - 1];
163 bin_width = (upper - lower) / (n_bins - 1);
165 for (i = 0; i < n_data; i++) {
176 if ((bin_idx <= n_bins) && (bin_idx >= 0)){
177 hist[bin_idx] += (use_weights) ? weights[i] : 1;
181 for (i = 0; i < n_data; i++) {
185 hist[bin_idx] += (use_weights) ? weights[i] : 1;
void histogram1D(T *data, int n_data, double *weights, int n_weights, T *bin_edges, int n_bins, double *hist, int n_hist, const char *axis_type, bool use_weights)
Definition Histogram.h:141
void bincount1D(int *data, int n_data, int *bins, int n_bins)
int search_bin_idx(T value, T *bin_edges, int n_bins)
Definition HistogramAxis.h:43
int calc_bin_idx(T begin, T bin_width, T value)
Definition HistogramAxis.h:75
Definition HistogramAxis.h:80
int getNumberOfBins()
Definition HistogramAxis.h:119
void update()
Definition HistogramAxis.h:96
int getBinIdx(T value)
Definition HistogramAxis.h:123
Definition Histogram.h:18
HistogramAxis< T > get_axis(size_t axis_index)
Definition Histogram.h:111
void get_histogram(T **hist, int *dim)
Definition Histogram.h:92
void set_axis(size_t data_column, std::string name, T begin, T end, int n_bins, std::string axis_type)
Definition Histogram.h:101
void set_axis(size_t data_column, HistogramAxis< T > &new_axis)
Definition Histogram.h:97
void update(T *data, int n_rows_data, int n_cols_data)
Definition Histogram.h:33