17#ifndef ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_SPLINE1DSPEC_H
18#define ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_SPLINE1DSPEC_H
24#if !defined(GPUCA_GPUCODE)
44template <
typename DataT>
58 GPUd() int32_t getU()
const {
return (int32_t)(
u + 0.1f); }
64 GPUd() static constexpr int32_t getVersion() {
return 1; }
79#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
82 std::function<
void(
double x,
double f[])> F,
83 int32_t nAuxiliaryDataPoints = 4);
88#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
105 GPUd() size_t getParameterAlignmentBytes()
const
107 size_t s = 2 *
sizeof(DataT) *
mYdim;
108 return (s < 16) ? s : 16;
112 GPUd() int32_t getNumberOfParameters()
const {
return calcNumberOfParameters(
mYdim); }
115 GPUd() size_t getSizeOfParameters()
const {
return sizeof(DataT) * getNumberOfParameters(); }
124 template <SafetyLevel SafeT = SafetyLevel::kSafe>
134 template <SafetyLevel SafeT = SafetyLevel::kSafe>
135 GPUd() int32_t getLeftKnotIndexForU(DataT u) const;
172 GPUd() int32_t calcNumberOfParameters(int32_t nYdim)
const {
return (2 * nYdim) * getNumberOfKnots(); }
176#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
178 static int32_t test(const bool draw = 0, const bool drawDataPoints = 1);
186#if !defined(GPUCA_GPUCODE)
204#if !defined(GPUCA_GPUCODE)
206 void recreate(int32_t nYdim, int32_t numberOfKnots);
209 void recreate(int32_t nYdim, int32_t numberOfKnots,
const int32_t knotU[]);
225template <
typename DataT>
226template <typename Spline1DContainer<DataT>::SafetyLevel SafeT>
231 int32_t iu = u < 0 ? 0 : (u > (
float)mUmax ? mUmax : (int32_t)u);
232 if (SafeT == SafetyLevel::kSafe) {
233 iu = (iu < 0) ? 0 : (iu > mUmax ? mUmax : iu);
235 return getUtoKnotMap()[iu];
238template <
typename DataT>
239GPUdi()
void Spline1DContainer<DataT>::setXrange(DataT xMin, DataT xMax)
242 double l = ((double)xMax) - xMin;
246 mXtoUscale = mUmax / l;
269template <
typename DataT,
int32_t YdimT,
int32_t SpecT>
276template <
typename DataT,
int32_t YdimT>
290 interpolateU<SafetyLevel::kSafe>(mYdim, mParameters, convXtoU(
x),
S);
294 template <SafetyLevel SafeT = SafetyLevel::kSafe>
298 const auto nYdimTmp = SplineUtil::getNdim<YdimT>(inpYdim);
299 const auto nYdim = nYdimTmp.get();
300 int32_t iknot = TBase::template getLeftKnotIndexForU<SafeT>(u);
301 const DataT* d =
Parameters + (2 * nYdim) * iknot;
302 interpolateU(nYdim, getKnots()[iknot], &(d[0]), &(d[nYdim]), &(d[2 * nYdim]), &(d[3 * nYdim]), u,
S);
308 template <
typename T>
314 const auto nYdimTmp = SplineUtil::getNdim<YdimT>(inpYdim);
315 const auto nYdim = nYdimTmp.get();
316 T uu = T(u - knotL.u);
319 for (int32_t dim = 0; dim < nYdim; ++dim) {
320 T df = (Sr[dim] - Sl[dim]) * li;
321 T
a = Dl[dim] + Dr[dim] - df - df;
322 T
b = df - Dl[dim] -
a;
323 S[dim] = ((
a *
v +
b) *
v + Dl[dim]) * uu + Sl[dim];
339 template <
typename T>
340 GPUd() static
void getUderivatives(const
Knot& knotL, DataT u,
341 T& dSl, T& dDl, T& dSr, T& dDr)
346 T
v = u * T(knotL.Li);
357 using TBase::convXtoU;
358 using TBase::getKnot;
359 using TBase::getKnots;
360 using TBase::getNumberOfKnots;
363 using TBase::mParameters;
373template <
typename DataT,
int32_t YdimT>
383#if !defined(GPUCA_GPUCODE)
390 recreate(numberOfKnots);
396 recreate(numberOfKnots, knotU);
401 TBase::cloneFromObject(
v,
nullptr);
404 void recreate(int32_t numberOfKnots) { TBase::recreate(YdimT, numberOfKnots); }
407 void recreate(int32_t numberOfKnots,
const int32_t knotU[])
409 TBase::recreate(YdimT, numberOfKnots, knotU);
414 GPUd() constexpr int32_t getYdimensions()
const {
return YdimT; }
417 GPUd() constexpr
size_t getParameterAlignmentBytes()
const
419 size_t s = 2 *
sizeof(DataT) * YdimT;
420 return (s < 16) ? s : 16;
424 GPUd() int32_t getNumberOfParameters()
const {
return (2 * YdimT) * getNumberOfKnots(); }
427 GPUd() size_t getSizeOfParameters()
const {
return (
sizeof(DataT) * 2 * YdimT) * getNumberOfKnots(); }
432 template <SafetyLevel SafeT = SafetyLevel::kSafe>
436 TBase::template interpolateU<SafeT>(YdimT,
Parameters, u,
S);
441 template <
typename T>
442 GPUd()
void interpolateU(const typename TBase::Knot& knotL,
447 TBase::interpolateU(YdimT, knotL, Sl, Dl, Sr, Dr, u,
S);
450 using TBase::getNumberOfKnots;
454#if !defined(GPUCA_GPUCODE)
455 using TBase::recreate;
457 using TBase::interpolateU;
464template <
typename DataT,
int32_t YdimT>
474#if !defined(GPUCA_GPUCODE)
481 TBase::recreate(nYdim, numberOfKnots);
486 TBase::recreate(nYdim, numberOfKnots, knotU);
491 TVeryBase::cloneFromObject(
v,
nullptr);
494 void recreate(int32_t nYdim, int32_t numberOfKnots) { TBase::recreate(nYdim, numberOfKnots); }
497 void recreate(int32_t nYdim, int32_t numberOfKnots,
const int32_t knotU[])
499 TBase::recreate(nYdim, numberOfKnots, knotU);
505 using TBase::interpolateU;
512template <
typename DataT>
514 :
public Spline1DSpec<DataT, 1, SplineUtil::getSpec(999)>
522 GPUd() DataT interpolate(DataT
x)
const
525 TBase::interpolate(
x, &
S);
Definition of FlatObject class.
char * releaseInternalBuffer()
_____________ Methods for making the data buffer external __________________________
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
static constexpr size_t getClassAlignmentBytes()
_____________ Memory alignment __________________________
void cloneFromObject(const Spline1DContainer &obj, char *newFlatBufferPtr)
void setFutureBufferAddress(char *futureFlatBufferPtr)
Knot * getKnots()
Non-const accessor to the knots array.
int32_t mUmax
U of the last knot.
GPUd() static const expr int32_t getVersion()
_____________ Version control __________________________
int32_t mYdim
_____________ Data members ____________
GPUd() const Knot *getKnots() const
Get the array of knots.
~Spline1DContainer()=default
Destructor.
GPUd() size_t getParameterAlignmentBytes() const
Get minimal required alignment for the spline parameters.
void setActualBufferAddress(char *actualFlatBufferPtr)
void approximateFunction(double xMin, double xMax, std::function< void(double x, double f[])> F, int32_t nAuxiliaryDataPoints=4)
_______________ Construction interface ________________________
GPUd() DataT getXtoUscale() const
Get XtoUscale.
DataT mXtoUscale
a scaling factor to convert X to U
GPUd() int32_t getYdimensions() const
Get number of Y dimensions.
ClassDefNV(Spline1DContainer, 1)
(transient!!) pointer to F-dependent parameters inside the mFlatBufferPtr array
SafetyLevel
Named enumeration for the safety level used by some methods.
Spline1DContainer(const Spline1DContainer &)=delete
Disable all other constructors.
GPUd() const Knot &getKnot(int32_t i) const
Get i-th knot.
Spline1DContainer()=default
_____________ C++ constructors / destructors __________________________
GPUd() const DataT *getParameters() const
Get spline parameters const.
GPUd() int32_t getNumberOfParameters() const
Number of parameters.
GPUd() int32_t getLeftKnotIndexForU(DataT u) const
Get index of an associated knot for a given U coordinate. Performs a boundary check.
void print() const
Print method.
GPUd() int32_t getNumberOfKnots() const
Get a number of knots.
DataT * mParameters
(transient!!) pointer to (integer U -> knot index) map inside the mFlatBufferPtr array
GPUd() const int32_t *getUtoKnotMap() const
_______________ Technical stuff ________________________
void recreate(int32_t nYdim, int32_t numberOfKnots)
Constructor for a regular spline.
GPUd() DataT convUtoX(DataT u) const
Convert U coordinate to X.
GPUd() DataT convXtoU(DataT x) const
Convert X coordinate to U.
GPUd() int32_t getUmax() const
_______________ Getters ________________________
GPUd() DataT getXmin() const
Get Xmin.
DataT mXmin
X of the first knot.
GPUd() DataT getXmax() const
Get Xmax.
GPUd() size_t getSizeOfParameters() const
Size of the parameter array in bytes.
GPUd() void setXrange(DataT xMin
Set X range.
void moveBufferTo(char *newBufferPtr)
int32_t writeToFile(TFile &outf, const char *name)
_______________ IO ________________________
int32_t * getUtoKnotMap()
Non-const accessor to U->knots map.
int32_t mNumberOfKnots
n knots on the grid
static Spline1DContainer * readFromFile(TFile &inpf, const char *name)
read a class object from the file
GPUd() DataT interpolate(DataT x) const
Simplified interface for 1D: return the interpolated value.
TBase::SafetyLevel SafetyLevel
GPUd() static void getUderivatives(const Knot &knotL
GPUd() void interpolate(DataT x
_______________ Interpolation math ________________________
ClassDefNV(Spline1DSpec, 0)
GPUd() void interpolateU(int32_t inpYdim
Get interpolated value for an nYdim-dimensional S(u) using spline parameters Parameters.
GPUd() const expr size_t getParameterAlignmentBytes() const
Get minimal required alignment for the spline parameters.
Spline1DSpec(int32_t numberOfKnots)
Constructor for a regular spline.
GPUd() void interpolateU(GPUgeneric() const DataT Parameters[]
_______ Expert tools: interpolation with given nYdim and external Parameters _______
Spline1DSpec(int32_t numberOfKnots, const int32_t knotU[])
Constructor for an irregular spline.
Spline1DSpec(const Spline1DSpec &v)
Copy constructor.
Spline1DSpec()
Default constructor.
void recreate(int32_t numberOfKnots, const int32_t knotU[])
Constructor for an irregular spline.
GPUd() int32_t getNumberOfParameters() const
Number of parameters.
GPUd() const expr int32_t getYdimensions() const
Get number of Y dimensions.
TVeryBase::SafetyLevel SafetyLevel
GPUd() size_t getSizeOfParameters() const
Size of the parameter array in bytes.
void recreate(int32_t numberOfKnots)
Constructor for a regular spline.
void recreate(int32_t nYdim, int32_t numberOfKnots)
Constructor for a regular spline.
void recreate(int32_t nYdim, int32_t numberOfKnots, const int32_t knotU[])
Constructor for an irregular spline.
Spline1DSpec(int32_t nYdim, int32_t numberOfKnots)
Constructor for a regular spline.
Spline1DSpec()
Default constructor.
ClassDefNV(Spline1DSpec, 0)
Spline1DSpec(int32_t nYdim, int32_t numberOfKnots, const int32_t knotU[])
Constructor for an irregular spline.
TVeryBase::SafetyLevel SafetyLevel
Spline1DSpec(const Spline1DSpec &v)
Copy constructor.
static constexpr int32_t getSpec(int32_t nXdim, int32_t nYdim)
GLuint const GLchar * name
GLboolean GLboolean GLboolean b
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLboolean GLboolean GLboolean GLboolean a
GLfloat GLfloat GLfloat v2
GPUd() const expr uint32_t MultivariatePolynomialHelper< Dim
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
GPUd() int32_t getU() const
Get u as an integer.
DataT u
u coordinate of the knot i (an integer number in float format)