From f51eafd2b4b623e9d688510a77f188183a7b9aa4 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Thu, 2 May 2024 22:40:50 +0200
Subject: [PATCH] TOF tracking interface: re-definition of zmin and zmax

---
 algo/ca/TrackingChain.cxx                     | 12 ++++-----
 algo/ca/TrackingSetup.h                       |  2 +-
 algo/detectors/sts/TrackingInterface.cxx      |  7 ++---
 algo/detectors/sts/TrackingInterface.h        |  2 +-
 algo/detectors/trd/TrackingInterface.cxx      | 10 ++-----
 algo/detectors/trd/TrackingInterface.h        |  2 +-
 .../detectors/tof/CbmTofTrackingInterface.cxx |  6 ++++-
 core/detectors/tof/CbmTofTrackingInterface.h  |  4 +--
 macro/beamtime/mcbm2024/CMakeLists.txt        | 26 +++++++++++++++++++
 9 files changed, 46 insertions(+), 25 deletions(-)
 create mode 100644 macro/beamtime/mcbm2024/CMakeLists.txt

diff --git a/algo/ca/TrackingChain.cxx b/algo/ca/TrackingChain.cxx
index b5899b3163..a572e708e2 100644
--- a/algo/ca/TrackingChain.cxx
+++ b/algo/ca/TrackingChain.cxx
@@ -20,11 +20,11 @@
 #include <boost/archive/binary_oarchive.hpp>
 
 #include <fstream>
+#include <set>
 #include <unordered_map>
 
 #include <fmt/format.h>
 #include <xpu/host.h>
-#include <set>
 
 using namespace cbm::algo;
 
@@ -268,13 +268,13 @@ void TrackingChain::ReadHits(PartitionedSpan<const ca::HitTypes_t::at<DetID>> hi
     const auto& [vHits, extHitAddress] = hits.Partition(iPartition);
     // ---- Define data stream and station index
     //int64_t dataStream = dataStreamDet | extHitAddress;
-    int iStLocal  = fpSetup->GetTrackingStation<ca::ToFlesSubsystem<DetID>()>(extHitAddress);
+    int iStLocal = fpSetup->GetTrackingStation<ca::ToFlesSubsystem<DetID>()>(extHitAddress);
     if (iStLocal < 0) {
       continue;  // Station is not used for tracking (e.g. TOF SMtype 5)
     }
 
     int iStActive = fCaFramework.GetParameters().GetStationIndexActive(iStLocal, DetID);
-    
+
     //size_t iOffset = hits.Offsets()[iPartition];
     if (iStActive < 0) {
       continue;  // legit
@@ -294,17 +294,17 @@ void TrackingChain::ReadHits(PartitionedSpan<const ca::HitTypes_t::at<DetID>> hi
       //  switch (extHitAddress) {
       //    case 0x5:
       //      if (!(fabs(hit.Z() - 116.77) < 10)) {
-      //        L_(info) << "AAAAAA!!!!!!!!! " << extHitAddress << ' ' << hit.Z();
+      //        L_(info) << "DBG! " << extHitAddress << ' ' << hit.Z();
       //      }
       //      break;
       //    case 0x15:
       //      if (!(fabs(hit.Z() - 163.8) < 10)) {
-      //        L_(info) << "AAAAAA!!!!!!!!! "  << extHitAddress << ' ' << hit.Z();
+      //        L_(info) << "DBG! "  << extHitAddress << ' ' << hit.Z();
       //      }
       //      break;
       //    case 0x25:
       //      if (!(fabs(hit.Z() - 190.8) < 10)) {
-      //        L_(info) << "AAAAAA!!!!!!!!! "  << extHitAddress << ' ' << hit.Z();
+      //        L_(info) << "DBG! "  << extHitAddress << ' ' << hit.Z();
       //      }
       //      break;
       //  }
diff --git a/algo/ca/TrackingSetup.h b/algo/ca/TrackingSetup.h
index a5f9abf75d..ba678c4e3b 100644
--- a/algo/ca/TrackingSetup.h
+++ b/algo/ca/TrackingSetup.h
@@ -54,7 +54,7 @@ namespace cbm::algo
       else if constexpr (DetID == fles::Subsystem::TOF) {
         return fTof.GetTrackingStation(address);
       }
-      return -1; // Default: no station is assigned, hit will be skept !
+      return -1;  // Default: no station is assigned, hit will be skept !
     }
 
     /// \brief Set detector subsystem usage
diff --git a/algo/detectors/sts/TrackingInterface.cxx b/algo/detectors/sts/TrackingInterface.cxx
index fa667fdecf..fad68ead46 100644
--- a/algo/detectors/sts/TrackingInterface.cxx
+++ b/algo/detectors/sts/TrackingInterface.cxx
@@ -16,17 +16,14 @@ using cbm::algo::sts::TrackingInterface;
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
-void TrackingInterface::Init()
-{
-  L_(info) << "STS: TrackingInterface initialization";
-}
+void TrackingInterface::Init() { L_(info) << "STS: TrackingInterface initialization"; }
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
 int TrackingInterface::GetTrackingStation(uint32_t address) const
 {
   // NOTE: SZh 30.04.2024:
-  //   This returns the valid STS station index at least for mCBM at beamtimes 2022 and 2024. There is no 
+  //   This returns the valid STS station index at least for mCBM at beamtimes 2022 and 2024. There is no
   //   guarantie, that it will work for other setups, should be cross-checked.
   return CbmStsAddress::GetElementId(address, kStsUnit);
 }
diff --git a/algo/detectors/sts/TrackingInterface.h b/algo/detectors/sts/TrackingInterface.h
index a037cd2fbc..472863eef1 100644
--- a/algo/detectors/sts/TrackingInterface.h
+++ b/algo/detectors/sts/TrackingInterface.h
@@ -35,4 +35,4 @@ namespace cbm::algo::sts
     /// \return  Local index of tracking station
     int GetTrackingStation(uint32_t address) const;
   };
-}  // namespace cbm::algo::tof
+}  // namespace cbm::algo::sts
diff --git a/algo/detectors/trd/TrackingInterface.cxx b/algo/detectors/trd/TrackingInterface.cxx
index 7ad681daa4..7b119cb64d 100644
--- a/algo/detectors/trd/TrackingInterface.cxx
+++ b/algo/detectors/trd/TrackingInterface.cxx
@@ -16,14 +16,8 @@ using cbm::algo::trd::TrackingInterface;
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
-void TrackingInterface::Init()
-{
-  L_(info) << "TRD: TrackingInterface initialization";
-}
+void TrackingInterface::Init() { L_(info) << "TRD: TrackingInterface initialization"; }
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
-int TrackingInterface::GetTrackingStation(uint32_t address) const
-{
-  return CbmTrdAddress::GetLayerId(address);
-}
+int TrackingInterface::GetTrackingStation(uint32_t address) const { return CbmTrdAddress::GetLayerId(address); }
diff --git a/algo/detectors/trd/TrackingInterface.h b/algo/detectors/trd/TrackingInterface.h
index 16eedf721d..e5f1bf05e8 100644
--- a/algo/detectors/trd/TrackingInterface.h
+++ b/algo/detectors/trd/TrackingInterface.h
@@ -35,4 +35,4 @@ namespace cbm::algo::trd
     /// \return  Local index of tracking station
     int GetTrackingStation(uint32_t address) const;
   };
-}  // namespace cbm::algo::tof
+}  // namespace cbm::algo::trd
diff --git a/core/detectors/tof/CbmTofTrackingInterface.cxx b/core/detectors/tof/CbmTofTrackingInterface.cxx
index 5135054088..1f11a22e7d 100644
--- a/core/detectors/tof/CbmTofTrackingInterface.cxx
+++ b/core/detectors/tof/CbmTofTrackingInterface.cxx
@@ -69,6 +69,9 @@ InitStatus CbmTofTrackingInterface::Init()
   fTofStationZMin.resize(nStations, std::numeric_limits<double>::max());
   fTofStationZMax.resize(nStations, std::numeric_limits<double>::lowest());
 
+  std::vector<std::set<double>> mRpcZ;
+  mRpcZ.resize(nStations, std::set<double>{});
+
   fmAddressToStation.clear();
   for (int iSmType = 0; iSmType < fDigiBdfPar->GetNbSmTypes(); ++iSmType) {
     for (int iSm = 0; iSm < fDigiBdfPar->GetNbSm(iSmType); ++iSm) {
@@ -99,6 +102,7 @@ InitStatus CbmTofTrackingInterface::Init()
         if (5 == iSmType) { continue; }  // Skip Bmon
         if (iStation < 0) { continue; }
 
+        mRpcZ[iStation].insert(chPosZ);
         fTofStationZ[iStation] += chPosZ;
         // FIXME: Sizes of stations are incorrect
         if (chPosZ > fTofStationZMax[iStation]) { fTofStationZMax[iStation] = chPosZ; }
@@ -114,7 +118,7 @@ InitStatus CbmTofTrackingInterface::Init()
   }
 
   /// Get the average values
-  for (int iSt = 0; iSt < this->GetNtrackingStations(); ++iSt) {
+  for (int iSt = 0; iSt < nStations; ++iSt) {
     fTofStationZ[iSt] = fTofStationZ[iSt] / nTofStationModules[iSt];
   }
 
diff --git a/core/detectors/tof/CbmTofTrackingInterface.h b/core/detectors/tof/CbmTofTrackingInterface.h
index 5e7b06eca2..515bed959a 100644
--- a/core/detectors/tof/CbmTofTrackingInterface.h
+++ b/core/detectors/tof/CbmTofTrackingInterface.h
@@ -129,12 +129,12 @@ public:
   /// Gets max z of the station
   /// \param  stationId  Tracking station ID in the setup (NOTE: must be in range [0..GetNstations()-1])
   /// \return max Z of the station [cm]
-  double GetZmax(int stationId) const { return GetZref(stationId) + 5.; }
+  double GetZmax(int stationId) const { return fTofStationZMax[stationId] + 0.5; }
 
   /// @brief  Gets min z of the station
   /// @param  stationId  Tracking station ID in the setup (NOTE: must be in range [0..GetNstations()-1])
   /// @return min Z of the station [cm]
-  double GetZmin(int stationId) const { return GetZref(stationId) - 5.; }
+  double GetZmin(int stationId) const { return fTofStationZMin[stationId] - 0.5; }
 
   /// @brief  Check if station provides time measurements
   /// @param  stationId  Tracking station ID in the setup (NOTE: must be in range [0..GetNstations()-1])
diff --git a/macro/beamtime/mcbm2024/CMakeLists.txt b/macro/beamtime/mcbm2024/CMakeLists.txt
new file mode 100644
index 0000000000..56a2a539ab
--- /dev/null
+++ b/macro/beamtime/mcbm2024/CMakeLists.txt
@@ -0,0 +1,26 @@
+
+# ROOT macros, par files, documentation files, bash scripts
+Install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
+        DESTINATION share/cbmroot/macro/beamtime
+        FILES_MATCHING PATTERN "*.C"
+                       PATTERN "*.par"
+                       PATTERN "*.md"
+                       PATTERN "*.sh"
+       )
+# # RICH calibration file, resolve symlink to get the full file
+# Get_filename_component(_resolvedRichFile ${CMAKE_CURRENT_SOURCE_DIR}/icd_offset_it_0.data REALPATH)
+# Install(FILES ${_resolvedRichFile}
+#         DESTINATION share/cbmroot/macro/beamtime/mcbm2022
+#        )
+# 
+# # SLURM scripts, bash scripts
+# Install(DIRECTORY online
+#         DESTINATION share/cbmroot/macro/beamtime/mcbm2022
+#         FILES_MATCHING PATTERN "*.sbatch"
+#                        PATTERN "*.sh"
+#         )
+# 
+# # Just the empty folder for output
+# Install(DIRECTORY data
+#         DESTINATION share/cbmroot/macro/beamtime/mcbm2022
+#         PATTERN "*" EXCLUDE)
-- 
GitLab