YODA is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis  1.3.1
Point1D.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_POINT1D_H
7 #define YODA_POINT1D_H
8 
9 #include "YODA/Exceptions.h"
10 #include "YODA/Utils/MathUtils.h"
11 #include <utility>
12 
13 namespace YODA {
14 
15 
17  class Point1D {
18  public:
19 
20  typedef std::pair<double,double> ValuePair;
21 
22 
24 
25 
26  // Default constructor
27  Point1D() { }
28 
29 
31  Point1D(double x, double ex=0.0)
32  : _x(x)
33  {
34  _ex = std::make_pair(ex, ex);
35  }
36 
37 
39  Point1D(double x, double exminus, double explus)
40  : _x(x)
41  {
42  _ex = std::make_pair(exminus, explus);
43  }
44 
45 
47  Point1D(double x, const std::pair<double,double>& ex)
48  : _x(x), _ex(ex)
49  { }
50 
51 
53  Point1D(const Point1D& p)
54  : _x(p._x), _ex(p._ex)
55  { }
56 
57 
60  _x = p._x;
61  _ex = p._ex;
62  return *this;
63  }
64 
66 
67 
68  public:
69 
71 
72 
74  double x() const { return _x; }
75 
77  void setX(double x) { _x = x; }
78 
80 
82 
83 
85 
86 
88  const std::pair<double,double>& xErrs() const {
89  return _ex;
90  }
91 
93  double xErrMinus() const {
94  return _ex.first;
95  }
96 
98  double xErrPlus() const {
99  return _ex.second;
100  }
101 
103  double xErrAvg() const {
104  return (_ex.first + _ex.second)/2.0;
105  }
106 
108  void setXErrMinus(double exminus) {
109  _ex.first = exminus;
110  }
111 
113  void setXErrPlus(double explus) {
114  _ex.second = explus;
115  }
116 
118  void setXErr(double ex) {
119  setXErrMinus(ex);
120  setXErrPlus(ex);
121  }
122 
124  void setXErr(double exminus, double explus) {
125  setXErrMinus(exminus);
126  setXErrPlus(explus);
127  }
128 
130  void setXErr(std::pair<double,double> ex) {
131  _ex = ex;
132  }
133 
136  double xMin() const {
137  return _x - _ex.first;
138  }
139 
142  double xMax() const {
143  return _x + _ex.second;
144  }
145 
146  // /// Set negative x-error via the xMin position
147  // /// @todo Remove when multiple errors are supported
148  // void setXMin(double xmin) {
149  // if (xmin > x()) throw UserError("Attempted to set an xmin > x");
150  // setXErrMinus(x() - xmin);
151  // }
152 
153  // /// Set positive x-error via the xMax position
154  // /// @todo Remove when multiple errors are supported
155  // void setXMax(double xmax) {
156  // if (xmax < x()) throw UserError("Attempted to set an xmax < x");
157  // setXErrPlus(xmax - x());
158  // }
159 
161 
162 
164 
165 
167 
168 
170  void setX(double x, double ex) {
171  setX(x);
172  setXErr(ex);
173  }
174 
176  void setX(double x, double exminus, double explus) {
177  setX(x);
178  setXErr(exminus, explus);
179  }
180 
182  void setX(double x, std::pair<double,double> ex) {
183  setX(x);
184  setXErr(ex);
185  }
186 
188 
189 
190  // @name Manipulations
192 
194  void scaleX(double scalex) {
195  setX(x()*scalex);
196  setXErr(xErrMinus()*scalex, xErrPlus()*scalex);
197  }
198 
200 
201 
202  protected:
203 
205 
206 
207  double _x;
208  std::pair<double,double> _ex;
209 
211 
212  };
213 
214 
215 
217 
218 
221  inline bool operator==(const YODA::Point1D& a, const YODA::Point1D& b) {
222  const bool same_val = YODA::fuzzyEquals(a.x(), b.x());
223  const bool same_eminus = YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus());
224  const bool same_eplus = YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus());
225  return same_val && same_eminus && same_eplus;
226  }
227 
230  inline bool operator != (const YODA::Point1D& a, const YODA::Point1D& b) {
231  return !(a == b);
232  }
233 
235  inline bool operator < (const YODA::Point1D& a, const YODA::Point1D& b) {
236  if (!YODA::fuzzyEquals(a.x(), b.x())) {
237  return a.x() < b.x();
238  }
239  if (!YODA::fuzzyEquals(a.xErrMinus(), b.xErrMinus())) {
240  return a.xErrMinus() < b.xErrMinus();
241  }
242  if (!YODA::fuzzyEquals(a.xErrPlus(), b.xErrPlus())) {
243  return a.xErrPlus() < b.xErrPlus();
244  }
245  return false;
246  }
247 
249  inline bool operator <= (const YODA::Point1D& a, const YODA::Point1D& b) {
250  if (a == b) return true;
251  return a < b;
252  }
253 
255  inline bool operator > (const YODA::Point1D& a, const YODA::Point1D& b) {
256  return !(a <= b);
257  }
258 
260  inline bool operator >= (const YODA::Point1D& a, const YODA::Point1D& b) {
261  return !(a < b);
262  }
263 
265 
266 
267 }
268 
269 #endif
void setXErr(std::pair< double, double > ex)
Set asymmetric x error.
Definition: Point1D.h:130
void setXErrPlus(double explus)
Set positive x error.
Definition: Point1D.h:113
std::pair< double, double > ValuePair
Definition: Point1D.h:20
double xMin() const
Definition: Point1D.h:136
Point1D(const Point1D &p)
Copy constructor.
Definition: Point1D.h:53
void setXErr(double exminus, double explus)
Set asymmetric x error.
Definition: Point1D.h:124
double xErrMinus() const
Get negative x-error value.
Definition: Point1D.h:93
Point1D(double x, const std::pair< double, double > &ex)
Constructor from values with asymmetric errors.
Definition: Point1D.h:47
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
Point1D(double x, double ex=0.0)
Constructor from values with optional symmetric errors.
Definition: Point1D.h:31
bool operator<(const Bin1D< DBN > &a, const Bin1D< DBN > &b)
Bin1Ds are compared for axis sorting by lower edge position.
Definition: Bin1D.h:341
Point1D(double x, double exminus, double explus)
Constructor from values with explicit asymmetric errors.
Definition: Point1D.h:39
bool operator>(const Error< N > &a, const Error< N > &b)
Greater-than operator used to sort errors.
Definition: ErrorND.h:206
void setXErrMinus(double exminus)
Set negative x error.
Definition: Point1D.h:108
double xMax() const
Definition: Point1D.h:142
A 1D data point to be contained in a Scatter1D.
Definition: Point1D.h:17
const std::pair< double, double > & xErrs() const
Get x-error values.
Definition: Point1D.h:88
bool operator!=(const Error< N > &a, const Error< N > &b)
Inequality test.
Definition: ErrorND.h:180
void scaleX(double scalex)
Scaling of x axis.
Definition: Point1D.h:194
double xErrPlus() const
Get positive x-error value.
Definition: Point1D.h:98
Point1D & operator=(const Point1D &p)
Copy assignment.
Definition: Point1D.h:59
bool operator>=(const Error< N > &a, const Error< N > &b)
Greater-than-or-equals operator used to sort errors.
Definition: ErrorND.h:212
void setX(double x, std::pair< double, double > ex)
Set x value and asymmetric error.
Definition: Point1D.h:182
void setXErr(double ex)
Set symmetric x error.
Definition: Point1D.h:118
double xErrAvg() const
Get average x-error value.
Definition: Point1D.h:103
void setX(double x, double ex)
Set x value and symmetric error.
Definition: Point1D.h:170
void setX(double x, double exminus, double explus)
Set x value and asymmetric error.
Definition: Point1D.h:176
double x() const
Get x value.
Definition: Point1D.h:74
void setX(double x)
Set x value.
Definition: Point1D.h:77
bool operator<=(const Error< N > &a, const Error< N > &b)
Less-than-or-equals operator used to sort errors.
Definition: ErrorND.h:199
bool operator==(const Error< N > &a, const Error< N > &b)
Equality test.
Definition: ErrorND.h:169