Logo ROOT   6.14/05
Reference Guide
THistBinIter.hxx
Go to the documentation of this file.
1 /// \file ROOT/THistBinIter.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-08-07
5 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
6 /// is welcome!
7 
8 /*************************************************************************
9  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
10  * All rights reserved. *
11  * *
12  * For the licensing terms see $ROOTSYS/LICENSE. *
13  * For the list of contributors see $ROOTSYS/README/CREDITS. *
14  *************************************************************************/
15 
16 #ifndef ROOT7_THistBinIter
17 #define ROOT7_THistBinIter
18 
19 #include "ROOT/TIndexIter.hxx"
20 
21 namespace ROOT {
22 namespace Experimental {
23 namespace Detail {
24 
25 /**
26 \class THistBinRef
27 Represents a bin reference. Value of the bin iteration.
28 
29 Provides access to bin content, bin geometry (from, to, center), and statistics
30 (for instance higher moments) associated to the bin.
31 */
32 
33 template <class HISTIMPL>
34 class THistBinRef {
35 public:
36  using HistImpl_t = HISTIMPL;
38  using Weight_t = typename HISTIMPL::Weight_t;
39  using HistBinStat_t = decltype(((HISTIMPL *)0x123)->GetStat().GetView(1));
40 
41 private:
42  size_t fIndex = 0; ///< Bin index
43  HistImpl_t *fHist; ///< The bin's histogram.
45 
46 public:
47  /// Construct from a histogram.
48  THistBinRef(HistImpl_t &hist, size_t idx): fIndex(idx), fHist(&hist), fStatView(hist.GetStat().GetView(idx)) {}
49 
50  /// \{
51  /// \name Statistics operations
52  /// Get the bin content (or reference to it, for non-const HistImpl_t).
53  auto GetContent() { return fStatView.GetContent(); }
54 
55  /// Get the bin uncertainty.
56  double GetUncertainty() const { return fStatView.GetUncertainty(); }
57 
58  /// Get a (const, for const HistImpl_t) reference to the bin-view of the
59  /// histogram statistics (uncertainty etc).
60  HistBinStat_t GetStat() const { return fStatView; }
61  /// \}
62 
63  /// \{
64  /// \name Bin operations
65  /// Get the bin center as an array over all dimensions.
66  CoordArray_t GetCenter() const { return fHist->GetBinCenter(fIndex); }
67 
68  /// Get the bin lower edge as an array over all dimensions.
69  CoordArray_t GetFrom() const { return fHist->GetBinFrom(fIndex); }
70 
71  /// Get the bin upper edge as an array over all dimensions.
72  CoordArray_t GetTo() const { return fHist->GetBinTo(fIndex); }
73  /// \}
74 };
75 
76 /**
77  \class THistBinPtr
78  Points to a histogram bin (or actually a `THistBinRef`).
79  */
80 template <class HISTIMPL>
81 class THistBinPtr {
82 public:
84 
85  const Ref_t &operator->() const noexcept { return fRef; }
86 
87 private:
88  Ref_t fRef; ///< Underlying bin reference
89 };
90 
91 /**
92  \class THistBinIter
93  Iterates over the bins of a THist or THistImpl.
94  */
95 
96 template <class HISTIMPL>
97 class THistBinIter: public Internal::TIndexIter<THistBinRef<HISTIMPL>, THistBinPtr<HISTIMPL>> {
98 public:
101 
102 private:
104 
105  HISTIMPL &fHist; ///< The histogram we iterate over.
106 
107 public:
108  /// Construct a THistBinIter from a histogram.
109  THistBinIter(HISTIMPL &hist): IndexIter_t(0), fHist(hist) {}
110 
111  /// Construct a THistBinIter from a histogram, setting the current index.
112  THistBinIter(HISTIMPL &hist, size_t idx): IndexIter_t(idx), fHist(hist) {}
113 
114  ///\{
115  ///\name Value access
116  Ref_t operator*() const noexcept { return Ref_t{fHist, IndexIter_t::GetIndex()}; }
117 
118  Ptr_t operator->() const noexcept { return Ptr_t{*this}; }
119  ///\}
120 };
121 
122 } // namespace Detail
123 } // namespace Experimental
124 } // namespace ROOT
125 
126 #endif
Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
Definition: TIndexIter.hxx:35
Ref_t fRef
Underlying bin reference.
const Ref_t & operator->() const noexcept
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
typename HISTIMPL::CoordArray_t CoordArray_t
Iterates over the bins of a THist or THistImpl.
THistBinRef(HistImpl_t &hist, size_t idx)
Construct from a histogram.
THistBinIter(HISTIMPL &hist, size_t idx)
Construct a THistBinIter from a histogram, setting the current index.
HISTIMPL & fHist
The histogram we iterate over.
double GetUncertainty() const
Get the bin uncertainty.
HistBinStat_t GetStat() const
Get a (const, for const HistImpl_t) reference to the bin-view of the histogram statistics (uncertaint...
decltype(((HISTIMPL *) 0x123) ->GetStat().GetView(1)) HistBinStat_t
TCoordArray< DIMENSIONS > CoordArray_t
Definition: THistUtils.hxx:49
Represents a bin reference.
HistImpl_t * fHist
The bin&#39;s histogram.
CoordArray_t GetTo() const
Get the bin upper edge as an array over all dimensions.
THistBinIter(HISTIMPL &hist)
Construct a THistBinIter from a histogram.
CoordArray_t GetFrom() const
Get the bin lower edge as an array over all dimensions.
typename HISTIMPL::Weight_t Weight_t
Points to a histogram bin (or actually a THistBinRef).