YODA::Binning< Axes > Class Template Reference
Detailed DescriptionMember Typedef Documentation◆ all_CAxes
template<typename... Axes>
◆ Dimension
template<typename... Axes>
◆ EdgeTypesTuple
template<typename... Axes>
◆ getAxisT
template<typename... Axes>
template<size_t I>
◆ getEdgeT
template<typename... Axes>
template<size_t I>
◆ IndexArr
template<typename... Axes>
◆ is_Arithmetic
template<typename... Axes>
template<size_t I>
◆ is_CAxis
template<typename... Axes>
template<size_t I>
Constructor & Destructor Documentation◆ Binning() [1/7]
template<typename... Axes>
◆ Binning() [2/7]
template<typename... Axes>
Constructs binning from vectors of axes' edges. Definition at line 98 of file Binning.h. 99 : _axes(Axes(edges)...) {
100 updateMaskedBins();
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>
Constructs binning from Rvalue vectors of axes' edges. Definition at line 104 of file Binning.h. References YODA::Binning< Axes >::updateMaskedBins(). ◆ Binning() [4/7]
template<typename... Axes>
Constructs binning from a sequence of axes. Definition at line 110 of file Binning.h. References YODA::Binning< Axes >::updateMaskedBins(). ◆ Binning() [5/7]
template<typename... Axes>
Constructs binning from a sequence of Rvalue axes. Definition at line 116 of file Binning.h. References YODA::Binning< Axes >::updateMaskedBins(). ◆ Binning() [6/7]
template<typename... Axes>
◆ Binning() [7/7]
template<typename... Axes>
Member Function Documentation◆ axis() [1/4]
template<typename... Axes>
template<size_t I>
Extracts axis corresponding to dimension. Const version. Referenced by YODA::Binning< Axes >::edges(), YODA::Binning< Axes >::max(), YODA::Binning< Axes >::min(), YODA::Binning< Axes >::updateMaskedBins(), and YODA::Binning< Axes >::widths(). ◆ axis() [2/4]
template<typename... Axes>
template<size_t I>
◆ axis() [3/4]
template<typename... Axes>
template<size_t I>
Extracts axis corresponding to dimension. Non-const version. ◆ axis() [4/4]
template<typename... Axes>
template<size_t I>
◆ calcOverflowBinsIndices()
template<typename... Axes>
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::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>
◆ clearMaskedBins()
template<typename... Axes>
◆ countOverflowBins()
template<typename... Axes>
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>
◆ dVol()
template<typename... Axes>
Return the differential volume for bin index. Definition at line 784 of file Binning.h. 784 {
785 double rtn = 1.0;
787
788 auto getCAxisWidths = [&rtn, &indices, &axes = _axes](auto I){
789 using isContinuous = typename Binning::template is_CAxis<I>;
790 if constexpr (isContinuous::value) {
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>>
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 {
288 if (!includeOverflows && Binning::template is_CAxis<I>::value) {
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 }
297 }
References YODA::Binning< Axes >::axis(). ◆ edgeTuple()
template<typename... Axes>
Return a coordinate tuple for bin index. Definition at line 762 of file Binning.h. 762 {
763
764 EdgeTypesTuple coords;
766
767 auto setCoords = [&coords, &indices, &axes = _axes](auto I) {
768 using isContinuous = typename Binning::template is_CAxis<I>;
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>
calculates global index for a given array of input values Definition at line 446 of file Binning.h. 446 {
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>
calculates array of local indices from a global index Definition at line 408 of file Binning.h. 408 {
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>
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>
◆ isVisible()
template<typename... Axes>
Check if bin is in visible range. Definition at line 554 of file Binning.h. 554 {
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>
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);
436
437 localIndices[I] = axis.index(coord);
438 };
439
440 MetaUtils::staticFor<Dimension::value>(extractIndices);
441
442 return localIndices;
443 }
◆ localToGlobalIndex()
template<typename... Axes>
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>
Mask/Unmask bin with local localIndices. Definition at line 517 of file Binning.h. 517 {
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>
Mask/Unmask bin with global index index. Only visible in this translation unit. Definition at line 512 of file Binning.h. References YODA::Binning< Axes >::maskBins(). ◆ maskBinAt()
template<typename... Axes>
Mask/Unmask bin at set of @ coords. Definition at line 523 of file Binning.h. 523 {
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>
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>
◆ maskSlice()
template<typename... Axes>
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 }
References YODA::Binning< Axes >::maskBins(), and YODA::Binning< Axes >::sliceIndices(). ◆ max()
template<typename... Axes>
template<size_t I, typename E = getEdgeT<I>>
Get the highest non-overflow edge of the axis.
Definition at line 326 of file Binning.h. 326 {
330 }
References YODA::Binning< Axes >::axis(). ◆ mergeBins()
template<typename... Axes>
template<size_t... AxisNs>
◆ min()
template<typename... Axes>
template<size_t I, typename E = getEdgeT<I>>
Get the lowest non-overflow edge of the axis.
Definition at line 316 of file Binning.h. 316 {
320 }
References YODA::Binning< Axes >::axis(). ◆ numBins()
template<typename... Axes>
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 }
751 }
std::vector< size_t > maskedBins() const noexcept Calculates indices of masked bins. Definition Binning.h:169 ◆ numBinsAt()
template<typename... Axes>
◆ operator=() [1/2]
template<typename... Axes>
◆ operator=() [2/2]
template<typename... Axes>
◆ sliceIndices() [1/2]
template<typename... Axes>
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 }
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>
Calculates indices of bins located in the specified slices.
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
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>
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) {
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>>
Templated version to get bin widths of axis N by reference. Overflows are included depending on includeOverflows Needed by axis-specific version from AxisMixin
Definition at line 307 of file Binning.h. References YODA::Binning< Axes >::axis(). The documentation for this class was generated from the following file:
Generated on Mon Oct 28 2024 13:47:24 for YODA - Yet more Objects for Data Analysis by 1.9.8 |