yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
Histo.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-2023 The YODA collaboration (see AUTHORS for details)
5//
6#ifndef YODA_Histo_h
7#define YODA_Histo_h
8
9#include "YODA/BinnedDbn.h"
10
11namespace YODA {
12
14 template <typename AxisT>
15 class BinnedDbn<1, AxisT>
16 : public DbnStorage<1, AxisT>,
17 public XAxisMixin<BinnedDbn<1, AxisT>, AxisT>,
18 public XStatsMixin<BinnedDbn<1, AxisT>> {
19 public:
20
23 using FillType = typename BaseT::FillType;
24 using BinType = typename BaseT::BinT;
25 using Ptr = std::shared_ptr<HistoT>;
26
28 using BaseT::BaseT;
29
30 BinnedDbn() = default;
31 BinnedDbn(const HistoT&) = default;
32 BinnedDbn(HistoT&&) =default;
33 BinnedDbn& operator =(const HistoT&) = default;
35 using AnalysisObject::operator =;
36
43 template <typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT>>
44 BinnedDbn(size_t nbins, double lower, double upper,
45 const std::string& path = "", const std::string& title = "")
46 : BaseT({nbins}, {{lower, upper}}, path, title) {}
47
51 BinnedDbn(const BaseT& other) : BaseT(other) {}
52 //
53 BinnedDbn(const HistoT& other, const std::string& path) : BaseT(other, path) {}
54
56 BinnedDbn(BaseT&& other) : BaseT(std::move(other)) {}
57 //
58 BinnedDbn(HistoT&& other, const std::string& path) : BaseT(std::move(other), path) {}
59
61 HistoT clone() const noexcept {
62 return HistoT(*this);
63 }
64
66 HistoT* newclone() const noexcept {
67 return new HistoT(*this);
68 }
69
71 virtual int fill(const AxisT val, const double weight = 1.0, const double fraction = 1.0) {
72 return BaseT::fill({val}, weight, fraction);
73 }
74
76 virtual int fill(FillType&& coords, const double weight = 1.0, const double fraction = 1.0) {
77 return BaseT::fill(std::move(coords), weight, fraction);
78 }
79
81 size_t indexAt(const AxisT xCoord) const noexcept {
82 return BaseT::binAt( {xCoord} ).index();
83 }
84
86 void maskBinAt(const AxisT xCoord, const bool status = true) noexcept {
87 return BaseT::maskBin({xCoord}, status);
88 }
89
90 };
91
92
93
94
95
97 template <typename AxisT1, typename AxisT2>
98 class BinnedDbn<2, AxisT1, AxisT2>
99 : public DbnStorage<2, AxisT1, AxisT2>,
100 public XAxisMixin<BinnedDbn<2, AxisT1, AxisT2>, AxisT1>,
101 public XStatsMixin<BinnedDbn<2, AxisT1, AxisT2>>,
102 public YAxisMixin<BinnedDbn<2, AxisT1, AxisT2>, AxisT2>,
103 public YStatsMixin<BinnedDbn<2, AxisT1, AxisT2>> {
104 public:
105
108 using FillType = typename BaseT::FillType;
109 using BinType = typename BaseT::BinT;
110 using Ptr = std::shared_ptr<HistoT>;
111
113 using BaseT::BaseT;
114
115 BinnedDbn() = default;
116 BinnedDbn(const HistoT&) = default;
117 BinnedDbn(HistoT&&) = default;
118 BinnedDbn& operator =(const HistoT&) = default;
120 using AnalysisObject::operator =;
121
128 template <typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT1, AxisT2>>
129 BinnedDbn(size_t nbinsX, double lowerX, double upperX,
130 size_t nbinsY, double lowerY, double upperY,
131 const std::string& path = "", const std::string& title = "")
132 : BaseT({nbinsX, nbinsY}, {{lowerX, upperX}, {lowerY, upperY}}, path, title) {}
133
137 BinnedDbn(const BaseT& other) : BaseT(other) {}
138 //
139 BinnedDbn(const HistoT& other, const std::string& path) : BaseT(other, path) {}
140
142 BinnedDbn(BaseT&& other) : BaseT(std::move(other)) {}
143 //
144 BinnedDbn(HistoT&& other, const std::string& path) : BaseT(std::move(other), path) {}
145
147 HistoT clone() const noexcept {
148 return HistoT(*this);
149 }
150
152 HistoT* newclone() const noexcept {
153 return new HistoT(*this);
154 }
155
157 virtual int fill(const AxisT1 valX, const AxisT2 valY, const double weight = 1.0, const double fraction = 1.0) {
158 return BaseT::fill({valX, valY}, weight, fraction);
159 }
160
162 virtual int fill(FillType&& coords, const double weight = 1.0, const double fraction = 1.0) {
163 return BaseT::fill(std::move(coords), weight, fraction);
164 }
165
167 BinType& bin(const size_t index) noexcept {
168 return BaseT::bin(index);
169 }
170
172 const BinType& bin(const size_t index) const noexcept {
173 return BaseT::bin(index);
174 }
175
177 BinType& bin(const size_t localX, const size_t localY) noexcept {
178 return BaseT::bin( {localX, localY} );
179 }
180
182 const BinType& bin(const size_t localX, const size_t localY) const noexcept {
183 return BaseT::bin( {localX, localY} );
184 }
185
187 BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord) noexcept {
188 return BaseT::binAt( {xCoord, yCoord} );
189 }
190
192 const BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept {
193 return BaseT::binAt( {xCoord, yCoord} );
194 }
195
197 size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept {
198 return BaseT::binAt( {xCoord, yCoord} ).index();
199 }
200
202 void maskBinAt(const AxisT1 xCoord, const AxisT2 yCoord, const bool status = true) noexcept {
203 return BaseT::maskBin({xCoord, yCoord}, status);
204 }
205
206 };
207
208
209
210
212 template <typename AxisT1, typename AxisT2, typename AxisT3>
213 class BinnedDbn<3, AxisT1, AxisT2, AxisT3>
214 : public DbnStorage<3, AxisT1, AxisT2, AxisT3>,
215 public XAxisMixin<BinnedDbn<3, AxisT1, AxisT2, AxisT3>, AxisT1>,
216 public XStatsMixin<BinnedDbn<3, AxisT1, AxisT2, AxisT3>>,
217 public YAxisMixin<BinnedDbn<3, AxisT1, AxisT2, AxisT3>, AxisT2>,
218 public YStatsMixin<BinnedDbn<3, AxisT1, AxisT2, AxisT3>>,
219 public ZAxisMixin<BinnedDbn<3, AxisT1, AxisT2, AxisT3>, AxisT3>,
220 public ZStatsMixin<BinnedDbn<3, AxisT1, AxisT2, AxisT3>> {
221 public:
222
225 using FillType = typename BaseT::FillType;
226 using BinType = typename BaseT::BinT;
227 using Ptr = std::shared_ptr<HistoT>;
228
230 using BaseT::BaseT;
231
232 BinnedDbn() = default;
233 BinnedDbn(const HistoT&) = default;
234 BinnedDbn(HistoT&&) = default;
235 BinnedDbn& operator =(const HistoT&) = default;
237 using AnalysisObject::operator =;
238
245 template <typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT1, AxisT2, AxisT3>>
246 BinnedDbn(size_t nbinsX, double lowerX, double upperX,
247 size_t nbinsY, double lowerY, double upperY,
248 size_t nbinsZ, double lowerZ, double upperZ,
249 const std::string& path = "", const std::string& title = "")
250 : BaseT({nbinsX, nbinsY, nbinsZ},
251 {{lowerX, upperX}, {lowerY, upperY}, {lowerZ, upperZ}},
252 path, title) {}
253
257 BinnedDbn(const BaseT& other) : BaseT(other) {}
258 //
259 BinnedDbn(const HistoT& other, const std::string& path) : BaseT(other, path) {}
260
262 BinnedDbn(BaseT&& other) : BaseT(std::move(other)) {}
263 //
264 BinnedDbn(HistoT&& other, const std::string& path) : BaseT(std::move(other), path) {}
265
267 HistoT clone() const noexcept {
268 return HistoT(*this);
269 }
270
272 HistoT* newclone() const noexcept {
273 return new HistoT(*this);
274 }
275
277 virtual int fill(const AxisT1 valX, const AxisT2 valY, const AxisT3 valZ, const double weight = 1.0, const double fraction = 1.0) {
278 return BaseT::fill({valX, valY, valZ}, weight, fraction);
279 }
280
282 virtual int fill(FillType&& coords, const double weight = 1.0, const double fraction = 1.0) {
283 return BaseT::fill(std::move(coords), weight, fraction);
284 }
285
287 BinType& bin(const size_t index) noexcept {
288 return BaseT::bin(index);
289 }
290
292 const BinType& bin(const size_t index) const noexcept {
293 return BaseT::bin(index);
294 }
295
297 BinType& bin(const size_t localX, const size_t localY, const size_t localZ) noexcept {
298 return BaseT::bin( {localX, localY, localZ} );
299 }
300
302 const BinType& bin(const size_t localX, const size_t localY, const size_t localZ) const noexcept {
303 return BaseT::bin( {localX, localY, localZ} );
304 }
305
307 BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) noexcept {
308 return BaseT::binAt( {xCoord, yCoord, zCoord} );
309 }
310
312 const BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept {
313 return BaseT::binAt( {xCoord, yCoord, zCoord} );
314 }
315
317 size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept {
318 return BaseT::binAt( {xCoord, yCoord, zCoord} ).index();
319 }
320
322 void maskBinAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord, const bool status = true) noexcept {
323 return BaseT::maskBin({xCoord, yCoord, zCoord}, status);
324 }
325
326 };
327
328
330 template<typename A1>
332
333 template <typename A1, typename A2>
335
336 template <typename A1, typename A2, typename A3>
338
340 namespace {
341 template <class T>
342 struct HistoMaker;
343
344 template<size_t... Is>
345 struct HistoMaker<std::index_sequence<Is...>> {
347 };
348 }
349
350 template<size_t N>
351 using HistoND = typename HistoMaker<std::make_index_sequence<N>>::type;
352
357
358}
359
360#endif
const std::string title() const
Get the AO title.
const std::string path() const
Get the AO path.
Specialisation of the BinnedDbn for a 1D histogram.
Definition Histo.h:18
BinnedDbn(BaseT &&other)
Move constructor.
Definition Histo.h:56
BinnedDbn(const HistoT &other, const std::string &path)
Definition Histo.h:53
BinnedDbn(const BaseT &other)
Copy constructor (needed for clone functions).
Definition Histo.h:51
BinnedDbn(HistoT &&)=default
HistoT * newclone() const noexcept
Make a copy on the heap.
Definition Histo.h:66
BinnedDbn(const HistoT &)=default
typename BaseT::FillType FillType
Definition Histo.h:23
std::shared_ptr< HistoT > Ptr
Definition Histo.h:25
virtual int fill(FillType &&coords, const double weight=1.0, const double fraction=1.0)
Fill function with FillType.
Definition Histo.h:76
void maskBinAt(const AxisT xCoord, const bool status=true) noexcept
Mask/Unmask bin at given set of coordinates.
Definition Histo.h:86
HistoT clone() const noexcept
Make a copy on the stack.
Definition Histo.h:61
BinnedDbn(size_t nbins, double lower, double upper, const std::string &path="", const std::string &title="")
Constructor with auto-setup of evenly spaced axes.
Definition Histo.h:44
virtual int fill(const AxisT val, const double weight=1.0, const double fraction=1.0)
Fill function with an explicit coordinate.
Definition Histo.h:71
typename BaseT::BinT BinType
Definition Histo.h:24
BinnedDbn(HistoT &&other, const std::string &path)
Definition Histo.h:58
size_t indexAt(const AxisT xCoord) const noexcept
Find bin index for given coordinates.
Definition Histo.h:81
Specialisation of the BinnedDbn for a 2D histogram.
Definition Histo.h:103
BinnedDbn(HistoT &&other, const std::string &path)
Definition Histo.h:144
const BinType & bin(const size_t localX, const size_t localY) const noexcept
Bin access using local indices (const version)
Definition Histo.h:182
const BinType & bin(const size_t index) const noexcept
Bin access using global index (const version)
Definition Histo.h:172
size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept
Find bin index for given coordinates.
Definition Histo.h:197
const BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept
Bin access using coordinates (const version)
Definition Histo.h:192
BinnedDbn(const BaseT &other)
Copy constructor (needed for clone functions).
Definition Histo.h:137
BinnedDbn(size_t nbinsX, double lowerX, double upperX, size_t nbinsY, double lowerY, double upperY, const std::string &path="", const std::string &title="")
Constructor with auto-setup of evenly spaced axes.
Definition Histo.h:129
BinType & bin(const size_t localX, const size_t localY) noexcept
Bin access using local indices.
Definition Histo.h:177
BinnedDbn(BaseT &&other)
Move constructor.
Definition Histo.h:142
typename BaseT::BinT BinType
Definition Histo.h:109
BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord) noexcept
Bin access using coordinates.
Definition Histo.h:187
BinnedDbn(const HistoT &)=default
BinnedDbn(const HistoT &other, const std::string &path)
Definition Histo.h:139
HistoT clone() const noexcept
Make a copy on the stack.
Definition Histo.h:147
typename BaseT::FillType FillType
Definition Histo.h:108
HistoT * newclone() const noexcept
Make a copy on the heap.
Definition Histo.h:152
std::shared_ptr< HistoT > Ptr
Definition Histo.h:110
virtual int fill(FillType &&coords, const double weight=1.0, const double fraction=1.0)
Fill function with FillType.
Definition Histo.h:162
BinType & bin(const size_t index) noexcept
Bin access using global index.
Definition Histo.h:167
virtual int fill(const AxisT1 valX, const AxisT2 valY, const double weight=1.0, const double fraction=1.0)
Fill function with two explicit coordinates.
Definition Histo.h:157
void maskBinAt(const AxisT1 xCoord, const AxisT2 yCoord, const bool status=true) noexcept
Mask/Unmask bin at given set of coordinates.
Definition Histo.h:202
Specialisation of the BinnedDbn for a 3D histogram.
Definition Histo.h:220
virtual int fill(FillType &&coords, const double weight=1.0, const double fraction=1.0)
Fill function with FillType.
Definition Histo.h:282
void maskBinAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord, const bool status=true) noexcept
Mask/Unmask bin at given set of coordinates.
Definition Histo.h:322
size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept
Find bin index for given coordinates.
Definition Histo.h:317
HistoT clone() const noexcept
Make a copy on the stack.
Definition Histo.h:267
BinnedDbn(BaseT &&other)
Move constructor.
Definition Histo.h:262
typename BaseT::FillType FillType
Definition Histo.h:225
const BinType & bin(const size_t localX, const size_t localY, const size_t localZ) const noexcept
Bin access using local indices (const version)
Definition Histo.h:302
std::shared_ptr< HistoT > Ptr
Definition Histo.h:227
BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) noexcept
Bin access using coordinates.
Definition Histo.h:307
BinnedDbn(const HistoT &other, const std::string &path)
Definition Histo.h:259
const BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept
Bin access using coordinates (const version)
Definition Histo.h:312
virtual int fill(const AxisT1 valX, const AxisT2 valY, const AxisT3 valZ, const double weight=1.0, const double fraction=1.0)
Fill function with three explicit coordinates.
Definition Histo.h:277
HistoT * newclone() const noexcept
Make a copy on the heap.
Definition Histo.h:272
BinType & bin(const size_t index) noexcept
Bin access using global index.
Definition Histo.h:287
const BinType & bin(const size_t index) const noexcept
Bin access using global index (const version)
Definition Histo.h:292
BinnedDbn(size_t nbinsX, double lowerX, double upperX, size_t nbinsY, double lowerY, double upperY, size_t nbinsZ, double lowerZ, double upperZ, const std::string &path="", const std::string &title="")
Constructor with auto-setup of evenly spaced axes.
Definition Histo.h:246
BinnedDbn(const BaseT &other)
Copy constructor (needed for clone functions).
Definition Histo.h:257
BinnedDbn(HistoT &&other, const std::string &path)
Definition Histo.h:264
BinType & bin(const size_t localX, const size_t localY, const size_t localZ) noexcept
Bin access using local indices.
Definition Histo.h:297
User-facing BinnedDbn class in arbitrary dimension.
Definition BinnedDbn.h:50
BinnedDbn< DbnN, AxisT... > HistoT
Definition BinnedDbn.h:52
BinnedDbn & operator=(const HistoT &)=default
void maskBin(const size_t indexToMask, const bool status=true) noexcept
Mask a bin at a given index.
BinT & bin(size_t idx) noexcept
Returns reference to the bin at idx.
BinT & binAt(typename BinningT::EdgeTypesTuple &&coords) noexcept
Returns reference to the bin at coordinates.
All histograms can be instantiated through this alias.
Definition BinnedDbn.h:116
virtual int fill(FillType &&coords, const double weight=1.0, const double fraction=1.0)
Triggers fill adapter on the bin corresponding to coords.
Definition BinnedDbn.h:229
typename BaseT::FillType FillType
Definition BinnedDbn.h:123
Anonymous namespace to limit visibility.
typename HistoMaker< std::make_index_sequence< N > >::type HistoND
Definition Histo.h:351
CRTP mixin introducing convenience aliases along X axis.
Definition BinnedUtils.h:18
CRTP mixin introducing convenience aliases to access statistics along X axis.
Definition BinnedUtils.h:73
CRTP mixin introducing convenience aliases along Y axis.
CRTP mixin introducing convenience aliases to access statistics along Y axis.
CRTP mixin introducing convenience aliases along Z axis.
CRTP mixin introducing convenience aliases to access statistics along Z axis.