From 02f8443c846f957e25e00380ed37f7490dbd44b8 Mon Sep 17 00:00:00 2001 From: Maximiliano Puccio Date: Thu, 26 Nov 2026 18:22:15 +0100 Subject: [PATCH] [ALICE3] TF3: cluster times at the TDC bin centre, exact multi-digit mean The multi-digit cluster time was accumulated in a time_t, an integer: every digit time was cut to whole nanoseconds before the sum and the mean cut again, and the cluster's BC and time in the BC were derived from that. Multi-digit clusters were up to 1 ns early. The mean now sums the BCs after the precluster's earliest BC and the digit times in their BCs separately, both small, and converts once to the BC and the time in it. A digit's time in its BC is the centre of its TDC bin instead of its start, half a bin later; the last bin of a BC ends with the BC. Assisted by LLMs. --- .../IOTOF/reconstruction/src/Clusterer.cxx | 36 ++++++++++++++----- 1 file changed, 27 insertions(+), 9 deletions(-) diff --git a/Detectors/Upgrades/ALICE3/IOTOF/reconstruction/src/Clusterer.cxx b/Detectors/Upgrades/ALICE3/IOTOF/reconstruction/src/Clusterer.cxx index af5837ccc8c0a..edb988f55a9c4 100644 --- a/Detectors/Upgrades/ALICE3/IOTOF/reconstruction/src/Clusterer.cxx +++ b/Detectors/Upgrades/ALICE3/IOTOF/reconstruction/src/Clusterer.cxx @@ -22,6 +22,16 @@ namespace o2::iotof { +namespace +{ +// Centre of a digit's TDC bin, in ns after its BC; the last bin of a BC ends with the BC. +double tdcBinCentre(int tdc, double tdcBin) +{ + const double binStart = tdc * tdcBin; + return 0.5 * (binStart + std::min(binStart + tdcBin, o2::constants::lhc::LHCBunchSpacingNS)); +} +} // namespace + //__________________________________________________ void Clusterer::process(gsl::span digits, gsl::span digitROFs, @@ -177,7 +187,7 @@ void Clusterer::ClustererThread::findClustersSingleHit(gsl::span di const uint16_t col = digit.getColumn(); // const time_t time = digit.getTime(); const uint64_t nbc = digit.getBc(); - const float timeWrtBc = digit.getTdc() * digitizerParams.tdcBin; + const float timeWrtBc = tdcBinCentre(digit.getTdc(), digitizerParams.tdcBin); const time_t time = timeWrtBc + nbc * o2::constants::lhc::LHCBunchSpacingNS; if (labelsClusPtr) { @@ -276,7 +286,7 @@ void Clusterer::ClustererThread::findClustersMultipleHits(gsl::span const uint16_t col = digit.getColumn(); // const time_t time = digit.getTime(); const uint64_t nbc = digit.getBc(); - const float timeWrtBc = digit.getTdc() * digitizerParams.tdcBin; + const float timeWrtBc = tdcBinCentre(digit.getTdc(), digitizerParams.tdcBin); const time_t time = timeWrtBc + nbc * o2::constants::lhc::LHCBunchSpacingNS; if (labelsClusPtr) { @@ -313,24 +323,32 @@ void Clusterer::ClustererThread::findClustersMultipleHits(gsl::span int nMcLabels = 0; - // Compute average time for digits in the precluster - time_t clsTime = 0.0; + // Average time of the digits in the precluster: the BCs after the earliest digit's BC, an + // integer, and the TDC bin centres are summed separately, so that the sums stay small. + auto firstBc = digits[precluster[0]].getBc(); + for (const auto& idx : precluster) { + firstBc = std::min(firstBc, digits[idx].getBc()); + } + uint64_t bcSum = 0; + double binCentreSum = 0.; for (const auto& idx : precluster) { const auto& digit = digits[idx]; minRow = std::min(minRow, digit.getRow()); minCol = std::min(minCol, digit.getColumn()); maxRow = std::max(maxRow, digit.getRow()); maxCol = std::max(maxCol, digit.getColumn()); - const time_t time = digit.getTdc() * digitizerParams.tdcBin + digit.getBc() * o2::constants::lhc::LHCBunchSpacingNS; - clsTime += time; + bcSum += digit.getBc() - firstBc; + binCentreSum += tdcBinCentre(digit.getTdc(), digitizerParams.tdcBin); fetchMCLabels(idx, labelsDigPtr, nMcLabels); } - clsTime /= precluster.size(); const uint8_t rowSpan = maxRow - minRow + 1; const uint8_t colSpan = maxCol - minCol + 1; - const uint64_t nbc = static_cast(clsTime / o2::constants::lhc::LHCBunchSpacingNS); - const float timeWrtBc = clsTime - nbc * o2::constants::lhc::LHCBunchSpacingNS; + const double timeAfterFirstBc = (bcSum * o2::constants::lhc::LHCBunchSpacingNS + binCentreSum) / precluster.size(); + const auto bcShift = static_cast(timeAfterFirstBc / o2::constants::lhc::LHCBunchSpacingNS); + const uint64_t nbc = firstBc + bcShift; + const float timeWrtBc = timeAfterFirstBc - bcShift * o2::constants::lhc::LHCBunchSpacingNS; + const time_t clsTime = nbc * o2::constants::lhc::LHCBunchSpacingNS + timeWrtBc; // Fired digits bitmask packed into a single 16-bit pattern variable uint16_t firedDigitsMask = 0;