File indexing completed on 2026-06-16 08:38:00
0001
0002
0003
0004
0005
0006 #ifndef YODA_PointUtils_h
0007 #define YODA_PointUtils_h
0008
0009 #include <type_traits>
0010
0011 namespace YODA {
0012
0013
0014
0015
0016
0017
0018 template <class Derived>
0019 struct XDirectionMixin {
0020
0021
0022
0023
0024
0025 double x() const {
0026 return static_cast<const Derived*>(this)->vals()[0];
0027 }
0028
0029
0030 void setX(double x) {
0031 static_cast<Derived*>(this)->setVal(0, x);
0032 }
0033
0034
0035
0036
0037
0038
0039
0040 std::pair<double,double> xErrs() const {
0041 return static_cast<const Derived*>(this)->errs(0);
0042 }
0043
0044
0045 double xErrMinus() const {
0046 return static_cast<const Derived*>(this)->errMinus(0);
0047 }
0048
0049
0050 double xErrPlus() const {
0051 return static_cast<const Derived*>(this)->errPlus(0);
0052 }
0053
0054
0055 double xErrAvg() const {
0056 return static_cast<const Derived*>(this)->errAvg(0);
0057 }
0058
0059
0060 void setXErrMinus(double err) {
0061 static_cast<Derived*>(this)->setErrMinus(0, err);
0062 }
0063
0064
0065 void setXErrPlus(double err) {
0066 static_cast<Derived*>(this)->setErrPlus(0, err);
0067 }
0068
0069
0070 void setXErr(double ex) {
0071 setXErrMinus(ex);
0072 setXErrPlus(ex);
0073 }
0074
0075
0076 void setXErrs(double ex) {
0077 setXErr(ex);
0078 }
0079
0080
0081 void setXErrs(double errminus, double errplus) {
0082 static_cast<Derived*>(this)->setErrs(0, {errminus, errplus});
0083 }
0084
0085
0086 void setXErrs(const std::pair<double,double>& errs) {
0087 static_cast<Derived*>(this)->setErrs(0, errs);
0088 }
0089
0090
0091 double xMin() const {
0092 return x() - xErrMinus();
0093 return static_cast<const Derived*>(this)->min(0);
0094 }
0095
0096
0097 double xMax() const {
0098 return static_cast<const Derived*>(this)->max(0);
0099 }
0100
0101
0102
0103
0104
0105
0106
0107 void setX(double x, double ex) {
0108 setX(x);
0109 setXErr(ex);
0110 }
0111
0112
0113 void setX(double x, double exminus, double explus) {
0114 setX(x);
0115 setXErrs(exminus, explus);
0116 }
0117
0118
0119 void setX(double x, const std::pair<double,double>& ex) {
0120 setX(x);
0121 setXErrs(ex);
0122 }
0123
0124
0125
0126
0127
0128
0129
0130 void scaleX(double scalex) {
0131 setX(x()*scalex);
0132 setXErrs(xErrMinus()*scalex, xErrPlus()*scalex);
0133 }
0134
0135
0136
0137
0138 };
0139
0140
0141
0142 template <class Derived>
0143 struct YDirectionMixin {
0144
0145
0146
0147
0148
0149 double y() const {
0150 return static_cast<const Derived*>(this)->vals()[1];
0151 }
0152
0153
0154 void setY(double y) {
0155 static_cast<Derived*>(this)->setVal(1, y);
0156 }
0157
0158 std::pair<double,double> xy() const {
0159 const auto& vals = static_cast<const Derived*>(this)->vals();
0160 return {vals[0], vals[1]};
0161 }
0162
0163
0164 void setXY(double x, double y) {
0165 static_cast<Derived*>(this)->setVal(0, x);
0166 static_cast<Derived*>(this)->setVal(1, y);
0167 }
0168
0169
0170 void setXY(const std::pair<double,double>& xy) {
0171 setXY(xy.first, xy.second);
0172 }
0173
0174
0175
0176
0177
0178
0179
0180 std::pair<double,double> yErrs() const {
0181 return static_cast<const Derived*>(this)->errs(1);
0182 }
0183
0184
0185 double yErrMinus() const {
0186 return static_cast<const Derived*>(this)->errMinus(1);
0187 }
0188
0189
0190 double yErrPlus() const {
0191 return static_cast<const Derived*>(this)->errPlus(1);
0192 }
0193
0194
0195 double yErrAvg() const {
0196 return static_cast<const Derived*>(this)->errAvg(1);
0197 }
0198
0199
0200 void setYErrMinus(double err) {
0201 static_cast<Derived*>(this)->setErrMinus(1, err);
0202 }
0203
0204
0205 void setYErrPlus(double err) {
0206 static_cast<Derived*>(this)->setErrPlus(1, err);
0207 }
0208
0209
0210 void setYErr(double ey) {
0211 setYErrMinus(ey);
0212 setYErrPlus(ey);
0213 }
0214
0215
0216 void setYErrs(double ey) {
0217 setYErr(ey);
0218 }
0219
0220
0221 void setYErrs(double errminus, double errplus) {
0222 static_cast<Derived*>(this)->setErrs(1, {errminus, errplus});
0223 }
0224
0225
0226 void setYErrs(const std::pair<double,double>& errs) {
0227 static_cast<Derived*>(this)->setErrs(1, errs);
0228 }
0229
0230
0231 double yMin() const {
0232 return static_cast<const Derived*>(this)->min(1);
0233 }
0234
0235
0236 double yMax() const {
0237 return static_cast<const Derived*>(this)->max(1);
0238 }
0239
0240
0241
0242
0243
0244
0245
0246 void setY(double y, double ey) {
0247 setY(y);
0248 setYErr(ey);
0249 }
0250
0251
0252 void setY(double y, double eyminus, double eyplus) {
0253 setY(y);
0254 setYErrs(eyminus, eyplus);
0255 }
0256
0257
0258 void setY(double y, const std::pair<double,double>& ey) {
0259 setY(y);
0260 setYErrs(ey);
0261 }
0262
0263
0264
0265
0266
0267
0268
0269 void scaleY(double scaley) {
0270 setY(y()*scaley);
0271 setYErrs(yErrMinus()*scaley, yErrPlus()*scaley);
0272 }
0273
0274
0275
0276
0277 };
0278
0279
0280
0281 template <class Derived>
0282 struct ZDirectionMixin {
0283
0284
0285
0286
0287
0288 double z() const {
0289 return static_cast<const Derived*>(this)->vals()[2];
0290 }
0291
0292
0293 void setZ(double z) {
0294 static_cast<Derived*>(this)->setVal(2, z);
0295 }
0296
0297
0298 void setXYZ(double x, double y, double z) {
0299 static_cast<Derived*>(this)->setVal(0, x);
0300 static_cast<Derived*>(this)->setVal(1, y);
0301 static_cast<Derived*>(this)->setVal(2, z);
0302 }
0303
0304
0305
0306
0307
0308
0309
0310 std::pair<double,double> zErrs() const {
0311 return static_cast<const Derived*>(this)->errs(2);
0312 }
0313
0314
0315 double zErrMinus() const {
0316 return static_cast<const Derived*>(this)->errMinus(2);
0317 }
0318
0319
0320 double zErrPlus() const {
0321 return static_cast<const Derived*>(this)->errPlus(2);
0322 }
0323
0324
0325 double zErrAvg() const {
0326 return static_cast<const Derived*>(this)->errAvg(2);
0327 }
0328
0329
0330 void setZErrMinus(double err) {
0331 static_cast<Derived*>(this)->setErrMinus(2, err);
0332 }
0333
0334
0335 void setZErrPlus(double err) {
0336 static_cast<Derived*>(this)->setErrPlus(2, err);
0337 }
0338
0339
0340 void setZErr(double ez) {
0341 setZErrMinus(ez);
0342 setZErrPlus(ez);
0343 }
0344
0345
0346 void setZErrs(double ez) {
0347 setZErr(ez);
0348 }
0349
0350
0351 void setZErrs(double errminus, double errplus) {
0352 static_cast<Derived*>(this)->setErrs(2, {errminus, errplus});
0353 }
0354
0355
0356 void setZErrs(const std::pair<double,double>& errs) {
0357 static_cast<Derived*>(this)->setErrs(2, errs);
0358 }
0359
0360
0361 double zMin() const {
0362 return static_cast<const Derived*>(this)->min(2);
0363 }
0364
0365
0366 double zMax() const {
0367 return static_cast<const Derived*>(this)->max(2);
0368 }
0369
0370
0371
0372
0373
0374
0375
0376 void setZ(double z, double ez) {
0377 setZ(z);
0378 setZErr(ez);
0379 }
0380
0381
0382 void setZ(double z, double ezminus, double ezplus) {
0383 setZ(z);
0384 setZErrs(ezminus, ezplus);
0385 }
0386
0387
0388 void setZ(double z, const std::pair<double,double>& ez) {
0389 setZ(z);
0390 setZErrs(ez);
0391 }
0392
0393
0394
0395
0396
0397
0398
0399 void scaleZ(double scalez) {
0400 setZ(z()*scalez);
0401 setZErrs(zErrMinus()*scalez, zErrPlus()*scalez);
0402 }
0403
0404
0405
0406
0407 };
0408
0409
0410
0411 }
0412
0413 #endif