Project
Loading...
Searching...
No Matches
TPCFastSpaceChargeCorrection.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
16
17#ifndef ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_TPCFASTSPACECHARGECORRECTION_H
18#define ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_TPCFASTSPACECHARGECORRECTION_H
19
20#include "Spline2D.h"
21#include "TPCFastTransformGeo.h"
22#include "FlatObject.h"
23#include "GPUCommonDef.h"
24#include "GPUCommonMath.h"
25
26namespace o2
27{
28namespace gpu
29{
30
40{
41 public:
45 struct RowInfo {
46 int32_t splineScenarioID{0};
47 size_t dataOffsetBytes[3]{0};
49 };
50
52 float maxDriftLengthCheb[5]{0.f};
53 float vMax{0.f};
54 float cuMin{0.f};
55 float cuMax{0.f};
56 float cvMax{0.f};
58 };
59
69
70 struct SliceInfo {
71 float vMax{0.f};
73 };
74
76
78
81
84
87
90
92
94
97
99
100 void cloneFromObject(const TPCFastSpaceChargeCorrection& obj, char* newFlatBufferPtr);
101 void destroy();
102
104
106 void moveBufferTo(char* newBufferPtr);
107
109
110 void setActualBufferAddress(char* actualFlatBufferPtr);
111 void setFutureBufferAddress(char* futureFlatBufferPtr);
112
114
116 void startConstruction(const TPCFastTransformGeo& geo, int32_t numberOfSplineScenarios);
117
119 void setRowScenarioID(int32_t iRow, int32_t iScenario);
120
122 void setSplineScenario(int32_t scenarioIndex, const SplineType& spline);
123
125 void finishConstruction();
126
128
130
132 GPUd() void setNoCorrection();
133
135 GPUd() void setTimeStamp(int64_t v) { mTimeStamp = v; }
136
139 GPUd() void setInterpolationSafetyMargin(float val) { fInterpolationSafetyMargin = val; }
140
142 GPUd() const SplineType& getSpline(int32_t slice, int32_t row) const;
143
145 GPUd() SplineType& getSpline(int32_t slice, int32_t row);
146
148 GPUd() float* getSplineData(int32_t slice, int32_t row, int32_t iSpline = 0);
149
151 GPUd() const float* getSplineData(int32_t slice, int32_t row, int32_t iSpline = 0) const;
152
155 GPUd() int32_t getCorrection(int32_t slice, int32_t row, float u, float v, float& dx, float& du, float& dv) const;
156
158 GPUd() void getCorrectionInvCorrectedX(int32_t slice, int32_t row, float corrU, float corrV, float& corrX) const;
159
161 GPUd() void getCorrectionInvUV(int32_t slice, int32_t row, float corrU, float corrV, float& nomU, float& nomV) const;
162
164 GPUd() float getMaxDriftLength(int32_t slice, int32_t row, float pad) const;
165
167 GPUd() float getMaxDriftLength(int32_t slice, int32_t row) const;
168
170 GPUd() float getMaxDriftLength(int32_t slice) const;
171
173
175 GPUd() void schrinkUV(int32_t slice, int32_t row, float& u, float& v) const;
176
178 GPUd() void schrinkCorrectedUV(int32_t slice, int32_t row, float& corrU, float& corrV) const;
179
181 GPUd() void convUVtoGrid(int32_t slice, int32_t row, float u, float v, float& gridU, float& gridV) const;
182
184 GPUd() void convGridToUV(int32_t slice, int32_t row, float gridU, float gridV, float& u, float& v) const;
185
187 GPUd() void convCorrectedUVtoGrid(int32_t slice, int32_t row, float cu, float cv, float& gridU, float& gridV) const;
188
190 GPUd() const TPCFastTransformGeo& getGeometry() const
191 {
192 return mGeo;
193 }
194
196 int64_t getTimeStamp() const { return mTimeStamp; }
197
199 GPUd() float getInterpolationSafetyMargin() const { return fInterpolationSafetyMargin; }
200
202 GPUd() const RowInfo& getRowInfo(int32_t row) const { return mRowInfoPtr[row]; }
203
205 GPUd() const SliceInfo& getSliceInfo(int32_t slice) const
206 {
207 return mSliceInfo[slice];
208 }
209
211 GPUd() SliceInfo& getSliceInfo(int32_t slice)
212 {
213 return mSliceInfo[slice];
214 }
215
217 GPUd() const SliceRowInfo& getSliceRowInfo(int32_t slice, int32_t row) const
218 {
219 return mSliceRowInfoPtr[mGeo.getNumberOfRows() * slice + row];
220 }
221
223 GPUd() SliceRowInfo& getSliceRowInfo(int32_t slice, int32_t row)
224 {
225 return mSliceRowInfoPtr[mGeo.getNumberOfRows() * slice + row];
226 }
227
228#if !defined(GPUCA_GPUCODE)
230 void print() const;
231 GPUh() double testInverse(bool prn = 0);
232#endif
233
234 private:
236 void relocateBufferPointers(const char* oldBuffer, char* newBuffer);
238 void releaseConstructionMemory();
239
241 GPUd() int32_t getCorrectionOld(int32_t slice, int32_t row, float u, float v, float& dx, float& du, float& dv) const;
242
244
246
247 RowInfo* mConstructionRowInfos = nullptr;
248 SplineType* mConstructionScenarios = nullptr;
249
251
253
254 int32_t mNumberOfScenarios;
255
256 SliceInfo mSliceInfo[TPCFastTransformGeo::getNumberOfSlices()];
257
258 SplineType* mScenarioPtr;
259 RowInfo* mRowInfoPtr;
260 SliceRowInfo* mSliceRowInfoPtr;
261
263
264 int64_t mTimeStamp;
265
266 char* mSplineData[3];
267
268 size_t mSliceDataSizeBytes[3];
269
270 float fInterpolationSafetyMargin{0.1f}; // 10% area around the TPC row. Outside of this area the interpolation returns the boundary values.
271
272 ClassDefNV(TPCFastSpaceChargeCorrection, 3);
273};
274
278
279GPUdi() const TPCFastSpaceChargeCorrection::SplineType& TPCFastSpaceChargeCorrection::getSpline(int32_t slice, int32_t row) const
280{
282 const RowInfo& rowInfo = mRowInfoPtr[row];
283 return mScenarioPtr[rowInfo.splineScenarioID];
284}
285
286GPUdi() TPCFastSpaceChargeCorrection::SplineType& TPCFastSpaceChargeCorrection::getSpline(int32_t slice, int32_t row)
287{
289 const RowInfo& rowInfo = mRowInfoPtr[row];
290 return mScenarioPtr[rowInfo.splineScenarioID];
291}
292
293GPUdi() float* TPCFastSpaceChargeCorrection::getSplineData(int32_t slice, int32_t row, int32_t iSpline)
294{
296 const RowInfo& rowInfo = mRowInfoPtr[row];
297 return reinterpret_cast<float*>(mSplineData[iSpline] + mSliceDataSizeBytes[iSpline] * slice + rowInfo.dataOffsetBytes[iSpline]);
298}
299
300GPUdi() const float* TPCFastSpaceChargeCorrection::getSplineData(int32_t slice, int32_t row, int32_t iSpline) const
301{
303 const RowInfo& rowInfo = mRowInfoPtr[row];
304 return reinterpret_cast<float*>(mSplineData[iSpline] + mSliceDataSizeBytes[iSpline] * slice + rowInfo.dataOffsetBytes[iSpline]);
305}
306
307GPUdi() void TPCFastSpaceChargeCorrection::schrinkUV(int32_t slice, int32_t row, float& u, float& v) const
308{
310
311 const TPCFastTransformGeo::RowInfo& rowInfo = mGeo.getRowInfo(row);
312
313 float uWidth05 = rowInfo.getUwidth() * (0.5f + fInterpolationSafetyMargin);
314 float vWidth = mGeo.getTPCzLength(slice);
315
316 if (u < -uWidth05) {
317 u = -uWidth05;
318 }
319 if (u > uWidth05) {
320 u = uWidth05;
321 }
322 if (v < -0.1f * vWidth) {
323 v = -0.1f * vWidth;
324 }
325 if (v > 1.1f * vWidth) {
326 v = 1.1f * vWidth;
327 }
328}
329
330GPUdi() void TPCFastSpaceChargeCorrection::schrinkCorrectedUV(int32_t slice, int32_t row, float& corrU, float& corrV) const
331{
333
334 const TPCFastTransformGeo::RowInfo& rowInfo = mGeo.getRowInfo(row);
335 const SliceRowInfo& sliceRowInfo = getSliceRowInfo(slice, row);
336
337 float uMargin = fInterpolationSafetyMargin * rowInfo.getUwidth();
338 float vMargin = fInterpolationSafetyMargin * mGeo.getTPCzLength(slice);
339
340 if (corrU < sliceRowInfo.activeArea.cuMin - uMargin) {
341 corrU = sliceRowInfo.activeArea.cuMin - uMargin;
342 }
343
344 if (corrU > sliceRowInfo.activeArea.cuMax + uMargin) {
345 corrU = sliceRowInfo.activeArea.cuMax + uMargin;
346 }
347
348 if (corrV < 0.f - vMargin) {
349 corrV = 0.f - vMargin;
350 }
351
352 if (corrV > sliceRowInfo.activeArea.cvMax + vMargin) {
353 corrV = sliceRowInfo.activeArea.cvMax + vMargin;
354 }
355}
356
357GPUdi() void TPCFastSpaceChargeCorrection::convUVtoGrid(int32_t slice, int32_t row, float u, float v, float& gu, float& gv) const
358{
359 // TODO optimise !!!
360 gu = 0.f;
361 gv = 0.f;
362
363 schrinkUV(slice, row, u, v);
364
365 const SliceRowInfo& info = getSliceRowInfo(slice, row);
366 const SplineType& spline = getSpline(slice, row);
367
368 float su0 = 0.f, sv0 = 0.f;
369 mGeo.convUVtoScaledUV(slice, row, u, info.gridV0, su0, sv0);
370 mGeo.convUVtoScaledUV(slice, row, u, v, gu, gv);
371
372 gv = (gv - sv0) / (1.f - sv0);
373 gu *= spline.getGridX1().getUmax();
374 gv *= spline.getGridX2().getUmax();
375}
376
377GPUdi() void TPCFastSpaceChargeCorrection::convGridToUV(int32_t slice, int32_t row, float gridU, float gridV, float& u, float& v) const
378{
379 // TODO optimise
381 float su0 = 0.f, sv0 = 0.f;
382 const SliceRowInfo& info = getSliceRowInfo(slice, row);
383 const SplineType& spline = getSpline(slice, row);
384 mGeo.convUVtoScaledUV(slice, row, 0.f, info.gridV0, su0, sv0);
385 float su = gridU / spline.getGridX1().getUmax();
386 float sv = sv0 + gridV / spline.getGridX2().getUmax() * (1.f - sv0);
387 mGeo.convScaledUVtoUV(slice, row, su, sv, u, v);
388}
389
390GPUdi() void TPCFastSpaceChargeCorrection::convCorrectedUVtoGrid(int32_t slice, int32_t row, float corrU, float corrV, float& gridU, float& gridV) const
391{
392 schrinkCorrectedUV(slice, row, corrU, corrV);
393
394 const SliceRowInfo& sliceRowInfo = getSliceRowInfo(slice, row);
395
396 gridU = (corrU - sliceRowInfo.gridCorrU0) * sliceRowInfo.scaleCorrUtoGrid;
397 gridV = (corrV - sliceRowInfo.gridCorrV0) * sliceRowInfo.scaleCorrVtoGrid;
398}
399
400GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrection(int32_t slice, int32_t row, float u, float v, float& dx, float& du, float& dv) const
401{
402 const SplineType& spline = getSpline(slice, row);
403 const float* splineData = getSplineData(slice, row);
404 float gridU = 0, gridV = 0;
405 convUVtoGrid(slice, row, u, v, gridU, gridV);
406 float dxuv[3];
407 spline.interpolateU(splineData, gridU, gridV, dxuv);
408 if (CAMath::Abs(dxuv[0]) > 100 || CAMath::Abs(dxuv[1]) > 100 || CAMath::Abs(dxuv[2]) > 100) {
409 dxuv[0] = dxuv[1] = dxuv[2] = 0;
410 }
411 dx = dxuv[0];
412 du = dxuv[1];
413 dv = dxuv[2];
414 return 0;
415}
416
417GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrectionOld(int32_t slice, int32_t row, float u, float v, float& dx, float& du, float& dv) const
418{
419 const SplineType& spline = getSpline(slice, row);
420 const float* splineData = getSplineData(slice, row);
421 float gridU = 0, gridV = 0;
422 convUVtoGrid(slice, row, u, v, gridU, gridV);
423 float dxuv[3];
424 spline.interpolateUold(splineData, gridU, gridV, dxuv);
425 if (CAMath::Abs(dxuv[0]) > 100 || CAMath::Abs(dxuv[1]) > 100 || CAMath::Abs(dxuv[2]) > 100) {
426 dxuv[0] = dxuv[1] = dxuv[2] = 0;
427 }
428 dx = dxuv[0];
429 du = dxuv[1];
430 dv = dxuv[2];
431 return 0;
432}
433
434GPUdi() void TPCFastSpaceChargeCorrection::getCorrectionInvCorrectedX(
435 int32_t slice, int32_t row, float corrU, float corrV, float& x) const
436{
437 float gridU, gridV;
438 convCorrectedUVtoGrid(slice, row, corrU, corrV, gridU, gridV);
439
440 const Spline2D<float, 1>& spline = reinterpret_cast<const Spline2D<float, 1>&>(getSpline(slice, row));
441 const float* splineData = getSplineData(slice, row, 1);
442 float dx = 0;
443 spline.interpolateU(splineData, gridU, gridV, &dx);
444 if (CAMath::Abs(dx) > 100) {
445 dx = 0;
446 }
447 x = mGeo.getRowInfo(row).x + dx;
448}
449
450GPUdi() void TPCFastSpaceChargeCorrection::getCorrectionInvUV(
451 int32_t slice, int32_t row, float corrU, float corrV, float& nomU, float& nomV) const
452{
453 float gridU, gridV;
454 convCorrectedUVtoGrid(slice, row, corrU, corrV, gridU, gridV);
455
456 const Spline2D<float, 2>& spline = reinterpret_cast<const Spline2D<float, 2>&>(getSpline(slice, row));
457 const float* splineData = getSplineData(slice, row, 2);
458
459 float duv[2];
460 spline.interpolateU(splineData, gridU, gridV, duv);
461 if (CAMath::Abs(duv[0]) > 100 || CAMath::Abs(duv[1]) > 100) {
462 duv[0] = duv[1] = 0;
463 }
464 nomU = corrU - duv[0];
465 nomV = corrV - duv[1];
466}
467
468GPUdi() float TPCFastSpaceChargeCorrection::getMaxDriftLength(int32_t slice, int32_t row, float pad) const
469{
470 const RowActiveArea& area = getSliceRowInfo(slice, row).activeArea;
471 const float* c = area.maxDriftLengthCheb;
472 float x = -1.f + 2.f * pad / mGeo.getRowInfo(row).maxPad;
473 float y = c[0] + c[1] * x;
474 float f0 = 1.f;
475 float f1 = x;
476 x *= 2.f;
477 for (int32_t i = 2; i < 5; i++) {
478 double f = x * f1 - f0;
479 y += c[i] * f;
480 f0 = f1;
481 f1 = f;
482 }
483 return y;
484}
485
486GPUdi() float TPCFastSpaceChargeCorrection::getMaxDriftLength(int32_t slice, int32_t row) const
487{
488 return getSliceRowInfo(slice, row).activeArea.vMax;
489}
490
491GPUdi() float TPCFastSpaceChargeCorrection::getMaxDriftLength(int32_t slice) const
492{
493 return getSliceInfo(slice).vMax;
494}
495
496} // namespace gpu
497} // namespace o2
498
499#endif
Definition of FlatObject class.
int32_t i
uint32_t c
Definition RawData.h:2
Definition of Spline2D class.
Definition of TPCFastTransformGeo class.
GPUCA_GPUCODE.
Definition FlatObject.h:176
char * releaseInternalBuffer()
_____________ Methods for making the data buffer external __________________________
Definition FlatObject.h:526
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
Definition FlatObject.h:197
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:342
static constexpr size_t getClassAlignmentBytes()
_____________ Memory alignment __________________________
Definition FlatObject.h:194
GPUd() void setInterpolationSafetyMargin(float val)
GPUd() void setNoCorrection()
_______________ Initialization interface ________________________
TPCFastSpaceChargeCorrection()
_____________ Constructors / destructors __________________________
void setSplineScenario(int32_t scenarioIndex, const SplineType &spline)
Sets approximation scenario.
TPCFastSpaceChargeCorrection & operator=(const TPCFastSpaceChargeCorrection &)=delete
Assignment operator: disabled to avoid ambiguity. Use cloneTo[In/Ex]ternalBuffer() instead.
void setRowScenarioID(int32_t iRow, int32_t iScenario)
Initializes a TPC row.
void finishConstruction()
Finishes construction: puts everything to the flat buffer, releases temporary memory.
GPUh() double testInverse(bool prn=0)
GPUd() float getInterpolationSafetyMargin() const
Gives the interpolation safety marging around the TPC row.
GPUd() SliceInfo &getSliceInfo(int32_t slice)
Gives TPC slice info.
void setFutureBufferAddress(char *futureFlatBufferPtr)
TPCFastSpaceChargeCorrection(const TPCFastSpaceChargeCorrection &)=delete
Copy constructor: disabled to avoid ambiguity. Use cloneTo[In/Ex]ternalBuffer() instead.
GPUd() const SliceInfo &getSliceInfo(int32_t slice) const
Gives TPC slice info.
void constructWithNoCorrection(const TPCFastTransformGeo &geo)
int64_t getTimeStamp() const
Gives the time stamp of the current calibaration parameters.
GPUd() const SliceRowInfo &getSliceRowInfo(int32_t slice
Gives TPC slice & row info.
void setActualBufferAddress(char *actualFlatBufferPtr)
Moving the class with its external buffer to another location.
GPUd() SliceRowInfo &getSliceRowInfo(int32_t slice
Gives TPC slice & row info.
void cloneFromObject(const TPCFastSpaceChargeCorrection &obj, char *newFlatBufferPtr)
Construction interface.
GPUd() const RowInfo &getRowInfo(int32_t row) const
Gives TPC row info.
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLdouble f
Definition glcorearb.h:310
GLint y
Definition glcorearb.h:270
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat * val
Definition glcorearb.h:1582
GPUdi() o2
Definition TrackTRD.h:38
value_T f1
Definition TrackUtils.h:91
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
The struct contains necessary info for TPC padrow.
int32_t splineScenarioID
scenario index (which of Spline2D splines to use)
size_t dataOffsetBytes[3]
offset for the spline data withing a TPC slice
float scaleCorrUtoGrid
scale corrected U to U-grid coordinate
float scaleCorrVtoGrid
scale corrected V to V-grid coordinate
float gridCorrU0
U coordinate of the U-grid start for corrected U.
float gridCorrV0
V coordinate of the V-grid start for corrected V.
std::vector< int > row