yoda is hosted by Hepforge, IPPP Durham
YODA - Yet more Objects for Data Analysis 2.0.0
YODA::Binning< Axes > Class Template Reference

#include <Binning.h>

Public Member Functions

template<size_t I>
const Binning< Axes... >::template getAxisT< I > & axis () const noexcept
 
template<size_t I>
Binning< Axes... >::template getAxisT< I > & axis () noexcept
 
Constructors
 Binning ()
 Nullary constructor for unique pointers etc.
 
 Binning (const std::initializer_list< typename Axes::EdgeT > &... edges)
 Constructs binning from vectors of axes' edges.
 
 Binning (std::initializer_list< typename Axes::EdgeT > &&... edges)
 Constructs binning from Rvalue vectors of axes' edges.
 
 Binning (const Axes &... axes)
 Constructs binning from a sequence of axes.
 
 Binning (Axes &&... axes)
 Constructs binning from a sequence of Rvalue axes.
 
 Binning (const Binning &other)
 Copy constructor.
 
 Binning (Binning &&other)
 Move constructor.
 
Binningoperator= (const Binning &other)
 Copy assignment.
 
Binningoperator= (Binning &&other)
 Move assignment.
 
Indexing methods
size_t localToGlobalIndex (const IndexArr &localIndices) const
 calculates global index from array of local indices
 
IndexArr globalToLocalIndices (size_t globalIndex) const
 calculates array of local indices from a global index
 
IndexArr localIndicesAt (const EdgeTypesTuple &coords) const
 assembles array of local indices for an array of input values
 
size_t globalIndexAt (const EdgeTypesTuple &coords) const
 calculates global index for a given array of input values
 
std::vector< size_t > calcOverflowBinsIndices () const noexcept
 Calculates indices of overflow bins.
 
size_t countOverflowBins (const size_t axisN) const noexcept
 Count number of overflow bins.
 
std::vector< size_t > maskedBins () const noexcept
 Calculates indices of masked bins.
 
void clearMaskedBins () noexcept
 Clear masked bins.
 
void maskBin (const size_t index, const bool status=true)
 Mask/Unmask bin with global index index.
 
void maskBin (const IndexArr &localIndices, const bool status=true)
 Mask/Unmask bin with local localIndices.
 
void maskBinAt (const EdgeTypesTuple &coords, const bool status=true) noexcept
 Mask/Unmask bin at set of @ coords.
 
void maskBins (const std::vector< size_t > &indices, const bool status=true)
 Mask/Unmask bins in list of global indices.
 
void maskSlice (const size_t dim, const size_t idx, const bool status=true)
 Mask a slice of the binning at local bin index idx along axis dimesnion dim.
 
bool isMasked (const size_t i) const noexcept
 Check if bin is masked.
 
bool isVisible (const size_t i) const noexcept
 Check if bin is in visible range.
 
size_t calcSliceSize (const size_t pivotAxisN) const noexcept
 Calculates size of a binning slice.
 
std::vector< size_t > sliceIndices (std::vector< std::pair< size_t, std::vector< size_t > > >) const noexcept
 Calculates indices of bins located in the specified slices.
 
std::vector< size_t > sliceIndices (size_t axisN, size_t binN) const noexcept
 Calculates indices of bins located in the slice corresponding to bin at nBin at axis N.
 
void updateMaskedBins () noexcept
 Helper function to extract and mask index slices corresponding to masked bins along the axes.
 
Transformations
template<size_t... AxisNs>
void mergeBins (std::decay_t< decltype(AxisNs, std::declval< std::pair< size_t, size_t > >())>... mergeRanges) noexcept
 
Comparisons to other Binning objects
bool isCompatible (const Binning< Axes... > &other) const noexcept
 checks if Binnings are compatible
 
Getters
template<size_t I>
const getAxisT< I > & axis () const noexcept
 Extracts axis corresponding to dimension. Const version.
 
template<size_t I>
getAxisT< I > & axis () noexcept
 Extracts axis corresponding to dimension. Non-const version.
 
size_t dim () const noexcept
 get dimension of Binning
 
size_t numBins (const bool includeOverflows=true, const bool includeMaskedBins=true) const noexcept
 get total number of bins in Binning
 
size_t numBinsAt (const size_t axisN, const bool includeOverflows=true) const noexcept
 get number of bins at axis
 
EdgeTypesTuple edgeTuple (const size_t index) const noexcept
 Return a coordinate tuple for bin index.
 
template<size_t I, typename E = getEdgeT<I>>
std::vector< E > edges (const bool includeOverflows=false) const noexcept
 Templated version to get edges of axis N by value.
 
template<size_t I, typename E = getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, std::vector< E > > widths (const bool includeOverflows=false) const noexcept
 Templated version to get bin widths of axis N by reference.
 
template<size_t I, typename E = getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > min () const noexcept
 Get the lowest non-overflow edge of the axis.
 
template<size_t I, typename E = getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > max () const noexcept
 Get the highest non-overflow edge of the axis.
 
double dVol (const size_t index) const
 Return the differential volume for bin index.
 

Utilities

using IndexArr = std::array< size_t, sizeof...(Axes)>
 
template<size_t I>
using getAxisT = std::tuple_element_t< I, std::tuple< Axes... > >
 
template<size_t I>
using getEdgeT = typename getAxisT< I >::EdgeT
 
template<size_t I>
using is_CAxis = typename std::is_floating_point< getEdgeT< I > >
 
template<size_t I>
using is_Arithmetic = typename std::is_arithmetic< getEdgeT< I > >
 
using all_CAxes = typename std::conjunction< std::is_floating_point< typename Axes::EdgeT >... >
 
using EdgeTypesTuple = decltype(std::tuple_cat(std::declval< std::tuple< typename Axes::EdgeT > >()...))
 
using Dimension = std::integral_constant< size_t, sizeof...(Axes)>
 

Detailed Description

template<typename... Axes>
class YODA::Binning< Axes >

Definition at line 48 of file Binning.h.

Member Typedef Documentation

◆ all_CAxes

template<typename... Axes>
using YODA::Binning< Axes >::all_CAxes = typename std::conjunction<std::is_floating_point<typename Axes::EdgeT>...>

Definition at line 82 of file Binning.h.

◆ Dimension

template<typename... Axes>
using YODA::Binning< Axes >::Dimension = std::integral_constant<size_t, sizeof...(Axes)>

Definition at line 87 of file Binning.h.

◆ EdgeTypesTuple

template<typename... Axes>
using YODA::Binning< Axes >::EdgeTypesTuple = decltype( std::tuple_cat(std::declval<std::tuple<typename Axes::EdgeT> >()...))

Definition at line 84 of file Binning.h.

◆ getAxisT

template<typename... Axes>
template<size_t I>
using YODA::Binning< Axes >::getAxisT = std::tuple_element_t<I, std::tuple<Axes...> >

Definition at line 71 of file Binning.h.

◆ getEdgeT

template<typename... Axes>
template<size_t I>
using YODA::Binning< Axes >::getEdgeT = typename getAxisT<I>::EdgeT

Definition at line 74 of file Binning.h.

◆ IndexArr

template<typename... Axes>
using YODA::Binning< Axes >::IndexArr = std::array<size_t, sizeof...(Axes)>
protected

Definition at line 61 of file Binning.h.

◆ is_Arithmetic

template<typename... Axes>
template<size_t I>
using YODA::Binning< Axes >::is_Arithmetic = typename std::is_arithmetic<getEdgeT<I> >

Definition at line 80 of file Binning.h.

◆ is_CAxis

template<typename... Axes>
template<size_t I>
using YODA::Binning< Axes >::is_CAxis = typename std::is_floating_point<getEdgeT<I> >

Definition at line 77 of file Binning.h.

Constructor & Destructor Documentation

◆ Binning() [1/7]

template<typename... Axes>
YODA::Binning< Axes >::Binning ( )
inline

Nullary constructor for unique pointers etc.

Definition at line 95 of file Binning.h.

95{ }

◆ Binning() [2/7]

template<typename... Axes>
YODA::Binning< Axes >::Binning ( const std::initializer_list< typename Axes::EdgeT > &...  edges)
inline

Constructs binning from vectors of axes' edges.

Definition at line 98 of file Binning.h.

99 : _axes(Axes(edges)...) {
101 }
void updateMaskedBins() noexcept
Helper function to extract and mask index slices corresponding to masked bins along the axes.
Definition Binning.h:209
std::vector< E > edges(const bool includeOverflows=false) const noexcept
Templated version to get edges of axis N by value.
Definition Binning.h:286

References YODA::Binning< Axes >::updateMaskedBins().

◆ Binning() [3/7]

template<typename... Axes>
YODA::Binning< Axes >::Binning ( std::initializer_list< typename Axes::EdgeT > &&...  edges)
inline

Constructs binning from Rvalue vectors of axes' edges.

Definition at line 104 of file Binning.h.

105 : _axes(Axes(std::move(edges))...) {
107 }

References YODA::Binning< Axes >::updateMaskedBins().

◆ Binning() [4/7]

template<typename... Axes>
YODA::Binning< Axes >::Binning ( const Axes &...  axes)
inline

Constructs binning from a sequence of axes.

Definition at line 110 of file Binning.h.

111 : _axes(axes...) {
113 }

References YODA::Binning< Axes >::updateMaskedBins().

◆ Binning() [5/7]

template<typename... Axes>
YODA::Binning< Axes >::Binning ( Axes &&...  axes)
inline

Constructs binning from a sequence of Rvalue axes.

Definition at line 116 of file Binning.h.

117 : _axes(std::move(axes)...) {
119 }

References YODA::Binning< Axes >::updateMaskedBins().

◆ Binning() [6/7]

template<typename... Axes>
YODA::Binning< Axes >::Binning ( const Binning< Axes > &  other)
inline

Copy constructor.

Definition at line 122 of file Binning.h.

122: _axes(other._axes), _maskedIndices(other._maskedIndices) {}

◆ Binning() [7/7]

template<typename... Axes>
YODA::Binning< Axes >::Binning ( Binning< Axes > &&  other)
inline

Move constructor.

Definition at line 125 of file Binning.h.

125: _axes(std::move(other._axes)), _maskedIndices(std::move(other._maskedIndices)) {}

Member Function Documentation

◆ axis() [1/4]

template<typename... Axes>
template<size_t I>
const getAxisT< I > & YODA::Binning< Axes >::axis ( ) const
noexcept

◆ axis() [2/4]

template<typename... Axes>
template<size_t I>
const Binning< Axes... >::template getAxisT< I > & YODA::Binning< Axes >::axis ( ) const
noexcept

Definition at line 678 of file Binning.h.

678 {
679 return std::get<I>(_axes);
680 }

◆ axis() [3/4]

template<typename... Axes>
template<size_t I>
getAxisT< I > & YODA::Binning< Axes >::axis ( )
noexcept

Extracts axis corresponding to dimension. Non-const version.

◆ axis() [4/4]

template<typename... Axes>
template<size_t I>
Binning< Axes... >::template getAxisT< I > & YODA::Binning< Axes >::axis ( )
noexcept

Definition at line 685 of file Binning.h.

685 {
686 return std::get<I>(_axes);
687 }

◆ calcOverflowBinsIndices()

template<typename... Axes>
std::vector< size_t > YODA::Binning< Axes >::calcOverflowBinsIndices ( ) const
noexcept

Calculates indices of overflow bins.

Definition at line 451 of file Binning.h.

451 {
452 IndexArr axesSizes = _getAxesSizes();
453 std::vector<bool> isCAxis;
454
455 auto getCAxisIndices = [&isCAxis](auto I){
456 using isContinuous = typename Binning::template is_CAxis<I>;
457 isCAxis.emplace_back(isContinuous::value);
458 };
459
460 MetaUtils::staticFor<Dimension::value>(getCAxisIndices);
461
462 std::vector<std::pair<size_t, std::vector<size_t>>> slicePivots;
463 slicePivots.reserve(isCAxis.size());
464
465 for (size_t axisN = 0; axisN < isCAxis.size(); ++axisN) {
466 if (isCAxis[axisN])
467 slicePivots.push_back({axisN, {0, axesSizes[axisN]-1} });
468 else
469 slicePivots.push_back({axisN, {0} });
470 }
471
472 std::vector<size_t> res = sliceIndices(slicePivots);
473 std::sort(res.begin(), res.end());
474 res.erase( std::unique(res.begin(), res.end()), res.end() );
475 return res;
476 }
std::array< size_t, sizeof...(Axes)> IndexArr
Definition Binning.h:61
std::vector< size_t > sliceIndices(std::vector< std::pair< size_t, std::vector< size_t > > >) const noexcept
Calculates indices of bins located in the specified slices.
Definition Binning.h:574

◆ calcSliceSize()

template<typename... Axes>
size_t YODA::Binning< Axes >::calcSliceSize ( const size_t  pivotAxisN) const
noexcept

Calculates size of a binning slice.

Definition at line 561 of file Binning.h.

561 {
562 const IndexArr axesSizes = _getAxesSizes();
563 size_t sliceSize = 1;
564 for (size_t iDim = 0; iDim < _dim; ++iDim) {
565 if (iDim == pivotAxisN)
566 continue;
567 sliceSize *= (axesSizes[iDim]);
568 }
569 return sliceSize;
570 }

◆ clearMaskedBins()

template<typename... Axes>
void YODA::Binning< Axes >::clearMaskedBins ( )
inlinenoexcept

Clear masked bins.

Definition at line 172 of file Binning.h.

172{ _maskedIndices.clear(); }

◆ countOverflowBins()

template<typename... Axes>
size_t YODA::Binning< Axes >::countOverflowBins ( const size_t  axisN) const
noexcept

Count number of overflow bins.

Helper function to count the number of under/other/overflow bins for a given axis axisN.

Continuous axes have an underflow and an overflow bin (= 2). Discrete axes have an otherflow bin (= 1).

Definition at line 485 of file Binning.h.

485 {
486 std::vector<bool> CAxisIndices;
487
488 auto getCAxisIndices = [&CAxisIndices](auto I){
489 using isContinuous = typename Binning::template is_CAxis<I>;
490 CAxisIndices.emplace_back(isContinuous::value);
491 };
492
493 MetaUtils::staticFor<Dimension::value>(getCAxisIndices);
494 return CAxisIndices.at(axisN) + 1;
495 }

◆ dim()

template<typename... Axes>
size_t YODA::Binning< Axes >::dim ( ) const
noexcept

get dimension of Binning

Definition at line 711 of file Binning.h.

711 {
712 return _dim;
713 }

◆ dVol()

template<typename... Axes>
double YODA::Binning< Axes >::dVol ( const size_t  index) const

Return the differential volume for bin index.

Definition at line 784 of file Binning.h.

784 {
785 double rtn = 1.0;
786 IndexArr indices = globalToLocalIndices(index);
787
788 auto getCAxisWidths = [&rtn, &indices, &axes = _axes](auto I){
789 using isContinuous = typename Binning::template is_CAxis<I>;
790 if constexpr (isContinuous::value) {
791 const auto& axis = std::get<I>(axes);
792 const size_t idx = std::get<I>(indices);
793 rtn *= axis.width(idx);
794 }
795 };
796 MetaUtils::staticFor<Binning::Dimension::value>(getCAxisWidths);
797
798 return rtn;
799 }
const getAxisT< I > & axis() const noexcept
Extracts axis corresponding to dimension. Const version.
IndexArr globalToLocalIndices(size_t globalIndex) const
calculates array of local indices from a global index
Definition Binning.h:408

◆ edges()

template<typename... Axes>
template<size_t I, typename E = getEdgeT<I>>
std::vector< E > YODA::Binning< Axes >::edges ( const bool  includeOverflows = false) const
inlinenoexcept

Templated version to get edges of axis N by value.

+-inf edges are included, depending on the value of includeOverflows Needed by axis-specific version from StatsMixin

Definition at line 286 of file Binning.h.

286 {
287 const auto& axis = std::get<I>(_axes);
288 if (!includeOverflows && Binning::template is_CAxis<I>::value) {
289 auto&& all_edges = axis.edges();
290 typename std::vector<E> rtn;
291 const size_t offset = all_edges.size() - 1;
292 rtn.insert(rtn.end(), std::make_move_iterator(all_edges.begin()+1),
293 std::make_move_iterator(all_edges.begin()+offset));
294 return rtn;
295 }
296 return axis.edges();
297 }

References YODA::Binning< Axes >::axis().

◆ edgeTuple()

template<typename... Axes>
Binning< Axes... >::EdgeTypesTuple YODA::Binning< Axes >::edgeTuple ( const size_t  index) const
noexcept

Return a coordinate tuple for bin index.

Definition at line 762 of file Binning.h.

762 {
763
764 EdgeTypesTuple coords;
765 IndexArr indices = globalToLocalIndices(index);
766
767 auto setCoords = [&coords, &indices, &axes = _axes](auto I) {
768 using isContinuous = typename Binning::template is_CAxis<I>;
769 const auto& axis = std::get<I>(axes);
770 const size_t idx = std::get<I>(indices);
771 if constexpr(isContinuous::value) {
772 std::get<I>(coords) = axis.mid(idx);
773 }
774 else {
775 std::get<I>(coords) = axis.edge(idx);
776 }
777 };
778 MetaUtils::staticFor<Dimension::value>(setCoords);
779
780 return coords;
781 }
decltype(std::tuple_cat(std::declval< std::tuple< typename Axes::EdgeT > >()...)) EdgeTypesTuple
Definition Binning.h:85

◆ globalIndexAt()

template<typename... Axes>
size_t YODA::Binning< Axes >::globalIndexAt ( const EdgeTypesTuple coords) const

calculates global index for a given array of input values

Definition at line 446 of file Binning.h.

446 {
447 return localToGlobalIndex(localIndicesAt(coords));
448 }
IndexArr localIndicesAt(const EdgeTypesTuple &coords) const
assembles array of local indices for an array of input values
Definition Binning.h:431
size_t localToGlobalIndex(const IndexArr &localIndices) const
calculates global index from array of local indices
Definition Binning.h:386

Referenced by YODA::Binning< Axes >::maskBinAt().

◆ globalToLocalIndices()

template<typename... Axes>
Binning< Axes... >::IndexArr YODA::Binning< Axes >::globalToLocalIndices ( size_t  globalIndex) const

calculates array of local indices from a global index

Definition at line 408 of file Binning.h.

408 {
409 if (globalIndex >= numBins(true, true)) throw RangeError("Global index outside bin range");
410 IndexArr localIndices{};
411
412 IndexArr axesSizes = _getAxesSizes();
413
414 for (ssize_t iIndex = localIndices.size()-1 ; iIndex >= 0; --iIndex){
415 size_t productOfNestedBinSizes = 1;
416
417 for (ssize_t iBinnedAxis = iIndex - 1; iBinnedAxis >= 0; --iBinnedAxis) {
418 productOfNestedBinSizes *= (axesSizes[iBinnedAxis]);
419 }
420
421 // integer division to get the multiplier
422 localIndices[iIndex] = globalIndex / productOfNestedBinSizes;
423 // then left with only the remainder
424 globalIndex = globalIndex % productOfNestedBinSizes;
425 }
426 return localIndices;
427 }
size_t numBins(const bool includeOverflows=true, const bool includeMaskedBins=true) const noexcept
get total number of bins in Binning
Definition Binning.h:739

◆ isCompatible()

template<typename... Axes>
bool YODA::Binning< Axes >::isCompatible ( const Binning< Axes... > &  other) const
noexcept

checks if Binnings are compatible

Binnings are compatible if they have the same number of axes, and those axes have the same bin edges

If one comparison fails, isEqal will stay false

Definition at line 717 of file Binning.h.

717 {
718 // compatible if they have the same number of axes,
719 // and those axes have the same bin edges
720 if (_dim != other.dim())
721 return false;
722
723 std::array<bool, 1> isEqual{true};
724 auto isEqAxes =
725 [&isEqual, &axes1 = _axes, &axes2 = other._axes](auto I) {
726 const auto& axis_lhs = std::get<I>(axes1);
727 const auto& axis_rhs = std::get<I>(axes2);
728
730 isEqual[0] &= axis_lhs.hasSameEdges(axis_rhs);
731 };
732
733 MetaUtils::staticFor<Dimension::value>(isEqAxes);
734
735 return isEqual[0];
736 }

◆ isMasked()

template<typename... Axes>
bool YODA::Binning< Axes >::isMasked ( const size_t  i) const
noexcept

Check if bin is masked.

Definition at line 547 of file Binning.h.

547 {
548 const auto& itEnd = _maskedIndices.cend();
549 return std::find(_maskedIndices.cbegin(), itEnd, i) != itEnd;
550 }

◆ isVisible()

template<typename... Axes>
bool YODA::Binning< Axes >::isVisible ( const size_t  i) const
noexcept

Check if bin is in visible range.

Definition at line 554 of file Binning.h.

554 {
555 const std::vector<size_t> overflows = calcOverflowBinsIndices();
556 const auto& itEnd = overflows.cend();
557 return std::find(overflows.cbegin(), itEnd, i) == itEnd;
558 }
std::vector< size_t > calcOverflowBinsIndices() const noexcept
Calculates indices of overflow bins.
Definition Binning.h:451

◆ localIndicesAt()

template<typename... Axes>
Binning< Axes... >::IndexArr YODA::Binning< Axes >::localIndicesAt ( const EdgeTypesTuple coords) const

assembles array of local indices for an array of input values

Definition at line 431 of file Binning.h.

431 {
432 IndexArr localIndices{};
433 auto extractIndices = [&localIndices, &coords, &axes = _axes](auto I) {
434 const auto& coord = std::get<I>(coords);
435 const auto& axis = std::get<I>(axes);
436
437 localIndices[I] = axis.index(coord);
438 };
439
440 MetaUtils::staticFor<Dimension::value>(extractIndices);
441
442 return localIndices;
443 }

◆ localToGlobalIndex()

template<typename... Axes>
size_t YODA::Binning< Axes >::localToGlobalIndex ( const IndexArr localIndices) const

calculates global index from array of local indices

x + y*width + z*width*height + w*width*height*depth + ...

Definition at line 386 of file Binning.h.

386 {
387 size_t gIndex = 0;
388 // std::string st_indices = "";
389 // for (size_t iIndex = 0; iIndex < localIndices.size(); ++iIndex) {
390 // st_indices += "|";
391 // st_indices += std::to_string(localIndices[iIndex]);
392 // }
393
395 IndexArr axesSizes = _getAxesSizes();
396 for (size_t iIndex = 0; iIndex < localIndices.size(); ++iIndex) {
397 size_t productOfBinSizes = 1;
398 for (ssize_t iBinnedAxis = iIndex - 1; iBinnedAxis >= 0; --iBinnedAxis) {
399 productOfBinSizes *= (axesSizes[iBinnedAxis]);
400 }
401 gIndex += localIndices[iIndex] * productOfBinSizes;
402 }
403 return gIndex;
404 }

Referenced by YODA::Binning< Axes >::maskBin().

◆ maskBin() [1/2]

template<typename... Axes>
void YODA::Binning< Axes >::maskBin ( const IndexArr localIndices,
const bool  status = true 
)

Mask/Unmask bin with local localIndices.

Definition at line 517 of file Binning.h.

517 {
518 const size_t gIndex = Binning<Axes...>::localToGlobalIndex(localIndices);
519 Binning<Axes...>::maskBins({{gIndex}}, status);
520 }
void maskBins(const std::vector< size_t > &indices, const bool status=true)
Mask/Unmask bins in list of global indices.
Definition Binning.h:529

References YODA::Binning< Axes >::localToGlobalIndex(), and YODA::Binning< Axes >::maskBins().

◆ maskBin() [2/2]

template<typename... Axes>
void YODA::Binning< Axes >::maskBin ( const size_t  index,
const bool  status = true 
)

Mask/Unmask bin with global index index.

Only visible in this translation unit.

Definition at line 512 of file Binning.h.

512 {
513 Binning<Axes...>::maskBins({{index}}, status);
514 }

References YODA::Binning< Axes >::maskBins().

◆ maskBinAt()

template<typename... Axes>
void YODA::Binning< Axes >::maskBinAt ( const EdgeTypesTuple coords,
const bool  status = true 
)
noexcept

Mask/Unmask bin at set of @ coords.

Definition at line 523 of file Binning.h.

523 {
524 const size_t gIndex = Binning<Axes...>::globalIndexAt(coords);
525 Binning<Axes...>::maskBins({{gIndex}}, status);
526 }
size_t globalIndexAt(const EdgeTypesTuple &coords) const
calculates global index for a given array of input values
Definition Binning.h:446

References YODA::Binning< Axes >::globalIndexAt(), and YODA::Binning< Axes >::maskBins().

◆ maskBins()

template<typename... Axes>
void YODA::Binning< Axes >::maskBins ( const std::vector< size_t > &  indices,
const bool  status = true 
)

Mask/Unmask bins in list of global indices.

Definition at line 529 of file Binning.h.

529 {
530 for (size_t i : indices) {
531 const auto& itEnd = this->_maskedIndices.cend();
532 const auto& res = std::find(this->_maskedIndices.cbegin(), itEnd, i);
533 if (status && res == itEnd) this->_maskedIndices.push_back(i);
534 else if (!status && res != itEnd) this->_maskedIndices.erase(res);
535 }
536 }

Referenced by YODA::Binning< Axes >::maskBin(), YODA::Binning< Axes >::maskBin(), YODA::Binning< Axes >::maskBinAt(), and YODA::Binning< Axes >::maskSlice().

◆ maskedBins()

template<typename... Axes>
std::vector< size_t > YODA::Binning< Axes >::maskedBins ( ) const
inlinenoexcept

Calculates indices of masked bins.

Definition at line 169 of file Binning.h.

169{ return _maskedIndices; }

◆ maskSlice()

template<typename... Axes>
void YODA::Binning< Axes >::maskSlice ( const size_t  dim,
const size_t  idx,
const bool  status = true 
)

Mask a slice of the binning at local bin index idx along axis dimesnion dim.

Definition at line 539 of file Binning.h.

539 {
540 //_binning.maskSlice(dim, idx, status);
541 std::vector<std::pair<size_t, std::vector<size_t>>> slicePivot{{dim,{idx}}};
542 std::vector<size_t> indices = Binning<Axes...>::sliceIndices(slicePivot);
543 Binning<Axes...>::maskBins(indices, status);
544 }
size_t dim() const noexcept
get dimension of Binning
Definition Binning.h:711

References YODA::Binning< Axes >::maskBins(), and YODA::Binning< Axes >::sliceIndices().

◆ max()

template<typename... Axes>
template<size_t I, typename E = getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > YODA::Binning< Axes >::max ( ) const
inlinenoexcept

Get the highest non-overflow edge of the axis.

Note
This method is only supported for continuous axes

Definition at line 326 of file Binning.h.

326 {
327 const auto& axis = std::get<I>(_axes);
328 assert(axis.numBins(true) > 2); // More than 2 overflow bins.
329 return axis.min(axis.numBins(true)-1); // Bin 0 is the underflow bin.
330 }

References YODA::Binning< Axes >::axis().

◆ mergeBins()

template<typename... Axes>
template<size_t... AxisNs>
void YODA::Binning< Axes >::mergeBins ( std::decay_t< decltype(AxisNs, std::declval< std::pair< size_t, size_t > >())>...  mergeRanges)
noexcept

Definition at line 666 of file Binning.h.

667 {
668
669 ((void)axis<AxisNs>().mergeBins(mergeRanges), ...);
671
672 }

◆ min()

template<typename... Axes>
template<size_t I, typename E = getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, E > YODA::Binning< Axes >::min ( ) const
inlinenoexcept

Get the lowest non-overflow edge of the axis.

Note
This method is only supported for continuous axes

Definition at line 316 of file Binning.h.

316 {
317 const auto& axis = std::get<I>(_axes);
318 assert(axis.numBins(true) > 2); // More than 2 overflow bins.
319 return axis.min(1); // Bin 0 is the underflow bin.
320 }

References YODA::Binning< Axes >::axis().

◆ numBins()

template<typename... Axes>
size_t YODA::Binning< Axes >::numBins ( const bool  includeOverflows = true,
const bool  includeMaskedBins = true 
) const
noexcept

get total number of bins in Binning

Definition at line 739 of file Binning.h.

739 {
740 size_t nBins = 0;
741 IndexArr axesSizes = _getAxesSizes(includeOverflows);
742 assert(axesSizes.size() > 0);
743 nBins = axesSizes[0];
744 if constexpr (sizeof...(Axes) > 1) {
745 for (size_t iDim = 1; iDim < _dim; ++iDim) {
746 nBins *= (axesSizes[iDim]);
747 }
748 }
749 const size_t maskedBins = includeMaskedBins? 0 : _maskedIndices.size();
750 return nBins - maskedBins;
751 }
std::vector< size_t > maskedBins() const noexcept
Calculates indices of masked bins.
Definition Binning.h:169

◆ numBinsAt()

template<typename... Axes>
size_t YODA::Binning< Axes >::numBinsAt ( const size_t  axisN,
const bool  includeOverflows = true 
) const
noexcept

get number of bins at axis

Definition at line 754 of file Binning.h.

754 {
755 IndexArr axesSizes = _getAxesSizes(includeOverflows);
756 assert(axesSizes.size() > 0);
757 return axesSizes[axisN];
758 }

◆ operator=() [1/2]

template<typename... Axes>
Binning & YODA::Binning< Axes >::operator= ( Binning< Axes > &&  other)
inline

Move assignment.

Definition at line 137 of file Binning.h.

137 {
138 if (this != &other) {
139 _axes = std::move(other._axes);
140 _maskedIndices = std::move(other._maskedIndices);
141 }
142 return *this;
143 }

◆ operator=() [2/2]

template<typename... Axes>
Binning & YODA::Binning< Axes >::operator= ( const Binning< Axes > &  other)
inline

Copy assignment.

Definition at line 128 of file Binning.h.

128 {
129 if (this != &other) {
130 _axes = other._axes;
131 _maskedIndices = other._maskedIndices;
132 }
133 return *this;
134 }

◆ sliceIndices() [1/2]

template<typename... Axes>
std::vector< size_t > YODA::Binning< Axes >::sliceIndices ( size_t  axisN,
size_t  binN 
) const
noexcept

Calculates indices of bins located in the slice corresponding to bin at nBin at axis N.

x + y*width + (const value of pivot bin)*width*height + w*width*height*depth + ...

Definition at line 612 of file Binning.h.

612 {
613 if(sizeof...(Axes) == 1) {
614 return {binN};
615 }
617 const IndexArr axesSizes = _getAxesSizes();
618 const size_t sliceSize = calcSliceSize(axisN);
619
620 IndexArr multiIdx{};
621 multiIdx[axisN] = binN;
622 std::vector<size_t> slicedIndices;
623
624 assert(axesSizes.size() != 0);
625 slicedIndices.reserve(sliceSize);
626
627 /* @note Iteratively generates permutations of multindex for fixed
633 */
634 size_t idxShift = axisN == 0 ? 1 : 0;
635
636 size_t idx = idxShift;
637
638 while (true) {
639 slicedIndices.emplace_back(localToGlobalIndex(multiIdx));
640
641 multiIdx[idx]++;
642
643 while (multiIdx[idx] == axesSizes[idx] || idx == axisN) {
644 // Overflow, we're done
645 if (idx == axesSizes.size() - 1) {
646 return slicedIndices;
647 }
648
649 if(idx != axisN)
650 multiIdx[idx] = 0;
651
652 idx++;
653
654 if(idx != axisN)
655 multiIdx[idx]++;
656 }
657
658 idx = idxShift;
659 }
660
661 return slicedIndices;
662 }
size_t calcSliceSize(const size_t pivotAxisN) const noexcept
Calculates size of a binning slice.
Definition Binning.h:561

◆ sliceIndices() [2/2]

template<typename... Axes>
std::vector< size_t > YODA::Binning< Axes >::sliceIndices ( std::vector< std::pair< size_t, std::vector< size_t > > >  slicePivots) const
noexcept

Calculates indices of bins located in the specified slices.

Note
Accept vector of pairs where pair.first is index of axis, and pair.second is slice pivot bins on this axis.

Definition at line 574 of file Binning.h.

574 {
575
576 std::vector<size_t> slicesSizes;
577 slicesSizes.reserve(slicePivots.size());
578 size_t slicedIndicesVecSize = 0;
579
580 for (const auto& slicePivot : slicePivots) {
581 if(slicePivot.second.size() == 0)
582 continue;
583
584 const size_t& sliceSize = calcSliceSize(slicePivot.first);
585
586 slicesSizes.emplace_back(sliceSize);
587 slicedIndicesVecSize += sliceSize;
588 }
589
590 std::vector<size_t> slicedIndices;
591 slicedIndices.reserve(slicedIndicesVecSize);
592
593 auto appendSliceIndices = [&slicedIndices](std::vector<size_t>&& overflowSlice) {
594 slicedIndices.insert(std::end(slicedIndices),
595 std::make_move_iterator(std::begin(overflowSlice)),
596 std::make_move_iterator(std::end(overflowSlice)));
597 };
598
599 for (const auto& slicePivot : slicePivots) {
600 const size_t axisN = slicePivot.first;
601 const auto& binPivots = slicePivot.second;
602
603 for(const auto& binPivot : binPivots) {
604 appendSliceIndices(sliceIndices(axisN, binPivot));
605 }
606 }
607
608 return slicedIndices;
609 }

Referenced by YODA::Binning< Axes >::maskSlice(), YODA::BinnedStorage< BinContentT, AxisT >::mergeBins(), and YODA::Binning< Axes >::updateMaskedBins().

◆ updateMaskedBins()

template<typename... Axes>
void YODA::Binning< Axes >::updateMaskedBins ( )
inlinenoexcept

Helper function to extract and mask index slices corresponding to masked bins along the axes.

Definition at line 209 of file Binning.h.

209 {
210
211 std::vector<std::pair<size_t, std::vector<size_t>>> slicePivots;
212 auto extractMaskedBins = [&slicePivots, &axes = _axes](auto I) {
213 using isContinuous = typename Binning::template is_CAxis<I>;
214
215 if constexpr(isContinuous::value) {
216 const auto& axis = std::get<I>(axes);
217 slicePivots.push_back({I, {axis.maskedBins()} });
218 }
219 };
220
221 // apply for all axes
222 MetaUtils::staticFor<Dimension::value>(extractMaskedBins);
223
224 // get indices along slice pivots and remove duplicates
225 _maskedIndices = sliceIndices(slicePivots);
226 std::sort(_maskedIndices.begin(), _maskedIndices.end());
227 _maskedIndices.erase( std::unique(_maskedIndices.begin(), _maskedIndices.end()),
228 _maskedIndices.end() );
229 }

References YODA::Binning< Axes >::axis(), and YODA::Binning< Axes >::sliceIndices().

Referenced by YODA::Binning< Axes >::Binning(), YODA::Binning< Axes >::Binning(), YODA::Binning< Axes >::Binning(), and YODA::Binning< Axes >::Binning().

◆ widths()

template<typename... Axes>
template<size_t I, typename E = getEdgeT<I>>
std::enable_if_t< std::is_floating_point< E >::value, std::vector< E > > YODA::Binning< Axes >::widths ( const bool  includeOverflows = false) const
inlinenoexcept

Templated version to get bin widths of axis N by reference.

Overflows are included depending on includeOverflows Needed by axis-specific version from AxisMixin

Note
This version is only supported for continuous axes.

Definition at line 307 of file Binning.h.

307 {
308 const auto& axis = std::get<I>(_axes);
309 return axis.widths(includeOverflows);
310 }

References YODA::Binning< Axes >::axis().


The documentation for this class was generated from the following file: