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
199 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;
200
202 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;
203
205 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;
206
208 GPUd() void TransformIdeal(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime) const;
209 GPUd() void TransformIdealZ(int32_t slice, float time, float& z, float vertexTime) const;
210
211 GPUd() void convPadTimeToUV(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float vertexTime) const;
212 GPUd() void convPadTimeToUVinTimeFrame(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float maxTimeBin) const;
213 GPUd() void convTimeToVinTimeFrame(int32_t slice, float time, float& v, float maxTimeBin) const;
214
215 GPUd() void convUVtoPadTime(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float vertexTime) const;
216 GPUd() void convUVtoPadTimeInTimeFrame(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float maxTimeBin) const;
217 GPUd() void convVtoTime(float v, float& time, float vertexTime) const;
218
219 GPUd() float convTimeToZinTimeFrame(int32_t slice, float time, float maxTimeBin) const;
220 GPUd() float convZtoTimeInTimeFrame(int32_t slice, float z, float maxTimeBin) const;
221 GPUd() float convDeltaTimeToDeltaZinTimeFrame(int32_t slice, float deltaTime) const;
222 GPUd() float convDeltaZtoDeltaTimeInTimeFrame(int32_t slice, float deltaZ) const;
223 GPUd() float convDeltaZtoDeltaTimeInTimeFrameAbs(float deltaZ) const;
224 GPUd() float convZOffsetToVertexTime(int32_t slice, float zOffset, float maxTimeBin) const;
225 GPUd() float convVertexTimeToZOffset(int32_t slice, float vertexTime, float maxTimeBin) const;
226
227 GPUd() void getTOFcorrection(int32_t slice, int32_t row, float x, float y, float z, float& dz) const;
228
229 void setApplyCorrectionOn() { mApplyCorrection = 1; }
230 void setApplyCorrectionOff() { mApplyCorrection = 0; }
231 bool isCorrectionApplied() { return mApplyCorrection; }
232
234
236 GPUd() const TPCFastTransformGeo& getGeometry() const { return mCorrection.getGeometry(); }
237
239 GPUd() int64_t getTimeStamp() const { return mTimeStamp; }
240
242 GPUd() float getVDrift() const { return mVdrift; }
243
245 GPUd() float getT0() const { return mT0; }
246
248 GPUd() float getVdriftCorrY() const { return mVdriftCorrY; }
249
251 GPUd() float getLdriftCorr() const { return mLdriftCorr; }
252
254 GPUd() float getTOFCorr() const { return mLdriftCorr; }
255
257 GPUd() float getLumi() const { return mLumi; }
258
259 GPUd() float isLumiSet() const { return mLumi != DEFLUMI; }
260
262 GPUd() float getLumiError() const { return mLumiError; }
263
265 GPUd() float getIDC() const;
266
267 GPUd() bool isIDCSet() const { return mIDC != DEFIDC; }
268
270 GPUd() float getIDCError() const { return mIDCError; }
271
272 GPUd() float getCTP2IDCFallBackThreshold() const { return mCTP2IDCFallBackThreshold; }
273
275 GPUd() float getLumiScaleFactor() const { return mLumiScaleFactor; }
276
278 GPUd() float getMaxDriftTime(int32_t slice, int32_t row, float pad) const;
279
281 GPUd() float getMaxDriftTime(int32_t slice, int32_t row) const;
282
284 GPUd() float getMaxDriftTime(int32_t slice) const;
285
286#if !defined(GPUCA_GPUCODE) && !defined(GPUCA_STANDALONE)
287
288 int32_t writeToFile(std::string outFName = "", std::string name = "");
289
291
292 static TPCFastTransform* loadFromFile(std::string inpFName = "", std::string name = "");
293
295 void setSlowTPCSCCorrection(TFile& inpf);
296
298 const auto& getCorrectionSlow() const { return *mCorrectionSlow; }
299
300#endif // !GPUCA_GPUCODE
301
303 void print() const;
304
305 private:
307 enum ConstructionExtraState : uint32_t {
308 CalibrationIsSet = 0x4
309 };
310
312
314
316
317 int64_t mTimeStamp;
318
324 TPCFastSpaceChargeCorrection mCorrection;
325
326 bool mApplyCorrection; // flag for applying correction
327
334 float mT0;
335 float mVdrift;
336 float mVdriftCorrY;
337 float mLdriftCorr;
338
346 float mTOFcorr;
347
348 float mPrimVtxZ;
349
350 float mLumi;
351 float mLumiError;
352 float mLumiScaleFactor;
353
354 float mIDC;
355 float mIDCError;
356 float mCTP2IDCFallBackThreshold;
357
359 TPCSlowSpaceChargeCorrection* mCorrectionSlow{nullptr};
360
361 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;
362
363 ClassDefNV(TPCFastTransform, 4);
364};
365
366// =======================================================================
367// Inline implementations of some methods
368// =======================================================================
369
370GPUdi() void TPCFastTransform::convPadTimeToUV(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float vertexTime) const
371{
372 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
373
374 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
375 const TPCFastTransformGeo::SliceInfo& sliceInfo = getGeometry().getSliceInfo(slice);
376
377 float x = rowInfo.x;
378 u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
379
380 float y = sideC ? -u : u; // pads are mirrorred on C-side
381 float yLab = y * sliceInfo.cosAlpha + x * sliceInfo.sinAlpha;
382
383 v = (time - mT0 - vertexTime) * (mVdrift + mVdriftCorrY * yLab) + mLdriftCorr; // drift length cm
384}
385
386GPUdi() void TPCFastTransform::convTimeToVinTimeFrame(int32_t slice, float time, float& v, float maxTimeBin) const
387{
388 v = (time - mT0 - maxTimeBin) * mVdrift + mLdriftCorr; // drift length cm
389 if (slice < getGeometry().getNumberOfSlicesA()) {
390 v += getGeometry().getTPCzLengthA();
391 } else {
392 v += getGeometry().getTPCzLengthC();
393 }
394}
395
396GPUdi() void TPCFastTransform::convPadTimeToUVinTimeFrame(int32_t slice, int32_t row, float pad, float time, float& u, float& v, float maxTimeBin) const
397{
398 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
399 u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
400 convTimeToVinTimeFrame(slice, time, v, maxTimeBin);
401}
402
403GPUdi() float TPCFastTransform::convZOffsetToVertexTime(int32_t slice, float zOffset, float maxTimeBin) const
404{
405 if (slice < getGeometry().getNumberOfSlicesA()) {
406 return maxTimeBin - (getGeometry().getTPCzLengthA() + zOffset) / mVdrift;
407 } else {
408 return maxTimeBin - (getGeometry().getTPCzLengthC() - zOffset) / mVdrift;
409 }
410}
411
412GPUdi() float TPCFastTransform::convVertexTimeToZOffset(int32_t slice, float vertexTime, float maxTimeBin) const
413{
414 if (slice < getGeometry().getNumberOfSlicesA()) {
415 return (maxTimeBin - vertexTime) * mVdrift - getGeometry().getTPCzLengthA();
416 } else {
417 return -((maxTimeBin - vertexTime) * mVdrift - getGeometry().getTPCzLengthC());
418 }
419}
420
421GPUdi() void TPCFastTransform::convUVtoPadTime(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float vertexTime) const
422{
423 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
424
425 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
426 const TPCFastTransformGeo::SliceInfo& sliceInfo = getGeometry().getSliceInfo(slice);
427
428 pad = u / rowInfo.padWidth + 0.5f * rowInfo.maxPad;
429
430 float x = rowInfo.x;
431 float y = sideC ? -u : u; // pads are mirrorred on C-side
432 float yLab = y * sliceInfo.cosAlpha + x * sliceInfo.sinAlpha;
433 time = mT0 + vertexTime + (v - mLdriftCorr) / (mVdrift + mVdriftCorrY * yLab);
434}
435
436GPUdi() void TPCFastTransform::convVtoTime(float v, float& time, float vertexTime) const
437{
438 float yLab = 0.f;
439 time = mT0 + vertexTime + (v - mLdriftCorr) / (mVdrift + mVdriftCorrY * yLab);
440}
441
442GPUdi() void TPCFastTransform::convUVtoPadTimeInTimeFrame(int32_t slice, int32_t row, float u, float v, float& pad, float& time, float maxTimeBin) const
443{
444 if (slice < getGeometry().getNumberOfSlicesA()) {
445 v -= getGeometry().getTPCzLengthA();
446 } else {
447 v -= getGeometry().getTPCzLengthC();
448 }
449 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
450 pad = u / rowInfo.padWidth + 0.5f * rowInfo.maxPad;
451 time = mT0 + maxTimeBin + (v - mLdriftCorr) / mVdrift;
452}
453
454GPUdi() void TPCFastTransform::getTOFcorrection(int32_t slice, int32_t /*row*/, float x, float y, float z, float& dz) const
455{
456 // calculate time of flight correction for z coordinate
457
458 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
459 float distZ = z - mPrimVtxZ;
460 float dv = -GPUCommonMath::Sqrt(x * x + y * y + distZ * distZ) * mTOFcorr;
461 dz = sideC ? dv : -dv;
462}
463
464GPUdi() 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
465{
466 GPUCA_RTC_SPECIAL_CODE(ref2 = nullptr; scale2 = 0.f;);
467 if (mApplyCorrection) {
468 float dx = 0.f, du = 0.f, dv = 0.f;
469 if ((scale >= 0.f) || (scaleMode == 1) || (scaleMode == 2)) {
470#ifndef GPUCA_GPUCODE
471 if (mCorrectionSlow) {
472 float ly, lz;
473 getGeometry().convUVtoLocal(slice, u, v, ly, lz);
474 float gx, gy, gz;
475 getGeometry().convLocalToGlobal(slice, x, ly, lz, gx, gy, gz);
476
477 float gdxC, gdyC, gdzC;
478 mCorrectionSlow->getCorrections(gx, gy, gz, slice, gdxC, gdyC, gdzC);
479 getGeometry().convGlobalToLocal(slice, gdxC, gdyC, gdzC, dx, du, dv);
480
481 if (slice >= 18) {
482 du = -du; // mirror for c-Side
483 } else {
484 dv = -dv; // mirror z for A-Side
485 }
486 } else
487#endif // GPUCA_GPUCODE
488 {
489 mCorrection.getCorrection(slice, row, u, v, dx, du, dv);
490 if (ref) {
491 if ((scale > 0.f) && (scaleMode == 0)) { // scaling was requested
492 float dxRef, duRef, dvRef;
493 ref->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
494 dx = (dx - dxRef) * scale + dxRef;
495 du = (du - duRef) * scale + duRef;
496 dv = (dv - dvRef) * scale + dvRef;
497 } else if ((scale != 0.f) && ((scaleMode == 1) || (scaleMode == 2))) {
498 float dxRef, duRef, dvRef;
499 ref->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
500 dx = dxRef * scale + dx;
501 du = duRef * scale + du;
502 dv = dvRef * scale + dv;
503 }
504 }
505 if (ref2 && (scale2 != 0)) {
506 float dxRef, duRef, dvRef;
507 ref2->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
508 dx = dxRef * scale2 + dx;
509 du = duRef * scale2 + du;
510 dv = dvRef * scale2 + dv;
511 }
512 }
513 }
514 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
515 float ly, lz;
516 getGeometry().convUVtoLocal(slice, u, v, ly, lz);
517
518 float gx, gy, gz;
519 getGeometry().convLocalToGlobal(slice, x, ly, lz, gx, gy, gz);
520
521 float lyT, lzT;
522 float uCorr = u + du;
523 float vCorr = v + dv;
524 float lxT = x + dx;
525 getGeometry().convUVtoLocal(slice, uCorr, vCorr, lyT, lzT);
526
527 float invYZtoXScaled;
528 InverseTransformYZtoX(slice, row, lyT, lzT, invYZtoXScaled, ref, ref2, scale, scale2, scaleMode);
529
530 float invYZtoX;
531 InverseTransformYZtoX(slice, row, lyT, lzT, invYZtoX);
532
533 float YZtoNominalY;
534 float YZtoNominalZ;
535 InverseTransformYZtoNominalYZ(slice, row, lyT, lzT, YZtoNominalY, YZtoNominalZ);
536
537 float YZtoNominalYScaled;
538 float YZtoNominalZScaled;
539 InverseTransformYZtoNominalYZ(slice, row, lyT, lzT, YZtoNominalYScaled, YZtoNominalZScaled, ref, ref2, scale, scale2, scaleMode);
540
541 float dxRef, duRef, dvRef;
542 if (ref) {
543 ref->mCorrection.getCorrection(slice, row, u, v, dxRef, duRef, dvRef);
544 }
545
546 float dxRef2, duRef2, dvRef2;
547 if (ref2) {
548 ref2->mCorrection.getCorrection(slice, row, u, v, dxRef2, duRef2, dvRef2);
549 }
550
551 float dxOrig, duOrig, dvOrig;
552 mCorrection.getCorrection(slice, row, u, v, dxOrig, duOrig, dvOrig);
553
554 o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_Transform").data()
555 // corrections in x, u, v
556 << "dxOrig=" << dxOrig
557 << "duOrig=" << duOrig
558 << "dvOrig=" << dvOrig
559 << "dxRef=" << dxRef
560 << "duRef=" << duRef
561 << "dvRef=" << dvRef
562 << "dxRef2=" << dxRef2
563 << "duRef2=" << duRef2
564 << "dvRef2=" << dvRef2
565 << "dx=" << dx
566 << "du=" << du
567 << "dv=" << dv
568 << "v=" << v
569 << "u=" << u
570 << "row=" << row
571 << "slice=" << slice
572 << "scale=" << scale
573 << "scale2=" << scale2
574 // original local coordinates
575 << "ly=" << ly
576 << "lz=" << lz
577 << "lx=" << x
578 // corrected local coordinated
579 << "lxT=" << lxT
580 << "lyT=" << lyT
581 << "lzT=" << lzT
582 // global uncorrected coordinates
583 << "gx=" << gx
584 << "gy=" << gy
585 << "gz=" << gz
586 // some transformations which are applied
587 << "invYZtoX=" << invYZtoX
588 << "invYZtoXScaled=" << invYZtoXScaled
589 << "YZtoNominalY=" << YZtoNominalY
590 << "YZtoNominalYScaled=" << YZtoNominalYScaled
591 << "YZtoNominalZ=" << YZtoNominalZ
592 << "YZtoNominalZScaled=" << YZtoNominalZScaled
593 << "scaleMode=" << scaleMode
594 << "\n";
595 })
596
597 x += dx;
598 u += du;
599 v += dv;
600 }
601}
602
603GPUdi() 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
604{
605 float u, v;
606 getGeometry().convLocalToUV(slice, y, z, u, v);
607 TransformInternal(slice, row, u, v, x, ref, ref2, scale, scale2, scaleMode);
608 getGeometry().convUVtoLocal(slice, u, v, y, z);
609 float dzTOF = 0;
610 getTOFcorrection(slice, row, x, y, z, dzTOF);
611 z += dzTOF;
612}
613
614GPUdi() 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
615{
621
622 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
623
624 // const SliceInfo &sliceInfo = getSliceInfo( slice );
625 // bool sideC = ( slice >= NumberOfSlices / 2 );
626
627 x = rowInfo.x;
628 float u = 0, v = 0;
629 convPadTimeToUV(slice, row, pad, time, u, v, vertexTime);
630
631 TransformInternal(slice, row, u, v, x, ref, ref2, scale, scale2, scaleMode);
632
633 getGeometry().convUVtoLocal(slice, u, v, y, z);
634
635 float dzTOF = 0;
636 getTOFcorrection(slice, row, x, y, z, dzTOF);
637 z += dzTOF;
638}
639
640GPUdi() void TPCFastTransform::TransformInTimeFrame(int32_t slice, float time, float& z, float maxTimeBin) const
641{
642 float v = 0;
643 convTimeToVinTimeFrame(slice, time, v, maxTimeBin);
644 getGeometry().convVtoLocal(slice, v, z);
645}
646
647GPUdi() void TPCFastTransform::TransformInTimeFrame(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float maxTimeBin) const
648{
654
655 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
656 x = rowInfo.x;
657 float u = 0, v = 0;
658 convPadTimeToUVinTimeFrame(slice, row, pad, time, u, v, maxTimeBin);
659 getGeometry().convUVtoLocal(slice, u, v, y, z);
660}
661
662GPUdi() void TPCFastTransform::InverseTransformInTimeFrame(int32_t slice, int32_t row, float /*x*/, float y, float z, float& pad, float& time, float maxTimeBin) const
663{
665 float u = 0, v = 0;
666 getGeometry().convLocalToUV(slice, y, z, u, v);
667 convUVtoPadTimeInTimeFrame(slice, row, u, v, pad, time, maxTimeBin);
668}
669
670GPUdi() void TPCFastTransform::TransformIdealZ(int32_t slice, float time, float& z, float vertexTime) const
671{
678
679 float v = (time - mT0 - vertexTime) * mVdrift; // drift length cm
680 getGeometry().convVtoLocal(slice, v, z);
681}
682
683GPUdi() void TPCFastTransform::TransformIdeal(int32_t slice, int32_t row, float pad, float time, float& x, float& y, float& z, float vertexTime) const
684{
691
692 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
693
694 x = rowInfo.x;
695 float u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
696 float v = (time - mT0 - vertexTime) * mVdrift; // drift length cm
697
698 getGeometry().convUVtoLocal(slice, u, v, y, z);
699}
700
701GPUdi() float TPCFastTransform::convTimeToZinTimeFrame(int32_t slice, float time, float maxTimeBin) const
702{
709
710 float v = (time - mT0 - maxTimeBin) * mVdrift + mLdriftCorr; // drift length cm
711 float z = getGeometry().getTPCalignmentZ(); // global TPC alignment
712 if (slice < getGeometry().getNumberOfSlicesA()) {
713 z -= v;
714 } else {
715 z += v;
716 }
717 return z;
718}
719
720GPUdi() float TPCFastTransform::convZtoTimeInTimeFrame(int32_t slice, float z, float maxTimeBin) const
721{
723 float v;
724 if (slice < getGeometry().getNumberOfSlicesA()) {
725 v = getGeometry().getTPCalignmentZ() - z;
726 } else {
727 v = z - getGeometry().getTPCalignmentZ();
728 }
729 return mT0 + maxTimeBin + (v - mLdriftCorr) / mVdrift;
730}
731
732GPUdi() float TPCFastTransform::convDeltaTimeToDeltaZinTimeFrame(int32_t slice, float deltaTime) const
733{
734 float deltaZ = deltaTime * mVdrift;
735 return slice < getGeometry().getNumberOfSlicesA() ? -deltaZ : deltaZ;
736}
737
738GPUdi() float TPCFastTransform::convDeltaZtoDeltaTimeInTimeFrameAbs(float deltaZ) const
739{
740 return deltaZ / mVdrift;
741}
742
743GPUdi() float TPCFastTransform::convDeltaZtoDeltaTimeInTimeFrame(int32_t slice, float deltaZ) const
744{
745 float deltaT = deltaZ / mVdrift;
746 return slice < getGeometry().getNumberOfSlicesA() ? -deltaT : deltaT;
747}
748
749/*
750GPUdi() float TPCFastTransform::getLastCalibratedTimeBin(int32_t slice) const
751{
753 float u, v, pad, time;
754 getGeometry().convScaledUVtoUV(slice, 0, 0.f, 1.f, u, v);
755 convUVtoPadTime(slice, 0, u, v, pad, time, 0);
756 return time;
757}
758*/
759
760GPUdi() float TPCFastTransform::getMaxDriftTime(int32_t slice, int32_t row, float pad) const
761{
763 float maxL = mCorrection.getMaxDriftLength(slice, row, pad);
764
765 bool sideC = (slice >= getGeometry().getNumberOfSlicesA());
766 const TPCFastTransformGeo::RowInfo& rowInfo = getGeometry().getRowInfo(row);
767 const TPCFastTransformGeo::SliceInfo& sliceInfo = getGeometry().getSliceInfo(slice);
768
769 float x = rowInfo.x;
770 float u = (pad - 0.5f * rowInfo.maxPad) * rowInfo.padWidth;
771
772 float y = sideC ? -u : u; // pads are mirrorred on C-side
773 float yLab = y * sliceInfo.cosAlpha + x * sliceInfo.sinAlpha;
774 return mT0 + (maxL - mLdriftCorr) / (mVdrift + mVdriftCorrY * yLab);
775}
776
777GPUdi() float TPCFastTransform::getMaxDriftTime(int32_t slice, int32_t row) const
778{
780 float maxL = mCorrection.getMaxDriftLength(slice, row);
781 float maxTime = 0.f;
782 convVtoTime(maxL, maxTime, 0.f);
783 return maxTime;
784}
785
786GPUdi() float TPCFastTransform::getMaxDriftTime(int32_t slice) const
787{
789 float maxL = mCorrection.getMaxDriftLength(slice);
790 float maxTime = 0.f;
791 convVtoTime(maxL, maxTime, 0.f);
792 return maxTime;
793}
794
795GPUdi() 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
796{
797 GPUCA_RTC_SPECIAL_CODE(ref2 = nullptr; scale2 = 0.f;);
799 float u = 0, v = 0;
800 getGeometry().convLocalToUV(slice, y, z, u, v);
801 if ((scale >= 0.f) || (scaleMode == 1) || (scaleMode == 2)) {
802 mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, x);
803 if (ref) { // scaling was requested
804 if (scaleMode == 0 && scale > 0.f) {
805 float xr;
806 ref->mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, xr);
807 x = (x - xr) * scale + xr;
808 } else if ((scale != 0) && ((scaleMode == 1) || (scaleMode == 2))) {
809 float xr;
810 ref->mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, xr);
811 x = (xr - getGeometry().getRowInfo(row).x) * scale + x; // xr=mGeo.getRowInfo(row).x + dx;
812 }
813 }
814 if (ref2 && (scale2 != 0)) {
815 float xr;
816 ref2->mCorrection.getCorrectionInvCorrectedX(slice, row, u, v, xr);
817 x = (xr - getGeometry().getRowInfo(row).x) * scale2 + x; // xr=mGeo.getRowInfo(row).x + dx;
818 }
819 } else {
820 x = mCorrection.getGeometry().getRowInfo(row).x; // corrections are disabled
821 }
822 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
823 o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_InverseTransformYZtoX").data()
824 << "slice=" << slice
825 << "row=" << row
826 << "scale=" << scale
827 << "y=" << y
828 << "z=" << z
829 << "x=" << x
830 << "v=" << v
831 << "u=" << u
832 << "\n";
833 })
834}
835
836GPUdi() 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
837{
838 GPUCA_RTC_SPECIAL_CODE(ref2 = nullptr; scale2 = 0.f;);
840 float u = 0, v = 0, un = 0, vn = 0;
841 getGeometry().convLocalToUV(slice, y, z, u, v);
842 if ((scale >= 0.f) || (scaleMode == 1) || (scaleMode == 2)) {
843 mCorrection.getCorrectionInvUV(slice, row, u, v, un, vn);
844 if (ref) { // scaling was requested
845 if (scaleMode == 0 && scale > 0.f) {
846 float unr = 0, vnr = 0;
847 ref->mCorrection.getCorrectionInvUV(slice, row, u, v, unr, vnr);
848 un = (un - unr) * scale + unr;
849 vn = (vn - vnr) * scale + vnr;
850 } else if ((scale != 0) && ((scaleMode == 1) || (scaleMode == 2))) {
851 float unr = 0, vnr = 0;
852 ref->mCorrection.getCorrectionInvUV(slice, row, u, v, unr, vnr);
853 un = (unr - u) * scale + un; // unr = u - duv[0];
854 vn = (vnr - v) * scale + vn;
855 }
856 if (ref2 && (scale2 != 0)) {
857 float unr = 0, vnr = 0;
858 ref2->mCorrection.getCorrectionInvUV(slice, row, u, v, unr, vnr);
859 un = (unr - u) * scale2 + un; // unr = u - duv[0];
860 vn = (vnr - v) * scale2 + vn;
861 }
862 }
863 } else {
864 un = u;
865 vn = v;
866 }
867 getGeometry().convUVtoLocal(slice, un, vn, ny, nz);
868
869 GPUCA_DEBUG_STREAMER_CHECK(if (o2::utils::DebugStreamer::checkStream(o2::utils::StreamFlags::streamFastTransform)) {
870 o2::utils::DebugStreamer::instance()->getStreamer("debug_fasttransform", "UPDATE") << o2::utils::DebugStreamer::instance()->getUniqueTreeName("tree_InverseTransformYZtoNominalYZ").data()
871 << "slice=" << slice
872 << "row=" << row
873 << "scale=" << scale
874 << "y=" << y
875 << "z=" << z
876 << "ny=" << ny
877 << "nz=" << nz
878 << "u=" << u
879 << "v=" << v
880 << "un=" << un
881 << "vn=" << vn
882 << "\n";
883 })
884}
885
886GPUdi() 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
887{
889 int32_t row2 = row + 1;
890 if (row2 >= getGeometry().getNumberOfRows()) {
891 row2 = row - 1;
892 }
893 float nx1, ny1, nz1; // nominal coordinates for row
894 float nx2, ny2, nz2; // nominal coordinates for row2
895 nx1 = getGeometry().getRowInfo(row).x;
896 nx2 = getGeometry().getRowInfo(row2).x;
897 InverseTransformYZtoNominalYZ(slice, row, y, z, ny1, nz1, ref, ref2, scale, scale2, scaleMode);
898 InverseTransformYZtoNominalYZ(slice, row2, y, z, ny2, nz2, ref, ref2, scale, scale2, scaleMode);
899 float c1 = (nx2 - nx) / (nx2 - nx1);
900 float c2 = (nx - nx1) / (nx2 - nx1);
901 nx = x;
902 ny = (ny1 * c1 + ny2 * c2);
903 nz = (nz1 * c1 + nz2 * c2);
904}
905
906} // namespace gpu
907} // namespace o2
908
909#endif
Definition of FlatObject class.
#define GPUCA_DEBUG_STREAMER_CHECK(...)
#define GPUCA_RTC_SPECIAL_CODE(...)
bool const GPUTPCGMMerger::trackCluster * c1
bool const GPUTPCGMMerger::trackCluster const clcomparestruct * c2
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:167
@ 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