Thermal-FIST  1.3
Package for hadron resonance gas model applications
BilinearSplineFunction.h
Go to the documentation of this file.
1 /*
2  * Thermal-FIST package
3  *
4  * Copyright (c) 2014-2019 Volodymyr Vovchenko
5  *
6  * GNU General Public License (GPLv3 or later)
7  */
8 #ifndef BILINEARSPLINEFUNCTION_H
9 #define BILINEARSPLINEFUNCTION_H
10 
11 #include "HRGBase/SplineFunction.h"
12 
13 namespace thermalfist {
14 
16 
22  {
23  public:
27  BilinearSplineFunction(void) : m_xs(), m_xspls() {
28  m_xs.resize(0);
29  m_xspls.resize(0);
30  }
31 
41  BilinearSplineFunction(const std::vector<double> &x, const std::vector<double> &y, const std::vector<double> &vals)
42  : m_xs(), m_xspls() {
43  setData(x, y, vals);
44  }
45 
55  void setData(const std::vector<double> &x, const std::vector<double> &y, const std::vector<double> &vals) {
56  if (x.size() > 0) {
57  m_xs.resize(0);
58  m_xspls.resize(0);
59  double cx = -1e50;
60  for (unsigned int i = 0; i < x.size(); ++i) {
61  if (fabs(x[i] - cx) > 1e-6) {
62  m_xspls.push_back(SplineFunction());
63  m_xs.push_back(x[i]);
64  m_xspls[m_xspls.size() - 1].add_val(y[i], vals[i]);
65  cx = x[i];
66  }
67  else {
68  m_xspls[m_xspls.size() - 1].add_val(y[i], vals[i]);
69  }
70  }
71  }
72  }
73 
75  double Eval(double x, double y) const {
76  if (m_xs.size() < 2) return -1.;
77  unsigned int indx = 0;
78  std::vector< double >::const_iterator it = std::lower_bound(m_xs.begin(), m_xs.end(), x);
79  indx = std::distance(m_xs.begin(), it);
80  int ind1 = 0, ind2 = 0;
81  if (indx == 0) {
82  ind1 = 0;
83  ind2 = 1;
84  }
85  else if (indx == m_xs.size()) {
86  ind1 = indx - 2;
87  ind2 = indx - 1;
88  }
89  else {
90  ind1 = indx - 1;
91  ind2 = indx;
92  }
93  double f1v = m_xspls[ind1].f(y);
94  double f2v = m_xspls[ind2].f(y);
95  return f1v + (x - m_xs[ind1]) * (f2v - f1v) / (m_xs[ind2] - m_xs[ind1]);
96  }
97 
100 
101  private:
102  std::vector<double> m_xs;
103  std::vector<SplineFunction> m_xspls;
104  };
105 
106 } // namespace thermalfist
107 
108 #endif
void setData(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &vals)
Class implementing a simple linear spline.
BilinearSplineFunction(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &vals)
A class implementing a bilinear spline.
double Eval(double x, double y) const
Evaluates interpolated f(x,y)
The main namespace where all classes and functions of the Thermal-FIST library reside.