meerkat is hosted by Hepforge, IPPP Durham
Meerkat  v1r3
Multidimensional kernel density estimation package
ParametricPhaseSpace.cpp
Go to the documentation of this file.
2 #include <stdio.h>
3 #include <stdlib.h>
4 
5 #include <vector>
6 
7 #include "TMath.h"
8 #include "TFormula.h"
9 
10 #include "Logger.hh"
11 
13  AbsPhaseSpace* phsp,
14  const char* lowerFormula,
15  const char* upperFormula,
16  Double_t lower,
17  Double_t upper) : AbsPhaseSpace (phspName) {
18 
19  char upperName[32];
20  char lowerName[32];
21 
22  Logger::print(0,"%20.20s INFO: Creating parametric phase space on top of base phase space \"%s\"\n", m_name, phsp->name());
23 
24  sprintf(upperName, "%20.20s_Upper", phspName);
25  sprintf(lowerName, "%20.20s_Lower", phspName);
26 
27  m_lowerFormula = new TFormula(lowerName, lowerFormula);
28  m_upperFormula = new TFormula(upperName, upperFormula);
29 
30  m_lowerLimit = lower;
31  m_upperLimit = upper;
32 
33  m_phaseSpace = phsp;
34 
35  if (m_phaseSpace->dimensionality() > 4) {
36  Logger::print(2,"%20.20s ERROR: Dimensionality of the base phase space \"%s\" for parametric phase space exceeds 4\n",
37  m_name, m_phaseSpace->name() );
38  abort();
39  }
41 
42  if (m_upperLimit <= m_lowerLimit) {
43  Logger::print(2,"%20.20s ERROR: Upper limit (%f) <= lowerLimit (%f) for parametric phase space\n",
45  abort();
46  }
47 
48 }
49 
51 
52 }
53 
54 Bool_t ParametricPhaseSpace::withinLimits(std::vector<Double_t> &x) {
55  Double_t x1 = x[m_dim-1];
56  if (x1 > m_upperLimit || x1 < m_lowerLimit) return 0;
57  if (m_phaseSpace->withinLimits(x) == 0) return 0;
58 
59  Double_t arg[4];
60  UInt_t i;
61  for (i=0; i<4; i++) arg[i] = 0;
62  for (i=0; i<m_dim-1; i++) {
63  arg[i] = x[i];
64  }
65 
66  Double_t upper = m_upperFormula->Eval(arg[0], arg[1], arg[2], arg[3]);
67  Double_t lower = m_lowerFormula->Eval(arg[0], arg[1], arg[2], arg[3]);
68  if (upper < lower) {
69  Logger::print(1,"%20.20s WARNING: Upper limit (%f) < lower limit (%f)\n for parametric phase space\n", m_name, upper, lower);
70  }
71 
72  if (x1 > upper || x1 < lower) return 0;
73  return 1;
74 }
75 
76 Double_t ParametricPhaseSpace::lowerLimit(UInt_t var) {
77  if (var == m_dim-1) return m_lowerLimit;
78  else if (var < m_dim-1) return m_phaseSpace->lowerLimit(var);
79  Logger::print(2,"%20.20s ERROR: var=%d for lower limit of parametric phase space\n", m_name, var);
80  abort();
81  return 0;
82 }
83 
84 Double_t ParametricPhaseSpace::upperLimit(UInt_t var) {
85  if (var == m_dim-1) return m_upperLimit;
86  else if (var < m_dim-1) return m_phaseSpace->upperLimit(var);
87  Logger::print(2,"%20.20s ERROR: var=%d for upper limit of parametric phase space\n", m_name, var);
88  abort();
89  return 0;
90 
91 }
92 
93 Bool_t ParametricPhaseSpace::limits(UInt_t var, std::vector<Double_t> &x,
94  Double_t* lower, Double_t* upper) {
95  if (var == m_dim-1) {
96  if (m_phaseSpace->withinLimits(x)) {
97  Double_t arg[4];
98  UInt_t i;
99  for (i=0; i<4; i++) arg[i] = 0;
100  for (i=0; i<m_dim-1; i++) {
101  arg[i] = x[i];
102  }
103  *upper = m_upperFormula->Eval(arg[0], arg[1], arg[2], arg[3]);
104  *lower = m_lowerFormula->Eval(arg[0], arg[1], arg[2], arg[3]);
105  return 1;
106  }
107  return 0;
108  }
109  else if (var < m_dim-1) {
110  return limits(var, x, lower, upper);
111  }
112  Logger::print(2,"%20.20s ERROR: var=%d for limits of parametric phase space\n", m_name, var);
113  abort();
114  return 0;
115 }
116 
Double_t m_lowerLimit
Lower limit in additional variable.
Double_t upperLimit(UInt_t var)
Get upper limit.
TFormula * m_lowerFormula
Lower limit formula.
UInt_t m_dim
Cached dimensionality.
virtual Double_t upperLimit(UInt_t var)=0
Return upper allowed limit of the variable.
char m_name[256]
Phase space name.
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...
void print(int level, const char *format,...)
Definition: Logger.cpp:27
Bool_t withinLimits(std::vector< Double_t > &x)
Check if the point is within the phase space limits.
virtual ~ParametricPhaseSpace()
Destructor.
Abstract class which defines phase space interface.
virtual UInt_t dimensionality()=0
Get dimensionality of phase space.
Double_t lowerLimit(UInt_t var)
Get lower limit.
virtual Double_t lowerLimit(UInt_t var)=0
Return lower allowed limit of the variable.
AbsPhaseSpace * m_phaseSpace
Base phase space.
const char * name(void)
Return the name of the phase space.
TFormula * m_upperFormula
Upper limit formula.
ParametricPhaseSpace(const char *phspName, AbsPhaseSpace *basePhaseSpace, const char *lowerFormula, const char *upperFormula, Double_t lowerLimit, Double_t upperLimit)
Constructor.
Double_t m_upperLimit
Upper limit in additional variable.
virtual Bool_t withinLimits(std::vector< Double_t > &x)=0
Check if the point is within phase space limits.