From 10d9efa7f7cab252b3c5a59106ced664ccd3c1b8 Mon Sep 17 00:00:00 2001
From: Dominik Smith <smith@th.physik.uni-frankfurt.de>
Date: Thu, 18 Apr 2024 14:46:53 +0200
Subject: [PATCH] Applied hotfix from MR 1752 to online TRD code.

---
 algo/detectors/trd/Clusterizer.cxx | 10 +++++++++-
 algo/detectors/trd/HitFinder.cxx   |  8 ++++++--
 2 files changed, 15 insertions(+), 3 deletions(-)

diff --git a/algo/detectors/trd/Clusterizer.cxx b/algo/detectors/trd/Clusterizer.cxx
index 3332d6d221..962ed2fdd1 100644
--- a/algo/detectors/trd/Clusterizer.cxx
+++ b/algo/detectors/trd/Clusterizer.cxx
@@ -78,6 +78,14 @@ namespace cbm::algo::trd
       bool sealtopcol = false;
       bool sealbotcol = false;
 
+      // already seal the cluster if the main trigger is already at the right or left padrow border
+      if (channel % ncols == ncols - 1) {
+        sealtopcol = true;
+      }
+      if (channel % ncols == 0) {
+        sealbotcol = true;
+      }
+
       // //vector which contains the actual cluster
       std::vector<std::pair<int, const CbmTrdDigi*>> cluster;
       cluster.emplace_back(digiId, digi);
@@ -93,7 +101,7 @@ namespace cbm::algo::trd
         const size_t oldSize = cluster.size();
 
         const int col = channel % ncols;
-        if (col == ncols) sealtopcol = true;  ///// Axel comment: change to ncols - 1, also for main!!
+        if (col == ncols - 1) sealtopcol = true;
         if (col == 0) sealbotcol = true;
 
         if (!sealbotcol && 0 <= lowcol - 1) {
diff --git a/algo/detectors/trd/HitFinder.cxx b/algo/detectors/trd/HitFinder.cxx
index 4faeaf608e..236dd779a9 100644
--- a/algo/detectors/trd/HitFinder.cxx
+++ b/algo/detectors/trd/HitFinder.cxx
@@ -175,6 +175,8 @@ namespace cbm::algo::trd
   {
     int colMin = fParams.rowPar[0].padPar.size();  //numCols
     int rowMin = fParams.rowPar.size();            //numRows
+    int colMax = 0;
+    int rowMax = 0;
 
     for (int i = 0; i < cluster->GetNofDigis(); ++i) {
       // const CbmTrdDigi* digi = CbmDigiManager::Instance()->Get<CbmTrdDigi>(cluster->GetDigi(i));
@@ -185,10 +187,12 @@ namespace cbm::algo::trd
 
       if (digiCol < colMin) colMin = digiCol;
       if (digiRow < rowMin) rowMin = digiRow;
+      if (digiCol > colMax) colMax = digiCol;
+      if (digiRow > rowMax) rowMax = digiRow;
     }
 
-    const uint16_t nCols = cluster->GetNCols();
-    const uint16_t nRows = cluster->GetNRows();
+    const uint16_t nCols = colMax - colMin + 1;
+    const uint16_t nRows = rowMax - rowMin + 1;
 
     CbmTrdDigi* digiMap[nRows][nCols];                        //create array on stack for optimal performance
     memset(digiMap, 0, sizeof(CbmTrdDigi*) * nCols * nRows);  //init with nullpointers
-- 
GitLab