laura is hosted by Hepforge, IPPP Durham
Laura++  3.6.0
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.
 
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.
 
Lau1DCubicSplineoperator= (const Lau1DCubicSpline &rhs)
 Copy assignment operator - not implemented.
 
void init ()
 Initialise the class.
 
void calcDerivatives ()
 Calculate the first derivative at each knot.
 
void calcDerivativesStandard ()
 Calculate the first derivatives according to the standard method.
 
void calcDerivativesAkima ()
 Calculate the first derivatives according to the Akima method.
 

Private Attributes

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

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 84 of file Lau1DCubicSpline.hh.

Member Enumeration Documentation

◆ LauSplineBoundaryType

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 98 of file Lau1DCubicSpline.hh.

◆ LauSplineType

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 88 of file Lau1DCubicSpline.hh.

Constructor & Destructor Documentation

◆ Lau1DCubicSpline()

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.

Parameters
[in]xsthe x-values of the knots
[in]ysthe y-values of the knots
[in]typethe type of the spline (e.g. StandardSpline, AkimaSpline, LinearInterpolation)
[in]leftBoundthe left-hand boundary condition
[in]rightBoundthe right-hand boundary condition
[in]dydx0the gradient at the left-hand boundary of a clamped spline
[in]dydxnthe gradient at the right-hand boundary of a clamped spline

Definition at line 38 of file Lau1DCubicSpline.cc.

Member Function Documentation

◆ evaluate()

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 61 of file Lau1DCubicSpline.cc.

◆ updateBoundaryConditions()

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

Update the boundary conditions for the spline.

Parameters
[in]leftBoundthe left-hand boundary condition
[in]rightBoundthe right-hand boundary condition
[in]dydx0the gradient at the left-hand boundary of a clamped spline
[in]dydxnthe gradient at the right-hand boundary of a clamped spline

Definition at line 120 of file Lau1DCubicSpline.cc.

◆ updateType()

void Lau1DCubicSpline::updateType ( LauSplineType  type)

Update the type of interpolation to perform.

Parameters
[in]typethe type of interpolation

Definition at line 112 of file Lau1DCubicSpline.cc.

◆ updateYValues()

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 106 of file Lau1DCubicSpline.cc.


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