Project
Loading...
Searching...
No Matches
Chebyshev3DCalc.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
15
16#ifndef ALICEO2_MATHUTILS_CHEBYSHEV3DCALC_H_
17#define ALICEO2_MATHUTILS_CHEBYSHEV3DCALC_H_
18
19#include <TNamed.h> // for TNamed
20#include <cstdio> // for FILE, stdout
21#include "Rtypes.h" // for Float_t, UShort_t, Int_t, Double_t, etc
22
23class TString;
24
25// To decrease the compilable code size comment this define. This will exclude the routines
26// used for the calculation and saving of the coefficients.
27#define _INC_CREATION_Chebyshev3D_
28
29// When _BRING_TO_BOUNDARY_ is defined, the point outside of the fitted folume is assumed to be on the surface
30// #define _BRING_TO_BOUNDARY_
31
32namespace o2
33{
34namespace math_utils
35{
36class Chebyshev3DCalc : public TNamed
37{
38
39 public:
42
45
48
51 {
52 Clear();
53 }
54
57
59 void Print(const Option_t* opt = "") const override;
60
62 void loadData(FILE* stream);
63
66 Float_t evaluateDerivative(int dim, const Float_t* par) const;
67
70 Float_t evaluateDerivative2(int dim1, int dim2, const Float_t* par) const;
71
72#ifdef _INC_CREATION_Chebyshev3D_
73
75 void saveData(const char* outfile, Bool_t append = kFALSE) const;
76
77 // Writes coefficients data to existing output stream
78 // Note: mNumberOfColumns, mNumberOfElementsBound2D and mColumnAtRowBeginning are not stored, will be computed on fly
79 // during the loading of this file
80 void saveData(FILE* stream = stdout) const;
81
82#endif
83
85 void initializeRows(int nr);
86
88 void initializeColumns(int nc);
89
91 {
92 return mNumberOfCoefficients;
93 }
94
95 Int_t getNumberOfColumns() const
96 {
97 return (Int_t)mNumberOfColumns;
98 }
99
100 Int_t getNumberOfRows() const
101 {
102 return (Int_t)mNumberOfRows;
103 }
104
106 {
107 return (Int_t)mNumberOfElementsBound2D;
108 }
109
110 Int_t getMaxColumnsAtRow() const;
111
112 UShort_t* getNumberOfColumnsAtRow() const
113 {
114 return mNumberOfColumnsAtRow;
115 }
116
117 UShort_t* getColAtRowBg() const
118 {
119 return mColumnAtRowBeginning;
120 }
121
123 {
124 return mPrecision;
125 }
126
128 void setPrecision(Float_t prc = 1e-6)
129 {
130 mPrecision = prc;
131 }
132
134 void initializeElementBound2D(int ne);
135
136 UShort_t* getCoefficientBound2D0() const
137 {
138 return mCoefficientBound2D0;
139 }
140
141 UShort_t* getCoefficientBound2D1() const
142 {
143 return mCoefficientBound2D1;
144 }
145
147 void Clear(const Option_t* option = "") override;
148
149 static Float_t chebyshevEvaluation1D(Float_t x, const Float_t* array, int ncf);
150
153
156
158 void initializeCoefficients(int nc);
159
161 {
162 return mCoefficients;
163 }
164
166 static void readLine(TString& str, FILE* stream);
167
168 Float_t Eval(const Float_t* par) const;
169
170 Double_t Eval(const Double_t* par) const;
171
172 private:
173 Int_t mNumberOfCoefficients;
174 Int_t mNumberOfRows;
175 Int_t mNumberOfColumns;
176 Int_t mNumberOfElementsBound2D;
177 Float_t mPrecision;
179 UShort_t*
180 mNumberOfColumnsAtRow; //[mNumberOfRows] number of sighificant columns (2nd dim) at each row of 3D coefs matrix
181 UShort_t* mColumnAtRowBeginning; //[mNumberOfRows] beginning of significant columns (2nd dim) for row in the 2D
182 // boundary matrix
183 UShort_t* mCoefficientBound2D0; //[mNumberOfElementsBound2D] 2D matrix defining the boundary of significance for 3D
184 // coeffs.matrix
185 //(Ncoefs for col/row)
186 UShort_t* mCoefficientBound2D1; //[mNumberOfElementsBound2D] 2D matrix defining the start beginning of significant
187 // coeffs for col/row
188 Float_t* mCoefficients; //[mNumberOfCoefficients] array of Chebyshev coefficients
189
190 Float_t* mTemporaryCoefficients2D; //[mNumberOfColumns] temp. coeffs for 2d summation
191 Float_t* mTemporaryCoefficients1D; //[mNumberOfRows] temp. coeffs for 1d summation
192
193 ClassDefOverride(o2::math_utils::Chebyshev3DCalc,
194 2) // Class for interpolation of 3D->1 function by Chebyshev parametrization
195};
196
199{
200 if (ncf <= 0) {
201 return 0;
202 }
203
204 Float_t b0, b1, b2, x2 = x + x;
205 b0 = array[--ncf];
206 b1 = b2 = 0;
207
208 for (int i = ncf; i--;) {
209 b2 = b1;
210 b1 = b0;
211 b0 = array[i] + x2 * b1 - b2;
212 }
213 return b0 - x * b1;
214}
215
218inline Float_t Chebyshev3DCalc::Eval(const Float_t* par) const
219{
220 for (int id0 = mNumberOfRows; id0--;) {
221 int nCLoc = mNumberOfColumnsAtRow[id0]; // number of significant coefs on this row
222 int col0 = mColumnAtRowBeginning[id0]; // beginning of local column in the 2D boundary matrix
223 for (int id1 = nCLoc; id1--;) {
224 int id = id1 + col0;
225 mTemporaryCoefficients2D[id1] = chebyshevEvaluation1D(par[2], mCoefficients + mCoefficientBound2D1[id], mCoefficientBound2D0[id]);
226 }
227 mTemporaryCoefficients1D[id0] = chebyshevEvaluation1D(par[1], mTemporaryCoefficients2D, nCLoc);
228 }
229 return chebyshevEvaluation1D(par[0], mTemporaryCoefficients1D, mNumberOfRows);
230}
231
234inline Double_t Chebyshev3DCalc::Eval(const Double_t* par) const
235{
236 for (int id0 = mNumberOfRows; id0--;) {
237 int nCLoc = mNumberOfColumnsAtRow[id0]; // number of significant coefs on this row
238 int col0 = mColumnAtRowBeginning[id0]; // beginning of local column in the 2D boundary matrix
239 for (int id1 = nCLoc; id1--;) {
240 int id = id1 + col0;
241 mTemporaryCoefficients2D[id1] = chebyshevEvaluation1D(par[2], mCoefficients + mCoefficientBound2D1[id], mCoefficientBound2D0[id]);
242 }
243 mTemporaryCoefficients1D[id0] = chebyshevEvaluation1D(par[1], mTemporaryCoefficients2D, nCLoc);
244 }
245 return chebyshevEvaluation1D(par[0], mTemporaryCoefficients1D, mNumberOfRows);
246}
247} // namespace math_utils
248} // namespace o2
249
250#endif
int32_t i
const GPUTPCGMMerger::trackCluster & b1
Float_t Eval(const Float_t *par) const
void Print(const Option_t *opt="") const override
Prints info.
static Float_t chebyshevEvaluation1Derivative2(Float_t x, const Float_t *array, int ncf)
Evaluates 1D Chebyshev parameterization's 2nd derivative. x is the argument mapped to [-1:1] interval...
void Clear(const Option_t *option="") override
Deletes all dynamically allocated structures.
UShort_t * getNumberOfColumnsAtRow() const
Chebyshev3DCalc & operator=(const Chebyshev3DCalc &rhs)
Assignment operator.
Float_t evaluateDerivative(int dim, const Float_t *par) const
void saveData(const char *outfile, Bool_t append=kFALSE) const
Writes coefficients data to output text file, optionally appending on the end of existing file.
static Float_t chebyshevEvaluation1D(Float_t x, const Float_t *array, int ncf)
Evaluates 1D Chebyshev parameterization. x is the argument mapped to [-1:1] interval.
void loadData(FILE *stream)
Loads coefficients from the stream.
UShort_t * getCoefficientBound2D0() const
void saveData(FILE *stream=stdout) const
Float_t evaluateDerivative2(int dim1, int dim2, const Float_t *par) const
static Float_t chebyshevEvaluation1Derivative(Float_t x, const Float_t *array, int ncf)
Evaluates 1D Chebyshev parameterization's derivative. x is the argument mapped to [-1:1] interval.
void initializeElementBound2D(int ne)
Sets maximum number of significant coefficients for given row/column of coefficients 3D matrix.
static void readLine(TString &str, FILE *stream)
Reads single line from the stream, skipping empty and commented lines. EOF is not expected.
~Chebyshev3DCalc() override
Default destructor.
void initializeRows(int nr)
Sets maximum number of significant rows in the coefficients matrix.
UShort_t * getCoefficientBound2D1() const
void initializeCoefficients(int nc)
Sets total number of significant coefficients.
Chebyshev3DCalc()
Default constructor.
void setPrecision(Float_t prc=1e-6)
Sets requested precision.
void initializeColumns(int nc)
Sets maximum number of significant columns in the coefficients matrix.
GLint GLenum GLint x
Definition glcorearb.h:403
GLenum src
Definition glcorearb.h:1767
GLenum array
Definition glcorearb.h:4274
GLuint GLuint stream
Definition glcorearb.h:1806
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
const std::string str