Project
Loading...
Searching...
No Matches
o2::gpu::Spline1DBase< DataT, YdimT, FlatBase > Class Template Reference

#include <Spline1D.h>

Inherits o2::gpu::Spline1DSpec< DataT, YdimT, SplineUtil::getSpec(YdimT), FlatBase >.

Public Member Functions

 Spline1DBase ()=default
 
 Spline1DBase (const Spline1DBase &v)
 
Spline1DBaseoperator= (const Spline1DBase &v)
 

Static Public Member Functions

static Spline1DBasereadFromFile (TFile &inpf, const char *name)
 

Protected Types

using Container = Spline1DContainer< DataT, FlatBase >
 
using ParentSpec = Spline1DSpec< DataT, YdimT, SplineUtil::getSpec(YdimT), FlatBase >
 

Detailed Description

template<typename DataT, int32_t YdimT, class FlatBase>
class o2::gpu::Spline1DBase< DataT, YdimT, FlatBase >

The Spline1D class performs a cubic spline interpolation on a one-dimensional non-uniform grid.

The class is a flat C structure. It inherits from the FlatObject. No virtual methods, no ROOT types are used.

— Interpolation —

The spline S(x) approximates a function F(x):[Xmin,Xmax]->Y X is one-dimensional, Y may be multi-dimensional.

The spline has n knots x_i. The spline value S(x_i) and its derivative S'(x_i) are stored for every knot. Inbetween the knots, S(x) is evaluated via interpolation by 3-rd degree polynomials.

The spline S(x) and its first derivative are continuous. Depending on the initialization of the derivatives S'(x_i), the second derivative may or may not be continuous at the knots.

— Knots —

The knots are not entirely irregular. There is an internal scaled coordinate, called U, where all N knots have some integer positions: {U0==0, U1, .., Un-1==Umax}. It is implemented this way for fast matching of any X value to its neighboring knots.

For example, three knots with U coordinates u_i={0, 3, 5}, being stretched on the X segment [0., 1.], will have X coordinates x_i={0., 3./5., 1.}

For a few reasons, it is better to keep U-gaps between the knots minimal. A spline with knots u_i={0,1,2} is mathematically the same as the spline with knots u_i={0,2,4}. However, it uses less memory.

The minimal number of knots is 2.

— Output dimensionality —

There are two ways to set the dimensionality of Y - either in the constructor or as a template argument:

Spline1D<float> s( nYdimensions, nKnots ); Spline1D<float, nYdimensions> s( nKnots );

The second implementation works faster. Use it when nYdimensions is known at the compile time.

There is also a variation of the first specification which lets the compiler know the maximal possible number of Y dimensions:

Spline1D<float, -nYdimensionsMax> s( nYdimensions, nKnots );

This specification does not allocate any variable-size arrays and therefore compiles for the GPU.

-— External storage of spline parameters for a given F —

One can store all F-dependent spline parameters outside of the spline object and provide them at each interpolation call. To do so, create a spline with nYdimensions=0; create spline parameters for F via Spline1DHelper class; then use special interpolateAtU(..) methods for the interpolation.

This feature allows one to use the same spline object for the approximation of different functions on the same grid of knots.

-— Creation of a spline -—

The spline is supposed to be a best-fit spline, created by the approximateFunction() method.

Best-fit means that the spline values S_i and its derivatives D_i at the knots are adjusted to minimize the overall difference between S(x) and F(x). The spline constructed this way is much more accurate than a classical interpolation spline.

The difference to F() is minimized at all integer values of U coordinate (in particular, at all knots) and at extra nAuxiliaryPoints points between the integer numbers.

nAuxiliaryPoints is given as a parameter of approximateFunction() method. With nAuxiliaryPoints==3, the approximation accuracy is noticeably better than the one with 1 or 2. Higher values usually give a little improvement over 3.

The number of auxiliary points does not influence the interpolation speed, but a high number can slow down the spline's creation.

It is also possible to construct the spline classically - by taking F(x) values only at knots and making the first and the second derivatives of S(x) continuous. Use the corresponding method from Spline1DHelper.

-— Example of creating a spline -—

auto F = [&](double x, double &f) { // a function to be approximated f[0] = x*x+3.f; // F(x) };

const int32_t nKnots = 3;

int32_t knots[nKnots] = {0, 1, 5}; // relative(!) knot positions

Spline1D<float,1> spline( nKnots, knots ); // create 1-dimensional spline with the knots

spline.approximateFunction(0., 1., F); // let the spline approximate F on a segment [0., 1.]

float s = spline.interpolate(0.2); // interpolated value at x==0.2

— See also Spline1D::test() method for examples ==================================================================================================

Declare the Spline1D class as a template with one optional parameters.

Class specializations depend on the XdimT, YdimT values. They can be found in SplineSpecs.h

Parameters
DataTdata type: float or double
YdimTYdimT > 0 : the number of Y dimensions is known at the compile time and is equal to XdimT YdimT = 0 : the number of Y dimensions will be set in the runtime YdimT < 0 : the number of Y dimensions will be set in the runtime, and it will not exceed abs(YdimT)

Common implementation (no ClassDefNV — ROOT dictionary is in the FlatObject specialization below)

Definition at line 137 of file Spline1D.h.

Member Typedef Documentation

◆ Container

template<typename DataT , int32_t YdimT, class FlatBase >
using o2::gpu::Spline1DBase< DataT, YdimT, FlatBase >::Container = Spline1DContainer<DataT, FlatBase>
protected

Definition at line 141 of file Spline1D.h.

◆ ParentSpec

template<typename DataT , int32_t YdimT, class FlatBase >
using o2::gpu::Spline1DBase< DataT, YdimT, FlatBase >::ParentSpec = Spline1DSpec<DataT, YdimT, SplineUtil::getSpec(YdimT), FlatBase>
protected

Definition at line 142 of file Spline1D.h.

Constructor & Destructor Documentation

◆ Spline1DBase() [1/2]

template<typename DataT , int32_t YdimT, class FlatBase >
o2::gpu::Spline1DBase< DataT, YdimT, FlatBase >::Spline1DBase ( )
default

◆ Spline1DBase() [2/2]

template<typename DataT , int32_t YdimT, class FlatBase >
o2::gpu::Spline1DBase< DataT, YdimT, FlatBase >::Spline1DBase ( const Spline1DBase< DataT, YdimT, FlatBase > &  v)
inline

Definition at line 147 of file Spline1D.h.

Member Function Documentation

◆ operator=()

template<typename DataT , int32_t YdimT, class FlatBase >
Spline1DBase & o2::gpu::Spline1DBase< DataT, YdimT, FlatBase >::operator= ( const Spline1DBase< DataT, YdimT, FlatBase > &  v)
inline

Definition at line 151 of file Spline1D.h.

◆ readFromFile()

template<typename DataT , int32_t YdimT, class FlatBase >
static Spline1DBase * o2::gpu::Spline1DBase< DataT, YdimT, FlatBase >::readFromFile ( TFile &  inpf,
const char name 
)
inlinestatic

Definition at line 162 of file Spline1D.h.


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