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_cloud2plot 4 #ifndef tools_sg_cloud2plot 5 #define tools_sg_cloud2plot 5 #define tools_sg_cloud2plot 6 6 7 #include "plottables" 7 #include "plottables" 8 8 9 #include "../words" 9 #include "../words" 10 #include "../num2s" 10 #include "../num2s" 11 11 12 #include "../histo/c2d" 12 #include "../histo/c2d" 13 13 14 #ifdef TOOLS_MEM 14 #ifdef TOOLS_MEM 15 #include "../mem" 15 #include "../mem" 16 #endif 16 #endif 17 17 18 namespace tools { 18 namespace tools { 19 namespace sg { 19 namespace sg { 20 20 21 class c2d2plot : public virtual points2D { 21 class c2d2plot : public virtual points2D { 22 TOOLS_SCLASS(tools::sg::c2d2plot) 22 TOOLS_SCLASS(tools::sg::c2d2plot) 23 public: //plottable 23 public: //plottable 24 virtual plottable* copy() const {return new 24 virtual plottable* copy() const {return new c2d2plot(*this);} 25 virtual bool is_valid() const {return true;} 25 virtual bool is_valid() const {return true;} 26 virtual const std::string& name() const {ret 26 virtual const std::string& name() const {return m_name;} 27 virtual void set_name(const std::string& a_s 27 virtual void set_name(const std::string& a_s) {m_name = a_s;} 28 virtual const std::string& title() const {re 28 virtual const std::string& title() const {return m_data.title();} 29 virtual const std::string& legend() const {r 29 virtual const std::string& legend() const {return m_legend;} 30 virtual void set_legend(const std::string& a 30 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 31 31 32 virtual void infos(const std::string& a_opts 32 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 33 a_sinfos.clear(); 33 a_sinfos.clear(); 34 std::string f_lf("\n"); 34 std::string f_lf("\n"); 35 std::vector<std::string> ws; 35 std::vector<std::string> ws; 36 words(a_opts," ",false,ws); 36 words(a_opts," ",false,ws); 37 std::vector<std::string>::const_iterator i 37 std::vector<std::string>::const_iterator it; 38 38 39 for(it=ws.begin();it!=ws.end();++it) { 39 for(it=ws.begin();it!=ws.end();++it) { 40 if(((*it)=="name") && m_name.size()) { 40 if(((*it)=="name") && m_name.size()) { 41 if(a_sinfos.size()) a_sinfos += f_lf; 41 if(a_sinfos.size()) a_sinfos += f_lf; 42 a_sinfos += "Name\n"; 42 a_sinfos += "Name\n"; 43 a_sinfos += m_name; 43 a_sinfos += m_name; 44 44 45 } else if((*it)=="entries") { 45 } else if((*it)=="entries") { 46 if(a_sinfos.size()) a_sinfos += f_lf; 46 if(a_sinfos.size()) a_sinfos += f_lf; 47 a_sinfos += "Entries\n"; 47 a_sinfos += "Entries\n"; 48 if(!numas<unsigned int>(m_data.entries 48 if(!numas<unsigned int>(m_data.entries(),a_sinfos)){} 49 49 50 } else if((*it)=="mean") { 50 } else if((*it)=="mean") { 51 if(a_sinfos.size()) a_sinfos += f_lf; 51 if(a_sinfos.size()) a_sinfos += f_lf; 52 a_sinfos += "MeanX\n"; 52 a_sinfos += "MeanX\n"; 53 if(!numas<double>(m_data.mean_x(),a_si 53 if(!numas<double>(m_data.mean_x(),a_sinfos)){} 54 a_sinfos += f_lf; 54 a_sinfos += f_lf; 55 a_sinfos += "MeanY\n"; 55 a_sinfos += "MeanY\n"; 56 if(!numas<double>(m_data.mean_y(),a_si 56 if(!numas<double>(m_data.mean_y(),a_sinfos)){} 57 57 58 } else if((*it)=="rms") { 58 } else if((*it)=="rms") { 59 if(a_sinfos.size()) a_sinfos += f_lf; 59 if(a_sinfos.size()) a_sinfos += f_lf; 60 a_sinfos += "RMS X\n"; 60 a_sinfos += "RMS X\n"; 61 if(!numas<double>(m_data.rms_x(),a_sin 61 if(!numas<double>(m_data.rms_x(),a_sinfos)){} 62 a_sinfos += f_lf; 62 a_sinfos += f_lf; 63 a_sinfos += "RMS Y\n"; 63 a_sinfos += "RMS Y\n"; 64 if(!numas<double>(m_data.rms_y(),a_sin 64 if(!numas<double>(m_data.rms_y(),a_sinfos)){} 65 65 66 } 66 } 67 } 67 } 68 } 68 } 69 public: //points2D 69 public: //points2D 70 virtual float x_axis_min() const {return (fl 70 virtual float x_axis_min() const {return (float)m_data.lower_edge_x();} 71 virtual float x_axis_max() const {return (fl 71 virtual float x_axis_max() const {return (float)m_data.upper_edge_x();} 72 virtual float y_axis_min() const {return (fl 72 virtual float y_axis_min() const {return (float)m_data.lower_edge_y();} 73 virtual float y_axis_max() const {return (fl 73 virtual float y_axis_max() const {return (float)m_data.upper_edge_y();} 74 74 75 virtual unsigned int points() const {return 75 virtual unsigned int points() const {return m_data.entries();} 76 virtual bool ith_point(unsigned int a_index, 76 virtual bool ith_point(unsigned int a_index,float& a_x,float& a_y) const { 77 if(a_index>=m_data.entries()) {a_x = 0;a_y 77 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;return false;} 78 if(a_index>=m_data.entries()) {a_x = 0;a_y 78 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;return false;} 79 a_x = (float)m_data.value_x(a_index); 79 a_x = (float)m_data.value_x(a_index); 80 a_y = (float)m_data.value_y(a_index); 80 a_y = (float)m_data.value_y(a_index); 81 return true; 81 return true; 82 } 82 } 83 public: 83 public: 84 c2d2plot(const histo::c2d& a_data) 84 c2d2plot(const histo::c2d& a_data) 85 :m_data(a_data) 85 :m_data(a_data) 86 { 86 { 87 #ifdef TOOLS_MEM 87 #ifdef TOOLS_MEM 88 mem::increment(s_class().c_str()); 88 mem::increment(s_class().c_str()); 89 #endif 89 #endif 90 } 90 } 91 virtual ~c2d2plot(){ 91 virtual ~c2d2plot(){ 92 #ifdef TOOLS_MEM 92 #ifdef TOOLS_MEM 93 mem::decrement(s_class().c_str()); 93 mem::decrement(s_class().c_str()); 94 #endif 94 #endif 95 } 95 } 96 public: 96 public: 97 c2d2plot(const c2d2plot& a_from) 97 c2d2plot(const c2d2plot& a_from) 98 :plottable(a_from) 98 :plottable(a_from) 99 ,points2D(a_from) 99 ,points2D(a_from) 100 ,m_data(a_from.m_data) 100 ,m_data(a_from.m_data) 101 ,m_name(a_from.m_name) 101 ,m_name(a_from.m_name) 102 ,m_legend(a_from.m_legend) 102 ,m_legend(a_from.m_legend) 103 { 103 { 104 #ifdef TOOLS_MEM 104 #ifdef TOOLS_MEM 105 mem::increment(s_class().c_str()); 105 mem::increment(s_class().c_str()); 106 #endif 106 #endif 107 } 107 } 108 c2d2plot& operator=(const c2d2plot& a_from){ 108 c2d2plot& operator=(const c2d2plot& a_from){ 109 m_name = a_from.m_name; 109 m_name = a_from.m_name; 110 m_legend = a_from.m_legend; 110 m_legend = a_from.m_legend; 111 return *this; 111 return *this; 112 } 112 } 113 protected: 113 protected: 114 const histo::c2d& m_data; 114 const histo::c2d& m_data; 115 std::string m_name; 115 std::string m_name; 116 std::string m_legend; 116 std::string m_legend; 117 }; 117 }; 118 118 119 }} 119 }} 120 120 121 #include "../histo/c3d" 121 #include "../histo/c3d" 122 122 123 namespace tools { 123 namespace tools { 124 namespace sg { 124 namespace sg { 125 125 126 class c3d2plot : public virtual points3D { 126 class c3d2plot : public virtual points3D { 127 TOOLS_SCLASS(tools::sg::c3d2plot) 127 TOOLS_SCLASS(tools::sg::c3d2plot) 128 public: //plottable 128 public: //plottable 129 virtual plottable* copy() const {return new 129 virtual plottable* copy() const {return new c3d2plot(*this);} 130 virtual bool is_valid() const {return true;} 130 virtual bool is_valid() const {return true;} 131 virtual const std::string& name() const {ret 131 virtual const std::string& name() const {return m_name;} 132 virtual void set_name(const std::string& a_s 132 virtual void set_name(const std::string& a_s) {m_name = a_s;} 133 virtual const std::string& title() const {re 133 virtual const std::string& title() const {return m_data.title();} 134 virtual const std::string& legend() const {r 134 virtual const std::string& legend() const {return m_legend;} 135 virtual void set_legend(const std::string& a 135 virtual void set_legend(const std::string& a_s) {m_legend = a_s;} 136 136 137 virtual void infos(const std::string& a_opts 137 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const { 138 a_sinfos.clear(); 138 a_sinfos.clear(); 139 std::string f_lf("\n"); 139 std::string f_lf("\n"); 140 std::vector<std::string> ws; 140 std::vector<std::string> ws; 141 words(a_opts," ",false,ws); 141 words(a_opts," ",false,ws); 142 std::vector<std::string>::const_iterator i 142 std::vector<std::string>::const_iterator it; 143 143 144 for(it=ws.begin();it!=ws.end();++it) { 144 for(it=ws.begin();it!=ws.end();++it) { 145 if(((*it)=="name") && m_name.size()) { 145 if(((*it)=="name") && m_name.size()) { 146 if(a_sinfos.size()) a_sinfos += f_lf; 146 if(a_sinfos.size()) a_sinfos += f_lf; 147 a_sinfos += "Name\n"; 147 a_sinfos += "Name\n"; 148 a_sinfos += m_name; 148 a_sinfos += m_name; 149 149 150 } else if((*it)=="entries") { 150 } else if((*it)=="entries") { 151 if(a_sinfos.size()) a_sinfos += f_lf; 151 if(a_sinfos.size()) a_sinfos += f_lf; 152 a_sinfos += "Entries\n"; 152 a_sinfos += "Entries\n"; 153 if(!numas<unsigned int>(m_data.entries 153 if(!numas<unsigned int>(m_data.entries(),a_sinfos)){} 154 154 155 } else if((*it)=="mean") { 155 } else if((*it)=="mean") { 156 if(a_sinfos.size()) a_sinfos += f_lf; 156 if(a_sinfos.size()) a_sinfos += f_lf; 157 a_sinfos += "MeanX\n"; 157 a_sinfos += "MeanX\n"; 158 if(!numas<double>(m_data.mean_x(),a_si 158 if(!numas<double>(m_data.mean_x(),a_sinfos)){} 159 a_sinfos += f_lf; 159 a_sinfos += f_lf; 160 a_sinfos += "MeanY\n"; 160 a_sinfos += "MeanY\n"; 161 if(!numas<double>(m_data.mean_y(),a_si 161 if(!numas<double>(m_data.mean_y(),a_sinfos)){} 162 a_sinfos += f_lf; 162 a_sinfos += f_lf; 163 a_sinfos += "MeanZ\n"; 163 a_sinfos += "MeanZ\n"; 164 if(!numas<double>(m_data.mean_z(),a_si 164 if(!numas<double>(m_data.mean_z(),a_sinfos)){} 165 165 166 } else if((*it)=="rms") { 166 } else if((*it)=="rms") { 167 if(a_sinfos.size()) a_sinfos += f_lf; 167 if(a_sinfos.size()) a_sinfos += f_lf; 168 a_sinfos += "RMS X\n"; 168 a_sinfos += "RMS X\n"; 169 if(!numas<double>(m_data.rms_x(),a_sin 169 if(!numas<double>(m_data.rms_x(),a_sinfos)){} 170 a_sinfos += f_lf; 170 a_sinfos += f_lf; 171 a_sinfos += "RMS Y\n"; 171 a_sinfos += "RMS Y\n"; 172 if(!numas<double>(m_data.rms_y(),a_sin 172 if(!numas<double>(m_data.rms_y(),a_sinfos)){} 173 a_sinfos += f_lf; 173 a_sinfos += f_lf; 174 a_sinfos += "RMS Z\n"; 174 a_sinfos += "RMS Z\n"; 175 if(!numas<double>(m_data.rms_z(),a_sin 175 if(!numas<double>(m_data.rms_z(),a_sinfos)){} 176 176 177 } 177 } 178 } 178 } 179 } 179 } 180 public: //points2D 180 public: //points2D 181 virtual float x_axis_min() const {return (fl 181 virtual float x_axis_min() const {return (float)m_data.lower_edge_x();} 182 virtual float x_axis_max() const {return (fl 182 virtual float x_axis_max() const {return (float)m_data.upper_edge_x();} 183 virtual float y_axis_min() const {return (fl 183 virtual float y_axis_min() const {return (float)m_data.lower_edge_y();} 184 virtual float y_axis_max() const {return (fl 184 virtual float y_axis_max() const {return (float)m_data.upper_edge_y();} 185 virtual float z_axis_min() const {return (fl 185 virtual float z_axis_min() const {return (float)m_data.lower_edge_z();} 186 virtual float z_axis_max() const {return (fl 186 virtual float z_axis_max() const {return (float)m_data.upper_edge_z();} 187 187 188 virtual unsigned int points() const {return 188 virtual unsigned int points() const {return m_data.entries();} 189 virtual bool ith_point(unsigned int a_index, 189 virtual bool ith_point(unsigned int a_index,float& a_x,float& a_y,float& a_z) const { 190 if(a_index>=m_data.entries()) {a_x = 0;a_y 190 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;a_z = 0;return false;} 191 if(a_index>=m_data.entries()) {a_x = 0;a_y 191 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;a_z = 0;return false;} 192 a_x = (float)m_data.value_x(a_index); 192 a_x = (float)m_data.value_x(a_index); 193 a_y = (float)m_data.value_y(a_index); 193 a_y = (float)m_data.value_y(a_index); 194 a_z = (float)m_data.value_z(a_index); 194 a_z = (float)m_data.value_z(a_index); 195 return true; 195 return true; 196 } 196 } 197 public: 197 public: 198 c3d2plot(const histo::c3d& a_data) 198 c3d2plot(const histo::c3d& a_data) 199 :m_data(a_data) 199 :m_data(a_data) 200 { 200 { 201 #ifdef TOOLS_MEM 201 #ifdef TOOLS_MEM 202 mem::increment(s_class().c_str()); 202 mem::increment(s_class().c_str()); 203 #endif 203 #endif 204 } 204 } 205 virtual ~c3d2plot(){ 205 virtual ~c3d2plot(){ 206 #ifdef TOOLS_MEM 206 #ifdef TOOLS_MEM 207 mem::decrement(s_class().c_str()); 207 mem::decrement(s_class().c_str()); 208 #endif 208 #endif 209 } 209 } 210 public: 210 public: 211 c3d2plot(const c3d2plot& a_from) 211 c3d2plot(const c3d2plot& a_from) 212 :plottable(a_from) 212 :plottable(a_from) 213 ,points3D(a_from) 213 ,points3D(a_from) 214 ,m_data(a_from.m_data) 214 ,m_data(a_from.m_data) 215 ,m_name(a_from.m_name) 215 ,m_name(a_from.m_name) 216 ,m_legend(a_from.m_legend) 216 ,m_legend(a_from.m_legend) 217 { 217 { 218 #ifdef TOOLS_MEM 218 #ifdef TOOLS_MEM 219 mem::increment(s_class().c_str()); 219 mem::increment(s_class().c_str()); 220 #endif 220 #endif 221 } 221 } 222 c3d2plot& operator=(const c3d2plot& a_from){ 222 c3d2plot& operator=(const c3d2plot& a_from){ 223 m_name = a_from.m_name; 223 m_name = a_from.m_name; 224 m_legend = a_from.m_legend; 224 m_legend = a_from.m_legend; 225 return *this; 225 return *this; 226 } 226 } 227 protected: 227 protected: 228 const histo::c3d& m_data; 228 const histo::c3d& m_data; 229 std::string m_name; 229 std::string m_name; 230 std::string m_legend; 230 std::string m_legend; 231 }; 231 }; 232 232 233 }} 233 }} 234 234 235 #endif 235 #endif