-
Notifications
You must be signed in to change notification settings - Fork 499
Expand file tree
/
Copy pathTPCFastTransformPOD.h
More file actions
726 lines (596 loc) · 34.5 KB
/
TPCFastTransformPOD.h
File metadata and controls
726 lines (596 loc) · 34.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
// Copyright 2019-2020 CERN and copyright holders of ALICE O2.
// See https://alice-o2.web.cern.ch/copyright for details of the copyright holders.
// All rights not expressly granted are reserved.
//
// This software is distributed under the terms of the GNU General Public
// License v3 (GPL Version 3), copied verbatim in the file "COPYING".
//
// In applying this license CERN does not waive the privileges and immunities
// granted to it by virtue of its status as an Intergovernmental Organization
// or submit itself to any jurisdiction.
/// \file TPCFastTransformPOD.h
/// \brief POD correction map
///
/// \author ruben.shahoayn@cern.ch
#ifndef ALICEO2_GPU_TPCFastTransformPOD_H
#define ALICEO2_GPU_TPCFastTransformPOD_H
#include "GPUCommonRtypes.h"
#include "TPCFastTransform.h"
#include "TPCFastTransformGeoPOD.h"
#include "DataFormatsTPC/Constants.h"
#ifndef GPUCA_GPUCODE
#include <memory>
#include <cstdlib>
#include "GPUCommonAlignedAlloc.h"
#endif
/*
Binary buffer should be cast to TPCFastTransformPOD class using static TPCFastTransformPOD& t = get(buffer); method,
so that its head becomes `this` pointer of the object.
First we have all the fixed size data members mentioned explicitly. Part of them is duplicating fixed size
data members of TPCFastSpaceChargeCorrection but those starting with mOffs... provide the offset in bytes
(wrt this) for dynamic data which cannot be declared as data member explicitly (since we cannot have any
pointer except `this`) but obtained via getters using stored offsets wrt `this`.
This is followed dynamic part itself.
dynamic part layout:
1) size_t[ mNumberOfScenarios ] array starting at offset mOffsScenariosOffsets, each element is the offset
of distict spline object (scenario in TPCFastSpaceChargeCorrection)
2) size_t[ mNSplineIDs ] array starting at offset mOffsSplineDataOffsets, each element is the offset of the
beginning of splines data for give splineID
*/
namespace o2::gpu
{
class TPCFastTransformPOD
{
public:
using SliceInfo = TPCFastSpaceChargeCorrection::SliceInfo; // obsolete
using GridInfo = TPCFastSpaceChargeCorrection::GridInfo;
using RowInfo = TPCFastSpaceChargeCorrection::RowInfo;
using SplineTypeXYZ = TPCFastSpaceChargeCorrection::SlimSplineTypeXYZ;
using SplineTypeInvX = TPCFastSpaceChargeCorrection::SlimSplineTypeInvX;
using SplineTypeInvYZ = TPCFastSpaceChargeCorrection::SlimSplineTypeInvYZ;
using SplineType = TPCFastSpaceChargeCorrection::SlimSplineType;
/// convert prefilled buffer to TPCFastTransformPOD
GPUd() static const TPCFastTransformPOD& get(const char* head) { return *reinterpret_cast<const TPCFastTransformPOD*>(head); }
/// _______________ high level methods a la TPCFastTransform _______________________
///
// Methods taking extra reference transform are legacy compound transforms used to scale corrections.
GPUd() void Transform(int32_t sector, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime = 0) const;
GPUd() void TransformXYZ(int32_t sector, int32_t row, float& x, float& y, float& z) const;
/// Transformation in the time frame
GPUd() void TransformInTimeFrame(int32_t sector, int32_t row, float pad, float time, float& x, float& y, float& z, float maxTimeBin) const;
GPUd() void TransformInTimeFrame(int32_t sector, float time, float& z, float maxTimeBin) const;
/// Inverse transformation
GPUd() void InverseTransformInTimeFrame(int32_t sector, int32_t row, float /*x*/, float y, float z, float& pad, float& time, float maxTimeBin) const;
GPUd() float InverseTransformInTimeFrame(int32_t sector, float z, float maxTimeBin) const;
/// Inverse transformation: Transformed Y and Z -> transformed X
GPUd() void InverseTransformYZtoX(int32_t sector, int32_t row, float y, float z, float& x) const;
/// Inverse transformation: Transformed Y and Z -> Y and Z, transformed w/o space charge correction
GPUd() void InverseTransformYZtoNominalYZ(int32_t sector, int32_t row, float y, float z, float& ny, float& nz) const;
/// Inverse transformation: Transformed X, Y and Z -> X, Y and Z, transformed w/o space charge correction
GPUd() void InverseTransformXYZtoNominalXYZ(int32_t sector, int32_t row, float x, float y, float z, float& nx, float& ny, float& nz) const;
/// Ideal transformation with Vdrift only - without calibration
GPUd() void TransformIdeal(int32_t sector, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime) const;
GPUd() void TransformIdealZ(int32_t sector, float time, float& z, float vertexTime) const;
GPUd() void convPadTimeToLocal(int32_t sector, int32_t row, float pad, float time, float& y, float& z, float vertexTime) const;
GPUd() void convPadTimeToLocalInTimeFrame(int32_t sector, int32_t row, float pad, float time, float& y, float& z, float maxTimeBin) const;
GPUd() void convLocalToPadTime(int32_t sector, int32_t row, float y, float z, float& pad, float& time, float vertexTime) const;
GPUd() void convLocalToPadTimeInTimeFrame(int32_t sector, int32_t row, float y, float z, float& pad, float& time, float maxTimeBin) const;
GPUd() float convTimeToZinTimeFrame(int32_t sector, float time, float maxTimeBin) const;
GPUd() float convZtoTimeInTimeFrame(int32_t sector, float z, float maxTimeBin) const;
GPUd() float convDeltaTimeToDeltaZinTimeFrame(int32_t sector, float deltaTime) const;
GPUd() float convDeltaZtoDeltaTimeInTimeFrame(int32_t sector, float deltaZ) const;
GPUd() float convDeltaZtoDeltaTimeInTimeFrameAbs(float deltaZ) const;
GPUd() float convZOffsetToVertexTime(int32_t sector, float zOffset, float maxTimeBin) const;
GPUd() float convVertexTimeToZOffset(int32_t sector, float vertexTime, float maxTimeBin) const;
/// _______________ methods a la TPCFastSpaceChargeCorrection: cluster correction _______________________
void setApplyCorrectionOn() { mApplyCorrection = 1; }
void setApplyCorrectionOff() { mApplyCorrection = 0; }
bool isCorrectionApplied() { return mApplyCorrection; }
/// TPC geometry information
GPUd() const TPCFastTransformGeoPOD& getGeometry() const { return mGeo; }
/// Gives TPC sector & row info
GPUd() const RowInfo& getRowInfo(int32_t row) const { return mRowInfos[row]; }
/// Gives TPC sector & row info
GPUd() RowInfo& getRowInfo(int32_t row) { return mRowInfos[row]; }
/// Gives its own size including dynamic part
GPUd() size_t size() const { return mTotalSize; }
/// Gives the time stamp of the current calibaration parameters
GPUd() long int getTimeStamp() const { return mTimeStamp; }
/// Return mVDrift in cm / time bin
GPUd() float getVDrift() const { return mVdrift; }
/// Return T0 in time bin units
GPUd() float getT0() const { return mT0; }
/// Return IDC estimator
GPUd() float getIDC() const { return mIDC; }
/// Return Lumi estimator
GPUd() float getLumi() const { return mLumi; }
/// maximal possible drift time of the active area
GPUd() float getMaxDriftTime(int32_t sector, int32_t row, float pad) const;
/// maximal possible drift time of the active area
GPUd() float getMaxDriftTime(int32_t sector, int32_t row) const;
/// maximal possible drift time of the active area
GPUd() float getMaxDriftTime(int32_t sector) const;
/// Sets the time stamp of the current calibaration
GPUd() void setTimeStamp(long int v) { mTimeStamp = v; }
/// Sets current vdrift
GPUd() void setVDrift(float v) { mVdrift = v; }
/// Sets current T0
GPUd() void setT0(float v) { mT0 = v; }
/// Sets IDC estimator
GPUd() void setIDC(float v) { mIDC = v; }
/// Sets CTP Lumi estimator
GPUd() void setLumi(float v) { mLumi = v; }
GPUd() void setCalibration(int64_t timeStamp, float t0, float vDrift);
/// Gives a reference to a spline
GPUd() const SplineType& getSplineForRow(int32_t row) const { return *reinterpret_cast<const SplineType*>(getThis() + getScenarioOffset(getRowInfo(row).splineScenarioID)); }
/// Gives pointer to spline data
GPUd() const float* getCorrectionData(int32_t sector, int32_t row, int32_t iSpline = 0) const { return reinterpret_cast<const float*>(getThis() + mSplineDataOffsets[sector][iSpline] + getRowInfo(row).dataOffsetBytes[iSpline]); }
/// Gives const pointer to a spline for the inverse X correction
GPUd() const SplineTypeInvX& getSplineInvXforRow(int32_t row) const { return reinterpret_cast<const SplineTypeInvX&>(getSplineForRow(row)); }
/// Gives pointer to spline data for the inverse X correction
GPUd() const float* getCorrectionDataInvX(int32_t sector, int32_t row) const { return getCorrectionData(sector, row, 1); }
/// Gives const pointer to a spline for the inverse YZ correction
GPUd() const SplineTypeInvYZ& getSplineInvYZforRow(int32_t row) const { return reinterpret_cast<const SplineTypeInvYZ&>(getSplineForRow(row)); }
/// Gives pointer to spline data for the inverse YZ correction
GPUd() const float* getCorrectionDataInvYZ(int32_t sector, int32_t row) const { return getCorrectionData(sector, row, 2); }
/// _______________ The main method: cluster correction _______________________
GPUdi() void getCorrectionLocal(int32_t sector, int32_t row, float y, float z, float& dx, float& dy, float& dz) const;
/// inverse correction: Real Y and Z -> Real X
GPUd() float getCorrectionXatRealYZ(int32_t sector, int32_t row, float realY, float realZ) const;
/// inverse correction: Real Y and Z -> measred Y and Z
GPUd() void getCorrectionYZatRealYZ(int32_t sector, int32_t row, float realY, float realZ, float& measuredY, float& measuredZ) const;
/// transformation in the sector local frame
GPUd() void TransformLocal(int32_t sector, int32_t row, float& x, float& y, float& z) const;
/// _______________ Utilities _______________________________________________
/// convert local y, z to internal grid coordinates u,v
/// return values: u, v, scaling factor
GPUd() void convLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const;
/// convert internal grid coordinates u,v to local y, z
/// return values: y, z, scaling factor
GPUd() void convGridToLocal(int32_t sector, int32_t row, float u, float v, float& y, float& z) const;
/// convert real Y, Z to the internal grid coordinates
/// return values: u, v, scaling factor
GPUd() void convRealLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const;
/// convert internal grid coordinates to the real Y, Z
/// return values: y, z
GPUd() void convGridToRealLocal(int32_t sector, int32_t row, float u, float v, float& y, float& z) const;
GPUd() bool isLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const;
GPUd() bool isRealLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const;
#if !defined(GPUCA_GPUCODE)
/// Create POD transform from old flat-buffer one. Provided vector will serve as a buffer
static TPCFastTransformPOD* create(aligned_unique_buffer_ptr<TPCFastTransformPOD>& destVector, const TPCFastTransform& src);
/// create filling only part corresponding to TPCFastSpaceChargeCorrection. Data members coming from TPCFastTransform (e.g. VDrift, T0..) are not set
static TPCFastTransformPOD* create(aligned_unique_buffer_ptr<TPCFastTransformPOD>& destVector, const TPCFastSpaceChargeCorrection& src);
static TPCFastTransformPOD* create(aligned_unique_buffer_ptr<TPCFastTransformPOD>& destVector, const TPCFastTransformPOD& src)
{
destVector.alloc(src.size());
std::memcpy(destVector.get(), &src, src.size());
return destVector.get();
}
static TPCFastTransformPOD* create(char* buff, size_t buffSize, const TPCFastTransform& src);
static TPCFastTransformPOD* create(char* buff, size_t buffSize, const TPCFastSpaceChargeCorrection& src);
static size_t estimateSize(const TPCFastTransform& src) { return estimateSize(src.getCorrection()); }
static size_t estimateSize(const TPCFastSpaceChargeCorrection& origCorr);
bool test(const TPCFastTransform& src, int32_t npoints = 100000) const { return test(src.getCorrection(), npoints); }
bool test(const TPCFastSpaceChargeCorrection& origCorr, int32_t npoints = 100000) const;
#endif
/// Print method
void print() const;
GPUd() float convDriftLengthToTime(float driftLength, float vertexTime) const;
static constexpr int NROWS = o2::tpc::constants::MAXGLOBALPADROW;
static constexpr int NSECTORS = o2::tpc::constants::MAXSECTOR;
static constexpr int NSECTORSA = o2::tpc::constants::MAXSECTOR / 2;
static constexpr int NSplineIDs = 3; ///< number of spline data sets for each sector/row
private:
#if !defined(GPUCA_GPUCODE)
static constexpr size_t AlignmentBytes = 8;
static size_t alignOffset(size_t offs)
{
auto res = offs % AlignmentBytes;
return res ? offs + (AlignmentBytes - res) : offs;
}
GPUd() static TPCFastTransformPOD& getNonConst(char* head) { return *reinterpret_cast<TPCFastTransformPOD*>(head); }
#endif
///< get address to which the offset in bytes must be added to arrive to particular dynamic part
GPUd() const char* getThis() const { return reinterpret_cast<const char*>(this); }
///< return offset of the spline object start (equivalent of mScenarioPtr in the TPCFastSpaceChargeCorrection)
GPUd() size_t getScenarioOffset(int s) const { return (reinterpret_cast<const size_t*>(getThis() + mOffsScenariosOffsets))[s]; }
GPUd() size_t getFlatBufferOffset(int s) const { return (reinterpret_cast<const size_t*>(getThis() + mOffsFlatBufferOffsets))[s]; }
// Returns a pointer to the flat buffer of scenario isc, using only the
// stored offset array (mOffsFlatBufferOffsets). No stale pointer involved.
GPUd() const char* getSplineFlatBuffer(int32_t isc) const
{
const size_t* offs = reinterpret_cast<const size_t*>(getThis() + mOffsFlatBufferOffsets);
return getThis() + offs[isc];
}
// Returns a pointer to mGridX2's flat buffer inside the spline flat buffer.
// Reproduces the layout from Spline2DContainer::setActualBufferAddress using
// only safe values: getFlatBufferSize() reads mNumberOfKnots/mUmax (plain ints).
template <typename SplineT>
GPUd() const char* getGridX2FlatBuffer(const SplineT& spline, int32_t isc) const
{
const size_t g1sz = spline.getGridX1().getFlatBufferSize();
const size_t g2align = spline.getGridX2().getBufferAlignmentBytes();
return getSplineFlatBuffer(isc) + FlatObject::alignSize(g1sz, g2align);
}
bool mApplyCorrection{}; ///< flag to apply corrections
int mNumberOfScenarios{}; ///< Number of approximation spline scenarios
size_t mTotalSize{}; ///< total size of the buffer
size_t mOffsScenariosOffsets{}; ///< start of the array of mNumberOfScenarios offsets for each type of spline
size_t mOffsFlatBufferOffsets{}; ///< offset to array of mNumberOfScenarios flat buffer offsets
size_t mSplineDataOffsets[TPCFastTransformGeo::getNumberOfSectors()][NSplineIDs]; ///< start of data for each sector and iSpline data
long int mTimeStamp{}; ///< time stamp of the current calibration
float mT0; ///< T0 in [time bin]
float mVdrift; ///< VDrift in [cm/time bin]
float mLumi; ///< luminosity estimator (for info only)
float mIDC; ///< IDC estimator (for info only)
TPCFastTransformGeoPOD mGeo; ///< TPC geometry information
RowInfo mRowInfos[NROWS];
ClassDefNV(TPCFastTransformPOD, 0);
};
GPUdi() void TPCFastTransformPOD::getCorrectionLocal(int32_t sector, int32_t row, float y, float z, float& dx, float& dy, float& dz) const
{
const auto& info = getRowInfo(row);
const int32_t isc = info.splineScenarioID;
const SplineType& spline = getSplineForRow(row);
const float* splineData = getCorrectionData(sector, row);
float u, v, s;
convLocalToGrid(sector, row, y, z, u, v, s);
const char* g1buf = getSplineFlatBuffer(isc);
const char* g2buf = getGridX2FlatBuffer(spline, isc);
float dxyz[3];
spline.interpolateAtUZeroCopy(g1buf, g2buf, splineData, u, v, dxyz);
if (CAMath::Abs(dxyz[0]) > TPCFastSpaceChargeCorrection::kMaxCorrection || CAMath::Abs(dxyz[1]) > TPCFastSpaceChargeCorrection::kMaxCorrection || CAMath::Abs(dxyz[2]) > TPCFastSpaceChargeCorrection::kMaxCorrection) {
s = 0.f; // TODO: DR: Protect from FPEs, fix upstream and remove once guaranteed that it is fixed
}
dx = s * dxyz[0];
dy = s * dxyz[1];
dz = s * dxyz[2];
}
GPUdi() float TPCFastTransformPOD::getCorrectionXatRealYZ(int32_t sector, int32_t row, float realY, float realZ) const
{
const auto& info = getRowInfo(row);
float u, v, s;
convRealLocalToGrid(sector, row, realY, realZ, u, v, s);
const int32_t isc = info.splineScenarioID;
const auto& spline = getSplineInvXforRow(row);
const char* g1buf = getSplineFlatBuffer(isc);
const char* g2buf = getGridX2FlatBuffer(spline, isc);
float dx = 0;
spline.interpolateAtUZeroCopy(g1buf, g2buf, getCorrectionDataInvX(sector, row), u, v, &dx);
if (CAMath::Abs(dx) > TPCFastSpaceChargeCorrection::kMaxCorrection) {
s = 0.f; // TODO: DR: Protect from FPEs, fix upstream and remove once guaranteed that it is fixed
}
dx = s * dx;
return dx;
}
GPUdi() void TPCFastTransformPOD::getCorrectionYZatRealYZ(int32_t sector, int32_t row, float realY, float realZ, float& y, float& z) const
{
float u, v, s;
convRealLocalToGrid(sector, row, realY, realZ, u, v, s);
const auto& info = getRowInfo(row);
const int32_t isc = info.splineScenarioID;
const auto& spline = getSplineInvYZforRow(row);
const char* g1buf = getSplineFlatBuffer(isc);
const char* g2buf = getGridX2FlatBuffer(spline, isc);
float dyz[2];
spline.interpolateAtUZeroCopy(g1buf, g2buf, getCorrectionDataInvYZ(sector, row), u, v, dyz);
if (CAMath::Abs(dyz[0]) > TPCFastSpaceChargeCorrection::kMaxCorrection || CAMath::Abs(dyz[1]) > TPCFastSpaceChargeCorrection::kMaxCorrection) {
s = 0.f; // TODO: DR: Protect from FPEs, fix upstream and remove once guaranteed that it is fixed
}
y = s * dyz[0];
z = s * dyz[1];
}
GPUdi() void TPCFastTransformPOD::convLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const
{
/// convert local y, z to internal grid coordinates u,v
/// return values: u, v, scaling factor
const SplineType& spline = getSplineForRow(row);
getRowInfo(row).gridMeasured.convLocalToGridUntruncated(sector, y, z, u, v, s);
// shrink to the grid
u = GPUCommonMath::Clamp(u, 0.f, (float)spline.getGridX1().getUmax());
v = GPUCommonMath::Clamp(v, 0.f, (float)spline.getGridX2().getUmax());
}
GPUdi() void TPCFastTransformPOD::convGridToLocal(int32_t sector, int32_t row, float gridU, float gridV, float& y, float& z) const
{
/// convert internal grid coordinates u,v to local y, z
getRowInfo(row).gridMeasured.convGridToLocal(sector, gridU, gridV, y, z);
}
GPUdi() void TPCFastTransformPOD::convRealLocalToGrid(int32_t sector, int32_t row, float y, float z, float& u, float& v, float& s) const
{
/// convert real y, z to the internal grid coordinates + scale
const SplineType& spline = getSplineForRow(row);
getRowInfo(row).gridReal.convLocalToGridUntruncated(sector, y, z, u, v, s);
// shrink to the grid
u = GPUCommonMath::Clamp(u, 0.f, (float)spline.getGridX1().getUmax());
v = GPUCommonMath::Clamp(v, 0.f, (float)spline.getGridX2().getUmax());
}
GPUdi() void TPCFastTransformPOD::convGridToRealLocal(int32_t sector, int32_t row, float gridU, float gridV, float& y, float& z) const
{
/// convert internal grid coordinates u,v to the real y, z
getRowInfo(row).gridReal.convGridToLocal(sector, gridU, gridV, y, z);
}
GPUdi() bool TPCFastTransformPOD::isLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const
{
/// check if local y, z are inside the grid
float u, v, s;
getRowInfo(row).gridMeasured.convLocalToGridUntruncated(sector, y, z, u, v, s);
const auto& spline = getSplineForRow(row);
// shrink to the grid
if (u < 0.f || u > (float)spline.getGridX1().getUmax() || //
v < 0.f || v > (float)spline.getGridX2().getUmax()) {
return false;
}
return true;
}
GPUdi() bool TPCFastTransformPOD::isRealLocalInsideGrid(int32_t sector, int32_t row, float y, float z) const
{
/// check if local y, z are inside the grid
float u, v, s;
getRowInfo(row).gridReal.convLocalToGridUntruncated(sector, y, z, u, v, s);
const auto& spline = getSplineForRow(row);
// shrink to the grid
if (u < 0.f || u > (float)spline.getGridX1().getUmax() || //
v < 0.f || v > (float)spline.getGridX2().getUmax()) {
return false;
}
return true;
}
GPUdi() void TPCFastTransformPOD::TransformLocal(int32_t sector, int32_t row, float& x, float& y, float& z) const
{
if (!mApplyCorrection) {
return;
}
float dx, dy, dz;
getCorrectionLocal(sector, row, y, z, dx, dy, dz);
GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
float lx = x, ly = y, lz = z;
float gx, gy, gz;
getGeometry().convLocalToGlobal(sector, lx, ly, lz, gx, gy, gz);
float lxT = lx + dx;
float lyT = ly + dy;
float lzT = lz + dz;
float invYZtoX;
InverseTransformYZtoX(sector, row, lyT, lzT, invYZtoX);
float YZtoNominalY;
float YZtoNominalZ;
InverseTransformYZtoNominalYZ(sector, row, lyT, lzT, YZtoNominalY, YZtoNominalZ);
o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_Transform").data()
// corrections in x, u, v
<< "dx=" << dx
<< "dy=" << dy
<< "dz=" << dz
<< "row=" << row
<< "sector=" << sector
// original local coordinates
<< "ly=" << ly
<< "lz=" << lz
<< "lx=" << lx
// corrected local coordinated
<< "lxT=" << lxT
<< "lyT=" << lyT
<< "lzT=" << lzT
// global uncorrected coordinates
<< "gx=" << gx
<< "gy=" << gy
<< "gz=" << gz
// some transformations which are applied
<< "invYZtoX=" << invYZtoX
<< "YZtoNominalY=" << YZtoNominalY
<< "YZtoNominalZ=" << YZtoNominalZ
<< "\n";
})
x += dx;
y += dy;
z += dz;
}
GPUdi() void TPCFastTransformPOD::Transform(int32_t sector, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime) const
{
/// _______________ The main method: cluster transformation _______________________
///
/// Transforms raw TPC coordinates to local XYZ withing a sector
/// taking calibration into account.
///
x = getGeometry().getRowInfoX(row);
convPadTimeToLocal(sector, row, pad, time, y, z, vertexTime);
TransformLocal(sector, row, x, y, z);
}
GPUdi() void TPCFastTransformPOD::TransformXYZ(int32_t sector, int32_t row, float& x, float& y, float& z) const
{
TransformLocal(sector, row, x, y, z);
}
GPUdi() void TPCFastTransformPOD::TransformInTimeFrame(int32_t sector, float time, float& z, float maxTimeBin) const
{
float l = (time - mT0 - maxTimeBin) * mVdrift; // drift length cm
z = getGeometry().convDriftLengthToZ(sector, l);
}
GPUdi() void TPCFastTransformPOD::TransformInTimeFrame(int32_t sector, int32_t row, float pad, float time, float& x, float& y, float& z, float maxTimeBin) const
{
/// _______________ Special cluster transformation for a time frame _______________________
///
/// Same as Transform(), but clusters are shifted in z such, that Z(maxTimeBin)==0
/// Corrections and Time-Of-Flight correction are not alpplied.
///
x = getGeometry().getRowInfoX(row);
convPadTimeToLocalInTimeFrame(sector, row, pad, time, y, z, maxTimeBin);
}
GPUdi() void TPCFastTransformPOD::InverseTransformInTimeFrame(int32_t sector, int32_t row, float /*x*/, float y, float z, float& pad, float& time, float maxTimeBin) const
{
/// Inverse transformation to TransformInTimeFrame
convLocalToPadTimeInTimeFrame(sector, row, y, z, pad, time, maxTimeBin);
}
GPUdi() float TPCFastTransformPOD::InverseTransformInTimeFrame(int32_t sector, float z, float maxTimeBin) const
{
float pad, time;
InverseTransformInTimeFrame(sector, 0, 0, 0, z, pad, time, maxTimeBin);
return time;
}
GPUdi() void TPCFastTransformPOD::TransformIdealZ(int32_t sector, float time, float& z, float vertexTime) const
{
/// _______________ The main method: cluster transformation _______________________
///
/// Transforms time TPC coordinates to local Z withing a sector
/// Ideal transformation: only Vdrift from DCS.
/// No space charge corrections, no time of flight correction
///
float l = (time - mT0 - vertexTime) * mVdrift; // drift length cm
z = getGeometry().convDriftLengthToZ(sector, l);
}
GPUdi() void TPCFastTransformPOD::TransformIdeal(int32_t sector, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime) const
{
/// _______________ The main method: cluster transformation _______________________
///
/// Transforms raw TPC coordinates to local XYZ withing a sector
/// Ideal transformation: only Vdrift from DCS.
/// No space charge corrections, no time of flight correction
///
x = getGeometry().getRowInfoX(row);
float driftLength = (time - mT0 - vertexTime) * mVdrift; // drift length cm
getGeometry().convPadDriftLengthToLocal(sector, row, pad, driftLength, y, z);
}
GPUdi() float TPCFastTransformPOD::convTimeToZinTimeFrame(int32_t sector, float time, float maxTimeBin) const
{
/// _______________ Special cluster transformation for a time frame _______________________
///
/// Same as Transform(), but clusters are shifted in z such, that Z(maxTimeBin)==0
/// Corrections and Time-Of-Flight correction are not alpplied.
/// Only Z coordinate.
///
float v = (time - mT0 - maxTimeBin) * mVdrift; // drift length cm
float z = (sector < getGeometry().getNumberOfSectorsA()) ? -v : v;
return z;
}
GPUdi() float TPCFastTransformPOD::convZtoTimeInTimeFrame(int32_t sector, float z, float maxTimeBin) const
{
/// Inverse transformation of convTimeToZinTimeFrame()
float v = (sector < getGeometry().getNumberOfSectorsA()) ? -z : z;
return mT0 + maxTimeBin + v / mVdrift;
}
GPUdi() float TPCFastTransformPOD::convDeltaTimeToDeltaZinTimeFrame(int32_t sector, float deltaTime) const
{
float deltaZ = deltaTime * mVdrift;
return sector < getGeometry().getNumberOfSectorsA() ? -deltaZ : deltaZ;
}
GPUdi() float TPCFastTransformPOD::convDeltaZtoDeltaTimeInTimeFrameAbs(float deltaZ) const
{
return deltaZ / mVdrift;
}
GPUdi() float TPCFastTransformPOD::convDeltaZtoDeltaTimeInTimeFrame(int32_t sector, float deltaZ) const
{
float deltaT = deltaZ / mVdrift;
return sector < getGeometry().getNumberOfSectorsA() ? -deltaT : deltaT;
}
GPUdi() float TPCFastTransformPOD::getMaxDriftTime(int32_t sector, int32_t row, float pad) const
{
/// maximal possible drift time of the active area
return convDriftLengthToTime(getGeometry().getTPCzLength(), 0.f);
}
GPUdi() float TPCFastTransformPOD::getMaxDriftTime(int32_t sector, int32_t row) const
{
/// maximal possible drift time of the active area
return convDriftLengthToTime(getGeometry().getTPCzLength(), 0.f);
}
GPUdi() float TPCFastTransformPOD::getMaxDriftTime(int32_t sector) const
{
/// maximal possible drift time of the active area
return convDriftLengthToTime(getGeometry().getTPCzLength(), 0.f);
}
GPUdi() void TPCFastTransformPOD::InverseTransformYZtoX(int32_t sector, int32_t row, float realY, float realZ, float& realX) const
{
/// Transformation y,z -> x
float dx = 0.f;
dx = getCorrectionXatRealYZ(sector, row, realY, realZ);
realX = getGeometry().getRowInfoX(row) + dx;
GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_InverseTransformYZtoX").data()
<< "sector=" << sector
<< "row=" << row
<< "y=" << realY
<< "z=" << realZ
<< "x=" << realX
<< "\n";
})
}
GPUdi() void TPCFastTransformPOD::InverseTransformYZtoNominalYZ(int32_t sector, int32_t row, float realY, float realZ, float& measuredY, float& measuredZ) const
{
/// Transformation real y,z -> measured y,z
float dy, dz;
getCorrectionYZatRealYZ(sector, row, realY, realZ, dy, dz);
measuredY = realY - dy;
measuredZ = realZ - dz;
GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_InverseTransformYZtoNominalYZ").data()
<< "sector=" << sector
<< "row=" << row
<< "real y=" << realY
<< "real z=" << realZ
<< "measured y=" << measuredY
<< "measured z=" << measuredZ
<< "\n";
})
}
GPUdi() void TPCFastTransformPOD::convPadTimeToLocal(int32_t sector, int32_t row, float pad, float time, float& y, float& z, float vertexTime) const
{
float l = (time - mT0 - vertexTime) * mVdrift;
getGeometry().convPadDriftLengthToLocal(sector, row, pad, l, y, z);
}
GPUdi() void TPCFastTransformPOD::convPadTimeToLocalInTimeFrame(int32_t sector, int32_t row, float pad, float time, float& y, float& z, float maxTimeBin) const
{
float l = getGeometry().getTPCzLength() + (time - mT0 - maxTimeBin) * mVdrift;
getGeometry().convPadDriftLengthToLocal(sector, row, pad, l, y, z);
}
GPUdi() void TPCFastTransformPOD::convLocalToPadTimeInTimeFrame(int32_t sector, int32_t row, float y, float z, float& pad, float& time, float maxTimeBin) const
{
float length = 0;
getGeometry().convLocalToPadDriftLength(sector, row, y, z, pad, length);
time = convDriftLengthToTime(length, maxTimeBin);
}
GPUdi() float TPCFastTransformPOD::convDriftLengthToTime(float driftLength, float vertexTime) const
{
return (mT0 + vertexTime + driftLength / mVdrift);
}
GPUdi() float TPCFastTransformPOD::convZOffsetToVertexTime(int32_t sector, float zOffset, float maxTimeBin) const
{
if (sector < getGeometry().getNumberOfSectorsA()) {
return maxTimeBin - (getGeometry().getTPCzLength() + zOffset) / mVdrift;
} else {
return maxTimeBin - (getGeometry().getTPCzLength() - zOffset) / mVdrift;
}
}
GPUdi() float TPCFastTransformPOD::convVertexTimeToZOffset(int32_t sector, float vertexTime, float maxTimeBin) const
{
if (sector < getGeometry().getNumberOfSectorsA()) {
return (maxTimeBin - vertexTime) * mVdrift - getGeometry().getTPCzLength();
} else {
return -((maxTimeBin - vertexTime) * mVdrift - getGeometry().getTPCzLength());
}
}
#ifndef GPUCA_GPUCODE_DEVICE // Functions not needed during GPU processing
GPUdi() void TPCFastTransformPOD::setCalibration(int64_t timeStamp, float t0, float vDrift)
{
mTimeStamp = timeStamp;
mT0 = t0;
mVdrift = vDrift;
}
GPUdi() void TPCFastTransformPOD::InverseTransformXYZtoNominalXYZ(int32_t sector, int32_t row, float x, float y, float z, float& nx, float& ny, float& nz) const
{
/// Inverse transformation: Transformed X, Y and Z -> X, Y and Z, transformed w/o space charge correction
int32_t row2 = row + 1;
if (row2 >= getGeometry().getNumberOfRows()) {
row2 = row - 1;
}
float nx1, ny1, nz1; // nominal coordinates for row
float nx2, ny2, nz2; // nominal coordinates for row2
nx1 = getGeometry().getRowInfoX(row);
nx2 = getGeometry().getRowInfoX(row2);
InverseTransformYZtoNominalYZ(sector, row, y, z, ny1, nz1);
InverseTransformYZtoNominalYZ(sector, row2, y, z, ny2, nz2);
float c1 = (nx2 - nx) / (nx2 - nx1);
float c2 = (nx - nx1) / (nx2 - nx1);
nx = x;
ny = (ny1 * c1 + ny2 * c2);
nz = (nz1 * c1 + nz2 * c2);
}
#endif // GPUCA_GPUCODE_DEVICE
} // namespace o2::gpu
#endif