YODA is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.3.1
Scatter3D.h
Go to the documentation of this file.
1 // -*- C++ -*-
2 //
3 // This file is part of YODA -- Yet more Objects for Data Analysis
4 // Copyright (C) 2008-2015 The YODA collaboration (see AUTHORS for details)
5 //
6 #ifndef YODA_SCATTER3D_H
7 #define YODA_SCATTER3D_H
8 
9 #include "YODA/AnalysisObject.h"
10 #include "YODA/Point3D.h"
12 #include <utility>
13 
14 namespace YODA {
15 
16 
17  // Forward declarations
18  class Histo2D;
19  class Profile2D;
20 
21 
23  class Scatter3D : public AnalysisObject {
24  public:
25 
27  typedef Point3D Point;
28  typedef Utils::sortedvector<Point3D> Points;
29 
30 
32 
33 
35  Scatter3D(const std::string& path="", const std::string& title="")
36  : AnalysisObject("Scatter3D", path, title)
37  { }
38 
39 
42  const std::string& path="", const std::string& title="")
43  : AnalysisObject("Scatter3D", path, title),
44  _points(points)
45  {
46  std::sort(_points.begin(), _points.end());
47  }
48 
49 
51  Scatter3D(const std::vector<double>& x,
52  const std::vector<double>& y,
53  const std::vector<double>& z,
54  const std::string& path="",
55  const std::string& title="")
56  : AnalysisObject("Scatter3D", path, title)
57  {
58  if (x.size() != y.size() || y.size() != z.size()) {
59  throw RangeError("There are different numbers of x, y, and z values in the provided vectors.");
60  }
61  const std::pair<double,double> nullerr = std::make_pair(0.0, 0.0);
62  for (size_t i = 0; i < x.size(); ++i) {
63  addPoint(Point3D(x[i], y[i], z[i], nullerr, nullerr, nullerr));
64  }
65  std::sort(_points.begin(), _points.end());
66  }
67 
68 
70  Scatter3D(const std::vector<double>& x, const std::vector<double>& y, const std::vector<double>& z,
71  const std::vector<std::pair<double,double> >& ex, const std::vector<std::pair<double,double> >& ey, const std::vector<std::pair<double,double> >& ez,
72  const std::string& path="", const std::string& title="")
73  : AnalysisObject("Scatter3D", path, title)
74  {
75  if (x.size() != y.size() || y.size() != z.size()) {
76  throw RangeError("There are different numbers of x, y, and z values in the provided vectors.");
77  }
78  if (x.size() != ex.size() || y.size() != ey.size() || z.size() != ez.size()) {
79  throw RangeError("The sizes of the provided error vectors don't match the corresponding x, y, or z value vectors.");
80  }
81  for (size_t i = 0; i < x.size(); ++i) {
82  addPoint(Point3D(x[i], y[i], z[i], ex[i], ey[i], ez[i]));
83  }
84  std::sort(_points.begin(), _points.end());
85  }
86 
87 
89  Scatter3D(const std::vector<double>& x, const std::vector<double>& y, const std::vector<double> z,
90  const std::vector<double>& exminus,
91  const std::vector<double>& explus,
92  const std::vector<double>& eyminus,
93  const std::vector<double>& eyplus,
94  const std::vector<double>& ezminus,
95  const std::vector<double>& ezplus,
96  const std::string& path="", const std::string& title="")
97  : AnalysisObject("Scatter3D", path, title)
98  {
99  if(x.size() != y.size() || y.size() != z.size() ||
100  x.size() != exminus.size() || x.size() != explus.size() ||
101  y.size() != eyminus.size() || y.size() != eyplus.size() ||
102  z.size() != ezminus.size() || z.size() != ezplus.size())
103  throw RangeError("There are either different amounts of points on x/y/z vectors or not every of these vectors has properly defined error vectors!");
104 
105  for (size_t i = 0; i < x.size(); ++i) {
106  addPoint(Point3D(x[i], y[i], z[i], exminus[i], explus[i], eyminus[i], eyplus[i], ezminus[i], ezplus[i]));
107  }
108 
109  std::sort(_points.begin(), _points.end());
110  }
111 
112 
115  Scatter3D(const Scatter3D& s3, const std::string& path="")
116  : AnalysisObject("Scatter3D", (path.size() == 0) ? s3.path() : path, s3, s3.title()),
117  _points(s3._points)
118  { }
119 
122  AnalysisObject::operator = (s3); //< AO treatment of paths etc.
123  _points = s3._points;
124  return *this;
125  }
126 
128  Scatter3D clone() const {
129  return Scatter3D(*this);
130  }
131 
133  Scatter3D* newclone() const {
134  return new Scatter3D(*this);
135  }
136 
138 
139 
141 
142 
144  void reset() {
145  _points.clear();
146  }
147 
149  void scaleX(double scalex) {
150  BOOST_FOREACH (Point3D& p, _points) p.scaleX(scalex);
151  }
152 
154  void scaleY(double scaley) {
155  BOOST_FOREACH (Point3D& p, _points) p.scaleY(scaley);
156  }
157 
159  void scaleZ(double scalez) {
160  BOOST_FOREACH (Point3D& p, _points) p.scaleZ(scalez);
161  }
162 
164  void scaleXYZ(double scalex, double scaley, double scalez) {
165  BOOST_FOREACH (Point3D& p, _points) p.scaleXYZ(scalex, scaley, scalez);
166  }
167 
170  void scale(double scalex, double scaley, double scalez) {
171  scaleXYZ(scalex, scaley, scalez);
172  }
173 
175 
176 
178 
179 
181  size_t numPoints() const {
182  return _points.size();
183  }
184 
185 
188  return _points;
189  }
190 
191 
193  const Points& points() const {
194  return _points;
195  }
196 
197 
199  Point3D& point(size_t index) {
200  if (index >= numPoints()) throw RangeError("There is no point with this index");
201  return _points.at(index);
202  }
203 
204 
206  const Point3D& point(size_t index) const {
207  if (index >= numPoints()) throw RangeError("There is no point with such index!");
208  return _points.at(index);
209  }
210 
212 
213 
215 
216 
218  void addPoint(const Point3D& pt) {
219  _points.insert(pt);
220  }
221 
223  void addPoint(double x, double y, double z) {
224  _points.insert(Point3D(x, y, z));
225  }
226 
228  void addPoint(double x, double y, double z,
229  double ex, double ey, double ez) {
230  _points.insert(Point3D(x, y, z, ex, ey, ez));
231  }
232 
234  void addPoint(double x, double y, double z,
235  const std::pair<double,double>& ex, const std::pair<double,double>& ey, const std::pair<double,double>& ez) {
236  _points.insert(Point3D(x, y, z, ex, ey, ez));
237  }
238 
240  void addPoint(double x, double y, double z,
241  double exminus, double explus,
242  double eyminus, double eyplus,
243  double ezminus, double ezplus) {
244  _points.insert(Point3D(x, y, z, exminus, explus, eyminus, eyplus, ezminus, ezplus));
245  }
246 
248  void addPoints(const Points& pts) {
249  BOOST_FOREACH (const Point3D& pt, pts) addPoint(pt);
250  }
251 
253 
254 
256  void combineWith(const Scatter3D& other) {
257  addPoints(other.points());
258  //return *this;
259  }
260 
261 
264  void combineWith(const std::vector<Scatter3D>& others) {
265  BOOST_FOREACH (const Scatter3D& s, others) combineWith(s);
266  //return *this;
267  }
268 
269 
271  bool operator == (const Scatter3D& other) {
272  return _points == other._points;
273  }
274 
276  bool operator != (const Scatter3D& other) {
277  return ! operator == (other);
278  }
279 
280 
281  private:
282 
283  Points _points;
284 
285  };
286 
287 
288 
290 
291 
292  inline Scatter3D combine(const Scatter3D& a, const Scatter3D& b) {
293  Scatter3D rtn = a;
294  rtn.combineWith(b);
295  return rtn;
296  }
297 
298  inline Scatter3D combine(const std::vector<Scatter3D>& scatters) {
299  Scatter3D rtn;
300  rtn.combineWith(scatters);
301  return rtn;
302  }
303 
305 
306 
308 
309 
311 
312 
314  Scatter3D mkScatter(const Histo2D& h, bool usefocus=false);
315 
317  Scatter3D mkScatter(const Profile2D& p, bool usefocus=false);
318 
321  inline Scatter3D mkScatter(const Scatter3D& s) { return Scatter3D(s); }
322  // /// @note The usefocus arg is just for consistency and has no effect for Scatter -> Scatter
323  //inline Scatter3D mkScatter(const Scatter3D& s, bool) { return mkScatter(s); }
324 
326 
327 
329 
330 
333 
334 
336  Scatter3D add(const Scatter3D& first, const Scatter3D& second);
337 
338 
340  inline Scatter3D operator + (const Scatter3D& first, const Scatter3D& second) {
341  return add(first, second);
342  }
343 
344 
346  Scatter3D subtract(const Scatter3D& first, const Scatter3D& second);
347 
348 
350  inline Scatter3D operator - (const Scatter3D& first, const Scatter3D& second) {
351  return subtract(first, second);
352  }
353 
354 
356  Scatter3D divide(const Scatter3D& numer, const Scatter3D& denom);
357 
358 
360  inline Scatter3D operator / (const Scatter3D& numer, const Scatter3D& denom) {
361  return divide(numer, denom);
362  }
363 
365 
366 
368 
369 
373  template<typename FNX>
374  inline void transformX(Scatter3D& s, FNX fx) {
375  for (size_t i = 0; i < s.numPoints(); ++i) {
376  Point3D& p = s.point(i);
377  const double newx = fx(p.x());
378  const double fx_xmin = fx(p.xMin());
379  const double fx_xmax = fx(p.xMax());
380  // Deal with possible inversions of min/max ordering under the transformation
381  const double newxmin = std::min(fx_xmin, fx_xmax);
382  const double newxmax = std::max(fx_xmin, fx_xmax);
383  // Set new point x values
384  p.setX(newx);
386  p.setXErrMinus(newx - newxmin);
387  p.setXErrPlus(newxmax - newx);
388  }
389  }
390 
391 
395  template<typename FNY>
396  inline void transformY(Scatter3D& s, FNY fy) {
397  for (size_t i = 0; i < s.numPoints(); ++i) {
398  Point3D& p = s.point(i);
399  const double newy = fy(p.y());
400  const double fy_ymin = fy(p.yMin());
401  const double fy_ymax = fy(p.yMax());
402  // Deal with possible inversions of min/max ordering under the transformation
403  const double newymin = std::min(fy_ymin, fy_ymax);
404  const double newymax = std::max(fy_ymin, fy_ymax);
405  // Set new point y values
406  p.setY(newy);
408  p.setYErrMinus(newy - newymin);
409  p.setYErrPlus(newymax - newy);
410  }
411  }
412 
413 
417  template<typename FNZ>
418  inline void transformZ(Scatter3D& s, FNZ fz) {
419  for (size_t i = 0; i < s.numPoints(); ++i) {
420  Point3D& p = s.point(i);
421  const double newz = fz(p.z());
422  const double fz_zmin = fz(p.zMin());
423  const double fz_zmax = fz(p.zMax());
424  // Deal with possible inversions of min/max ordering under the transformation
425  const double newzmin = std::min(fz_zmin, fz_zmax);
426  const double newzmax = std::max(fz_zmin, fz_zmax);
427  // Set new point z values
428  p.setZ(newz);
430  p.setZErrMinus(newz - newzmin);
431  p.setZErrPlus(newzmax - newz);
432  }
433  }
434 
435 
437 
439 
440 
441 }
442 
443 #endif
bool operator==(const Scatter3D &other)
Equality operator.
Definition: Scatter3D.h:271
Utils::sortedvector< Point3D > Points
Definition: Scatter3D.h:28
const Point3D & point(size_t index) const
Get the point with index index (const version)
Definition: Scatter3D.h:206
Scatter3D & operator=(const Scatter3D &s3)
Assignment operator.
Definition: Scatter3D.h:121
Scatter1D combine(const Scatter1D &a, const Scatter1D &b)
Definition: Scatter1D.h:248
void scaleY(double scaley)
Scaling of y axis.
Definition: Point3D.h:385
Scatter1D divide(const Counter &numer, const Counter &denom)
Definition: Counter.cc:24
void setYErrMinus(double eyminus)
Set negative y error.
Definition: Point3D.h:211
void reset()
Clear all points.
Definition: Scatter3D.h:144
void setZErrPlus(double ezplus)
Set positive z error.
Definition: Point3D.h:279
size_t numPoints() const
Number of points in the scatter.
Definition: Scatter3D.h:181
void combineWith(const std::vector< Scatter3D > &others)
Definition: Scatter3D.h:264
void scale(double scalex, double scaley, double scalez)
Definition: Scatter3D.h:170
double zMax() const
Get value plus positive z-error.
Definition: Point3D.h:306
Axis1D< BIN1D, DBN > operator-(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Subtract the statistics on two axis.
Definition: Axis1D.h:494
double x() const
Get x value.
Definition: Point3D.h:93
Error for e.g. use of invalid bin ranges.
Definition: Exceptions.h:34
Scatter3D * newclone() const
Make a copy on the heap, via 'new'.
Definition: Scatter3D.h:133
Scatter3D(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::vector< std::pair< double, double > > &ex, const std::vector< std::pair< double, double > > &ey, const std::vector< std::pair< double, double > > &ez, const std::string &path="", const std::string &title="")
Constructor from vectors of values with asymmetric errors on both x and y.
Definition: Scatter3D.h:70
Scatter3D clone() const
Make a copy on the stack.
Definition: Scatter3D.h:128
void scaleZ(double scalez)
Scaling of z axis.
Definition: Point3D.h:391
Counter add(const Counter &first, const Counter &second)
Add two counters.
Definition: Counter.h:205
void transformZ(Scatter3D &s, FNZ fz)
Apply transformation fz(z) to all values and error positions (operates in-place on s) ...
Definition: Scatter3D.h:418
void addPoint(double x, double y, double z, const std::pair< double, double > &ex, const std::pair< double, double > &ey, const std::pair< double, double > &ez)
Insert a new point, defined as the x/y/z value triplet and asymmetric error pairs.
Definition: Scatter3D.h:234
Point3D & point(size_t index)
Get a reference to the point with index index.
Definition: Scatter3D.h:199
double y() const
Get y value.
Definition: Point3D.h:99
const Points & points() const
Get the collection of points (const)
Definition: Scatter3D.h:193
A 3D data point to be contained in a Scatter3D.
Definition: Point3D.h:17
void scaleY(double scaley)
Scaling of y axis.
Definition: Scatter3D.h:154
void setXErrPlus(double explus)
Set positive x error.
Definition: Point3D.h:153
double z() const
Get z value.
Definition: Point3D.h:105
Scatter3D(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &z, const std::string &path="", const std::string &title="")
Constructor from vectors of values with no errors.
Definition: Scatter3D.h:51
void addPoints(const Points &pts)
Insert a collection of new points.
Definition: Scatter3D.h:248
void combineWith(const Scatter3D &other)
Definition: Scatter3D.h:256
Axis1D< BIN1D, DBN > operator+(const Axis1D< BIN1D, DBN > &first, const Axis1D< BIN1D, DBN > &second)
Add the statistics on two axes.
Definition: Axis1D.h:486
Scatter3D(const Points &points, const std::string &path="", const std::string &title="")
Constructor from a set of points.
Definition: Scatter3D.h:41
Scatter3D(const std::string &path="", const std::string &title="")
Empty constructor.
Definition: Scatter3D.h:35
Scatter3D(const Scatter3D &s3, const std::string &path="")
Definition: Scatter3D.h:115
Counter subtract(const Counter &first, const Counter &second)
Subtract two counters.
Definition: Counter.h:219
void setZErrMinus(double ezminus)
Set negative z error.
Definition: Point3D.h:274
Scatter1D mkScatter(const Counter &c)
Make a Scatter1D representation of a Histo1D.
Definition: Scatter1D.cc:8
double yMax() const
Get value plus positive y-error.
Definition: Point3D.h:243
void scaleX(double scalex)
Scaling of x axis.
Definition: Scatter3D.h:149
void setYErrPlus(double eyplus)
Set positive y error.
Definition: Point3D.h:216
void scaleXYZ(double scalex, double scaley, double scalez)
Scaling of all three axes.
Definition: Scatter3D.h:164
A very generic data type which is just a collection of 3D data points with errors.
Definition: Scatter3D.h:23
AnalysisObject is the base class for histograms and scatters.
const std::string path() const
Scatter1D operator/(const Counter &numer, const Counter &denom)
Definition: Counter.h:239
double zMin() const
Get value minus negative z-error.
Definition: Point3D.h:301
void scaleXYZ(double scalex, double scaley, double scalez)
Scaling of all three axes.
Definition: Point3D.h:397
void setX(double x)
Set x value.
Definition: Point3D.h:96
Points & points()
Get the collection of points (non-const)
Definition: Scatter3D.h:187
Point3D Point
Types of the native Point3D collection.
Definition: Scatter3D.h:27
double yMin() const
Get value minus negative y-error.
Definition: Point3D.h:238
const std::string title() const
void transformX(Scatter1D &s, FNX fx)
Apply transformation fx(x) to all values and error positions (operates in-place on s) ...
Definition: Scatter1D.h:327
void setY(double y)
Set y value.
Definition: Point3D.h:102
bool operator!=(const Scatter3D &other)
Non-equality operator.
Definition: Scatter3D.h:276
void setXErrMinus(double exminus)
Set negative x error.
Definition: Point3D.h:148
void setZ(double z)
Set z value.
Definition: Point3D.h:108
Scatter3D(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > z, const std::vector< double > &exminus, const std::vector< double > &explus, const std::vector< double > &eyminus, const std::vector< double > &eyplus, const std::vector< double > &ezminus, const std::vector< double > &ezplus, const std::string &path="", const std::string &title="")
Constructor from vectors of values with completely explicit asymmetric errors.
Definition: Scatter3D.h:89
double xMin() const
Get value minus negative x-error.
Definition: Point3D.h:175
void addPoint(const Point3D &pt)
Insert a new point.
Definition: Scatter3D.h:218
void addPoint(double x, double y, double z, double exminus, double explus, double eyminus, double eyplus, double ezminus, double ezplus)
Insert a new point, defined as the x/y/z value triplet and asymmetric errors.
Definition: Scatter3D.h:240
void scaleZ(double scalez)
Scaling of z axis.
Definition: Scatter3D.h:159
double xMax() const
Get value plus positive x-error.
Definition: Point3D.h:180
void scaleX(double scalex)
Scaling of x axis.
Definition: Point3D.h:379
void addPoint(double x, double y, double z, double ex, double ey, double ez)
Insert a new point, defined as the x/y/z value triplet and symmetric errors.
Definition: Scatter3D.h:228
virtual AnalysisObject & operator=(const AnalysisObject &ao)
Default copy assignment operator.
void transformY(Scatter2D &s, FNY fy)
Apply transformation fy(y) to all values and error positions (operates in-place on s) ...
Definition: Scatter2D.h:384
void addPoint(double x, double y, double z)
Insert a new point, defined as the x/y/z value triplet and no errors.
Definition: Scatter3D.h:223