meerkat is hosted by Hepforge, IPPP Durham
Meerkat  v1r3
Multidimensional kernel density estimation package
CombinedPhaseSpace.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <vector>
3 
4 #include "TMath.h"
5 
6 #include "CombinedPhaseSpace.hh"
7 
8 #include "Logger.hh"
9 
11  std::vector<AbsPhaseSpace*> &phspList) : AbsPhaseSpace(phspName) {
12  init(phspList);
13 }
14 
16  AbsPhaseSpace *phaseSpace1,
17  AbsPhaseSpace *phaseSpace2,
18  AbsPhaseSpace *phaseSpace3,
19  AbsPhaseSpace *phaseSpace4) : AbsPhaseSpace(phspName) {
20 
21  std::vector<AbsPhaseSpace*> phspVector(2);
22  phspVector[0] = phaseSpace1;
23  phspVector[1] = phaseSpace2;
24  if (phaseSpace3) {
25  phspVector.push_back(phaseSpace3);
26  }
27  if (phaseSpace4) {
28  phspVector.push_back(phaseSpace4);
29  }
30 
31  init(phspVector);
32 
33 }
34 
36 
37 }
38 
39 void CombinedPhaseSpace::init(std::vector<AbsPhaseSpace*> &phspList) {
40 
41  m_phspList = phspList;
42  m_dim = 0;
43 
44  std::vector<AbsPhaseSpace*>::iterator i;
45 
46  Logger::print(0,"%20.20s INFO: Creating combined phase space of %d components\n", m_name, (UInt_t)m_phspList.size() );
47 
48  // Calculate dimensionality as a sum of component phase spaces
49  for (i=m_phspList.begin(); i != m_phspList.end(); i++) {
50  UInt_t dim = (*i)->dimensionality();
51  Logger::print(0,"%20.20s INFO: Adding component phase space \"%s\", dim=%d\n", m_name, (*i)->name(), dim);
52  m_dim += dim;
53  }
54  Logger::print(0,"%20.20s INFO: Resulting dimensionality is %d\n", m_name, m_dim);
55 
56  m_lowerLimit.resize(m_dim);
57  m_upperLimit.resize(m_dim);
58 
59  // Cache lower and upper limits for variables from component phase spaces
60  UInt_t n = 0;
61  for (i=m_phspList.begin(); i != m_phspList.end(); i++) {
62  UInt_t dim = (*i)->dimensionality();
63  UInt_t j;
64  for (j=0; j<dim; j++) {
65  m_lowerLimit[n] = (*i)->lowerLimit(j);
66  m_upperLimit[n] = (*i)->upperLimit(j);
67  n++;
68  }
69  }
70 }
71 
72 
74  return m_dim;
75 }
76 
77 Bool_t CombinedPhaseSpace::withinLimits(std::vector<Double_t> &x) {
78  if (x.size() != m_dim) {
79  Logger::print(1,"%20.20s WARNING: Dimensionality of vector (%d) does not correspond to phase space definition (%d)\n",
80  m_name, (UInt_t)x.size(), m_dim);
81  return 0;
82  }
83 
84  UInt_t n=0;
85  std::vector<AbsPhaseSpace*>::iterator i;
86  for (i=m_phspList.begin(); i != m_phspList.end(); i++) {
87  UInt_t dim = (*i)->dimensionality();
88  UInt_t j;
89  std::vector<Double_t> subset(dim);
90  for (j=0; j<dim; j++) {
91  subset[j] = x[n];
92  n++;
93  }
94  if ( !(*i)->withinLimits(subset) ) return 0;
95  }
96 
97  return 1;
98 }
99 
100 Double_t CombinedPhaseSpace::lowerLimit(UInt_t var) {
101  if (var < m_lowerLimit.size()) {
102  return m_lowerLimit[var];
103  }
104 
105  Logger::print(2,"%20.20s ERROR: var=%d for lower limit of combined phase space of dim=%d\n", m_name, var, m_dim);
106  abort();
107 
108  return 0;
109 }
110 
111 Double_t CombinedPhaseSpace::upperLimit(UInt_t var) {
112  if (var < m_upperLimit.size()) {
113  return m_upperLimit[var];
114  }
115 
116  Logger::print(2,"%20.20s ERROR: var=%d for upper limit of combined phase space of dim=%d\n", m_name, var, m_dim);
117  abort();
118 
119  return 0;
120 }
121 
122 Bool_t CombinedPhaseSpace::limits(UInt_t var, std::vector<Double_t> &x,
123  Double_t* lower, Double_t* upper) {
124 
125  UInt_t n = 0;
126  UInt_t m = 0;
127  std::vector<AbsPhaseSpace*>::iterator i;
128 
129  for (i=m_phspList.begin(); i != m_phspList.end(); i++) {
130  UInt_t dim = (*i)->dimensionality();
131  std::vector<Double_t> subset(dim);
132  UInt_t j;
133 
134  for (j=0; j<dim; j++) {
135  subset[j] = x[m];
136  m++;
137  }
138 
139  for (j=0; j<dim; j++) {
140  if (x[n] < m_lowerLimit[n] || x[n] > m_upperLimit[n])
141  return 0;
142  if (n == var) {
143  Bool_t res = (*i)->limits(j, subset, lower, upper);
144  if (!res) return 0;
145  }
146  n++;
147  }
148  }
149  return 1;
150 
151 }
char m_name[256]
Phase space name.
std::vector< Double_t > m_lowerLimit
Vector of cached lower limits in each variable.
Double_t upperLimit(UInt_t var)
Return upper allowed limit of the variable.
void print(int level, const char *format,...)
Definition: Logger.cpp:27
std::vector< Double_t > m_upperLimit
Vector of cached upper limits in each variable.
Abstract class which defines phase space interface.
CombinedPhaseSpace(const char *phaseSpaceName, std::vector< AbsPhaseSpace * > &phspList)
Constructor from the vector of component phase spaces.
Double_t lowerLimit(UInt_t var)
Return lower allowed limit of the variable.
Bool_t limits(UInt_t var, std::vector< Double_t > &x, Double_t *lower, Double_t *upper)
Return limits (lower and upper) for the variable at the certain point of the phase space...
virtual ~CombinedPhaseSpace()
Destructor.
UInt_t m_dim
Cached dimensionality of the combined phase space.
Bool_t withinLimits(std::vector< Double_t > &x)
Check if the point is within phase space limits.
void init(std::vector< AbsPhaseSpace * > &phspList)
Common initialise function for all constructors.
std::vector< AbsPhaseSpace * > m_phspList
vector of component phase spaces
UInt_t dimensionality()
Get dimensionality of phase space.