@@ -58,16 +58,16 @@ class TPCFastSpaceChargeCorrection : public FlatObject
5858 };
5959
6060 struct SliceRowInfo {
61- float gridU0{0 .f }; // < U coordinate of the U-grid start
62- float scaleUtoGrid{0 .f }; // < scale U to U-grid coordinate
63- float gridV0{0 .f }; // /< V coordinate of the V-grid start
64- float scaleVtoGrid{0 .f }; // < scale V to V-grid coordinate
65- float gridCorrU0{0 .f }; // /< U coordinate of the U-grid start for corrected U
66- float scaleCorrUtoGrid{0 .f }; // /< scale corrected U to U-grid coordinate
67- float gridCorrV0{0 .f }; // /< V coordinate of the V-grid start for corrected V
68- float scaleCorrVtoGrid{0 .f }; // /< scale corrected V to V-grid coordinate
69- float maxCorr[3 ]{10 .f , 10 .f , 10 .f }; // /< max correction for dX, dU, dV
70- float minCorr[3 ]{-10 .f , -10 .f , -10 .f }; // /< min correction for dX, dU, dV
61+ float gridU0{0 .f }; // < U coordinate of the U-grid start
62+ float scaleUtoGrid{0 .f }; // < scale U to U-grid coordinate
63+ float gridV0{0 .f }; // /< V coordinate of the V-grid start
64+ float scaleVtoGrid{0 .f }; // < scale V to V-grid coordinate
65+ float gridCorrU0{0 .f }; // /< U coordinate of the U-grid start for corrected U
66+ float scaleCorrUtoGrid{0 .f }; // /< scale corrected U to U-grid coordinate
67+ float gridCorrV0{0 .f }; // /< V coordinate of the V-grid start for corrected V
68+ float scaleCorrVtoGrid{0 .f }; // /< scale corrected V to V-grid coordinate
69+ float maxCorr[3 ]{10 .f , 10 .f , 10 .f }; // /< max correction for dX, dU, dV
70+ float minCorr[3 ]{-10 .f , -10 .f , -10 .f }; // /< min correction for dX, dU, dV
7171 RowActiveArea activeArea;
7272
7373 void resetMaxValues ()
@@ -199,12 +199,6 @@ class TPCFastSpaceChargeCorrection : public FlatObject
199199
200200 // / _______________ Utilities _______________________________________________
201201
202- // / shrink u,v coordinats to the TPC row area +/- fkInterpolationSafetyMargin
203- GPUd () void schrinkUV (int32_t slice, int32_t row, float & u, float & v) const ;
204-
205- // / shrink corrected u,v coordinats to the TPC row area +/- fkInterpolationSafetyMargin
206- GPUd () void schrinkCorrectedUV (int32_t slice, int32_t row, float & corrU, float & corrV) const ;
207-
208202 // / convert u,v to internal grid coordinates
209203 GPUd () void convUVtoGrid (int32_t slice, int32_t row, float u, float v, float & gridU, float & gridV) const ;
210204
@@ -338,60 +332,9 @@ GPUdi() const float* TPCFastSpaceChargeCorrection::getSplineData(int32_t slice,
338332 return reinterpret_cast <float *>(mSplineData [iSpline] + mSliceDataSizeBytes [iSpline] * slice + rowInfo.dataOffsetBytes [iSpline]);
339333}
340334
341- GPUdi () void TPCFastSpaceChargeCorrection::schrinkUV(int32_t slice, int32_t row, float & u, float & v) const
342- {
343- // / shrink u,v coordinats to the TPC row area +/- fInterpolationSafetyMargin
344-
345- const TPCFastTransformGeo::RowInfo& rowInfo = mGeo .getRowInfo (row);
346-
347- float uWidth05 = rowInfo.getUwidth () * (0 .5f + fInterpolationSafetyMargin );
348- float vWidth = mGeo .getTPCzLength (slice);
349-
350- if (u < -uWidth05) {
351- u = -uWidth05;
352- }
353- if (u > uWidth05) {
354- u = uWidth05;
355- }
356- if (v < -0 .1f * vWidth) {
357- v = -0 .1f * vWidth;
358- }
359- if (v > 1 .1f * vWidth) {
360- v = 1 .1f * vWidth;
361- }
362- }
363-
364- GPUdi () void TPCFastSpaceChargeCorrection::schrinkCorrectedUV(int32_t slice, int32_t row, float & corrU, float & corrV) const
365- {
366- // / shrink corrected u,v coordinats to the TPC row area +/- fInterpolationSafetyMargin
367-
368- const TPCFastTransformGeo::RowInfo& rowInfo = mGeo .getRowInfo (row);
369- const SliceRowInfo& sliceRowInfo = getSliceRowInfo (slice, row);
370-
371- float uMargin = fInterpolationSafetyMargin * rowInfo.getUwidth ();
372- float vMargin = fInterpolationSafetyMargin * mGeo .getTPCzLength (slice);
373-
374- if (corrU < sliceRowInfo.activeArea .cuMin - uMargin) {
375- corrU = sliceRowInfo.activeArea .cuMin - uMargin;
376- }
377-
378- if (corrU > sliceRowInfo.activeArea .cuMax + uMargin) {
379- corrU = sliceRowInfo.activeArea .cuMax + uMargin;
380- }
381-
382- if (corrV < 0 .f - vMargin) {
383- corrV = 0 .f - vMargin;
384- }
385-
386- if (corrV > sliceRowInfo.activeArea .cvMax + vMargin) {
387- corrV = sliceRowInfo.activeArea .cvMax + vMargin;
388- }
389- }
390-
391335GPUdi () void TPCFastSpaceChargeCorrection::convUVtoGrid(int32_t slice, int32_t row, float u, float v, float & gu, float & gv) const
392336{
393- schrinkUV (slice, row, u, v);
394- const SliceRowInfo& info = getSliceRowInfo (slice, row);
337+ const auto & info = getSliceRowInfo (slice, row);
395338 gu = (u - info.gridU0 ) * info.scaleUtoGrid ;
396339 gv = (v - info.gridV0 ) * info.scaleVtoGrid ;
397340}
@@ -406,34 +349,36 @@ GPUdi() void TPCFastSpaceChargeCorrection::convGridToUV(int32_t slice, int32_t r
406349
407350GPUdi () void TPCFastSpaceChargeCorrection::convCorrectedUVtoGrid(int32_t slice, int32_t row, float corrU, float corrV, float & gridU, float & gridV) const
408351{
409- schrinkCorrectedUV (slice, row, corrU, corrV);
410-
411- const SliceRowInfo& sliceRowInfo = getSliceRowInfo (slice, row);
412-
413- gridU = (corrU - sliceRowInfo.gridCorrU0 ) * sliceRowInfo.scaleCorrUtoGrid ;
414- gridV = (corrV - sliceRowInfo.gridCorrV0 ) * sliceRowInfo.scaleCorrVtoGrid ;
352+ const SliceRowInfo& info = getSliceRowInfo (slice, row);
353+ gridU = (corrU - info.gridCorrU0 ) * info.scaleCorrUtoGrid ;
354+ gridV = (corrV - info.gridCorrV0 ) * info.scaleCorrVtoGrid ;
415355}
416356
417357GPUdi () int32_t TPCFastSpaceChargeCorrection::getCorrection(int32_t slice, int32_t row, float u, float v, float & dx, float & du, float & dv) const
418358{
359+ const auto & info = getSliceRowInfo (slice, row);
419360 const SplineType& spline = getSpline (slice, row);
420361 const float * splineData = getSplineData (slice, row);
421362 float gridU = 0 , gridV = 0 ;
422363 convUVtoGrid (slice, row, u, v, gridU, gridV);
364+ // shrink to the grid area
365+ gridU = GPUCommonMath::Clamp (gridU, 0 .f , (float )spline.getGridX1 ().getUmax ());
366+ gridV = GPUCommonMath::Clamp (gridV, 0 .f , (float )spline.getGridX2 ().getUmax ());
367+
423368 float dxuv[3 ];
424369 spline.interpolateU (splineData, gridU, gridV, dxuv);
425- const auto & info = getSliceRowInfo (slice, row);
370+
426371 float s = v / info.gridV0 ;
427- if (s < 0 .) {
428- s = 0 .;
429- }
430- if (s > 1 . ) {
431- s = 1 . ;
372+
373+ if (v >= info. gridV0 ) {
374+ s = 1 . f ;
375+ } else if (v <= 0 . f ) {
376+ s = 0 . f ;
432377 }
433378
434- dx = GPUCommonMath::Max (info. minCorr [0 ], GPUCommonMath::Min ( info.maxCorr [0 ], s * dxuv [0 ]) );
435- du = GPUCommonMath::Max (info. minCorr [1 ], GPUCommonMath::Min ( info.maxCorr [1 ], s * dxuv [1 ]) );
436- dv = GPUCommonMath::Max (info. minCorr [2 ], GPUCommonMath::Min ( info.maxCorr [2 ], s * dxuv [2 ]) );
379+ dx = GPUCommonMath::Clamp (s * dxuv [0 ], info.minCorr [0 ], info. maxCorr [0 ]);
380+ du = GPUCommonMath::Clamp (s * dxuv [1 ], info.minCorr [1 ], info. maxCorr [1 ]);
381+ dv = GPUCommonMath::Clamp (s * dxuv [2 ], info.minCorr [2 ], info. maxCorr [2 ]);
437382 return 0 ;
438383}
439384
@@ -462,45 +407,56 @@ GPUdi() int32_t TPCFastSpaceChargeCorrection::getCorrectionOld(int32_t slice, in
462407GPUdi () void TPCFastSpaceChargeCorrection::getCorrectionInvCorrectedX(
463408 int32_t slice, int32_t row, float corrU, float corrV, float & x) const
464409{
410+ const auto & info = getSliceRowInfo (slice, row);
411+ const Spline2D<float , 1 >& spline = reinterpret_cast <const Spline2D<float , 1 >&>(getSpline (slice, row));
412+ const float * splineData = getSplineData (slice, row, 1 );
413+
465414 float gridU, gridV;
466415 convCorrectedUVtoGrid (slice, row, corrU, corrV, gridU, gridV);
467416
468- const Spline2D<float , 1 >& spline = reinterpret_cast <const Spline2D<float , 1 >&>(getSpline (slice, row));
469- const float * splineData = getSplineData (slice, row, 1 );
417+ // shrink to the grid area
418+ gridU = GPUCommonMath::Clamp (gridU, 0 .f , (float )spline.getGridX1 ().getUmax ());
419+ gridV = GPUCommonMath::Clamp (gridV, 0 .f , (float )spline.getGridX2 ().getUmax ());
420+
470421 float dx = 0 ;
471422 spline.interpolateU (splineData, gridU, gridV, &dx);
472- const auto & info = getSliceRowInfo (slice, row);
473423
474424 float s = corrV / info.gridCorrV0 ;
475- if (s < 0 .) {
476- s = 0 .;
477- }
478- if (s > 1 . ) {
479- s = 1 . ;
425+
426+ if (corrV >= info. gridCorrV0 ) {
427+ s = 1 . f ;
428+ } else if (corrV <= 0 . f ) {
429+ s = 0 . f ;
480430 }
431+
481432 dx = GPUCommonMath::Clamp (s * dx, info.minCorr [0 ], info.maxCorr [0 ]);
482433 x = mGeo .getRowInfo (row).x + dx;
483434}
484435
485436GPUdi () void TPCFastSpaceChargeCorrection::getCorrectionInvUV(
486437 int32_t slice, int32_t row, float corrU, float corrV, float & nomU, float & nomV) const
487438{
439+ const Spline2D<float , 2 >& spline = reinterpret_cast <const Spline2D<float , 2 >&>(getSpline (slice, row));
440+ const float * splineData = getSplineData (slice, row, 2 );
441+
488442 float gridU, gridV;
489443 convCorrectedUVtoGrid (slice, row, corrU, corrV, gridU, gridV);
490444
491- const Spline2D<float , 2 >& spline = reinterpret_cast <const Spline2D<float , 2 >&>(getSpline (slice, row));
492- const float * splineData = getSplineData (slice, row, 2 );
445+ // shrink to the grid area
446+ gridU = GPUCommonMath::Clamp (gridU, 0 .f , (float )spline.getGridX1 ().getUmax ());
447+ gridV = GPUCommonMath::Clamp (gridV, 0 .f , (float )spline.getGridX2 ().getUmax ());
493448
494449 float duv[2 ];
495450 spline.interpolateU (splineData, gridU, gridV, duv);
496451 const auto & info = getSliceRowInfo (slice, row);
497452 float s = corrV / info.gridCorrV0 ;
498- if (s < 0 .) {
499- s = 0 .;
500- }
501- if (s > 1 . ) {
502- s = 1 . ;
453+
454+ if (corrV >= info. gridCorrV0 ) {
455+ s = 1 . f ;
456+ } else if (corrV <= 0 . f ) {
457+ s = 0 . f ;
503458 }
459+
504460 duv[0 ] = GPUCommonMath::Clamp (s * duv[0 ], info.minCorr [1 ], info.maxCorr [1 ]);
505461 duv[1 ] = GPUCommonMath::Clamp (s * duv[1 ], info.minCorr [2 ], info.maxCorr [2 ]);
506462 nomU = corrU - duv[0 ];
0 commit comments