npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
MinuitSemiparametricFitUtils.hh
Go to the documentation of this file.
1 #ifndef NPSI_MINUITSEMIPARAMETRICFITUTILS_HH_
2 #define NPSI_MINUITSEMIPARAMETRICFITUTILS_HH_
3 
4 /*!
5 // \file MinuitSemiparametricFitUtils.hh
6 //
7 // \brief Utilities for semiparametric fitting of signal/backround mixtures
8 //
9 // Author: I. Volobouev
10 //
11 // October 2013
12 */
13 
14 #include <cmath>
15 #include <cassert>
16 
17 #include "npstat/stat/HistoND.hh"
19 
20 namespace npsi {
21  //
22  // histo -- the fitted histogram
23  //
24  // filterDeg -- LOrPE filter degree
25  //
26  // m -- power of the symmetric beta kernel (Gaussian if m < 0)
27  //
28  template <typename Numeric>
29  inline double boundaryBandwidth1D(const npstat::HistoND<Numeric>& histo,
30  const double filterDeg,
31  const int m)
32  {
33  // The minimal bandwidth must be such that there are still
34  // enough bins covered by the filter weight function in order
35  // to fit the polynomial of the requested maximum degree near
36  // the histogram edge.
37  assert(histo.dim() == 1U);
38  double minBandwidth = (filterDeg + 2.0)*histo.binVolume();
39  if (m < 0)
40  minBandwidth /= 12.0;
41  return minBandwidth;
42  }
43 
44  //
45  // Approximate bandwidth needed to model a feature of certain size
46  //
47  inline double featureBandwidth1D(const double featureSize,
48  const double filterDeg,
49  const double effectiveNBg,
50  const int m)
51  {
52  double bw = 0.0;
53  if (featureSize > 0.0)
54  {
55  bw = npstat::approxAmisePluginBwGauss(filterDeg, effectiveNBg,
56  featureSize);
57  if (m >= 0)
58  bw *= npstat::approxSymbetaBandwidthRatio(m, filterDeg);
59  }
60  return bw;
61  }
62 
63  //
64  // Minimum bandwidth to use for background density estimation
65  //
66  template <typename Numeric>
67  inline double minHistoBandwidth1D(const npstat::HistoND<Numeric>& histo,
68  const double featureSize,
69  const double filterDeg,
70  const double nbg,
71  const int m)
72  {
73  const double bw1 = boundaryBandwidth1D(histo, filterDeg, m);
74  const double bw2 = featureBandwidth1D(featureSize, filterDeg, nbg, m);
75  return std::sqrt(bw1*bw1 + bw2*bw2);
76  }
77 }
78 
79 #endif // NPSI_MINUITSEMIPARAMETRICFITUTILS_HH_
Arbitrary-dimensional histogram template.
Optimal AMISE bandwidth for KDE with high order kernels.
Definition: HistoND.hh:46
double binVolume(unsigned long binNumber=0) const
unsigned dim() const
Definition: HistoND.hh:187
Definition: fitCompositeJohnson.hh:16
double approxSymbetaBandwidthRatio(int power, double filterDegree)
double approxAmisePluginBwGauss(double filterDegree, double npoints, double sampleSigma)