From ee72f895b0864286b6f3309a065a8daa8ebe2480 Mon Sep 17 00:00:00 2001 From: Felix Weiglhofer Date: Wed, 10 Jun 2026 16:45:38 +0200 Subject: [PATCH] GPU/TPC: Clamp gain correction of raw ADCs to 1022 --- GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx index 3d1ebbd54490e..a11637621f3b8 100644 --- a/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx +++ b/GPU/GPUTracking/TPCClusterFinder/GPUTPCCFDecodeZS.cxx @@ -478,8 +478,10 @@ GPUd() void GPUTPCCFDecodeZSLinkBase::WriteCharge(processorType& clusterer, floa positions[positionOffset] = pos; // Only apply gain correction if ADC not fully saturated - if (charge < 1023.f) { - charge *= clusterer.GetConstantMem()->calibObjects.tpcPadGain->getGainCorrection(sector, padAndRow.getRow(), padAndRow.getPad()); + // and ensure gain correction doesn't accidentally saturate the ADC + if (charge < 1023.f) [[likely]] { + auto gain = clusterer.GetConstantMem()->calibObjects.tpcPadGain->getGainCorrection(sector, padAndRow.getRow(), padAndRow.getPad()); + charge = CAMath::Min(charge * gain, 1022.f); } chargeMap[pos] = PackedCharge(charge);