From 7c403947e6dcdc305e905b4d845e9fb1d78ad836 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Sun, 22 Oct 2023 00:47:45 +0200
Subject: [PATCH] online: Adding tracking algorithm into the tracking chain

---
 algo/ca/TrackingChain.cxx         | 21 +++++++++++++++------
 algo/ca/TrackingChain.h           | 15 +++++++++------
 algo/ca/core/data/CaDataManager.h |  7 -------
 algo/global/Reco.cxx              | 19 ++++++++-----------
 reco/L1/CbmL1.cxx                 |  3 +--
 5 files changed, 33 insertions(+), 32 deletions(-)

diff --git a/algo/ca/TrackingChain.cxx b/algo/ca/TrackingChain.cxx
index a1d1dfc917..2005a16737 100644
--- a/algo/ca/TrackingChain.cxx
+++ b/algo/ca/TrackingChain.cxx
@@ -16,6 +16,7 @@
 #include "CaParameters.h"
 
 using cbm::algo::TrackingChain;
+using cbm::algo::ca::Framework;
 using cbm::algo::ca::InitManager;
 using cbm::algo::ca::Parameters;
 using cbm::algo::ca::Track;
@@ -27,7 +28,7 @@ using cbm::algo::ca::constants::clrs::GNb;  // grin bald text
 //
 void TrackingChain::Init()
 {
-  // ------ Reading parameters from binary
+  // ------ Read parameters from binary
   std::string paramFileBase = "mcbm_beam_2022_05_23_nickel.ca.par";  // TODO: Get the setup name from Opts()
   auto paramFile            = Opts().ParamsDir();
   paramFile /= paramFileBase;
@@ -35,23 +36,31 @@ void TrackingChain::Init()
   auto manager = InitManager {};
   manager.ReadParametersObject(paramFile.string());
   auto parameters = manager.TakeParameters();
-
   L_(info) << "Tracking Chain: parameters object: \n" << parameters.ToString(1) << '\n';
+
+  // ------ Initialize CA framework
+  fCaFramework.Init(ca::Framework::TrackingMode::kMcbm);
+  fCaFramework.ReceiveParameters(std::move(parameters));
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
 //
 TrackingChain::Return_t TrackingChain::Run(/*vectors of hits*/)
 {
-  ca::Vector<ca::Track> vRecoTracks;
-  ca::TrackingMonitorData monitorData;
-
   // ----- Init input data ---------------------------------------------------------------------------------------------
+  fCaDataManager.ResetInputData(/*nHits = */ 0);
+  // Create and push back hits....
+  fCaDataManager.SetNhitKeys(/*nHitKeys = */ 0);
+  fCaFramework.ReceiveInputData(fCaDataManager.TakeInputData());
 
   // ----- Run reconstruction ------------------------------------------------------------------------------------------
+  // FIXME: SZh 22.10.2023: Return fMonitorDataPerCall, when the corresponding MR is accepted
+  fCaFramework.fTrackFinder.FindTracks();
+  L_(info) << "Timeslice contains " << fCaFramework.fRecoTracks.size() << " tracks";
 
   // ----- Init output data --------------------------------------------------------------------------------------------
-  return std::make_pair(vRecoTracks, monitorData);
+  // FIXME: SZh 22.10.2023: Provide a class for the tracking output data (tracks, hit indices and monitor)
+  return std::make_pair(std::move(fCaFramework.fRecoTracks), fCaFramework.GetMonitor().GetMonitorData());
 }
 
 // ---------------------------------------------------------------------------------------------------------------------
diff --git a/algo/ca/TrackingChain.h b/algo/ca/TrackingChain.h
index f1cd00e99a..c524bd477b 100644
--- a/algo/ca/TrackingChain.h
+++ b/algo/ca/TrackingChain.h
@@ -7,14 +7,15 @@
 /// \brief  A chain class to execute CA tracking algorithm in online reconstruction (header)
 /// \author S.Zharko <s.zharko@gsi.de>
 
-#ifndef CBM_ALGO_CA_TRACKING_CHAIN
-#define CBM_ALGO_CA_TRACKING_CHAIN 1
+#pragma once
 
 #include <vector>
 
+#include "CaDataManager.h"
+#include "CaFramework.h"
 #include "CaTrack.h"
-#include "CaVector.h"
 #include "CaTrackingMonitor.h"
+#include "CaVector.h"
 #include "SubChain.h"
 
 namespace cbm::algo::ca
@@ -49,11 +50,13 @@ namespace cbm::algo
 
     /// \brief  Provides action for a given time-slice
     /// \return A vector of cbm::algo::ca::Track
-    Return_t Run(/*vecotrs of hits*/);
+    Return_t Run(/*vectors of hits*/);
 
     /// \brief  Provides action in the end of the run
     void Finalize();
+
+  private:
+    ca::Framework fCaFramework {};      ///< CA framework instance
+    ca::DataManager fCaDataManager {};  ///< CA data manager
   };
 }  // namespace cbm::algo
-
-#endif  // CBM_ALGO_CA_TRACKING_CHAIN
diff --git a/algo/ca/core/data/CaDataManager.h b/algo/ca/core/data/CaDataManager.h
index ccf124a53d..f24ffe44c8 100644
--- a/algo/ca/core/data/CaDataManager.h
+++ b/algo/ca/core/data/CaDataManager.h
@@ -71,10 +71,6 @@ namespace cbm::algo::ca
     /// \param  nKeys  Number of hit keys
     void SetNhitKeys(int nKeys) { fInputData.fNhitKeys = nKeys; }
 
-    /// \brief Sets number of active stations
-    /// \param nStations  Number of stations
-    void SetNofActiveStations(int nStations) { fNofActiveStations = nStations; }
-
     /// \brief Sends (moves) input data to an object (alternative method of data sending)
     /// \param destination  Destination object of input data
     bool SendInputData(InputData& destination);
@@ -107,11 +103,8 @@ namespace cbm::algo::ca
     // ***************************
     // ** Member variables list **
     // ***************************
-
     InputData fInputData {};  ///< Object of input data
-
     int64_t fLastStreamId {-1};   ///< data stream Id of the last hit added
-    int fNofActiveStations = -1;  ///< Number of active stations
   };
 
 
diff --git a/algo/global/Reco.cxx b/algo/global/Reco.cxx
index ff293c2a85..fae16aded9 100644
--- a/algo/global/Reco.cxx
+++ b/algo/global/Reco.cxx
@@ -294,17 +294,14 @@ void Reco::QueueEvbuildMetrics(const evbuild::EventbuildChainMonitorData& mon)
 
 void Reco::QueueTrackingRecoMetrics(const ca::TrackingMonitorData& monitor)
 {
-  if (!HasMonitor()) { return; } 
+  if (!HasMonitor()) { return; }
 
   GetMonitor().QueueMetric("cbmreco", {{"hostname", fles::system::current_hostname()}, {"child", Opts().ChildId()}},
-                           {
-                             {"caRecoTimeTotal", monitor.GetTimer(ca::ETimer::Tracking).GetTotal()},
-                             {"caTrackFinderTime", monitor.GetTimer(ca::ETimer::TrackFinder).GetTotal()},
-                             {"caTrackFitterTime", monitor.GetTimer(ca::ETimer::TrackFitter).GetTotal()},
-                             {"caNofRecoTracks", monitor.GetCounterValue(ca::ECounter::RecoTrack)},
-                             {"caNofRecoHitsTotal", monitor.GetCounterValue(ca::ECounter::RecoHit)},
-                             {"caNofRecoHitsUsed", monitor.GetCounterValue(ca::ECounter::RecoHitUsed)},
-                             {"caNofWindowa", monitor.GetCounterValue(ca::ECounter::SubTS)}
-                           });
+                           {{"caRecoTimeTotal", monitor.GetTimer(ca::ETimer::Tracking).GetTotal()},
+                            {"caTrackFinderTime", monitor.GetTimer(ca::ETimer::TrackFinder).GetTotal()},
+                            {"caTrackFitterTime", monitor.GetTimer(ca::ETimer::TrackFitter).GetTotal()},
+                            {"caNofRecoTracks", monitor.GetCounterValue(ca::ECounter::RecoTrack)},
+                            {"caNofRecoHitsTotal", monitor.GetCounterValue(ca::ECounter::RecoHit)},
+                            {"caNofRecoHitsUsed", monitor.GetCounterValue(ca::ECounter::RecoHitUsed)},
+                            {"caNofWindowa", monitor.GetCounterValue(ca::ECounter::SubTS)}});
 }
-
diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index b87f935910..58631f4305 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -650,7 +650,7 @@ InitStatus CbmL1::Init()
   // Init L1 algo core
 
   // FIXME: SZh 22.08.2023:
-  //   Re-organize the the relation between CbmL1 and ca::Framework. I belive, we don't need a global pointer to the ca::Framework
+  //   Re-organize the the relation between CbmL1 and ca::Framework. I believe, we don't need a global pointer to the ca::Framework
   //   instance.
   fpAlgo = &gAlgo;
   fpAlgo->Init(fTrackingMode);
@@ -671,7 +671,6 @@ InitStatus CbmL1::Init()
   fNStations     = fpAlgo->GetParameters().GetNstationsActive();
 
   LOG(info) << fpAlgo->GetParameters().ToString(1);
-  fpIODataManager->SetNofActiveStations(fNStations);
 
   LOG(info) << "----- Numbers of stations active in tracking -----";
   LOG(info) << "  MVD:    " << fNMvdStations;
-- 
GitLab