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_sg_h2plot 4 #ifndef tools_sg_h2plot 5 #define tools_sg_h2plot 5 #define tools_sg_h2plot 6 6 7 // Connexion tools/histo to sg/plotter. 7 // Connexion tools/histo to sg/plotter. 8 8 9 // Inheritance : 9 // Inheritance : 10 #include "plottables" 10 #include "plottables" 11 11 12 #include "../histo/h1d" 12 #include "../histo/h1d" 13 #include "../histo/h2d" 13 #include "../histo/h2d" 14 #include "../histo/p1d" 14 #include "../histo/p1d" 15 #include "../histo/p2d" 15 #include "../histo/p2d" 16 16 17 #include "../words" 17 #include "../words" 18 #include "../num2s" 18 #include "../num2s" 19 19 20 #ifdef TOOLS_MEM 20 #ifdef TOOLS_MEM 21 #include "../mem" 21 #include "../mem" 22 #endif 22 #endif 23 23 24 namespace tools { 24 namespace tools { 25 namespace sg { 25 namespace sg { 26 26 27 class h1d2plot : public virtual bins1D { 27 class h1d2plot : public virtual bins1D { 28 public: 28 public: 29 TOOLS_SCLASS(tools::sg::h1d2plot) 29 TOOLS_SCLASS(tools::sg::h1d2plot) 30 public: 30 public: 31 virtual void* cast(const std::string& a_clas 31 virtual void* cast(const std::string& a_class) const { 32 if(void* p = cmp_cast<h1d2plot>(this,a_cla 32 if(void* p = cmp_cast<h1d2plot>(this,a_class)) {return p;} 33 return bins1D::cast(a_class); 33 return bins1D::cast(a_class); 34 } 34 } 35 public: //plottable 35 public: //plottable 36 virtual plottable* copy() const {return new 36 virtual plottable* copy() const {return new h1d2plot(*this);} 37 virtual bool is_valid() const {return true;} 37 virtual bool is_valid() const {return true;} 38 virtual const std::string& name() const {ret 38 virtual const std::string& name() const {return m_name;} 39 virtual void set_name(const std::string& a_s 39 virtual void set_name(const std::string& a_s) {m_name = a_s;} 40 40 41 virtual const std::string& title() const {re 41 virtual const std::string& title() const {return m_data.title();} 42 virtual const std::string& legend() const {r 42 virtual const std::string& legend() const {return m_legend;} 43 virtual void set_legend(const std::string& a 43 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 44 44 45 virtual void infos(const std::string& a_opts 45 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 46 a_sinfos.clear(); 46 a_sinfos.clear(); 47 std::string f_lf("\n"); 47 std::string f_lf("\n"); 48 std::vector<std::string> ws; 48 std::vector<std::string> ws; 49 words(a_opts," ",false,ws); 49 words(a_opts," ",false,ws); 50 std::vector<std::string>::const_iterator i 50 std::vector<std::string>::const_iterator it; 51 51 52 /*bool show_fit_ndf = false; 52 /*bool show_fit_ndf = false; 53 {for(it=ws.begin();it!=ws.end();++it) { 53 {for(it=ws.begin();it!=ws.end();++it) { 54 if((*it)=="fit_ndf") {show_fit_ndf = tru 54 if((*it)=="fit_ndf") {show_fit_ndf = true;break;} 55 }}*/ 55 }}*/ 56 56 57 for(it=ws.begin();it!=ws.end();++it) { 57 for(it=ws.begin();it!=ws.end();++it) { 58 if(((*it)=="name") && m_name.size()) { 58 if(((*it)=="name") && m_name.size()) { 59 if(a_sinfos.size()) a_sinfos += f_lf; 59 if(a_sinfos.size()) a_sinfos += f_lf; 60 a_sinfos += "Name"; 60 a_sinfos += "Name"; 61 a_sinfos += f_lf; 61 a_sinfos += f_lf; 62 a_sinfos += m_name; 62 a_sinfos += m_name; 63 63 64 } else if((*it)=="entries") { 64 } else if((*it)=="entries") { 65 if(a_sinfos.size()) a_sinfos += f_lf; 65 if(a_sinfos.size()) a_sinfos += f_lf; 66 a_sinfos += "Entries"; 66 a_sinfos += "Entries"; 67 a_sinfos += f_lf; 67 a_sinfos += f_lf; 68 if(!numas<unsigned int>(m_data.all_ent 68 if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)){} 69 69 70 } else if((*it)=="mean") { 70 } else if((*it)=="mean") { 71 if(a_sinfos.size()) a_sinfos += f_lf; 71 if(a_sinfos.size()) a_sinfos += f_lf; 72 a_sinfos += "Mean"; 72 a_sinfos += "Mean"; 73 a_sinfos += f_lf; 73 a_sinfos += f_lf; 74 if(!numas<double>(m_data.mean(),a_sinf 74 if(!numas<double>(m_data.mean(),a_sinfos)) {} 75 75 76 } else if((*it)=="rms") { 76 } else if((*it)=="rms") { 77 if(a_sinfos.size()) a_sinfos += f_lf; 77 if(a_sinfos.size()) a_sinfos += f_lf; 78 a_sinfos += "RMS"; 78 a_sinfos += "RMS"; 79 a_sinfos += f_lf; 79 a_sinfos += f_lf; 80 if(!numas<double>(m_data.rms(),a_sinfo 80 if(!numas<double>(m_data.rms(),a_sinfos)) {} 81 81 82 } else if((*it)=="underflow") { 82 } else if((*it)=="underflow") { 83 if(a_sinfos.size()) a_sinfos += f_lf; 83 if(a_sinfos.size()) a_sinfos += f_lf; 84 a_sinfos += "UDFLW"; 84 a_sinfos += "UDFLW"; 85 a_sinfos += f_lf; 85 a_sinfos += f_lf; 86 if(!numas<double>(m_data.bin_height(hi 86 if(!numas<double>(m_data.bin_height(histo::axis_UNDERFLOW_BIN),a_sinfos)){} 87 87 88 } else if((*it)=="overflow") { 88 } else if((*it)=="overflow") { 89 if(a_sinfos.size()) a_sinfos += f_lf; 89 if(a_sinfos.size()) a_sinfos += f_lf; 90 a_sinfos += "OVFLW"; 90 a_sinfos += "OVFLW"; 91 a_sinfos += f_lf; 91 a_sinfos += f_lf; 92 if(!numas<double>(m_data.bin_height(hi 92 if(!numas<double>(m_data.bin_height(histo::axis_OVERFLOW_BIN),a_sinfos)){} 93 93 94 /* 94 /* 95 } else if((*it)=="fit_quality") { 95 } else if((*it)=="fit_quality") { 96 //look in m_data annotations for "fit. 96 //look in m_data annotations for "fit.chi2" and "fit.ndf" keys : 97 if(show_fit_ndf) { 97 if(show_fit_ndf) { 98 std::string schi2; 98 std::string schi2; 99 std::string sndf; 99 std::string sndf; 100 if(m_data.annotation("fit.chi2",schi 100 if(m_data.annotation("fit.chi2",schi2) && 101 m_data.annotation("fit.ndf",sndf) 101 m_data.annotation("fit.ndf",sndf) ){ 102 if(a_sinfos.size()) a_sinfos += f_ 102 if(a_sinfos.size()) a_sinfos += f_lf; 103 a_sinfos += "[h]^2! / ndf"; 103 a_sinfos += "[h]^2! / ndf"; 104 a_sinfos += f_lf; 104 a_sinfos += f_lf; 105 a_sinfos += schi2; 105 a_sinfos += schi2; 106 a_sinfos += " / "; 106 a_sinfos += " / "; 107 a_sinfos += sndf; 107 a_sinfos += sndf; 108 } 108 } 109 } else { //show chi2 only. 109 } else { //show chi2 only. 110 std::string schi2; 110 std::string schi2; 111 if(m_data.annotation("fit.chi2",schi 111 if(m_data.annotation("fit.chi2",schi2)){ 112 if(a_sinfos.size()) a_sinfos += f_ 112 if(a_sinfos.size()) a_sinfos += f_lf; 113 a_sinfos += "[h]^2!"; 113 a_sinfos += "[h]^2!"; 114 a_sinfos += f_lf; 114 a_sinfos += f_lf; 115 a_sinfos += schi2; 115 a_sinfos += schi2; 116 } 116 } 117 } 117 } 118 118 119 } else if((*it)=="fit_parameters") { 119 } else if((*it)=="fit_parameters") { 120 //look in m_data annotations for "fit. 120 //look in m_data annotations for "fit.param.<name>" keys : 121 typedef std::map<std::string,std::stri 121 typedef std::map<std::string,std::string> annots_t; 122 const annots_t& annots = m_data.annota 122 const annots_t& annots = m_data.annotations(); 123 annots_t::const_iterator it; 123 annots_t::const_iterator it; 124 for(it=annots.begin();it!=annots.end() 124 for(it=annots.begin();it!=annots.end();++it) { 125 const std::string& key = (*it).first 125 const std::string& key = (*it).first; 126 if(key.substr(0,10)=="fit.param.") { 126 if(key.substr(0,10)=="fit.param.") { 127 //fit.param.mean 14 127 //fit.param.mean 14 128 //01234567890123 128 //01234567890123 129 std::string name = key.substr(10,k 129 std::string name = key.substr(10,key.size()-10); 130 if(a_sinfos.size()) a_sinfos += f_ 130 if(a_sinfos.size()) a_sinfos += f_lf; 131 a_sinfos += name; 131 a_sinfos += name; 132 a_sinfos += f_lf; 132 a_sinfos += f_lf; 133 a_sinfos += (*it).second; 133 a_sinfos += (*it).second; 134 } 134 } 135 } 135 } 136 */ 136 */ 137 } 137 } 138 } 138 } 139 } 139 } 140 public: //bins1D 140 public: //bins1D 141 virtual void bins_Sw_range(float& a_mn,float 141 virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const { 142 if(a_with_entries && m_data.has_entries_pe 142 if(a_with_entries && m_data.has_entries_per_bin()) { 143 double mn,mx; 143 double mn,mx; 144 m_data.min_bin_height_with_entries(mn); 144 m_data.min_bin_height_with_entries(mn); 145 m_data.max_bin_height_with_entries(mx); 145 m_data.max_bin_height_with_entries(mx); 146 a_mn = float(mn); 146 a_mn = float(mn); 147 a_mx = float(mx); 147 a_mx = float(mx); 148 } else { 148 } else { 149 a_mn = (float)m_data.min_bin_height(); 149 a_mn = (float)m_data.min_bin_height(); 150 a_mx = (float)m_data.max_bin_height(); 150 a_mx = (float)m_data.max_bin_height(); 151 } 151 } 152 } 152 } 153 virtual unsigned int bins() const {return m_ 153 virtual unsigned int bins() const {return m_data.axis().bins();} 154 virtual float axis_min() const {return (floa 154 virtual float axis_min() const {return (float)m_data.axis().lower_edge();} 155 virtual float axis_max() const {return (floa 155 virtual float axis_max() const {return (float)m_data.axis().upper_edge();} 156 virtual float bin_lower_edge(int aI) const { 156 virtual float bin_lower_edge(int aI) const {return (float)m_data.axis().bin_lower_edge(aI);} 157 virtual float bin_upper_edge(int aI) const { 157 virtual float bin_upper_edge(int aI) const {return (float)m_data.axis().bin_upper_edge(aI);} 158 158 159 virtual bool has_entries_per_bin() const {re 159 virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();} 160 virtual unsigned int bin_entries(int aI) con 160 virtual unsigned int bin_entries(int aI) const {return m_data.bin_entries(aI);} 161 161 162 virtual float bin_Sw(int aI) const {return ( 162 virtual float bin_Sw(int aI) const {return (float)m_data.bin_height(aI);} 163 163 164 virtual float bin_error(int aI) const {retur 164 virtual float bin_error(int aI) const {return (float)m_data.bin_error(aI);} 165 virtual bool is_profile() const {return fals 165 virtual bool is_profile() const {return false;} 166 public: 166 public: 167 h1d2plot(const histo::h1d& a_data):m_data(a_ 167 h1d2plot(const histo::h1d& a_data):m_data(a_data) { 168 #ifdef TOOLS_MEM 168 #ifdef TOOLS_MEM 169 mem::increment(s_class().c_str()); 169 mem::increment(s_class().c_str()); 170 #endif 170 #endif 171 } 171 } 172 virtual ~h1d2plot(){ 172 virtual ~h1d2plot(){ 173 #ifdef TOOLS_MEM 173 #ifdef TOOLS_MEM 174 mem::decrement(s_class().c_str()); 174 mem::decrement(s_class().c_str()); 175 #endif 175 #endif 176 } 176 } 177 public: 177 public: 178 h1d2plot(const h1d2plot& a_from) 178 h1d2plot(const h1d2plot& a_from) 179 :plottable(a_from),bins1D(a_from) 179 :plottable(a_from),bins1D(a_from) 180 ,m_data(a_from.m_data) 180 ,m_data(a_from.m_data) 181 ,m_name(a_from.m_name) 181 ,m_name(a_from.m_name) 182 ,m_legend(a_from.m_legend) 182 ,m_legend(a_from.m_legend) 183 { 183 { 184 #ifdef TOOLS_MEM 184 #ifdef TOOLS_MEM 185 mem::increment(s_class().c_str()); 185 mem::increment(s_class().c_str()); 186 #endif 186 #endif 187 } 187 } 188 h1d2plot& operator=(const h1d2plot& a_from){ 188 h1d2plot& operator=(const h1d2plot& a_from){ 189 m_name = a_from.m_name; 189 m_name = a_from.m_name; 190 m_legend = a_from.m_legend; 190 m_legend = a_from.m_legend; 191 return *this; 191 return *this; 192 } 192 } 193 public: 193 public: 194 const histo::h1d& data() const {return m_dat 194 const histo::h1d& data() const {return m_data;} 195 protected: 195 protected: 196 const histo::h1d& m_data; 196 const histo::h1d& m_data; 197 std::string m_name; 197 std::string m_name; 198 std::string m_legend; 198 std::string m_legend; 199 }; 199 }; 200 200 201 class h2d2plot : public virtual bins2D { 201 class h2d2plot : public virtual bins2D { 202 public: 202 public: 203 TOOLS_SCLASS(tools::sg::h2d2plot) 203 TOOLS_SCLASS(tools::sg::h2d2plot) 204 public: 204 public: 205 virtual void* cast(const std::string& a_clas 205 virtual void* cast(const std::string& a_class) const { 206 if(void* p = cmp_cast<h2d2plot>(this,a_cla 206 if(void* p = cmp_cast<h2d2plot>(this,a_class)) {return p;} 207 return bins2D::cast(a_class); 207 return bins2D::cast(a_class); 208 } 208 } 209 public: //plottable 209 public: //plottable 210 virtual plottable* copy() const {return new 210 virtual plottable* copy() const {return new h2d2plot(*this);} 211 virtual bool is_valid() const {return true;} 211 virtual bool is_valid() const {return true;} 212 virtual const std::string& name() const {ret 212 virtual const std::string& name() const {return m_name;} 213 virtual void set_name(const std::string& a_s 213 virtual void set_name(const std::string& a_s) {m_name = a_s;} 214 virtual const std::string& title() const {re 214 virtual const std::string& title() const {return m_data.title();} 215 virtual const std::string& legend() const {r 215 virtual const std::string& legend() const {return m_legend;} 216 virtual void set_legend(const std::string& a 216 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 217 217 218 virtual void infos(const std::string& a_opts 218 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 219 a_sinfos.clear(); 219 a_sinfos.clear(); 220 std::string f_lf("\n"); 220 std::string f_lf("\n"); 221 std::vector<std::string> ws; 221 std::vector<std::string> ws; 222 words(a_opts," ",false,ws); 222 words(a_opts," ",false,ws); 223 std::vector<std::string>::const_iterator i 223 std::vector<std::string>::const_iterator it; 224 for(it=ws.begin();it!=ws.end();++it) { 224 for(it=ws.begin();it!=ws.end();++it) { 225 if(((*it)=="name") && m_name.size()) { 225 if(((*it)=="name") && m_name.size()) { 226 if(a_sinfos.size()) a_sinfos += f_lf; 226 if(a_sinfos.size()) a_sinfos += f_lf; 227 a_sinfos += "Name\n"; 227 a_sinfos += "Name\n"; 228 a_sinfos += m_name; 228 a_sinfos += m_name; 229 229 230 } else if((*it)=="entries") { 230 } else if((*it)=="entries") { 231 if(a_sinfos.size()) a_sinfos += f_lf; 231 if(a_sinfos.size()) a_sinfos += f_lf; 232 a_sinfos += "Entries\n"; 232 a_sinfos += "Entries\n"; 233 if(!numas<unsigned int>(m_data.all_ent 233 if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)) {} 234 234 235 } else if((*it)=="mean") { 235 } else if((*it)=="mean") { 236 if(a_sinfos.size()) a_sinfos += f_lf; 236 if(a_sinfos.size()) a_sinfos += f_lf; 237 a_sinfos += "MeanX\n"; 237 a_sinfos += "MeanX\n"; 238 if(!numas<double>(m_data.mean_x(),a_si 238 if(!numas<double>(m_data.mean_x(),a_sinfos)) {} 239 a_sinfos += f_lf; 239 a_sinfos += f_lf; 240 a_sinfos += "MeanY\n"; 240 a_sinfos += "MeanY\n"; 241 if(!numas<double>(m_data.mean_y(),a_si 241 if(!numas<double>(m_data.mean_y(),a_sinfos)) {} 242 242 243 } else if((*it)=="rms") { 243 } else if((*it)=="rms") { 244 if(a_sinfos.size()) a_sinfos += f_lf; 244 if(a_sinfos.size()) a_sinfos += f_lf; 245 a_sinfos += "RMS X\n"; 245 a_sinfos += "RMS X\n"; 246 if(!numas<double>(m_data.rms_x(),a_sin 246 if(!numas<double>(m_data.rms_x(),a_sinfos)) {} 247 a_sinfos += f_lf; 247 a_sinfos += f_lf; 248 a_sinfos += "RMS Y\n"; 248 a_sinfos += "RMS Y\n"; 249 if(!numas<double>(m_data.rms_y(),a_sin 249 if(!numas<double>(m_data.rms_y(),a_sinfos)) {} 250 250 251 } 251 } 252 } 252 } 253 } 253 } 254 public: //bins2D 254 public: //bins2D 255 virtual void bins_Sw_range(float& a_mn,float 255 virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const { 256 if(a_with_entries && m_data.has_entries_pe 256 if(a_with_entries && m_data.has_entries_per_bin()) { 257 double mn,mx; 257 double mn,mx; 258 m_data.min_bin_height_with_entries(mn); 258 m_data.min_bin_height_with_entries(mn); 259 m_data.max_bin_height_with_entries(mx); 259 m_data.max_bin_height_with_entries(mx); 260 a_mn = float(mn); 260 a_mn = float(mn); 261 a_mx = float(mx); 261 a_mx = float(mx); 262 } else { 262 } else { 263 a_mn = (float)m_data.min_bin_height(); 263 a_mn = (float)m_data.min_bin_height(); 264 a_mx = (float)m_data.max_bin_height(); 264 a_mx = (float)m_data.max_bin_height(); 265 } 265 } 266 } 266 } 267 virtual unsigned int x_bins() const {return 267 virtual unsigned int x_bins() const {return m_data.axis_x().bins();} 268 virtual unsigned int y_bins() const {return 268 virtual unsigned int y_bins() const {return m_data.axis_y().bins();} 269 virtual float x_axis_min() const {return (fl 269 virtual float x_axis_min() const {return (float)m_data.axis_x().lower_edge();} 270 virtual float x_axis_max() const {return (fl 270 virtual float x_axis_max() const {return (float)m_data.axis_x().upper_edge();} 271 virtual float y_axis_min() const {return (fl 271 virtual float y_axis_min() const {return (float)m_data.axis_y().lower_edge();} 272 virtual float y_axis_max() const {return (fl 272 virtual float y_axis_max() const {return (float)m_data.axis_y().upper_edge();} 273 273 274 virtual float bin_lower_edge_x(int aI) const 274 virtual float bin_lower_edge_x(int aI) const {return (float)m_data.axis_x().bin_lower_edge(aI);} 275 virtual float bin_upper_edge_x(int aI) const 275 virtual float bin_upper_edge_x(int aI) const {return (float)m_data.axis_x().bin_upper_edge(aI);} 276 virtual float bin_lower_edge_y(int aI) const 276 virtual float bin_lower_edge_y(int aI) const {return (float)m_data.axis_y().bin_lower_edge(aI);} 277 virtual float bin_upper_edge_y(int aI) const 277 virtual float bin_upper_edge_y(int aI) const {return (float)m_data.axis_y().bin_upper_edge(aI);} 278 278 279 virtual bool has_entries_per_bin() const {re 279 virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();} 280 virtual unsigned int bin_entries(int aI,int 280 virtual unsigned int bin_entries(int aI,int aJ) const {return m_data.bin_entries(aI,aJ);} 281 281 282 virtual float bin_Sw(int aI,int aJ) const {r 282 virtual float bin_Sw(int aI,int aJ) const {return (float)m_data.bin_height(aI,aJ);} 283 283 284 virtual float bin_error(int aI,int aJ) const 284 virtual float bin_error(int aI,int aJ) const {return (float)m_data.bin_error(aI,aJ);} 285 public: 285 public: 286 h2d2plot(const histo::h2d& a_data) 286 h2d2plot(const histo::h2d& a_data) 287 :m_data(a_data) 287 :m_data(a_data) 288 { 288 { 289 #ifdef TOOLS_MEM 289 #ifdef TOOLS_MEM 290 mem::increment(s_class().c_str()); 290 mem::increment(s_class().c_str()); 291 #endif 291 #endif 292 } 292 } 293 virtual ~h2d2plot(){ 293 virtual ~h2d2plot(){ 294 #ifdef TOOLS_MEM 294 #ifdef TOOLS_MEM 295 mem::decrement(s_class().c_str()); 295 mem::decrement(s_class().c_str()); 296 #endif 296 #endif 297 } 297 } 298 public: 298 public: 299 h2d2plot(const h2d2plot& a_from) 299 h2d2plot(const h2d2plot& a_from) 300 :plottable(a_from),bins2D(a_from) 300 :plottable(a_from),bins2D(a_from) 301 ,m_data(a_from.m_data) 301 ,m_data(a_from.m_data) 302 ,m_name(a_from.m_name) 302 ,m_name(a_from.m_name) 303 ,m_legend(a_from.m_legend) 303 ,m_legend(a_from.m_legend) 304 { 304 { 305 #ifdef TOOLS_MEM 305 #ifdef TOOLS_MEM 306 mem::increment(s_class().c_str()); 306 mem::increment(s_class().c_str()); 307 #endif 307 #endif 308 } 308 } 309 h2d2plot& operator=(const h2d2plot& a_from){ 309 h2d2plot& operator=(const h2d2plot& a_from){ 310 m_name = a_from.m_name; 310 m_name = a_from.m_name; 311 m_legend = a_from.m_legend; 311 m_legend = a_from.m_legend; 312 return *this; 312 return *this; 313 } 313 } 314 protected: 314 protected: 315 const histo::h2d& m_data; 315 const histo::h2d& m_data; 316 std::string m_name; 316 std::string m_name; 317 std::string m_legend; 317 std::string m_legend; 318 }; 318 }; 319 319 320 //NOTE : for the moment, same code as h1d2plot 320 //NOTE : for the moment, same code as h1d2plot ! 321 class p1d2plot : public virtual bins1D { 321 class p1d2plot : public virtual bins1D { 322 public: 322 public: 323 TOOLS_SCLASS(tools::sg::p1d2plot) 323 TOOLS_SCLASS(tools::sg::p1d2plot) 324 public: 324 public: 325 virtual void* cast(const std::string& a_clas 325 virtual void* cast(const std::string& a_class) const { 326 if(void* p = cmp_cast<p1d2plot>(this,a_cla 326 if(void* p = cmp_cast<p1d2plot>(this,a_class)) {return p;} 327 return bins1D::cast(a_class); 327 return bins1D::cast(a_class); 328 } 328 } 329 public: 329 public: 330 virtual plottable* copy() const {return new 330 virtual plottable* copy() const {return new p1d2plot(*this);} 331 virtual bool is_valid() const {return true;} 331 virtual bool is_valid() const {return true;} 332 virtual const std::string& name() const {ret 332 virtual const std::string& name() const {return m_name;} 333 virtual void set_name(const std::string& a_s 333 virtual void set_name(const std::string& a_s) {m_name = a_s;} 334 virtual const std::string& title() const {re 334 virtual const std::string& title() const {return m_data.title();} 335 virtual const std::string& legend() const {r 335 virtual const std::string& legend() const {return m_legend;} 336 virtual void set_legend(const std::string& a 336 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 337 337 338 virtual void infos(const std::string& a_opts 338 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 339 a_sinfos.clear(); 339 a_sinfos.clear(); 340 std::string f_lf("\n"); 340 std::string f_lf("\n"); 341 std::vector<std::string> ws; 341 std::vector<std::string> ws; 342 words(a_opts," ",false,ws); 342 words(a_opts," ",false,ws); 343 std::vector<std::string>::const_iterator i 343 std::vector<std::string>::const_iterator it; 344 for(it=ws.begin();it!=ws.end();++it) { 344 for(it=ws.begin();it!=ws.end();++it) { 345 if(((*it)=="name") && m_name.size()) { 345 if(((*it)=="name") && m_name.size()) { 346 if(a_sinfos.size()) a_sinfos += f_lf; 346 if(a_sinfos.size()) a_sinfos += f_lf; 347 a_sinfos += "Name\n"; 347 a_sinfos += "Name\n"; 348 a_sinfos += m_name; 348 a_sinfos += m_name; 349 349 350 } else if((*it)=="entries") { 350 } else if((*it)=="entries") { 351 if(a_sinfos.size()) a_sinfos += f_lf; 351 if(a_sinfos.size()) a_sinfos += f_lf; 352 a_sinfos += "Entries\n"; 352 a_sinfos += "Entries\n"; 353 if(!numas<unsigned int>(m_data.all_ent 353 if(!numas<unsigned int>(m_data.all_entries(),a_sinfos)) {} 354 } else if((*it)=="mean") { 354 } else if((*it)=="mean") { 355 if(a_sinfos.size()) a_sinfos += f_lf; 355 if(a_sinfos.size()) a_sinfos += f_lf; 356 a_sinfos += "Mean\n"; 356 a_sinfos += "Mean\n"; 357 if(!numas<double>(m_data.mean(),a_sinf 357 if(!numas<double>(m_data.mean(),a_sinfos)) {} 358 } else if((*it)=="rms") { 358 } else if((*it)=="rms") { 359 if(a_sinfos.size()) a_sinfos += f_lf; 359 if(a_sinfos.size()) a_sinfos += f_lf; 360 a_sinfos += "RMS\n"; 360 a_sinfos += "RMS\n"; 361 if(!numas<double>(m_data.rms(),a_sinfo 361 if(!numas<double>(m_data.rms(),a_sinfos)) {} 362 362 363 } 363 } 364 } 364 } 365 } 365 } 366 public: 366 public: 367 virtual unsigned int bins() const {return m_ 367 virtual unsigned int bins() const {return m_data.axis().bins();} 368 368 369 virtual void bins_Sw_range(float& a_mn,float 369 virtual void bins_Sw_range(float& a_mn,float& a_mx,bool a_with_entries) const { 370 if(a_with_entries && m_data.has_entries_pe 370 if(a_with_entries && m_data.has_entries_per_bin()) { 371 double mn,mx; 371 double mn,mx; 372 m_data.min_bin_height_with_entries(mn); 372 m_data.min_bin_height_with_entries(mn); 373 m_data.max_bin_height_with_entries(mx); 373 m_data.max_bin_height_with_entries(mx); 374 a_mn = float(mn); 374 a_mn = float(mn); 375 a_mx = float(mx); 375 a_mx = float(mx); 376 } else { 376 } else { 377 a_mn = (float)m_data.min_bin_height(); 377 a_mn = (float)m_data.min_bin_height(); 378 a_mx = (float)m_data.max_bin_height(); 378 a_mx = (float)m_data.max_bin_height(); 379 } 379 } 380 } 380 } 381 381 382 virtual float axis_min() const {return (floa 382 virtual float axis_min() const {return (float)m_data.axis().lower_edge();} 383 virtual float axis_max() const {return (floa 383 virtual float axis_max() const {return (float)m_data.axis().upper_edge();} 384 virtual float bin_lower_edge(int aI) const { 384 virtual float bin_lower_edge(int aI) const {return (float)m_data.axis().bin_lower_edge(aI);} 385 virtual float bin_upper_edge(int aI) const { 385 virtual float bin_upper_edge(int aI) const {return (float)m_data.axis().bin_upper_edge(aI);} 386 386 387 virtual bool has_entries_per_bin() const {re 387 virtual bool has_entries_per_bin() const {return m_data.has_entries_per_bin();} 388 virtual unsigned int bin_entries(int aI) con 388 virtual unsigned int bin_entries(int aI) const {return m_data.bin_entries(aI);} 389 389 390 virtual float bin_Sw(int aI) const {return ( 390 virtual float bin_Sw(int aI) const {return (float)m_data.bin_height(aI);} 391 391 392 virtual float bin_error(int aI) const {retur 392 virtual float bin_error(int aI) const {return (float)m_data.bin_error(aI);} 393 393 394 virtual bool is_profile() const {return true 394 virtual bool is_profile() const {return true;} 395 public: 395 public: 396 p1d2plot(const histo::p1d& a_data):m_data(a_ 396 p1d2plot(const histo::p1d& a_data):m_data(a_data){} 397 virtual ~p1d2plot(){} 397 virtual ~p1d2plot(){} 398 public: 398 public: 399 p1d2plot(const p1d2plot& a_from) 399 p1d2plot(const p1d2plot& a_from) 400 :plottable(a_from),bins1D(a_from) 400 :plottable(a_from),bins1D(a_from) 401 ,m_data(a_from.m_data) 401 ,m_data(a_from.m_data) 402 ,m_name(a_from.m_name) 402 ,m_name(a_from.m_name) 403 ,m_legend(a_from.m_legend) 403 ,m_legend(a_from.m_legend) 404 {} 404 {} 405 p1d2plot& operator=(const p1d2plot& a_from){ 405 p1d2plot& operator=(const p1d2plot& a_from){ 406 m_name = a_from.m_name; 406 m_name = a_from.m_name; 407 m_legend = a_from.m_legend; 407 m_legend = a_from.m_legend; 408 return *this; 408 return *this; 409 } 409 } 410 protected: 410 protected: 411 const histo::p1d& m_data; 411 const histo::p1d& m_data; 412 std::string m_name; 412 std::string m_name; 413 std::string m_legend; 413 std::string m_legend; 414 }; 414 }; 415 415 416 /* 416 /* 417 class p2d2plot : public virtual SbPlottableBin 417 class p2d2plot : public virtual SbPlottableBins2D { 418 public: 418 public: 419 TOOLS_SCLASS(tools::sg::p2d2plot) 419 TOOLS_SCLASS(tools::sg::p2d2plot) 420 public: 420 public: 421 virtual void* cast(const std::string& a_clas 421 virtual void* cast(const std::string& a_class) const { 422 if(void* p = cmp_cast<p2d2plot>(this,a_cla 422 if(void* p = cmp_cast<p2d2plot>(this,a_class)) {return p;} 423 return bins2D::cast(a_class); 423 return bins2D::cast(a_class); 424 } 424 } 425 public: //SbPlottableObject 425 public: //SbPlottableObject 426 virtual bool is_valid() const {return true;} 426 virtual bool is_valid() const {return true;} 427 virtual const char* name(){return m_name;} 427 virtual const char* name(){return m_name;} 428 virtual const char* legend(){return m_legend 428 virtual const char* legend(){return m_legend;} 429 public: 429 public: 430 virtual int getDimension() const{return 2;} 430 virtual int getDimension() const{return 2;} 431 virtual const char* title(){return m_data.ti 431 virtual const char* title(){return m_data.title();} 432 public: //SbPlottableBins2D 432 public: //SbPlottableBins2D 433 virtual void getBinsSumOfWeightsRange(float& 433 virtual void getBinsSumOfWeightsRange(float& a_mn,float& a_mx) const { 434 a_mn = (float)m_data.min_bin_height(); 434 a_mn = (float)m_data.min_bin_height(); 435 a_mx = (float)m_data.max_bin_height(); 435 a_mx = (float)m_data.max_bin_height(); 436 } 436 } 437 virtual int getAxisNumberOfBinsX() const {re 437 virtual int getAxisNumberOfBinsX() const {return m_data.axis_x().bins();} 438 virtual int getAxisNumberOfBinsY() const {re 438 virtual int getAxisNumberOfBinsY() const {return m_data.axis_y().bins();} 439 virtual float getAxisMinimumX() const {retur 439 virtual float getAxisMinimumX() const {return (float)m_data.axis_x().lower_edge();} 440 virtual float getAxisMaximumX() const {retur 440 virtual float getAxisMaximumX() const {return (float)m_data.axis_x().upper_edge();} 441 virtual float getAxisMinimumY() const {retur 441 virtual float getAxisMinimumY() const {return (float)m_data.axis_y().lower_edge();} 442 virtual float getAxisMaximumY() const {retur 442 virtual float getAxisMaximumY() const {return (float)m_data.axis_y().upper_edge();} 443 virtual float getBinLowerEdgeX(int aI) const 443 virtual float getBinLowerEdgeX(int aI) const { 444 return (float)m_data.axis_x().bin_lower_ed 444 return (float)m_data.axis_x().bin_lower_edge(aI); 445 } 445 } 446 virtual float bin_upper_edgeX(int aI) const 446 virtual float bin_upper_edgeX(int aI) const { 447 return (float)m_data.axis_x().bin_upper_ed 447 return (float)m_data.axis_x().bin_upper_edge(aI); 448 } 448 } 449 virtual float getBinLowerEdgeY(int aI) const 449 virtual float getBinLowerEdgeY(int aI) const { 450 return (float)m_data.axis_y().bin_lower_ed 450 return (float)m_data.axis_y().bin_lower_edge(aI); 451 } 451 } 452 virtual float bin_upper_edgeY(int aI) const 452 virtual float bin_upper_edgeY(int aI) const { 453 return (float)m_data.axis_y().bin_upper_ed 453 return (float)m_data.axis_y().bin_upper_edge(aI); 454 } 454 } 455 virtual int getBinNumberOfEntries(int aI,int 455 virtual int getBinNumberOfEntries(int aI,int aJ) const { 456 return m_data.bin_entries(aI,aJ); 456 return m_data.bin_entries(aI,aJ); 457 } 457 } 458 virtual float getBinSumOfWeights(int aI,int 458 virtual float getBinSumOfWeights(int aI,int aJ) const { 459 return (float)m_data.bin_height(aI,aJ); 459 return (float)m_data.bin_height(aI,aJ); 460 } 460 } 461 virtual float getBinBar(int aI,int aJ) const 461 virtual float getBinBar(int aI,int aJ) const { 462 return (float)m_data.bin_error(aI,aJ); 462 return (float)m_data.bin_error(aI,aJ); 463 } 463 } 464 464 465 virtual void infos(const std::string& a_opts 465 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 466 a_sinfos.clear(); 466 a_sinfos.clear(); 467 std::string f_lf("\n"); 467 std::string f_lf("\n"); 468 std::vector<std::string> ws; 468 std::vector<std::string> ws; 469 words(a_opts," ",false,ws); 469 words(a_opts," ",false,ws); 470 std::vector<std::string>::const_iterator i 470 std::vector<std::string>::const_iterator it; 471 for(it=ws.begin();it!=ws.end();++it) { 471 for(it=ws.begin();it!=ws.end();++it) { 472 if(((*it)=="name") && m_name.size()) { 472 if(((*it)=="name") && m_name.size()) { 473 if(a_sinfos.size()) a_sinfos += f_lf; 473 if(a_sinfos.size()) a_sinfos += f_lf; 474 a_sinfos += "Name\n"; 474 a_sinfos += "Name\n"; 475 a_sinfos += m_name; 475 a_sinfos += m_name; 476 476 477 } else if((*it)=="entries") { 477 } else if((*it)=="entries") { 478 if(a_sinfos.size()) a_sinfos += f_lf; 478 if(a_sinfos.size()) a_sinfos += f_lf; 479 a_sinfos += "Entries\n"; 479 a_sinfos += "Entries\n"; 480 if(!numasd int>(m_data.all_entries(),a 480 if(!numasd int>(m_data.all_entries(),a_sinfos)) {} 481 } else if((*it)=="mean") { 481 } else if((*it)=="mean") { 482 if(a_sinfos.size()) a_sinfos += f_lf; 482 if(a_sinfos.size()) a_sinfos += f_lf; 483 a_sinfos += "MeanX\n"; 483 a_sinfos += "MeanX\n"; 484 if(!numas<double>(m_data.mean_x(),a_si 484 if(!numas<double>(m_data.mean_x(),a_sinfos)) {} 485 a_sinfos += f_lf; 485 a_sinfos += f_lf; 486 a_sinfos += "MeanY\n"; 486 a_sinfos += "MeanY\n"; 487 if(!numas<double>(m_data.mean_y(),a_si 487 if(!numas<double>(m_data.mean_y(),a_sinfos)) {} 488 } else if((*it)=="rms") { 488 } else if((*it)=="rms") { 489 if(a_sinfos.size()) a_sinfos += f_lf; 489 if(a_sinfos.size()) a_sinfos += f_lf; 490 a_sinfos += "RMS X\n"; 490 a_sinfos += "RMS X\n"; 491 if(!numas<double>(m_data.rms_x(),a_sin 491 if(!numas<double>(m_data.rms_x(),a_sinfos)) {} 492 a_sinfos += f_lf; 492 a_sinfos += f_lf; 493 a_sinfos += "RMS Y\n"; 493 a_sinfos += "RMS Y\n"; 494 if(!numas<double>(m_data.rms_y(),a_sin 494 if(!numas<double>(m_data.rms_y(),a_sinfos)) {} 495 495 496 } 496 } 497 } 497 } 498 } 498 } 499 499 500 public: 500 public: 501 p2d2plot(const histo::p2d& a_data) 501 p2d2plot(const histo::p2d& a_data) 502 :m_data(a_data) 502 :m_data(a_data) 503 { 503 { 504 #ifdef TOOLS_MEM 504 #ifdef TOOLS_MEM 505 mem::increment(s_class().c_str()); 505 mem::increment(s_class().c_str()); 506 #endif 506 #endif 507 } 507 } 508 virtual ~p2d2plot(){ 508 virtual ~p2d2plot(){ 509 #ifdef TOOLS_MEM 509 #ifdef TOOLS_MEM 510 mem::decrement(s_class().c_str()); 510 mem::decrement(s_class().c_str()); 511 #endif 511 #endif 512 } 512 } 513 public: 513 public: 514 p2d2plot(const p2d2plot& a_from) 514 p2d2plot(const p2d2plot& a_from) 515 :m_data(a_from.m_data) 515 :m_data(a_from.m_data) 516 ,m_name(a_from.m_name) 516 ,m_name(a_from.m_name) 517 ,m_legend(a_from.m_legend) 517 ,m_legend(a_from.m_legend) 518 { 518 { 519 #ifdef TOOLS_MEM 519 #ifdef TOOLS_MEM 520 mem::increment(s_class().c_str()); 520 mem::increment(s_class().c_str()); 521 #endif 521 #endif 522 } 522 } 523 p2d2plot& operator=(const p2d2plot& a_from){ 523 p2d2plot& operator=(const p2d2plot& a_from){ 524 m_name = a_from.m_name; 524 m_name = a_from.m_name; 525 m_legend = a_from.m_legend; 525 m_legend = a_from.m_legend; 526 return *this; 526 return *this; 527 } 527 } 528 protected: 528 protected: 529 const histo::p2d& m_data; 529 const histo::p2d& m_data; 530 std::string m_name; 530 std::string m_name; 531 std::string m_legend; 531 std::string m_legend; 532 }; 532 }; 533 */ 533 */ 534 534 535 }} 535 }} 536 536 537 #endif 537 #endif