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#ifndef GPUCA_GPUCODE_DEVICE
26#include "GPUCommonArray.h" // Would work on GPU, but yields performance regressions
27#endif
28
29namespace o2::gpu
30{
31
41{
42 friend class TPCFastTransformPOD;
43
44 public:
45 // obsolete structure, declared here only for the backward compatibility
46 struct SliceInfo {
48 };
49
50 struct GridInfo {
51 private:
52 float y0{0.f};
53 float yScale{0.f}; //< scale Y to U-grid coordinate
54 float z0{0.f};
55 float zScale{0.f}; //< scale Z to V-grid coordinate
56 float zOut{0.f}; // outer z of the grid;
57 float splineScalingWithZ{0.f};
58
59 public:
60 void set(float y0_, float yScale_, float z0_, float zScale_, float zOut_, float zReadout_)
61 {
62 this->y0 = y0_;
63 this->yScale = yScale_;
64 this->z0 = z0_;
65 this->zScale = zScale_;
66 this->zOut = zOut_;
67 // no scaling when the distance to the readout is too small
68 this->splineScalingWithZ = fabs(zReadout_ - zOut_) > 1.f ? 1.f / (zReadout_ - zOut_) : 0.f;
69 }
70
71 float getY0() const { return y0; }
72 float getYscale() const { return yScale; }
73 float getZ0() const { return z0; }
74 float getZscale() const { return zScale; }
75
76 GPUdi() float getSpineScaleForZ(float z) const
77 {
78 return 1.f - GPUCommonMath::Clamp((z - zOut) * splineScalingWithZ, 0.f, 1.f);
79 }
80
82 GPUdi() void convLocalToGridUntruncated(int sector, float y, float z, float& u, float& v, float& s) const
83 {
85 z = -z;
86 }
87 u = (y - y0) * yScale;
88 v = (z - z0) * zScale;
89 s = getSpineScaleForZ(z);
90 }
91
93 GPUdi() void convGridToLocal(int sector, float gridU, float gridV, float& y, float& z) const
94 {
95 y = y0 + gridU / yScale;
96 z = z0 + gridV / zScale;
98 z = -z;
99 }
100 }
102 };
103
113
117
119
125
127
130
133
136
139
141
143
146
148
149 void cloneFromObject(const TPCFastSpaceChargeCorrection& obj, char* newFlatBufferPtr);
150 void destroy();
151
153
155 void moveBufferTo(char* newBufferPtr);
156
158
159 void setActualBufferAddress(char* actualFlatBufferPtr);
160 void setFutureBufferAddress(char* futureFlatBufferPtr);
161
163
165 void startConstruction(const TPCFastTransformGeo& geo, int32_t numberOfSplineScenarios);
166
168 void setRowScenarioID(int32_t iRow, int32_t iScenario);
169
171 void setSplineScenario(int32_t scenarioIndex, const SplineType& spline);
172
174 void finishConstruction();
175
177
179
181 GPUd() void setNoCorrection();
182
184 GPUdi() void setTimeStamp(int64_t v) { mTimeStamp = v; }
185
187 GPUd() const SplineType& getSplineForRow(int32_t row) const;
188
190 GPUd() SplineType& getSplineForRow(int32_t row);
191
193 GPUd() float* getCorrectionData(int32_t sector, int32_t row, int32_t iSpline = 0);
194
196 GPUd() const float* getCorrectionData(int32_t sector, int32_t row, int32_t iSpline = 0) const;
197
199 GPUd() const SplineTypeInvX& getSplineInvXforRow(int32_t row) const;
200
202 GPUd() SplineTypeInvX& getSplineInvXforRow(int32_t row);
203
205 GPUd() float* getCorrectionDataInvX(int32_t sector, int32_t row);
206
208 GPUd() const float* getCorrectionDataInvX(int32_t sector, int32_t row) const;
209
211 GPUd() const SplineTypeInvYZ& getSplineInvYZforRow(int32_t row) const;
212
214 GPUd() SplineTypeInvYZ& getSplineInvYZforRow(int32_t row);
215
217 GPUd() float* getCorrectionDataInvYZ(int32_t sector, int32_t row);
218
220 GPUd() const float* getCorrectionDataInvYZ(int32_t sector, int32_t row) const;
221
224 // GPUd() int32_t getCorrectionInternal(int32_t sector, int32_t row, float u, float v, float& dx, float& du, float& dv) const;
225
226 GPUdi() void getCorrectionLocal(int32_t sector, int32_t row, float y, float z, float& dx, float& dy, float& dz) const;
227
229 GPUd() float getCorrectionXatRealYZ(int32_t sector, int32_t row, float realY, float realZ) const;
230
232 GPUd() void getCorrectionYZatRealYZ(int32_t sector, int32_t row, float realY, float realZ, float& y, float& z) const;
233
235
238 GPUd() void convLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const;
239
242 GPUd() void convGridToLocal(int32_t sector, int32_t row, float u, float v, float& y, float& z) const;
243
246 GPUd() void convRealLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const;
247
250 GPUd() void convGridToRealLocal(int32_t sector, int32_t row, float u, float v, float& y, float& z) const;
251
252 GPUd() bool isLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const;
253 GPUd() bool isRealLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const;
254
256 GPUdi() const TPCFastTransformGeo& getGeometry() const
257 {
258 return mGeo;
259 }
260
262 int64_t getTimeStamp() const { return mTimeStamp; }
263
265 GPUdi() const RowInfo& getRowInfo(int32_t row) const
266 {
267 return mRowInfos[row];
268 }
269
271 GPUdi() RowInfo& getRowInfo(int32_t row)
272 {
273 return mRowInfos[row];
274 }
275
276#if !defined(GPUCA_GPUCODE)
278 void print() const;
279 GPUh() double testInverse(bool prn = 0);
280#endif
281
282 private:
284 void relocateBufferPointers(const char* oldBuffer, char* newBuffer);
286 void releaseConstructionMemory();
287
288 static constexpr float kMaxCorrection = 100.f;
289
291
293
294 SplineType* mConstructionScenarios = nullptr;
295
297
299
300 int32_t mNumberOfScenarios;
301
302 SplineType* mScenarioPtr;
303
305
306 int64_t mTimeStamp;
307
308 char* mCorrectionData[3];
309
310 size_t mSectorDataSizeBytes[3];
311
315 int32_t mClassVersion{3};
316
317 RowInfo mRowInfos[TPCFastTransformGeo::getMaxNumberOfRows()];
318
319 ClassDefNV(TPCFastSpaceChargeCorrection, 4);
320};
321
325
326GPUdi() const TPCFastSpaceChargeCorrection::SplineType& TPCFastSpaceChargeCorrection::getSplineForRow(int32_t row) const
327{
329 return mScenarioPtr[getRowInfo(row).splineScenarioID];
330}
331
332GPUdi() TPCFastSpaceChargeCorrection::SplineType& TPCFastSpaceChargeCorrection::getSplineForRow(int32_t row)
333{
335 return mScenarioPtr[getRowInfo(row).splineScenarioID];
336}
337
338GPUdi() float* TPCFastSpaceChargeCorrection::getCorrectionData(int32_t sector, int32_t row, int32_t iSpline)
339{
341 size_t offset = sector * mSectorDataSizeBytes[iSpline] + getRowInfo(row).dataOffsetBytes[iSpline];
342 return reinterpret_cast<float*>(mCorrectionData[iSpline] + offset);
343}
344
345GPUdi() const float* TPCFastSpaceChargeCorrection::getCorrectionData(int32_t sector, int32_t row, int32_t iSpline) const
346{
348 size_t offset = sector * mSectorDataSizeBytes[iSpline] + getRowInfo(row).dataOffsetBytes[iSpline];
349 return reinterpret_cast<const float*>(mCorrectionData[iSpline] + offset);
350}
351
352GPUdi() TPCFastSpaceChargeCorrection::SplineTypeInvX& TPCFastSpaceChargeCorrection::getSplineInvXforRow(int32_t row)
353{
355 return reinterpret_cast<SplineTypeInvX&>(getSplineForRow(row));
356}
357
358GPUdi() const TPCFastSpaceChargeCorrection::SplineTypeInvX& TPCFastSpaceChargeCorrection::getSplineInvXforRow(int32_t row) const
359{
361 return reinterpret_cast<const SplineTypeInvX&>(getSplineForRow(row));
362}
363
364GPUdi() float* TPCFastSpaceChargeCorrection::getCorrectionDataInvX(int32_t sector, int32_t row)
365{
367 return getCorrectionData(sector, row, 1);
368}
369
370GPUdi() const float* TPCFastSpaceChargeCorrection::getCorrectionDataInvX(int32_t sector, int32_t row) const
371{
373 return getCorrectionData(sector, row, 1);
374}
375
376GPUdi() TPCFastSpaceChargeCorrection::SplineTypeInvYZ& TPCFastSpaceChargeCorrection::getSplineInvYZforRow(int32_t row)
377{
379 return reinterpret_cast<SplineTypeInvYZ&>(getSplineForRow(row));
380}
381
382GPUdi() const TPCFastSpaceChargeCorrection::SplineTypeInvYZ& TPCFastSpaceChargeCorrection::getSplineInvYZforRow(int32_t row) const
383{
385 return reinterpret_cast<const SplineTypeInvYZ&>(getSplineForRow(row));
386}
387
388GPUdi() float* TPCFastSpaceChargeCorrection::getCorrectionDataInvYZ(int32_t sector, int32_t row)
389{
391 return getCorrectionData(sector, row, 2);
392}
393
394GPUdi() const float* TPCFastSpaceChargeCorrection::getCorrectionDataInvYZ(int32_t sector, int32_t row) const
395{
397 return getCorrectionData(sector, row, 2);
398}
399
400GPUdi() void TPCFastSpaceChargeCorrection::convLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const
401{
404 const SplineType& spline = getSplineForRow(row);
405 getRowInfo(row).gridMeasured.convLocalToGridUntruncated(sector, y, z, u, v, s);
406 // shrink to the grid
407 u = GPUCommonMath::Clamp(u, 0.f, (float)spline.getGridX1().getUmax());
408 v = GPUCommonMath::Clamp(v, 0.f, (float)spline.getGridX2().getUmax());
409}
410
411GPUdi() bool TPCFastSpaceChargeCorrection::isLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const
412{
414 float u, v, s;
415 getRowInfo(row).gridMeasured.convLocalToGridUntruncated(sector, y, z, u, v, s);
416 const auto& spline = getSplineForRow(row);
417 // shrink to the grid
418 if (u < 0.f || u > (float)spline.getGridX1().getUmax() || //
419 v < 0.f || v > (float)spline.getGridX2().getUmax()) {
420 return false;
421 }
422 return true;
423}
424
425GPUdi() bool TPCFastSpaceChargeCorrection::isRealLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const
426{
428 float u, v, s;
429 getRowInfo(row).gridReal.convLocalToGridUntruncated(sector, y, z, u, v, s);
430 const auto& spline = getSplineForRow(row);
431 // shrink to the grid
432 if (u < 0.f || u > (float)spline.getGridX1().getUmax() || //
433 v < 0.f || v > (float)spline.getGridX2().getUmax()) {
434 return false;
435 }
436 return true;
437}
438
439GPUdi() void TPCFastSpaceChargeCorrection::convGridToLocal(int32_t sector, int32_t row, float gridU, float gridV, float& y, float& z) const
440{
442 getRowInfo(row).gridMeasured.convGridToLocal(sector, gridU, gridV, y, z);
443}
444
445GPUdi() void TPCFastSpaceChargeCorrection::convRealLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const
446{
448 const SplineType& spline = getSplineForRow(row);
449 getRowInfo(row).gridReal.convLocalToGridUntruncated(sector, y, z, u, v, s);
450 // shrink to the grid
451 u = GPUCommonMath::Clamp(u, 0.f, (float)spline.getGridX1().getUmax());
452 v = GPUCommonMath::Clamp(v, 0.f, (float)spline.getGridX2().getUmax());
453}
454
455GPUdi() void TPCFastSpaceChargeCorrection::convGridToRealLocal(int32_t sector, int32_t row, float gridU, float gridV, float& y, float& z) const
456{
458 getRowInfo(row).gridReal.convGridToLocal(sector, gridU, gridV, y, z);
459}
460
461GPUdi() void TPCFastSpaceChargeCorrection::getCorrectionLocal(int32_t sector, int32_t row, float y, float z, float& dx, float& dy, float& dz) const
462{
463 const SplineType& spline = getSplineForRow(row);
464 const float* splineData = getCorrectionData(sector, row);
465
466 float u, v, s;
467 convLocalToGrid(sector, row, y, z, u, v, s);
468
469 float dxyz[3];
470 spline.interpolateAtU(splineData, u, v, dxyz);
471
472 if (CAMath::Abs(dxyz[0]) > kMaxCorrection || CAMath::Abs(dxyz[1]) > kMaxCorrection || CAMath::Abs(dxyz[2]) > kMaxCorrection) {
473 s = 0.f; // TODO: DR: Protect from FPEs, fix upstream and remove once guaranteed that it is fixed
474 }
475
476 dx = s * dxyz[0];
477 dy = s * dxyz[1];
478 dz = s * dxyz[2];
479}
480
481GPUdi() float TPCFastSpaceChargeCorrection::getCorrectionXatRealYZ(int32_t sector, int32_t row, float realY, float realZ) const
482{
483 float u, v, s;
484 convRealLocalToGrid(sector, row, realY, realZ, u, v, s);
485 float dx = 0;
486 getSplineInvXforRow(row).interpolateAtU(getCorrectionDataInvX(sector, row), u, v, &dx);
487 if (CAMath::Abs(dx) > kMaxCorrection) {
488 s = 0.f; // TODO: DR: Protect from FPEs, fix upstream and remove once guaranteed that it is fixed
489 }
490 return s * dx;
491}
492
493GPUdi() void TPCFastSpaceChargeCorrection::getCorrectionYZatRealYZ(int32_t sector, int32_t row, float realY, float realZ, float& y, float& z) const
494{
495 float u, v, s;
496 convRealLocalToGrid(sector, row, realY, realZ, u, v, s);
497 float dyz[2];
498 getSplineInvYZforRow(row).interpolateAtU(getCorrectionDataInvYZ(sector, row), u, v, dyz);
499 if (CAMath::Abs(dyz[0]) > kMaxCorrection || CAMath::Abs(dyz[1]) > kMaxCorrection) {
500 s = 0.f; // TODO: DR: Protect from FPEs, fix upstream and remove once guaranteed that it is fixed
501 }
502 y = s * dyz[0];
503 z = s * dyz[1];
504}
505
506} // namespace o2::gpu
507
508#endif
Definition of FlatObject class.
Definition of Spline2D class.
Definition of TPCFastTransformGeo class.
char * releaseInternalBuffer()
_____________ Methods for making the data buffer external __________________________
Definition FlatObject.h:538
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
Definition FlatObject.h:195
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:354
static constexpr size_t getClassAlignmentBytes()
GPUCA_GPUCODE.
Definition FlatObject.h:192
Forward declaration — specializations below select ClassDefNV based on FlatBase.
Definition Spline2D.h:104
GPUd() const SplineType &getSplineForRow(int32_t row) const
Gives const pointer to a spline.
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.
GPUdi() const RowInfo &getRowInfo(int32_t row) const
Gives TPC row info.
void setRowScenarioID(int32_t iRow, int32_t iScenario)
Initializes a TPC row.
GPUdi() void setTimeStamp(int64_t v)
Sets the time stamp of the current calibaration.
void finishConstruction()
Finishes construction: puts everything to the flat buffer, releases temporary memory.
Spline2D< float, 3, NoFlatObject > SlimSplineTypeXYZ
Slim variants (NoFlatObject base) for use in TPCFastTransformPOD.
GPUh() double testInverse(bool prn=0)
void setFutureBufferAddress(char *futureFlatBufferPtr)
TPCFastSpaceChargeCorrection(const TPCFastSpaceChargeCorrection &)=delete
Copy constructor: disabled to avoid ambiguity. Use cloneTo[In/Ex]ternalBuffer() instead.
void constructWithNoCorrection(const TPCFastTransformGeo &geo)
int64_t getTimeStamp() const
Gives the time stamp of the current calibaration parameters.
void setActualBufferAddress(char *actualFlatBufferPtr)
Moving the class with its external buffer to another location.
void cloneFromObject(const TPCFastSpaceChargeCorrection &obj, char *newFlatBufferPtr)
Construction interface.
GPUdi() RowInfo &getRowInfo(int32_t row)
Gives TPC row info.
static constexpr int getMaxNumberOfRows()
Gives number of TPC rows.
static constexpr int32_t getNumberOfSectorsA()
Gives number of TPC sectors on the A side.
const GLdouble * v
Definition glcorearb.h:832
GLintptr offset
Definition glcorearb.h:660
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat GLfloat y0
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
GPUdi() o2
Definition TrackTRD.h:39
void set(float y0_, float yScale_, float z0_, float zScale_, float zOut_, float zReadout_)
GridInfo gridReal
grid info for the real coordinates
GridInfo gridMeasured
grid info for the measured coordinates
int32_t splineScenarioID
scenario index (which of Spline2D splines to use)
size_t dataOffsetBytes[3]
offset for the spline data withing a TPC sector
std::vector< int > row