From 124e81991a771df594f3dd3fcb75ed3a9f9660c3 Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Wed, 19 Oct 2022 21:22:45 +0200
Subject: [PATCH] L1[bugfix]: digi parameters initialization was added in TOF
 tracking interface

---
 .../base/CbmTrackingDetectorInterfaceBase.cxx | 44 ++++++++++++++++++-
 core/base/CbmTrackingDetectorInterfaceBase.h  |  3 ++
 .../detectors/tof/CbmTofTrackingInterface.cxx |  7 ++-
 macro/run/run_qa.C                            | 10 ++++-
 mvd/CbmMvdTrackingInterface.cxx               |  2 +-
 5 files changed, 62 insertions(+), 4 deletions(-)

diff --git a/core/base/CbmTrackingDetectorInterfaceBase.cxx b/core/base/CbmTrackingDetectorInterfaceBase.cxx
index 9fad5ba124..997182b13d 100644
--- a/core/base/CbmTrackingDetectorInterfaceBase.cxx
+++ b/core/base/CbmTrackingDetectorInterfaceBase.cxx
@@ -11,13 +11,17 @@
 
 #include <Logger.h>
 
+#include <iomanip>
 #include <limits>
 #include <set>
 #include <vector>
 
+// ---------------------------------------------------------------------------------------------------------------------
+//
 bool CbmTrackingDetectorInterfaceBase::Check() const
 {
   bool res = true;
+  LOG(info) << ToString();
   std::stringstream msg;
   msg << "Errors in the detector interface initialization for " << this->GetDetectorName() << ":\n";
 
@@ -27,7 +31,6 @@ bool CbmTrackingDetectorInterfaceBase::Check() const
     res = false && res;
   }
   else {
-
     // Station individual parameters check
     for (int iSt = 0; iSt < this->GetNtrackingStations(); ++iSt) {
       std::string prefix = std::string("\t- Station ") + std::to_string(iSt) + " has ";
@@ -124,3 +127,42 @@ bool CbmTrackingDetectorInterfaceBase::Check() const
 
   return res;
 }
+
+// ---------------------------------------------------------------------------------------------------------------------
+//
+std::string CbmTrackingDetectorInterfaceBase::ToString() const
+{
+  using std::setfill;
+  using std::setw;
+  std::stringstream table;
+  table << "\nTracking detector interface: " << setw(5) << setfill(' ') << GetDetectorName() << '\n';
+  table << setw(5) << setfill(' ') << "st.No" << ' ';
+  table << setw(10) << setfill(' ') << "z[cm]" << ' ';
+  table << setw(10) << setfill(' ') << "R_min[cm]" << ' ';
+  table << setw(10) << setfill(' ') << "R_max[cm]" << ' ';
+  table << setw(10) << setfill(' ') << "x_max[cm]" << ' ';
+  table << setw(10) << setfill(' ') << "y_max[cm]" << ' ';
+  table << setw(12) << setfill(' ') << "res.time[ns]" << ' ';
+  table << setw(11) << setfill(' ') << "angleF[rad]" << ' ';
+  table << setw(11) << setfill(' ') << "angleB[rad]" << ' ';
+  table << setw(10) << setfill(' ') << "res.F [cm]" << ' ';
+  table << setw(10) << setfill(' ') << "res.B [cm]" << ' ';
+  table << setw(10) << setfill(' ') << "dz [cm]" << ' ';
+  table << setw(10) << setfill(' ') << "RL [cm]" << '\n';
+  for (int iSt = 0; iSt < GetNtrackingStations(); ++iSt) {
+    table << setw(5) << setfill(' ') << iSt << ' ';
+    table << setw(10) << setfill(' ') << GetZ(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetRmin(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetRmax(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetXmax(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetYmax(iSt) << ' ';
+    table << setw(12) << setfill(' ') << GetTimeResolution(iSt) << ' ';
+    table << setw(11) << setfill(' ') << GetStripsStereoAngleFront(iSt) << ' ';
+    table << setw(11) << setfill(' ') << GetStripsStereoAngleBack(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetStripsSpatialRmsFront(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetStripsSpatialRmsBack(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetThickness(iSt) << ' ';
+    table << setw(10) << setfill(' ') << GetRadLength(iSt) << '\n';
+  }
+  return table.str();
+}
diff --git a/core/base/CbmTrackingDetectorInterfaceBase.h b/core/base/CbmTrackingDetectorInterfaceBase.h
index c5a5827bee..2c402a314f 100644
--- a/core/base/CbmTrackingDetectorInterfaceBase.h
+++ b/core/base/CbmTrackingDetectorInterfaceBase.h
@@ -117,6 +117,9 @@ public:
 
   /// Checks detector interface: boundary conditions of the parameters
   bool Check() const;
+
+  /// Prints all the parameters into table and saves the table as a string
+  std::string ToString() const;
 };
 
 #endif  // CbmTrackingDetectorInterfaceBase_h
diff --git a/core/detectors/tof/CbmTofTrackingInterface.cxx b/core/detectors/tof/CbmTofTrackingInterface.cxx
index ff5e388559..de024d1750 100644
--- a/core/detectors/tof/CbmTofTrackingInterface.cxx
+++ b/core/detectors/tof/CbmTofTrackingInterface.cxx
@@ -12,6 +12,7 @@
 #include "CbmTofTrackingInterface.h"
 
 #include "CbmTofCell.h"
+#include "CbmTofCreateDigiPar.h"
 #include "CbmTofDigiPar.h"
 
 #include "FairDetector.h"
@@ -40,6 +41,10 @@ CbmTofTrackingInterface::~CbmTofTrackingInterface()
 //
 InitStatus CbmTofTrackingInterface::Init()
 {
+  // create digitization parameters from geometry file
+  CbmTofCreateDigiPar* tofDigiPar = new CbmTofCreateDigiPar("TOF Digi Producer", "TOF task");
+  LOG(info) << "Create DigiPar";
+  tofDigiPar->Init();
   // ** ToF tracking station position z-components initialization **
 
   // Init ToF stations position z-components. For each ToF tracking station the position z-component is calculated
@@ -56,7 +61,6 @@ InitStatus CbmTofTrackingInterface::Init()
         int iAddr         = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType);
         int station       = fDigiBdfPar->GetTrackingStation(iSmType, iSm, iRpc);
         auto* channelInfo = dynamic_cast<CbmTofCell*>(fDigiPar->GetCell(iAddr));
-
         if (nullptr == channelInfo) { break; }
 
         float z = channelInfo->GetZ();
@@ -103,6 +107,7 @@ InitStatus CbmTofTrackingInterface::ReInit()
 //
 void CbmTofTrackingInterface::SetParContainers()
 {
+
   auto runtimeDb = FairRunAna::Instance()->GetRuntimeDb();
   fDigiPar       = dynamic_cast<CbmTofDigiPar*>(runtimeDb->getContainer("CbmTofDigiPar"));
   fDigiBdfPar    = dynamic_cast<CbmTofDigiBdfPar*>(runtimeDb->getContainer("CbmTofDigiBdfPar"));
diff --git a/macro/run/run_qa.C b/macro/run/run_qa.C
index 2292beed81..eae28b1e68 100644
--- a/macro/run/run_qa.C
+++ b/macro/run/run_qa.C
@@ -189,7 +189,15 @@ void run_qa(TString dataTra = "data/sis100_muon_jpsi_test", TString dataRaw = "d
 
   // ----- TRD QA  ---------------------------------
   if (CbmSetup::Instance()->IsActive(ECbmModuleId::kTof)) {
-    run->AddTask(new CbmTrackerInputQaTof());  // Tracker requirements to TRD
+    // TODO: SZh 19.10.2022:
+    // After the proper TOF digi parameters initialization it is appeared,
+    // that CbmTrackerInputQaTof causes segmentation violation in
+    // CbmTrackerInputQaTof::ResolutionQa() for the event-based running
+    // (before the branch with the related code inside the task was never
+    // executed). Temporarily commented that task, till the bug would not be
+    // resolved.
+
+    //run->AddTask(new CbmTrackerInputQaTof());  // Tracker requirements to TRD
   }
   // ------------------------------------------------------------------------
 
diff --git a/mvd/CbmMvdTrackingInterface.cxx b/mvd/CbmMvdTrackingInterface.cxx
index f3e9655ade..7714dc6143 100644
--- a/mvd/CbmMvdTrackingInterface.cxx
+++ b/mvd/CbmMvdTrackingInterface.cxx
@@ -44,7 +44,7 @@ InitStatus CbmMvdTrackingInterface::Init()
   // Check the validity of the parameters
   if (!this->Check()) {
     LOG(error)
-      << "Some errors occurred in the tracking detector interface initialization for MuCh (see information above)";
+      << "Some errors occurred in the tracking detector interface initialization for MVD (see information above)";
     return kFATAL;
   }
 
-- 
GitLab