yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
PointUtils.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-2024 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_PointUtils_h
7#define YODA_PointUtils_h
8
9#include <type_traits>
10
11namespace YODA {
12
15
17 template <class Derived>
19
22
24 double x() const {
25 return static_cast<const Derived*>(this)->vals()[0];
26 }
27
29 void setX(double x) {
30 static_cast<Derived*>(this)->setVal(0, x);
31 }
32
34
37
39 std::pair<double,double> xErrs() const {
40 return static_cast<const Derived*>(this)->errs(0);
41 }
42
44 double xErrMinus() const {
45 return static_cast<const Derived*>(this)->errMinus(0);
46 }
47
49 double xErrPlus() const {
50 return static_cast<const Derived*>(this)->errPlus(0);
51 }
52
53 // Get the average x error
54 double xErrAvg() const {
55 return static_cast<const Derived*>(this)->errAvg(0);
56 }
57
59 void setXErrMinus(double err) {
60 static_cast<Derived*>(this)->setErrMinus(0, err);
61 }
62
64 void setXErrPlus(double err) {
65 static_cast<Derived*>(this)->setErrPlus(0, err);
66 }
67
69 void setXErr(double ex) {
70 setXErrMinus(ex);
71 setXErrPlus(ex);
72 }
73
75 void setXErrs(double ex) {
76 setXErr(ex);
77 }
78
80 void setXErrs(double errminus, double errplus) {
81 static_cast<Derived*>(this)->setErrs(0, {errminus, errplus});
82 }
83
85 void setXErrs(std::pair<double,double> errs) {
86 static_cast<Derived*>(this)->setErrs(0, errs);
87 }
88
90 double xMin() const {
91 return x() - xErrMinus();
92 return static_cast<const Derived*>(this)->min(0);
93 }
94
96 double xMax() const {
97 return static_cast<const Derived*>(this)->max(0);
98 }
99
101
104
106 void setX(double x, double ex) {
107 setX(x);
108 setXErr(ex);
109 }
110
112 void setX(double x, double exminus, double explus) {
113 setX(x);
114 setXErrs(exminus, explus);
115 }
116
118 void setX(double x, std::pair<double,double>& ex) {
119 setX(x);
120 setXErrs(ex);
121 }
122
124
125 // @name Manipulations
127
129 void scaleX(double scalex) {
130 setX(x()*scalex);
131 setXErrs(xErrMinus()*scalex, xErrPlus()*scalex);
132 }
133
135
136
137 };
138
139
141 template <class Derived>
143
146
148 double y() const {
149 return static_cast<const Derived*>(this)->vals()[1];
150 }
151
153 void setY(double y) {
154 static_cast<Derived*>(this)->setVal(1, y);
155 }
156
157 std::pair<double,double> xy() const {
158 const auto& vals = static_cast<const Derived*>(this)->vals();
159 return {vals[0], vals[1]};
160 }
161
163 void setXY(double x, double y) {
164 static_cast<Derived*>(this)->setVal(0, x);
165 static_cast<Derived*>(this)->setVal(1, y);
166 }
167
169 void setXY(const std::pair<double,double>& xy) {
170 setXY(xy.first, xy.second);
171 }
172
174
177
179 std::pair<double,double> yErrs() const {
180 return static_cast<const Derived*>(this)->errs(1);
181 }
182
184 double yErrMinus() const {
185 return static_cast<const Derived*>(this)->errMinus(1);
186 }
187
189 double yErrPlus() const {
190 return static_cast<const Derived*>(this)->errPlus(1);
191 }
192
193 // Get the average y error
194 double yErrAvg() const {
195 return static_cast<const Derived*>(this)->errAvg(1);
196 }
197
199 void setYErrMinus(double err) {
200 static_cast<Derived*>(this)->setErrMinus(1, err);
201 }
202
204 void setYErrPlus(double err) {
205 static_cast<Derived*>(this)->setErrPlus(1, err);
206 }
207
209 void setYErr(double ey) {
210 setYErrMinus(ey);
211 setYErrPlus(ey);
212 }
213
215 void setYErrs(double ey) {
216 setYErr(ey);
217 }
218
220 void setYErrs(double errminus, double errplus) {
221 static_cast<Derived*>(this)->setErrs(1, {errminus, errplus});
222 }
223
225 void setYErrs(std::pair<double,double> errs) {
226 static_cast<Derived*>(this)->setErrs(1, errs);
227 }
228
230 double yMin() const {
231 return static_cast<const Derived*>(this)->min(1);
232 }
233
235 double yMax() const {
236 return static_cast<const Derived*>(this)->max(1);
237 }
238
240
243
245 void setY(double y, double ey) {
246 setY(y);
247 setYErr(ey);
248 }
249
251 void setY(double y, double eyminus, double eyplus) {
252 setY(y);
253 setYErrs(eyminus, eyplus);
254 }
255
257 void setY(double y, std::pair<double,double>& ey) {
258 setY(y);
259 setYErrs(ey);
260 }
261
263
264 // @name Manipulations
266
268 void scaleY(double scaley) {
269 setY(y()*scaley);
270 setYErrs(yErrMinus()*scaley, yErrPlus()*scaley);
271 }
272
274
275
276 };
277
278
280 template <class Derived>
282
285
287 double z() const {
288 return static_cast<const Derived*>(this)->vals()[2];
289 }
290
292 void setZ(double z) {
293 static_cast<Derived*>(this)->setVal(2, z);
294 }
295
297 void setXYZ(double x, double y, double z) {
298 static_cast<Derived*>(this)->setVal(0, x);
299 static_cast<Derived*>(this)->setVal(1, y);
300 static_cast<Derived*>(this)->setVal(2, z);
301 }
302
304
307
309 std::pair<double,double> zErrs() const {
310 return static_cast<const Derived*>(this)->errs(2);
311 }
312
314 double zErrMinus() const {
315 return static_cast<const Derived*>(this)->errMinus(2);
316 }
317
319 double zErrPlus() const {
320 return static_cast<const Derived*>(this)->errPlus(2);
321 }
322
323 // Get the average z error
324 double zErrAvg() const {
325 return static_cast<const Derived*>(this)->errAvg(2);
326 }
327
329 void setZErrMinus(double err) {
330 static_cast<Derived*>(this)->setErrMinus(2, err);
331 }
332
334 void setZErrPlus(double err) {
335 static_cast<Derived*>(this)->setErrPlus(2, err);
336 }
337
339 void setZErr(double ez) {
340 setZErrMinus(ez);
341 setZErrPlus(ez);
342 }
343
345 void setZErrs(double ez) {
346 setZErr(ez);
347 }
348
350 void setZErrs(double errminus, double errplus) {
351 static_cast<Derived*>(this)->setErrs(2, {errminus, errplus});
352 }
353
355 void setZErrs(std::pair<double,double> errs) {
356 static_cast<Derived*>(this)->setErrs(2, errs);
357 }
358
360 double zMin() const {
361 return static_cast<const Derived*>(this)->min(2);
362 }
363
365 double zMax() const {
366 return static_cast<const Derived*>(this)->max(2);
367 }
368
370
373
375 void setZ(double z, double ez) {
376 setZ(z);
377 setZErr(ez);
378 }
379
381 void setZ(double z, double ezminus, double ezplus) {
382 setZ(z);
383 setZErrs(ezminus, ezplus);
384 }
385
387 void setZ(double z, std::pair<double,double>& ez) {
388 setZ(z);
389 setZErrs(ez);
390 }
391
393
394 // @name Manipulations
396
398 void scaleZ(double scalez) {
399 setZ(z()*scalez);
400 setZErrs(zErrMinus()*scalez, zErrPlus()*scalez);
401 }
402
404
405
406 };
407
409
410}
411
412#endif
Anonymous namespace to limit visibility.
CRTP mixin introducing convenience aliases along X axis.
Definition PointUtils.h:18
void scaleX(double scalex)
Scaling of x axis.
Definition PointUtils.h:129
double x() const
Get x value.
Definition PointUtils.h:24
void setXErrs(double ex)
Set symmetric x error (alias)
Definition PointUtils.h:75
double xErrPlus() const
Get plus x error.
Definition PointUtils.h:49
void setXErrs(double errminus, double errplus)
Set the x errors.
Definition PointUtils.h:80
void setXErrs(std::pair< double, double > errs)
Set the x errors.
Definition PointUtils.h:85
void setXErr(double ex)
Set symmetric x error.
Definition PointUtils.h:69
void setX(double x, double exminus, double explus)
Set x value and asymmetric error.
Definition PointUtils.h:112
void setX(double x)
Set the x value.
Definition PointUtils.h:29
std::pair< double, double > xErrs() const
Get x error pair.
Definition PointUtils.h:39
void setXErrMinus(double err)
Set the minus x errors.
Definition PointUtils.h:59
void setXErrPlus(double err)
Set the plus x errors.
Definition PointUtils.h:64
void setX(double x, double ex)
Set x value and symmetric error.
Definition PointUtils.h:106
double xMin() const
Get value minus negative x-error.
Definition PointUtils.h:90
void setX(double x, std::pair< double, double > &ex)
Set x value and asymmetric error.
Definition PointUtils.h:118
double xErrAvg() const
Definition PointUtils.h:54
double xMax() const
Get value plus positive x-error.
Definition PointUtils.h:96
double xErrMinus() const
Get minus x error.
Definition PointUtils.h:44
CRTP mixin introducing convenience aliases along Y axis.
Definition PointUtils.h:142
void setYErrMinus(double err)
Set the minus y errors.
Definition PointUtils.h:199
void setXY(double x, double y)
Set x and y values.
Definition PointUtils.h:163
double yErrAvg() const
Definition PointUtils.h:194
void setYErrs(double errminus, double errplus)
Set the y errors.
Definition PointUtils.h:220
std::pair< double, double > yErrs() const
Get y error pair.
Definition PointUtils.h:179
void setY(double y, double eyminus, double eyplus)
Set y value and asymmetric error.
Definition PointUtils.h:251
double y() const
Get y value.
Definition PointUtils.h:148
void setXY(const std::pair< double, double > &xy)
Set x and y values.
Definition PointUtils.h:169
void setY(double y, std::pair< double, double > &ey)
Set y value and asymmetric error.
Definition PointUtils.h:257
void setY(double y, double ey)
Set y value and symmetric error.
Definition PointUtils.h:245
void setYErrs(std::pair< double, double > errs)
Set the y errors.
Definition PointUtils.h:225
void setYErrs(double ey)
Set symmetric y error (alias)
Definition PointUtils.h:215
double yErrMinus() const
Get minus y error.
Definition PointUtils.h:184
void setYErrPlus(double err)
Set the plus y errors.
Definition PointUtils.h:204
std::pair< double, double > xy() const
Definition PointUtils.h:157
void scaleY(double scaley)
Scaling of y axis.
Definition PointUtils.h:268
double yErrPlus() const
Get plus y error.
Definition PointUtils.h:189
void setYErr(double ey)
Set symmetric y error.
Definition PointUtils.h:209
double yMin() const
Get value minus negative y-error.
Definition PointUtils.h:230
double yMax() const
Get value plus positive y-error.
Definition PointUtils.h:235
void setY(double y)
Set the y value.
Definition PointUtils.h:153
CRTP mixin introducing convenience aliases along Z axis.
Definition PointUtils.h:281
void setZErrPlus(double err)
Set the plus y errors.
Definition PointUtils.h:334
void setXYZ(double x, double y, double z)
Set x and y values.
Definition PointUtils.h:297
double zErrAvg() const
Definition PointUtils.h:324
double zErrPlus() const
Get plus z error.
Definition PointUtils.h:319
double zErrMinus() const
Get minus z error.
Definition PointUtils.h:314
std::pair< double, double > zErrs() const
Get y error pair.
Definition PointUtils.h:309
void setZErrMinus(double err)
Set the minus z errors.
Definition PointUtils.h:329
void setZErrs(std::pair< double, double > errs)
Set the z errors.
Definition PointUtils.h:355
void setZ(double z, double ezminus, double ezplus)
Set y value and asymmetric error.
Definition PointUtils.h:381
void setZ(double z)
Set the y value.
Definition PointUtils.h:292
void setZErrs(double errminus, double errplus)
Set the z errors.
Definition PointUtils.h:350
void setZErr(double ez)
Set symmetric z error.
Definition PointUtils.h:339
void setZErrs(double ez)
Set symmetric z error (alias)
Definition PointUtils.h:345
double zMax() const
Get value plus positive y-error.
Definition PointUtils.h:365
void setZ(double z, std::pair< double, double > &ez)
Set z value and asymmetric error.
Definition PointUtils.h:387
double zMin() const
Get value minus negative y-error.
Definition PointUtils.h:360
void setZ(double z, double ez)
Set z value and symmetric error.
Definition PointUtils.h:375
void scaleZ(double scalez)
Scaling of z axis.
Definition PointUtils.h:398
double z() const
Get z value.
Definition PointUtils.h:287