CbmRoot
CbmBilinearSplineFunction.h
Go to the documentation of this file.
1 /*
2  *====================================================================
3  *
4  * Class for 2D spline function used by CbmModels package
5  *
6  * Authors: V.Vovchenko
7  *
8  * e-mail :
9  *
10  *====================================================================
11  *
12  * 2D spline class
13  *
14  *====================================================================
15  */
16 
17 #ifndef BILINEARSPLINEFUNCTION_H
18 #define BILINEARSPLINEFUNCTION_H
19 #include "CbmSplineFunction.h"
20 
22  std::vector<double> xs;
23  std::vector<SplineFunction> xspls;
24 
25 public:
27  xs.resize(0);
28  xspls.resize(0);
29  }
30  BilinearSplineFunction(const std::vector<double>& x,
31  const std::vector<double>& y,
32  const std::vector<double>& vals)
33  : xs(), xspls() {
34  setData(x, y, vals);
35  }
36  void setData(const std::vector<double>& x,
37  const std::vector<double>& y,
38  const std::vector<double>& vals) {
39  if (x.size() > 0) {
40  xs.resize(0);
41  xspls.resize(0);
42  double cx = -1e50;
43  for (unsigned int i = 0; i < x.size(); ++i) {
44  if (fabs(x[i] - cx) > 1e-6) {
45  xspls.push_back(SplineFunction());
46  xs.push_back(x[i]);
47  xspls[xspls.size() - 1].add_val(y[i], vals[i]);
48  cx = x[i];
49  } else {
50  xspls[xspls.size() - 1].add_val(y[i], vals[i]);
51  }
52  }
53  }
54  }
55  double Eval(double x, double y) const {
56  if (xs.size() < 2) return -1.;
57  unsigned int indx = 0;
58  std::vector<double>::const_iterator it =
59  lower_bound(xs.begin(), xs.end(), x);
60  indx = distance(xs.begin(), it);
61  int ind1 = 0, ind2 = 0;
62  if (indx == 0) {
63  ind1 = 0;
64  ind2 = 1;
65  } else if (indx == xs.size()) {
66  ind1 = indx - 2;
67  ind2 = indx - 1;
68  } else {
69  ind1 = indx - 1;
70  ind2 = indx;
71  }
72  double f1v = xspls[ind1].f(y);
73  double f2v = xspls[ind2].f(y);
74  return f1v + (x - xs[ind1]) * (f2v - f1v) / (xs[ind2] - xs[ind1]);
75  }
77 };
78 
79 #endif
BilinearSplineFunction::xs
std::vector< double > xs
Definition: CbmBilinearSplineFunction.h:22
BilinearSplineFunction::BilinearSplineFunction
BilinearSplineFunction(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &vals)
Definition: CbmBilinearSplineFunction.h:30
BilinearSplineFunction::~BilinearSplineFunction
~BilinearSplineFunction(void)
Definition: CbmBilinearSplineFunction.h:76
i
int i
Definition: L1/vectors/P4_F32vec4.h:25
CbmSplineFunction.h
BilinearSplineFunction::setData
void setData(const std::vector< double > &x, const std::vector< double > &y, const std::vector< double > &vals)
Definition: CbmBilinearSplineFunction.h:36
SplineFunction
Definition: CbmSplineFunction.h:23
BilinearSplineFunction::Eval
double Eval(double x, double y) const
Definition: CbmBilinearSplineFunction.h:55
BilinearSplineFunction::BilinearSplineFunction
BilinearSplineFunction(void)
Definition: CbmBilinearSplineFunction.h:26
BilinearSplineFunction
Definition: CbmBilinearSplineFunction.h:21
BilinearSplineFunction::xspls
std::vector< SplineFunction > xspls
Definition: CbmBilinearSplineFunction.h:23
x
Double_t x
Definition: CbmMvdSensorDigiToHitTask.cxx:68
fabs
friend F32vec4 fabs(const F32vec4 &a)
Definition: L1/vectors/P4_F32vec4.h:60
y
Double_t y
Definition: CbmMvdSensorDigiToHitTask.cxx:68