From b5e47a9328bad33956f3cf7da4308000161e0416 Mon Sep 17 00:00:00 2001
From: David Schledt <schledt@iri.uni-frankfurt.de>
Date: Sun, 17 Mar 2024 11:10:58 +0000
Subject: [PATCH] Trd unpacker: Fix for incorrect time

=> The relative microslice time is now added to the timestamp with the correct units
---
 reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx | 5 +++--
 reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.h   | 3 +++
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx
index f12519401d..67794ea4ee 100644
--- a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx
+++ b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.cxx
@@ -333,7 +333,7 @@ void CbmTrdUnpackAlgoR::makeDigi(Spadic::FexWord<0x10> fw, std::uint32_t criid)
 
     // Store the full time information to last full-time member for error message handling
     // Get the time information and apply the necessary correction
-    ULong64_t time = (fw.timestamp - fw.prec_time) * fSpadic->GetClockCycle() + fMsStartTimeRelCC;
+    ULong64_t time = (fw.timestamp - fw.prec_time) * fSpadic->GetClockCycle() + fMsStartTimeRel;
 
     auto energy = fSpadic->MaxAdcToEnergyCal(fw.maxAdc);
 
@@ -381,7 +381,8 @@ bool CbmTrdUnpackAlgoR::unpack(const fles::Timeslice* ts, std::uint16_t icomp, U
 
   // Get the µSlice starttime relative to the timeslice starttime.
   // The UTC is already to large for storing it CbmTrdRawMessageSpadic due to a cast, caused by the multiplication with a double used in the raw message
-  fMsStartTimeRelCC = (msdesc.idx - fTsStartTime) / fSpadic->GetClockCycle();
+  fMsStartTimeRel   = msdesc.idx - fTsStartTime;
+  fMsStartTimeRelCC = fMsStartTimeRel / fSpadic->GetClockCycle();
 
   // Get the hardware ids from which the current µSlice is coming
   std::uint8_t crobId = 0;
diff --git a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.h b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.h
index 1d16c3eefd..8ff65e9576 100644
--- a/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.h
+++ b/reco/detectors/trd/unpack/CbmTrdUnpackAlgoR.h
@@ -200,6 +200,9 @@ class CbmTrdUnpackAlgoR : public CbmTrdUnpackAlgoBaseR {
   /** @brief Number of corrupted EOM frames */
   size_t fNrCorruptEom = 0;
 
+  /** @brief Start time of the current µSlice relative to the Timeslice start time in ns. */
+  size_t fMsStartTimeRel = 0;
+
   /** @brief Start time of the current µSlice relative to the Timeslice start time in Spadic CC. */
   size_t fMsStartTimeRelCC = 0;
 
-- 
GitLab