YODA is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.3.1
Point3D.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_POINT3D_H
7 #define YODA_POINT3D_H
8 
9 #include "YODA/Exceptions.h"
10 #include "YODA/Utils/MathUtils.h"
11 #include <utility>
12 
13 namespace YODA {
14 
15 
17  class Point3D {
18  public:
19 
20  typedef std::pair<double,double> ValuePair;
21 
22 
24 
25 
26  // Default constructor
27  Point3D() { }
28 
29 
31  Point3D(double x, double y, double z, double ex=0.0, double ey=0.0, double ez=0.0)
32  : _x(x), _y(y), _z(z)
33  {
34  _ex = std::make_pair(ex, ex);
35  _ey = std::make_pair(ey, ey);
36  _ez = std::make_pair(ez, ez);
37  }
38 
39 
41  Point3D(double x, double y, double z,
42  double exminus,
43  double explus,
44  double eyminus,
45  double eyplus,
46  double ezminus,
47  double ezplus)
48  : _x(x), _y(y), _z(z)
49  {
50  _ex = std::make_pair(exminus, explus);
51  _ey = std::make_pair(eyminus, eyplus);
52  _ez = std::make_pair(ezminus, ezplus);
53  }
54 
56  Point3D(double x, double y, double z,
57  const std::pair<double,double>& ex,
58  const std::pair<double,double>& ey,
59  const std::pair<double,double>& ez)
60  : _x(x), _y(y), _z(z),
61  _ex(ex), _ey(ey), _ez(ez)
62  { }
63 
64 
66  Point3D(const Point3D& p)
67  : _x(p._x), _y(p._y), _z(p._z),
68  _ex(p._ex), _ey(p._ey), _ez(p._ez)
69  { }
70 
71 
74  _x = p._x;
75  _y = p._y;
76  _z = p._z;
77  _ex = p._ex;
78  _ey = p._ey;
79  _ez = p._ez;
80  return *this;
81  }
82 
83 
85 
86 
87  public:
88 
90 
91 
93  double x() const { return _x; }
94 
96  void setX(double x) { _x = x; }
97 
99  double y() const { return _y; }
100 
102  void setY(double y) { _y = y; }
103 
105  double z() const { return _z;}
106 
108  void setZ(double z) { _z = z;}
109 
111 
112  // /// Get x,y,z value tuple
113  // triple<double,double,double> xyz() const { return std::triple(_x, _y, _z); }
114 
116  void setXYZ(double x, double y, double z) { setX(x); setY(y); setZ(z); }
117 
118  // /// Set x and y values
119  // void setXY(triple<double,double,double> xyz) { setX(xy.first); setY(xy.second); setZ(xy.third); }
120 
122 
123 
125 
126 
128  const std::pair<double,double>& xErrs() const {
129  return _ex;
130  }
131 
133  double xErrMinus() const {
134  return _ex.first;
135  }
136 
138  double xErrPlus() const {
139  return _ex.second;
140  }
141 
143  double xErrAvg() const {
144  return (_ex.first + _ex.second)/2.0;
145  }
146 
148  void setXErrMinus(double exminus) {
149  _ex.first = exminus;
150  }
151 
153  void setXErrPlus(double explus) {
154  _ex.second = explus;
155  }
156 
158  void setXErr(double ex) {
159  setXErrMinus(ex);
160  setXErrPlus(ex);
161  }
162 
164  void setXErr(double exminus, double explus) {
165  setXErrMinus(exminus);
166  setXErrPlus(explus);
167  }
168 
170  void setXErr(std::pair<double,double> ex) {
171  _ex = ex;
172  }
173 
175  double xMin() const {
176  return _x - _ex.first;
177  }
178 
180  double xMax() const {
181  return _x + _ex.second;
182  }
183 
185 
186 
188 
189 
191  const std::pair<double,double>& yErrs() const {
192  return _ey;
193  }
194 
196  double yErrMinus() const {
197  return _ey.first;
198  }
199 
201  double yErrPlus() const {
202  return _ey.second;
203  }
204 
206  double yErrAvg() const {
207  return (_ey.first + _ey.second)/2.0;
208  }
209 
211  void setYErrMinus(double eyminus) {
212  _ey.first = eyminus;
213  }
214 
216  void setYErrPlus(double eyplus) {
217  _ey.second = eyplus;
218  }
219 
221  void setYErr(double ey) {
222  setYErrMinus(ey);
223  setYErrPlus(ey);
224  }
225 
227  void setYErr(double eyminus, double eyplus) {
228  setYErrMinus(eyminus);
229  setYErrPlus(eyplus);
230  }
231 
233  void setYErr(std::pair<double,double> ey) {
234  _ey = ey;
235  }
236 
238  double yMin() const {
239  return _y - _ey.first;
240  }
241 
243  double yMax() const {
244  return _y + _ey.second;
245  }
246 
248 
249 
251 
252 
254  const std::pair<double,double>& zErrs() const {
255  return _ez;
256  }
257 
259  double zErrMinus() const {
260  return _ez.first;
261  }
262 
264  double zErrPlus() const {
265  return _ez.second;
266  }
267 
269  double zErrAvg() const {
270  return (_ez.first + _ez.second)/2.0;
271  }
272 
274  void setZErrMinus(double ezminus) {
275  _ez.first = ezminus;
276  }
277 
279  void setZErrPlus(double ezplus) {
280  _ez.second = ezplus;
281  }
282 
284  void setZErr(double ez) {
285  setZErrMinus(ez);
286  setZErrPlus(ez);
287  }
288 
290  void setZErr(double ezminus, double ezplus) {
291  setZErrMinus(ezminus);
292  setZErrPlus(ezplus);
293  }
294 
296  void setZErr(std::pair<double,double> ez) {
297  _ez = ez;
298  }
299 
301  double zMin() const {
302  return _z - _ez.first;
303  }
304 
306  double zMax() const {
307  return _z + _ez.second;
308  }
309 
311 
312 
314 
315 
317  void setX(double x, double ex) {
318  setX(x);
319  setXErr(ex);
320  }
321 
323  void setX(double x, double exminus, double explus) {
324  setX(x);
325  setXErr(exminus, explus);
326  }
327 
329  void setX(double x, std::pair<double,double> ex) {
330  setX(x);
331  setXErr(ex);
332  }
333 
334 
336  void setY(double y, double ey) {
337  setY(y);
338  setYErr(ey);
339  }
340 
342  void setY(double y, double eyminus, double eyplus) {
343  setY(y);
344  setYErr(eyminus, eyplus);
345  }
346 
348  void setY(double y, std::pair<double,double> ey) {
349  setY(y);
350  setYErr(ey);
351  }
352 
353 
355  void setZ(double z, double ez) {
356  setZ(z);
357  setZErr(ez);
358  }
359 
361  void setZ(double z, double ezminus, double ezplus) {
362  setZ(z);
363  setZErr(ezminus, ezplus);
364  }
365 
367  void setZ(double z, std::pair<double,double> ez) {
368  setZ(z);
369  setZErr(ez);
370  }
371 
373 
374 
375  // @name Manipulations
377 
379  void scaleX(double scalex) {
380  setX(x()*scalex);
381  setXErr(xErrMinus()*scalex, xErrPlus()*scalex);
382  }
383 
385  void scaleY(double scaley) {
386  setY(y()*scaley);
387  setYErr(yErrMinus()*scaley, yErrPlus()*scaley);
388  }
389 
391  void scaleZ(double scalez) {
392  setZ(z()*scalez);
393  setZErr(zErrMinus()*scalez, zErrPlus()*scalez);
394  }
395 
397  void scaleXYZ(double scalex, double scaley, double scalez) {
398  scaleX(scalex);
399  scaleY(scaley);
400  scaleZ(scalez);
401  }
402 
405  void scale(double scalex, double scaley, double scalez) {
406  scaleXYZ(scalex, scaley, scalez);
407  }
408 
410 
411 
412  protected:
413 
415 
416 
417  double _x;
418  double _y;
419  double _z;
420  std::pair<double,double> _ex;
421  std::pair<double,double> _ey;
422  std::pair<double,double> _ez;
423 
425 
426  };
427 
428 
429 
431 
432 
434  inline bool operator==(const Point3D& a, const YODA::Point3D& b) {
435  const bool same_val = fuzzyEquals(a.x(), b.x()) && fuzzyEquals(a.y(), b.y());
436  const bool same_eminus = fuzzyEquals(a.xErrMinus(), b.xErrMinus()) &&
437  fuzzyEquals(a.yErrMinus(), b.yErrMinus());
438  const bool same_eplus = fuzzyEquals(a.xErrPlus(), b.xErrPlus()) &&
439  fuzzyEquals(a.yErrPlus(), b.yErrPlus());
440  return same_val && same_eminus && same_eplus;
441  }
442 
444  inline bool operator != (const Point3D& a, const YODA::Point3D& b) {
445  return !(a == b);
446  }
447 
449  inline bool operator < (const Point3D& a, const YODA::Point3D& b) {
450  if (! fuzzyEquals(a.x(), b.x())) {
451  return a.x() < b.x();
452  }
453  if (!fuzzyEquals(a.y(), b.y())) {
454  return a.y() < b.y();
455  }
456  if (! fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
457  return a.xErrMinus() < b.xErrMinus();
458  }
459  if (!fuzzyEquals(a.yErrMinus(), b.yErrMinus())) {
460  return a.yErrMinus() < b.yErrMinus();
461  }
462  if (! fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
463  return a.xErrPlus() < b.xErrPlus();
464  }
465  if (!fuzzyEquals(a.yErrPlus(), b.yErrPlus())) {
466  return a.yErrPlus() < b.yErrPlus();
467  }
468  return false;
469  }
470 
472  inline bool operator <= (const Point3D& a, const YODA::Point3D& b) {
473  if (a == b) return true;
474  return a < b;
475  }
476 
478  inline bool operator > (const Point3D& a, const YODA::Point3D& b) {
479  return !(a <= b);
480  }
481 
483  inline bool operator >= (const Point3D& a, const YODA::Point3D& b) {
484  return !(a < b);
485  }
486 
488 
489 
490 }
491 
492 #endif
Point3D & operator=(const Point3D &p)
Copy assignment.
Definition: Point3D.h:73
void setY(double y, double eyminus, double eyplus)
Set y value and asymmetric error.
Definition: Point3D.h:342
void scaleY(double scaley)
Scaling of y axis.
Definition: Point3D.h:385
void setY(double y, std::pair< double, double > ey)
Set y value and asymmetric error.
Definition: Point3D.h:348
void setYErrMinus(double eyminus)
Set negative y error.
Definition: Point3D.h:211
void setZErrPlus(double ezplus)
Set positive z error.
Definition: Point3D.h:279
const std::pair< double, double > & xErrs() const
Get x-error values.
Definition: Point3D.h:128
void setXYZ(double x, double y, double z)
Set x, y and z values.
Definition: Point3D.h:116
double xErrPlus() const
Get positive x-error value.
Definition: Point3D.h:138
double zErrMinus() const
Get negative z-error value.
Definition: Point3D.h:259
double zErrPlus() const
Get positive z-error value.
Definition: Point3D.h:264
void setZErr(double ezminus, double ezplus)
Set asymmetric z error.
Definition: Point3D.h:290
double zMax() const
Get value plus positive z-error.
Definition: Point3D.h:306
double x() const
Get x value.
Definition: Point3D.h:93
std::pair< double, double > ValuePair
Definition: Point3D.h:20
bool fuzzyEquals(double a, double b, double tolerance=1E-5)
Compare two floating point numbers for equality with a degree of fuzziness.
Definition: MathUtils.h:68
Point3D(double x, double y, double z, const std::pair< double, double > &ex, const std::pair< double, double > &ey, const std::pair< double, double > &ez)
Constructor from asymmetric errors given as vectors.
Definition: Point3D.h:56
void scaleZ(double scalez)
Scaling of z axis.
Definition: Point3D.h:391
const std::pair< double, double > & yErrs() const
Get y-error values.
Definition: Point3D.h:191
bool operator<(const Bin1D< DBN > &a, const Bin1D< DBN > &b)
Bin1Ds are compared for axis sorting by lower edge position.
Definition: Bin1D.h:341
void setZErr(double ez)
Set symmetric z error.
Definition: Point3D.h:284
void setYErr(double ey)
Set symmetric y error.
Definition: Point3D.h:221
Point3D(double x, double y, double z, double exminus, double explus, double eyminus, double eyplus, double ezminus, double ezplus)
Constructor from values with explicit asymmetric errors.
Definition: Point3D.h:41
double yErrPlus() const
Get positive y-error value.
Definition: Point3D.h:201
double y() const
Get y value.
Definition: Point3D.h:99
double zErrAvg() const
Get average z-error value.
Definition: Point3D.h:269
void setX(double x, double exminus, double explus)
Set x value and asymmetric error.
Definition: Point3D.h:323
bool operator>(const Error< N > &a, const Error< N > &b)
Greater-than operator used to sort errors.
Definition: ErrorND.h:206
A 3D data point to be contained in a Scatter3D.
Definition: Point3D.h:17
void setYErr(std::pair< double, double > ey)
Set asymmetric y error.
Definition: Point3D.h:233
void setXErrPlus(double explus)
Set positive x error.
Definition: Point3D.h:153
double xErrAvg() const
Get average x-error value.
Definition: Point3D.h:143
double xErrMinus() const
Get negative x-error value.
Definition: Point3D.h:133
void setX(double x, double ex)
Set x value and symmetric error.
Definition: Point3D.h:317
double z() const
Get z value.
Definition: Point3D.h:105
void setY(double y, double ey)
Set y value and symmetric error.
Definition: Point3D.h:336
void setYErr(double eyminus, double eyplus)
Set asymmetric y error.
Definition: Point3D.h:227
void scale(double scalex, double scaley, double scalez)
Definition: Point3D.h:405
void setZ(double z, double ezminus, double ezplus)
Set z value and asymmetric error.
Definition: Point3D.h:361
void setZErr(std::pair< double, double > ez)
Set asymmetric z error.
Definition: Point3D.h:296
void setXErr(double exminus, double explus)
Set asymmetric x error.
Definition: Point3D.h:164
void setZ(double z, std::pair< double, double > ez)
Set z value and asymmetric error.
Definition: Point3D.h:367
void setZErrMinus(double ezminus)
Set negative z error.
Definition: Point3D.h:274
double yMax() const
Get value plus positive y-error.
Definition: Point3D.h:243
void setXErr(std::pair< double, double > ex)
Set asymmetric x error.
Definition: Point3D.h:170
bool operator!=(const Error< N > &a, const Error< N > &b)
Inequality test.
Definition: ErrorND.h:180
void setYErrPlus(double eyplus)
Set positive y error.
Definition: Point3D.h:216
Point3D(const Point3D &p)
Copy constructor.
Definition: Point3D.h:66
bool operator>=(const Error< N > &a, const Error< N > &b)
Greater-than-or-equals operator used to sort errors.
Definition: ErrorND.h:212
const std::pair< double, double > & zErrs() const
Get z-error values.
Definition: Point3D.h:254
double zMin() const
Get value minus negative z-error.
Definition: Point3D.h:301
double yErrMinus() const
Get negative y-error value.
Definition: Point3D.h:196
void setX(double x, std::pair< double, double > ex)
Set x value and asymmetric error.
Definition: Point3D.h:329
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
double yMin() const
Get value minus negative y-error.
Definition: Point3D.h:238
void setY(double y)
Set y value.
Definition: Point3D.h:102
void setXErrMinus(double exminus)
Set negative x error.
Definition: Point3D.h:148
void setZ(double z, double ez)
Set z value and symmetric error.
Definition: Point3D.h:355
void setXErr(double ex)
Set symmetric x error.
Definition: Point3D.h:158
void setZ(double z)
Set z value.
Definition: Point3D.h:108
double xMin() const
Get value minus negative x-error.
Definition: Point3D.h:175
Point3D(double x, double y, double z, double ex=0.0, double ey=0.0, double ez=0.0)
Constructor from values with optional symmetric errors.
Definition: Point3D.h:31
bool operator<=(const Error< N > &a, const Error< N > &b)
Less-than-or-equals operator used to sort errors.
Definition: ErrorND.h:199
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
bool operator==(const Error< N > &a, const Error< N > &b)
Equality test.
Definition: ErrorND.h:169
double yErrAvg() const
Get average y-error value.
Definition: Point3D.h:206