Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-04-19 09:13:37

0001 // -*- C++ -*-
0002 //
0003 // This file is part of YODA -- Yet more Objects for Data Analysis
0004 // Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details)
0005 //
0006 #ifndef YODA_PointUtils_h
0007 #define YODA_PointUtils_h
0008 
0009 #include <type_traits>
0010 
0011 namespace YODA {
0012 
0013   /// @name Mixin of convenience methods using CRTP
0014   /// @{
0015 
0016   /// @brief CRTP mixin introducing convenience aliases along X axis.
0017   template <class Derived>
0018   struct XDirectionMixin {
0019 
0020     /// @name Point accessors
0021     /// @{
0022 
0023     /// Get x value
0024     double x() const {
0025       return static_cast<const Derived*>(this)->vals()[0];
0026     }
0027 
0028     /// Set the x value
0029     void setX(double x) {
0030       static_cast<Derived*>(this)->setVal(0, x);
0031     }
0032 
0033     /// @}
0034 
0035     /// @name x error accessors
0036     /// @{
0037 
0038     /// Get x error pair
0039     std::pair<double,double> xErrs() const {
0040       return static_cast<const Derived*>(this)->errs(0);
0041     }
0042 
0043     /// Get minus x error
0044     double xErrMinus() const {
0045       return static_cast<const Derived*>(this)->errMinus(0);
0046     }
0047 
0048     /// Get plus x error
0049     double xErrPlus() const {
0050       return static_cast<const Derived*>(this)->errPlus(0);
0051     }
0052 
0053     // Get the average x error
0054     double xErrAvg() const {
0055       return static_cast<const Derived*>(this)->errAvg(0);
0056     }
0057 
0058     /// Set the minus x errors
0059     void setXErrMinus(double err) {
0060       static_cast<Derived*>(this)->setErrMinus(0, err);
0061     }
0062 
0063     /// Set the plus x errors
0064     void setXErrPlus(double err) {
0065       static_cast<Derived*>(this)->setErrPlus(0, err);
0066     }
0067 
0068     /// Set symmetric x error
0069     void setXErr(double ex) {
0070       setXErrMinus(ex);
0071       setXErrPlus(ex);
0072     }
0073 
0074     /// Set symmetric x error (alias)
0075     void setXErrs(double ex) {
0076       setXErr(ex);
0077     }
0078 
0079     /// Set the x errors
0080     void setXErrs(double errminus, double errplus) {
0081       static_cast<Derived*>(this)->setErrs(0, {errminus, errplus});
0082     }
0083 
0084     /// Set the x errors
0085     void setXErrs(std::pair<double,double> errs) {
0086       static_cast<Derived*>(this)->setErrs(0, errs);
0087     }
0088 
0089     /// Get value minus negative x-error
0090     double xMin() const {
0091       return x() - xErrMinus();
0092       return static_cast<const Derived*>(this)->min(0);
0093     }
0094 
0095     /// Get value plus positive x-error
0096     double xMax() const {
0097       return static_cast<const Derived*>(this)->max(0);
0098     }
0099 
0100     /// @}
0101 
0102     /// @name Combined x value and error setters
0103     /// @{
0104 
0105     /// Set x value and symmetric error
0106     void setX(double x, double ex) {
0107       setX(x);
0108       setXErr(ex);
0109     }
0110 
0111     /// Set x value and asymmetric error
0112     void setX(double x, double exminus, double explus) {
0113       setX(x);
0114       setXErrs(exminus, explus);
0115     }
0116 
0117     /// Set x value and asymmetric error
0118     void setX(double x, std::pair<double,double>& ex) {
0119       setX(x);
0120       setXErrs(ex);
0121     }
0122 
0123     /// @}
0124 
0125     // @name Manipulations
0126     /// @{
0127 
0128     /// Scaling of x axis
0129     void scaleX(double scalex) {
0130       setX(x()*scalex);
0131       setXErrs(xErrMinus()*scalex, xErrPlus()*scalex);
0132     }
0133 
0134     /// @}
0135 
0136 
0137   };
0138 
0139 
0140   /// @brief CRTP mixin introducing convenience aliases along Y axis.
0141   template <class Derived>
0142   struct YDirectionMixin {
0143 
0144     /// @name Point accessors
0145     /// @{
0146 
0147     /// Get y value
0148     double y() const {
0149       return static_cast<const Derived*>(this)->vals()[1];
0150     }
0151 
0152     /// Set the y value
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     /// Set x and y values
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     /// Set x and y values
0169     void setXY(const std::pair<double,double>& xy) {
0170       setXY(xy.first, xy.second);
0171     }
0172 
0173     /// @}
0174 
0175     /// @name x error accessors
0176     /// @{
0177 
0178     /// Get y error pair
0179     std::pair<double,double> yErrs() const {
0180       return static_cast<const Derived*>(this)->errs(1);
0181     }
0182 
0183     /// Get minus y error
0184     double yErrMinus() const {
0185       return static_cast<const Derived*>(this)->errMinus(1);
0186     }
0187 
0188     /// Get plus y error
0189     double yErrPlus() const {
0190       return static_cast<const Derived*>(this)->errPlus(1);
0191     }
0192 
0193     // Get the average y error
0194     double yErrAvg() const {
0195       return static_cast<const Derived*>(this)->errAvg(1);
0196     }
0197 
0198     /// Set the minus y errors
0199     void setYErrMinus(double err) {
0200       static_cast<Derived*>(this)->setErrMinus(1, err);
0201     }
0202 
0203     /// Set the plus y errors
0204     void setYErrPlus(double err) {
0205       static_cast<Derived*>(this)->setErrPlus(1, err);
0206     }
0207 
0208     /// Set symmetric y error
0209     void setYErr(double ey) {
0210       setYErrMinus(ey);
0211       setYErrPlus(ey);
0212     }
0213 
0214     /// Set symmetric y error (alias)
0215     void setYErrs(double ey) {
0216       setYErr(ey);
0217     }
0218 
0219     /// Set the y errors
0220     void setYErrs(double errminus, double errplus) {
0221       static_cast<Derived*>(this)->setErrs(1, {errminus, errplus});
0222     }
0223 
0224     /// Set the y errors
0225     void setYErrs(std::pair<double,double> errs) {
0226       static_cast<Derived*>(this)->setErrs(1, errs);
0227     }
0228 
0229     /// Get value minus negative y-error
0230     double yMin() const {
0231       return static_cast<const Derived*>(this)->min(1);
0232     }
0233 
0234     /// Get value plus positive y-error
0235     double yMax() const {
0236       return static_cast<const Derived*>(this)->max(1);
0237     }
0238 
0239     /// @}
0240 
0241     /// @name Combined y value and error setters
0242     /// @{
0243 
0244     /// Set y value and symmetric error
0245     void setY(double y, double ey) {
0246       setY(y);
0247       setYErr(ey);
0248     }
0249 
0250     /// Set y value and asymmetric error
0251     void setY(double y, double eyminus, double eyplus) {
0252       setY(y);
0253       setYErrs(eyminus, eyplus);
0254     }
0255 
0256     /// Set y value and asymmetric error
0257     void setY(double y, std::pair<double,double>& ey) {
0258       setY(y);
0259       setYErrs(ey);
0260     }
0261 
0262     /// @}
0263 
0264     // @name Manipulations
0265     /// @{
0266 
0267     /// Scaling of y axis
0268     void scaleY(double scaley) {
0269       setY(y()*scaley);
0270       setYErrs(yErrMinus()*scaley, yErrPlus()*scaley);
0271     }
0272 
0273     /// @}
0274 
0275 
0276   };
0277 
0278 
0279   /// @brief CRTP mixin introducing convenience aliases along Z axis.
0280   template <class Derived>
0281   struct ZDirectionMixin {
0282 
0283     /// @name Point accessors
0284     /// @{
0285 
0286     /// Get z value
0287     double z() const {
0288       return static_cast<const Derived*>(this)->vals()[2];
0289     }
0290 
0291     /// Set the y value
0292     void setZ(double z) {
0293       static_cast<Derived*>(this)->setVal(2, z);
0294     }
0295 
0296     /// Set x and y values
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     /// @name x error accessors
0306     /// @{
0307 
0308     /// Get y error pair
0309     std::pair<double,double> zErrs() const {
0310       return static_cast<const Derived*>(this)->errs(2);
0311     }
0312 
0313     /// Get minus z error
0314     double zErrMinus() const {
0315       return static_cast<const Derived*>(this)->errMinus(2);
0316     }
0317 
0318     /// Get plus z error
0319     double zErrPlus() const {
0320       return static_cast<const Derived*>(this)->errPlus(2);
0321     }
0322 
0323     // Get the average z error
0324     double zErrAvg() const {
0325       return static_cast<const Derived*>(this)->errAvg(2);
0326     }
0327 
0328     /// Set the minus z errors
0329     void setZErrMinus(double err) {
0330       static_cast<Derived*>(this)->setErrMinus(2, err);
0331     }
0332 
0333     /// Set the plus y errors
0334     void setZErrPlus(double err) {
0335       static_cast<Derived*>(this)->setErrPlus(2, err);
0336     }
0337 
0338     /// Set symmetric z error
0339     void setZErr(double ez) {
0340       setZErrMinus(ez);
0341       setZErrPlus(ez);
0342     }
0343 
0344     /// Set symmetric z error (alias)
0345     void setZErrs(double ez) {
0346       setZErr(ez);
0347     }
0348 
0349     /// Set the z errors
0350     void setZErrs(double errminus, double errplus) {
0351       static_cast<Derived*>(this)->setErrs(2, {errminus, errplus});
0352     }
0353 
0354     /// Set the z errors
0355     void setZErrs(std::pair<double,double> errs) {
0356       static_cast<Derived*>(this)->setErrs(2, errs);
0357     }
0358 
0359     /// Get value minus negative y-error
0360     double zMin() const {
0361       return static_cast<const Derived*>(this)->min(2);
0362     }
0363 
0364     /// Get value plus positive y-error
0365     double zMax() const {
0366       return static_cast<const Derived*>(this)->max(2);
0367     }
0368 
0369     /// @}
0370 
0371     /// @name Combined z value and error setters
0372     /// @{
0373 
0374     /// Set z value and symmetric error
0375     void setZ(double z, double ez) {
0376       setZ(z);
0377       setZErr(ez);
0378     }
0379 
0380     /// Set y value and asymmetric error
0381     void setZ(double z, double ezminus, double ezplus) {
0382       setZ(z);
0383       setZErrs(ezminus, ezplus);
0384     }
0385 
0386     /// Set z value and asymmetric error
0387     void setZ(double z, std::pair<double,double>& ez) {
0388       setZ(z);
0389       setZErrs(ez);
0390     }
0391 
0392     /// @}
0393 
0394     // @name Manipulations
0395     /// @{
0396 
0397     /// Scaling of z axis
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