15#ifndef ALICEO2_TPC_MULTIVARIATEPOLYNOMIAL
16#define ALICEO2_TPC_MULTIVARIATEPOLYNOMIAL
23#if !defined(GPUCA_GPUCODE)
26#if !defined(GPUCA_STANDALONE)
43template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly = false>
47#if !defined(GPUCA_GPUCODE)
51 template <
bool IsEnabled = true,
typename std::enable_if<(IsEnabled && (Dim == 0 && Degree == 0)),
int32_t>::type = 0>
58 template <
bool IsEnabled = true,
typename std::enable_if<(IsEnabled && (Dim != 0 && Degree != 0)),
int32_t>::type = 0>
75#if !defined(GPUCA_GPUCODE)
96 GPUd() float eval(const
float x[])
const {
return this->evalPol(mParams,
x); }
98#if !defined(GPUCA_GPUCODE)
113#ifndef GPUCA_STANDALONE
129 template <
bool IsEnabled = true,
typename std::enable_if<(IsEnabled && (Dim == 0 && Degree == 0)),
int32_t>::type = 0>
130 void fit(std::vector<double>&
x, std::vector<double>&
y, std::vector<double>& error,
const bool clearPoints)
149 using DataTParams = float;
151 DataTParams* mParams{
nullptr};
153#if !defined(GPUCA_GPUCODE)
155 std::size_t sizeOfParameters()
const {
return mNParams *
sizeof(DataTParams); }
168#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
169template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
173 inpf.GetObject(
name, polTmp);
175 setFromContainer(*polTmp);
178 LOGP(info,
"couldnt load object {} from input file",
name);
182template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
185 if constexpr (Dim > 0 &&
Degree > 0) {
186 if (this->getDim() != container.
mDim) {
187 LOGP(info,
"wrong number of dimensions! this {} container {}", this->getDim(), container.
mDim);
190 if (this->getDegree() != container.
mDegree) {
191 LOGP(info,
"wrong number of degrees! this {} container {}", this->getDegree(), container.
mDegree);
195 LOGP(info,
"InteractionOnly is set for this object to {}, but stored as {} in the container", this->isInteractionOnly(), container.
mInteractionOnly);
198 setParams(container.
mParams.data());
202 this->cloneFromObject(polTmp,
nullptr);
206template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
210 outf.WriteObject(&cont,
name);
215template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
220 mNParams = obj.mNParams;
221 if constexpr (Dim == 0 &&
Degree == 0) {
222 this->mDim = obj.mDim;
223 this->mDegree = obj.mDegree;
224 this->mInteractionOnly = obj.mInteractionOnly;
231template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
234 char* oldFlatBufferPtr = mFlatBufferPtr;
236 char* currFlatBufferPtr = mFlatBufferPtr;
237 mFlatBufferPtr = oldFlatBufferPtr;
238 setActualBufferAddress(currFlatBufferPtr);
241template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
245 const std::size_t flatbufferSize = sizeOfParameters();
247 mParams =
reinterpret_cast<float*
>(mFlatBufferPtr);
251template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
258template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
262 mParams =
reinterpret_cast<float*
>(mFlatBufferPtr);
265template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
Definition of FlatObject class.
void setFutureBufferAddress(char *futureFlatBufferPtr)
void destroy()
_______________ Utilities _______________________________________________
static T * relocatePointer(const char *oldBase, char *newBase, const T *ptr)
Relocates a pointer inside a buffer to the new buffer address.
void setActualBufferAddress(char *actualFlatBufferPtr)
_____________ Methods for moving the class with its external buffer to another location _____________...
void startConstruction()
_____________ Construction _________
void moveBufferTo(char *newBufferPtr)
void finishConstruction(int32_t flatBufferSize)
void cloneFromObject(const FlatObject &obj, char *newFlatBufferPtr)
~MultivariatePolynomial()=default
default destructor
void setFromContainer(const MultivariatePolynomialContainer &container)
MultivariatePolynomialContainer getContainer() const
converts the parameters to a container which can be written to a root file
MultivariatePolynomial(const uint32_t nDim, const uint32_t degree, const bool interactionOnly=false)
void moveBufferTo(char *newBufferPtr)
void loadFromFile(TFile &inpf, const char *name)
void writeToFile(TFile &outf, const char *name) const
MultivariatePolynomial()
constructor for compile time evaluation of polynomial formula
GPUd() float eval(const float x[]) const
================================================================================================
void setParams(const float params[])
void setActualBufferAddress(char *actualFlatBufferPtr)
set location of external flat buffer
void setFutureBufferAddress(char *futureFlatBufferPtr)
set future location of the flat buffer
const float * getParams() const
void destroy()
destroy the object (release internal flat buffer)
void cloneFromObject(const MultivariatePolynomial &obj, char *newFlatBufferPtr)
========== FlatObject functionality, see FlatObject class for description =================
MultivariatePolynomial(const MultivariatePolynomial &obj)
Copy constructor.
uint32_t getNParams() const
void setParam(const uint32_t param, const float val)
void fit(std::vector< double > &x, std::vector< double > &y, std::vector< double > &error, const bool clearPoints)
GLuint const GLchar * name
GLenum const GLfloat * params
simple struct to enable writing the MultivariatePolynomial to file
const uint32_t mDim
number of dimensions of the polynomial
const uint32_t mDegree
degree of the polynomials
const bool mInteractionOnly
consider only interaction terms
const std::vector< float > mParams
parameters of the polynomial
std::vector< o2::ctf::BufferType > vec