laura is hosted by Hepforge, IPPP Durham
Laura++  v3r3
A maximum likelihood fitting package for performing Dalitz-plot analysis.

Class for defining a 1D cubic spline based on a set of knots. More...

#include <Lau1DCubicSpline.hh>

Public Types

enum  LauSplineType { StandardSpline, AkimaSpline, LinearInterpolation }
 Define the allowed interpolation types. More...
 
enum  LauSplineBoundaryType { Clamped, Natural, NotAKnot }
 Define the allowed boundary condition types. More...
 

Public Member Functions

 Lau1DCubicSpline (const std::vector< Double_t > &xs, const std::vector< Double_t > &ys, LauSplineType type=Lau1DCubicSpline::StandardSpline, LauSplineBoundaryType leftBound=Lau1DCubicSpline::NotAKnot, LauSplineBoundaryType rightBound=Lau1DCubicSpline::NotAKnot, Double_t dydx0=0.0, Double_t dydxn=0.0)
 Constructor. More...
 
virtual ~Lau1DCubicSpline ()
 Destructor. More...
 
Double_t evaluate (Double_t x) const
 Evaluate the function at given point. More...
 
void updateYValues (const std::vector< Double_t > &ys)
 Update the y-values of the knots. More...
 
void updateType (LauSplineType type)
 Update the type of interpolation to perform. More...
 
void updateBoundaryConditions (LauSplineBoundaryType leftBound, LauSplineBoundaryType rightBound, Double_t dydx0=0.0, Double_t dydxn=0.0)
 Update the boundary conditions for the spline. More...
 

Private Member Functions

 Lau1DCubicSpline (const Lau1DCubicSpline &rhs)
 Copy constructor - not implemented. More...
 
Lau1DCubicSplineoperator= (const Lau1DCubicSpline &rhs)
 Copy assignment operator - not implemented. More...
 
void init ()
 Initialise the class. More...
 
void calcDerivatives ()
 Calculate the first derivative at each knot. More...
 
void calcDerivativesStandard ()
 Calculate the first derivatives according to the standard method. More...
 
void calcDerivativesAkima ()
 Calculate the first derivatives according to the Akima method. More...
 
 ClassDef (Lau1DCubicSpline, 0)
 

Private Attributes

const UInt_t nKnots_
 The number of knots in the spline. More...
 
std::vector< Double_t > x_
 The x-value at each knot. More...
 
std::vector< Double_t > y_
 The y-value at each knot. More...
 
std::vector< Double_t > dydx_
 The first derivative at each knot. More...
 
std::vector< Double_t > a_
 The 'a' coefficients used to determine the derivatives. More...
 
std::vector< Double_t > b_
 The 'b' coefficients used to determine the derivatives. More...
 
std::vector< Double_t > c_
 The 'c' coefficients used to determine the derivatives. More...
 
std::vector< Double_t > d_
 The 'd' coefficients used to determine the derivatives. More...
 
LauSplineType type_
 The type of interpolation to be performed. More...
 
LauSplineBoundaryType leftBound_
 The left-hand boundary condition on the spline. More...
 
LauSplineBoundaryType rightBound_
 The right-hand boundary condition on the spline. More...
 
Double_t dydx0_
 The gradient at the left boundary for a clamped spline. More...
 
Double_t dydxn_
 The gradient at the right boundary for a clamped spline. More...
 

Detailed Description

Class for defining a 1D cubic spline based on a set of knots.

Class for defining a 1D cubic spline based on a set of knots. Interpolation between the knots is performed either by one of two types of cubic spline (standard or Akima) or by linear interpolation. The splines are defined by a piecewise cubic function which, between knots i and i+1, has the form

f_i(x) = (1 - t)*y_i + t*y_i+1 + t*(1 - t)(a*(1 - t) + b*t)

where t = (x - x_i)/(x_i+1 - x_i), a = k_i *(x_i+1 - x_i) - (y_i+1 - y_i), b = -k_i+1*(x_i+1 - x_i) + (y_i+1 - y_i)

and k_i is (by construction) the first derivative at knot i. f(x) and f'(x) are continuous at the internal knots by construction.

For the standard splines, f''(x) is required to be continuous at all internal knots placing n-2 constraints on the n parameters, k_i. The final two constraints are set by the boundary conditions. At each boundary, the function may be:

(i) Clamped : f'(x) = C at the last knot (ii) Natural : f''(x) = 0 at the last knot (iii) Not a knot : f'''(x) continuous at the second last knot

The algorithms used in these splines can be found on: http://en.wikipedia.org/wiki/Spline_interpolation#Algorithm_to_find_the_interpolating_cubic_spline http://en.wikipedia.org/wiki/Tridiagonal_matrix_algorithm

For the Akima splines, the values of k_i are determined from the slopes of the four nearest segments (a_i-1, a_i, a_i+1 and a_i+2) as

k_i = ( | a_i+2 - a_i+1 | a_i + | a_i - a_i-1 | a_i+1 ) / ( | a_i+2 - a_i+1 | + | a_i - a_i-1 | )

and as

k_i = ( a_i + a_i+1 ) / 2

in the special case a_i-1 == a_i != a_i+1 == a_i+2.

Boundary conditions are specified by the relations a_2 - a_1 = a_1 - a_0 = a_0 - a_-1 and a_n-1 - a_n-2 = a_n - a_n-1 = a_n+1 - a_n

The algorithms used in these splines can be found in: J.ACM vol. 17 no. 4 pp 589-602

Definition at line 70 of file Lau1DCubicSpline.hh.

Member Enumeration Documentation

Define the allowed boundary condition types.

These are only supported by standard splines

Enumerator
Clamped 

clamped boundary - f'(x) = C

Natural 

natural boundary - f''(x) = 0

NotAKnot 

'not a knot' boundary - f'''(x) continuous at second last knot

Definition at line 84 of file Lau1DCubicSpline.hh.

Define the allowed interpolation types.

Enumerator
StandardSpline 

standard cubic splines with f''(x) continuous at all internal knots

AkimaSpline 

Akima cubic splines with f'(x) at each knot defined locally by the positions of only five knots

LinearInterpolation 

Linear interpolation between each pair of knots

Definition at line 74 of file Lau1DCubicSpline.hh.

Constructor & Destructor Documentation

Lau1DCubicSpline::Lau1DCubicSpline ( const std::vector< Double_t > &  xs,
const std::vector< Double_t > &  ys,
LauSplineType  type = Lau1DCubicSpline::StandardSpline,
LauSplineBoundaryType  leftBound = Lau1DCubicSpline::NotAKnot,
LauSplineBoundaryType  rightBound = Lau1DCubicSpline::NotAKnot,
Double_t  dydx0 = 0.0,
Double_t  dydxn = 0.0 
)

Constructor.

/param [in] xs the x-values of the knots /param [in] ys the y-values of the knots /param [in] leftBound the left-hand boundary condition /param [in] rightBound the right-hand boundary condition /param [in] dydx0 the gradient at the left-hand boundary of a clamped spline /param [in] dydxn the gradient at the right-hand boundary of a clamped spline

Definition at line 24 of file Lau1DCubicSpline.cc.

Lau1DCubicSpline::~Lau1DCubicSpline ( )
virtual

Destructor.

Definition at line 41 of file Lau1DCubicSpline.cc.

Lau1DCubicSpline::Lau1DCubicSpline ( const Lau1DCubicSpline rhs)
private

Copy constructor - not implemented.

Member Function Documentation

void Lau1DCubicSpline::calcDerivatives ( )
private

Calculate the first derivative at each knot.

Definition at line 147 of file Lau1DCubicSpline.cc.

void Lau1DCubicSpline::calcDerivativesAkima ( )
private

Calculate the first derivatives according to the Akima method.

Definition at line 267 of file Lau1DCubicSpline.cc.

void Lau1DCubicSpline::calcDerivativesStandard ( )
private

Calculate the first derivatives according to the standard method.

Definition at line 162 of file Lau1DCubicSpline.cc.

Lau1DCubicSpline::ClassDef ( Lau1DCubicSpline  ,
 
)
private
Double_t Lau1DCubicSpline::evaluate ( Double_t  x) const

Evaluate the function at given point.

Parameters
[in]xthe x-coordinate
Returns
the value of the spline at x

Definition at line 45 of file Lau1DCubicSpline.cc.

void Lau1DCubicSpline::init ( )
private

Initialise the class.

Definition at line 129 of file Lau1DCubicSpline.cc.

Lau1DCubicSpline& Lau1DCubicSpline::operator= ( const Lau1DCubicSpline rhs)
private

Copy assignment operator - not implemented.

void Lau1DCubicSpline::updateBoundaryConditions ( LauSplineBoundaryType  leftBound,
LauSplineBoundaryType  rightBound,
Double_t  dydx0 = 0.0,
Double_t  dydxn = 0.0 
)

Update the boundary conditions for the spline.

/param [in] leftBound the left-hand boundary condition /param [in] rightBound the right-hand boundary condition /param [in] dydx0 the gradient at the left-hand boundary of a clamped spline /param [in] dydxn the gradient at the right-hand boundary of a clamped spline

Definition at line 102 of file Lau1DCubicSpline.cc.

void Lau1DCubicSpline::updateType ( LauSplineType  type)

Update the type of interpolation to perform.

Parameters
[in]typethe type of interpolation

Definition at line 94 of file Lau1DCubicSpline.cc.

void Lau1DCubicSpline::updateYValues ( const std::vector< Double_t > &  ys)

Update the y-values of the knots.

Parameters
[in]ysthe y-values of the knots

Definition at line 88 of file Lau1DCubicSpline.cc.

Member Data Documentation

std::vector<Double_t> Lau1DCubicSpline::a_
private

The 'a' coefficients used to determine the derivatives.

Definition at line 168 of file Lau1DCubicSpline.hh.

std::vector<Double_t> Lau1DCubicSpline::b_
private

The 'b' coefficients used to determine the derivatives.

Definition at line 170 of file Lau1DCubicSpline.hh.

std::vector<Double_t> Lau1DCubicSpline::c_
private

The 'c' coefficients used to determine the derivatives.

Definition at line 172 of file Lau1DCubicSpline.hh.

std::vector<Double_t> Lau1DCubicSpline::d_
private

The 'd' coefficients used to determine the derivatives.

Definition at line 174 of file Lau1DCubicSpline.hh.

Double_t Lau1DCubicSpline::dydx0_
private

The gradient at the left boundary for a clamped spline.

Definition at line 185 of file Lau1DCubicSpline.hh.

std::vector<Double_t> Lau1DCubicSpline::dydx_
private

The first derivative at each knot.

Definition at line 165 of file Lau1DCubicSpline.hh.

Double_t Lau1DCubicSpline::dydxn_
private

The gradient at the right boundary for a clamped spline.

Definition at line 187 of file Lau1DCubicSpline.hh.

LauSplineBoundaryType Lau1DCubicSpline::leftBound_
private

The left-hand boundary condition on the spline.

Definition at line 180 of file Lau1DCubicSpline.hh.

const UInt_t Lau1DCubicSpline::nKnots_
private

The number of knots in the spline.

Definition at line 158 of file Lau1DCubicSpline.hh.

LauSplineBoundaryType Lau1DCubicSpline::rightBound_
private

The right-hand boundary condition on the spline.

Definition at line 182 of file Lau1DCubicSpline.hh.

LauSplineType Lau1DCubicSpline::type_
private

The type of interpolation to be performed.

Definition at line 177 of file Lau1DCubicSpline.hh.

std::vector<Double_t> Lau1DCubicSpline::x_
private

The x-value at each knot.

Definition at line 161 of file Lau1DCubicSpline.hh.

std::vector<Double_t> Lau1DCubicSpline::y_
private

The y-value at each knot.

Definition at line 163 of file Lau1DCubicSpline.hh.


The documentation for this class was generated from the following files: