Geant4 Cross Reference |
1 // Copyright (C) 2010, Guy Barrand. All rights 1 // Copyright (C) 2010, Guy Barrand. All rights reserved. 2 // See the file tools.license for terms. 2 // See the file tools.license for terms. 3 3 4 #ifndef tools_histo_dps 4 #ifndef tools_histo_dps 5 #define tools_histo_dps 5 #define tools_histo_dps 6 6 7 // data point set. 7 // data point set. 8 8 9 #include <vector> 9 #include <vector> 10 #include <string> 10 #include <string> 11 #include "../mnmx" 11 #include "../mnmx" 12 12 13 #ifdef TOOLS_MEM 13 #ifdef TOOLS_MEM 14 #include "../mem" 14 #include "../mem" 15 #endif 15 #endif 16 16 17 namespace tools { 17 namespace tools { 18 namespace histo { 18 namespace histo { 19 19 20 class measurement { 20 class measurement { 21 static const std::string& s_class() { 21 static const std::string& s_class() { 22 static const std::string s_v("tools::histo 22 static const std::string s_v("tools::histo::measurement"); 23 return s_v; 23 return s_v; 24 } 24 } 25 public: 25 public: 26 measurement():m_value(0),m_error_plus(0),m_e 26 measurement():m_value(0),m_error_plus(0),m_error_minus(0){ 27 #ifdef TOOLS_MEM 27 #ifdef TOOLS_MEM 28 mem::increment(s_class().c_str()); 28 mem::increment(s_class().c_str()); 29 #endif 29 #endif 30 } 30 } 31 measurement(double a_value,double a_error_pl 31 measurement(double a_value,double a_error_plus,double a_error_minus) 32 :m_value(a_value) 32 :m_value(a_value) 33 ,m_error_plus(a_error_plus) 33 ,m_error_plus(a_error_plus) 34 ,m_error_minus(a_error_minus) 34 ,m_error_minus(a_error_minus) 35 { 35 { 36 #ifdef TOOLS_MEM 36 #ifdef TOOLS_MEM 37 mem::increment(s_class().c_str()); 37 mem::increment(s_class().c_str()); 38 #endif 38 #endif 39 } 39 } 40 virtual ~measurement(){ 40 virtual ~measurement(){ 41 #ifdef TOOLS_MEM 41 #ifdef TOOLS_MEM 42 mem::decrement(s_class().c_str()); 42 mem::decrement(s_class().c_str()); 43 #endif 43 #endif 44 } 44 } 45 public: 45 public: 46 measurement(const measurement& a_from) 46 measurement(const measurement& a_from) 47 :m_value(a_from.m_value) 47 :m_value(a_from.m_value) 48 ,m_error_plus(a_from.m_error_plus) 48 ,m_error_plus(a_from.m_error_plus) 49 ,m_error_minus(a_from.m_error_minus) 49 ,m_error_minus(a_from.m_error_minus) 50 { 50 { 51 #ifdef TOOLS_MEM 51 #ifdef TOOLS_MEM 52 mem::increment(s_class().c_str()); 52 mem::increment(s_class().c_str()); 53 #endif 53 #endif 54 } 54 } 55 measurement& operator=(const measurement& a_ 55 measurement& operator=(const measurement& a_from) { 56 if(&a_from==this) return *this; 56 if(&a_from==this) return *this; 57 m_value = a_from.m_value; 57 m_value = a_from.m_value; 58 m_error_plus = a_from.m_error_plus; 58 m_error_plus = a_from.m_error_plus; 59 m_error_minus = a_from.m_error_minus; 59 m_error_minus = a_from.m_error_minus; 60 return *this; 60 return *this; 61 } 61 } 62 public: 62 public: 63 double value() const {return m_value;} 63 double value() const {return m_value;} 64 double error_plus() const {return m_error_pl 64 double error_plus() const {return m_error_plus;} 65 double error_minus() const {return m_error_m 65 double error_minus() const {return m_error_minus;} 66 void set_value(double a_v) {m_value = a_v;} 66 void set_value(double a_v) {m_value = a_v;} 67 void set_error_plus(double a_v) {m_error_plu 67 void set_error_plus(double a_v) {m_error_plus = a_v;} 68 void set_error_minus(double a_v) {m_error_mi 68 void set_error_minus(double a_v) {m_error_minus = a_v;} 69 protected: 69 protected: 70 double m_value; 70 double m_value; 71 double m_error_plus; 71 double m_error_plus; 72 double m_error_minus; 72 double m_error_minus; 73 }; 73 }; 74 74 75 class data_point { 75 class data_point { 76 static const std::string& s_class() { 76 static const std::string& s_class() { 77 static const std::string s_v("tools::histo 77 static const std::string s_v("tools::histo::data_point"); 78 return s_v; 78 return s_v; 79 } 79 } 80 public: 80 public: 81 data_point(unsigned int a_dim):m_measurement 81 data_point(unsigned int a_dim):m_measurements(a_dim){ 82 #ifdef TOOLS_MEM 82 #ifdef TOOLS_MEM 83 mem::increment(s_class().c_str()); 83 mem::increment(s_class().c_str()); 84 #endif 84 #endif 85 } 85 } 86 virtual ~data_point() { 86 virtual ~data_point() { 87 #ifdef TOOLS_MEM 87 #ifdef TOOLS_MEM 88 mem::decrement(s_class().c_str()); 88 mem::decrement(s_class().c_str()); 89 #endif 89 #endif 90 } 90 } 91 public: 91 public: 92 data_point(const data_point& a_from) 92 data_point(const data_point& a_from) 93 :m_measurements(a_from.m_measurements) 93 :m_measurements(a_from.m_measurements) 94 { 94 { 95 #ifdef TOOLS_MEM 95 #ifdef TOOLS_MEM 96 mem::increment(s_class().c_str()); 96 mem::increment(s_class().c_str()); 97 #endif 97 #endif 98 } 98 } 99 data_point& operator=(const data_point& a_fr 99 data_point& operator=(const data_point& a_from) { 100 if(&a_from==this) return *this; 100 if(&a_from==this) return *this; 101 m_measurements = a_from.m_measurements; 101 m_measurements = a_from.m_measurements; 102 return *this; 102 return *this; 103 } 103 } 104 public: //AIDA/Idata_point 104 public: //AIDA/Idata_point 105 size_t dimension() const {return m_measureme 105 size_t dimension() const {return m_measurements.size();} 106 measurement& coordinate(unsigned int a_coord 106 measurement& coordinate(unsigned int a_coord) { 107 //WARNING : no check done on a_coord vs m_ 107 //WARNING : no check done on a_coord vs m_dim. 108 return m_measurements[a_coord]; 108 return m_measurements[a_coord]; 109 } 109 } 110 const measurement& coordinate(unsigned int a 110 const measurement& coordinate(unsigned int a_coord) const { 111 //WARNING : no check done on a_coord vs m_ 111 //WARNING : no check done on a_coord vs m_dim. 112 return m_measurements[a_coord]; 112 return m_measurements[a_coord]; 113 } 113 } 114 protected: 114 protected: 115 std::vector<measurement> m_measurements; 115 std::vector<measurement> m_measurements; 116 }; 116 }; 117 117 118 118 119 class dps { 119 class dps { 120 public: 120 public: 121 static const std::string& s_class() { 121 static const std::string& s_class() { 122 static const std::string s_v("tools::histo 122 static const std::string s_v("tools::histo::dps"); 123 return s_v; 123 return s_v; 124 } 124 } 125 public: 125 public: 126 dps():m_dim(0){} 126 dps():m_dim(0){} 127 127 128 dps(const std::string& a_title,unsigned int 128 dps(const std::string& a_title,unsigned int a_dim) 129 :m_title(a_title),m_dim(a_dim) 129 :m_title(a_title),m_dim(a_dim) 130 {} 130 {} 131 virtual ~dps(){} 131 virtual ~dps(){} 132 public: 132 public: 133 dps(const dps& a_from) 133 dps(const dps& a_from) 134 :m_title(a_from.m_title) 134 :m_title(a_from.m_title) 135 ,m_dim(a_from.m_dim) 135 ,m_dim(a_from.m_dim) 136 ,m_points(a_from.m_points) 136 ,m_points(a_from.m_points) 137 {} 137 {} 138 dps& operator=(const dps& a_from) { 138 dps& operator=(const dps& a_from) { 139 if(&a_from==this) return *this; 139 if(&a_from==this) return *this; 140 m_title = a_from.m_title; 140 m_title = a_from.m_title; 141 m_dim = a_from.m_dim; 141 m_dim = a_from.m_dim; 142 m_points = a_from.m_points; 142 m_points = a_from.m_points; 143 return *this; 143 return *this; 144 } 144 } 145 145 146 public: 146 public: 147 const std::string& title() const {return m_t 147 const std::string& title() const {return m_title;} 148 148 149 void set_title(const std::string& a_s) {m_ti 149 void set_title(const std::string& a_s) {m_title = a_s;} 150 150 151 unsigned int dimension() const {return m_dim 151 unsigned int dimension() const {return m_dim;} 152 void clear() {m_points.clear();} 152 void clear() {m_points.clear();} 153 size_t size() const {return m_points.size(); 153 size_t size() const {return m_points.size();} 154 154 155 const data_point& point(size_t a_index) cons 155 const data_point& point(size_t a_index) const { 156 //WARNING : no check done on a_index. 156 //WARNING : no check done on a_index. 157 return m_points[a_index]; 157 return m_points[a_index]; 158 } 158 } 159 data_point& point(size_t a_index) { 159 data_point& point(size_t a_index) { 160 //WARNING : no check done on a_index. 160 //WARNING : no check done on a_index. 161 return m_points[a_index]; 161 return m_points[a_index]; 162 } 162 } 163 163 164 data_point& add_point() { 164 data_point& add_point() { 165 m_points.push_back(data_point(m_dim)); 165 m_points.push_back(data_point(m_dim)); 166 return m_points.back(); 166 return m_points.back(); 167 } 167 } 168 168 169 bool remove_point(size_t a_index) { 169 bool remove_point(size_t a_index) { 170 bool done = false; 170 bool done = false; 171 if(a_index<m_points.size()){ 171 if(a_index<m_points.size()){ 172 std::vector<data_point>::iterator it = m 172 std::vector<data_point>::iterator it = m_points.begin(); 173 it += a_index; 173 it += a_index; 174 m_points.erase(it); 174 m_points.erase(it); 175 done = true; 175 done = true; 176 } 176 } 177 return done; 177 return done; 178 } 178 } 179 179 180 bool lower_extent(unsigned int a_coord,doubl 180 bool lower_extent(unsigned int a_coord,double& a_value) const { 181 if(m_points.empty()||(a_coord>=m_dim)){ 181 if(m_points.empty()||(a_coord>=m_dim)){ 182 a_value = 0; 182 a_value = 0; 183 return false; 183 return false; 184 } 184 } 185 std::vector<data_point>::const_iterator it 185 std::vector<data_point>::const_iterator it = m_points.begin(); 186 a_value = (*it).coordinate(a_coord).value( 186 a_value = (*it).coordinate(a_coord).value(); 187 ++it; 187 ++it; 188 for(;it!=m_points.end();++it) { 188 for(;it!=m_points.end();++it) { 189 a_value = mn<double>(a_value,(*it).coord 189 a_value = mn<double>(a_value,(*it).coordinate(a_coord).value()); 190 } 190 } 191 return true; 191 return true; 192 } 192 } 193 193 194 bool upper_extent(unsigned int a_coord,doubl 194 bool upper_extent(unsigned int a_coord,double& a_value) const { 195 if(m_points.empty()||(a_coord>=m_dim)){ 195 if(m_points.empty()||(a_coord>=m_dim)){ 196 a_value = 0; 196 a_value = 0; 197 return false; 197 return false; 198 } 198 } 199 std::vector<data_point>::const_iterator it 199 std::vector<data_point>::const_iterator it = m_points.begin(); 200 a_value = (*it).coordinate(a_coord).value( 200 a_value = (*it).coordinate(a_coord).value(); 201 ++it; 201 ++it; 202 for(;it!=m_points.end();++it) { 202 for(;it!=m_points.end();++it) { 203 a_value = mx<double>(a_value,(*it).coord 203 a_value = mx<double>(a_value,(*it).coordinate(a_coord).value()); 204 } 204 } 205 return true; 205 return true; 206 } 206 } 207 207 208 void scale(double a_scale) { 208 void scale(double a_scale) { 209 std::vector<data_point>::iterator it; 209 std::vector<data_point>::iterator it; 210 for(it=m_points.begin();it!=m_points.end() 210 for(it=m_points.begin();it!=m_points.end();++it) { 211 for(unsigned int coord=0;coord<m_dim;coo 211 for(unsigned int coord=0;coord<m_dim;coord++) { 212 measurement& _m = (*it).coordinate(coo << 212 measurement& m = (*it).coordinate(coord); 213 _m.set_value(_m.value() * a_scale); << 213 m.set_value(m.value() * a_scale); 214 _m.set_error_plus(_m.error_plus() * a_ << 214 m.set_error_plus(m.error_plus() * a_scale); 215 _m.set_error_minus(_m.error_minus() * << 215 m.set_error_minus(m.error_minus() * a_scale); 216 } 216 } 217 } 217 } 218 } 218 } 219 219 220 void scale_value(double a_scale) { 220 void scale_value(double a_scale) { 221 std::vector<data_point>::iterator it; 221 std::vector<data_point>::iterator it; 222 for(it=m_points.begin();it!=m_points.end() 222 for(it=m_points.begin();it!=m_points.end();++it) { 223 for(unsigned int coord=0;coord<m_dim;coo 223 for(unsigned int coord=0;coord<m_dim;coord++) { 224 measurement& _m = (*it).coordinate(coo << 224 measurement& m = (*it).coordinate(coord); 225 _m.set_value(_m.value() * a_scale); << 225 m.set_value(m.value() * a_scale); 226 } 226 } 227 } 227 } 228 } 228 } 229 229 230 void scale_errors(double a_scale) { 230 void scale_errors(double a_scale) { 231 std::vector<data_point>::iterator it; 231 std::vector<data_point>::iterator it; 232 for(it=m_points.begin();it!=m_points.end() 232 for(it=m_points.begin();it!=m_points.end();++it) { 233 for(unsigned int coord=0;coord<m_dim;coo 233 for(unsigned int coord=0;coord<m_dim;coord++) { 234 measurement& _m = (*it).coordinate(coo << 234 measurement& m = (*it).coordinate(coord); 235 _m.set_error_plus(_m.error_plus() * a_ << 235 m.set_error_plus(m.error_plus() * a_scale); 236 _m.set_error_minus(_m.error_minus() * << 236 m.set_error_minus(m.error_minus() * a_scale); 237 } 237 } 238 } 238 } 239 } 239 } 240 240 241 protected: 241 protected: 242 std::string m_title; 242 std::string m_title; 243 unsigned int m_dim; 243 unsigned int m_dim; 244 std::vector<data_point> m_points; 244 std::vector<data_point> m_points; 245 }; 245 }; 246 246 247 }} 247 }} 248 248 249 #endif 249 #endif