Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:10:44

0001 /// \file ROOT/RHistView.hxx
0002 /// \ingroup HistV7
0003 /// \author Axel Naumann <axel@cern.ch>
0004 /// \date 2015-08-06
0005 /// \warning This is part of the ROOT 7 prototype! It will change without notice. It might trigger earthquakes. Feedback
0006 /// is welcome!
0007 
0008 /*************************************************************************
0009  * Copyright (C) 1995-2015, Rene Brun and Fons Rademakers.               *
0010  * All rights reserved.                                                  *
0011  *                                                                       *
0012  * For the licensing terms see $ROOTSYS/LICENSE.                         *
0013  * For the list of contributors see $ROOTSYS/README/CREDITS.             *
0014  *************************************************************************/
0015 
0016 #ifndef ROOT7_RHistView
0017 #define ROOT7_RHistView
0018 
0019 #include "ROOT/RHist.hxx"
0020 
0021 namespace ROOT {
0022 namespace Experimental {
0023 
0024 /*
0025  * Need RHist::iterator for full range, takes a predicate for "in range?"
0026  * Returns true for RHist; for RHistView, checks range, returns false if not in
0027  * range. i+= 7 then does i++ seven times and checks at each step.
0028  * iterator is simply an int with a predicate functor. end is end of the
0029  * histogram - i.e. the number of bins (incl over / underflow).
0030  *
0031  * Add is then an operation (through a functor) on two bins.
0032  *
0033  * Drawing: need adaptor from RHist<n,p>::GetBinContent(...) to
0034  * RHistPrecNormalizer<n>::Get(i) that casts the bin content to a double. That
0035  * should be in internal but outside the drawing library (that needs to
0036  * communicate through abstract interfaces and can thus not instantiate
0037  * templates with user precision parameters.
0038  */
0039 
0040 template <class HISTVIEW>
0041 struct RHistViewOutOfRange {
0042    HISTVIEW &fHistView;
0043    bool operator()(int idx) { return fHistView.IsBinOutOfRange(idx); }
0044 };
0045 
0046 /**
0047  \class RHistView
0048  A view on a histogram, selecting a range on a subset of dimensions.
0049  */
0050 template <int DIMENSIONS, class PRECISION, template <int D_, class P_> class... STAT>
0051 class RHistView {
0052 public:
0053    using Hist_t = RHist<DIMENSIONS, PRECISION, STAT...>;
0054    using AxisRange_t = typename Hist_t::AxisIterRange_t;
0055    using HistViewOutOfRange_t = RHistViewOutOfRange<RHistView>;
0056 
0057    using const_iterator = Detail::RHistBinIter<typename Hist_t::ImplBase_t>;
0058 
0059    RHistView(Hist_t &hist, int nbins, const AxisRange_t &range): fHist(hist), fNBins(nbins), fRange(range) {}
0060 
0061    bool IsBinOutOfRange(int idx) const noexcept
0062    {
0063       // TODO: use fRange!
0064       return idx < 0 || idx > fNBins;
0065    }
0066 
0067    void SetRange(int axis, double from, double to)
0068    {
0069       const RAxisBase &axisView = fHist.GetImpl()->GetAxis(axis);
0070       fRange[axis] = axisView.FindBin(from);
0071       fRange[axis] = axisView.FindBin(to);
0072    }
0073 
0074    const_iterator begin() const noexcept
0075    {
0076       int beginidx = 0;
0077       size_t nbins = fHist.GetNBins();
0078       while (IsBinOutOfRange(beginidx) && beginidx < nbins)
0079          ++beginidx;
0080       return const_iterator(beginidx, HistViewOutOfRange_t(*this));
0081    }
0082 
0083    const_iterator end() const noexcept { return const_iterator(fHist.GetImpl(), fHist.GetImpl().GetNBins()); }
0084 
0085 private:
0086    Hist_t &fHist;
0087    int fNBins = 0;
0088    AxisRange_t fRange;
0089 };
0090 
0091 } // namespace Experimental
0092 } // namespace ROOT
0093 
0094 #endif