Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
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 
40 Interpolator::Interpolator(unsigned int ndata, Interpolation::Type type ) {
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 
58 Interpolator::~Interpolator()
59 {
60  // destructor (delete underlined obj)
61  if (fInterp) delete fInterp;
62 }
63 
64 Interpolator::Interpolator(const Interpolator &)
65 {
66 }
67 
68 Interpolator & Interpolator::operator = (const Interpolator &rhs)
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