yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.2
BinnedUtils.h
Go to the documentation of this file.
1// -*- C++ -*-
2//
3// This file is part of YODA -- Yet more Objects for Data Analysis
4// Copyright (C) 2008-2024 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_BinnedUtils_h
7#define YODA_BinnedUtils_h
8
10
11namespace YODA {
12
15
17 template <class Derived, typename EdgeT = double>
18 struct XAxisMixin {
19
22
24 size_t numBinsX(const bool includeOverflows=false) const {
25 return static_cast<const Derived*>(this)->numBinsAt(0, includeOverflows);
26 }
27
29 template <class T = EdgeT>
30 enable_if_CAxisT<T> xMin() const { return static_cast<const Derived*>(this)->template min<0>(); }
31
33 template <class T = EdgeT>
34 enable_if_CAxisT<T> xMax() const { return static_cast<const Derived*>(this)->template max<0>(); }
35
37 std::vector<EdgeT> xEdges(const bool includeOverflows = false) const {
38 return static_cast<const Derived*>(this)->template edges<0>(includeOverflows);
39 }
40
44 template <class T = EdgeT>
45 std::enable_if_t<std::is_floating_point<T>::value, std::vector<T>>
46 xWidths(const bool includeOverflows = false) const {
47 return static_cast<const Derived*>(this)->template widths<0>(includeOverflows);
48 }
49
50 void rebinXBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
51 static_cast<Derived*>(this)->template rebinBy<0>(n, begin, end);
52 }
53
54 void rebinXTo(const std::vector<double>& newedges) {
55 static_cast<Derived*>(this)->template rebinTo<0>(newedges);
56 }
57
58 void rebinX(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
59 static_cast<Derived*>(this)->template rebinBy<0>(n, begin, end);
60 }
61
62 void rebinX(const std::vector<double>& newedges) {
63 static_cast<Derived*>(this)->template rebinTo<0>(newedges);
64 }
65
67
68 };
69
70
72 template <class Derived>
73 struct XStatsMixin {
74
77
79 double xMean(const bool includeOverflows=true) const noexcept {
80 return static_cast<const Derived*>(this)->mean(0, includeOverflows);
81 }
82
84 double xVariance(const bool includeOverflows=true) const noexcept {
85 return static_cast<const Derived*>(this)->variance(0, includeOverflows);
86 }
87
89 double xStdDev(const bool includeOverflows=true) const noexcept {
90 return static_cast<const Derived*>(this)->stdDev(0, includeOverflows);
91 }
92
94 double xStdErr(const bool includeOverflows=true) const noexcept {
95 return static_cast<const Derived*>(this)->stdErr(0, includeOverflows);
96 }
97
99 double xRMS(const bool includeOverflows=true) const noexcept {
100 return static_cast<const Derived*>(this)->rms(0, includeOverflows);
101 }
102
104 };
105
106
108 template <class Derived, typename EdgeT = double>
109 struct YAxisMixin {
110
113
115 size_t numBinsY(const bool includeOverflows=false) const {
116 return static_cast<const Derived*>(this)->numBinsAt(1, includeOverflows);
117 }
118
120 template <class T = EdgeT>
121 enable_if_CAxisT<T> yMin() const { return static_cast<const Derived*>(this)->template min<1>(); }
122
124 template <class T = EdgeT>
125 enable_if_CAxisT<T> yMax() const { return static_cast<const Derived*>(this)->template max<1>(); }
126
128 std::vector<EdgeT> yEdges(const bool includeOverflows = false) const {
129 return static_cast<const Derived*>(this)->template edges<1>(includeOverflows);
130 }
131
135 template <class T = EdgeT>
136 std::enable_if_t<std::is_floating_point<T>::value, std::vector<T>>
137 yWidths(const bool includeOverflows = false) const {
138 return static_cast<const Derived*>(this)->template widths<1>(includeOverflows);
139 }
140
141 void rebinYBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
142 static_cast<Derived*>(this)->template rebinBy<1>(n, begin, end);
143 }
144
145 void rebinYTo(const std::vector<double>& newedges) {
146 static_cast<Derived*>(this)->template rebinTo<1>(newedges);
147 }
148
149 void rebinY(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
150 static_cast<Derived*>(this)->template rebinBy<1>(n, begin, end);
151 }
152
153 void rebinY(const std::vector<double>& newedges) {
154 static_cast<Derived*>(this)->template rebinTo<1>(newedges);
155 }
156
158
159 };
160
162 template <class Derived>
163 struct YStatsMixin {
164
167
169 double yMean(const bool includeOverflows=true) const noexcept {
170 return static_cast<const Derived*>(this)->mean(1, includeOverflows);
171 }
172
174 double yVariance(const bool includeOverflows=true) const noexcept {
175 return static_cast<const Derived*>(this)->variance(1, includeOverflows);
176 }
177
179 double yStdDev(const bool includeOverflows=true) const noexcept {
180 return static_cast<const Derived*>(this)->stdDev(1, includeOverflows);
181 }
182
184 double yStdErr(const bool includeOverflows=true) const noexcept {
185 return static_cast<const Derived*>(this)->stdErr(1, includeOverflows);
186 }
187
189 double yRMS(const bool includeOverflows=true) const noexcept {
190 return static_cast<const Derived*>(this)->rms(1, includeOverflows);
191 }
192
193 };
194
195
197 template <class Derived, typename EdgeT = double>
198 struct ZAxisMixin {
199
202
204 size_t numBinsZ(const bool includeOverflows=false) const {
205 return static_cast<const Derived*>(this)->numBinsAt(2, includeOverflows);
206 }
207
209 template <class T = EdgeT>
210 enable_if_CAxisT<T> zMin() const { return static_cast<const Derived*>(this)->template min<2>(); }
211
213 template <class T = EdgeT>
214 enable_if_CAxisT<T> zMax() const { return static_cast<const Derived*>(this)->template max<2>(); }
215
217 std::vector<EdgeT> zEdges(const bool includeOverflows = false) const {
218 return static_cast<const Derived*>(this)->template edges<2>(includeOverflows);
219 }
220
224 template <class T = EdgeT>
225 std::enable_if_t<std::is_floating_point<T>::value, std::vector<T>>
226 zWidths(const bool includeOverflows = false) const {
227 return static_cast<const Derived*>(this)->template widths<2>(includeOverflows);
228 }
229
230 void rebinZBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
231 static_cast<Derived*>(this)->template rebinBy<2>(n, begin, end);
232 }
233
234 void rebinZTo(const std::vector<double>& newedges) {
235 static_cast<Derived*>(this)->template rebinTo<2>(newedges);
236 }
237
238 void rebinZ(unsigned int n, size_t begin=1, size_t end=UINT_MAX) {
239 static_cast<Derived*>(this)->template rebinBy<2>(n, begin, end);
240 }
241
242 void rebinZ(const std::vector<double>& newedges) {
243 static_cast<Derived*>(this)->template rebinTo<2>(newedges);
244 }
245
247
248 };
249
251 template <class Derived>
252 struct ZStatsMixin {
253
256
258 double zMean(const bool includeOverflows=true) const noexcept {
259 return static_cast<const Derived*>(this)->mean(2, includeOverflows);
260 }
261
263 double zVariance(const bool includeOverflows=true) const noexcept {
264 return static_cast<const Derived*>(this)->variance(2, includeOverflows);
265 }
266
268 double zStdDev(const bool includeOverflows=true) const noexcept {
269 return static_cast<const Derived*>(this)->stdDev(2, includeOverflows);
270 }
271
273 double zStdErr(const bool includeOverflows=true) const noexcept {
274 return static_cast<const Derived*>(this)->stdErr(2, includeOverflows);
275 }
276
278 double zRMS(const bool includeOverflows=true) const noexcept {
279 return static_cast<const Derived*>(this)->rms(2, includeOverflows);
280 }
281
282 };
283
285
286}
287
288#endif
Anonymous namespace to limit visibility.
double stdErr(const double sumWX, const double sumW, const double sumWX2, const double sumW2)
Calculate the weighted standard error of a sample.
Definition MathUtils.h:470
double stdDev(const double sumWX, const double sumW, const double sumWX2, const double sumW2)
Calculate the weighted standard deviation of a sample.
Definition MathUtils.h:458
std::enable_if_t< std::is_floating_point< EdgeT >::value, EdgeT > enable_if_CAxisT
Checks if edge type is continuous and returns edge type.
double variance(const double sumWX, const double sumW, const double sumWX2, const double sumW2)
Calculate the weighted variance of a sample.
Definition MathUtils.h:421
double mean(const std::vector< int > &sample)
Calculate the mean of a sample.
Definition MathUtils.h:391
CRTP mixin introducing convenience aliases along X axis.
Definition BinnedUtils.h:18
enable_if_CAxisT< T > xMin() const
Low edge of first histo's axis.
Definition BinnedUtils.h:30
size_t numBinsX(const bool includeOverflows=false) const
Number of bins along the X axis.
Definition BinnedUtils.h:24
std::vector< EdgeT > xEdges(const bool includeOverflows=false) const
All bin edges on X axis. +-inf edges are included.
Definition BinnedUtils.h:37
void rebinXBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX)
Definition BinnedUtils.h:50
void rebinX(unsigned int n, size_t begin=1, size_t end=UINT_MAX)
Definition BinnedUtils.h:58
void rebinX(const std::vector< double > &newedges)
Definition BinnedUtils.h:62
void rebinXTo(const std::vector< double > &newedges)
Definition BinnedUtils.h:54
enable_if_CAxisT< T > xMax() const
High edge of first histo's axis.
Definition BinnedUtils.h:34
std::enable_if_t< std::is_floating_point< T >::value, std::vector< T > > xWidths(const bool includeOverflows=false) const
All widths on X axis.
Definition BinnedUtils.h:46
CRTP mixin introducing convenience aliases to access statistics along X axis.
Definition BinnedUtils.h:73
double xMean(const bool includeOverflows=true) const noexcept
Calculate the mean on X axis.
Definition BinnedUtils.h:79
double xVariance(const bool includeOverflows=true) const noexcept
Calculate the variance on X axis.
Definition BinnedUtils.h:84
double xRMS(const bool includeOverflows=true) const noexcept
Calculate the RMS on X axis.
Definition BinnedUtils.h:99
double xStdDev(const bool includeOverflows=true) const noexcept
Calculate the standard deviation on X axis.
Definition BinnedUtils.h:89
double xStdErr(const bool includeOverflows=true) const noexcept
Calculate the standard error on X axis.
Definition BinnedUtils.h:94
CRTP mixin introducing convenience aliases along Y axis.
void rebinYTo(const std::vector< double > &newedges)
size_t numBinsY(const bool includeOverflows=false) const
Number of bins along the Y axis.
void rebinY(unsigned int n, size_t begin=1, size_t end=UINT_MAX)
void rebinYBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX)
enable_if_CAxisT< T > yMax() const
High edge of second histo's axis.
std::vector< EdgeT > yEdges(const bool includeOverflows=false) const
All bin edges on Y axis. +-inf edges are included.
std::enable_if_t< std::is_floating_point< T >::value, std::vector< T > > yWidths(const bool includeOverflows=false) const
All widths on Y axis.
void rebinY(const std::vector< double > &newedges)
enable_if_CAxisT< T > yMin() const
Low edge of second histo's axis.
CRTP mixin introducing convenience aliases to access statistics along Y axis.
double yStdDev(const bool includeOverflows=true) const noexcept
Calculate the standard deviation on Y axis.
double yVariance(const bool includeOverflows=true) const noexcept
Calculate the variance on Y axis.
double yMean(const bool includeOverflows=true) const noexcept
Calculate the mean on Y axis.
double yRMS(const bool includeOverflows=true) const noexcept
Calculate the RMS on Y axis.
double yStdErr(const bool includeOverflows=true) const noexcept
Calculate the standard error on Y axis.
CRTP mixin introducing convenience aliases along Z axis.
enable_if_CAxisT< T > zMin() const
Low edge of second histo's axis.
enable_if_CAxisT< T > zMax() const
High edge of second histo's axis.
void rebinZBy(unsigned int n, size_t begin=1, size_t end=UINT_MAX)
size_t numBinsZ(const bool includeOverflows=false) const
Number of bins along the Z axis.
std::vector< EdgeT > zEdges(const bool includeOverflows=false) const
All bin edges on Z axis. +-inf edges are included.
std::enable_if_t< std::is_floating_point< T >::value, std::vector< T > > zWidths(const bool includeOverflows=false) const
All widths on Z axis.
void rebinZ(unsigned int n, size_t begin=1, size_t end=UINT_MAX)
void rebinZTo(const std::vector< double > &newedges)
void rebinZ(const std::vector< double > &newedges)
CRTP mixin introducing convenience aliases to access statistics along Z axis.
double zStdDev(const bool includeOverflows=true) const noexcept
Calculate the standard deviation on Z axis.
double zStdErr(const bool includeOverflows=true) const noexcept
Calculate the standard error on Z axis.
double zRMS(const bool includeOverflows=true) const noexcept
Calculate the RMS on Z axis.
double zMean(const bool includeOverflows=true) const noexcept
Calculate the mean on Z axis.
double zVariance(const bool includeOverflows=true) const noexcept
Calculate the variance on Z axis.