11 #ifndef __EstimatePlotter_h
12 #define __EstimatePlotter_h
22 class EstimatePlotter {
27 static bool report_mean;
29 bool report_mean_on_single_line;
38 void set_control_viewport (
bool flag);
41 void set_border (
float fraction_x,
float fraction_y);
44 void set_xrange (
float x_min,
float x_max);
47 void set_minimum_error (
float error);
50 void set_maximum_error (
float error);
53 void set_graph_marker (
int symbol);
56 void separate_viewports (
bool scaled =
true,
bool vertical =
true);
59 void set_viewport (
unsigned index);
62 void set_world (
float x1,
float x2,
float y1,
float y2);
65 float get_x_min ()
const {
return x_min; }
67 float get_x_max ()
const {
return x_max; }
70 float get_y_min ()
const {
return y_min; }
72 float get_y_max ()
const {
return y_max; }
75 void restore_viewport ();
78 template<
class T>
void add_plot (
const std::vector<
Estimate<T> >& data);
80 template<
class Xt,
class Yt>
81 void add_plot (
const std::vector<Xt>&,
const std::vector<
Estimate<Yt> >&);
83 template<
class Xt,
class Yt>
84 void add_plot (
const std::vector<Xt>& xdata,
85 const std::vector< std::complex<
Estimate<Yt> > >& ydata);
88 template<
class T>
void plot (
const std::vector<
Estimate<T> >& data);
91 unsigned plot (
unsigned index);
93 unsigned excise (
unsigned index);
99 void set_minmax_range (
unsigned i_min,
unsigned i_max);
101 void minmax (
bool& xrange_set,
float& xmin,
float& xmax,
102 bool& yrange_set,
float& ymin,
float& ymax,
103 const std::vector<float>& x,
104 const std::vector<float>& y,
105 const std::vector<float>& yerr);
107 void set_plot_error_bars (
bool flag)
108 { plot_error_bars = flag; }
113 bool control_viewport;
116 float x_border, y_border;
119 float xrange_min, xrange_max;
128 unsigned i_min, i_max;
144 bool plot_error_bars;
147 float log_err_madm_threshold;
148 bool log_err_madm_applied;
150 std::vector< std::vector<float> > xval;
151 std::vector< std::vector<float> > yval;
152 std::vector< std::vector<float> > yerr;
156 std::vector<float> data_xmin;
157 std::vector<float> data_xmax;
158 std::vector<float> data_ymin;
159 std::vector<float> data_ymax;
161 float vp_x1, vp_x2, vp_y1, vp_y2;
164 bool viewports_vertical;
165 bool viewports_scaled;
170 void EstimatePlotter::plot (
const std::vector<
Estimate<T> >& data)
178 void EstimatePlotter::add_plot (
const std::vector<
Estimate<T> >& data)
180 unsigned ipt = 0, npt = data.size();
184 log_err_madm_applied =
false;
186 xval.push_back ( std::vector<float>(npt) );
187 yval.push_back ( std::vector<float>(npt) );
188 yerr.push_back ( std::vector<float>(npt) );
190 std::vector<float>& x = xval.back();
191 std::vector<float>& y = yval.back();
192 std::vector<float>& ye = yerr.back();
196 xscale = double(xrange_max - xrange_min) / double(npt-1);
200 for (ipt=0; ipt<npt; ipt++)
202 x[ipt] = xrange_min + xscale * double(ipt);
204 if (!myfinite( data[ipt].val ))
208 y[ipt] = data[ipt].val;
209 ye[ipt] =
sqrt (data[ipt].var);
220 std::cerr <<
"Mean = " << mean << std::endl;
222 else if (report_mean_on_single_line)
224 std::cout << mean.get_Estimate().get_value() <<
" ";
225 std::cout << mean.get_Estimate().get_error() <<
" ";
228 minmax (xrange_set, x_min, x_max, yrange_set, y_min, y_max, x, y, ye);
231 template<
class Xt,
class Yt>
232 void EstimatePlotter::add_plot (
const std::vector<Xt>& xdata,
235 unsigned ipt = 0, npt = xdata.size();
239 if (ydata.size() != npt)
240 throw Error (InvalidParam,
"EstimatePlotter::add_plot (Xt, Yt)",
241 "xdata.size=%d != ydata.size=%d", npt, ydata.size());
243 log_err_madm_applied =
false;
245 xval.push_back ( std::vector<float>(npt) );
246 yval.push_back ( std::vector<float>(npt) );
247 yerr.push_back ( std::vector<float>(npt) );
249 std::vector<float>& x = xval.back();
250 std::vector<float>& y = yval.back();
251 std::vector<float>& ye = yerr.back();
253 for (ipt=0; ipt<npt; ipt++) {
254 ye[ipt] =
sqrt (ydata[ipt].var);
256 y[ipt] = ydata[ipt].val;
259 minmax (xrange_set, x_min, x_max, yrange_set, y_min, y_max, x, y, ye);
262 template<
class Xt,
class Yt>
263 void EstimatePlotter::add_plot
264 (
const std::vector<Xt>& xdata,
265 const std::vector< std::complex<
Estimate<Yt> > >& ydata)
267 unsigned ipt = 0, npt = xdata.size();
271 if (ydata.size() != npt)
272 throw Error (InvalidParam,
"EstimatePlotter::add_plot (Xt, Yt)",
273 "xdata.size=%d != ydata.size=%d", npt, ydata.size());
275 log_err_madm_applied =
false;
277 xval.push_back ( std::vector<float>(npt) );
278 std::vector<float>& x = xval.back();
280 std::vector<float> re_y (npt);
281 std::vector<float> re_ye (npt);
283 std::vector<float> im_y (npt);
284 std::vector<float> im_ye (npt);
286 for (ipt=0; ipt<npt; ipt++)
290 re_y[ipt] = ydata[ipt].real().val;
291 re_ye[ipt] =
sqrt (ydata[ipt].real().var);
293 im_y[ipt] = ydata[ipt].imag().val;
294 im_ye[ipt] =
sqrt (ydata[ipt].imag().var);
297 minmax (xrange_set, x_min, x_max, yrange_set, y_min, y_max, x, re_y, re_ye);
298 minmax (xrange_set, x_min, x_max, yrange_set, y_min, y_max, x, im_y, im_ye);
300 yval.push_back ( re_y );
301 yval.push_back ( im_y );
303 yerr.push_back ( re_ye );
304 yerr.push_back ( im_ye );