Logo ROOT   6.08/07
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 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_THistView
16 #define ROOT7_THistView
17 
18 #include "ROOT/THist.hxx"
19 
20 namespace ROOT {
21 namespace Experimental {
22 
23 /*
24  * Need THist::iterator for full range, takes a predicate for "in range?"
25  * Returns true for THist; for THistView, checks range, returns false if not in
26  * range. i+= 7 then does i++ seven times and checks at each step.
27  * iterator is simply an int with a predicate functor. end is end of the
28  * histogram - i.e. the number of bins (incl over / underflow).
29  *
30  * Add is then an operation (through a functor) on two bins.
31  *
32  * Drawing: need adaptor from THist<n,p>::GetBinContent(...) to
33  * THistPrecNormalizer<n>::Get(i) that casts the bin content to a double. That
34  * should be in internal but outside the drawing library (that needs to
35  * communicate through abstract interfaces and can thus not instantiate
36  * templates with user precision parameters.
37  */
38 
39 template <class HISTVIEW>
41  HISTVIEW& fHistView;
42  bool operator()(int idx) { return fHistView.IsBinOutOfRange(idx); }
43 };
44 
45 /**
46  \class THistView
47  A view on a histogram, selecting a range on a subset of dimensions.
48  */
49 template<int DIMENSIONS, class PRECISION,
50  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):
60  fHist(hist), fNBins(nbins), fRange(range) {}
61 
62  bool IsBinOutOfRange(int idx) const noexcept {
63  // TODO: use fRange!
64  return idx < 0 || idx > fNBins;
65  }
66 
67  void SetRange(int axis, double from, double to) {
68  TAxisView axisView = fHist.GetImpl()->GetAxis(axis);
69  fRange[axis] = axisView.FindBin(from);
70  fRange[axis] = axisView.FindBin(to);
71  }
72 
73  const_iterator begin() const noexcept {
74  int beginidx = 0;
75  size_t nbins = fHist.GetNBins();
76  while (IsBinOutOfRange(beginidx) && beginidx < nbins)
77  ++beginidx;
78  return const_iterator(beginidx, HistViewOutOfRange_t(*this));
79  }
80 
81  const_iterator end() const noexcept {
82  return const_iterator(fHist.GetImpl(), fHist.GetImpl().GetNBins());
83  }
84 
85 private:
87  int fNBins = 0;
89 };
90 
91 
92 } // namespace Experimental
93 } // namespace ROOT
94 
95 #endif
void SetRange(int axis, double from, double to)
Definition: THistView.hxx:67
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
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:911
Common view on a TAxis, no matter what its kind.
Definition: TAxis.hxx:891
int nbins[3]
#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:73
const_iterator end() const noexcept
Definition: THistView.hxx:81
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:40
THistView(Hist_t &hist, int nbins, const AxisRange_t &range)
Definition: THistView.hxx:59
bool IsBinOutOfRange(int idx) const noexcept
Definition: THistView.hxx:62