meerkat is hosted by Hepforge, IPPP Durham
Meerkat  v1r3
Multidimensional kernel density estimation package
HistogramDensity.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <vector>
3 
4 #include "TH1.h"
5 
6 #include "AbsPhaseSpace.hh"
7 #include "AbsDensity.hh"
8 #include "HistogramDensity.hh"
9 
10 #include "Logger.hh"
11 
12 HistogramDensity::HistogramDensity(const char* pdfName, AbsPhaseSpace* thePhaseSpace, TH1* hist) : AbsDensity(pdfName) {
13 
14  m_phaseSpace = thePhaseSpace;
16 
17  if (m_dim > 3) {
18  Logger::print(2, "%20.20s ERROR: Dimensionality of the HistogramDensity phase space is %d (must not exceed 3)\n",
19  m_name, m_dim);
20  abort();
21  }
22 
23  m_hist = hist;
24 }
25 
27 
28 }
29 
30 Double_t HistogramDensity::density(std::vector<Double_t> &x) {
31 
32  UInt_t i;
33  Double_t arg[3];
34  for (i=0; i<3; i++) arg[i] = 0;
35 
36  for (i=0; i<m_dim; i++) {
37  arg[i] = x[i];
38  }
39 
40  if (m_dim == 1)
41  return m_hist->Interpolate(arg[0]);
42  if (m_dim == 2)
43  return m_hist->Interpolate(arg[0], arg[1]);
44  if (m_dim == 3)
45  return m_hist->Interpolate(arg[0], arg[1], arg[2]);
46  return 0.;
47 }
virtual ~HistogramDensity()
Abstract class which defines probability density interface.
Definition: AbsDensity.hh:16
void print(int level, const char *format,...)
Definition: Logger.cpp:27
char m_name[256]
PDF name.
Definition: AbsDensity.hh:118
Abstract class which defines phase space interface.
virtual UInt_t dimensionality()=0
Get dimensionality of phase space.
TH1 * m_hist
ROOT Histogram.
Double_t density(std::vector< Double_t > &x)
Calculate PDF value at the given point.
HistogramDensity(const char *pdfName, AbsPhaseSpace *thePhaseSpace, TH1 *Histogram)
Constructor.
AbsPhaseSpace * m_phaseSpace
Reference to phase space.
UInt_t m_dim
Cached dimensionality of the phase space.