npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
histoUtils.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_HISTOUTILS_HH_
2 #define NPSTAT_HISTOUTILS_HH_
3 
4 /*!
5 // \file histoUtils.hh
6 //
7 // \brief Various utility code related to histogram filling, etc
8 //
9 // Author: I. Volobouev
10 //
11 // April 2015
12 */
13 
14 #include <utility>
15 
16 #include "npstat/stat/HistoND.hh"
18 
19 namespace npstat {
20  /**
21  // Fill histogram with weighted values. Weights are calculated
22  // on the basis of position of an entry in a sorted collection
23  // (typically, std::vector). If the collection has length N, the
24  // entry with number m is assigned the "coordinate" x = m/(N - 1).
25  // Then the argument density is used to calculate a weight from
26  // this "coordinate".
27  //
28  // The coordinate with which the histogram is filled is calculated
29  // from each entry by a functor. This functor (represented by the
30  // CoordExtractor template parameter) should take (a const reference
31  // to) a collection element as its argument and return a double.
32  //
33  // It is assumed that the density has a finite bandwidth. The
34  // collection scan starts near the "coordinate" obtained from
35  // the density "location" function and proceeds up and down only
36  // until the first point with 0 weight is encountered. Typical
37  // densities useful with this function are TruncatedGauss1D
38  // and SymmetricBeta1D.
39  //
40  // The function returns the Kish's effective sample size for the
41  // histogram fills performed.
42  */
43  template<class Axis, class Collection, class CoordExtractor>
44  double fill1DHistoWithCDFWeights(const Collection& coll,
45  const AbsScalableDistribution1D& weightCalc,
46  CoordExtractor extractor,
48 
49  /**
50  // Similar function which fills the histogram with a product of
51  // weights calculated by "weightCalc" and "coordWeightCalc".
52  // "weightCalc" works just like in the previous function.
53  // "coordWeightCalc" is a functor which is given two arguments:
54  // the collection element and the coordinate of the bin center.
55  // For each collection element, each bin of the histogram is filled
56  // with the product of the weights returned by "weightCalc" and
57  // "coordWeightCalc".
58  //
59  // The function returns the sum of the weights calculated by
60  // "weightCalc" as the first element of the pair and the sum of
61  // these weights squared as the second element.
62  */
63  template<class Axis, class Collection, class CoordWeightCalc>
64  std::pair<double,double>
65  multiFill1DHistoWithCDFWeights(const Collection& coll,
66  const AbsScalableDistribution1D& weightCalc,
67  CoordWeightCalc coordWeightCalc,
69 }
70 
71 #include "npstat/stat/histoUtils.icc"
72 
73 #endif // NPSTAT_HISTOUTILS_HH_
Interface definition for 1-d continuous statistical distributions.
Arbitrary-dimensional histogram template.
Definition: AbsDistribution1D.hh:165
Definition: HistoND.hh:46
Definition: AbsArrayProjector.hh:14
std::pair< double, double > multiFill1DHistoWithCDFWeights(const Collection &coll, const AbsScalableDistribution1D &weightCalc, CoordWeightCalc coordWeightCalc, HistoND< double, Axis > *h)
double fill1DHistoWithCDFWeights(const Collection &coll, const AbsScalableDistribution1D &weightCalc, CoordExtractor extractor, HistoND< double, Axis > *h)