Logo ROOT   6.14/05
Reference Guide
THistView.hxx
Go to the documentation of this file.
1 /// \file ROOT/THistView.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_THistView
17 #define ROOT7_THistView
18 
19 #include "ROOT/THist.hxx"
20 
21 namespace ROOT {
22 namespace Experimental {
23 
24 /*
25  * Need THist::iterator for full range, takes a predicate for "in range?"
26  * Returns true for THist; for THistView, 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 THist<n,p>::GetBinContent(...) to
34  * THistPrecNormalizer<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>
42  HISTVIEW &fHistView;
43  bool operator()(int idx) { return fHistView.IsBinOutOfRange(idx); }
44 };
45 
46 /**
47  \class THistView
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_, template <class P__> class S_> class... STAT>
51 class THistView {
52 public:
53  using Hist_t = THist<DIMENSIONS, PRECISION, STAT...>;
56 
58 
59  THistView(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  TAxisView 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
void SetRange(int axis, double from, double to)
Definition: THistView.hxx:67
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
typename Hist_t::AxisIterRange_t AxisRange_t
Definition: THistView.hxx:54
Iterates over the bins of a THist or THistImpl.
int FindBin(double x) const noexcept
Find the bin containing coordinate x. Forwards to the underlying axis.
Definition: TAxis.hxx:854
Common view on a TAxis, no matter what its kind.
Definition: TAxis.hxx:836
#define PRECISION
Definition: MnPrint.cxx:26
A view on a histogram, selecting a range on a subset of dimensions.
Definition: THistView.hxx:51
const_iterator begin() const noexcept
Definition: THistView.hxx:74
const_iterator end() const noexcept
Definition: THistView.hxx:83
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
Definition: THist.hxx:33
std::array< AxisIter_t< NDIM >, 2 > AxisIterRange_t
Range over n dimensional axes - a pair of arrays of n axis iterators.
Definition: THistImpl.hxx:43
THistView(Hist_t &hist, int nbins, const AxisRange_t &range)
Definition: THistView.hxx:59
bool IsBinOutOfRange(int idx) const noexcept
Definition: THistView.hxx:61