npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
HistoND.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_HISTOND_HH_
2 #define NPSTAT_HISTOND_HH_
3 
4 /*!
5 // \file HistoND.hh
6 //
7 // \brief Arbitrary-dimensional histogram template
8 //
9 // Author: I. Volobouev
10 //
11 // July 2010
12 */
13 
14 #include <utility>
15 
16 #include "npstat/nm/ArrayND.hh"
17 #include "npstat/stat/HistoAxis.hh"
18 
19 namespace npstat {
20  /**
21  // (Almost) arbitrary-dimensional histogram with binning determined
22  // by the second template parameter (typically HistoAxis or NUHistoAxis).
23  // The dimensionality must not exceed CHAR_BIT*sizeof(unsigned long)-1
24  // which is normally 31/63 on 32/64-bit systems.
25  //
26  // The template parameter class (Numeric) must be such that it can be
27  // used as the template parameter of ArrayND class. For a typical usage
28  // pattern, Numeric should also support operator += between itself and
29  // the weights with which the histogram is filled (see, however, the
30  // description of the "dispatch" method which is not subject to
31  // this recommendation).
32  //
33  // If the "fillC" method is used to accumulate the data then the weights
34  // must support multiplication by a double, and then it must be possible
35  // to use the "+=" operator to add such a product to Numeric.
36  //
37  // Note that there are no methods which would allow the user to examine
38  // the bin contents of the histogram using bin numbers. This is
39  // intentional: almost always such examinations are performed in a loop
40  // over indices, and it is more efficient to grab a reference to the
41  // underlying array using the "binContents()" method and then examine
42  // that array directly.
43  */
44  template <typename Numeric, class Axis=HistoAxis>
45  class HistoND
46  {
47  template <typename Num2, class Axis2> friend class HistoND;
48 
49  public:
50  typedef Numeric value_type;
51  typedef Axis axis_type;
52 
53  enum RebinType {
54  SAMPLE = 0,
55  SUM,
56  AVERAGE
57  };
58 
59  /** Main constructor for arbitrary-dimensional histograms */
60  explicit HistoND(const std::vector<Axis>& axes, const char* title=0,
61  const char* accumulatedDataLabel=0);
62 
63  /** Convenience constructor for 1-d histograms */
64  explicit HistoND(const Axis& xAxis, const char* title=0,
65  const char* accumulatedDataLabel=0);
66 
67  /** Convenience constructor for 2-d histograms */
68  HistoND(const Axis& xAxis, const Axis& yAxis,
69  const char* title=0, const char* accumulatedDataLabel=0);
70 
71  /** Convenience constructor for 3-d histograms */
72  HistoND(const Axis& xAxis, const Axis& yAxis, const Axis& zAxis,
73  const char* title=0, const char* accumulatedDataLabel=0);
74 
75  /** Convenience constructor for 4-d histograms */
76  HistoND(const Axis& a0, const Axis& a1,
77  const Axis& a2, const Axis& a3,
78  const char* title=0, const char* accumulatedDataLabel=0);
79 
80  /** Convenience constructor for 5-d histograms */
81  HistoND(const Axis& a0, const Axis& a1,
82  const Axis& a2, const Axis& a3, const Axis& a4,
83  const char* title=0, const char* accumulatedDataLabel=0);
84 
85  /** Convenience constructor for 6-d histograms */
86  HistoND(const Axis& a0, const Axis& a1, const Axis& a2,
87  const Axis& a3, const Axis& a4, const Axis& a5,
88  const char* title=0, const char* accumulatedDataLabel=0);
89 
90  /** Convenience constructor for 7-d histograms */
91  HistoND(const Axis& a0, const Axis& a1, const Axis& a2,
92  const Axis& a3, const Axis& a4, const Axis& a5, const Axis& a6,
93  const char* title=0, const char* accumulatedDataLabel=0);
94 
95  /** Convenience constructor for 8-d histograms */
96  HistoND(const Axis& a0, const Axis& a1, const Axis& a2,
97  const Axis& a3, const Axis& a4, const Axis& a5,
98  const Axis& a6, const Axis& a7,
99  const char* title=0, const char* accumulatedDataLabel=0);
100 
101  /** Convenience constructor for 9-d histograms */
102  HistoND(const Axis& a0, const Axis& a1, const Axis& a2,
103  const Axis& a3, const Axis& a4, const Axis& a5,
104  const Axis& a6, const Axis& a7, const Axis& a8,
105  const char* title=0, const char* accumulatedDataLabel=0);
106 
107  /** Convenience constructor for 10-d histograms */
108  HistoND(const Axis& a0, const Axis& a1, const Axis& a2,
109  const Axis& a3, const Axis& a4, const Axis& a5,
110  const Axis& a6, const Axis& a7, const Axis& a8, const Axis& a9,
111  const char* title=0, const char* accumulatedDataLabel=0);
112 
113  /**
114  // Simple constructor for uniformly binned histograms without
115  // axis labels. Sequence size returned by the size() method of
116  // both "shape" and "boundingBox" arguments must be the same.
117  */
119  const char* title=0, const char* accumulatedDataLabel=0);
120 
121  /**
122  // Converting constructor. The functor will be applied to all bins
123  // of the argument histogram to fill the bins of the constructed
124  // histogram. If the title and data label are not provided, they
125  // will be cleared.
126  */
127  template <typename Num2, class Functor>
128  HistoND(const HistoND<Num2,Axis>& h, const Functor& f,
129  const char* title=0, const char* accumulatedDataLabel=0);
130 
131  /**
132  // A slicing constructor. The new histogram will be created by
133  // slicing another histogram. See the description of the slicing
134  // constructor in the "ArrayND" class for the meaning of arguments
135  // "indices" and "nIndices". The data of the newly created histogram
136  // is cleared.
137  */
138  template <typename Num2>
139  HistoND(const HistoND<Num2,Axis>& h, const unsigned *indices,
140  unsigned nIndices, const char* title=0);
141 
142  /**
143  // A constructor that inserts a new axis into a histogram
144  // (as if the argument histogram was a slice of the new histogram).
145  // The "newAxisNumber" argument specifies the number of the
146  // new axis in the axis sequence of the constructed histogram.
147  // If the "newAxisNumber" exceeds the number of axes of the
148  // argument histogram, the new axis will become last. The data
149  // of the newly created histogram is cleared.
150  */
151  template <typename Num2>
152  HistoND(const HistoND<Num2,Axis>& h, const Axis& newAxis,
153  unsigned newAxisNumber, const char* title=0);
154 
155  /**
156  // Create a rebinned histogram with the same axis coverage.
157  // Note that not all such operations will be meaningful if the
158  // bin contents do not belong to one of the floating point types.
159  // The "newBinCounts" argument specifies the new number of bins
160  // along each axis. The length of this array (provided by the
161  // "lenNewBinCounts" argument) should be equal to the input
162  // histogram dimensionality.
163  //
164  // The "shifts" argument can be meaningfully specified with the
165  // "rType" argument set to "SAMPLE". These shifts will be added
166  // to the bin centers of the created histogram when the bin contents
167  // are looked up in the input histogram. This can be useful in case
168  // the bin center lookup without shifts would fall exactly on the
169  // bin edge. Naturally, the length of the "shifts" array should be
170  // equal to the input histogram dimensionality.
171  */
172  template <typename Num2>
173  HistoND(const HistoND<Num2,Axis>& h, RebinType rType,
174  const unsigned *newBinCounts, unsigned lenNewBinCounts,
175  const double* shifts=0, const char* title=0);
176 
177  /** Copy constructor */
178  HistoND(const HistoND&);
179 
180  /**
181  // Assignment operator. Works even when the binning of the two
182  // histograms is not compatible.
183  */
185 
186  /** Histogram dimensionality */
187  inline unsigned dim() const {return dim_;}
188 
189  /** Histogram title */
190  inline const std::string& title() const {return title_;}
191 
192  /** Label associated with accumulated data */
193  inline const std::string& accumulatedDataLabel() const
194  {return accumulatedDataLabel_;}
195 
196  /** Retrive a reference to the array of bin contents */
197  inline const ArrayND<Numeric>& binContents() const {return data_;}
198 
199  /** Retrive a reference to the array of overflows */
200  inline const ArrayND<Numeric>& overflows() const {return overflow_;}
201 
202  /**
203  // Retrieve overflows for individual axes, marginalized
204  // over all other axes
205  */
206  inline Numeric underflowWeight(unsigned axisNumber) const
207  {return overflowSum(axisNumber, 0U);}
208  inline Numeric overflowWeight(unsigned axisNumber) const
209  {return overflowSum(axisNumber, 2U);}
210 
211  /**
212  // The sum of the weights when there was no overflow for the
213  // given axis but there was at least one overflow in any other axis
214  */
215  inline Numeric inRangeOverWeight(unsigned axisNumber) const
216  {return overflowSum(axisNumber, 1U);}
217 
218  /** Inspect histogram axes */
219  inline const std::vector<Axis>& axes() const {return axes_;}
220 
221  /** Inspect a histogram axis for the given dimension */
222  inline const Axis& axis(const unsigned i) const
223  {return axes_.at(i);}
224 
225  /** Total number of bins */
226  inline unsigned long nBins() const {return data_.length();}
227 
228  /** Total number of fills performed */
229  inline unsigned long nFillsTotal() const {return fillCount_;}
230 
231  /** Total number of fills which fell inside the histogram range */
232  inline unsigned long nFillsInRange() const
233  {return fillCount_ - overCount_;}
234 
235  /** Total number of fills which fell outside the histogram range */
236  inline unsigned long nFillsOver() const {return overCount_;}
237 
238  /**
239  // This method returns "true" if the method isUniform()
240  // of each histogram axis returns "true"
241  */
242  bool isUniformlyBinned() const;
243 
244  //@{
245  /** A convenience function */
246  std::vector<double> lowerAxisLimits() const;
247  std::vector<double> upperAxisLimits() const;
248  std::vector<double> axisLengths() const;
249  //@}
250 
251  /** Modify the histogram title */
252  inline void setTitle(const char* newtitle)
253  {title_ = newtitle ? newtitle : ""; ++modCount_;}
254 
255  /** Modify the label associated with accumulated data */
256  inline void setAccumulatedDataLabel(const char* newlabel)
257  {accumulatedDataLabel_ = newlabel ? newlabel : ""; ++modCount_;}
258 
259  /** Modify the label for the histogram axis with the given number */
260  inline void setAxisLabel(const unsigned axisNum, const char* newlabel)
261  {axes_.at(axisNum).setLabel(newlabel); ++modCount_;}
262 
263  /**
264  // This method returns width/area/volume/etc. of a single bin.
265  // 1.0 is returned for a dimensionless histogram.
266  */
267  double binVolume(unsigned long binNumber=0) const;
268 
269  /**
270  // Position of the bin center. Length of the "coords" array
271  // (filled on return) should be equal to the dimensionality
272  // of the histogram.
273  */
274  void binCenter(unsigned long binNumber,
275  double* coords, unsigned lenCoords) const;
276 
277  /**
278  // Convenience function which fills out a vector of bin centers
279  // in the same order as the linear order of binContents().
280  // The class "Point" must have a subscript operator, default
281  // constructor, copy constructor, and the size() method (use,
282  // for example, std::array).
283  */
284  template <class Point>
285  void allBinCenters(std::vector<Point>* centers) const;
286 
287  /** Bounding box for the given bin */
288  void binBox(unsigned long binNumber, BoxND<double>* box) const;
289 
290  /** Bounding box for the whole histogram */
292 
293  /**
294  // Volume of the histogram bounding box (this direct call is faster
295  // than calling boundingBox().volume() ). This function returns 1.0
296  // for 0-dim histogram, axis interval length for 1-d histogram, etc.
297  */
298  double volume() const;
299 
300  /** Integral of the histogram */
301  double integral() const;
302 
303  /** Clear the histogram contents (both bins and overflows) */
304  void clear();
305 
306  /** This method clears the bin contents but not overflows */
308 
309  /** This method clears overflows but not the bin contents */
311 
312  /** Comparison for equality */
313  bool operator==(const HistoND&) const;
314 
315  /** Logical negation of operator== */
316  bool operator!=(const HistoND&) const;
317 
318  /**
319  // Check data for equality (both bin contents and overflows).
320  // Do not compare axes, labels, fill counts, etc.
321  */
322  bool isSameData(const HistoND&) const;
323 
324  /**
325  // Fill function for histograms of arbitrary dimensionality.
326  // The length of the "coords" array should be equal to the
327  // histogram dimensionality. The Numeric type must have the "+="
328  // operator defined with the Num2 type on the right side.
329  */
330  template <typename Num2>
331  void fill(const double* coords, unsigned coordLength,
332  const Num2& weight);
333 
334  /** Fill (possibly) multiple times from a flat vector */
335  template <typename Num2>
336  inline void fill(const std::vector<double>& c, const Num2& weight)
337  {
338  const unsigned long sz = c.size();
339  const unsigned long nFills = sz/dim_;
340  if (sz % dim_) throw std::invalid_argument(
341  "In npstat::HistoND::fill: incompatible sample size");
342  const double* buf = 0;
343  if (!c.empty()) buf = &c[0];
344  for (unsigned long i=0; i<nFills; ++i)
345  {
346  fill(buf, dim_, weight);
347  buf += dim_;
348  }
349  }
350 
351  /**
352  // Fill a 1-d histogram from a flat vector of weighted coordinates.
353  // The first element of each pair is the coordinate and the second
354  // is the weight.
355  */
356  template <typename Num2>
357  inline void fill(const std::vector<std::pair<double,Num2> >& c)
358  {
359  if (dim_ != 1U) throw std::invalid_argument(
360  "In npstat::HistoND::fill: flat vector of weighted "
361  "coordinates can only be used to fill 1-d histograms");
362  const unsigned long sz = c.size();
363  if (sz)
364  {
365  const std::pair<double,Num2>* buf = &c[0];
366  for (unsigned long i=0; i<sz; ++i, ++buf)
367  fill(&buf->first, 1U, buf->second);
368  }
369  }
370 
371  //@{
372  /**
373  // Convenience "fill" method for histograms of corresponding
374  // dimensionality
375  */
376  template <typename Num2>
377  void fill(const Num2& weight);
378 
379  template <typename Num2>
380  void fill(double x0, const Num2& weight);
381 
382  template <typename Num2>
383  void fill(double x0, double x1, const Num2& weight);
384 
385  template <typename Num2>
386  void fill(double x0, double x1, double x2, const Num2& weight);
387 
388  template <typename Num2>
389  void fill(double x0, double x1, double x2, double x3,
390  const Num2& weight);
391 
392  template <typename Num2>
393  void fill(double x0, double x1, double x2, double x3, double x4,
394  const Num2& weight);
395 
396  template <typename Num2>
397  void fill(double x0, double x1, double x2, double x3, double x4,
398  double x5, const Num2& weight);
399 
400  template <typename Num2>
401  void fill(double x0, double x1, double x2, double x3, double x4,
402  double x5, double x6, const Num2& weight);
403 
404  template <typename Num2>
405  void fill(double x0, double x1, double x2, double x3, double x4,
406  double x5, double x6, double x7, const Num2& weight);
407 
408  template <typename Num2>
409  void fill(double x0, double x1, double x2, double x3, double x4,
410  double x5, double x6, double x7, double x8,
411  const Num2& weight);
412 
413  template <typename Num2>
414  void fill(double x0, double x1, double x2, double x3, double x4,
415  double x5, double x6, double x7, double x8, double x9,
416  const Num2& weight);
417  //@}
418 
419  /**
420  // Location-based dispatch method. The provided binary functor
421  // will be called with the approprite histogram bin value as the
422  // first argument and the weight as the second (functor return value
423  // is ignored). This allows for a very general use of the histogram
424  // binning functionality. For example, with a proper functor, the
425  // histogram bins can be filled with pointers to an arbitrary class
426  // (this is the only way to use classes which do not have default
427  // constructors as bin contents) and the functor can be used to
428  // dispatch class methods. Depending on the exact nature of the
429  // functor, multiple things might be modified as the result of this
430  // call: the bin value, the weight, and the functor internal state.
431  */
432  template <typename Num2, class Functor>
433  void dispatch(const double* coords, unsigned coordLength,
434  Num2& weight, Functor& f);
435 
436  //@{
437  /**
438  // Convenience "dispatch" method for histograms of corresponding
439  // dimensionality
440  */
441  template <typename Num2, class Functor>
442  void dispatch(Num2& weight, Functor& f);
443 
444  template <typename Num2, class Functor>
445  void dispatch(double x0, Num2& weight, Functor& f);
446 
447  template <typename Num2, class Functor>
448  void dispatch(double x0, double x1, Num2& weight, Functor& f);
449 
450  template <typename Num2, class Functor>
451  void dispatch(double x0, double x1, double x2, Num2& weight,
452  Functor& f);
453 
454  template <typename Num2, class Functor>
455  void dispatch(double x0, double x1, double x2, double x3,
456  Num2& weight, Functor& f);
457 
458  template <typename Num2, class Functor>
459  void dispatch(double x0, double x1, double x2, double x3, double x4,
460  Num2& weight, Functor& f);
461 
462  template <typename Num2, class Functor>
463  void dispatch(double x0, double x1, double x2, double x3, double x4,
464  double x5, Num2& weight, Functor& f);
465 
466  template <typename Num2, class Functor>
467  void dispatch(double x0, double x1, double x2, double x3, double x4,
468  double x5, double x6, Num2& weight, Functor& f);
469 
470  template <typename Num2, class Functor>
471  void dispatch(double x0, double x1, double x2, double x3, double x4,
472  double x5, double x6, double x7, Num2& weight,
473  Functor& f);
474 
475  template <typename Num2, class Functor>
476  void dispatch(double x0, double x1, double x2, double x3, double x4,
477  double x5, double x6, double x7, double x8,
478  Num2& weight, Functor& f);
479 
480  template <typename Num2, class Functor>
481  void dispatch(double x0, double x1, double x2, double x3, double x4,
482  double x5, double x6, double x7, double x8, double x9,
483  Num2& weight, Functor& f);
484  //@}
485 
486  /**
487  // The "examine" functions allow the user to access bin contents
488  // when bins are addressed by their coordinates. Use "binContents()"
489  // to access the data by bin numbers. Overflow bins will be accessed
490  // if the given coordinates fall outside the histogram range.
491  */
492  const Numeric& examine(const double* coords,
493  unsigned coordLength) const;
494 
495  //@{
496  /**
497  // Convenience "examine" method for histograms of corresponding
498  // dimensionality
499  */
500  const Numeric& examine() const;
501 
502  const Numeric& examine(double x0) const;
503 
504  const Numeric& examine(double x0, double x1) const;
505 
506  const Numeric& examine(double x0, double x1, double x2) const;
507 
508  const Numeric& examine(double x0, double x1, double x2,
509  double x3) const;
510 
511  const Numeric& examine(double x0, double x1, double x2, double x3,
512  double x4) const;
513 
514  const Numeric& examine(double x0, double x1, double x2, double x3,
515  double x4, double x5) const;
516 
517  const Numeric& examine(double x0, double x1, double x2, double x3,
518  double x4, double x5, double x6) const;
519 
520  const Numeric& examine(double x0, double x1, double x2, double x3,
521  double x4, double x5, double x6,
522  double x7) const;
523 
524  const Numeric& examine(double x0, double x1, double x2, double x3,
525  double x4, double x5, double x6, double x7,
526  double x8) const;
527 
528  const Numeric& examine(double x0, double x1, double x2, double x3,
529  double x4, double x5, double x6, double x7,
530  double x8, double x9) const;
531  //@}
532 
533  /**
534  // The "closestBin" functions are similar to the "examine" functions
535  // but always return a valid bin and never overflow. This can be
536  // useful for implementing lookup tables with constant extrapolation
537  // outside of the histogram range.
538  */
539  const Numeric& closestBin(const double* coords,
540  unsigned coordLength) const;
541 
542  //@{
543  /**
544  // Convenience "closestBin" method for histograms of corresponding
545  // dimensionality
546  */
547  const Numeric& closestBin() const;
548 
549  const Numeric& closestBin(double x0) const;
550 
551  const Numeric& closestBin(double x0, double x1) const;
552 
553  const Numeric& closestBin(double x0, double x1, double x2) const;
554 
555  const Numeric& closestBin(double x0, double x1, double x2,
556  double x3) const;
557 
558  const Numeric& closestBin(double x0, double x1, double x2, double x3,
559  double x4) const;
560 
561  const Numeric& closestBin(double x0, double x1, double x2, double x3,
562  double x4, double x5) const;
563 
564  const Numeric& closestBin(double x0, double x1, double x2, double x3,
565  double x4, double x5, double x6) const;
566 
567  const Numeric& closestBin(double x0, double x1, double x2, double x3,
568  double x4, double x5, double x6,
569  double x7) const;
570 
571  const Numeric& closestBin(double x0, double x1, double x2, double x3,
572  double x4, double x5, double x6, double x7,
573  double x8) const;
574 
575  const Numeric& closestBin(double x0, double x1, double x2, double x3,
576  double x4, double x5, double x6, double x7,
577  double x8, double x9) const;
578  //@}
579 
580  /**
581  // The "fillC" functions are similar to the "fill" methods but
582  // they preserve the centroid of the deposit. Note that, if the
583  // histogram dimensionality is high, "fillC" works significantly
584  // slower than the corresponding "fill". Also note that there
585  // must be at least 2 bins in each dimension in order for this
586  // function to work.
587  //
588  // A word of caution. What is added to the bins is the input weight
589  // multiplied by another weight calculated using the bin proximity.
590  // If the input weight is just 1 (which happens quite often in
591  // practice), the product of the weights is normally less than 1.
592  // If the histogram template parameter is one of the integer types,
593  // operator += will convert this product to 0 before adding it to
594  // the bin! Therefore, it is best to use "fillC" only with floating
595  // point template parameters (float, double, etc).
596  //
597  // Currently, the "fillC" methods work sensibly only in the case
598  // the binning is uniform (i.e., the second template parameter is
599  // HistoAxis rather than, let say, NUHistoAxis). They typically
600  // will not even compile if the binning is not uniform.
601  */
602  template <typename Num2>
603  void fillC(const double* coords, unsigned coordLength,
604  const Num2& weight);
605 
606  /** Fill (possibly) multiple times from a flat vector */
607  template <typename Num2>
608  inline void fillC(const std::vector<double>& c, const Num2& weight)
609  {
610  const unsigned long sz = c.size();
611  const unsigned long nFills = sz/dim_;
612  if (sz % dim_) throw std::invalid_argument(
613  "In npstat::HistoND::fillC: incompatible sample size");
614  const double* buf = 0;
615  if (!c.empty()) buf = &c[0];
616  for (unsigned long i=0; i<nFills; ++i)
617  {
618  fillC(buf, dim_, weight);
619  buf += dim_;
620  }
621  }
622 
623  /**
624  // Fill a 1-d histogram from a flat vector of weighted coordinates.
625  // The first element of each pair is the coordinate and the second
626  // is the weight.
627  */
628  template <typename Num2>
629  inline void fillC(const std::vector<std::pair<double,Num2> >& c)
630  {
631  if (dim_ != 1U) throw std::invalid_argument(
632  "In npstat::HistoND::fillC: flat vector of weighted "
633  "coordinates can only be used to fill 1-d histograms");
634  const unsigned long sz = c.size();
635  if (sz)
636  {
637  const std::pair<double,Num2>* buf = &c[0];
638  for (unsigned long i=0; i<sz; ++i, ++buf)
639  fillC(&buf->first, 1U, buf->second);
640  }
641  }
642 
643  //@{
644  /**
645  // Convenience "fillC" method for histograms of corresponding
646  // dimensionality
647  */
648  template <typename Num2>
649  void fillC(const Num2& weight);
650 
651  template <typename Num2>
652  void fillC(double x0, const Num2& weight);
653 
654  template <typename Num2>
655  void fillC(double x0, double x1, const Num2& weight);
656 
657  template <typename Num2>
658  void fillC(double x0, double x1, double x2, const Num2& weight);
659 
660  template <typename Num2>
661  void fillC(double x0, double x1, double x2, double x3,
662  const Num2& weight);
663 
664  template <typename Num2>
665  void fillC(double x0, double x1, double x2, double x3, double x4,
666  const Num2& weight);
667 
668  template <typename Num2>
669  void fillC(double x0, double x1, double x2, double x3, double x4,
670  double x5, const Num2& weight);
671 
672  template <typename Num2>
673  void fillC(double x0, double x1, double x2, double x3, double x4,
674  double x5, double x6, const Num2& weight);
675 
676  template <typename Num2>
677  void fillC(double x0, double x1, double x2, double x3, double x4,
678  double x5, double x6, double x7, const Num2& weight);
679 
680  template <typename Num2>
681  void fillC(double x0, double x1, double x2, double x3, double x4,
682  double x5, double x6, double x7, double x8,
683  const Num2& weight);
684 
685  template <typename Num2>
686  void fillC(double x0, double x1, double x2, double x3, double x4,
687  double x5, double x6, double x7, double x8, double x9,
688  const Num2& weight);
689  //@}
690 
691  /**
692  // Fill from another histogram. Compatibility of axis limits
693  // will not be checked, but compatibility of array shapes will be.
694  */
695  template <typename Num2>
697 
698  /**
699  // Subtract contents of another histogram. Equivalent to multiplying
700  // the contents of the other histogram by -1 and then adding them.
701  // One of the consequences of this approach is that, for histograms
702  // "a" and "b", the sequence of operations "a += b; a -= b;" does not
703  // leave histogram "a" unchanged: although its bin contents will
704  // remain the same (up to round-off errors), the fill counts will
705  // increase by twice the fill counts of "b".
706  */
707  template <typename Num2>
709 
710  //@{
711  /** Method to set contents of individual bins (no bounds checking) */
712  template <typename Num2>
713  void setBin(const unsigned *index, unsigned indexLen, const Num2& v);
714 
715  template <typename Num2>
716  void setBin(const Num2& v);
717 
718  template <typename Num2>
719  void setBin(unsigned i0, const Num2& v);
720 
721  template <typename Num2>
722  void setBin(unsigned i0, unsigned i1, const Num2& v);
723 
724  template <typename Num2>
725  void setBin(unsigned i0, unsigned i1, unsigned i2, const Num2& v);
726 
727  template <typename Num2>
728  void setBin(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
729  const Num2& v);
730 
731  template <typename Num2>
732  void setBin(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
733  unsigned i4, const Num2& v);
734 
735  template <typename Num2>
736  void setBin(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
737  unsigned i4, unsigned i5, const Num2& v);
738 
739  template <typename Num2>
740  void setBin(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
741  unsigned i4, unsigned i5, unsigned i6, const Num2& v);
742 
743  template <typename Num2>
744  void setBin(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
745  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
746  const Num2& v);
747 
748  template <typename Num2>
749  void setBin(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
750  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
751  unsigned i8, const Num2& v);
752 
753  template <typename Num2>
754  void setBin(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
755  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
756  unsigned i8, unsigned i9, const Num2& v);
757 
758  template <typename Num2>
759  inline void setLinearBin(const unsigned long index, const Num2& v)
760  {data_.linearValue(index) = v; ++modCount_;}
761  //@}
762 
763  //@{
764  /** Method to set contents of individual bins with bounds checking */
765  template <typename Num2>
766  void setBinAt(const unsigned *index, unsigned indexLen, const Num2& v);
767 
768  template <typename Num2>
769  void setBinAt(const Num2& v);
770 
771  template <typename Num2>
772  void setBinAt(unsigned i0, const Num2& v);
773 
774  template <typename Num2>
775  void setBinAt(unsigned i0, unsigned i1, const Num2& v);
776 
777  template <typename Num2>
778  void setBinAt(unsigned i0, unsigned i1, unsigned i2, const Num2& v);
779 
780  template <typename Num2>
781  void setBinAt(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
782  const Num2& v);
783 
784  template <typename Num2>
785  void setBinAt(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
786  unsigned i4, const Num2& v);
787 
788  template <typename Num2>
789  void setBinAt(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
790  unsigned i4, unsigned i5, const Num2& v);
791 
792  template <typename Num2>
793  void setBinAt(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
794  unsigned i4, unsigned i5, unsigned i6, const Num2& v);
795 
796  template <typename Num2>
797  void setBinAt(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
798  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
799  const Num2& v);
800 
801  template <typename Num2>
802  void setBinAt(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
803  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
804  unsigned i8, const Num2& v);
805 
806  template <typename Num2>
807  void setBinAt(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
808  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
809  unsigned i8, unsigned i9, const Num2& v);
810 
811  template <typename Num2>
812  inline void setLinearBinAt(const unsigned long index, const Num2& v)
813  {data_.linearValueAt(index) = v; ++modCount_;}
814  //@}
815 
816  /** This method sets all bin contents in one fell swoop */
817  template <typename Num2>
818  void setBinContents(const Num2* data, unsigned long dataLength,
819  bool clearOverflows=true);
820 
821  /** This method sets all overflows in one fell swoop */
822  template <typename Num2>
823  void setOverflows(const Num2* data, unsigned long dataLength);
824 
825  /**
826  // Setting bin contents to some constant value.
827  // The Num2 type should allow automatic conversion to Numeric.
828  */
829  template <typename Num2>
830  inline void setBinsToConst(const Num2& value)
831  {data_.constFill(value); ++modCount_;}
832 
833  /**
834  // Setting overflows to some constant value.
835  // The Num2 type should allow automatic conversion to Numeric.
836  */
837  template <typename Num2>
838  inline void setOverflowsToConst(const Num2& value)
839  {overflow_.constFill(value); ++modCount_;}
840 
841  /**
842  // This member function instructs the histogram to recalculate
843  // the number of fills from data. It may be useful to call this
844  // function after "setBinContents" in case the contents are filled
845  // from another histogram.
846  */
848 
849  //@{
850  /**
851  // This method is intended for data format conversion
852  // programs only, not for typical histogramming use
853  */
854  inline void setNFillsTotal(const unsigned long i)
855  {fillCount_ = i; ++modCount_;}
856  inline void setNFillsOver(const unsigned long i)
857  {overCount_ = i; ++modCount_;}
858  //@}
859 
860  /** In-place multiplication by a scalar (scaling) */
861  template <typename Num2>
862  HistoND& operator*=(const Num2& r);
863 
864  /** In-place division by a scalar */
865  template <typename Num2>
866  HistoND& operator/=(const Num2& r);
867 
868  //@{
869  /** Multiplication by a value which is different for every bin */
870  template <typename Num2>
871  void scaleBinContents(const Num2* data, unsigned long dataLength);
872 
873  template <typename Num2>
874  void scaleOverflows(const Num2* data, unsigned long dataLength);
875  //@}
876 
877  //@{
878  /**
879  // In-place addition of a scalar to all bins. Equivalent to calling
880  // the "fill" function with the same weight once for every bin.
881  */
882  template <typename Num2>
883  void addToBinContents(const Num2& weight);
884 
885  template <typename Num2>
886  void addToOverflows(const Num2& weight);
887  //@}
888 
889  //@{
890  /**
891  // In-place addition of an array. Equivalent to calling the "fill"
892  // function once for every bin with the weight taken from the
893  // corresponding array element.
894  */
895  template <typename Num2>
896  void addToBinContents(const Num2* data, unsigned long dataLength);
897 
898  template <typename Num2>
899  void addToOverflows(const Num2* data, unsigned long dataLength);
900  //@}
901 
902  /**
903  // Add contents of all bins inside the given box to the accumulator.
904  // Note that Numeric type must support multiplication by a double
905  // in order for this function to work (it calculates the overlap
906  // fraction of each bin with the box and multiplies bin content
907  // by that fraction for subsequent accumulation). The operation
908  // Acc += Numeric must be defined.
909  */
910  template <typename Acc>
911  void accumulateBinsInBox(const BoxND<double>& box, Acc* acc,
912  bool calculateAverage = false) const;
913 
914  //@{
915  /**
916  // Code for projecting one histogram onto another. For now,
917  // this is done for bin contents only, not for overflows.
918  // The projection should be created in advance from this
919  // histogram with the aid of the slicing constructor. The indices
920  // used in that constructor should be provided here as well.
921  //
922  // Note that you might want to recalculate the number of fills
923  // from data after performing all projections needed.
924  */
925  template <typename Num2, typename Num3>
928  const unsigned *projectedIndices,
929  unsigned nProjectedIndices) const;
930 
931  template <typename Num2, typename Num3>
932  void addToProjection(HistoND<Num2,Axis>* projection,
933  AbsVisitor<Numeric,Num3>& projector,
934  const unsigned *projectedIndices,
935  unsigned nProjectedIndices) const;
936  //@}
937 
938  /** Transpose the histogram axes and bin contents */
939  HistoND transpose(unsigned axisNum1, unsigned axisNum2) const;
940 
941  /**
942  // This method returns the number of modifications
943  // performed on the histogram since its creation. This number
944  // is always increasing during the lifetime of the histogram
945  // object. Its main property is as follows: if the method
946  // "getModCount" returns the same number twice, there should
947  // be no changes in the histogram object (so that a drawing
948  // program does not need to redraw the histogram image).
949  //
950  // This number is pure transient, it is not serialized and
951  // does not participate in histogram comparisons for equality.
952  */
953  inline unsigned long getModCount() const {return modCount_;}
954 
955  /**
956  // Indicate that the histogram contents have changed. Should
957  // be used by any code which directly modifies histogram bins
958  // (after using const_cast on the relevant reference).
959  */
960  inline void incrModCount() {++modCount_;}
961 
962  //@{
963  /** Method related to "geners" I/O */
964  inline gs::ClassId classId() const {return gs::ClassId(*this);}
965  bool write(std::ostream& of) const;
966  //@}
967 
968  static const char* classname();
969  static inline unsigned version() {return 1;}
970  static HistoND* read(const gs::ClassId& id, std::istream& in);
971 
972  private:
973  HistoND();
974 
975  // Special constructor which speeds up the "transpose" operation.
976  // Does not do full error checking (some of it is done in transpose).
977  HistoND(const HistoND& r, unsigned ax1, unsigned ax2);
978 
979  template <typename Num2>
980  void fillPreservingCentroid(const Num2& weight);
981 
982  template <typename Acc>
983  void accumulateBinsLoop(unsigned level, const BoxND<double>& box,
984  unsigned* idx, Acc* accumulator,
985  double overlapFraction, long double* wsum) const;
986 
987  Numeric overflowSum(unsigned indexToFix, unsigned fixValue) const;
988 
989  std::string title_;
990  std::string accumulatedDataLabel_;
991  ArrayND<Numeric> data_;
992  ArrayND<Numeric> overflow_;
993  std::vector<Axis> axes_;
994  mutable std::vector<double> weightBuf_;
995  mutable std::vector<unsigned> indexBuf_;
996  unsigned long fillCount_;
997  unsigned long overCount_;
998  unsigned long modCount_;
999  unsigned dim_;
1000 
1001 #ifdef SWIG
1002  // Simplified non-template methods for the python API. Not for use in C++.
1003  public:
1004  inline Numeric examine2(const std::vector<double>& c) const
1005  {
1006  const unsigned sz = c.size();
1007  return examine(sz ? &c[0] : (double*)0, sz);
1008  }
1009 
1010  inline Numeric examine2() const
1011  {return examine();}
1012 
1013  inline Numeric examine2(double x0) const
1014  {return examine(x0);}
1015 
1016  inline Numeric examine2(double x0, double x1) const
1017  {return examine(x0, x1);}
1018 
1019  inline Numeric examine2(double x0, double x1, double x2) const
1020  {return examine(x0, x1, x2);}
1021 
1022  inline Numeric examine2(double x0, double x1, double x2,
1023  double x3) const
1024  {return examine(x0, x1, x2, x3);}
1025 
1026  inline Numeric examine2(double x0, double x1, double x2, double x3,
1027  double x4) const
1028  {return examine(x0, x1, x2, x3, x4);}
1029 
1030  inline Numeric examine2(double x0, double x1, double x2, double x3,
1031  double x4, double x5) const
1032  {return examine(x0, x1, x2, x3, x4, x5);}
1033 
1034  inline Numeric examine2(double x0, double x1, double x2, double x3,
1035  double x4, double x5, double x6) const
1036  {return examine(x0, x1, x2, x3, x4, x5, x6);}
1037 
1038  inline Numeric examine2(double x0, double x1, double x2, double x3,
1039  double x4, double x5, double x6,
1040  double x7) const
1041  {return examine(x0, x1, x2, x3, x4, x5, x6, x7);}
1042 
1043  inline Numeric examine2(double x0, double x1, double x2, double x3,
1044  double x4, double x5, double x6, double x7,
1045  double x8) const
1046  {return examine(x0, x1, x2, x3, x4, x5, x6, x7, x8);}
1047 
1048  inline Numeric examine2(double x0, double x1, double x2, double x3,
1049  double x4, double x5, double x6, double x7,
1050  double x8, double x9) const
1051  {return examine(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9);}
1052 
1053  inline Numeric closestBin2(const std::vector<double>& c) const
1054  {
1055  const unsigned sz = c.size();
1056  return closestBin(sz ? &c[0] : (double*)0, sz);
1057  }
1058 
1059  inline Numeric closestBin2() const
1060  {return closestBin();}
1061 
1062  inline Numeric closestBin2(double x0) const
1063  {return closestBin(x0);}
1064 
1065  inline Numeric closestBin2(double x0, double x1) const
1066  {return closestBin(x0, x1);}
1067 
1068  inline Numeric closestBin2(double x0, double x1, double x2) const
1069  {return closestBin(x0, x1, x2);}
1070 
1071  inline Numeric closestBin2(double x0, double x1, double x2,
1072  double x3) const
1073  {return closestBin(x0, x1, x2, x3);}
1074 
1075  inline Numeric closestBin2(double x0, double x1, double x2, double x3,
1076  double x4) const
1077  {return closestBin(x0, x1, x2, x3, x4);}
1078 
1079  inline Numeric closestBin2(double x0, double x1, double x2, double x3,
1080  double x4, double x5) const
1081  {return closestBin(x0, x1, x2, x3, x4, x5);}
1082 
1083  inline Numeric closestBin2(double x0, double x1, double x2, double x3,
1084  double x4, double x5, double x6) const
1085  {return closestBin(x0, x1, x2, x3, x4, x5, x6);}
1086 
1087  inline Numeric closestBin2(double x0, double x1, double x2, double x3,
1088  double x4, double x5, double x6,
1089  double x7) const
1090  {return closestBin(x0, x1, x2, x3, x4, x5, x6, x7);}
1091 
1092  inline Numeric closestBin2(double x0, double x1, double x2, double x3,
1093  double x4, double x5, double x6, double x7,
1094  double x8) const
1095  {return closestBin(x0, x1, x2, x3, x4, x5, x6, x7, x8);}
1096 
1097  inline Numeric closestBin2(double x0, double x1, double x2, double x3,
1098  double x4, double x5, double x6, double x7,
1099  double x8, double x9) const
1100  {return closestBin(x0, x1, x2, x3, x4, x5, x6, x7, x8, x9);}
1101 
1102  inline void setBin2(const std::vector<unsigned>& index, Numeric v)
1103  {
1104  const unsigned sz = index.size();
1105  setBinAt(sz ? &index[0] : (unsigned*)0, sz, v);
1106  }
1107 
1108  inline void setBin2(Numeric v)
1109  {setBinAt(v);}
1110 
1111  inline void setBin2(unsigned i0, Numeric v)
1112  {setBinAt(i0, v);}
1113 
1114  inline void setBin2(unsigned i0, unsigned i1, Numeric v)
1115  {setBinAt(i0, i1, v);}
1116 
1117  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, Numeric v)
1118  {setBinAt(i0, i1, i2, v);}
1119 
1120  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
1121  Numeric v)
1122  {setBinAt(i0, i1, i2, i3, v);}
1123 
1124  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
1125  unsigned i4, Numeric v)
1126  {setBinAt(i0, i1, i2, i3, i4, v);}
1127 
1128  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
1129  unsigned i4, unsigned i5, Numeric v)
1130  {setBinAt(i0, i1, i2, i3, i4, i5, v);}
1131 
1132  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
1133  unsigned i4, unsigned i5, unsigned i6, Numeric v)
1134  {setBinAt(i0, i1, i2, i3, i4, i5, i6, v);}
1135 
1136  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
1137  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
1138  Numeric v)
1139  {setBinAt(i0, i1, i2, i3, i4, i5, i6, i7, v);}
1140 
1141  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
1142  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
1143  unsigned i8, Numeric v)
1144  {setBinAt(i0, i1, i2, i3, i4, i5, i6, i7, i8, v);}
1145 
1146  inline void setBin2(unsigned i0, unsigned i1, unsigned i2, unsigned i3,
1147  unsigned i4, unsigned i5, unsigned i6, unsigned i7,
1148  unsigned i8, unsigned i9, Numeric v)
1149  {setBinAt(i0, i1, i2, i3, i4, i5, i6, i7, i8, i9, v);}
1150 
1151  inline void setLinearBin2(const unsigned long index, Numeric v)
1152  {data_.linearValueAt(index) = v; ++modCount_;}
1153 
1154  inline void setBinsToConst2(const Numeric value)
1155  {data_.constFill(value); ++modCount_;}
1156 
1157  inline void setOverflowsToConst2(const Numeric value)
1158  {overflow_.constFill(value); ++modCount_;}
1159 
1160  inline std::vector<Axis> axes2() const
1161  {return axes_;}
1162 
1163  inline std::vector<double> binWidths() const
1164  {
1165  if (!isUniformlyBinned()) throw std::runtime_error(
1166  "In npstat::HistoND::binWidths: the histogram "
1167  "is not uniformly binned");
1168  std::vector<double> bw(dim_);
1169  for (unsigned i=0; i<dim_; ++i)
1170  bw[i] = axes_[i].binWidth(0);
1171  return bw;
1172  }
1173 
1174  inline ArrayShape shape() const
1175  {
1176  const unsigned* sh = data_.shapeData();
1177  return ArrayShape(sh, sh+dim_);
1178  }
1179 #endif // SWIG
1180  };
1181 
1182  /**
1183  // Reset negative histogram bins to zero and then divide histogram
1184  // bin contents by the histogram integral. If the "knownNonNegative"
1185  // argument is true, it will be assumed that there are no negative
1186  // bins, and their explicit reset is unnecessary.
1187  //
1188  // This function will throw std::runtime_error in case the histogram
1189  // is empty after all negative bins are reset.
1190  //
1191  // This function is not a member of the HistoND class itself because
1192  // these operations do not necessarily make sense for all bin types.
1193  // Making such operation a member would make creation of HistoND
1194  // scripting API (e.g., for python) more difficult.
1195  */
1196  template <typename Histo>
1197  void convertHistoToDensity(Histo* histogram, bool knownNonNegative=false);
1198 
1199  /**
1200  // Generate a density scanning map for subsequent use with
1201  // the "DensityScanND" template. Naturally, only histograms
1202  // with uniform binning can be used here.
1203  */
1204  template <typename Histo>
1205  std::vector<LinearMapper1d> densityScanHistoMap(const Histo& histo);
1206 
1207  /**
1208  // Generate a density scanning map for subsequent use with the
1209  // "DensityScanND" template when a density is to be convolved with
1210  // the histogram data. Only histograms with uniform binning
1211  // can be used here.
1212  //
1213  // The "doubleDataRange" should be set "true" in case the data
1214  // will be mirrored (or just empty range added) to avoid circular
1215  // spilling after convolution.
1216  */
1217  template <typename Histo>
1218  std::vector<CircularMapper1d> convolutionHistoMap(const Histo& histo,
1219  bool doubleDataRange);
1220 }
1221 
1222 #include "npstat/stat/HistoND.icc"
1223 
1224 #endif // NPSTAT_HISTOND_HH_
Arbitrary-dimensional array template.
Histogram axis with equidistant bins.
ArrayND & constFill(Numeric c)
unsigned long length() const
Definition: ArrayND.hh:320
Numeric & linearValue(unsigned long index)
Numeric & linearValueAt(unsigned long index)
Definition: HistoND.hh:46
void setAccumulatedDataLabel(const char *newlabel)
Definition: HistoND.hh:256
const Axis & axis(const unsigned i) const
Definition: HistoND.hh:222
const ArrayND< Numeric > & binContents() const
Definition: HistoND.hh:197
void setTitle(const char *newtitle)
Definition: HistoND.hh:252
HistoND & operator-=(const HistoND< Num2, Axis > &r)
const std::vector< Axis > & axes() const
Definition: HistoND.hh:219
HistoND transpose(unsigned axisNum1, unsigned axisNum2) const
void addToProjection(HistoND< Num2, Axis > *projection, AbsArrayProjector< Numeric, Num3 > &projector, const unsigned *projectedIndices, unsigned nProjectedIndices) const
void dispatch(const double *coords, unsigned coordLength, Num2 &weight, Functor &f)
void accumulateBinsInBox(const BoxND< double > &box, Acc *acc, bool calculateAverage=false) const
void fill(const Num2 &weight)
void binBox(unsigned long binNumber, BoxND< double > *box) const
HistoND(const Axis &xAxis, const Axis &yAxis, const char *title=0, const char *accumulatedDataLabel=0)
void setAxisLabel(const unsigned axisNum, const char *newlabel)
Definition: HistoND.hh:260
HistoND(const HistoND< Num2, Axis > &h, const unsigned *indices, unsigned nIndices, const char *title=0)
void fill(const std::vector< std::pair< double, Num2 > > &c)
Definition: HistoND.hh:357
void addToBinContents(const Num2 &weight)
unsigned long getModCount() const
Definition: HistoND.hh:953
void fillC(const Num2 &weight)
BoxND< double > boundingBox() const
bool operator==(const HistoND &) const
const Numeric & closestBin() const
void setOverflowsToConst(const Num2 &value)
Definition: HistoND.hh:838
double binVolume(unsigned long binNumber=0) const
void setBinAt(const unsigned *index, unsigned indexLen, const Num2 &v)
HistoND(const Axis &a0, const Axis &a1, const Axis &a2, const Axis &a3, const Axis &a4, const Axis &a5, const Axis &a6, const Axis &a7, const Axis &a8, const Axis &a9, const char *title=0, const char *accumulatedDataLabel=0)
HistoND & operator=(const HistoND &)
double integral() const
bool isSameData(const HistoND &) const
Numeric inRangeOverWeight(unsigned axisNumber) const
Definition: HistoND.hh:215
void clearBinContents()
HistoND(const Axis &a0, const Axis &a1, const Axis &a2, const Axis &a3, const Axis &a4, const Axis &a5, const char *title=0, const char *accumulatedDataLabel=0)
HistoND(const HistoND< Num2, Axis > &h, const Axis &newAxis, unsigned newAxisNumber, const char *title=0)
const Numeric & closestBin(const double *coords, unsigned coordLength) const
gs::ClassId classId() const
Definition: HistoND.hh:964
const std::string & accumulatedDataLabel() const
Definition: HistoND.hh:193
void incrModCount()
Definition: HistoND.hh:960
HistoND(const Axis &a0, const Axis &a1, const Axis &a2, const Axis &a3, const Axis &a4, const Axis &a5, const Axis &a6, const char *title=0, const char *accumulatedDataLabel=0)
HistoND(const std::vector< Axis > &axes, const char *title=0, const char *accumulatedDataLabel=0)
const Numeric & examine() const
unsigned long nBins() const
Definition: HistoND.hh:226
void setOverflows(const Num2 *data, unsigned long dataLength)
HistoND(const Axis &a0, const Axis &a1, const Axis &a2, const Axis &a3, const char *title=0, const char *accumulatedDataLabel=0)
HistoND(const Axis &xAxis, const Axis &yAxis, const Axis &zAxis, const char *title=0, const char *accumulatedDataLabel=0)
void clearOverflows()
const std::string & title() const
Definition: HistoND.hh:190
HistoND(const HistoND< Num2, Axis > &h, const Functor &f, const char *title=0, const char *accumulatedDataLabel=0)
void addToBinContents(const Num2 *data, unsigned long dataLength)
void fillC(const std::vector< std::pair< double, Num2 > > &c)
Definition: HistoND.hh:629
unsigned long nFillsInRange() const
Definition: HistoND.hh:232
void setBinContents(const Num2 *data, unsigned long dataLength, bool clearOverflows=true)
void fillC(const double *coords, unsigned coordLength, const Num2 &weight)
unsigned dim() const
Definition: HistoND.hh:187
HistoND(const Axis &a0, const Axis &a1, const Axis &a2, const Axis &a3, const Axis &a4, const Axis &a5, const Axis &a6, const Axis &a7, const char *title=0, const char *accumulatedDataLabel=0)
HistoND & operator/=(const Num2 &r)
void recalculateNFillsFromData()
HistoND(const Axis &a0, const Axis &a1, const Axis &a2, const Axis &a3, const Axis &a4, const char *title=0, const char *accumulatedDataLabel=0)
HistoND(const Axis &xAxis, const char *title=0, const char *accumulatedDataLabel=0)
bool operator!=(const HistoND &) const
HistoND(const HistoND &)
unsigned long nFillsOver() const
Definition: HistoND.hh:236
void dispatch(Num2 &weight, Functor &f)
HistoND & operator+=(const HistoND< Num2, Axis > &r)
bool isUniformlyBinned() const
void scaleBinContents(const Num2 *data, unsigned long dataLength)
std::vector< double > lowerAxisLimits() const
void allBinCenters(std::vector< Point > *centers) const
void setBin(const unsigned *index, unsigned indexLen, const Num2 &v)
void binCenter(unsigned long binNumber, double *coords, unsigned lenCoords) const
double volume() const
void fillC(const std::vector< double > &c, const Num2 &weight)
Definition: HistoND.hh:608
void fill(const double *coords, unsigned coordLength, const Num2 &weight)
void setBinsToConst(const Num2 &value)
Definition: HistoND.hh:830
HistoND(const Axis &a0, const Axis &a1, const Axis &a2, const Axis &a3, const Axis &a4, const Axis &a5, const Axis &a6, const Axis &a7, const Axis &a8, const char *title=0, const char *accumulatedDataLabel=0)
void fill(const std::vector< double > &c, const Num2 &weight)
Definition: HistoND.hh:336
HistoND & operator*=(const Num2 &r)
unsigned long nFillsTotal() const
Definition: HistoND.hh:229
Numeric underflowWeight(unsigned axisNumber) const
Definition: HistoND.hh:206
void setNFillsTotal(const unsigned long i)
Definition: HistoND.hh:854
HistoND(const ArrayShape &shape, const BoxND< double > &boundingBox, const char *title=0, const char *accumulatedDataLabel=0)
const ArrayND< Numeric > & overflows() const
Definition: HistoND.hh:200
const Numeric & examine(const double *coords, unsigned coordLength) const
HistoND(const HistoND< Num2, Axis > &h, RebinType rType, const unsigned *newBinCounts, unsigned lenNewBinCounts, const double *shifts=0, const char *title=0)
Definition: AbsArrayProjector.hh:14
std::vector< unsigned > ArrayShape
Definition: ArrayShape.hh:21
std::vector< CircularMapper1d > convolutionHistoMap(const Histo &histo, bool doubleDataRange)
void convertHistoToDensity(Histo *histogram, bool knownNonNegative=false)
std::vector< LinearMapper1d > densityScanHistoMap(const Histo &histo)
Definition: AbsArrayProjector.hh:21
Definition: AbsVisitor.hh:20