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