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