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