// // lin_scale.h // mc_electron // // Created by Christian Reiling on 06.06.19. // Copyright © 2019 Christian Reiling. All rights reserved. // #ifndef lin_scale_h #define lin_scale_h #include #include #include "error_types.h" #include "scale.h" class Lin_Scale : public Scale { double min_x; double max_x; double delta_x; int number_bins; public: Lin_Scale() {}; Lin_Scale(const double &min_x, const double &max_x, const int &number_bins); ~Lin_Scale() {}; Scale *clone() {return new Lin_Scale(*this);} double get_lower_scale_end(); double get_upper_scale_end(); int get_number_bins(); int calc_index(const double &x); double get_lower_bin_bound(const int &index); double get_bin_mid(const int &index); double get_upper_bin_bound(const int &index); bool is_valid_index (const int &index); friend bool operator==(const Lin_Scale &scale1, const Lin_Scale &scale2); }; inline Lin_Scale::Lin_Scale(const double &min_x, const double &max_x, const int &number_bins) { this->min_x = min_x; this->max_x = max_x; this->number_bins = number_bins; if (number_bins<1) { std::stringstream ss; ss<<"Lin_Scale::Lin_Scale: Less than 1 bin not possible.\n"; throw MyException (ss.str()); } delta_x = (max_x - min_x)/(number_bins); } inline double Lin_Scale::get_lower_scale_end() { return(min_x); } inline double Lin_Scale::get_upper_scale_end() { return(max_x); } inline int Lin_Scale::get_number_bins() { return(number_bins); } inline int Lin_Scale::calc_index(const double &x) { if (x <= min_x) { return (0); } if (x >= max_x) { return (number_bins-1); } return (std::ceil((x-min_x)/delta_x) - 1); } inline double Lin_Scale::get_lower_bin_bound(const int &index) { return (min_x + double(index) * delta_x); } inline double Lin_Scale::get_bin_mid(const int &index) { return (min_x + double(index+0.5) * delta_x); } inline double Lin_Scale::get_upper_bin_bound(const int &index) { return (min_x + double(index + 1) * delta_x); } inline bool Lin_Scale::is_valid_index (const int &index) { if (index < 0 || index > (number_bins-1) ) { return (false); } else { return (true); } } inline bool operator==(const Lin_Scale &scale1, const Lin_Scale &scale2) { return (scale1.min_x== scale2.min_x && scale1.max_x== scale2.max_x && scale1.delta_x== scale2.delta_x && scale1.number_bins== scale2.number_bins); } #endif /* lin_scale_h */