Logo ROOT   6.08/07
Reference Guide
THistImpl.hxx
Go to the documentation of this file.
1 /// \file ROOT/THistImpl.h
2 /// \ingroup Hist ROOT7
3 /// \author Axel Naumann <axel@cern.ch>
4 /// \date 2015-03-23
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_THistImpl
16 #define ROOT7_THistImpl
17 
18 #include <cctype>
19 #include "ROOT/RArrayView.hxx"
20 #include "ROOT/RTupleApply.hxx"
21 
22 #include "ROOT/TAxis.hxx"
23 #include "ROOT/THistBinIter.hxx"
24 #include "ROOT/THistUtils.hxx"
25 
26 class TRootIOCtor;
27 
28 namespace ROOT {
29 namespace Experimental {
30 
31 template<int DIMENSIONS, class PRECISION,
32  template <int D_, class P_, template <class P__> class STORAGE> class... STAT>
33 class THist;
34 
35 
36 namespace Hist {
37 /// Iterator over n dimensional axes - an array of n axis iterators.
38 template<int NDIM> using AxisIter_t = std::array<TAxisBase::const_iterator, NDIM>;
39 /// Range over n dimensional axes - a pair of arrays of n axis iterators.
40 template<int NDIM> using AxisIterRange_t = std::array<AxisIter_t<NDIM>, 2>;
41 
42 /// Kinds of under- and overflow handling.
43 enum class EOverflow {
44  kNoOverflow = 0x0, ///< Exclude under- and overflows
45  kUnderflow = 0x1, ///< Include underflows
46  kOverflow = 0x2, ///< Include overflows
47  kUnderOver = 0x3, ///< Include both under- and overflows
48 };
49 
50 inline bool operator&(EOverflow a, EOverflow b) {
51  return static_cast<int>(a) & static_cast<int>(b);
52 }
53 } // namespace Hist
54 
55 namespace Detail {
56 
57 /**
58  \class THistImplPrecisionAgnosticBase
59  Base class for THistImplBase that abstracts out the histogram's PRECISION.
60 
61  For operations such as painting a histogram, the PRECISION (type of the bin
62  content) is not relevant; painting will cast the underlying bin type to double.
63  To facilitate this, THistImplBase itself inherits from the
64  THistImplPrecisionAgnosticBase interface.
65  */
66 template <int DIMENSIONS>
67 class THistImplPrecisionAgnosticBase {
68 public:
69  /// Type of the coordinate: a DIMENSIONS-dimensional array of doubles.
71  /// Range type.
73 
79 
80  /// Number of dimensions of the coordinates
81  static constexpr int GetNDim() { return DIMENSIONS; }
82  /// Number of bins of this histogram, including all overflow and underflow
83  /// bins. Simply the product of all axes' number of bins.
84  virtual int GetNBins() const noexcept = 0;
85 
86  /// Get the histogram title.
87  const std::string& GetTitle() const { return fTitle; }
88 
89  /// Given the coordinate `x`, determine the index of the bin.
90  virtual int GetBinIndex(const CoordArray_t& x) const = 0;
91  /// Given the coordinate `x`, determine the index of the bin, possibly growing
92  /// axes for which `x` is out of range.
93  virtual int GetBinIndexAndGrow(const CoordArray_t& x) = 0;
94 
95  /// Get the center in all dimensions of the bin with index `binidx`.
96  virtual CoordArray_t GetBinCenter(int binidx) const = 0;
97  /// Get the lower edge in all dimensions of the bin with index `binidx`.
98  virtual CoordArray_t GetBinFrom(int binidx) const = 0;
99  /// Get the upper edge in all dimensions of the bin with index `binidx`.
100  virtual CoordArray_t GetBinTo(int binidx) const = 0;
101 
102  /// The bin's uncertainty. size() of the vector is a multiple of 2:
103  /// several kinds of uncertainty, same number of entries for lower and upper.
104  virtual double GetBinUncertainty(int binidx) const = 0;
105 
106  /// Whether this histogram's statistics provide storage for uncertainties, or
107  /// whether uncertainties are determined as poisson uncertainty of the content.
108  virtual bool HasBinUncertainty() const = 0;
109 
110  /// The bin content, cast to double.
111  virtual double GetBinContentAsDouble(int binidx) const = 0;
112 
113  /// Get a TAxisView on axis with index iAxis.
114  ///
115  /// \param iAxis - index of the axis, must be 0 <= iAxis < DIMENSION
116  virtual TAxisView GetAxis(int iAxis) const = 0;
117 
118  /// Get a AxisIterRange_t for the whole histogram, possibly restricting the
119  /// range to non-overflow bins.
120  ///
121  /// \param withOverUnder - specifies for each dimension whether under and
122  /// overflow should be included in the returned range.
123  virtual AxisIterRange_t
124  GetRange(const std::array<Hist::EOverflow, DIMENSIONS>& withOverUnder) const = 0;
125 
126 private:
127  std::string fTitle; ///< Histogram title.
128 };
129 
130 
131 /**
132  \class THistImplBase
133  Interface class for THistImpl.
134 
135  THistImpl is templated for a specific configuration of axes. To enable access
136  through THist, THistImpl inherits from THistImplBase, exposing only dimension
137  (`DIMENSION`) and bin type (`PRECISION`).
138  */
139 template<class DATA>
140 class THistImplBase: public THistImplPrecisionAgnosticBase<DATA::GetNDim()> {
141 public:
142  /// Type of the statistics (bin content, uncertainties etc).
143  using Stat_t = DATA;
144  /// Type of the coordinate: a DIMENSIONS-dimensional array of doubles.
146  /// Type of the bin content (and thus weights).
147  using Weight_t = typename DATA::Weight_t;
148 
149  /// Type of the Fill(x, w) function
151 
152 private:
153  /// The histogram's bin content, uncertainties etc.
155 
156 public:
157  THistImplBase() = default;
158  THistImplBase(size_t numBins): fStatistics(numBins) {}
159  THistImplBase(std::string_view title, size_t numBins):
160  THistImplPrecisionAgnosticBase<DATA::GetNDim()>(title), fStatistics(numBins) {}
161  THistImplBase(const THistImplBase&) = default;
162  THistImplBase(THistImplBase&&) = default;
163 
164  /// Interface function to fill a vector or array of coordinates with
165  /// corresponding weights.
166  /// \note the size of `xN` and `weightN` must be the same!
167  virtual void FillN(const std::array_view<CoordArray_t> xN,
168  const std::array_view<Weight_t> weightN) = 0;
169 
170  /// Interface function to fill a vector or array of coordinates.
171  virtual void FillN(const std::array_view<CoordArray_t> xN) = 0;
172 
173  /// Retrieve the pointer to the overridden Fill(x, w) function.
174  virtual FillFunc_t GetFillFunc() const = 0;
175 
176  /// Apply a function (lambda) to all bins of the histogram. The function takes
177  /// the bin reference.
178  virtual void Apply(std::function<void(THistBinRef<const THistImplBase>)>) const = 0;
179 
180  /// Apply a function (lambda) to all bins of the histogram. The function takes
181  /// the bin coordinate and content.
182  virtual void ApplyXC(std::function<void(const CoordArray_t&, Weight_t)>) const = 0;
183 
184  /// Apply a function (lambda) to all bins of the histogram. The function takes
185  /// the bin coordinate, content and uncertainty ("error") of the content.
186  virtual void ApplyXCE(std::function<void(const CoordArray_t&, Weight_t, double)>) const = 0;
187 
188  /// Get the bin content (sum of weights) for the bin at coordinate x.
189  virtual Weight_t GetBinContent(const CoordArray_t& x) const = 0;
190 
192 
193  /// Get the bin uncertainty for the bin at coordinate x.
194  virtual double GetBinUncertainty(const CoordArray_t& x) const = 0;
195 
196  /// Get the number of bins in this histogram, including possible under- and
197  /// overflow bins.
198  int GetNBins() const noexcept final { return fStatistics.size(); }
199 
200  /// Get the bin content (sum of weights) for bin index `binidx`.
201  Weight_t GetBinContent(int binidx) const { return fStatistics[binidx]; }
202 
203  /// Get the bin content (sum of weights) for bin index `binidx` (non-const).
204  Weight_t & GetBinContent(int binidx) { return fStatistics[binidx]; }
205 
206  /// Const access to statistics.
207  const Stat_t & GetStat() const noexcept { return fStatistics; }
208 
209  /// Non-const access to statistics.
210  Stat_t & GetStat() noexcept { return fStatistics; }
211 
212  /// Get the bin content (sum of weights) for bin index `binidx`, cast to
213  /// double.
214  double GetBinContentAsDouble(int binidx) const final {
215  return (double) GetBinContent(binidx);
216  }
217 
218  /// Add `w` to the bin at index `bin`.
219  void AddBinContent(int binidx, Weight_t w) { fStatistics[binidx] += w; }
220 };
221 } // namespace Detail
222 
223 
224 namespace Internal {
225 /** \name Histogram traits
226  Helper traits for histogram operations.
227  */
228 ///\{
229 
230 /// \name Axis tuple operations
231 /// Template operations on axis tuple.
232 ///@{
233 template <int IDX, class AXISTUPLE> struct TGetBinCount;
234 
235 template <class AXES> struct TGetBinCount<0, AXES> {
236  int operator()(const AXES& axes) const {
237  return std::get<0>(axes).GetNBins();
238  }
239 };
240 
241 
242 template <int I, class AXES>
243 struct TGetBinCount {
244  int operator()(const AXES& axes) const {
245  return std::get<I>(axes).GetNBins() * TGetBinCount<I - 1, AXES>()(axes);
246  }
247 };
248 
249 
250 template<class... AXISCONFIG>
251 int GetNBinsFromAxes(AXISCONFIG... axisArgs) {
252  using axesTuple = std::tuple<AXISCONFIG...>;
253  return TGetBinCount<sizeof...(AXISCONFIG) - 1, axesTuple>()(axesTuple{axisArgs...});
254 }
255 
256 
257 template <int IDX, class HISTIMPL, class AXES, bool GROW>
259 
260 // Break recursion
261 template <class HISTIMPL, class AXES, bool GROW>
262 struct TGetBinIndex< -1, HISTIMPL, AXES, GROW> {
263  int operator()(HISTIMPL*, const AXES&, const typename HISTIMPL::CoordArray_t&,
264  TAxisBase::EFindStatus& status) const {
266  return 0;
267  }
268 };
269 
270 template <int I, class HISTIMPL, class AXES, bool GROW>
271 struct TGetBinIndex {
272  int operator()(HISTIMPL* hist, const AXES& axes,
273  const typename HISTIMPL::CoordArray_t& x, TAxisBase::EFindStatus& status) const {
274  constexpr const int thisAxis = HISTIMPL::GetNDim() - I - 1;
275  int bin = std::get<thisAxis>(axes).FindBin(x[thisAxis]);
276  if (GROW && std::get<thisAxis>(axes).CanGrow()
277  && (bin < 0 || bin > std::get<thisAxis>(axes).GetNBinsNoOver())) {
278  hist->GrowAxis(I, x[thisAxis]);
280 
281  // Abort bin calculation; we don't care. Let THist::GetBinIndex() retry!
282  return bin;
283  }
284  return bin + TGetBinIndex<I - 1, HISTIMPL, AXES, GROW>()(hist, axes, x, status)
285  * std::get<thisAxis>(axes).GetNBins();
286  }
287 };
288 
289 
290 template<int I, class AXES> struct TFillIterRange;
291 
292 // Break recursion.
293 template<class AXES> struct TFillIterRange<-1, AXES> {
294  void operator()(Hist::AxisIterRange_t<std::tuple_size<AXES>::value>& /*range*/,
295  const AXES& /*axes*/,
296  const std::array<Hist::EOverflow, std::tuple_size<AXES>::value>& /*over*/) const {}
297 };
298 
299 /** Fill `range` with begin() and end() of all axes, including under/overflow
300  as specified by `over`.
301 */
302 template<int I, class AXES>
303 struct TFillIterRange {
304  void operator()(Hist::AxisIterRange_t<std::tuple_size<AXES>::value> &range,
305  const AXES &axes,
306  const std::array<Hist::EOverflow, std::tuple_size<AXES>::value> &over) const {
307  if (over[I] & Hist::EOverflow::kUnderflow)
308  range[0][I] = std::get<I>(axes).begin_with_underflow();
309  else
310  range[0][I] = std::get<I>(axes).begin();
311  if (over[I] & Hist::EOverflow::kOverflow)
312  range[1][I] = std::get<I>(axes).end_with_overflow();
313  else
314  range[1][I] = std::get<I>(axes).end();
315  TFillIterRange<I - 1, AXES>()(range, axes, over);
316  }
317 };
318 
319 
320 
321 enum class EBinCoord {
322  kBinFrom, ///< Get the lower bin edge
323  kBinCenter, ///< Get the bin center
324  kBinTo ///< Get the bin high edge
325 };
326 
327 template<int I, class COORD, class AXES> struct TFillBinCoord;
328 
329 // Break recursion.
330 template<class COORD, class AXES> struct TFillBinCoord<-1, COORD, AXES> {
331  void operator()(COORD& /*coord*/, const AXES& /*axes*/, EBinCoord /*kind*/, int /*binidx*/) const {}
332 };
333 
334 /** Fill `coord` with low bin edge or center or high bin edge of all axes.
335 */
336 template<int I, class COORD, class AXES>
337 struct TFillBinCoord {
338  void operator()(COORD& coord, const AXES& axes, EBinCoord kind, int binidx) const {
339  int axisbin = binidx % std::get<I>(axes).GetNBins();
340  size_t coordidx = std::tuple_size<AXES>::value - I - 1;
341  switch (kind) {
342  case EBinCoord::kBinFrom:
343  coord[coordidx] = std::get<I>(axes).GetBinFrom(axisbin);
344  break;
345  case EBinCoord::kBinCenter:
346  coord[coordidx] = std::get<I>(axes).GetBinCenter(axisbin);
347  break;
348  case EBinCoord::kBinTo:
349  coord[coordidx] = std::get<I>(axes).GetBinTo(axisbin);
350  break;
351  }
352  TFillBinCoord<I - 1, COORD, AXES>()(coord, axes, kind,
353  binidx / std::get<I>(axes).GetNBins());
354  }
355 };
356 
357 
358 
359 template <class... AXISCONFIG>
360 static std::array<TAxisView, sizeof...(AXISCONFIG)>
361 GetAxisView(const AXISCONFIG&...axes) noexcept {
362  std::array<TAxisView, sizeof...(AXISCONFIG)> axisViews = {
363  {TAxisView(axes)...}
364  };
365  return axisViews;
366 }
367 
368 ///\}
369 } // namespace Internal
370 
371 
372 namespace Detail {
373 
374 template <class DATA, class... AXISCONFIG>
375 class THistImpl final: public THistImplBase<DATA> {
376  static_assert(sizeof...(AXISCONFIG) == DATA::GetNDim(),
377  "Number of axes must equal histogram dimension");
378 
379  friend typename DATA::Hist_t;
380 
381 public:
384  using Weight_t = typename ImplBase_t::Weight_t;
385  using typename ImplBase_t::FillFunc_t;
386  template <int NDIM = DATA::GetNDim()> using AxisIterRange_t
388 
389 private:
390  std::tuple<AXISCONFIG...> fAxes; ///< The histogram's axes
391 
392 public:
394  THistImpl(AXISCONFIG... axisArgs);
395  THistImpl(std::string_view title, AXISCONFIG... axisArgs);
396 
397  /// Retrieve the fill function for this histogram implementation, to prevent
398  /// the virtual function call for high-frequency fills.
399  FillFunc_t GetFillFunc() const final { return (FillFunc_t)&THistImpl::Fill; }
400 
401  /// Apply a function (lambda) to all bins of the histogram. The function takes
402  /// the bin reference.
403  void Apply(std::function<void(THistBinRef<const ImplBase_t>)> op) const final {
404  for (THistBinRef<const ImplBase_t>&& binref: *this)
405  op(binref);
406  }
407 
408  /// Apply a function (lambda) to all bins of the histogram. The function takes
409  /// the bin coordinate and content.
410  void ApplyXC(std::function<void(const CoordArray_t&, Weight_t)> op) const final {
411  for (auto&& binref: *this)
412  op(binref.GetCenter(), binref.GetContent());
413  }
414 
415  /// Apply a function (lambda) to all bins of the histogram. The function takes
416  /// the bin coordinate, content and uncertainty ("error") of the content.
417  virtual void ApplyXCE(std::function<void(const CoordArray_t&, Weight_t, double)> op) const final {
418  for (auto&& binref: *this)
419  op(binref.GetCenter(), binref.GetContent(), binref.GetUncertainty());
420  }
421 
422 
423  /// Get the axes of this histogram.
424  const std::tuple<AXISCONFIG...>& GetAxes() const { return fAxes; }
425 
426  /// Normalized axes access, converting the actual axis to TAxisConfig
427  TAxisView GetAxis(int iAxis) const final {
428  return std::apply(Internal::GetAxisView<AXISCONFIG...>, fAxes)[iAxis];
429  }
430 
431 
432  /// Gets the bin index for coordinate `x`; returns -1 if there is no such bin,
433  /// e.g. for axes without over / underflow but coordinate out of range.
434  int GetBinIndex(const CoordArray_t& x) const final {
436  int ret = Internal::TGetBinIndex<DATA::GetNDim() - 1, THistImpl,
437  decltype(fAxes), false>()(nullptr, fAxes, x, status);
438  if (status != TAxisBase::EFindStatus::kValid)
439  return -1;
440  return ret;
441  }
442 
443  /// Gets the bin index for coordinate `x`, growing the axes as needed and
444  /// possible. Returns -1 if there is no such bin,
445  /// e.g. for axes without over / underflow but coordinate out of range.
446  int GetBinIndexAndGrow(const CoordArray_t& x) final {
448  int ret = - 1;
449  while (status == TAxisBase::EFindStatus::kCanGrow) {
450  ret = Internal::TGetBinIndex<DATA::GetNDim() - 1, THistImpl, decltype(fAxes), true>()
451  (this, fAxes, x, status);
452  }
453  return ret;
454  }
455 
456  /// Get the center coordinate of the bin.
457  CoordArray_t GetBinCenter(int binidx) const final {
458  using TFillBinCoord
459  = Internal::TFillBinCoord<DATA::GetNDim() - 1, CoordArray_t, decltype(fAxes)>;
460  CoordArray_t coord;
461  TFillBinCoord()(coord, fAxes, Internal::EBinCoord::kBinCenter, binidx);
462  return coord;
463  }
464 
465  /// Get the coordinate of the low limit of the bin.
466  CoordArray_t GetBinFrom(int binidx) const final {
467  using TFillBinCoord = Internal::TFillBinCoord<DATA::GetNDim() - 1, CoordArray_t, decltype(fAxes)>;
468  CoordArray_t coord;
469  TFillBinCoord()(coord, fAxes, Internal::EBinCoord::kBinFrom, binidx);
470  return coord;
471  }
472 
473  /// Get the coordinate of the high limit of the bin.
474  CoordArray_t GetBinTo(int binidx) const final {
475  using TFillBinCoord = Internal::TFillBinCoord<DATA::GetNDim() - 1, CoordArray_t, decltype(fAxes)>;
476  CoordArray_t coord;
477  TFillBinCoord()(coord, fAxes, Internal::EBinCoord::kBinTo, binidx);
478  return coord;
479  }
480 
481  /// Fill an array of `weightN` to the bins specified by coordinates `xN`.
482  /// For each element `i`, the weight `weightN[i]` will be added to the bin
483  /// at the coordinate `xN[i]`
484  /// \note `xN` and `weightN` must have the same size!
485  void FillN(const std::array_view<CoordArray_t> xN,
486  const std::array_view<Weight_t> weightN) final {
487 #ifndef NDEBUG
488  if (xN.size() != weightN.size()) {
489  R__ERROR_HERE("HIST") << "Not the same number of points and weights!";
490  return;
491  }
492 #endif
493 
494  for (size_t i = 0; i < xN.size(); ++i) {
495  Fill(xN[i], weightN[i]);
496  }
497  }
498 
499  /// Fill an array of `weightN` to the bins specified by coordinates `xN`.
500  /// For each element `i`, the weight `weightN[i]` will be added to the bin
501  /// at the coordinate `xN[i]`
502  void FillN(const std::array_view<CoordArray_t> xN) final {
503  for (auto&& x: xN) {
504  Fill(x);
505  }
506  }
507 
508  /// Add a single weight `w` to the bin at coordinate `x`.
509  void Fill(const CoordArray_t& x, Weight_t w = 1.) {
510  int bin = GetBinIndexAndGrow(x);
511  this->GetStat().Fill(x, bin, w);
512  }
513 
514  /// Get the content of the bin at position `x`.
515  Weight_t GetBinContent(const CoordArray_t& x) const final {
516  int bin = GetBinIndex(x);
517  if (bin >= 0)
518  return ImplBase_t::GetBinContent(bin);
519  return 0.;
520  }
521 
522  /// Return the uncertainties for the given bin.
523  double GetBinUncertainty(int binidx) const final {
524  return this->GetStat().GetBinUncertainty(binidx);
525  }
526 
527  /// Get the bin uncertainty for the bin at coordinate x.
528  double GetBinUncertainty(const CoordArray_t& x) const final {
529  const int bin = GetBinIndex(x);
530  return this->GetBinUncertainty(bin);
531  }
532 
533  /// Whether this histogram's statistics provide storage for uncertainties, or
534  /// whether uncertainties are determined as poisson uncertainty of the content.
535  bool HasBinUncertainty() const final {
536  return this->GetStat().HasBinUncertainty();
537  }
538 
539  /// Get the begin() and end() for each axis.
540  ///
541  ///\param[in] withOverUnder - Whether the begin and end should contain over-
542  /// or underflow. Ignored if the axis does not support over- / underflow.
544  GetRange(const std::array<Hist::EOverflow, DATA::GetNDim()>& withOverUnder) const final {
545  std::array<std::array<TAxisBase::const_iterator, DATA::GetNDim()>, 2> ret;
546  Internal::TFillIterRange<DATA::GetNDim() - 1, decltype(fAxes)>()(ret, fAxes, withOverUnder);
547  return ret;
548  }
549 
550  /// Grow the axis number `iAxis` to fit the coordinate `x`.
551  ///
552  /// The histogram (conceptually) combines pairs of bins along this axis until
553  /// `x` is within the range of the axis.
554  /// The axis must support growing for this to work (e.g. a `TAxisGrow`).
555  void GrowAxis(int /*iAxis*/, double /*x*/) {
556  // TODO: Implement GrowAxis()
557  }
558 
559  /// \{
560  /// \name Iterator interface
563  iterator begin() noexcept { return iterator(*this); }
564  const_iterator begin() const noexcept { return const_iterator(*this); }
565  iterator end() noexcept { return iterator(*this, this->GetNBins()); }
566  const_iterator end() const noexcept { return const_iterator(*this, this->GetNBins()); }
567  /// \}
568 };
569 
570 template <class DATA, class... AXISCONFIG>
572 {
573 }
574 
575 template <class DATA, class... AXISCONFIG>
577 THistImpl(AXISCONFIG... axisArgs):
578  ImplBase_t(Internal::GetNBinsFromAxes(axisArgs...)),
579  fAxes{axisArgs...}
580 {}
581 
582 template <class DATA, class... AXISCONFIG>
584 THistImpl(std::string_view title, AXISCONFIG... axisArgs):
585  ImplBase_t(title, Internal::GetNBinsFromAxes(axisArgs...)),
586  fAxes{axisArgs...}
587 {}
588 
589 #if 0
590 // In principle we can also have a runtime version of THistImpl, that does not
591 // contain a tuple of concrete axis types but a vector of `TAxisConfig`.
592 template <class DATA>
593 class THistImplRuntime: public THistImplBase<DATA> {
594 public:
595  THistImplRuntime(std::array<TAxisConfig, DATA::GetNDim()>&& axisCfg);
596 };
597 #endif
598 
599 } // namespace Detail
600 
601 } // namespace Experimental
602 } // namespace ROOT
603 
604 #endif
int GetNBins() const noexcept final
Get the number of bins in this histogram, including possible under- and overflow bins.
Definition: THistImpl.hxx:198
DATA Stat_t
Type of the statistics (bin content, uncertainties etc).
Definition: THistImpl.hxx:143
void AddBinContent(int binidx, Weight_t w)
Add w to the bin at index bin.
Definition: THistImpl.hxx:219
std::array< double, DIMENSIONS > CoordArray_t
Definition: THistUtils.hxx:22
CoordArray_t GetBinFrom(int binidx) const final
Get the coordinate of the low limit of the bin.
Definition: THistImpl.hxx:466
This namespace contains pre-defined functions to be used in conjuction with TExecutor::Map and TExecu...
Definition: StringConv.hxx:21
Weight_t GetBinContent(const CoordArray_t &x) const final
Get the content of the bin at position x.
Definition: THistImpl.hxx:515
void operator()(COORD &coord, const AXES &axes, EBinCoord kind, int binidx) const
Definition: THistImpl.hxx:338
double GetBinContentAsDouble(int binidx) const final
Get the bin content (sum of weights) for bin index binidx, cast to double.
Definition: THistImpl.hxx:214
bool operator &(EOverflow a, EOverflow b)
Definition: THistImpl.hxx:50
Interface class for THistImpl.
Definition: THistImpl.hxx:140
int GetBinIndexAndGrow(const CoordArray_t &x) final
Gets the bin index for coordinate x, growing the axes as needed and possible.
Definition: THistImpl.hxx:446
int operator()(HISTIMPL *, const AXES &, const typename HISTIMPL::CoordArray_t &, TAxisBase::EFindStatus &status) const
Definition: THistImpl.hxx:263
typename Hist::AxisIterRange_t< NDIM > AxisIterRange_t
Definition: THistImpl.hxx:387
Weight_t GetBinContent(int binidx) const
Get the bin content (sum of weights) for bin index binidx.
Definition: THistImpl.hxx:201
Weight_t & GetBinContent(int binidx)
Get the bin content (sum of weights) for bin index binidx (non-const).
Definition: THistImpl.hxx:204
void operator()(COORD &, const AXES &, EBinCoord, int) const
Definition: THistImpl.hxx:331
Iterates over the bins of a THist or THistImpl.
std::tuple< AXISCONFIG... > fAxes
The histogram&#39;s axes.
Definition: THistImpl.hxx:390
void GrowAxis(int, double)
Grow the axis number iAxis to fit the coordinate x.
Definition: THistImpl.hxx:555
int GetBinIndex(const CoordArray_t &x) const final
Gets the bin index for coordinate x; returns -1 if there is no such bin, e.g.
Definition: THistImpl.hxx:434
Common view on a TAxis, no matter what its kind.
Definition: TAxis.hxx:891
const_iterator begin() const noexcept
Definition: THistImpl.hxx:564
TArc * a
Definition: textangle.C:12
const std::tuple< AXISCONFIG... > & GetAxes() const
Get the axes of this histogram.
Definition: THistImpl.hxx:424
EFindStatus
Status of FindBin(x)
Definition: TAxis.hxx:43
int GetNBinsFromAxes(AXISCONFIG... axisArgs)
Definition: THistImpl.hxx:251
Stat_t & GetStat() noexcept
Non-const access to statistics.
Definition: THistImpl.hxx:210
Double_t x[n]
Definition: legend1.C:17
#define PRECISION
Definition: MnPrint.cxx:26
Hist::CoordArray_t< DIMENSIONS > CoordArray_t
Type of the coordinate: a DIMENSIONS-dimensional array of doubles.
Definition: THistImpl.hxx:70
void FillN(const std::array_view< CoordArray_t > xN) final
Fill an array of weightN to the bins specified by coordinates xN.
Definition: THistImpl.hxx:502
FillFunc_t GetFillFunc() const final
Retrieve the fill function for this histogram implementation, to prevent the virtual function call fo...
Definition: THistImpl.hxx:399
static std::array< TAxisView, sizeof...(AXISCONFIG)> GetAxisView(const AXISCONFIG &...axes) noexcept
Definition: THistImpl.hxx:361
static void GetRange(const char *comments, Double_t &xmin, Double_t &xmax, Double_t &factor)
Parse comments to search for a range specifier of the style: [xmin,xmax] or [xmin,xmax,nbits] [0,1] [-10,100]; [-pi,pi], [-pi/2,pi/4],[-2pi,2*pi] [-10,100,16] [0,0,8] if nbits is not specified, or nbits <2 or nbits>32 it is set to 32 if (xmin==0 and xmax==0 and nbits <=16) the double word will be converted to a float and its mantissa truncated to nbits significative bits.
AxisIterRange_t< DATA::GetNDim()> GetRange(const std::array< Hist::EOverflow, DATA::GetNDim()> &withOverUnder) const final
Get the begin() and end() for each axis.
Definition: THistImpl.hxx:544
const_iterator end() const noexcept
Definition: THistImpl.hxx:566
bool HasBinUncertainty() const final
Whether this histogram&#39;s statistics provide storage for uncertainties, or whether uncertainties are d...
Definition: THistImpl.hxx:535
Include both under- and overflows.
void Fill(const CoordArray_t &x, Weight_t w=1.)
Add a single weight w to the bin at coordinate x.
Definition: THistImpl.hxx:509
Objects used to configure the different axis types.
Definition: TAxis.hxx:706
const Stat_t & GetStat() const noexcept
Const access to statistics.
Definition: THistImpl.hxx:207
typename DATA::Weight_t Weight_t
Type of the bin content (and thus weights).
Definition: THistImpl.hxx:147
Represents a bin reference.
CoordArray_t GetBinTo(int binidx) const final
Get the coordinate of the high limit of the bin.
Definition: THistImpl.hxx:474
Hist::CoordArray_t< DATA::GetNDim()> CoordArray_t
Type of the coordinate: a DIMENSIONS-dimensional array of doubles.
Definition: THistImpl.hxx:145
void Apply(std::function< void(THistBinRef< const ImplBase_t >)> op) const final
Apply a function (lambda) to all bins of the histogram.
Definition: THistImpl.hxx:403
void ApplyXC(std::function< void(const CoordArray_t &, Weight_t)> op) const final
Apply a function (lambda) to all bins of the histogram.
Definition: THistImpl.hxx:410
static constexpr int GetNDim()
Number of dimensions of the coordinates.
Definition: THistImpl.hxx:81
THistImplBase(std::string_view title, size_t numBins)
Definition: THistImpl.hxx:159
double GetBinUncertainty(int binidx) const final
Return the uncertainties for the given bin.
Definition: THistImpl.hxx:523
void(THistImplBase::*)(const CoordArray_t &x, Weight_t w) FillFunc_t
Type of the Fill(x, w) function.
Definition: THistImpl.hxx:150
TAxisView GetAxis(int iAxis) const final
Normalized axes access, converting the actual axis to TAxisConfig.
Definition: THistImpl.hxx:427
Base class for THistImplBase that abstracts out the histogram&#39;s PRECISION.
Hist::AxisIterRange_t< DIMENSIONS > AxisIterRange_t
Range type.
Definition: THistImpl.hxx:72
Stat_t fStatistics
The histogram&#39;s bin content, uncertainties etc.
Definition: THistImpl.hxx:154
void FillN(const std::array_view< CoordArray_t > xN, const std::array_view< Weight_t > weightN) final
Fill an array of weightN to the bins specified by coordinates xN.
Definition: THistImpl.hxx:485
typedef void((*Func_t)())
double GetBinUncertainty(const CoordArray_t &x) const final
Get the bin uncertainty for the bin at coordinate x.
Definition: THistImpl.hxx:528
Fill range with begin() and end() of all axes, including under/overflow as specified by over...
Definition: THistImpl.hxx:290
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
int operator()(const AXES &axes) const
Definition: THistImpl.hxx:244
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &, const AXES &, const std::array< Hist::EOverflow, std::tuple_size< AXES >::value > &) const
Definition: THistImpl.hxx:294
virtual void ApplyXCE(std::function< void(const CoordArray_t &, Weight_t, double)> op) const final
Apply a function (lambda) to all bins of the histogram.
Definition: THistImpl.hxx:417
Fill coord with low bin edge or center or high bin edge of all axes.
Definition: THistImpl.hxx:327
Coordinate could fit after growing the axis.
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
#define I(x, y, z)
int operator()(HISTIMPL *hist, const AXES &axes, const typename HISTIMPL::CoordArray_t &x, TAxisBase::EFindStatus &status) const
Definition: THistImpl.hxx:272
CoordArray_t GetBinCenter(int binidx) const final
Get the center coordinate of the bin.
Definition: THistImpl.hxx:457
EOverflow
Kinds of under- and overflow handling.
Definition: THistImpl.hxx:43
decltype(auto) constexpr apply(F &&f, Tuple &&t)
const std::string & GetTitle() const
Get the histogram title.
Definition: THistImpl.hxx:87
#define R__ERROR_HERE(GROUP)
Definition: TLogger.hxx:122
std::array< TAxisBase::const_iterator, NDIM > AxisIter_t
Iterator over n dimensional axes - an array of n axis iterators.
Definition: THistImpl.hxx:38
void operator()(Hist::AxisIterRange_t< std::tuple_size< AXES >::value > &range, const AXES &axes, const std::array< Hist::EOverflow, std::tuple_size< AXES >::value > &over) const
Definition: THistImpl.hxx:304