yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
Profile.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_Profile_h
7#define YODA_Profile_h
8
9#include "YODA/BinnedDbn.h"
10
11namespace YODA {
12
14 template <typename AxisT>
15 class BinnedDbn<2, AxisT>
16 : public DbnStorage<2, AxisT>,
17 public XAxisMixin<BinnedDbn<2, AxisT>, AxisT>,
18 public XStatsMixin<BinnedDbn<2, AxisT>> {
19 public:
20
23 using FillType = typename BaseT::FillType;
24 using BinType = typename BaseT::BinT;
25 using Ptr = std::shared_ptr<ProfileT>;
26
28 using BaseT::BaseT;
29
30 BinnedDbn() = default;
31 BinnedDbn(const ProfileT&) = default;
32 BinnedDbn(ProfileT&&) = default;
33 BinnedDbn& operator =(const ProfileT&) = default;
35 using AnalysisObject::operator =;
36
40 BinnedDbn(const BaseT& other) : BaseT(other) {}
41 //
42 BinnedDbn(const ProfileT& other, const std::string& path) : BaseT(other, path) {}
43
45 BinnedDbn(BaseT&& other) : BaseT(std::move(other)) {}
46 //
47 BinnedDbn(ProfileT&& other, const std::string& path) : BaseT(std::move(other), path) {}
48
55 template <typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT>>
56 BinnedDbn(size_t nbins, double lower, double upper,
57 const std::string& path = "", const std::string& title = "")
58 : BaseT({nbins}, {{lower, upper}}, path, title) {}
59
61 ProfileT clone() const noexcept {
62 return ProfileT(*this);
63 }
64
66 ProfileT* newclone() const noexcept {
67 return new ProfileT(*this);
68 }
69
71 virtual int fill(const AxisT valX, const double valY, const double weight = 1.0, const double fraction = 1.0) {
72 return BaseT::fill({valX, valY}, 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
94 template <typename AxisT1, typename AxisT2>
95 class BinnedDbn<3, AxisT1, AxisT2>
96 : public DbnStorage<3, AxisT1, AxisT2>,
97 public XAxisMixin<BinnedDbn<3, AxisT1, AxisT2>, AxisT1>,
98 public XStatsMixin<BinnedDbn<3, AxisT1, AxisT2>>,
99 public YAxisMixin<BinnedDbn<3, AxisT1, AxisT2>, AxisT2>,
100 public YStatsMixin<BinnedDbn<3, AxisT1, AxisT2>> {
101 public:
102
105 using FillType = typename BaseT::FillType;
106 using BinType = typename BaseT::BinT;
107 using Ptr = std::shared_ptr<ProfileT>;
108
110 using BaseT::BaseT;
111
112 BinnedDbn() = default;
113 BinnedDbn(const ProfileT&) = default;
114 BinnedDbn(ProfileT&&) = default;
115 BinnedDbn& operator =(const ProfileT&) = default;
117 using AnalysisObject::operator =;
118
122 BinnedDbn(const BaseT& other) : BaseT(other) {}
123 //
124 BinnedDbn(const ProfileT& other, const std::string& path) : BaseT(other, path) {}
125
127 BinnedDbn(BaseT&& other) : BaseT(std::move(other)) {}
128 //
129 BinnedDbn(ProfileT&& other, const std::string& path) : BaseT(std::move(other), path) {}
130
137 template <typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT1, AxisT2>>
138 BinnedDbn(size_t nbinsX, double lowerX, double upperX,
139 size_t nbinsY, double lowerY, double upperY,
140 const std::string& path, const std::string& title = "")
141 : BaseT({nbinsX, nbinsY}, {{lowerX, upperX}, {lowerY, upperY}}, path, title) {}
142
144 ProfileT clone() const noexcept {
145 return ProfileT(*this);
146 }
147
149 ProfileT* newclone() const noexcept {
150 return new ProfileT(*this);
151 }
152
154 virtual int fill(const AxisT1 valX, const AxisT2 valY, const double valZ, const double weight = 1.0, const double fraction = 1.0) {
155 return BaseT::fill({valX, valY, valZ}, weight, fraction);
156 }
157
159 virtual int fill(FillType&& coords, const double weight = 1.0, const double fraction = 1.0) {
160 return BaseT::fill(std::move(coords), weight, fraction);
161 }
162
164 BinType& bin(const size_t index) noexcept {
165 return BaseT::bin(index);
166 }
167
169 const BinType& bin(const size_t index) const noexcept {
170 return BaseT::bin(index);
171 }
172
174 BinType& bin(const size_t localX, const size_t localY) noexcept {
175 return BaseT::bin( {localX, localY} );
176 }
177
179 const BinType& bin(const size_t localX, const size_t localY) const noexcept {
180 return BaseT::bin( {localX, localY} );
181 }
182
184 BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord) noexcept {
185 return BaseT::binAt( {xCoord, yCoord} );
186 }
187
189 const BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept {
190 return BaseT::binAt( {xCoord, yCoord} );
191 }
192
194 size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept {
195 return BaseT::binAt( {xCoord, yCoord} ).index();
196 }
197
199 void maskBinAt(const AxisT1 xCoord, const AxisT2 yCoord, const bool status = true) noexcept {
200 return BaseT::maskBin({xCoord, yCoord}, status);
201 }
202
203 };
204
205
206
208 template <typename AxisT1, typename AxisT2, typename AxisT3>
209 class BinnedDbn<4, AxisT1, AxisT2, AxisT3>
210 : public DbnStorage<4, AxisT1, AxisT2, AxisT3>,
211 public XAxisMixin<BinnedDbn<4, AxisT1, AxisT2, AxisT3>, AxisT1>,
212 public XStatsMixin<BinnedDbn<4, AxisT1, AxisT2, AxisT3>>,
213 public YAxisMixin<BinnedDbn<4, AxisT1, AxisT2, AxisT3>, AxisT3>,
214 public YStatsMixin<BinnedDbn<4, AxisT1, AxisT2, AxisT3>> {
215 public:
216
219 using FillType = typename BaseT::FillType;
220 using BinType = typename BaseT::BinT;
221 using Ptr = std::shared_ptr<ProfileT>;
222
224 using BaseT::BaseT;
225
226 BinnedDbn() = default;
227 BinnedDbn(const ProfileT&) = default;
228 BinnedDbn(ProfileT&&) = default;
229 BinnedDbn& operator =(const ProfileT&) = default;
231 using AnalysisObject::operator =;
232
236 BinnedDbn(const BaseT& other) : BaseT(other) {}
237 //
238 BinnedDbn(const ProfileT& other, const std::string& path) : BaseT(other, path) {}
239
241 BinnedDbn(BaseT&& other) : BaseT(std::move(other)) {}
242 //
243 BinnedDbn(ProfileT&& other, const std::string& path) : BaseT(std::move(other), path) {}
244
251 template <typename EdgeT = double, typename = enable_if_all_CAxisT<EdgeT, AxisT1, AxisT2, AxisT3>>
252 BinnedDbn(size_t nbinsX, double lowerX, double upperX,
253 size_t nbinsY, double lowerY, double upperY,
254 size_t nbinsZ, double lowerZ, double upperZ,
255 const std::string& path, const std::string& title = "")
256 : BaseT({nbinsX, nbinsY, nbinsZ},
257 {{lowerX, upperX}, {lowerY, upperY},
258 {lowerZ, upperZ}}, path, title) {}
259
261 ProfileT clone() const noexcept {
262 return ProfileT(*this);
263 }
264
266 ProfileT* newclone() const noexcept {
267 return new ProfileT(*this);
268 }
269
271 virtual int fill(const AxisT1 valX, const AxisT2 valY, const AxisT3 valZ, const double valZplus,
272 const double weight = 1.0, const double fraction = 1.0) {
273 return BaseT::fill({valX, valY, valZ, valZplus}, weight, fraction);
274 }
275
277 virtual int fill(FillType&& coords, const double weight = 1.0, const double fraction = 1.0) {
278 return BaseT::fill(std::move(coords), weight, fraction);
279 }
280
282 BinType& bin(const size_t index) noexcept {
283 return BaseT::bin(index);
284 }
285
287 const BinType& bin(const size_t index) const noexcept {
288 return BaseT::bin(index);
289 }
290
292 BinType& bin(const size_t localX, const size_t localY, const size_t localZ) noexcept {
293 return BaseT::bin( {localX, localY, localZ} );
294 }
295
297 const BinType& bin(const size_t localX, const size_t localY, const size_t localZ) const noexcept {
298 return BaseT::bin( {localX, localY, localZ} );
299 }
300
302 BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) noexcept {
303 return BaseT::binAt( {xCoord, yCoord, zCoord} );
304 }
305
307 const BinType& binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept {
308 return BaseT::binAt( {xCoord, yCoord, zCoord} );
309 }
310
312 size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept {
313 return BaseT::binAt( {xCoord, yCoord, zCoord} ).index();
314 }
315
317 void maskBinAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord, const bool status = true) noexcept {
318 return BaseT::maskBin({xCoord, yCoord, zCoord}, status);
319 }
320
321 };
322
323
325 template<typename A1>
327
328 template <typename A1, typename A2>
330
331 template <typename A1, typename A2, typename A3>
333
335 namespace {
336 template <class T>
337 struct ProfileMaker;
338
339 template<size_t... Is>
340 struct ProfileMaker<std::index_sequence<Is...>> {
342 };
343 }
344
346 template<size_t N>
347 using ProfileND = typename ProfileMaker<std::make_index_sequence<N>>::type;
348
353
354}
355
356#endif
357
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 profile.
Definition Profile.h:18
virtual int fill(FillType &&coords, const double weight=1.0, const double fraction=1.0)
Fill function with FillType.
Definition Profile.h:76
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 Profile.h:56
ProfileT * newclone() const noexcept
Make a copy on the heap.
Definition Profile.h:66
BinnedDbn(const BaseT &other)
Copy constructor (needed for clone functions).
Definition Profile.h:40
BinnedDbn(const ProfileT &)=default
BinnedDbn(const ProfileT &other, const std::string &path)
Definition Profile.h:42
std::shared_ptr< ProfileT > Ptr
Definition Profile.h:25
void maskBinAt(const AxisT xCoord, const bool status=true) noexcept
Mask/Unmask bin at given set of coordinates.
Definition Profile.h:86
virtual int fill(const AxisT valX, const double valY, const double weight=1.0, const double fraction=1.0)
Fill function with an explicit coordinate.
Definition Profile.h:71
BinnedDbn(BaseT &&other)
Move constructor.
Definition Profile.h:45
ProfileT clone() const noexcept
Make a copy on the stack.
Definition Profile.h:61
BinnedDbn(ProfileT &&)=default
typename BaseT::BinT BinType
Definition Profile.h:24
BinnedDbn(ProfileT &&other, const std::string &path)
Definition Profile.h:47
typename BaseT::FillType FillType
Definition Profile.h:23
size_t indexAt(const AxisT xCoord) const noexcept
Find bin index for given coordinates.
Definition Profile.h:81
Specialisation of the BinnedDbn for a 2D profile.
Definition Profile.h:100
BinnedDbn(const ProfileT &other, const std::string &path)
Definition Profile.h:124
const BinType & bin(const size_t localX, const size_t localY) const noexcept
Bin access using local indices (const version)
Definition Profile.h:179
virtual int fill(FillType &&coords, const double weight=1.0, const double fraction=1.0)
Fill function with FillType.
Definition Profile.h:159
typename BaseT::BinT BinType
Definition Profile.h:106
BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord) noexcept
Bin access using coordinates.
Definition Profile.h:184
ProfileT clone() const noexcept
Make a copy on the stack.
Definition Profile.h:144
BinType & bin(const size_t localX, const size_t localY) noexcept
Bin access using local indices.
Definition Profile.h:174
const BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept
Bin access using coordinates (const version)
Definition Profile.h:189
typename BaseT::FillType FillType
Definition Profile.h:105
ProfileT * newclone() const noexcept
Make a copy on the heap.
Definition Profile.h:149
BinnedDbn(ProfileT &&other, const std::string &path)
Definition Profile.h:129
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 Profile.h:138
size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord) const noexcept
Find bin index for given coordinates.
Definition Profile.h:194
std::shared_ptr< ProfileT > Ptr
Definition Profile.h:107
BinnedDbn(BaseT &&other)
Move constructor.
Definition Profile.h:127
void maskBinAt(const AxisT1 xCoord, const AxisT2 yCoord, const bool status=true) noexcept
Mask/Unmask bin at given set of coordinates.
Definition Profile.h:199
virtual int fill(const AxisT1 valX, const AxisT2 valY, const double valZ, const double weight=1.0, const double fraction=1.0)
Fill function with two explicit coordinates.
Definition Profile.h:154
BinnedDbn(const ProfileT &)=default
BinnedDbn(const BaseT &other)
Copy constructor (needed for clone functions).
Definition Profile.h:122
BinType & bin(const size_t index) noexcept
Bin access using global index.
Definition Profile.h:164
const BinType & bin(const size_t index) const noexcept
Bin access using global index (const version)
Definition Profile.h:169
Specialisation of the BinnedDbn for a 2D profile.
Definition Profile.h:214
BinnedDbn(BaseT &&other)
Move constructor.
Definition Profile.h:241
const BinType & bin(const size_t index) const noexcept
Bin access using global index (const version)
Definition Profile.h:287
ProfileT * newclone() const noexcept
Make a copy on the heap.
Definition Profile.h:266
BinnedDbn(const ProfileT &other, const std::string &path)
Definition Profile.h:238
BinType & bin(const size_t localX, const size_t localY, const size_t localZ) noexcept
Bin access using local indices.
Definition Profile.h:292
size_t indexAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept
Find bin index for given coordinates.
Definition Profile.h:312
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 Profile.h:252
BinType & bin(const size_t index) noexcept
Bin access using global index.
Definition Profile.h:282
std::shared_ptr< ProfileT > Ptr
Definition Profile.h:221
BinnedDbn(const BaseT &other)
Copy constructor (needed for clone functions).
Definition Profile.h:236
BinnedDbn(ProfileT &&other, const std::string &path)
Definition Profile.h:243
virtual int fill(const AxisT1 valX, const AxisT2 valY, const AxisT3 valZ, const double valZplus, const double weight=1.0, const double fraction=1.0)
Fill function with three explicit coordinates.
Definition Profile.h:271
const BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) const noexcept
Bin access using coordinates (const version)
Definition Profile.h:307
BinType & binAt(const AxisT1 xCoord, const AxisT2 yCoord, const AxisT3 zCoord) noexcept
Bin access using coordinates.
Definition Profile.h:302
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 Profile.h:297
virtual int fill(FillType &&coords, const double weight=1.0, const double fraction=1.0)
Fill function with FillType.
Definition Profile.h:277
ProfileT clone() const noexcept
Make a copy on the stack.
Definition Profile.h:261
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 Profile.h:317
User-facing BinnedDbn class in arbitrary dimension.
Definition BinnedDbn.h:50
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 ProfileMaker< std::make_index_sequence< N > >::type ProfileND
User-friendly name for the N-dimensional profile with all-continuous axes.
Definition Profile.h:347
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.