From c31d8dbd31c4b92af3f37420df8a1ff98e850624 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Fri, 17 Nov 2023 17:10:01 +0000
Subject: [PATCH] sts::Hitfinder: Fix Hit copying.

---
 algo/detectors/sts/Hitfinder.cxx         | 4 ++--
 algo/detectors/sts/HitfinderChain.cxx    | 3 ++-
 services/archive_explorer/lib/Server.cxx | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/algo/detectors/sts/Hitfinder.cxx b/algo/detectors/sts/Hitfinder.cxx
index bee37563e8..8edebeeed2 100644
--- a/algo/detectors/sts/Hitfinder.cxx
+++ b/algo/detectors/sts/Hitfinder.cxx
@@ -788,7 +788,7 @@ XPU_D void sts::Hitfinder::CreateHit(int iModule, float xLocal, float yLocal, fl
     .fX         = globalX,
     .fY         = globalY,
     .fZ         = globalZ,
-    .fTime      = static_cast<uint32_t>(hitTime),
+    .fTime      = static_cast<u32>(hitTime),
     .fDx        = errX,
     .fDy        = errY,
     .fDz        = errZ,
@@ -808,7 +808,7 @@ XPU_D void sts::Hitfinder::CreateHit(int iModule, float xLocal, float yLocal, fl
     return;
   }
 
-  hitsPerModule[iModule * maxHitsPerModule + idx] = hit;
+  hitsPerModule[iModule * hitsAllocatedPerModule + idx] = hit;
 }
 
 XPU_D float sts::Hitfinder::LandauWidth(float charge) const
diff --git a/algo/detectors/sts/HitfinderChain.cxx b/algo/detectors/sts/HitfinderChain.cxx
index 239f342220..d0a2d5aa5c 100644
--- a/algo/detectors/sts/HitfinderChain.cxx
+++ b/algo/detectors/sts/HitfinderChain.cxx
@@ -303,7 +303,7 @@ void sts::HitfinderChain::AllocateStatic()
     gpuPars.lorentzF   = module.lorentzF;
     gpuPars.lorentzB   = module.lorentzB;
   }
-  xpu::copy(fHitfinder.sensorPars, xpu::h2d);
+  q.copy(fHitfinder.sensorPars, xpu::h2d);
 
   // Time errors
   fHitfinder.maxClusterTimeErrorByModuleSide.reset(nModuleSides, xpu::buf_device);
@@ -565,6 +565,7 @@ PartitionedSpan<sts::Hit> sts::HitfinderChain::FlattenHits(xpu::queue queue)
   // Could do this more efficiently, cache addresses once in the beginning, ...
   // doesn't really matter overhead wise
   fHitOffsets.clear();
+  // nModules + 1 entries, first entry is always 0, last entry is total number of hits (required by PartitionedSpan)
   fHitOffsets.push_back(0);
   for (int m = 0; m < hfc.nModules; m++)
     fHitOffsets.push_back(fHitOffsets.back() + GetNHits(nHits, m));
diff --git a/services/archive_explorer/lib/Server.cxx b/services/archive_explorer/lib/Server.cxx
index 6ddb0950a2..331e4894db 100644
--- a/services/archive_explorer/lib/Server.cxx
+++ b/services/archive_explorer/lib/Server.cxx
@@ -121,7 +121,7 @@ void Server::CreateHistos()
   CreateFolder("/sts/hits", "Hits");
   CreateHisto(fHStsHitsX, "/sts/hits", "hStsHitsX", "Sts Hits X", 100, -10, 10);
   CreateHisto(fHStsHitsY, "/sts/hits", "hStsHitsY", "Sts Hits Y", 100, -10, 10);
-  CreateHisto(fHStsHitsZ, "/sts/hits", "hStsHitsZ", "Sts Hits Z", 100, -10, 10);
+  CreateHisto(fHStsHitsZ, "/sts/hits", "hStsHitsZ", "Sts Hits Z", 100, 0, 50);
   CreateHisto(fHStsHitsTime, "/sts/hits", "hStsHitsTime", "Sts Hits Time", 1000, 0, 128000000);
   CreateHisto(fHStsHitsDx, "/sts/hits", "hStsHitsDx", "Sts Hits Dx", 100, 0, 0.1);
   CreateHisto(fHStsHitsDy, "/sts/hits", "hStsHitsDy", "Sts Hits Dy", 100, 0, 0.1);
-- 
GitLab