Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-06-16 08:38:00

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