15#ifndef ALICEO2_TPC_MULTIVARIATEPOLYNOMIALHELPER
16#define ALICEO2_TPC_MULTIVARIATEPOLYNOMIALHELPER
20#if !defined(GPUCA_GPUCODE)
24#if !defined(GPUCA_NO_FMT)
25#include <fmt/format.h>
34#if !defined(GPUCA_GPUCODE)
63 template <u
int32_t Degree, u
int32_t Dim>
66 if constexpr (
Degree == 0) {
67 return binomialCoeff<Dim - 1, 0>();
69 return binomialCoeff<Dim - 1 +
Degree,
Degree>() + getNParametersAllTerms<Degree - 1, Dim>();
79 return binomialCoeff(dim - 1, 0);
81 return binomialCoeff(dim - 1 + degree, degree) + getNParametersAllTerms(degree - 1, dim);
86 template <u
int32_t Degree, u
int32_t Dim>
87 GPUd() static constexpr
uint32_t getNParametersInteractionOnly()
89 if constexpr (
Degree == 0) {
90 return binomialCoeff<Dim - 1, 0>();
92 return binomialCoeff<Dim, Degree>() + getNParametersInteractionOnly<
Degree - 1, Dim>();
100 return binomialCoeff(dim - 1, 0);
102 return binomialCoeff(dim, degree) + getNParametersInteractionOnly(degree - 1, dim);
106 template <u
int32_t Degree, u
int32_t Dim,
bool InteractionOnly>
109 if constexpr (InteractionOnly) {
110 return getNParametersInteractionOnly<Degree, Dim>();
112 return getNParametersAllTerms<Degree, Dim>();
118 if (interactionOnly) {
119 return getNParametersInteractionOnly(degree, dim);
121 return getNParametersAllTerms(degree, dim);
128 template <u
int32_t N>
131 if constexpr (N == 0 || N == 1) {
134 return N * factorial<N - 1>();
144 template <u
int32_t N, u
int32_t K>
147 return factorial<N>() / (factorial<K>() * factorial<N - K>());
154 return factorial(
n) / (factorial(k) * factorial(
n - k));
163template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
166 static GPUglobalconstexpr()
uint16_t FMaxdim = 10;
167 static GPUglobalconstexpr()
uint16_t FMaxdegree = 9;
169#if !defined(GPUCA_GPUCODE)
170 static_assert(Dim <= MultivariatePolynomialHelper<Dim, Degree, InteractionOnly>::FMaxdim && Degree <= MultivariatePolynomialHelper<Dim, Degree, InteractionOnly>::FMaxdegree,
"Max. number of dimensions or degrees exceeded!");
177 GPUd() static constexpr
float evalPol(
GPUgeneric() const
float par[], const
float x[])
179 return par[0] + loopDegrees<1>(par,
x);
189 GPUd() static constexpr
bool isInteractionOnly() {
return InteractionOnly; }
195 template <u
int32_t N>
198 if constexpr (N == 0) {
201 return 10 * pow10<N - 1>();
208 template <u
int32_t A, u
int32_t B>
224 GPUd() static constexpr
float prodTerm(const
float x[]);
228 static constexpr
bool checkInteraction();
235 GPUd() static constexpr
float sumTerms(
GPUgeneric() const
float par[], const
float x[]);
242 GPUd() static constexpr
float loopDegrees(
GPUgeneric() const
float par[], const
float x[]);
245#if !defined(GPUCA_GPUCODE)
284 static std::vector<float>
fit(TLinearFitter& fitter, std::vector<double>&
x, std::vector<double>&
y, std::vector<double>&
error,
const bool clearPoints);
292 std::vector<float>
fit(std::vector<double>&
x, std::vector<double>&
y, std::vector<double>&
error,
const bool clearPoints)
const;
297 float evalPol(
const float par[],
const float x[])
const
299 return evalPol(par,
x, mDegree, mDim, mInteractionOnly);
317 bool mInteractionOnly{};
320 static constexpr uint16_t FMaxdegree = 9;
323 template <
class Type>
324 Type combination_with_repetiton(
const uint32_t degree,
const uint32_t dim,
const float par[],
int32_t& indexPar,
const float x[],
const bool interactionOnly)
const;
332template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
335 if (iter <= degreePol) {
336 const int32_t powTmp = pow10(leftDigit);
337 const int32_t rightDigit = mod10(
pos, powTmp);
338 const int32_t posTmp =
pos - (rightDigit - refDigit) * powTmp;
339 return resetIndices(degreePol, posTmp, leftDigit - 1, iter + 1, refDigit);
344template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
345template <u
int32_t DegreePol, u
int32_t Pos, u
int32_t DigitPos>
346GPUd() constexpr
uint32_t MultivariatePolynomialHelper<Dim,
Degree, InteractionOnly>::getNewPos()
348 if constexpr (DegreePol > DigitPos) {
350 if constexpr (mod10<Pos, pow10<DigitPos>()>() == Dim) {
352 constexpr uint32_t LeftDigit = DigitPos + 1;
353 constexpr uint32_t PowLeftDigit = pow10<LeftDigit>();
354 constexpr uint32_t PosTmp = Pos + PowLeftDigit;
355 constexpr uint32_t RefDigit = mod10<PosTmp, PowLeftDigit>();
358 constexpr uint32_t PosReset = resetIndices(DegreePol, PosTmp, LeftDigit - 1, DegreePol - DigitPos, RefDigit);
361 return getNewPos<DegreePol, PosReset, DigitPos + 1>();
363 return getNewPos<DegreePol, Pos, DigitPos + 1>();
370template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
371template <u
int32_t DegreePol, u
int32_t Pos>
374 if constexpr (DegreePol > 0) {
377 return x[
index] * prodTerm<DegreePol - 1, Pos>(
x);
382template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
383template <u
int32_t DegreePol, u
int32_t posNew>
384constexpr bool MultivariatePolynomialHelper<Dim, Degree, InteractionOnly>::checkInteraction()
386 if constexpr (DegreePol > 1) {
387 constexpr bool isInteraction = mod10<posNew, pow10<DegreePol - 1>()>() == mod10<posNew, pow10<DegreePol - 2>()>();
388 if constexpr (isInteraction) {
391 return checkInteraction<DegreePol - 1, posNew>();
396template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
397template <u
int32_t DegreePol, u
int32_t Pos, u
int32_t Index>
398GPUd() constexpr
float MultivariatePolynomialHelper<Dim,
Degree, InteractionOnly>::sumTerms(
GPUgeneric() const
float par[], const
float x[])
401 constexpr uint32_t PosNew = getNewPos<DegreePol, Pos, 0>();
402 if constexpr (mod10<PosNew, pow10<DegreePol>()>() != 1) {
405 if constexpr (InteractionOnly && checkInteraction<DegreePol, PosNew>()) {
406 return sumTerms<DegreePol, PosNew + 1, Index>(par,
x);
409 return par[Index] * prodTerm<DegreePol, PosNew>(
x) + sumTerms<DegreePol, PosNew + 1, Index + 1>(par,
x);
415template <u
int32_t Dim, u
int32_t Degree,
bool InteractionOnly>
416template <u
int32_t DegreePol>
419 if constexpr (DegreePol <=
Degree) {
420 constexpr uint32_t index{getNParameters<DegreePol - 1, Dim, InteractionOnly>()};
421 return sumTerms<DegreePol, 0, index>(par,
x) + loopDegrees<DegreePol + 1>(par,
x);
unsigned short int uint16_t
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions false
configStandalone Reconstruction rec_tpc multiplier for the combined cluster track error during track following area in cm for the search of for z only used if decrease removal by when above this local occupancy rowx Shift of TPC revert cluster flag edge bit distance to edge exceeds this ZOffset for secondary multiple of radius max P of electron K BB bands crossing max P of electron p BB bands crossing max P of electron d BB bands crossing max P of electron t BB bands crossing min accepted dEdxMaxTPC of the track Additive extra cluster error for Y2 if edge flag set Additive extra cluster error for Y2 if single set Additive extra cluster error for Y2 if or single set Additive extra cluster error for Z2 if or single set Extra errors to add to track when crossing depending on addErrorsCECrossing Inner portion of y range in sector that is not used in searching for extrapolated track candidates factor2YS for track merging factor2K for track merging Margin in cm of Y position when rejecting edge clusters based on uncorrected track Y Max fraction of shared clusters for tracklet Except pad from cluster finding if total number of charges in a fragment is above this Except pad from cluster finding if number of consecutive charges in a fragment is above this Threshold where a timebin is considered disabling the noisy pad check for that pad Treat signal above this minimum as saturated Smoothing factor for the exponential Highly Ionising Particle tail filter Number of timebins to use for the averaging Add additional custom track errors when crossing relative as fraction of Do N fit passes in final fit of< 0:reject at max -n hits") AddOptionRTC(rejectIFCLowRadiusCluster, uint8_t, 1, "", 0, "Reject clusters that get the IFC mask error during refit") AddOptionRTC(dEdxTruncLow, uint8_t, 2, "", 0, "Low truncation threshold, fraction of 128") AddOptionRTC(dEdxTruncHigh, uint8_t, 77, "", 0, "High truncation threshold, fraction of 128") AddOptionRTC(extrapolationTracking, int8_t, 1, "", 0, "Enable Extrapolation Tracking(prolong tracks to adjacent sectors to find short segments)") AddOptionRTC(disableRefitAttachment, uint8_t, 0, "", 0, "Bitmask to disable certain attachment steps during refit(1:attachment, 2:propagation, 4:loop following, 8:mirroring)") AddOptionRTC(rejectionStrategy, uint8_t, o2::gpu::GPUSettings::RejectionStrategyA, "", 0, "Enable rejection of TPC clusters for compression(0=no, 1=strategy A, 2=strategy B)") AddOptionRTC(mergeLoopersAfterburner, uint8_t, 1, "", 0, "Run afterburner for additional looper merging") AddOptionRTC(compressionTypeMask, uint8_t, o2::gpu::GPUSettings::CompressionFull, "", 0, "TPC Compression mode bits(1=truncate charge/width LSB, 2=differences, 4=track-model)") AddOptionRTC(compressionSortOrder, uint8_t, o2::gpu::GPUSettings::SortTime, "", 0, "Sort order of TPC compression(0=time, 1=pad, 2=Z-time-pad, 3=Z-pad-time, 4=no sorting(use incoming order))") AddOptionRTC(sigBitsCharge, uint8_t, 4, "", 0, "Number of significant bits for TPC cluster charge in compression mode 1") AddOptionRTC(sigBitsWidth, uint8_t, 3, "", 0, "Number of significant bits for TPC cluster width in compression mode 1") AddOptionRTC(dropLoopers, uint8_t, 0, "", 0, "Drop looping tracks starting from second loop") AddOptionRTC(mergerInterpolateErrors, uint8_t, 1, "", 0, "Use interpolation instead of extrapolation for chi2 based cluster rejection") AddOptionRTC(mergerInterpolateRejectAlsoOnCurrentPosition, uint8_t, 1, "", 0, "When using mergerInterpolateErrors, reject based on chi2 twice computed with interpolated and current track position starting from NDF > mergerNonInterpolateRejectMinNDF Merge tracks accross the central electrode Enable PID response Add sub threshold clusters in TPC dEdx computation OR mask of TPC flags that will reject the cluster in alternative dEdx Reject edge clusters based on uncorrected track Y during track fit Increase decrease removal by when on this number of pads from the edge h configStandalone Reconstruction rec_trd Max chi2 for TRD tracklets to be matched to a track Chi2 cut for strict matching mode Number of sigmas for ITS TPC track time error estimate Addition to search road around track prolongation along Y in cm Optimal tracklet rphi resolution in maximum chi2 per attached tracklet for TRD tracks take into account the full likelihood of the slope including exponential tails Tracks with less attached tracklets are discarded after the tracking Post trigger Pile up integration time in BCs fits all iterations but the last one in projections Use material lookup table for TPC refit Apply workarounds to avoid cyclic merge should not be needed tpc dyn configStandalone Processing proc_rtc Replace constant variables static by constexpr expressions Compile RTC in deterministic with NO_FAST_MATH flags and GPUCA_DETERMINISTIC_MODE define Use RTC to optimize GPU code h configStandalone Processing proc_rtctech Use a file lock to serialize access to the cache folder int32_t
char error[CURL_ERROR_SIZE]
uint32_t getDegree() const
TLinearFitter getTLinearFitter() const
std::string getFormula() const
MultivariatePolynomialHelper(const uint32_t nDim, const uint32_t degree, const bool interactionOnly)
MultivariatePolynomialHelper()=default
default constructor
static std::vector< float > fit(TLinearFitter &fitter, std::vector< double > &x, std::vector< double > &y, std::vector< double > &error, const bool clearPoints)
std::vector< std::string > getTerms() const
std::vector< float > fit(std::vector< double > &x, std::vector< double > &y, std::vector< double > &error, const bool clearPoints) const
~MultivariatePolynomialHelper()=default
Destructor.
float evalPol(const float par[], const float x[], const uint32_t degree, const uint32_t dim, const bool interactionOnly) const
evalutes the polynomial
std::string getTLinearFitterFormula() const
float evalPol(const float par[], const float x[]) const
void print() const
printing the formula of the polynomial
bool isInteractionOnly() const
GPUd() static const expr uint32_t getDegree()
GPUd() static const expr float evalPol(GPUgeneric() const float par[]
GPUd() static const expr uint32_t getDim()
GPUd() static const expr bool isInteractionOnly()
Helper class for calculating the number of parameters for a multidimensional polynomial.
GPUd() static const expr uint32_t getNParametersAllTerms(uint32_t degree
GPUd() static const expr uint32_t getNParametersAllTerms()
GLboolean GLboolean GLboolean b
GLenum const GLfloat * params
GLboolean GLboolean GLboolean GLboolean a
o2::track::TrackParametrization< float > par
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
MultivariatePolynomialContainer()=default
for ROOT I/O
const bool mInteractionOnly
consider only interaction terms
MultivariatePolynomialContainer(const uint32_t dim, const uint32_t degree, const uint32_t nParameters, const float params[], const bool interactionOnly)
const std::vector< float > mParams
parameters of the polynomial