Logo ROOT   6.14/05
Reference Guide
Interpolator.cxx
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 // Implementation file for class Interpolator using GSL
26 //
27 // Created by: moneta at Fri Nov 26 15:00:25 2004
28 //
29 // Last update: Fri Nov 26 15:00:25 2004
30 //
31 
32 #include "Math/Interpolator.h"
33 #include "GSLInterpolator.h"
34 #include <algorithm>
35 
36 
37 namespace ROOT {
38 namespace Math {
39 
41  // allocate GSL interpolaiton object
42  fInterp = new GSLInterpolator(ndata, type);
43 }
44 
45 Interpolator::Interpolator(const std::vector<double> & x, const std::vector<double> & y, Interpolation::Type type)
46 {
47  // allocate and initialize GSL interpolation object with data
48 
49  size_t size = std::min( x.size(), y.size() );
50 
51  fInterp = new GSLInterpolator(size, type);
52 
53  fInterp->Init(size, &x.front(), &y.front() );
54 
55 }
56 
57 
59 {
60  // destructor (delete underlined obj)
61  if (fInterp) delete fInterp;
62 }
63 
65 {
66 }
67 
69 {
70  // dummy (private) assignment
71  if (this == &rhs) return *this; // time saving self-test
72 
73  return *this;
74 }
75 
76 bool Interpolator::SetData(unsigned int ndata, const double * x, const double *y) {
77  // set the interpolation data
78  return fInterp->Init(ndata, x, y);
79 }
80 bool Interpolator::SetData(const std::vector<double> & x, const std::vector<double> &y) {
81  // set the interpolation data
82  size_t size = std::min( x.size(), y.size() );
83  return fInterp->Init(size, &x.front(), &y.front());
84 }
85 
86 
87 double Interpolator::Eval( double x ) const
88 {
89  // forward evaluation
90  return fInterp->Eval(x);
91 }
92 
93 double Interpolator::Deriv( double x ) const
94 {
95  // forward deriv evaluation
96  return fInterp->Deriv(x);
97 }
98 
99 double Interpolator::Deriv2( double x ) const {
100  // forward deriv evaluation
101  return fInterp->Deriv2(x);
102 }
103 
104 double Interpolator::Integ( double a, double b) const {
105  // forward integ evaluation
106  return fInterp->Integ(a,b);
107 }
108 
109 std::string Interpolator::TypeGet() const {
110  // forward name request
111  return fInterp->Name();
112 }
113 std::string Interpolator::Type() const {
114  // forward name request
115  return fInterp->Name();
116 }
117 
118 
119 
120 } // namespace Math
121 } // namespace ROOT
double Integ(double a, double b) const
Return the Integral of the interpolated function over the range [a,b].
bool SetData(const std::vector< double > &x, const std::vector< double > &y)
Set the data vector ( x[] and y[] ) To be efficient, the size of the data must be the same of the val...
GSLInterpolator * fInterp
Definition: Interpolator.h:139
Namespace for new ROOT classes and functions.
Definition: StringConv.hxx:21
double Deriv(double x) const
Return the derivative of the interpolated function at point x.
Interpolator & operator=(const Interpolator &)
Class for performing function interpolation of points.
Definition: Interpolator.h:66
Double_t x[n]
Definition: legend1.C:17
double Deriv(double x) const
double Integ(double a, double b) const
auto * a
Definition: textangle.C:12
std::string Type() const
Return the type of interpolation method.
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.
double Deriv2(double x) const
Return the second derivative of the interpolated function at point x.
double Eval(double x) const
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Definition: TRolke.cxx:630
double Eval(double x) const
Return the interpolated value at point x.
Interpolator(unsigned int ndata=0, Interpolation::Type type=Interpolation::kCSPLINE)
Constructs an interpolator class from number of data points and with Interpolation::Type type...
double Deriv2(double x) const
std::string TypeGet() const