npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
FitUtils.hh
Go to the documentation of this file.
1 #ifndef NPSTAT_FITUTILS_HH_
2 #define NPSTAT_FITUTILS_HH_
3 
4 /*!
5 // \file FitUtils.hh
6 //
7 // \brief Utility functions which facilitate fitting of parametric distributions
8 //
9 // Author: I. Volobouev
10 //
11 // September 2010
12 */
13 
14 #include "npstat/stat/HistoND.hh"
16 
17 namespace npstat {
18  /**
19  // This function calculates log-likelihood of a 1-d histogram
20  // fit by a 1-d density (the value can then be maximized -- see,
21  // for example, MinuitDensityFitFcn1D.hh header in the "interfaces"
22  // section).
23  //
24  // The length of the "binMask" array should be the same as the number
25  // of bins in the histogram. Only those bins will be used for which
26  // corresponding mask values are not 0.
27  //
28  // The "workBuffer" array should be at least as long as the number
29  // of bins in the histogram.
30  //
31  // "minlog" is the minimal value of log-likelihood which can be
32  // contributed by one data point (that is, by a part of the bin height
33  // which corresponds to 1 point). This should normally be a negative
34  // number with reasonably large magnitude.
35  //
36  // "nQuad" is the number of quadrature points to use for calculating
37  // the density integral inside each bin (should be supported by
38  // GaussLegendreQuadrature class). If this parameter is set to 0,
39  // cumulative density function will be used.
40  //
41  // "densityArea" and "enabledBinCount" can be used to obtain the
42  // area of the density and the bin count for masked bins.
43  //
44  // The code essentially assumes Poisson distribution of counts
45  // for each bin, constrained by the requirement that the sum of
46  // expected events should be equal to the sum of events observed
47  // (all of this is relevant for unmasked bins only). Note that,
48  // although histogram scaling will not affect the central value
49  // of the fit, it will affect the fit error determination.
50  // Therefore, it is important to use histograms with actual
51  // event counts rather than any kind of a scaled version.
52  */
53  template<class Histo>
55  const Histo& histo,
56  const unsigned char* binMask, unsigned maskLength,
57  const AbsDistribution1D& density, double minlog,
58  double* workBuffer, unsigned workBufferLength,
59  unsigned nQuad = 6U, double* densityArea = 0,
60  double* enabledBinCount = 0);
61 
62  /** Simple unbinned log-likelihood for a 1-d sample of points */
63  template<typename Numeric>
65  const Numeric* samplePonts, unsigned long sampleLength,
66  const AbsDistribution1D& density, double minlog);
67 
68 #ifdef SWIG
69  inline double unbinnedLogLikelihood1D_2(
70  const double* samplePonts, unsigned long nSamplePonts,
71  const AbsDistribution1D& density, double minlog)
72  {
73  return unbinnedLogLikelihood1D(samplePonts, nSamplePonts,
74  density, minlog);
75  }
76 #endif // SWIG
77 }
78 
79 #include "npstat/stat/FitUtils.icc"
80 
81 #endif // NPSTAT_FITUTILS_HH_
Interface definition for 1-d continuous statistical distributions.
Arbitrary-dimensional histogram template.
Definition: AbsArrayProjector.hh:14
double unbinnedLogLikelihood1D(const Numeric *samplePonts, unsigned long sampleLength, const AbsDistribution1D &density, double minlog)
double densityFitLogLikelihood1D(const Histo &histo, const unsigned char *binMask, unsigned maskLength, const AbsDistribution1D &density, double minlog, double *workBuffer, unsigned workBufferLength, unsigned nQuad=6U, double *densityArea=0, double *enabledBinCount=0)
Definition: AbsDistribution1D.hh:31