ROOT  6.06/09
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 
46 namespace ROOT {
47 namespace Math {
48 
49 
50  /**
51  Interpolation class based on GSL interpolation functions
52  @ingroup Interpolation
53  */
54 
56 
57  public:
58 
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  if (fResetNErrors) { nErrors = 0; fResetNErrors = false;}
79  int ierr = gsl_spline_eval_e(fSpline, x, fAccel, &y );
80  if (ierr){
81  ++nErrors;
82  if(nErrors < 5)
83  MATH_WARN_MSG("GSLInterpolator::Eval",gsl_strerror(ierr) ) //Trying to suppress errors B Zimmerman 11-11-11
84  else if(nErrors == 4)
85  MATH_WARN_MSG("GSLInterpolator::Eval","Suppressing additional warnings");
86  }
87  return y;
88  }
89 
90  double Deriv( double x ) const
91  {
92  assert(fAccel);
93  double deriv = 0;
94  static unsigned int nErrors = 0;
95  if (fResetNErrors) { nErrors = 0; fResetNErrors = false;}
96  int ierr = gsl_spline_eval_deriv_e(fSpline, x, fAccel, &deriv );
97  if (ierr){
98  ++nErrors;
99  if(nErrors < 5)
100  MATH_WARN_MSG("GSLInterpolator::Deriv",gsl_strerror(ierr) )
101  else if(nErrors == 4)
102  MATH_WARN_MSG("GSLInterpolator::Deriv","Suppressing additional warnings");
103  }
104  return deriv;
105  }
106 
107  double Deriv2( double x ) const {
108  assert(fAccel);
109  double deriv2 = 0;
110  static unsigned int nErrors = 0;
111  if (fResetNErrors) { nErrors = 0; fResetNErrors = false;}
112  int ierr = gsl_spline_eval_deriv2_e(fSpline, x, fAccel, &deriv2 );
113  if (ierr){
114  ++nErrors;
115  if(nErrors < 5)
116  MATH_WARN_MSG("GSLInterpolator::Deriv2",gsl_strerror(ierr) )
117  else if(nErrors == 4)
118  MATH_WARN_MSG("GSLInterpolator::Deriv2","Suppressing additional warnings");
119  }
120  return deriv2;
121  }
122 
123  double Integ( double a, double b) const {
124  if ( a > b) return -Integ(b,a); // gsl will report an error in this case
125  assert(fAccel);
126  double result = 0;
127  static unsigned int nErrors = 0;
128  if (fResetNErrors) { nErrors = 0; fResetNErrors = false;}
129  int ierr = gsl_spline_eval_integ_e(fSpline, a, b, fAccel, &result );
130  if (ierr){
131  ++nErrors;
132  if(nErrors < 5)
133  MATH_WARN_MSG("GSLInterpolator::Integ",gsl_strerror(ierr) )
134  else if(nErrors == 4)
135  MATH_WARN_MSG("GSLInterpolator::Integ","Suppress additional warnings" )
136  }
137  return result;
138  }
139 
140  std::string Name() {
141  return fInterpType->name;
142  }
143 
144 
145  protected:
146 
147 
148  private:
149 
150  mutable bool fResetNErrors; // flag to reset counter for error messages
151  gsl_interp_accel * fAccel;
152  gsl_spline * fSpline;
153  const gsl_interp_type * fInterpType;
154 
155  };
156 
157 } // namespace Math
158 } // namespace ROOT
159 
160 
161 #endif /* ROOT_Math_GSLInterpolator */
const int ndata
Namespace for new ROOT classes and functions.
Definition: ROOT.py:1
double Deriv2(double x) const
double Eval(double x) const
#define assert(cond)
Definition: unittest.h:542
double Deriv(double x) const
TArc * a
Definition: textangle.C:12
#define MATH_WARN_MSG(loc, str)
Definition: Error.h:47
Double_t x[n]
Definition: legend1.C:17
GSLInterpolator & operator=(const GSLInterpolator &)
bool Init(unsigned int ndata, const double *x, const double *y)
Interpolation class based on GSL interpolation functions.
int type
Definition: TGX11.cxx:120
Type
Enumeration defining the types of interpolation methods availables.
Double_t y[n]
Definition: legend1.C:17
Namespace for new Math classes and functions.
const gsl_interp_type * fInterpType
double result[121]
double Integ(double a, double b) const
GSLInterpolator(unsigned int ndata, Interpolation::Type type)