Logo ROOT   6.18/05
Reference Guide
GSLInterpolator.h
Go to the documentation of this file.
1// @(#)root/mathmore:$Id$
2// Authors: L. Moneta, A. Zsenei 08/2005
3
4 /**********************************************************************
5 * *
6 * Copyright (c) 2004 ROOT Foundation, CERN/PH-SFT *
7 * *
8 * This library is free software; you can redistribute it and/or *
9 * modify it under the terms of the GNU General Public License *
10 * as published by the Free Software Foundation; either version 2 *
11 * of the License, or (at your option) any later version. *
12 * *
13 * This library is distributed in the hope that it will be useful, *
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
16 * General Public License for more details. *
17 * *
18 * You should have received a copy of the GNU General Public License *
19 * along with this library (see file COPYING); if not, write *
20 * to the Free Software Foundation, Inc., 59 Temple Place, Suite *
21 * 330, Boston, MA 02111-1307 USA, or contact the author. *
22 * *
23 **********************************************************************/
24
25// Header file for class GSLInterpolator
26//
27// Created by: moneta at Fri Nov 26 15:31:41 2004
28//
29// Last update: Fri Nov 26 15:31:41 2004
30//
31#ifndef ROOT_Math_GSLInterpolator
32#define ROOT_Math_GSLInterpolator
33
34#include <vector>
35#include <string>
36#include <cassert>
37
39
40#include "gsl/gsl_interp.h"
41#include "gsl/gsl_spline.h"
42
43#include "gsl/gsl_errno.h"
44#include "Math/Error.h"
45
46namespace ROOT {
47namespace Math {
48
49
50 /**
51 Interpolation class based on GSL interpolation functions
52 @ingroup Interpolation
53 */
54
56
57 public:
58
59 GSLInterpolator(unsigned int ndata, Interpolation::Type type);
60
61 GSLInterpolator(const Interpolation::Type type, const std::vector<double> & x, const std::vector<double> & y );
62 virtual ~GSLInterpolator();
63
64 private:
65 // usually copying is non trivial, so we make this unaccessible
68
69 public:
70
71 bool Init(unsigned int ndata, const double *x, const double *y);
72
73 double Eval(double x) const
74 {
75 assert(fAccel);
76 double y = 0;
77 static unsigned int nErrors = 0;
78 int ierr = gsl_spline_eval_e(fSpline, x, fAccel, &y);
79
80 if (fResetNErrors)
81 nErrors = 0, fResetNErrors = false;
82
83 if (ierr) {
84 ++nErrors;
85 if(nErrors <= 4) {
86 MATH_WARN_MSG("GSLInterpolator::Eval", gsl_strerror(ierr));
87 if(nErrors == 4)
88 MATH_WARN_MSG("GSLInterpolator::Eval", "Suppressing additional warnings");
89 }
90 }
91
92 return y;
93 }
94
95 double Deriv(double x) const
96 {
97 assert(fAccel);
98 double deriv = 0;
99 static unsigned int nErrors = 0;
100 int ierr = gsl_spline_eval_deriv_e(fSpline, x, fAccel, &deriv);
101
102 if (fResetNErrors)
103 nErrors = 0, fResetNErrors = false;
104
105 if (ierr) {
106 ++nErrors;
107 if(nErrors <= 4) {
108 MATH_WARN_MSG("GSLInterpolator::Deriv", gsl_strerror(ierr));
109 if(nErrors == 4)
110 MATH_WARN_MSG("GSLInterpolator::Deriv", "Suppressing additional warnings");
111 }
112 }
113
114 return deriv;
115 }
116
117 double Deriv2(double x) const {
118 assert(fAccel);
119 double deriv2 = 0;
120 static unsigned int nErrors = 0;
121 int ierr = gsl_spline_eval_deriv2_e(fSpline, x, fAccel, &deriv2);
122
123 if (fResetNErrors)
124 nErrors = 0, fResetNErrors = false;
125
126 if (ierr) {
127 ++nErrors;
128 if(nErrors <= 4) {
129 MATH_WARN_MSG("GSLInterpolator::Deriv2", gsl_strerror(ierr));
130 if(nErrors == 4)
131 MATH_WARN_MSG("GSLInterpolator::Deriv2", "Suppressing additional warnings");
132 }
133 }
134
135 return deriv2;
136 }
137
138 double Integ(double a, double b) const {
139 if (a > b) // gsl will report an error in this case
140 return -Integ(b, a);
141
142 assert(fAccel);
143 double result = 0;
144 static unsigned int nErrors = 0;
145 int ierr = gsl_spline_eval_integ_e(fSpline, a, b, fAccel, &result);
146
147 if (fResetNErrors)
148 nErrors = 0, fResetNErrors = false;
149
150 if (ierr) {
151 ++nErrors;
152 if(nErrors <= 4) {
153 MATH_WARN_MSG("GSLInterpolator::Integ", gsl_strerror(ierr));
154 if(nErrors == 4)
155 MATH_WARN_MSG("GSLInterpolator::Integ", "Suppressing additional warnings");
156 }
157 }
158
159 return result;
160 }
161
162 std::string Name() {
163 return fInterpType->name;
164 }
165
166 private:
167
168 mutable bool fResetNErrors; // flag to reset counter for error messages
169 gsl_interp_accel * fAccel;
170 gsl_spline * fSpline;
171 const gsl_interp_type * fInterpType;
172
173 };
174
175} // namespace Math
176} // namespace ROOT
177
178#endif /* ROOT_Math_GSLInterpolator */
#define MATH_WARN_MSG(loc, str)
Definition: Error.h:79
#define b(i)
Definition: RSha256.hxx:100
int type
Definition: TGX11.cxx:120
Interpolation class based on GSL interpolation functions.
GSLInterpolator(unsigned int ndata, Interpolation::Type type)
double Deriv2(double x) const
double Eval(double x) const
GSLInterpolator & operator=(const GSLInterpolator &)
bool Init(unsigned int ndata, const double *x, const double *y)
const gsl_interp_type * fInterpType
double Integ(double a, double b) const
GSLInterpolator(const Interpolation::Type type, const std::vector< double > &x, const std::vector< double > &y)
double Deriv(double x) const
Type
Enumeration defining the types of interpolation methods availables.
Double_t y[n]
Definition: legend1.C:17
Double_t x[n]
Definition: legend1.C:17
Namespace for new Math classes and functions.
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
auto * a
Definition: textangle.C:12