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 <cmath> // for std::fma
22#include <algorithm>
23#include <vector>
24#include "Rtypes.h" // for Float_t, UShort_t, Int_t, Double_t, etc
25
26class TString;
27
28// To decrease the compilable code size comment this define. This will exclude the routines
29// used for the calculation and saving of the coefficients.
30#define _INC_CREATION_Chebyshev3D_
31
32// When _BRING_TO_BOUNDARY_ is defined, the point outside of the fitted folume is assumed to be on the surface
33// #define _BRING_TO_BOUNDARY_
34
35namespace o2
36{
37namespace math_utils
38{
39class Chebyshev3DCalc : public TNamed
40{
41
42 public:
45
48
51
54 {
55 Clear();
56 }
57
60
62 void Print(const Option_t* opt = "") const override;
63
65 void loadData(FILE* stream);
66
69 Float_t evaluateDerivative(int dim, const Float_t* par) const;
70
73 Float_t evaluateDerivative2(int dim1, int dim2, const Float_t* par) const;
74
75#ifdef _INC_CREATION_Chebyshev3D_
76
78 void saveData(const char* outfile, Bool_t append = kFALSE) const;
79
80 // Writes coefficients data to existing output stream
81 // Note: mNumberOfColumns, mNumberOfElementsBound2D and mColumnAtRowBeginning are not stored, will be computed on fly
82 // during the loading of this file
83 void saveData(FILE* stream = stdout) const;
84
85#endif
86
88 void initializeRows(int nr);
89
91 void initializeColumns(int nc);
92
94 {
95 return mNumberOfCoefficients;
96 }
97
98 Int_t getNumberOfColumns() const
99 {
100 return (Int_t)mNumberOfColumns;
101 }
102
103 Int_t getNumberOfRows() const
104 {
105 return (Int_t)mNumberOfRows;
106 }
107
109 {
110 return (Int_t)mNumberOfElementsBound2D;
111 }
112
113 Int_t getMaxColumnsAtRow() const;
114
115 UShort_t* getNumberOfColumnsAtRow() const
116 {
117 return mNumberOfColumnsAtRow;
118 }
119
120 UShort_t* getColAtRowBg() const
121 {
122 return mColumnAtRowBeginning;
123 }
124
126 {
127 return mPrecision;
128 }
129
131 void setPrecision(Float_t prc = 1e-6)
132 {
133 mPrecision = prc;
134 }
135
137 void initializeElementBound2D(int ne);
138
139 UShort_t* getCoefficientBound2D0() const
140 {
141 return mCoefficientBound2D0;
142 }
143
144 UShort_t* getCoefficientBound2D1() const
145 {
146 return mCoefficientBound2D1;
147 }
148
150 void Clear(const Option_t* option = "") override;
151
152 static Float_t chebyshevEvaluation1D(Float_t x, const Float_t* array, int ncf);
153
156
159
161 void initializeCoefficients(int nc);
162
164 {
165 return mCoefficients;
166 }
167
169 static void readLine(TString& str, FILE* stream);
170
171 Float_t Eval(const Float_t* par) const;
172
173 Double_t Eval(const Double_t* par) const;
174
175 private:
178 class EvalScratch
179 {
180 public:
181 EvalScratch(int nrows, int ncols)
182 {
183 if (nrows <= kStackSize && ncols <= kStackSize) {
184 mRows = mStackRows;
185 mCols = mStackCols;
186 } else {
187 thread_local std::vector<Float_t> rows, cols;
188 rows.resize(std::max<size_t>(nrows, rows.size()));
189 cols.resize(std::max<size_t>(ncols, cols.size()));
190 mRows = rows.data();
191 mCols = cols.data();
192 }
193 }
194 EvalScratch(const EvalScratch&) = delete;
195 EvalScratch& operator=(const EvalScratch&) = delete;
196 Float_t* rows() { return mRows; }
197 Float_t* cols() { return mCols; }
198
199 private:
200 static constexpr int kStackSize = 64;
201 Float_t mStackRows[kStackSize];
202 Float_t mStackCols[kStackSize];
203 Float_t* mRows;
204 Float_t* mCols;
205 };
206
207 Int_t mNumberOfCoefficients;
208 Int_t mNumberOfRows;
209 Int_t mNumberOfColumns;
210 Int_t mNumberOfElementsBound2D;
211 Float_t mPrecision;
213 UShort_t*
214 mNumberOfColumnsAtRow; //[mNumberOfRows] number of sighificant columns (2nd dim) at each row of 3D coefs matrix
215 UShort_t* mColumnAtRowBeginning; //[mNumberOfRows] beginning of significant columns (2nd dim) for row in the 2D
216 // boundary matrix
217 UShort_t* mCoefficientBound2D0; //[mNumberOfElementsBound2D] 2D matrix defining the boundary of significance for 3D
218 // coeffs.matrix
219 //(Ncoefs for col/row)
220 UShort_t* mCoefficientBound2D1; //[mNumberOfElementsBound2D] 2D matrix defining the start beginning of significant
221 // coeffs for col/row
222 Float_t* mCoefficients; //[mNumberOfCoefficients] array of Chebyshev coefficients
223
224 Float_t* mTemporaryCoefficients2D; //[mNumberOfColumns] no longer used for evaluation
225 Float_t* mTemporaryCoefficients1D; //[mNumberOfRows] no longer used for evaluation
226
227 ClassDefOverride(o2::math_utils::Chebyshev3DCalc,
228 2) // Class for interpolation of 3D->1 function by Chebyshev parametrization
229};
230
233{
234 if (ncf <= 0) {
235 return 0;
236 }
237
238 Float_t b0, b1, b2, x2 = x + x;
239 b0 = array[--ncf];
240 b1 = b2 = 0;
241
242 for (int i = ncf; i--;) {
243 b2 = b1;
244 b1 = b0;
245 // Clenshaw recurrence, grouped as fma(x2, b1, array[i] - b2). Mathematically
246 // identical to `array[i] + x2 * b1 - b2`, but `array[i] - b2` does not depend
247 // on the just-updated b1, so the loop-carried chain collapses to a single FMA
248 // latency instead of a dependent multiply+add+subtract. This kernel dominates
249 // magnetic-field evaluation in (e.g.) muon track extrapolation.
250 b0 = std::fma(x2, b1, array[i] - b2);
251 }
252 return std::fma(-x, b1, b0);
253}
254
257inline Float_t Chebyshev3DCalc::Eval(const Float_t* par) const
258{
259 EvalScratch scratch(mNumberOfRows, mNumberOfColumns);
260 Float_t* coefs2D = scratch.cols();
261 Float_t* coefs1D = scratch.rows();
262 for (int id0 = mNumberOfRows; id0--;) {
263 int nCLoc = mNumberOfColumnsAtRow[id0]; // number of significant coefs on this row
264 int col0 = mColumnAtRowBeginning[id0]; // beginning of local column in the 2D boundary matrix
265 for (int id1 = nCLoc; id1--;) {
266 int id = id1 + col0;
267 coefs2D[id1] = chebyshevEvaluation1D(par[2], mCoefficients + mCoefficientBound2D1[id], mCoefficientBound2D0[id]);
268 }
269 coefs1D[id0] = chebyshevEvaluation1D(par[1], coefs2D, nCLoc);
270 }
271 return chebyshevEvaluation1D(par[0], coefs1D, mNumberOfRows);
272}
273
276inline Double_t Chebyshev3DCalc::Eval(const Double_t* par) const
277{
278 EvalScratch scratch(mNumberOfRows, mNumberOfColumns);
279 Float_t* coefs2D = scratch.cols();
280 Float_t* coefs1D = scratch.rows();
281 for (int id0 = mNumberOfRows; id0--;) {
282 int nCLoc = mNumberOfColumnsAtRow[id0]; // number of significant coefs on this row
283 int col0 = mColumnAtRowBeginning[id0]; // beginning of local column in the 2D boundary matrix
284 for (int id1 = nCLoc; id1--;) {
285 int id = id1 + col0;
286 coefs2D[id1] = chebyshevEvaluation1D(par[2], mCoefficients + mCoefficientBound2D1[id], mCoefficientBound2D0[id]);
287 }
288 coefs1D[id0] = chebyshevEvaluation1D(par[1], coefs2D, nCLoc);
289 }
290 return chebyshevEvaluation1D(par[0], coefs1D, mNumberOfRows);
291}
292} // namespace math_utils
293} // namespace o2
294
295#endif
int32_t i
Timeframe settings Average distance in cm of events merged into Randomize distance around average distance of merged events Simulate correct bunch interactions instead of placing only the average number of events A value[n] sets TFlen for[n] collisions in Number of bunches per trainsort Number of bunch trains Instantaneous interaction rate Do not simulate border Total number of collisions to be placed in the interior of all time Do not select random but walk over array of events in stride steps h Event generator settings h configStandalone Use CPU for GPU Force usage of the specified GPU device no CPU fallback Continue processing after an error First event to Number of events to Number of iterations to Number of iterations to Number of initial iterations excluded from const char e
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 Print launch bounds used for RTC code as debugging option
uint32_t cols
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
GLuint GLuint stream
Definition glcorearb.h:1806
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
std::vector< ReadoutWindowData > rows
const std::string str