meerkat is hosted by Hepforge, IPPP Durham
Meerkat  v1r3
Multidimensional kernel density estimation package
DivideDensity.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <vector>
3 #include <stdlib.h>
4 
5 #include "TMath.h"
6 
7 #include "AbsPhaseSpace.hh"
8 #include "AbsDensity.hh"
9 #include "DivideDensity.hh"
10 
11 #include "Logger.hh"
12 
13 DivideDensity::DivideDensity(const char* pdfName,
14  AbsPhaseSpace* thePhaseSpace,
15  AbsDensity* d1, AbsDensity* d2) : AbsDensity(pdfName) {
16 
17  m_phaseSpace = thePhaseSpace;
18  m_density1 = d1;
19  m_density2 = d2;
20 
21  Logger::print(0,"%20.20s INFO: Creating divide density\n", m_name);
22 
24 
25  UInt_t dim = m_density1->phaseSpace()->dimensionality();
26  if (dim != m_dim) {
27  Logger::print(2,"%20.20s ERROR: Dimensionalities of the Divide phase space and its component %s differ\n", m_name, m_density1->name() );
28  abort();
29  }
31  if (dim != m_dim) {
32  Logger::print(2,"%20.20s ERROR: Dimensionalities of the Divide phase space and its component %s differ\n", m_name, m_density2->name() );
33  abort();
34  }
35 }
36 
38 
39 }
40 
41 Double_t DivideDensity::density(std::vector<Double_t> &x) {
42 
43  if (x.size() != m_dim) {
44  Logger::print(2,"%20.20s ERROR: Dimensionality of vector (%d) does not correspond to phase space definition (%d)\n",
45  m_name, (UInt_t)x.size(), m_dim);
46  abort();
47  }
48 
49  Double_t d1 = m_density1->density(x);
50  Double_t d2 = m_density2->density(x);
51  Double_t d = d1;
52  if (d2 > 0.) {
53  d /= d2;
54  } else {
55  d = 0.;
56  }
57  return d;
58 }
const char * name(void)
Return the name of the PDF.
Definition: AbsDensity.hh:106
Abstract class which defines probability density interface.
Definition: AbsDensity.hh:16
virtual AbsPhaseSpace * phaseSpace()=0
Return phase space definition for this PDF.
void print(int level, const char *format,...)
Definition: Logger.cpp:27
char m_name[256]
PDF name.
Definition: AbsDensity.hh:118
DivideDensity(const char *pdfName, AbsPhaseSpace *thePhaseSpace, AbsDensity *d1, AbsDensity *d2)
Constructor of Divide density.
AbsDensity * m_density2
Density component 2.
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.
AbsPhaseSpace * m_phaseSpace
Reference to phase space.
virtual Double_t density(std::vector< Double_t > &x)=0
Calculate PDF value at the given point.
UInt_t m_dim
Cached dimensionality of the phase space.
virtual ~DivideDensity()
Destructor.
AbsDensity * m_density1
Density component 1.