![]() |
Project
|
#include <IrregularSpline1D.h>
Inherits o2::gpu::FlatObject.
Classes | |
struct | Knot |
The struct represents a knot(i) and interval [ knot(i), knot(i+1) ]. More... | |
Public Member Functions | |
IrregularSpline1D () | |
_____________ Constructors / destructors __________________________ | |
IrregularSpline1D (const IrregularSpline1D &)=delete | |
Copy constructor: disabled to avoid ambiguity. Use cloneFromObject instead. | |
IrregularSpline1D & | operator= (const IrregularSpline1D &)=delete |
Assignment operator: disabled to avoid ambiguity. Use cloneFromObject instead. | |
~IrregularSpline1D ()=default | |
Destructor. | |
void | cloneFromObject (const IrregularSpline1D &obj, char *newFlatBufferPtr) |
Construction interface. | |
void | destroy () |
void | construct (int32_t numberOfKnots, const float knots[], int32_t numberOfAxisBins) |
_______________ Construction interface ________________________ | |
void | constructRegular (int32_t numberOfKnotsU) |
Constructor for a regular spline. | |
template<typename T > | |
GPUd () void correctEdges(T *data) const | |
_______________ Main functionality ________________________ | |
template<typename T > | |
GPUd() static T getSpline(const IrregularSpline1D | GPUd () T getSpline(const T correctedData[] |
Get interpolated value for f(u) using spline at knot "knot1" and function values at knots {knot_0,knot_1,knot_2,knot_3}. | |
GPUd () int32_t getNumberOfKnots() const | |
Get number of knots. | |
GPUd () int32_t getKnotIndex(float u) const | |
GPUd () const IrregularSpline1D | |
Get i-th knot, no border check performed! | |
GPUd () const int32_t *getBin2KnotMap() const | |
technical stuff | |
int32_t | getNumberOfAxisBins () const |
Get number of axis bins. | |
GPUd () static void getEdgeCorrectionCoefficients(double u0 | |
void | print () const |
Print method. | |
char * | releaseInternalBuffer () |
Making the data buffer external. | |
void | moveBufferTo (char *newBufferPtr) |
void | setActualBufferAddress (char *actualFlatBufferPtr) |
Moving the class with its external buffer to another location. | |
void | setFutureBufferAddress (char *futureFlatBufferPtr) |
![]() | |
FlatObject ()=default | |
_____________ Constructors / destructors __________________________ | |
~FlatObject () | |
FlatObject (const FlatObject &)=delete | |
FlatObject & | operator= (const FlatObject &)=delete |
void | destroy () |
_______________ Utilities _______________________________________________ | |
size_t | getFlatBufferSize () const |
Gives size of the flat buffer. | |
const char * | getFlatBufferPtr () const |
Gives pointer to the flat buffer. | |
bool | isConstructed () const |
Tells if the object is constructed. | |
bool | isBufferInternal () const |
Tells if the buffer is internal. | |
void | adoptInternalBuffer (char *buf) |
void | clearInternalBufferPtr () |
void | printC () const |
Print the content of the flat buffer. | |
Static Public Member Functions | |
static constexpr size_t | getBufferAlignmentBytes () |
Get minimal required alignment for the flat buffer. | |
static constexpr size_t | getDataAlignmentBytes () |
Get minimal required alignment for the spline data. | |
static constexpr size_t | getBufferAlignmentBytes () |
_____________ FlatObject functionality, see FlatObject class for description ____________ | |
static constexpr size_t | getClassAlignmentBytes () |
_____________ Memory alignment __________________________ | |
![]() | |
static size_t | alignSize (size_t sizeBytes, size_t alignmentBytes) |
_______________ Generic utilities _______________________________________________ | |
template<class T > | |
static T * | relocatePointer (const char *oldBase, char *newBase, const T *ptr) |
Relocates a pointer inside a buffer to the new buffer address. | |
template<class T , class TFile > | |
static int32_t | writeToFile (T &obj, TFile &outf, const char *name) |
write a child class object to the file | |
template<class T , class TFile > | |
static T * | readFromFile (TFile &inpf, const char *name) |
read a child class object from the file | |
template<class T > | |
static std::string | stressTest (T &obj) |
Test the flat object functionality for a child class T. | |
Public Attributes | |
GPUd() static T getSpline(const IrregularSpline1D float u | const |
double | u1 |
double double | u2 |
double double double | u3 |
double double double double & | c0 |
double double double double double & | c1 |
double double double double double double & | c2 |
double double double double double double double & | c3 |
Additional Inherited Members | |
![]() | |
enum | ConstructionState : uint32_t { NotConstructed = 0x0 , Constructed = 0x1 , InProgress = 0x2 } |
GPUCA_GPUCODE. More... | |
![]() | |
void | startConstruction () |
_____________ Construction _________ | |
void | finishConstruction (int32_t flatBufferSize) |
void | cloneFromObject (const FlatObject &obj, char *newFlatBufferPtr) |
char * | releaseInternalBuffer () |
_____________ Methods for making the data buffer external __________________________ | |
void | moveBufferTo (char *newBufferPtr) |
void | setActualBufferAddress (char *actualFlatBufferPtr) |
_____________ Methods for moving the class with its external buffer to another location __________________________ | |
void | setFutureBufferAddress (char *futureFlatBufferPtr) |
ClassDefNV (FlatObject, 1) | |
Pointer to the flat buffer. | |
![]() | |
static constexpr size_t | getClassAlignmentBytes () |
_____________ Memory alignment __________________________ | |
static constexpr size_t | getBufferAlignmentBytes () |
Gives minimal alignment in bytes required for the flat buffer. | |
![]() | |
int32_t | mFlatBufferSize = 0 |
size of the flat buffer | |
uint32_t | mConstructionMask = ConstructionState::NotConstructed |
mask for constructed object members, first two bytes are used by this class | |
char * | mFlatBufferContainer = nullptr |
char * | mFlatBufferPtr = nullptr |
The IrregularSpline1D class represents one-dimensional spline interpolation on nonunifom (irregular) grid.
The class is flat C structure. No virtual methods, no ROOT types are used. It is designed for spline parameterisation of TPC transformation.
The spline interpolates a generic function F:[0,1]->R.
Let's call the function parameter U, the function value F. The interpolation is performed on n knots {U0==0., U1, .., Un==1.} with given function values {F0, ..., Fn} at the knots.
An interpolation in each interval between two knots is performed by 3-th degree polynom. The polynoms cross the Fi values at the knots and have contnious 1-th derivative. For performance reasons, the polynoms are created locally on-the-fly using only four values of F at four neighbouring knots. Therefore unlike the classical splines, the second derivative may not be continious.
The knots should belong to interval [0,1], the distance between knots is (almost) arbitrary.
Nothing which depends on F is stored in the class. Therefore one can use the same class for different F functions. The function values {F0,..Fn} have to be provided by user for each call.
The class performs a fast search of a spline interval: (float U ) -> [int32_t iKnot, int32_t iKnot+1 ). For that purpose, initial U coordinates of the knots are rounded to the closest i*1./nAxisBins values.
The minimal number of knots is 5, the minimal number of axis bins is 4
Knots U0=0. and Un=1. are always present. They are added automatically when they are not set by an user.
Number of knots and they U coordinates may change during initialisation!
User should provide function values Fi for all !constructed! knots.
---------— Edge correction ---------—
The function values at both edges should be corrected beforehand via spline.correctEdges( f ); method. It is needed for the fast spline mathematics to work correctly.
Explanation:
To calculate a spline at interval [Ui,U{i+1}), we need to know the function values at 4 knots: {i-1,i,i+1,i+2} As the knots {-1} and {n} do not exist, the edge intervals [U0,U1) and [U{n-2},U{n-1}] need special treatment. Thus, the algorithm needs to have 3 big branches containing different math :(
To avoid the branches in the code, we do a trick:
Function values for the interval [U0,U1) are constructed using a spline polynom from the next interval [U1,U2). To do so, all U values from the first interval are assigned to the second interval [U1,U2) in the U->(knot interval) map.
This approach has no branches, but has another problem: the spline from the second interval [U1,U2) will not necessarily cross the original F0 value at u=U0.
To fix this, we modify the function value F0 in the way, that the spline from [U1,U2) also crosses the original F0 value at u=U0
The same trick is performed for the last interval [U{n-2},U{n-1})
Example of creating a spline:
const int32_t nKnots=5; float knots[nKnots] = {0., 0.25, 0.5, 0.7, 1.}; IrregularSpline1D spline; spline.construct(nKnots, knots, 4); float f[nKnots] = { 3.5, 2.0, 1.4, 3.8, 2.3}; spline.correctEdges( f ); spline.getSpline( f, 0. ); // == 3.5 spline.getSpline( f, 0.1 ); // == some interpolated value spline.getSpline( f, 0.25 ); // == 2.0 spline.getSpline( f, 0.5 ); // == 1.4 spline.getSpline( f, 1. ); // == 2.3
Definition at line 112 of file IrregularSpline1D.h.
IrregularSpline1D::IrregularSpline1D | ( | ) |
_____________ Constructors / destructors __________________________
Default constructor. Creates an empty uninitialised object
Default constructor. Creates an empty uninitialised object
Definition at line 29 of file IrregularSpline1D.cxx.
|
delete |
Copy constructor: disabled to avoid ambiguity. Use cloneFromObject instead.
|
default |
Destructor.
void IrregularSpline1D::cloneFromObject | ( | const IrregularSpline1D & | obj, |
char * | newFlatBufferPtr | ||
) |
Construction interface.
See FlatObject for description
Definition at line 43 of file IrregularSpline1D.cxx.
void IrregularSpline1D::construct | ( | int32_t | numberOfKnots, |
const float | knots[], | ||
int32_t | numberOfAxisBins | ||
) |
_______________ Construction interface ________________________
Constructor
Number of knots created and their values may differ from the input values:
numberOfKnots | Number of knots in knots[] array |
knots | Array of knots. |
numberOfAxisBins | Number of axis bins to map U coordinate to an appropriate [knot(i),knot(i+1)] interval. The knot positions have a "granularity" of 1./numberOfAxisBins |
Constructor. Initialises the spline with a grid with numberOfKnots knots in the interval [0,1] array inputKnots[] has numberOfKnots entries, ordered from 0. to 1. knots on the edges u==0. & u==1. are obligatory
The number of knots created and their values may change during initialisation:
numberOfKnots | Number of knots in knots[] array |
knots | Array of knots. |
numberOfAxisBins | Number of axis bins to map U coordinate to an appropriate [knot(i),knot(i+1)] interval. The knot positions have a "granularity" of 1./(numberOfAxisBins-1) |
Definition at line 52 of file IrregularSpline1D.cxx.
void IrregularSpline1D::constructRegular | ( | int32_t | numberOfKnotsU | ) |
Constructor for a regular spline.
Constructor for a regular spline
numberOfKnots | Number of knots |
Definition at line 187 of file IrregularSpline1D.cxx.
void IrregularSpline1D::destroy | ( | ) |
See FlatObject for description
Definition at line 34 of file IrregularSpline1D.cxx.
|
inlinestaticconstexpr |
_____________ FlatObject functionality, see FlatObject class for description ____________
Memory alignment
Definition at line 197 of file FlatObject.h.
|
inlinestaticconstexpr |
Get minimal required alignment for the flat buffer.
Definition at line 227 of file IrregularSpline1D.h.
|
inlinestaticconstexpr |
_____________ Memory alignment __________________________
Gives minimal alignment in bytes required for the class object
Definition at line 194 of file FlatObject.h.
|
inlinestaticconstexpr |
Get minimal required alignment for the spline data.
Definition at line 230 of file IrregularSpline1D.h.
|
inline |
Get number of axis bins.
Definition at line 238 of file IrregularSpline1D.h.
|
inline |
technical stuff
Get a map (U axis bin index) -> (corresponding knot index)
Definition at line 235 of file IrregularSpline1D.h.
|
inline |
Get i-th knot, no border check performed!
Definition at line 218 of file IrregularSpline1D.h.
o2::gpu::IrregularSpline1D::GPUd | ( | ) | const |
Get index of associated knot for a given U coordinate.
Note: U values from the first interval are mapped to the second inrerval. Values from the last interval are mapped to the previous interval.
|
inline |
Get number of knots.
Definition at line 208 of file IrregularSpline1D.h.
o2::gpu::IrregularSpline1D::GPUd | ( | ) |
Get coefficients for edge correction
Let's the interpolated function has values f0, f1, f2, f3 at knots u0, u1, u2, u3 The corrected value of f0 is calculated as: f0_corr = c0*f0 + c1*f1 + c2*f2 + c3*f3
The coefficients ci are calculated in double precision because they are temporary and used only at the initialisation phase. So we can pay a price for the higher accuracy here.
GPUd() static T getSpline(const IrregularSpline1D o2::gpu::IrregularSpline1D::GPUd | ( | ) | const |
o2::gpu::IrregularSpline1D::GPUd | ( | ) | const |
_______________ Main functionality ________________________
Correction of data values at both edge knots.
It is needed for the fast spline mathematics to work correctly. See explanation at the class comment above.
data | array of function values. It has the size of getNumberOfKnots() |
Sets buffer pointer to the new address, move the buffer content there. A daughter class must relocate all the pointers inside th buffer
sets buffer pointer to the new address, move the buffer content there.
Definition at line 225 of file FlatObject.h.
|
delete |
Assignment operator: disabled to avoid ambiguity. Use cloneFromObject instead.
void IrregularSpline1D::print | ( | ) | const |
Print method.
Definition at line 207 of file IrregularSpline1D.cxx.
|
inline |
Making the data buffer external.
Definition at line 220 of file FlatObject.h.
Moving the class with its external buffer to another location.
Definition at line 234 of file FlatObject.h.
Sets a future location of the external flat buffer before moving it to this location (i.e. when copying to GPU).
The object can be used immidiatelly after the move, call of setActualFlatBufferAddress() is not needed.
A daughter class should already relocate all the pointers inside the current buffer to the future location. It should not touch memory in the future location, since it may be not yet available.
!!! Information about the actual buffer location will be lost. !!! Most of the class methods may be called only after the buffer will be moved to its new location. !!! To undo call setActualFlatBufferAddress()
Sets a future location of the external flat buffer before moving it to this location.
A daughter class should already reset all the pointers inside the current buffer to the future location without touching memory in the future location.
Definition at line 247 of file FlatObject.h.
double double double double& o2::gpu::IrregularSpline1D::c0 |
Definition at line 249 of file IrregularSpline1D.h.
double double double double double& o2::gpu::IrregularSpline1D::c1 |
Definition at line 249 of file IrregularSpline1D.h.
double double double double double double& o2::gpu::IrregularSpline1D::c2 |
Definition at line 249 of file IrregularSpline1D.h.
double double double double double double double& o2::gpu::IrregularSpline1D::c3 |
Definition at line 249 of file IrregularSpline1D.h.
GPUd() static T getSpline(const IrregularSpline1D float u o2::gpu::IrregularSpline1D::const |
Definition at line 205 of file IrregularSpline1D.h.
double o2::gpu::IrregularSpline1D::u1 |
Definition at line 249 of file IrregularSpline1D.h.
double double o2::gpu::IrregularSpline1D::u2 |
Definition at line 249 of file IrregularSpline1D.h.
double double double o2::gpu::IrregularSpline1D::u3 |
Definition at line 249 of file IrregularSpline1D.h.