ROOT  6.06/09
Reference Guide
THistView.h
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.h"
19 
20 namespace ROOT {
21 
22 /*
23  * Need THist::iterator for full range, takes a predicate for "in range?"
24  * Returns true for THist; for THistView, checks range, returns false if not in
25  * range. i+= 7 then does i++ seven times and checks at each step.
26  * iterator is simply an int with a predicate functor. end is end of the
27  * histogram - i.e. the number of bins (incl over / underflow).
28  *
29  * Add is then an operation (through a functor) on two bins.
30  *
31  * Drawing: need adaptor from THist<n,p>::GetBinContent(...) to
32  * THistPrecNormalizer<n>::Get(i) that casts the bin content to a double. That
33  * should be in internal but outside the drawing library (that needs to
34  * communicate through abstract interfaces and can thus not instantiate
35  * templates with user precision parameters.
36  */
37 
38 template <class HISTVIEW>
40  HISTVIEW& fHistView;
41  bool operator()(int idx) { return fHistView.IsBinOutOfRange(idx); }
42 };
43 
44 /**
45  \class THistView
46  A view on a histogram, selecting a range on a subset of dimensions.
47  */
48 template <int DIMENSIONS, class PRECISION>
49 class THistView {
50 public:
54 
56 
57  THistView(Hist_t& hist, int nbins, const AxisRange_t& range):
58  fHist(hist), fNBins(nbins), fRange(range) {}
59 
60  bool IsBinOutOfRange(int idx) const noexcept {
61  // TODO: implement IsBinOutOfRange()!
62  }
63 
64  void SetRange(int axis, double from, double to) {
65  TAxisView axis = fHist.GetImpl()->GetAxis(axis);
66  fRange[axis] = axis.FindBin(from);
67  fRange[axis] = axis.FindBin(to);
68  }
69 
70  const_iterator begin() const noexcept {
71  int beginidx = 0;
72  size_t nbins = fHist.GetNBins();
73  while (IsBinOutOfRange(beginidx) && beginidx < nbins)
74  ++beginidx;
75  return const_iterator(beginidx, THistViewOutOfRange(*this));
76  }
77 
78  const_iterator end() const noexcept {
81  }
82 
83 private:
85  int fNBins = 0;
87 };
88 
89 
90 
91 
92 } // namespace ROOT
93 
94 #endif
bool IsBinOutOfRange(int idx) const noexcept
Definition: THistView.h:60
std::array< TAxisBase::const_iterator, NDIM > AxisIter_t
Iterator over n dimensional axes - an array of n axis iterators.
Definition: THistImpl.h:28
void SetRange(int axis, double from, double to)
Definition: THistView.h:64
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
Common view on a TAxis, no matter what its kind.
Definition: TAxis.h:699
AxisRange_t fRange
Definition: THistView.h:86
int FindBin(double x) const noexcept
Find the bin containing coordinate x. Forwards to the underlying axis.
Definition: TAxis.h:714
int nbins[3]
Hist::AxisIter_t< DIMENSIONS > AxisIter_t
Definition: THistView.h:52
ImplBase_t * GetImpl() const noexcept
Access the ImplBase_t this THist points to.
Definition: THist.h:154
THistView(Hist_t &hist, int nbins, const AxisRange_t &range)
Definition: THistView.h:57
Hist::AxisIterRange_t< DIMENSIONS > AxisRange_t
Definition: THistView.h:53
const_iterator end() const noexcept
Definition: THistView.h:78
virtual int GetNBins() const =0
Number of bins of this histogram, including all overflow and underflow bins.
A predicate for THistBinIterBase to accept all bins.
Definition: THistBinIter.h:83
std::array< AxisIter_t< NDIM >, 2 > AxisIterRange_t
Range over n dimensional axes - a pair of arrays of n axis iterators.
Definition: THistImpl.h:30
virtual TAxisView GetAxis(int iAxis) const =0
Get a TAxisView on axis with index iAxis.
A view on a histogram, selecting a range on a subset of dimensions.
Definition: THistView.h:49
Internal::THistBinIter< THistViewOutOfRange > const_iterator
Definition: THistView.h:55
A bin iterator taking a predicate whether it should skip a bin.
Definition: THistBinIter.h:89
Hist_t & fHist
Definition: THistView.h:84
const_iterator begin() const noexcept
Definition: THistView.h:70
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
Definition: THist.h:31
bool operator()(int idx)
Definition: THistView.h:41