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