Back to home page

EIC code displayed by LXR

 
 

    


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

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_BinnedUtils_h
0007 #define YODA_BinnedUtils_h
0008 
0009 #include "YODA/Utils/BinningUtils.h"
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, typename EdgeT = double>
0018   struct XAxisMixin {
0019 
0020     /// @name Bin accessors
0021     /// @{
0022 
0023     /// @brief Number of bins along the X axis
0024     size_t numBinsX(const bool includeOverflows=false) const {
0025       return static_cast<const Derived*>(this)->numBinsAt(0, includeOverflows);
0026     }
0027 
0028     /// @brief Low edge of first histo's axis
0029     template <class T = EdgeT>
0030     enable_if_CAxisT<T> xMin() const { return static_cast<const Derived*>(this)->template min<0>(); }
0031 
0032     /// @brief High edge of first histo's axis
0033     template <class T = EdgeT>
0034     enable_if_CAxisT<T> xMax() const { return static_cast<const Derived*>(this)->template max<0>(); }
0035 
0036     /// @brief All bin edges on X axis. +-inf edges are included.
0037     std::vector<EdgeT> xEdges(const bool includeOverflows = false) const {
0038       return static_cast<const Derived*>(this)->template edges<0>(includeOverflows);
0039     }
0040 
0041     /// @brief All widths on X axis
0042     ///
0043     /// @note Only supported for continuous axes
0044     template <class T = EdgeT>
0045     std::enable_if_t<std::is_floating_point<T>::value, std::vector<T>>
0046     xWidths(const bool includeOverflows = false) const {
0047       return static_cast<const Derived*>(this)->template widths<0>(includeOverflows);
0048     }
0049 
0050     void rebinXBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
0051       static_cast<Derived*>(this)->template rebinBy<0>(n, begin, end);
0052     }
0053 
0054     void rebinXTo(const std::vector<double>& newedges) {
0055       static_cast<Derived*>(this)->template rebinTo<0>(newedges);
0056     }
0057 
0058     void rebinX(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
0059       static_cast<Derived*>(this)->template rebinBy<0>(n, begin, end);
0060     }
0061 
0062     void rebinX(const std::vector<double>& newedges) {
0063       static_cast<Derived*>(this)->template rebinTo<0>(newedges);
0064     }
0065 
0066     /// @}
0067 
0068   };
0069 
0070 
0071   /// @brief CRTP mixin introducing convenience aliases to access statistics along X axis.
0072   template <class Derived>
0073   struct XStatsMixin {
0074 
0075     /// @name Whole histo data
0076     /// @{
0077 
0078     /// @brief Calculate the mean on X axis
0079     double xMean(const bool includeOverflows=true) const noexcept {
0080       return static_cast<const Derived*>(this)->mean(0, includeOverflows);
0081     }
0082 
0083     /// @brief Calculate the variance on X axis
0084     double xVariance(const bool includeOverflows=true) const noexcept {
0085       return static_cast<const Derived*>(this)->variance(0, includeOverflows);
0086     }
0087 
0088     /// @brief Calculate the standard deviation on X axis
0089     double xStdDev(const bool includeOverflows=true) const noexcept {
0090       return static_cast<const Derived*>(this)->stdDev(0, includeOverflows);
0091     }
0092 
0093     /// @brief Calculate the standard error on X axis
0094     double xStdErr(const bool includeOverflows=true) const noexcept {
0095       return static_cast<const Derived*>(this)->stdErr(0, includeOverflows);
0096     }
0097 
0098     /// @brief Calculate the RMS on X axis
0099     double xRMS(const bool includeOverflows=true) const noexcept {
0100       return static_cast<const Derived*>(this)->rms(0, includeOverflows);
0101     }
0102 
0103     /// @}
0104   };
0105 
0106 
0107   /// @brief CRTP mixin introducing convenience aliases along Y axis.
0108   template <class Derived, typename EdgeT = double>
0109   struct YAxisMixin {
0110 
0111     /// @name Bin accessors
0112     /// @{
0113 
0114     /// @brief Number of bins along the Y axis
0115     size_t numBinsY(const bool includeOverflows=false) const {
0116       return static_cast<const Derived*>(this)->numBinsAt(1, includeOverflows);
0117     }
0118 
0119     /// @brief Low edge of second histo's axis
0120     template <class T = EdgeT>
0121     enable_if_CAxisT<T> yMin() const { return static_cast<const Derived*>(this)->template min<1>(); }
0122 
0123     /// @brief High edge of second histo's axis
0124     template <class T = EdgeT>
0125     enable_if_CAxisT<T> yMax() const { return static_cast<const Derived*>(this)->template max<1>(); }
0126 
0127     /// @brief All bin edges on Y axis. +-inf edges are included.
0128     std::vector<EdgeT> yEdges(const bool includeOverflows = false) const {
0129       return static_cast<const Derived*>(this)->template edges<1>(includeOverflows);
0130     }
0131 
0132     /// @brief All widths on Y axis
0133     ///
0134     /// @note Only supported for continuous axes
0135     template <class T = EdgeT>
0136     std::enable_if_t<std::is_floating_point<T>::value, std::vector<T>>
0137     yWidths(const bool includeOverflows = false) const {
0138       return static_cast<const Derived*>(this)->template widths<1>(includeOverflows);
0139     }
0140 
0141     void rebinYBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
0142       static_cast<Derived*>(this)->template rebinBy<1>(n, begin, end);
0143     }
0144 
0145     void rebinYTo(const std::vector<double>& newedges) {
0146       static_cast<Derived*>(this)->template rebinTo<1>(newedges);
0147     }
0148 
0149     void rebinY(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
0150       static_cast<Derived*>(this)->template rebinBy<1>(n, begin, end);
0151     }
0152 
0153     void rebinY(const std::vector<double>& newedges) {
0154       static_cast<Derived*>(this)->template rebinTo<1>(newedges);
0155     }
0156 
0157     /// @}
0158 
0159   };
0160 
0161   /// @brief CRTP mixin introducing convenience aliases to access statistics along Y axis.
0162   template <class Derived>
0163   struct YStatsMixin {
0164 
0165     /// @name Whole histo data
0166     /// @{
0167 
0168     /// @brief Calculate the mean on Y axis
0169     double yMean(const bool includeOverflows=true) const noexcept {
0170       return static_cast<const Derived*>(this)->mean(1, includeOverflows);
0171     }
0172 
0173     /// @brief Calculate the variance on Y axis
0174     double yVariance(const bool includeOverflows=true) const noexcept {
0175       return static_cast<const Derived*>(this)->variance(1, includeOverflows);
0176     }
0177 
0178     /// @brief Calculate the standard deviation on Y axis
0179     double yStdDev(const bool includeOverflows=true) const noexcept {
0180       return static_cast<const Derived*>(this)->stdDev(1, includeOverflows);
0181     }
0182 
0183     /// @brief Calculate the standard error on Y axis
0184     double yStdErr(const bool includeOverflows=true) const noexcept {
0185       return static_cast<const Derived*>(this)->stdErr(1, includeOverflows);
0186     }
0187 
0188     /// @brief Calculate the RMS on Y axis
0189     double yRMS(const bool includeOverflows=true) const noexcept {
0190       return static_cast<const Derived*>(this)->rms(1, includeOverflows);
0191     }
0192 
0193   };
0194 
0195 
0196   /// @brief CRTP mixin introducing convenience aliases along Z axis.
0197   template <class Derived, typename EdgeT = double>
0198   struct ZAxisMixin {
0199 
0200     /// @name Bin accessors
0201     /// @{
0202 
0203     /// @brief Number of bins along the Z axis
0204     size_t numBinsZ(const bool includeOverflows=false) const {
0205       return static_cast<const Derived*>(this)->numBinsAt(2, includeOverflows);
0206     }
0207 
0208     /// @brief Low edge of second histo's axis
0209     template <class T = EdgeT>
0210     enable_if_CAxisT<T> zMin() const { return static_cast<const Derived*>(this)->template min<2>(); }
0211 
0212     /// @brief High edge of second histo's axis
0213     template <class T = EdgeT>
0214     enable_if_CAxisT<T> zMax() const { return static_cast<const Derived*>(this)->template max<2>(); }
0215 
0216     /// @brief All bin edges on Z axis. +-inf edges are included.
0217     std::vector<EdgeT> zEdges(const bool includeOverflows = false) const {
0218       return static_cast<const Derived*>(this)->template edges<2>(includeOverflows);
0219     }
0220 
0221     /// @brief All widths on Z axis
0222     ///
0223     /// @note Only supported for continuous axes
0224     template <class T = EdgeT>
0225     std::enable_if_t<std::is_floating_point<T>::value, std::vector<T>>
0226     zWidths(const bool includeOverflows = false) const {
0227       return static_cast<const Derived*>(this)->template widths<2>(includeOverflows);
0228     }
0229 
0230     void rebinZBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
0231       static_cast<Derived*>(this)->template rebinBy<2>(n, begin, end);
0232     }
0233 
0234     void rebinZTo(const std::vector<double>& newedges) {
0235       static_cast<Derived*>(this)->template rebinTo<2>(newedges);
0236     }
0237 
0238     void rebinZ(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
0239       static_cast<Derived*>(this)->template rebinBy<2>(n, begin, end);
0240     }
0241 
0242     void rebinZ(const std::vector<double>& newedges) {
0243       static_cast<Derived*>(this)->template rebinTo<2>(newedges);
0244     }
0245 
0246     /// @}
0247 
0248   };
0249 
0250   /// @brief CRTP mixin introducing convenience aliases to access statistics along Z axis.
0251   template <class Derived>
0252   struct ZStatsMixin {
0253 
0254     /// @name Whole histo data
0255     /// @{
0256 
0257     /// @brief Calculate the mean on Z axis
0258     double zMean(const bool includeOverflows=true) const noexcept {
0259       return static_cast<const Derived*>(this)->mean(2, includeOverflows);
0260     }
0261 
0262     /// @brief Calculate the variance on Z axis
0263     double zVariance(const bool includeOverflows=true) const noexcept {
0264       return static_cast<const Derived*>(this)->variance(2, includeOverflows);
0265     }
0266 
0267     /// @brief Calculate the standard deviation on Z axis
0268     double zStdDev(const bool includeOverflows=true) const noexcept {
0269       return static_cast<const Derived*>(this)->stdDev(2, includeOverflows);
0270     }
0271 
0272     /// @brief Calculate the standard error on Z axis
0273     double zStdErr(const bool includeOverflows=true) const noexcept {
0274       return static_cast<const Derived*>(this)->stdErr(2, includeOverflows);
0275     }
0276 
0277     /// @brief Calculate the RMS on Z axis
0278     double zRMS(const bool includeOverflows=true) const noexcept {
0279       return static_cast<const Derived*>(this)->rms(2, includeOverflows);
0280     }
0281 
0282   };
0283 
0284   /// @}
0285 
0286 }
0287 
0288 #endif