Project
Loading...
Searching...
No Matches
MultivariatePolynomial.h
Go to the documentation of this file.
1// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
2// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
3// All rights not expressly granted are reserved.
4//
5// This software is distributed under the terms of the GNU General Public
6// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
7//
8// In applying this license CERN does not waive the privileges and immunities
9// granted to it by virtue of its status as an Intergovernmental Organization
10// or submit itself to any jurisdiction.
11
14
15#ifndef ALICEO2_TPC_MULTIVARIATEPOLYNOMIAL
16#define ALICEO2_TPC_MULTIVARIATEPOLYNOMIAL
17
18#include "GPUCommonDef.h"
19#include "GPUCommonLogger.h"
20#include "FlatObject.h"
22
23#if !defined(GPUCA_GPUCODE)
24#include <algorithm>
25#include <type_traits>
26#if !defined(GPUCA_STANDALONE)
27#include <TFile.h>
28#endif
29#endif
30
31namespace o2::gpu
32{
33
43template <uint32_t Dim, uint32_t Degree, bool InteractionOnly = false>
44class MultivariatePolynomial : public FlatObject, public MultivariatePolynomialHelper<Dim, Degree, InteractionOnly>
45{
46 public:
47#if !defined(GPUCA_GPUCODE)
51 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (Dim == 0 && Degree == 0)), int32_t>::type = 0>
52 MultivariatePolynomial(const uint32_t nDim, const uint32_t degree, const bool interactionOnly = false) : MultivariatePolynomialHelper<Dim, Degree, false>{nDim, degree, interactionOnly}, mNParams{this->getNParameters(degree, nDim, interactionOnly)}
53 {
54 construct();
55 }
56
58 template <bool IsEnabled = true, typename std::enable_if<(IsEnabled && (Dim != 0 && Degree != 0)), int32_t>::type = 0>
59 MultivariatePolynomial() : mNParams{this->template getNParameters<Degree, Dim, InteractionOnly>()}
60 {
61 construct();
62 }
63#else
65 MultivariatePolynomial() = default;
66#endif
67
70
73
75#if !defined(GPUCA_GPUCODE)
77 void cloneFromObject(const MultivariatePolynomial& obj, char* newFlatBufferPtr);
78
81 void moveBufferTo(char* newBufferPtr);
82#endif
83
85 void destroy();
86
88 void setActualBufferAddress(char* actualFlatBufferPtr);
89
91 void setFutureBufferAddress(char* futureFlatBufferPtr);
93
96 GPUd() float eval(const float x[/*Dim*/]) const { return this->evalPol(mParams, x); }
97
98#if !defined(GPUCA_GPUCODE)
100 uint32_t getNParams() const { return mNParams; }
101
104 void setParams(const float params[/*mNParams*/]) { std::copy(params, params + mNParams, mParams); }
105
108 void setParam(const uint32_t param, const float val) { mParams[param] = val; };
109
111 const float* getParams() const { return mParams; }
112
113#ifndef GPUCA_STANDALONE
117 void loadFromFile(TFile& inpf, const char* name);
118
122 void writeToFile(TFile& outf, const char* name) const;
123
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)
131 {
133 if (vec.empty()) {
134 return;
135 }
136 setParams(vec.data());
137 }
138#endif
139
141 MultivariatePolynomialContainer getContainer() const { return MultivariatePolynomialContainer{this->getDim(), this->getDegree(), mNParams, mParams, this->isInteractionOnly()}; }
142
146#endif
147
148 private:
149 using DataTParams = float;
150 uint32_t mNParams{};
151 DataTParams* mParams{nullptr};
152
153#if !defined(GPUCA_GPUCODE)
155 std::size_t sizeOfParameters() const { return mNParams * sizeof(DataTParams); }
156
157 // construct the object (flatbuffer)
158 void construct();
159#endif
160
161 ClassDefNV(MultivariatePolynomial, 1);
162};
163
164//=================================================================================
165//============================ inline implementations =============================
166//=================================================================================
167
168#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
169template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
171{
172 MultivariatePolynomialContainer* polTmp = nullptr;
173 inpf.GetObject(name, polTmp);
174 if (polTmp) {
175 setFromContainer(*polTmp);
176 delete polTmp;
177 } else {
178 LOGP(info, "couldnt load object {} from input file", name);
179 }
180}
181
182template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
184{
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);
188 return;
189 }
190 if (this->getDegree() != container.mDegree) {
191 LOGP(info, "wrong number of degrees! this {} container {}", this->getDegree(), container.mDegree);
192 return;
193 }
194 if (this->isInteractionOnly() != container.mInteractionOnly) {
195 LOGP(info, "InteractionOnly is set for this object to {}, but stored as {} in the container", this->isInteractionOnly(), container.mInteractionOnly);
196 return;
197 }
198 setParams(container.mParams.data());
199 } else {
200 MultivariatePolynomial polTmp(container.mDim, container.mDegree);
201 polTmp.setParams(container.mParams.data());
202 this->cloneFromObject(polTmp, nullptr);
203 }
204}
205
206template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
208{
209 const MultivariatePolynomialContainer cont = getContainer();
210 outf.WriteObject(&cont, name);
211}
212#endif
213
214#ifndef GPUCA_GPUCODE
215template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
217{
218 const char* oldFlatBufferPtr = obj.mFlatBufferPtr;
219 FlatObject::cloneFromObject(obj, newFlatBufferPtr);
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;
225 }
226 if (obj.mParams) {
227 mParams = FlatObject::relocatePointer(oldFlatBufferPtr, mFlatBufferPtr, obj.mParams);
228 }
229}
230
231template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
233{
234 char* oldFlatBufferPtr = mFlatBufferPtr;
235 FlatObject::moveBufferTo(newFlatBufferPtr);
236 char* currFlatBufferPtr = mFlatBufferPtr;
237 mFlatBufferPtr = oldFlatBufferPtr;
238 setActualBufferAddress(currFlatBufferPtr);
239}
240
241template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
243{
245 const std::size_t flatbufferSize = sizeOfParameters();
246 FlatObject::finishConstruction(flatbufferSize);
247 mParams = reinterpret_cast<float*>(mFlatBufferPtr);
248}
249#endif
250
251template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
257
258template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
260{
261 FlatObject::setActualBufferAddress(actualFlatBufferPtr);
262 mParams = reinterpret_cast<float*>(mFlatBufferPtr);
263}
264
265template <uint32_t Dim, uint32_t Degree, bool InteractionOnly>
267{
268 mParams = FlatObject::relocatePointer(mFlatBufferPtr, futureFlatBufferPtr, mParams);
269 FlatObject::setFutureBufferAddress(futureFlatBufferPtr);
270}
271
272} // namespace o2::gpu
273
274#endif
Definition of FlatObject class.
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 float
char error[CURL_ERROR_SIZE]
void setFutureBufferAddress(char *futureFlatBufferPtr)
Definition FlatObject.h:569
void destroy()
_______________ Utilities _______________________________________________
Definition FlatObject.h:361
static T * relocatePointer(const char *oldBase, char *newBase, const T *ptr)
Relocates a pointer inside a buffer to the new buffer address.
Definition FlatObject.h:283
void setActualBufferAddress(char *actualFlatBufferPtr)
_____________ Methods for moving the class with its external buffer to another location _____________...
Definition FlatObject.h:559
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:354
void moveBufferTo(char *newBufferPtr)
Definition FlatObject.h:408
void finishConstruction(int32_t flatBufferSize)
Definition FlatObject.h:370
void cloneFromObject(const FlatObject &obj, char *newFlatBufferPtr)
Definition FlatObject.h:385
~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 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
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.
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)
GLint GLenum GLint x
Definition glcorearb.h:403
GLuint const GLchar * name
Definition glcorearb.h:781
GLint y
Definition glcorearb.h:270
GLenum const GLfloat * params
Definition glcorearb.h:272
GLuint GLfloat * val
Definition glcorearb.h:1582
GLenum GLfloat param
Definition glcorearb.h:271
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