Logo ROOT  
Reference Guide
RHistView.hxx
Go to the documentation of this file.
1 /// \file ROOT/RHistView.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-08-06
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_RHistView
17 #define ROOT7_RHistView
18 
19 #include "ROOT/RHist.hxx"
20 
21 namespace ROOT {
22 namespace Experimental {
23 
24 /*
25  * Need RHist::iterator for full range, takes a predicate for "in range?"
26  * Returns true for RHist; for RHistView, checks range, returns false if not in
27  * range. i+= 7 then does i++ seven times and checks at each step.
28  * iterator is simply an int with a predicate functor. end is end of the
29  * histogram - i.e. the number of bins (incl over / underflow).
30  *
31  * Add is then an operation (through a functor) on two bins.
32  *
33  * Drawing: need adaptor from RHist<n,p>::GetBinContent(...) to
34  * RHistPrecNormalizer<n>::Get(i) that casts the bin content to a double. That
35  * should be in internal but outside the drawing library (that needs to
36  * communicate through abstract interfaces and can thus not instantiate
37  * templates with user precision parameters.
38  */
39 
40 template <class HISTVIEW>
41 struct RHistViewOutOfRange {
42  HISTVIEW &fHistView;
43  bool operator()(int idx) { return fHistView.IsBinOutOfRange(idx); }
44 };
45 
46 /**
47  \class RHistView
48  A view on a histogram, selecting a range on a subset of dimensions.
49  */
50 template <int DIMENSIONS, class PRECISION, template <int D_, class P_> class... STAT>
51 class RHistView {
52 public:
53  using Hist_t = RHist<DIMENSIONS, PRECISION, STAT...>;
54  using AxisRange_t = typename Hist_t::AxisIterRange_t;
56 
58 
59  RHistView(Hist_t &hist, int nbins, const AxisRange_t &range): fHist(hist), fNBins(nbins), fRange(range) {}
60 
61  bool IsBinOutOfRange(int idx) const noexcept
62  {
63  // TODO: use fRange!
64  return idx < 0 || idx > fNBins;
65  }
66 
67  void SetRange(int axis, double from, double to)
68  {
69  const RAxisBase &axisView = fHist.GetImpl()->GetAxis(axis);
70  fRange[axis] = axisView.FindBin(from);
71  fRange[axis] = axisView.FindBin(to);
72  }
73 
74  const_iterator begin() const noexcept
75  {
76  int beginidx = 0;
77  size_t nbins = fHist.GetNBins();
78  while (IsBinOutOfRange(beginidx) && beginidx < nbins)
79  ++beginidx;
80  return const_iterator(beginidx, HistViewOutOfRange_t(*this));
81  }
82 
83  const_iterator end() const noexcept { return const_iterator(fHist.GetImpl(), fHist.GetImpl().GetNBins()); }
84 
85 private:
87  int fNBins = 0;
89 };
90 
91 } // namespace Experimental
92 } // namespace ROOT
93 
94 #endif
RHist.hxx
ROOT::Experimental::RAxisBase::FindBin
virtual int FindBin(double x) const noexcept=0
Find the adjusted bin index (returning kUnderflowBin for underflow and kOverflowBin for overflow) for...
ROOT::Experimental::Detail::RHistBinIter
Definition: RHistBinIter.hxx:115
ROOT::Experimental::RHistView::fHist
Hist_t & fHist
Definition: RHistView.hxx:98
ROOT::Experimental::RHistView::AxisRange_t
typename Hist_t::AxisIterRange_t AxisRange_t
Definition: RHistView.hxx:66
ROOT::Experimental::RHistView::fNBins
int fNBins
Definition: RHistView.hxx:99
ROOT::Experimental::RHistViewOutOfRange
Definition: RHistView.hxx:53
ROOT::Experimental::RHist::GetImpl
ImplBase_t * GetImpl() const noexcept
Access the ImplBase_t this RHist points to.
Definition: RHist.hxx:145
ROOT::Experimental::RHistView::IsBinOutOfRange
bool IsBinOutOfRange(int idx) const noexcept
Definition: RHistView.hxx:73
ROOT::Experimental::RHistViewOutOfRange::operator()
bool operator()(int idx)
Definition: RHistView.hxx:61
ROOT::Experimental::RHistView::end
const_iterator end() const noexcept
Definition: RHistView.hxx:95
STAT
ROOT::Experimental::Detail::RHistImplPrecisionAgnosticBase::GetAxis
virtual const RAxisBase & GetAxis(int iAxis) const =0
Get a base-class view on axis with index iAxis.
ROOT::Experimental::RHistView::begin
const_iterator begin() const noexcept
Definition: RHistView.hxx:86
ROOT::Experimental::RAxisBase
Definition: RAxis.hxx:56
ROOT::Experimental::RHistView::const_iterator
Detail::RHistBinIter< typename Hist_t::ImplBase_t > const_iterator
Definition: RHistView.hxx:69
ROOT::Experimental::RHistView::HistViewOutOfRange_t
RHistViewOutOfRange< RHistView > HistViewOutOfRange_t
Definition: RHistView.hxx:67
ROOT::Experimental::Detail::RHistImplBase::GetNBins
int GetNBins() const noexcept final
Get the number of bins in this histogram, including possible under- and overflow bins.
Definition: RHistImpl.hxx:201
ROOT::Experimental::RHistView::RHistView
RHistView(Hist_t &hist, int nbins, const AxisRange_t &range)
Definition: RHistView.hxx:71
ROOT::Experimental::RHistView::Hist_t
RHist< DIMENSIONS, PRECISION, STAT... > Hist_t
Definition: RHistView.hxx:65
ROOT::Experimental::RHistViewOutOfRange::fHistView
HISTVIEW & fHistView
Definition: RHistView.hxx:60
ROOT::Experimental::RHist
Definition: RHist.hxx:44
PRECISION
#define PRECISION
Definition: MnPrint.cxx:26
ROOT::Experimental::Hist::AxisIterRange_t
std::array< AxisIter_t< NDIMS >, 2 > AxisIterRange_t
Range over n dimensional axes - a pair of arrays of n axis iterators.
Definition: RHistImpl.hxx:43
ROOT::Experimental::RHistView::SetRange
void SetRange(int axis, double from, double to)
Definition: RHistView.hxx:79
ROOT::Experimental::RHistView::fRange
AxisRange_t fRange
Definition: RHistView.hxx:100
ROOT
VSD Structures.
Definition: StringConv.hxx:21