Project
Loading...
Searching...
No Matches
TPCFastTransform.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_TPCFASTTRANSFORM_H
18#define ALICEO2_GPUCOMMON_TPCFASTTRANSFORMATION_TPCFASTTRANSFORM_H
19
20#include "FlatObject.h"
21#include "TPCFastTransformGeo.h"
23#include "GPUCommonMath.h"
24#include "GPUDebugStreamer.h"
25
26#if !defined(GPUCA_GPUCODE)
27#include <string>
28#endif // !GPUCA_GPUCODE
29
30namespace o2::tpc
31{
32template <class T>
33class SpaceCharge;
34}
35
36namespace o2
37{
38namespace gpu
39{
40
43
44#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
47
49 void getCorrections(const float gx, const float gy, const float gz, const int32_t slice, float& gdxC, float& gdyC, float& gdzC) const;
50
52#else
54
56 GPUd() void getCorrections(const float gx, const float gy, const float gz, const int32_t slice, float& gdxC, float& gdyC, float& gdzC) const
57 {
58 gdxC = 0;
59 gdyC = 0;
60 gdzC = 0;
61 }
62#endif
63
65};
66
95
97{
98 public:
99 static constexpr float DEFLUMI = -1e6f; // default value to check if member was set
100 static constexpr float DEFIDC = -1e6f; // default value to check if member was set
101
103
106
109
112
113 inline void destroy()
114 {
115 mCorrection.destroy();
117 }
118
120#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE) && defined(GPUCA_O2_LIB)
122 {
123 delete mCorrectionSlow;
124 }
125#else
126 ~TPCFastTransform() = default;
127#endif
128
130
132
135
138
140
141 void cloneFromObject(const TPCFastTransform& obj, char* newFlatBufferPtr);
142
144
146 void moveBufferTo(char* newBufferPtr);
147
149
150 void setActualBufferAddress(char* actualFlatBufferPtr);
151 void setFutureBufferAddress(char* futureFlatBufferPtr);
152
154
156 void startConstruction(const TPCFastSpaceChargeCorrection& correction);
157
162 void setCalibration(int64_t timeStamp, float t0, float vDrift, float vDriftCorrY, float lDriftCorr, float tofCorr, float primVtxZ);
163
165 void setLumi(float l) { mLumi = l; }
166 void setLumiError(float e) { mLumiError = e; }
167 void setLumiScaleFactor(float s) { mLumiScaleFactor = s; }
168 void setIDC(float l) { mIDC = l; }
169 void setIDCError(float e) { mIDCError = e; }
170 void setCTP2IDCFallBackThreshold(float v) { mCTP2IDCFallBackThreshold = v; }
172 void setTimeStamp(int64_t v) { mTimeStamp = v; }
173
175 GPUd() const TPCFastSpaceChargeCorrection& getCorrection() const { return mCorrection; }
176
179
181 void finishConstruction();
182
188 GPUd() void Transform(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime = 0, const TPCFastTransform* ref = nullptr, const TPCFastTransform* ref2 = nullptr, float scale = 0.f, float scale2 = 0.f, int32_t scaleMode = 0) const;
189 GPUd() void TransformXYZ(int32_t slice, int32_t row, float& x, float& y, float& z, const TPCFastTransform* ref = nullptr, const TPCFastTransform* ref2 = nullptr, float scale = 0.f, float scale2 = 0.f, int32_t scaleMode = 0) const;
190
192 GPUd() void TransformInTimeFrame(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float maxTimeBin) const;
193 GPUd() void TransformInTimeFrame(int32_t slice, float time, float& z, float maxTimeBin) const;
194
196 GPUd() void InverseTransformInTimeFrame(int32_t slice, int32_t row, float /*x*/, float y, float z, float& pad, float& time, float maxTimeBin) const;
197 GPUd() float InverseTransformInTimeFrame(int32_t slice, float z, float maxTimeBin) const;
198
200 GPUd() void InverseTransformYZtoX(int32_t slice, int32_t row, float y, float z, float& x, const TPCFastTransform* ref = nullptr, const TPCFastTransform* ref2 = nullptr, float scale = 0.f, float scale2 = 0.f, int32_t scaleMode = 0) const;
201
203 GPUd() void InverseTransformYZtoNominalYZ(int32_t slice, int32_t row, float y, float z, float& ny, float& nz, const TPCFastTransform* ref = nullptr, const TPCFastTransform* ref2 = nullptr, float scale = 0.f, float scale2 = 0.f, int32_t scaleMode = 0) const;
204
206 GPUd() void InverseTransformXYZtoNominalXYZ(int32_t slice, int32_t row, float x, float y, float z, float& nx, float& ny, float& nz, const TPCFastTransform* ref = nullptr, const TPCFastTransform* ref2 = nullptr, float scale = 0.f, float scale2 = 0.f, int32_t scaleMode = 0) const;
207
209 GPUd() void TransformIdeal(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime) const;
210 GPUd() void TransformIdealZ(int32_t slice, float time, float& z, float vertexTime) const;
211
212 GPUd() void convPadTimeToUV(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float vertexTime) const;
213 GPUd() void convPadTimeToUVinTimeFrame(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float maxTimeBin) const;
214 GPUd() void convTimeToVinTimeFrame(int32_t slice, float time, float& v, float maxTimeBin) const;
215
216 GPUd() void convUVtoPadTime(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float vertexTime) const;
217 GPUd() void convUVtoPadTimeInTimeFrame(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float maxTimeBin) const;
218 GPUd() void convVtoTime(float v, float& time, float vertexTime) const;
219
220 GPUd() float convTimeToZinTimeFrame(int32_t slice, float time, float maxTimeBin) const;
221 GPUd() float convZtoTimeInTimeFrame(int32_t slice, float z, float maxTimeBin) const;
222 GPUd() float convDeltaTimeToDeltaZinTimeFrame(int32_t slice, float deltaTime) const;
223 GPUd() float convDeltaZtoDeltaTimeInTimeFrame(int32_t slice, float deltaZ) const;
224 GPUd() float convDeltaZtoDeltaTimeInTimeFrameAbs(float deltaZ) const;
225 GPUd() float convZOffsetToVertexTime(int32_t slice, float zOffset, float maxTimeBin) const;
226 GPUd() float convVertexTimeToZOffset(int32_t slice, float vertexTime, float maxTimeBin) const;
227
228 GPUd() void getTOFcorrection(int32_t slice, int32_t row, float x, float y, float z, float& dz) const;
229
230 void setApplyCorrectionOn() { mApplyCorrection = 1; }
231 void setApplyCorrectionOff() { mApplyCorrection = 0; }
232 bool isCorrectionApplied() { return mApplyCorrection; }
233
235
237 GPUd() const TPCFastTransformGeo& getGeometry() const { return mCorrection.getGeometry(); }
238
240 GPUd() int64_t getTimeStamp() const { return mTimeStamp; }
241
243 GPUd() float getVDrift() const { return mVdrift; }
244
246 GPUd() float getT0() const { return mT0; }
247
249 GPUd() float getVdriftCorrY() const { return mVdriftCorrY; }
250
252 GPUd() float getLdriftCorr() const { return mLdriftCorr; }
253
255 GPUd() float getTOFCorr() const { return mLdriftCorr; }
256
258 GPUd() float getLumi() const { return mLumi; }
259
260 GPUd() float isLumiSet() const { return mLumi != DEFLUMI; }
261
263 GPUd() float getLumiError() const { return mLumiError; }
264
266 GPUd() float getIDC() const;
267
268 GPUd() bool isIDCSet() const { return mIDC != DEFIDC; }
269
271 GPUd() float getIDCError() const { return mIDCError; }
272
273 GPUd() float getCTP2IDCFallBackThreshold() const { return mCTP2IDCFallBackThreshold; }
274
276 GPUd() float getLumiScaleFactor() const { return mLumiScaleFactor; }
277
279 GPUd() float getMaxDriftTime(int32_t slice, int32_t row, float pad) const;
280
282 GPUd() float getMaxDriftTime(int32_t slice, int32_t row) const;
283
285 GPUd() float getMaxDriftTime(int32_t slice) const;
286
287#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
288
289 int32_t writeToFile(std::string outFName = "", std::string name = "");
290
292
293 static TPCFastTransform* loadFromFile(std::string inpFName = "", std::string name = "");
294
296 void setSlowTPCSCCorrection(TFile& inpf);
297
299 const auto& getCorrectionSlow() const { return *mCorrectionSlow; }
300
301#endif // !GPUCA_GPUCODE
302
304 void print() const;
305
306 private:
308 enum ConstructionExtraState : uint32_t {
309 CalibrationIsSet = 0x4
310 };
311
313
315
317
318 int64_t mTimeStamp;
319
325 TPCFastSpaceChargeCorrection mCorrection;
326
327 bool mApplyCorrection; // flag for applying correction
328
335 float mT0;
336 float mVdrift;
337 float mVdriftCorrY;
338 float mLdriftCorr;
339
347 float mTOFcorr;
348
349 float mPrimVtxZ;
350
351 float mLumi;
352 float mLumiError;
353 float mLumiScaleFactor;
354
355 float mIDC;
356 float mIDCError;
357 float mCTP2IDCFallBackThreshold;
358
360 TPCSlowSpaceChargeCorrection* mCorrectionSlow{nullptr};
361
362 GPUd() void TransformInternal(int32_t slice, int32_t row, float& u, float& v, float& x, const TPCFastTransform* ref, const TPCFastTransform* ref2, float scale, float scale2, int32_t scaleMode) const;
363
364 ClassDefNV(TPCFastTransform, 4);
365};
366
367// =======================================================================
368// Inline implementations of some methods
369// =======================================================================
370
371GPUdi() void TPCFastTransform::convPadTimeToUV(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float vertexTime) const
372{
373 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
374
375 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
376 const TPCFastTransformGeo::SliceInfo& sliceInfo = getGeometry().getSliceInfo(slice);
377
378 float x = rowInfo.x;
379 u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
380
381 float y = sideC ? -u : u; // pads are mirrorred on C-side
382 float yLab = y * sliceInfo.cosAlpha + x * sliceInfo.sinAlpha;
383
384 v = (time - mT0 - vertexTime) * (mVdrift + mVdriftCorrY * yLab) + mLdriftCorr; // drift length cm
385}
386
387GPUdi() void TPCFastTransform::convTimeToVinTimeFrame(int32_t slice, float time, float& v, float maxTimeBin) const
388{
389 v = (time - mT0 - maxTimeBin) * mVdrift + mLdriftCorr; // drift length cm
390 if (slice < getGeometry().getNumberOfSlicesA()) {
391 v += getGeometry().getTPCzLengthA();
392 } else {
393 v += getGeometry().getTPCzLengthC();
394 }
395}
396
397GPUdi() void TPCFastTransform::convPadTimeToUVinTimeFrame(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float maxTimeBin) const
398{
399 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
400 u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
401 convTimeToVinTimeFrame(slice, time, v, maxTimeBin);
402}
403
404GPUdi() float TPCFastTransform::convZOffsetToVertexTime(int32_t slice, float zOffset, float maxTimeBin) const
405{
406 if (slice < getGeometry().getNumberOfSlicesA()) {
407 return maxTimeBin - (getGeometry().getTPCzLengthA() + zOffset) / mVdrift;
408 } else {
409 return maxTimeBin - (getGeometry().getTPCzLengthC() - zOffset) / mVdrift;
410 }
411}
412
413GPUdi() float TPCFastTransform::convVertexTimeToZOffset(int32_t slice, float vertexTime, float maxTimeBin) const
414{
415 if (slice < getGeometry().getNumberOfSlicesA()) {
416 return (maxTimeBin - vertexTime) * mVdrift - getGeometry().getTPCzLengthA();
417 } else {
418 return -((maxTimeBin - vertexTime) * mVdrift - getGeometry().getTPCzLengthC());
419 }
420}
421
422GPUdi() void TPCFastTransform::convUVtoPadTime(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float vertexTime) const
423{
424 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
425
426 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
427 const TPCFastTransformGeo::SliceInfo& sliceInfo = getGeometry().getSliceInfo(slice);
428
429 pad = u / rowInfo.padWidth + 0.5f * rowInfo.maxPad;
430
431 float x = rowInfo.x;
432 float y = sideC ? -u : u; // pads are mirrorred on C-side
433 float yLab = y * sliceInfo.cosAlpha + x * sliceInfo.sinAlpha;
434 time = mT0 + vertexTime + (v - mLdriftCorr) / (mVdrift + mVdriftCorrY * yLab);
435}
436
437GPUdi() void TPCFastTransform::convVtoTime(float v, float& time, float vertexTime) const
438{
439 float yLab = 0.f;
440 time = mT0 + vertexTime + (v - mLdriftCorr) / (mVdrift + mVdriftCorrY * yLab);
441}
442
443GPUdi() void TPCFastTransform::convUVtoPadTimeInTimeFrame(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float maxTimeBin) const
444{
445 if (slice < getGeometry().getNumberOfSlicesA()) {
446 v -= getGeometry().getTPCzLengthA();
447 } else {
448 v -= getGeometry().getTPCzLengthC();
449 }
450 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
451 pad = u / rowInfo.padWidth + 0.5f * rowInfo.maxPad;
452 time = mT0 + maxTimeBin + (v - mLdriftCorr) / mVdrift;
453}
454
455GPUdi() void TPCFastTransform::getTOFcorrection(int32_t slice, int32_t /*row*/, float x, float y, float z, float& dz) const
456{
457 // calculate time of flight correction for z coordinate
458
459 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
460 float distZ = z - mPrimVtxZ;
461 float dv = -GPUCommonMath::Sqrt(x * x + y * y + distZ * distZ) * mTOFcorr;
462 dz = sideC ? dv : -dv;
463}
464
465GPUdi() void TPCFastTransform::TransformInternal(int32_t slice, int32_t row, float& u, float& v, float& x, const TPCFastTransform* ref, const TPCFastTransform* ref2, float scale, float scale2, int32_t scaleMode) const
466{
467 GPUCA_RTC_SPECIAL_CODE(ref2 = nullptr; scale2 = 0.f;);
468 if (mApplyCorrection) {
469 float dx = 0.f, du = 0.f, dv = 0.f;
470 if ((scale >= 0.f) || (scaleMode == 1) || (scaleMode == 2)) {
471#ifndef GPUCA_GPUCODE
472 if (mCorrectionSlow) {
473 float ly, lz;
474 getGeometry().convUVtoLocal(slice, u, v, ly, lz);
475 float gx, gy, gz;
476 getGeometry().convLocalToGlobal(slice, x, ly, lz, gx, gy, gz);
477
478 float gdxC, gdyC, gdzC;
479 mCorrectionSlow->getCorrections(gx, gy, gz, slice, gdxC, gdyC, gdzC);
480 getGeometry().convGlobalToLocal(slice, gdxC, gdyC, gdzC, dx, du, dv);
481
482 if (slice >= 18) {
483 du = -du; // mirror for c-Side
484 } else {
485 dv = -dv; // mirror z for A-Side
486 }
487 } else
488#endif // GPUCA_GPUCODE
489 {
490 mCorrection.getCorrection(slice, row, u, v, dx, du, dv);
491 if (ref) {
492 if ((scale > 0.f) && (scaleMode == 0)) { // scaling was requested
493 float dxRef, duRef, dvRef;
494 ref->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
495 dx = (dx - dxRef) * scale + dxRef;
496 du = (du - duRef) * scale + duRef;
497 dv = (dv - dvRef) * scale + dvRef;
498 } else if ((scale != 0.f) && ((scaleMode == 1) || (scaleMode == 2))) {
499 float dxRef, duRef, dvRef;
500 ref->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
501 dx = dxRef * scale + dx;
502 du = duRef * scale + du;
503 dv = dvRef * scale + dv;
504 }
505 }
506 if (ref2 && (scale2 != 0)) {
507 float dxRef, duRef, dvRef;
508 ref2->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
509 dx = dxRef * scale2 + dx;
510 du = duRef * scale2 + du;
511 dv = dvRef * scale2 + dv;
512 }
513 }
514 }
515 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
516 float ly, lz;
517 getGeometry().convUVtoLocal(slice, u, v, ly, lz);
518
519 float gx, gy, gz;
520 getGeometry().convLocalToGlobal(slice, x, ly, lz, gx, gy, gz);
521
522 float lyT, lzT;
523 float uCorr = u + du;
524 float vCorr = v + dv;
525 float lxT = x + dx;
526 getGeometry().convUVtoLocal(slice, uCorr, vCorr, lyT, lzT);
527
528 float invYZtoXScaled;
529 InverseTransformYZtoX(slice, row, lyT, lzT, invYZtoXScaled, ref, ref2, scale, scale2, scaleMode);
530
531 float invYZtoX;
532 InverseTransformYZtoX(slice, row, lyT, lzT, invYZtoX);
533
534 float YZtoNominalY;
535 float YZtoNominalZ;
536 InverseTransformYZtoNominalYZ(slice, row, lyT, lzT, YZtoNominalY, YZtoNominalZ);
537
538 float YZtoNominalYScaled;
539 float YZtoNominalZScaled;
540 InverseTransformYZtoNominalYZ(slice, row, lyT, lzT, YZtoNominalYScaled, YZtoNominalZScaled, ref, ref2, scale, scale2, scaleMode);
541
542 float dxRef, duRef, dvRef;
543 if (ref) {
544 ref->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
545 }
546
547 float dxRef2, duRef2, dvRef2;
548 if (ref2) {
549 ref2->mCorrection.getCorrection(slice, row, u, v, dxRef2, duRef2, dvRef2);
550 }
551
552 float dxOrig, duOrig, dvOrig;
553 mCorrection.getCorrection(slice, row, u, v, dxOrig, duOrig, dvOrig);
554
555 o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_Transform").data()
556 // corrections in x, u, v
557 << "dxOrig=" << dxOrig
558 << "duOrig=" << duOrig
559 << "dvOrig=" << dvOrig
560 << "dxRef=" << dxRef
561 << "duRef=" << duRef
562 << "dvRef=" << dvRef
563 << "dxRef2=" << dxRef2
564 << "duRef2=" << duRef2
565 << "dvRef2=" << dvRef2
566 << "dx=" << dx
567 << "du=" << du
568 << "dv=" << dv
569 << "v=" << v
570 << "u=" << u
571 << "row=" << row
572 << "slice=" << slice
573 << "scale=" << scale
574 << "scale2=" << scale2
575 // original local coordinates
576 << "ly=" << ly
577 << "lz=" << lz
578 << "lx=" << x
579 // corrected local coordinated
580 << "lxT=" << lxT
581 << "lyT=" << lyT
582 << "lzT=" << lzT
583 // global uncorrected coordinates
584 << "gx=" << gx
585 << "gy=" << gy
586 << "gz=" << gz
587 // some transformations which are applied
588 << "invYZtoX=" << invYZtoX
589 << "invYZtoXScaled=" << invYZtoXScaled
590 << "YZtoNominalY=" << YZtoNominalY
591 << "YZtoNominalYScaled=" << YZtoNominalYScaled
592 << "YZtoNominalZ=" << YZtoNominalZ
593 << "YZtoNominalZScaled=" << YZtoNominalZScaled
594 << "scaleMode=" << scaleMode
595 << "\n";
596 })
597
598 x += dx;
599 u += du;
600 v += dv;
601 }
602}
603
604GPUdi() void TPCFastTransform::TransformXYZ(int32_t slice, int32_t row, float& x, float& y, float& z, const TPCFastTransform* ref, const TPCFastTransform* ref2, float scale, float scale2, int32_t scaleMode) const
605{
606 float u, v;
607 getGeometry().convLocalToUV(slice, y, z, u, v);
608 TransformInternal(slice, row, u, v, x, ref, ref2, scale, scale2, scaleMode);
609 getGeometry().convUVtoLocal(slice, u, v, y, z);
610 float dzTOF = 0;
611 getTOFcorrection(slice, row, x, y, z, dzTOF);
612 z += dzTOF;
613}
614
615GPUdi() void TPCFastTransform::Transform(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime, const TPCFastTransform* ref, const TPCFastTransform* ref2, float scale, float scale2, int32_t scaleMode) const
616{
622
623 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
624
625 // const SliceInfo &sliceInfo = getSliceInfo( slice );
626 // bool sideC = ( slice >= NumberOfSlices / 2 );
627
628 x = rowInfo.x;
629 float u = 0, v = 0;
630 convPadTimeToUV(slice, row, pad, time, u, v, vertexTime);
631
632 TransformInternal(slice, row, u, v, x, ref, ref2, scale, scale2, scaleMode);
633
634 getGeometry().convUVtoLocal(slice, u, v, y, z);
635
636 float dzTOF = 0;
637 getTOFcorrection(slice, row, x, y, z, dzTOF);
638 z += dzTOF;
639}
640
641GPUdi() void TPCFastTransform::TransformInTimeFrame(int32_t slice, float time, float& z, float maxTimeBin) const
642{
643 float v = 0;
644 convTimeToVinTimeFrame(slice, time, v, maxTimeBin);
645 getGeometry().convVtoLocal(slice, v, z);
646}
647
648GPUdi() void TPCFastTransform::TransformInTimeFrame(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float maxTimeBin) const
649{
655
656 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
657 x = rowInfo.x;
658 float u = 0, v = 0;
659 convPadTimeToUVinTimeFrame(slice, row, pad, time, u, v, maxTimeBin);
660 getGeometry().convUVtoLocal(slice, u, v, y, z);
661}
662
663GPUdi() void TPCFastTransform::InverseTransformInTimeFrame(int32_t slice, int32_t row, float /*x*/, float y, float z, float& pad, float& time, float maxTimeBin) const
664{
666 float u = 0, v = 0;
667 getGeometry().convLocalToUV(slice, y, z, u, v);
668 convUVtoPadTimeInTimeFrame(slice, row, u, v, pad, time, maxTimeBin);
669}
670
671GPUdi() float TPCFastTransform::InverseTransformInTimeFrame(int32_t slice, float z, float maxTimeBin) const
672{
673 float pad, time;
674 InverseTransformInTimeFrame(slice, 0, 0, 0, z, pad, time, maxTimeBin);
675 return time;
676}
677
678GPUdi() void TPCFastTransform::TransformIdealZ(int32_t slice, float time, float& z, float vertexTime) const
679{
686
687 float v = (time - mT0 - vertexTime) * mVdrift; // drift length cm
688 getGeometry().convVtoLocal(slice, v, z);
689}
690
691GPUdi() void TPCFastTransform::TransformIdeal(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime) const
692{
699
700 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
701
702 x = rowInfo.x;
703 float u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
704 float v = (time - mT0 - vertexTime) * mVdrift; // drift length cm
705
706 getGeometry().convUVtoLocal(slice, u, v, y, z);
707}
708
709GPUdi() float TPCFastTransform::convTimeToZinTimeFrame(int32_t slice, float time, float maxTimeBin) const
710{
717
718 float v = (time - mT0 - maxTimeBin) * mVdrift + mLdriftCorr; // drift length cm
719 float z = getGeometry().getTPCalignmentZ(); // global TPC alignment
720 if (slice < getGeometry().getNumberOfSlicesA()) {
721 z -= v;
722 } else {
723 z += v;
724 }
725 return z;
726}
727
728GPUdi() float TPCFastTransform::convZtoTimeInTimeFrame(int32_t slice, float z, float maxTimeBin) const
729{
731 float v;
732 if (slice < getGeometry().getNumberOfSlicesA()) {
733 v = getGeometry().getTPCalignmentZ() - z;
734 } else {
735 v = z - getGeometry().getTPCalignmentZ();
736 }
737 return mT0 + maxTimeBin + (v - mLdriftCorr) / mVdrift;
738}
739
740GPUdi() float TPCFastTransform::convDeltaTimeToDeltaZinTimeFrame(int32_t slice, float deltaTime) const
741{
742 float deltaZ = deltaTime * mVdrift;
743 return slice < getGeometry().getNumberOfSlicesA() ? -deltaZ : deltaZ;
744}
745
746GPUdi() float TPCFastTransform::convDeltaZtoDeltaTimeInTimeFrameAbs(float deltaZ) const
747{
748 return deltaZ / mVdrift;
749}
750
751GPUdi() float TPCFastTransform::convDeltaZtoDeltaTimeInTimeFrame(int32_t slice, float deltaZ) const
752{
753 float deltaT = deltaZ / mVdrift;
754 return slice < getGeometry().getNumberOfSlicesA() ? -deltaT : deltaT;
755}
756
757/*
758GPUdi() float TPCFastTransform::getLastCalibratedTimeBin(int32_t slice) const
759{
761 float u, v, pad, time;
762 getGeometry().convScaledUVtoUV(slice, 0, 0.f, 1.f, u, v);
763 convUVtoPadTime(slice, 0, u, v, pad, time, 0);
764 return time;
765}
766*/
767
768GPUdi() float TPCFastTransform::getMaxDriftTime(int32_t slice, int32_t row, float pad) const
769{
771 float maxL = mCorrection.getMaxDriftLength(slice, row, pad);
772
773 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
774 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
775 const TPCFastTransformGeo::SliceInfo& sliceInfo = getGeometry().getSliceInfo(slice);
776
777 float x = rowInfo.x;
778 float u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
779
780 float y = sideC ? -u : u; // pads are mirrorred on C-side
781 float yLab = y * sliceInfo.cosAlpha + x * sliceInfo.sinAlpha;
782 return mT0 + (maxL - mLdriftCorr) / (mVdrift + mVdriftCorrY * yLab);
783}
784
785GPUdi() float TPCFastTransform::getMaxDriftTime(int32_t slice, int32_t row) const
786{
788 float maxL = mCorrection.getMaxDriftLength(slice, row);
789 float maxTime = 0.f;
790 convVtoTime(maxL, maxTime, 0.f);
791 return maxTime;
792}
793
794GPUdi() float TPCFastTransform::getMaxDriftTime(int32_t slice) const
795{
797 float maxL = mCorrection.getMaxDriftLength(slice);
798 float maxTime = 0.f;
799 convVtoTime(maxL, maxTime, 0.f);
800 return maxTime;
801}
802
803GPUdi() void TPCFastTransform::InverseTransformYZtoX(int32_t slice, int32_t row, float y, float z, float& x, const TPCFastTransform* ref, const TPCFastTransform* ref2, float scale, float scale2, int32_t scaleMode) const
804{
805 GPUCA_RTC_SPECIAL_CODE(ref2 = nullptr; scale2 = 0.f;);
807 float u = 0, v = 0;
808 getGeometry().convLocalToUV(slice, y, z, u, v);
809 if ((scale >= 0.f) || (scaleMode == 1) || (scaleMode == 2)) {
810 mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, x);
811 if (ref) { // scaling was requested
812 if (scaleMode == 0 && scale > 0.f) {
813 float xr;
814 ref->mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, xr);
815 x = (x - xr) * scale + xr;
816 } else if ((scale != 0) && ((scaleMode == 1) || (scaleMode == 2))) {
817 float xr;
818 ref->mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, xr);
819 x = (xr - getGeometry().getRowInfo(row).x) * scale + x; // xr=mGeo.getRowInfo(row).x + dx;
820 }
821 }
822 if (ref2 && (scale2 != 0)) {
823 float xr;
824 ref2->mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, xr);
825 x = (xr - getGeometry().getRowInfo(row).x) * scale2 + x; // xr=mGeo.getRowInfo(row).x + dx;
826 }
827 } else {
828 x = mCorrection.getGeometry().getRowInfo(row).x; // corrections are disabled
829 }
830 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
831 o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_InverseTransformYZtoX").data()
832 << "slice=" << slice
833 << "row=" << row
834 << "scale=" << scale
835 << "y=" << y
836 << "z=" << z
837 << "x=" << x
838 << "v=" << v
839 << "u=" << u
840 << "\n";
841 })
842}
843
844GPUdi() void TPCFastTransform::InverseTransformYZtoNominalYZ(int32_t slice, int32_t row, float y, float z, float& ny, float& nz, const TPCFastTransform* ref, const TPCFastTransform* ref2, float scale, float scale2, int32_t scaleMode) const
845{
846 GPUCA_RTC_SPECIAL_CODE(ref2 = nullptr; scale2 = 0.f;);
848 float u = 0, v = 0, un = 0, vn = 0;
849 getGeometry().convLocalToUV(slice, y, z, u, v);
850 if ((scale >= 0.f) || (scaleMode == 1) || (scaleMode == 2)) {
851 mCorrection.getCorrectionInvUV(slice, row, u, v, un, vn);
852 if (ref) { // scaling was requested
853 if (scaleMode == 0 && scale > 0.f) {
854 float unr = 0, vnr = 0;
855 ref->mCorrection.getCorrectionInvUV(slice, row, u, v, unr, vnr);
856 un = (un - unr) * scale + unr;
857 vn = (vn - vnr) * scale + vnr;
858 } else if ((scale != 0) && ((scaleMode == 1) || (scaleMode == 2))) {
859 float unr = 0, vnr = 0;
860 ref->mCorrection.getCorrectionInvUV(slice, row, u, v, unr, vnr);
861 un = (unr - u) * scale + un; // unr = u - duv[0];
862 vn = (vnr - v) * scale + vn;
863 }
864 if (ref2 && (scale2 != 0)) {
865 float unr = 0, vnr = 0;
866 ref2->mCorrection.getCorrectionInvUV(slice, row, u, v, unr, vnr);
867 un = (unr - u) * scale2 + un; // unr = u - duv[0];
868 vn = (vnr - v) * scale2 + vn;
869 }
870 }
871 } else {
872 un = u;
873 vn = v;
874 }
875 getGeometry().convUVtoLocal(slice, un, vn, ny, nz);
876
877 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
878 o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_InverseTransformYZtoNominalYZ").data()
879 << "slice=" << slice
880 << "row=" << row
881 << "scale=" << scale
882 << "y=" << y
883 << "z=" << z
884 << "ny=" << ny
885 << "nz=" << nz
886 << "u=" << u
887 << "v=" << v
888 << "un=" << un
889 << "vn=" << vn
890 << "\n";
891 })
892}
893
894GPUdi() void TPCFastTransform::InverseTransformXYZtoNominalXYZ(int32_t slice, int32_t row, float x, float y, float z, float& nx, float& ny, float& nz, const TPCFastTransform* ref, const TPCFastTransform* ref2, float scale, float scale2, int32_t scaleMode) const
895{
897 int32_t row2 = row + 1;
898 if (row2 >= getGeometry().getNumberOfRows()) {
899 row2 = row - 1;
900 }
901 float nx1, ny1, nz1; // nominal coordinates for row
902 float nx2, ny2, nz2; // nominal coordinates for row2
903 nx1 = getGeometry().getRowInfo(row).x;
904 nx2 = getGeometry().getRowInfo(row2).x;
905 InverseTransformYZtoNominalYZ(slice, row, y, z, ny1, nz1, ref, ref2, scale, scale2, scaleMode);
906 InverseTransformYZtoNominalYZ(slice, row2, y, z, ny2, nz2, ref, ref2, scale, scale2, scaleMode);
907 float c1 = (nx2 - nx) / (nx2 - nx1);
908 float c2 = (nx - nx1) / (nx2 - nx1);
909 nx = x;
910 ny = (ny1 * c1 + ny2 * c2);
911 nz = (nz1 * c1 + nz2 * c2);
912}
913
914} // namespace gpu
915} // namespace o2
916
917#endif
Definition of FlatObject class.
#define GPUCA_DEBUG_STREAMER_CHECK(...)
#define GPUCA_RTC_SPECIAL_CODE(...)
Definition of TPCFastSpaceChargeCorrection class.
Definition of TPCFastTransformGeo class.
GPUCA_GPUCODE.
Definition FlatObject.h:176
char * releaseInternalBuffer()
_____________ Methods for making the data buffer external __________________________
Definition FlatObject.h:526
void destroy()
_______________ Utilities _______________________________________________
Definition FlatObject.h:349
void startConstruction()
_____________ Construction _________
Definition FlatObject.h:342
static constexpr size_t getBufferAlignmentBytes()
_____________ FlatObject functionality, see FlatObject class for description ____________
Definition FlatObject.h:197
static constexpr size_t getClassAlignmentBytes()
_____________ Memory alignment __________________________
Definition FlatObject.h:194
GPUd() float getVDrift() const
Return mVDrift in cm / time bin.
void setActualBufferAddress(char *actualFlatBufferPtr)
Moving the class with its external buffer to another location.
int32_t float float float float float & z
int32_t float float float float float float maxTimeBin const
int32_t float float float float float float const TPCFastTransform const TPCFastTransform float float int32_t scaleMode
void setLumi(float l)
Set Lumi info.
void finishConstruction()
Finishes initialization: puts everything to the flat buffer, releases temporary memory.
void moveBufferTo(char *newBufferPtr)
GPUd() float getIDC() const
Return map lumi.
void setTimeStamp(int64_t v)
Sets the time stamp of the current calibaration.
void cloneFromObject(const TPCFastTransform &obj, char *newFlatBufferPtr)
Construction interface.
TPCFastTransform(const TPCFastTransform &)=delete
Copy constructor: disabled to avoid ambiguity. Use cloneFromObject() instead.
static constexpr size_t getBufferAlignmentBytes()
Gives minimal alignment in bytes required for the flat buffer.
static constexpr float DEFLUMI
void setCalibration(int64_t timeStamp, float t0, float vDrift, float vDriftCorrY, float lDriftCorr, float tofCorr, float primVtxZ)
int32_t writeToFile(std::string outFName="", std::string name="")
GPUd() float getLumiError() const
Return map lumi error.
void setCTP2IDCFallBackThreshold(float v)
int32_t float float float float float float vertexTime
int32_t float float float float float float const TPCFastTransform const TPCFastTransform float scale
void setSlowTPCSCCorrection(TFile &inpf)
setting the reference corrections
static constexpr size_t getClassAlignmentBytes()
_____________ FlatObject functionality, see FlatObject class for description ____________
TPCFastSpaceChargeCorrection & getCorrection()
Gives a reference for external initialization of TPC corrections.
int32_t float float float float & v
GPUd() float getLumiScaleFactor() const
Return map user defined lumi scale factor.
GPUd() float getVdriftCorrY() const
Return VdriftCorrY in time_bin / cn.
int32_t float float float float & nz
~TPCFastTransform()=default
Destructor.
TPCFastTransform()
_____________ Constructors / destructors __________________________
GPUd() float getCTP2IDCFallBackThreshold() const
GPUd() float isLumiSet() const
static TPCFastTransform * loadFromFile(std::string inpFName="", std::string name="")
GPUd() float getTOFCorr() const
Return TOF correction (vdrift / C)
void setFutureBufferAddress(char *futureFlatBufferPtr)
int32_t float float float float float float const TPCFastTransform const TPCFastTransform float float scale2
int32_t float float float float float float const TPCFastTransform const TPCFastTransform * ref2
TPCFastTransform & operator=(const TPCFastTransform &)=delete
Assignment operator: disabled to avoid ambiguity. Use cloneFromObject() instead.
GPUd() int64_t getTimeStamp() const
Gives the time stamp of the current calibaration parameters.
void print() const
Print method.
GPUd() float getLumi() const
Return map lumi.
int32_t float float float & u
int32_t float float float & ny
int32_t float float float & x
GPUd() const TPCFastSpaceChargeCorrection &getCorrection() const
Gives a reference for external initialization of TPC corrections.
static constexpr float DEFIDC
GPUd() float getIDCError() const
Return map lumi error.
const auto & getCorrectionSlow() const
GPUd() const TPCFastTransformGeo &getGeometry() const
_______________ Utilities _______________________________________________
GPUd() void Transform(int32_t slice
GPUd() float getT0() const
Return T0 in time bin units.
int32_t float float float float & nx
GPUd() float getLdriftCorr() const
Return LdriftCorr offset in cm.
GLint GLenum GLint x
Definition glcorearb.h:403
const GLdouble * v
Definition glcorearb.h:832
GLuint const GLchar * name
Definition glcorearb.h:781
GLdouble f
Definition glcorearb.h:310
typedef void(APIENTRYP PFNGLCULLFACEPROC)(GLenum mode)
GLuint GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat GLfloat t0
Definition glcorearb.h:5034
GLdouble GLdouble GLdouble z
Definition glcorearb.h:843
GPUdi() o2
Definition TrackTRD.h:38
GPUd() const expr uint32_t MultivariatePolynomialHelper< Dim
Global TPC definitions and constants.
Definition SimTraits.h:168
@ streamFastTransform
stream tpc fast transform
a couple of static helper functions to create timestamp values for CCDB queries or override obsolete ...
simple struct to hold the space charge object which can be used for CPU reconstruction only
ClassDefNV(TPCSlowSpaceChargeCorrection, 2)
o2::tpc::SpaceCharge< float > * mCorr
reference space charge corrections
void getCorrections(const float gx, const float gy, const float gz, const int32_t slice, float &gdxC, float &gdyC, float &gdzC) const
getting the corrections for global coordinates