Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
RHistView.hxx
Go to the documentation of this file.
1/// \file ROOT/RHistView.hxx
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
21namespace ROOT {
22namespace 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
40template <class HISTVIEW>
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 */
50template <int DIMENSIONS, class PRECISION, template <int D_, class P_> class... STAT>
51class RHistView {
52public:
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
85private:
87 int fNBins = 0;
89};
90
91} // namespace Experimental
92} // namespace ROOT
93
94#endif
constexpr int PRECISION
Definition MnPrint.cxx:30
Iterates over the bins of a RHist or RHistImpl.
int GetNBins() const noexcept final
Get the number of bins in this histogram, including possible under- and overflow bins.
virtual const RAxisBase & GetAxis(int iAxis) const =0
Get a base-class view on axis with index iAxis.
Histogram axis base class.
Definition RAxis.hxx:44
virtual int FindBin(double x) const noexcept=0
Find the adjusted bin index (returning kUnderflowBin for underflow and kOverflowBin for overflow) for...
A view on a histogram, selecting a range on a subset of dimensions.
Definition RHistView.hxx:51
typename Hist_t::AxisIterRange_t AxisRange_t
Definition RHistView.hxx:54
const_iterator begin() const noexcept
Definition RHistView.hxx:74
RHistView(Hist_t &hist, int nbins, const AxisRange_t &range)
Definition RHistView.hxx:59
bool IsBinOutOfRange(int idx) const noexcept
Definition RHistView.hxx:61
const_iterator end() const noexcept
Definition RHistView.hxx:83
RHistViewOutOfRange< RHistView > HistViewOutOfRange_t
Definition RHistView.hxx:55
Detail::RHistBinIter< typename Hist_t::ImplBase_t > const_iterator
Definition RHistView.hxx:57
void SetRange(int axis, double from, double to)
Definition RHistView.hxx:67
Histogram class for histograms with DIMENSIONS dimensions, where each bin count is stored by a value ...
Definition RHist.hxx:53
ImplBase_t * GetImpl() const noexcept
Access the ImplBase_t this RHist points to.
Definition RHist.hxx:134
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...