meerkat is hosted by Hepforge, IPPP Durham
Meerkat  v1r3
Multidimensional kernel density estimation package
ProductDensity.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 "ProductDensity.hh"
10 
11 #include "Logger.hh"
12 
13 ProductDensity::ProductDensity(const char* pdfName,
14  AbsPhaseSpace* thePhaseSpace,
15  std::vector<AbsDensity*> &densityComponents) : AbsDensity(pdfName) {
16 
17  init(thePhaseSpace, densityComponents);
18 }
19 
20 ProductDensity::ProductDensity(const char* pdfName,
21  AbsPhaseSpace* thePhaseSpace,
22  AbsDensity* d1, AbsDensity* d2,
23  AbsDensity* d3, AbsDensity* d4) : AbsDensity(pdfName) {
24 
25  std::vector<AbsDensity*> densityVector(2);
26  densityVector[0] = d1;
27  densityVector[1] = d2;
28  if (d3) {
29  densityVector.push_back(d3);
30  }
31  if (d4) {
32  densityVector.push_back(d4);
33  }
34  init(thePhaseSpace, densityVector);
35 }
36 
38 
39 }
40 
41 void ProductDensity::init(AbsPhaseSpace* thePhaseSpace,
42  std::vector<AbsDensity*> &densityComponents) {
43 
44  m_phaseSpace = thePhaseSpace;
45  m_densityComponents = densityComponents;
46 
47  Logger::print(0,"%20.20s INFO: Creating product density of %d components\n", m_name, (UInt_t)densityComponents.size() );
48 
50 
51  std::vector<AbsDensity*>::iterator i;
52  for (i=densityComponents.begin(); i != densityComponents.end(); i++) {
53  UInt_t dim = (*i)->phaseSpace()->dimensionality();
54  if (dim != m_dim) {
55  Logger::print(2,"%20.20s ERROR: Dimensionalities of the product phase space and its component %s differ\n", m_name, (*i)->name() );
56  abort();
57  }
58  }
59 
60 }
61 
62 Double_t ProductDensity::density(std::vector<Double_t> &x) {
63 
64  if (x.size() != m_dim) {
65  Logger::print(2,"%20.20s ERROR: Dimensionality of vector (%d) does not correspond to phase space definition (%d)\n",
66  m_name, (UInt_t)x.size(), m_dim);
67  abort();
68  }
69 
70  Double_t prod = 1.;
71  std::vector<AbsDensity*>::iterator i;
72  for (i=m_densityComponents.begin(); i != m_densityComponents.end(); i++) {
73  Double_t d = (*i)->density(x);
74  prod *= d;
75 // Logger::print(0,"Component %d, density=%f, prod=%f\n", n, d, prod);
76  }
77  return prod;
78 }
UInt_t m_dim
Cached dimensionality of the phase space.
Abstract class which defines probability density interface.
Definition: AbsDensity.hh:16
Double_t density(std::vector< Double_t > &x)
Calculate PDF value at the given point.
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.
ProductDensity(const char *pdfName, AbsPhaseSpace *thePhaseSpace, std::vector< AbsDensity * > &densityComponents)
Constructor of Product density of an arbitrary number of density components.
void init(AbsPhaseSpace *thePhaseSpace, std::vector< AbsDensity * > &densityComponents)
Common initialise function used by all constructors.
std::vector< AbsDensity * > m_densityComponents
Vector of density components.
virtual ~ProductDensity()
Destructor.
AbsPhaseSpace * m_phaseSpace
Reference to phase space.