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