// @(#)root/mathmore:$Id$
// Authors: L. Moneta, A. Zsenei   08/2005

 /**********************************************************************
  *                                                                    *
  * Copyright (c) 2004 ROOT Foundation,  CERN/PH-SFT                   *
  *                                                                    *
  * This library is free software; you can redistribute it and/or      *
  * modify it under the terms of the GNU General Public License        *
  * as published by the Free Software Foundation; either version 2     *
  * of the License, or (at your option) any later version.             *
  *                                                                    *
  * This library is distributed in the hope that it will be useful,    *
  * but WITHOUT ANY WARRANTY; without even the implied warranty of     *
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU   *
  * General Public License for more details.                           *
  *                                                                    *
  * You should have received a copy of the GNU General Public License  *
  * along with this library (see file COPYING); if not, write          *
  * to the Free Software Foundation, Inc., 59 Temple Place, Suite      *
  * 330, Boston, MA 02111-1307 USA, or contact the author.             *
  *                                                                    *
  **********************************************************************/

// Header file for class Interpolator
//
// Created by: moneta  at Fri Nov 26 15:00:25 2004
//
// Last update: Fri Nov 26 15:00:25 2004
//
#ifndef ROOT_Math_Interpolator
#define ROOT_Math_Interpolator

#include "Math/InterpolationTypes.h"

#include <vector>
#include <string>

/**
@defgroup Interpolation Interpolation
@ingroup NumAlgo
*/


namespace ROOT {
namespace Math {


   class GSLInterpolator;

//_____________________________________________________________________________________
   /**
      Class for performing function interpolation of points.
      The class is instantiated with an interpolation methods, passed as an enumeration in the constructor.
      See Interpolation::Type for the available interpolation algorithms, which are implemented using GSL.
      See also the <A HREF=http://www.gnu.org/software/gsl/manual/html_node/Interpolation.html">GSL manual</A> for more information.
      The class provides additional methods for computing derivatives and integrals of interpolating functions.

      This class does not support copying.
      @ingroup Interpolation
   */

class Interpolator {

public:

   /**
      Constructs an interpolator class from  number of data points and with Interpolation::Type type.
      The data can be set later on with the SetData method.
      In case the data size is not known, better using the default of zero or the next constructor later on.
      The default interpolation type is Cubic spline
   */
   Interpolator(unsigned int ndata = 0, Interpolation::Type type = Interpolation::kCSPLINE);

   /**
      Constructs an interpolator class from vector of data points \f$ (x_i, y_i )\f$ and with Interpolation::Type type.
      The method will compute a continuous interpolating function \f$ y(x) \f$ such that \f$ y_i = y ( x_i )\f$.
      The default interpolation type is Cubic spline
   */
   Interpolator(const std::vector<double> & x, const std::vector<double> & y, Interpolation::Type type = Interpolation::kCSPLINE);

   virtual ~Interpolator();

private:
   // usually copying is non trivial, so we make this unaccessible
   Interpolator(const Interpolator &);
   Interpolator & operator = (const Interpolator &);

public:

   /**
      Set the data vector ( x[] and y[] )
      To be efficient, the size of the data must be the same of the value used in the constructor (ndata)
      If this is not  the case a new re-initialization is performed with the new data size
    */
   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 value used when  constructing the class (ndata)
      If this is not  the case a new re-initialization is performed with the new data size.
    */
   bool SetData(unsigned int ndata, const double * x, const double *  y);

   /**
      Return the interpolated value at point x
   */
   double Eval( double x ) const;

   /**
      Return the derivative of the interpolated function at point x
   */
   double Deriv( double x ) const;

   /**
      Return the second derivative of the interpolated function at point x
   */
   double Deriv2( double x ) const;

   /**
      Return the Integral of the interpolated function over the range [a,b]
   */
   double Integ( double a, double b) const;

   /**
      Return the type of interpolation method
   */
   std::string Type() const;
   std::string TypeGet() const;

protected:


private:

   GSLInterpolator * fInterp;   // pointer to GSL interpolator class

};

} // namespace Math
} // namespace ROOT


#endif /* ROOT_Math_Interpolator */
 Interpolator.h:1
 Interpolator.h:2
 Interpolator.h:3
 Interpolator.h:4
 Interpolator.h:5
 Interpolator.h:6
 Interpolator.h:7
 Interpolator.h:8
 Interpolator.h:9
 Interpolator.h:10
 Interpolator.h:11
 Interpolator.h:12
 Interpolator.h:13
 Interpolator.h:14
 Interpolator.h:15
 Interpolator.h:16
 Interpolator.h:17
 Interpolator.h:18
 Interpolator.h:19
 Interpolator.h:20
 Interpolator.h:21
 Interpolator.h:22
 Interpolator.h:23
 Interpolator.h:24
 Interpolator.h:25
 Interpolator.h:26
 Interpolator.h:27
 Interpolator.h:28
 Interpolator.h:29
 Interpolator.h:30
 Interpolator.h:31
 Interpolator.h:32
 Interpolator.h:33
 Interpolator.h:34
 Interpolator.h:35
 Interpolator.h:36
 Interpolator.h:37
 Interpolator.h:38
 Interpolator.h:39
 Interpolator.h:40
 Interpolator.h:41
 Interpolator.h:42
 Interpolator.h:43
 Interpolator.h:44
 Interpolator.h:45
 Interpolator.h:46
 Interpolator.h:47
 Interpolator.h:48
 Interpolator.h:49
 Interpolator.h:50
 Interpolator.h:51
 Interpolator.h:52
 Interpolator.h:53
 Interpolator.h:54
 Interpolator.h:55
 Interpolator.h:56
 Interpolator.h:57
 Interpolator.h:58
 Interpolator.h:59
 Interpolator.h:60
 Interpolator.h:61
 Interpolator.h:62
 Interpolator.h:63
 Interpolator.h:64
 Interpolator.h:65
 Interpolator.h:66
 Interpolator.h:67
 Interpolator.h:68
 Interpolator.h:69
 Interpolator.h:70
 Interpolator.h:71
 Interpolator.h:72
 Interpolator.h:73
 Interpolator.h:74
 Interpolator.h:75
 Interpolator.h:76
 Interpolator.h:77
 Interpolator.h:78
 Interpolator.h:79
 Interpolator.h:80
 Interpolator.h:81
 Interpolator.h:82
 Interpolator.h:83
 Interpolator.h:84
 Interpolator.h:85
 Interpolator.h:86
 Interpolator.h:87
 Interpolator.h:88
 Interpolator.h:89
 Interpolator.h:90
 Interpolator.h:91
 Interpolator.h:92
 Interpolator.h:93
 Interpolator.h:94
 Interpolator.h:95
 Interpolator.h:96
 Interpolator.h:97
 Interpolator.h:98
 Interpolator.h:99
 Interpolator.h:100
 Interpolator.h:101
 Interpolator.h:102
 Interpolator.h:103
 Interpolator.h:104
 Interpolator.h:105
 Interpolator.h:106
 Interpolator.h:107
 Interpolator.h:108
 Interpolator.h:109
 Interpolator.h:110
 Interpolator.h:111
 Interpolator.h:112
 Interpolator.h:113
 Interpolator.h:114
 Interpolator.h:115
 Interpolator.h:116
 Interpolator.h:117
 Interpolator.h:118
 Interpolator.h:119
 Interpolator.h:120
 Interpolator.h:121
 Interpolator.h:122
 Interpolator.h:123
 Interpolator.h:124
 Interpolator.h:125
 Interpolator.h:126
 Interpolator.h:127
 Interpolator.h:128
 Interpolator.h:129
 Interpolator.h:130
 Interpolator.h:131
 Interpolator.h:132
 Interpolator.h:133
 Interpolator.h:134
 Interpolator.h:135
 Interpolator.h:136
 Interpolator.h:137
 Interpolator.h:138
 Interpolator.h:139
 Interpolator.h:140
 Interpolator.h:141
 Interpolator.h:142
 Interpolator.h:143
 Interpolator.h:144