Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:43

0001 /// \file ROOT/RHistBinIter.hxx
0002 /// \ingroup HistV7
0003 /// \author Axel Naumann <axel@cern.ch>
0004 /// \date 2015-08-07
0005 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
0006 /// is welcome!
0007 
0008 /*************************************************************************
0009  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers.               *
0010  * All rights reserved.                                                  *
0011  *                                                                       *
0012  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0013  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0014  *************************************************************************/
0015 
0016 #ifndef ROOT7_RHistBinIter
0017 #define ROOT7_RHistBinIter
0018 
0019 #include "ROOT/RIndexIter.hxx"
0020 
0021 namespace ROOT {
0022 namespace Experimental {
0023 namespace Detail {
0024 
0025 /**
0026 \class RHistBinRef
0027 Represents a bin reference. Value of the bin iteration.
0028 
0029 Provides access to bin content, bin geometry (from, to, center), and statistics
0030 (for instance higher moments) associated to the bin.
0031 */
0032 
0033 template <class HISTIMPL>
0034 class RHistBinRef {
0035 public:
0036    using HistImpl_t = HISTIMPL;
0037    using CoordArray_t = typename HISTIMPL::CoordArray_t;
0038    using Weight_t = typename HISTIMPL::Weight_t;
0039    using HistBinStat_t = decltype(((HISTIMPL *)0x123)->GetStat().GetView(1));
0040 
0041 private:
0042    size_t fIndex{0}; ///< Bin index
0043    HistImpl_t *fHist{nullptr}; ///< The bin's histogram.
0044    HistBinStat_t fStatView;
0045 
0046 public:
0047    /// Construct from a histogram.
0048    RHistBinRef(HistImpl_t &hist, size_t idx): fIndex(idx), fHist(&hist), fStatView(hist.GetStat().GetView(idx)) {}
0049 
0050    /// \{
0051    /// \name Statistics operations
0052    /// Get the bin content (or reference to it, for non-const HistImpl_t).
0053    auto GetContent() { return fStatView.GetContent(); }
0054 
0055    /// Get the bin uncertainty.
0056    double GetUncertainty() const { return fStatView.GetUncertainty(); }
0057 
0058    /// Get a (const, for const HistImpl_t) reference to the bin-view of the
0059    /// histogram statistics (uncertainty etc).
0060    HistBinStat_t GetStat() const { return fStatView; }
0061    /// \}
0062 
0063    /// \{
0064    /// \name Bin operations
0065    /// Get the bin center as an array over all dimensions.
0066    CoordArray_t GetCenter() const { return fHist->GetBinCenter(fIndex); }
0067 
0068    /// Get the bin lower edge as an array over all dimensions.
0069    CoordArray_t GetFrom() const { return fHist->GetBinFrom(fIndex); }
0070 
0071    /// Get the bin upper edge as an array over all dimensions.
0072    CoordArray_t GetTo() const { return fHist->GetBinTo(fIndex); }
0073    /// \}
0074 };
0075 
0076 /**
0077  \class RHistBinPtr
0078  Points to a histogram bin (or actually a `RHistBinRef`).
0079  */
0080 template <class HISTIMPL>
0081 class RHistBinPtr {
0082 public:
0083    using Ref_t = RHistBinRef<HISTIMPL>;
0084 
0085    const Ref_t &operator->() const noexcept { return fRef; }
0086 
0087 private:
0088    Ref_t fRef; ///< Underlying bin reference
0089 };
0090 
0091 /**
0092  \class RHistBinIter
0093  Iterates over the bins of a RHist or RHistImpl.
0094  */
0095 
0096 template <class HISTIMPL>
0097 class RHistBinIter: public Internal::RIndexIter<RHistBinRef<HISTIMPL>, RHistBinPtr<HISTIMPL>> {
0098 public:
0099    using Ref_t = RHistBinRef<HISTIMPL>;
0100    using Ptr_t = RHistBinPtr<HISTIMPL>;
0101 
0102 private:
0103    using IndexIter_t = Internal::RIndexIter<RHistBinRef<HISTIMPL>, RHistBinPtr<HISTIMPL>>;
0104 
0105    HISTIMPL &fHist; ///< The histogram we iterate over.
0106 
0107 public:
0108    /// Construct a RHistBinIter from a histogram.
0109    RHistBinIter(HISTIMPL &hist): IndexIter_t(0), fHist(hist) {}
0110 
0111    /// Construct a RHistBinIter from a histogram, setting the current index.
0112    RHistBinIter(HISTIMPL &hist, size_t idx): IndexIter_t(idx), fHist(hist) {}
0113 
0114    ///\{
0115    ///\name Value access
0116    Ref_t operator*() const noexcept { return Ref_t{fHist, IndexIter_t::GetIndex()}; }
0117 
0118    Ptr_t operator->() const noexcept { return Ptr_t{*this}; }
0119    ///\}
0120 };
0121 
0122 } // namespace Detail
0123 } // namespace Experimental
0124 } // namespace ROOT
0125 
0126 #endif