Logo ROOT   6.10/09
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 is welcome!
6 
7 /*************************************************************************
8  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers. *
9  * All rights reserved. *
10  * *
11  * For the licensing terms see $ROOTSYS/LICENSE. *
12  * For the list of contributors see $ROOTSYS/README/CREDITS. *
13  *************************************************************************/
14 
15 #ifndef ROOT7_THistBinIter
16 #define ROOT7_THistBinIter
17 
18 #include "ROOT/TIndexIter.hxx"
19 
20 namespace ROOT {
21 namespace Experimental {
22 namespace Detail {
23 
24 /**
25 \class THistBinRef
26 Represents a bin reference. Value of the bin iteration.
27 
28 Provides access to bin content, bin geometry (from, to, center), and statistics
29 (for instance higher moments) associated to the bin.
30 */
31 
32 template <class HISTIMPL>
33 class THistBinRef {
34 public:
35  using HistImpl_t = HISTIMPL;
37  using Weight_t = typename HISTIMPL::Weight_t;
38  using HistBinStat_t = decltype(((HISTIMPL*)0x123)->GetStat().GetView(1));
39 
40 private:
41  size_t fIndex = 0; ///< Bin index
42  HistImpl_t* fHist; ///< The bin's histogram.
44 
45 public:
46  /// Construct from a histogram.
47  THistBinRef(HistImpl_t& hist, size_t idx):
48  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 /**
78  \class THistBinPtr
79  Points to a histogram bin (or actually a `THistBinRef`).
80  */
81 template<class HISTIMPL>
82 class THistBinPtr {
83 public:
85 
86  const Ref_t &operator->() const noexcept {
87  return fRef;
88  }
89 
90 private:
91  Ref_t fRef; ///< Underlying bin reference
92 };
93 
94 
95 /**
96  \class THistBinIter
97  Iterates over the bins of a THist or THistImpl.
98  */
99 
100 template<class HISTIMPL>
102  public Internal::TIndexIter<THistBinRef < HISTIMPL>, THistBinPtr<HISTIMPL>> {
103 public:
106 
107 private:
109 
110  HISTIMPL &fHist; ///< The histogram we iterate over.
111 
112 public:
113  /// Construct a THistBinIter from a histogram.
114  THistBinIter(HISTIMPL &hist):
115  IndexIter_t(0), fHist(hist) { }
116 
117  /// Construct a THistBinIter from a histogram, setting the current index.
118  THistBinIter(HISTIMPL &hist, size_t idx):
119  IndexIter_t(idx), fHist(hist) { }
120 
121  ///\{
122  ///\name Value access
123  Ref_t operator*() const noexcept {
124  return Ref_t{fHist, IndexIter_t::GetIndex()};
125  }
126 
127  Ptr_t operator->() const noexcept {
128  return Ptr_t{*this};
129  }
130  ///\}
131 };
132 
133 } // namespace Detail
134 } // namespace Experimental
135 } // namespace ROOT
136 
137 #endif
Iterates over an index; the REFERENCE is defined by the REFERENCE template parameter.
Definition: TIndexIter.hxx:34
Ref_t fRef
Underlying bin reference.
std::array< double, DIMENSIONS > CoordArray_t
Definition: THistUtils.hxx:25
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
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).