meerkat is hosted by Hepforge, IPPP Durham
Meerkat  v1r3
Multidimensional kernel density estimation package
TransposedFactorisedDensity.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"
10 
11 #include "Logger.hh"
12 
14  AbsPhaseSpace* thePhaseSpace,
15  AbsDensity* d1, AbsDensity* d2,
16  UInt_t index) : AbsDensity(pdfName) {
17 
18  m_density1 = d1;
19  m_density2 = d2;
20  m_index = index;
21 
22  m_phaseSpace = thePhaseSpace;
23 
24  Logger::print(0,"%20.20s INFO: Creating transposed factorised density\n", m_name );
25 
29 
30  if (m_dim1 + m_dim2 != m_dim) {
31  Logger::print(2,"%20.20s ERROR: Dimensionalities of the factorised phase space and sum of its components differ\n", m_name);
32  abort();
33  }
34 }
35 
37 
38 }
39 
40 Double_t TransposedFactorisedDensity::density(std::vector<Double_t> &x) {
41 
42  if (x.size() != m_dim) {
43  Logger::print(2,"%20.20s ERROR: Dimensionality of vector (%d) does not correspond to phase space definition (%d)\n",
44  m_name, (UInt_t)x.size(), m_dim);
45  abort();
46  }
47 
48  Double_t prod = 1.;
49  std::vector<Double_t> x1(m_dim1);
50  std::vector<Double_t> x2(m_dim2);
51 
52  UInt_t j;
53  for (j=0; j<m_dim1; j++) {
54  if (j<m_index)
55  x1[j] = x[j];
56  else
57  x1[j] = x[j+m_dim2];
58  }
59  for (j=0; j<m_dim2; j++) {
60  x2[j] = x[j+m_index];
61  }
62  prod = m_density1->density(x1)*m_density2->density(x2);
63 
64 // Logger::print(0,"Component %d, density=%f, prod=%f\n", n, d, prod);
65 
66  return prod;
67 
68 }
TransposedFactorisedDensity(const char *pdfName, AbsPhaseSpace *thePhaseSpace, AbsDensity *density1, AbsDensity *density2, UInt_t index)
Constructor of factorised density of an arbitrary number of density components.
UInt_t m_dim2
Cached dimensionality of the density 2 phase space.
Abstract class which defines probability density interface.
Definition: AbsDensity.hh:16
virtual ~TransposedFactorisedDensity()
Destructor.
virtual AbsPhaseSpace * phaseSpace()=0
Return phase space definition for this PDF.
AbsDensity * m_density1
Density component 1.
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.
Double_t density(std::vector< Double_t > &x)
Calculate PDF value at the given point.
AbsDensity * m_density2
Density component 2.
UInt_t m_index
Index at which density 2 phase space is inserted.
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 combined phase space.
AbsPhaseSpace * m_phaseSpace
Reference to phase space.
UInt_t m_dim1
Cached dimensionality of the density 1 phase space.