From 31f2797fa107ba78dc5e49df53f79b4c556b5551 Mon Sep 17 00:00:00 2001
From: Dominik Smith <smith@th.physik.uni-frankfurt.de>
Date: Mon, 30 Oct 2023 10:59:13 +0100
Subject: [PATCH] Cleaned up TOF hitfinding parameters (moved cell geometry
 from channel to rpc).

---
 algo/detectors/tof/Hitfind.cxx               | 12 ++++---
 algo/detectors/tof/HitfindSetup.h            |  7 ++--
 reco/tasks/CbmTaskTofClusterizerParWrite.cxx | 37 +++++++++++---------
 3 files changed, 31 insertions(+), 25 deletions(-)

diff --git a/algo/detectors/tof/Hitfind.cxx b/algo/detectors/tof/Hitfind.cxx
index 282df409ee..06c562a0f6 100644
--- a/algo/detectors/tof/Hitfind.cxx
+++ b/algo/detectors/tof/Hitfind.cxx
@@ -125,19 +125,21 @@ namespace cbm::algo::tof
           par->fCPTOffYRange       = rpcPar.CPTOffYRange;
           par->fTimeRes            = rpcPar.timeRes;
 
+          //geometry information, can in principle be done channel-wise but not needed for now
+          const double* tra_ptr = rpcPar.cell.translation.data();
+          const double* rot_ptr = rpcPar.cell.rotation.data();
+
+          //channel parameters
           int32_t NbChan = rpcPar.chanPar.size();
           par->fChanPar.resize(NbChan);
 
           for (int32_t Ch = 0; Ch < NbChan; Ch++) {
-
             HitfindSetup::Channel chanPar   = rpcPar.chanPar[Ch];
-            const double* tra_ptr           = chanPar.cell.translation.data();
-            const double* rot_ptr           = chanPar.cell.rotation.data();
             par->fChanPar[Ch].address       = chanPar.address;
             par->fChanPar[Ch].cell.pos      = ROOT::Math::XYZVector(tra_ptr[0], tra_ptr[1], tra_ptr[2]);
             par->fChanPar[Ch].cell.rotation = ROOT::Math::Rotation3D(&rot_ptr[0], &rot_ptr[9]);
-            par->fChanPar[Ch].cell.sizeX    = chanPar.cell.sizeX;
-            par->fChanPar[Ch].cell.sizeY    = chanPar.cell.sizeY;
+            par->fChanPar[Ch].cell.sizeX    = rpcPar.cell.sizeX;
+            par->fChanPar[Ch].cell.sizeY    = rpcPar.cell.sizeY;
           }
           fAlgo[SmType][Sm * NbRpc + Rpc].SetParams(std::move(par));
         }
diff --git a/algo/detectors/tof/HitfindSetup.h b/algo/detectors/tof/HitfindSetup.h
index 12e8c1b7f9..e24ce81be8 100644
--- a/algo/detectors/tof/HitfindSetup.h
+++ b/algo/detectors/tof/HitfindSetup.h
@@ -38,11 +38,8 @@ namespace cbm::algo::tof
 
     struct Channel {
       i32 address;
-      Cell cell;
-
       static constexpr auto Properties =
-        std::make_tuple(config::Property(&Channel::address, "address", "unique address"),
-                        config::Property(&Channel::cell, "cell", "cell parameters"));
+        std::make_tuple(config::Property(&Channel::address, "address", "unique address"));
     };
 
     struct Rpc {
@@ -52,6 +49,7 @@ namespace cbm::algo::tof
       double maxSpaceDist;
       double sigVel;
       double timeRes;
+      Cell cell;
       double CPTOffYBinWidth;
       double CPTOffYRange;
       std::vector<double> CPTOffY;
@@ -64,6 +62,7 @@ namespace cbm::algo::tof
                         config::Property(&Rpc::maxSpaceDist, "maxSpaceDist", "maximum space distance"),
                         config::Property(&Rpc::sigVel, "sigVel", "signal velocity"),
                         config::Property(&Rpc::timeRes, "timeRes", "time resolution"),
+                        config::Property(&Rpc::cell, "cell", "cell parameters"),
                         config::Property(&Rpc::CPTOffYBinWidth, "CPTOffYBinWidth", "CPT Y offset bin width"),
                         config::Property(&Rpc::CPTOffYRange, "CPTOffYRange", "CPT Y offset range"),
                         config::Property(&Rpc::CPTOffY, "CPTOffY", "CPT Y offset array"),
diff --git a/reco/tasks/CbmTaskTofClusterizerParWrite.cxx b/reco/tasks/CbmTaskTofClusterizerParWrite.cxx
index 347ae503b6..03b75d98c8 100644
--- a/reco/tasks/CbmTaskTofClusterizerParWrite.cxx
+++ b/reco/tasks/CbmTaskTofClusterizerParWrite.cxx
@@ -442,6 +442,25 @@ bool CbmTaskTofClusterizerParWrite::InitAlgos()
 
         cbm::algo::tof::HitfindSetup::Rpc par;
 
+        /* Cell geometry for hitfinding (can in principle be set channel-wise but is not needed for now) */
+
+        const int32_t rpcAddress = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType);
+        CbmTofCell* channelInfo  = fDigiPar->GetCell(rpcAddress);
+        if (channelInfo == nullptr) { continue; }
+
+        // prepare local->global trafo
+        gGeoManager->FindNode(channelInfo->GetX(), channelInfo->GetY(), channelInfo->GetZ());
+        const double* tra_ptr = gGeoManager->MakePhysicalNode()->GetMatrix()->GetTranslation();
+        const double* rot_ptr = gGeoManager->GetCurrentMatrix()->GetRotationMatrix();
+
+        memcpy(par.cell.translation.data(), tra_ptr, 3 * sizeof(double));
+        memcpy(par.cell.rotation.data(), rot_ptr, 9 * sizeof(double));
+
+        par.cell.sizeX = channelInfo->GetSizex();
+        par.cell.sizeY = channelInfo->GetSizey();
+
+        /* Other fitfinding parameters */
+
         const int32_t iDetId   = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType);
         const int32_t iDetIndx = detIdIndexMap[iDetId];
         par.deadStrips         = fvDeadStrips[iDetIndx];
@@ -473,22 +492,8 @@ bool CbmTaskTofClusterizerParWrite::InitAlgos()
           /* Hitfinding parameters */
 
           cbm::algo::tof::HitfindSetup::Channel& chan = par.chanPar[iCh];
-
-          const int32_t address   = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType);
-          CbmTofCell* channelInfo = fDigiPar->GetCell(address);
-          if (channelInfo == nullptr) { continue; }
-
-          // prepare local->global trafo
-          gGeoManager->FindNode(channelInfo->GetX(), channelInfo->GetY(), channelInfo->GetZ());
-          const double* tra_ptr = gGeoManager->MakePhysicalNode()->GetMatrix()->GetTranslation();
-          const double* rot_ptr = gGeoManager->GetCurrentMatrix()->GetRotationMatrix();
-
-          memcpy(chan.cell.translation.data(), tra_ptr, 3 * sizeof(double));
-          memcpy(chan.cell.rotation.data(), rot_ptr, 9 * sizeof(double));
-
-          chan.cell.sizeX = channelInfo->GetSizex();
-          chan.cell.sizeY = channelInfo->GetSizey();
-          chan.address    = address;
+          const int32_t address                       = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType);
+          chan.address                                = address;
 
           /* Calibration paramters */
 
-- 
GitLab