00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef O2SCL_HIST_GRID_H
00024 #define O2SCL_HIST_GRID_H
00025
00026 #ifndef DOXYGENP
00027 namespace o2scl {
00028 #endif
00029
00030
00031
00032
00033
00034
00035
00036
00037 class hist_grid {
00038
00039 private:
00040
00041
00042 hist_grid() {
00043 }
00044
00045 public:
00046
00047 friend class hist_base;
00048
00049
00050 double start;
00051
00052 double end;
00053
00054 double size;
00055
00056 size_t n;
00057
00058 bool log;
00059
00060 };
00061
00062
00063
00064
00065
00066
00067 class hist_base {
00068
00069 public:
00070
00071
00072 hist_grid grid_size(double start, double size, size_t n, bool log=false) {
00073 hist_grid h;
00074 h.start=start;
00075 h.size=size;
00076 h.n=n;
00077 h.log=log;
00078 if (log) {
00079 h.end=start*std::pow(size,((double)n));
00080 } else {
00081 h.end=start+n*size;
00082 }
00083 return h;
00084 }
00085
00086
00087 hist_grid grid_end(double start, double end, size_t n, bool log=false) {
00088 hist_grid h;
00089 h.start=start;
00090 h.end=end;
00091 h.n=n;
00092 h.log=log;
00093 if (log) {
00094 h.size=std::pow(end/start,1.0/((double)n));
00095 } else {
00096 h.size=(end-start)/((double)n);
00097 }
00098 return h;
00099 }
00100
00101
00102
00103
00104 hist_grid grid_end_size(double start, double end, double size,
00105 bool log=false) {
00106 hist_grid h;
00107 h.start=start;
00108 h.end=end;
00109 h.size=size;
00110 h.log=log;
00111 if (log) {
00112 h.n=((size_t)(std::log(end/start)/std::log(size)*(1.0+1.0e-12)));
00113 } else {
00114 h.n=((size_t)(fabs(start-end)/size*(1.0+1.0e-12)));
00115 }
00116 return h;
00117 }
00118
00119
00120
00121
00122 template<class vec_t>
00123 int uniform_grid_internal(double start, double end, double bin_size,
00124 size_t n, vec_t &v) {
00125
00126 bin_size=fabs(bin_size);
00127
00128 if (start<end) {
00129 v[0]=start;
00130 for(size_t i=1;i<n;i++) {
00131 v[i]=start+i*bin_size;
00132 }
00133 v[n]=end;
00134 } else {
00135 v[0]=start;
00136 for(size_t i=1;i<n;i++) {
00137 v[i]=start-i*bin_size;
00138 }
00139 v[n]=end;
00140 }
00141
00142 return 0;
00143 }
00144
00145
00146
00147
00148 template<class vec_t>
00149 int logarithmic_grid_internal(double start, double end,
00150 double bin_factor, size_t n,
00151 vec_t &v) {
00152
00153 bin_factor=fabs(bin_factor);
00154
00155 if (start<end) {
00156 v[0]=start;
00157 for(size_t i=1;i<n;i++) {
00158 v[i]=start*std::pow(bin_factor,((double)i));
00159 }
00160 v[n]=end;
00161 } else {
00162 v[0]=start;
00163 for(size_t i=1;i<n;i++) {
00164 v[i]=start/std::pow(bin_factor,((double)i));
00165 }
00166 v[n]=end;
00167 }
00168
00169 return 0;
00170 }
00171
00172 };
00173
00174 #ifndef DOXYGENP
00175 }
00176 #endif
00177
00178 #endif