Warning, /include/Geant4/tools/sg/cloud2plot is written in an unsupported language. File is not indexed.
0001 // Copyright (C) 2010, Guy Barrand. All rights reserved.
0002 // See the file tools.license for terms.
0003
0004 #ifndef tools_sg_cloud2plot
0005 #define tools_sg_cloud2plot
0006
0007 #include "plottables"
0008
0009 #include "../tokenize"
0010 #include "../num2s"
0011
0012 #include "../histo/c2d"
0013
0014 namespace tools {
0015 namespace sg {
0016
0017 class c2d2plot : public virtual points2D {
0018 TOOLS_SCLASS(tools::sg::c2d2plot)
0019 public: //plottable
0020 virtual plottable* copy() const {return new c2d2plot(*this);}
0021 virtual bool is_valid() const {return true;}
0022 virtual const std::string& name() const {return m_name;}
0023 virtual void set_name(const std::string& a_s) {m_name = a_s;}
0024 virtual const std::string& title() const {return m_data.title();}
0025 virtual const std::string& legend() const {return m_legend;}
0026 virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0027
0028 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0029 a_sinfos.clear();
0030 std::string f_lf("\n");
0031 std::vector<std::string> ws;
0032 words(a_opts," ",false,ws);
0033 std::vector<std::string>::const_iterator it;
0034
0035 for(it=ws.begin();it!=ws.end();++it) {
0036 if(((*it)=="name") && m_name.size()) {
0037 if(a_sinfos.size()) a_sinfos += f_lf;
0038 a_sinfos += "Name\n";
0039 a_sinfos += m_name;
0040
0041 } else if((*it)=="entries") {
0042 if(a_sinfos.size()) a_sinfos += f_lf;
0043 a_sinfos += "Entries\n";
0044 if(!numas<unsigned int>(m_data.entries(),a_sinfos)){}
0045
0046 } else if((*it)=="mean") {
0047 if(a_sinfos.size()) a_sinfos += f_lf;
0048 a_sinfos += "MeanX\n";
0049 if(!numas<double>(m_data.mean_x(),a_sinfos)){}
0050 a_sinfos += f_lf;
0051 a_sinfos += "MeanY\n";
0052 if(!numas<double>(m_data.mean_y(),a_sinfos)){}
0053
0054 } else if((*it)=="rms") {
0055 if(a_sinfos.size()) a_sinfos += f_lf;
0056 a_sinfos += "RMS X\n";
0057 if(!numas<double>(m_data.rms_x(),a_sinfos)){}
0058 a_sinfos += f_lf;
0059 a_sinfos += "RMS Y\n";
0060 if(!numas<double>(m_data.rms_y(),a_sinfos)){}
0061
0062 }
0063 }
0064 }
0065 public: //points2D
0066 virtual float x_axis_min() const {return (float)m_data.lower_edge_x();}
0067 virtual float x_axis_max() const {return (float)m_data.upper_edge_x();}
0068 virtual float y_axis_min() const {return (float)m_data.lower_edge_y();}
0069 virtual float y_axis_max() const {return (float)m_data.upper_edge_y();}
0070
0071 virtual unsigned int points() const {return m_data.entries();}
0072 virtual bool ith_point(unsigned int a_index,float& a_x,float& a_y) const {
0073 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;return false;}
0074 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;return false;}
0075 a_x = (float)m_data.value_x(a_index);
0076 a_y = (float)m_data.value_y(a_index);
0077 return true;
0078 }
0079 public:
0080 c2d2plot(const histo::c2d& a_data)
0081 :m_data(a_data)
0082 {
0083 }
0084 virtual ~c2d2plot(){
0085 }
0086 public:
0087 c2d2plot(const c2d2plot& a_from)
0088 :plottable(a_from)
0089 ,points2D(a_from)
0090 ,m_data(a_from.m_data)
0091 ,m_name(a_from.m_name)
0092 ,m_legend(a_from.m_legend)
0093 {
0094 }
0095 c2d2plot& operator=(const c2d2plot& a_from){
0096 m_name = a_from.m_name;
0097 m_legend = a_from.m_legend;
0098 return *this;
0099 }
0100 protected:
0101 const histo::c2d& m_data;
0102 std::string m_name;
0103 std::string m_legend;
0104 };
0105
0106 }}
0107
0108 #include "../histo/c3d"
0109
0110 namespace tools {
0111 namespace sg {
0112
0113 class c3d2plot : public virtual points3D {
0114 TOOLS_SCLASS(tools::sg::c3d2plot)
0115 public: //plottable
0116 virtual plottable* copy() const {return new c3d2plot(*this);}
0117 virtual bool is_valid() const {return true;}
0118 virtual const std::string& name() const {return m_name;}
0119 virtual void set_name(const std::string& a_s) {m_name = a_s;}
0120 virtual const std::string& title() const {return m_data.title();}
0121 virtual const std::string& legend() const {return m_legend;}
0122 virtual void set_legend(const std::string& a_s) {m_legend = a_s;}
0123
0124 virtual void infos(const std::string& a_opts,std::string& a_sinfos) const {
0125 a_sinfos.clear();
0126 std::string f_lf("\n");
0127 std::vector<std::string> ws;
0128 words(a_opts," ",false,ws);
0129 std::vector<std::string>::const_iterator it;
0130
0131 for(it=ws.begin();it!=ws.end();++it) {
0132 if(((*it)=="name") && m_name.size()) {
0133 if(a_sinfos.size()) a_sinfos += f_lf;
0134 a_sinfos += "Name\n";
0135 a_sinfos += m_name;
0136
0137 } else if((*it)=="entries") {
0138 if(a_sinfos.size()) a_sinfos += f_lf;
0139 a_sinfos += "Entries\n";
0140 if(!numas<unsigned int>(m_data.entries(),a_sinfos)){}
0141
0142 } else if((*it)=="mean") {
0143 if(a_sinfos.size()) a_sinfos += f_lf;
0144 a_sinfos += "MeanX\n";
0145 if(!numas<double>(m_data.mean_x(),a_sinfos)){}
0146 a_sinfos += f_lf;
0147 a_sinfos += "MeanY\n";
0148 if(!numas<double>(m_data.mean_y(),a_sinfos)){}
0149 a_sinfos += f_lf;
0150 a_sinfos += "MeanZ\n";
0151 if(!numas<double>(m_data.mean_z(),a_sinfos)){}
0152
0153 } else if((*it)=="rms") {
0154 if(a_sinfos.size()) a_sinfos += f_lf;
0155 a_sinfos += "RMS X\n";
0156 if(!numas<double>(m_data.rms_x(),a_sinfos)){}
0157 a_sinfos += f_lf;
0158 a_sinfos += "RMS Y\n";
0159 if(!numas<double>(m_data.rms_y(),a_sinfos)){}
0160 a_sinfos += f_lf;
0161 a_sinfos += "RMS Z\n";
0162 if(!numas<double>(m_data.rms_z(),a_sinfos)){}
0163
0164 }
0165 }
0166 }
0167 public: //points2D
0168 virtual float x_axis_min() const {return (float)m_data.lower_edge_x();}
0169 virtual float x_axis_max() const {return (float)m_data.upper_edge_x();}
0170 virtual float y_axis_min() const {return (float)m_data.lower_edge_y();}
0171 virtual float y_axis_max() const {return (float)m_data.upper_edge_y();}
0172 virtual float z_axis_min() const {return (float)m_data.lower_edge_z();}
0173 virtual float z_axis_max() const {return (float)m_data.upper_edge_z();}
0174
0175 virtual unsigned int points() const {return m_data.entries();}
0176 virtual bool ith_point(unsigned int a_index,float& a_x,float& a_y,float& a_z) const {
0177 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;a_z = 0;return false;}
0178 if(a_index>=m_data.entries()) {a_x = 0;a_y = 0;a_z = 0;return false;}
0179 a_x = (float)m_data.value_x(a_index);
0180 a_y = (float)m_data.value_y(a_index);
0181 a_z = (float)m_data.value_z(a_index);
0182 return true;
0183 }
0184 public:
0185 c3d2plot(const histo::c3d& a_data)
0186 :m_data(a_data)
0187 {
0188 }
0189 virtual ~c3d2plot(){
0190 }
0191 public:
0192 c3d2plot(const c3d2plot& a_from)
0193 :plottable(a_from)
0194 ,points3D(a_from)
0195 ,m_data(a_from.m_data)
0196 ,m_name(a_from.m_name)
0197 ,m_legend(a_from.m_legend)
0198 {
0199 }
0200 c3d2plot& operator=(const c3d2plot& a_from){
0201 m_name = a_from.m_name;
0202 m_legend = a_from.m_legend;
0203 return *this;
0204 }
0205 protected:
0206 const histo::c3d& m_data;
0207 std::string m_name;
0208 std::string m_legend;
0209 };
0210
0211 }}
0212
0213 #endif