meerkat is hosted by Hepforge, IPPP Durham
Meerkat  v1r3
Multidimensional kernel density estimation package
IntersectionPhaseSpace.cpp
Go to the documentation of this file.
1 #include <stdio.h>
2 #include <vector>
3 
4 #include "TMath.h"
5 
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 IntersectionPhaseSpace::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 Intersection 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  if (m_dim == 0) m_dim = dim;
53  if (m_dim != dim) {
54  Logger::print(1,"%20.20s WARNING: Dimensionality of \"%s\" (%d) does not match previous (%d)\n", m_name, (*i)->name(), dim, m_dim);
55  abort();
56  }
57  }
58 
59  m_lowerLimit.resize(m_dim);
60  m_upperLimit.resize(m_dim);
61 
62  // Cache lower and upper limits for variables from component phase spaces
63  UInt_t j;
64  for (j=0; j<m_dim; j++) {
65  i = m_phspList.begin();
66  Double_t maxLowerLimit = (*i)->lowerLimit(j);
67  Double_t minUpperLimit = (*i)->upperLimit(j);
68  for (i=m_phspList.begin(); i != m_phspList.end(); i++) {
69  if (maxLowerLimit < (*i)->lowerLimit(j) ) maxLowerLimit = (*i)->lowerLimit(j);
70  if (minUpperLimit > (*i)->upperLimit(j) ) minUpperLimit = (*i)->upperLimit(j);
71  }
72  m_lowerLimit[j] = maxLowerLimit;
73  m_upperLimit[j] = minUpperLimit;
74  }
75 }
76 
77 
79  return m_dim;
80 }
81 
82 Bool_t IntersectionPhaseSpace::withinLimits(std::vector<Double_t> &x) {
83  if (x.size() != m_dim) {
84  Logger::print(1,"%20.20s WARNING: Dimensionality of vector (%d) does not correspond to phase space definition (%d)\n",
85  m_name, (UInt_t)x.size(), m_dim);
86  return 0;
87  }
88 
89  std::vector<AbsPhaseSpace*>::iterator i;
90  for (i=m_phspList.begin(); i != m_phspList.end(); i++) {
91  if ( !(*i)->withinLimits(x) ) return 0;
92  }
93  return 1;
94 }
95 
96 Double_t IntersectionPhaseSpace::lowerLimit(UInt_t var) {
97  if (var < m_lowerLimit.size()) {
98  return m_lowerLimit[var];
99  }
100 
101  Logger::print(2,"%20.20s ERROR: var=%d for lower limit of Intersection phase space of dim=%d\n", m_name, var, m_dim);
102  abort();
103 
104  return 0;
105 }
106 
108  if (var < m_upperLimit.size()) {
109  return m_upperLimit[var];
110  }
111 
112  Logger::print(2,"%20.20s ERROR: var=%d for upper limit of Intersection phase space of dim=%d\n", m_name, var, m_dim);
113  abort();
114 
115  return 0;
116 }
117 
118 Bool_t IntersectionPhaseSpace::limits(UInt_t var, __attribute__((unused)) std::vector<Double_t> &x,
119  Double_t* lower, Double_t* upper) {
120 
121  *lower = lowerLimit(var);
122  *upper = upperLimit(var);
123 
124  return 0;
125 
126 }
IntersectionPhaseSpace(const char *phaseSpaceName, std::vector< AbsPhaseSpace * > &phspList)
Constructor from the vector of component phase spaces.
std::vector< Double_t > m_upperLimit
Vector of cached upper limits in each variable.
char m_name[256]
Phase space name.
void print(int level, const char *format,...)
Definition: Logger.cpp:27
std::vector< AbsPhaseSpace * > m_phspList
vector of component phase spaces
UInt_t m_dim
Cached dimensionality of the Intersection phase space.
Abstract class which defines phase space interface.
void init(std::vector< AbsPhaseSpace * > &phspList)
Common initialise function for all constructors.
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...
Double_t upperLimit(UInt_t var)
Return upper allowed limit of the variable.
virtual ~IntersectionPhaseSpace()
Destructor.
std::vector< Double_t > m_lowerLimit
Vector of cached lower limits in each variable.
UInt_t dimensionality()
Get dimensionality of phase space.
Bool_t withinLimits(std::vector< Double_t > &x)
Check if the point is within phase space limits.
Double_t lowerLimit(UInt_t var)
Return lower allowed limit of the variable.