From 6c7d2a6f35a45225528d62f4cf5abfb6a93417e1 Mon Sep 17 00:00:00 2001
From: "se.gorbunov" <se.gorbunov@gsi.de>
Date: Wed, 18 Oct 2023 21:20:34 +0000
Subject: [PATCH] Ca: cleanup

---
 algo/ca/core/utils/CaDefines.h                | 18 ++++
 reco/KF/ParticleFitter/CbmL1PFFitter.cxx      |  1 -
 reco/KF/obsolete/CbmL1TofMerger.cxx           |  2 -
 reco/KF/obsolete/CbmL1TrackMerger.cxx         |  2 -
 reco/L1/CMakeLists.txt                        |  6 --
 reco/L1/CbmL1.cxx                             |  2 -
 reco/L1/CbmL1Performance.cxx                  |  3 +-
 reco/L1/L1Algo/L1Algo.h                       | 23 ++---
 reco/L1/L1Algo/L1CaTrackFinderSlice.cxx       |  9 --
 reco/L1/L1Algo/L1CloneMerger.cxx              |  6 --
 reco/L1/L1Algo/L1CloneMerger.h                |  1 -
 reco/L1/L1Algo/L1Def.h                        | 43 ----------
 reco/L1/L1Algo/L1Utils.h                      | 85 -------------------
 reco/L1/L1Algo/utils/CaUvConverter.h          |  1 -
 reco/L1/L1Algo/utils/L1AlgoDraw.h             |  1 -
 .../utils/L1AlgoEfficiencyPerformance.h       |  1 -
 reco/L1/L1Algo/utils/L1AlgoPulls.h            |  1 -
 reco/L1/qa/CbmCaTrackFitQa.cxx                |  1 -
 reco/L1/utils/CbmCaIdealHitProducerDet.h      |  1 -
 19 files changed, 28 insertions(+), 179 deletions(-)
 delete mode 100644 reco/L1/L1Algo/L1Def.h
 delete mode 100644 reco/L1/L1Algo/L1Utils.h

diff --git a/algo/ca/core/utils/CaDefines.h b/algo/ca/core/utils/CaDefines.h
index ae101e651f..04e58e8013 100644
--- a/algo/ca/core/utils/CaDefines.h
+++ b/algo/ca/core/utils/CaDefines.h
@@ -21,8 +21,26 @@
     std::cerr << __FILE__ << ":" << __LINE__ << " assertion failed: " << #v << " = " << (v) << std::endl;              \
     assert(v);                                                                                                         \
   }
+
+#define CBMCA_DEBUG_SHOW(expr)                                                                                         \
+  std::cout << __FILE__ << ":" << __LINE__ << ": \033[01;38;5;208m" << (#expr) << "\033[0m = " << (expr) << "\n"
+
+#define CBMCA_DEBUG_SHOWF(msg)                                                                                         \
+  std::cout << "(!) " << __FILE__ << ":" << __LINE__ << ": \033[01;38;5;208m" << (#msg) << "\033[0m\n"
+
+#define CBMCA_DEBUG_SHOWCONTAINER(cont)                                                                                \
+  std::cout << __FILE__ << ":" << __LINE__ << ": \033[01;38;5;208m" << (#cont) << "\033[0m: ";                         \
+  std::for_each(cont.cbegin(), cont.cend(), [](const auto& el) { std::cout << el << ' '; });                           \
+  std::cout << '\n';
+
 #else  // not CBMCA_DEBUG_MODE
 
 #define CBMCA_DEBUG_ASSERT(v)
 
+#define CBMCA_DEBUG_SHOW(expr)
+
+#define CBMCA_DEBUG_SHOWF(msg)
+
+#define CBMCA_DEBUG_SHOWCONTAINER(cont)
+
 #endif  // CBMCA_DEBUG_MODE
diff --git a/reco/KF/ParticleFitter/CbmL1PFFitter.cxx b/reco/KF/ParticleFitter/CbmL1PFFitter.cxx
index 8118377e9d..b4a6162c7a 100644
--- a/reco/KF/ParticleFitter/CbmL1PFFitter.cxx
+++ b/reco/KF/ParticleFitter/CbmL1PFFitter.cxx
@@ -41,7 +41,6 @@
 #include "CaTrackParam.h"
 #include "KFParticleDatabase.h"
 #include "L1Algo.h"  // Also defines L1Parameters
-#include "L1Def.h"
 
 //typedef ca::TrackFit1 ca::TrackFit;
 
diff --git a/reco/KF/obsolete/CbmL1TofMerger.cxx b/reco/KF/obsolete/CbmL1TofMerger.cxx
index 791cc19021..a3cf09a664 100644
--- a/reco/KF/obsolete/CbmL1TofMerger.cxx
+++ b/reco/KF/obsolete/CbmL1TofMerger.cxx
@@ -22,8 +22,6 @@
 #include <map>
 #include <utility>
 
-#include "L1Def.h"
-
 using std::cout;
 using std::endl;
 using std::make_pair;
diff --git a/reco/KF/obsolete/CbmL1TrackMerger.cxx b/reco/KF/obsolete/CbmL1TrackMerger.cxx
index 2acf4de2e1..f4c93462fb 100644
--- a/reco/KF/obsolete/CbmL1TrackMerger.cxx
+++ b/reco/KF/obsolete/CbmL1TrackMerger.cxx
@@ -23,8 +23,6 @@
 #include <iostream>
 #include <map>
 
-#include "L1Def.h"
-
 using std::cout;
 using std::endl;
 using std::map;
diff --git a/reco/L1/CMakeLists.txt b/reco/L1/CMakeLists.txt
index d86fb29b54..3ab91e31e3 100644
--- a/reco/L1/CMakeLists.txt
+++ b/reco/L1/CMakeLists.txt
@@ -89,7 +89,6 @@ set(HEADERS
   CbmL1Hit.h
   CbmL1Track.h
   CbmL1Vtx.h
-  L1Algo/L1Def.h
   L1Algo/utils/CaUvConverter.h
   catools/CaToolsWindowFinder.h
   catools/CaToolsLinkKey.h
@@ -181,15 +180,10 @@ generate_cbm_library()
 add_dependencies(G__L1 KFPARTICLE)
 
 install(FILES CbmL1Counters.h
-#  L1Algo/L1Assert.h
-  L1Algo/L1Utils.h
   utils/CbmCaIdealHitProducer.h
   utils/CbmCaIdealHitProducerDet.h
   L1Algo/utils/CaUvConverter.h
   qa/CbmCaInputQaBase.h
-#  L1Algo/inactive/L1EventEfficiencies.h
-#  L1Algo/inactive/L1Event.h
-#  L1Algo/inactive/L1EventMatch.h
   DESTINATION include
 )
 
diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index 79f9218e4f..f32cff1496 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -421,7 +421,6 @@ InitStatus CbmL1::Init()
     }
 
     fInitManager.SetDetectorNames(cbm::ca::kDetName);
-    L1_SHOW(fInitManager.GetDetectorName(ca::EDetectorID::kSts));
 
     auto mvdInterface  = CbmMvdTrackingInterface::Instance();
     auto stsInterface  = CbmStsTrackingInterface::Instance();
@@ -1103,7 +1102,6 @@ void CbmL1::DefineSTAPNames(const char* dirName)
   TString sDirName = TString(dirName);
   if (sDirName.Length() == 0) {
     fSTAPDataDir = pathToRecoOutput.parent_path().string();
-    L1_SHOW(fSTAPDataDir);
   }
   else if (bfs::exists(sDirName.Data()) && bfs::is_directory(sDirName.Data())) {
     fSTAPDataDir = sDirName;
diff --git a/reco/L1/CbmL1Performance.cxx b/reco/L1/CbmL1Performance.cxx
index 83cdcf733a..51d507a1bb 100644
--- a/reco/L1/CbmL1Performance.cxx
+++ b/reco/L1/CbmL1Performance.cxx
@@ -57,8 +57,7 @@
 
 #include "CaToolsDebugger.h"
 #include "CaTrackFit.h"
-#include "L1Algo/L1Algo.h"
-#include "L1Algo/L1Def.h"
+#include "L1Algo.h"
 
 using cbm::ca::tools::Debugger;
 using std::cout;
diff --git a/reco/L1/L1Algo/L1Algo.h b/reco/L1/L1Algo/L1Algo.h
index 9ed463c9df..e625198f28 100644
--- a/reco/L1/L1Algo/L1Algo.h
+++ b/reco/L1/L1Algo/L1Algo.h
@@ -12,7 +12,6 @@
 // #define DRAW             // event display
 #ifdef DRAW
 class L1AlgoDraw;
-#include "CbmL1Track.h"
 #endif
 //#define XXX               // time debug
 //#define COUNTERS          // diff counters (hits, doublets, ... )
@@ -20,8 +19,6 @@ class L1AlgoDraw;
 //#define GLOBAL
 //#define mCBM
 
-#define FIND_GAPED_TRACKS  // use triplets with gaps
-
 #include <array>
 #include <iomanip>
 #include <iostream>
@@ -43,7 +40,6 @@ class L1AlgoDraw;
 #include "CaTriplet.h"
 #include "CaVector.h"
 #include "L1CloneMerger.h"
-#include "L1Utils.h"
 
 using namespace cbm::algo::ca;  //TODO: remove
 
@@ -219,7 +215,6 @@ public:
 
 #ifdef DRAW
   L1AlgoDraw* draw {nullptr};
-  void DrawRecoTracksTime(const Vector<CbmL1Track>& tracks);
 #endif
 
   /// TODO: Move to L1
@@ -363,19 +358,19 @@ private:
   float fTimeCut2 {0.f};
 
   /// correction in order to take into account overlaping and iff z. if sort by y then it is max diff between same station's modules (~0.4cm)
-  fvec fMaxDZ {L1Utils::kNaN};
+  fvec fMaxDZ {constants::Undef<fvec>};
 
   /// parameters which are different for different iterations. Set in the begin of CAL1TrackFinder
 
-  float fPickGather {L1Utils::kNaN};       ///< same for attaching additional hits to track
-  float fTripletLinkChi2 {L1Utils::kNaN};  ///< (dp2/dp_error2 < fTripletLinkChi2)  =>  triplets are neighbours
-  fvec fMaxInvMom {L1Utils::kNaN};         ///< max considered q/p for tracks
-  fvec fMaxSlopePV {L1Utils::kNaN};        ///< max slope (tx\ty) in prim vertex
-  float fMaxSlope {L1Utils::kNaN};         ///< max slope (tx\ty) in 3d hit position of a triplet
+  float fPickGather {constants::Undef<fvec>};       ///< same for attaching additional hits to track
+  float fTripletLinkChi2 {constants::Undef<fvec>};  ///< (dp2/dp_error2 < fTripletLinkChi2)  =>  triplets are neighbours
+  fvec fMaxInvMom {constants::Undef<fvec>};         ///< max considered q/p for tracks
+  fvec fMaxSlopePV {constants::Undef<fvec>};        ///< max slope (tx\ty) in prim vertex
+  float fMaxSlope {constants::Undef<fvec>};         ///< max slope (tx\ty) in 3d hit position of a triplet
 
-  fvec fTargX {L1Utils::kNaN};  ///< target position x coordinate for the current iteration (modifiable)
-  fvec fTargY {L1Utils::kNaN};  ///< target position y coordinate for the current iteration (modifiable)
-  fvec fTargZ {L1Utils::kNaN};  ///< target position z coordinate for the current iteration (modifiable)
+  fvec fTargX {constants::Undef<fvec>};  ///< target position x coordinate for the current iteration (modifiable)
+  fvec fTargY {constants::Undef<fvec>};  ///< target position y coordinate for the current iteration (modifiable)
+  fvec fTargZ {constants::Undef<fvec>};  ///< target position z coordinate for the current iteration (modifiable)
 
   bool fIsTargetField {false};  ///< is the magnetic field present at the target
 
diff --git a/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx b/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx
index f5e481871d..ca2249227b 100644
--- a/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx
+++ b/reco/L1/L1Algo/L1CaTrackFinderSlice.cxx
@@ -865,12 +865,3 @@ void L1Algo::CAFindTrack(int ista, ca::Branch& best_tr, const ca::Triplet* curr_
     }    // for neighbours
   }      // level = 0
 }
-
-#ifdef DRAW
-void L1Algo::DrawRecoTracksTime(const cbm::algo::ca::Vector<CbmL1Track>& tracks)
-{
-  // TODO: find where the DrawRecoTracksTime is. It is missing in the git repository.
-  //draw->DrawRecoTracksTime(tracks);
-  draw->SaveCanvas(" ");
-}
-#endif
diff --git a/reco/L1/L1Algo/L1CloneMerger.cxx b/reco/L1/L1Algo/L1CloneMerger.cxx
index c592bec15f..707d12ba6c 100644
--- a/reco/L1/L1Algo/L1CloneMerger.cxx
+++ b/reco/L1/L1Algo/L1CloneMerger.cxx
@@ -63,9 +63,6 @@ void L1CloneMerger::Exec(Vector<Track>& extTracks, Vector<ca::HitIndex_t>& extRe
 
   ca::HitIndex_t start_hit = 0;
 
-#ifdef OMP
-#pragma omp parallel for
-#endif
   for (int iTr = 0; iTr < nTracks; iTr++) {
     firstHit[iTr]     = start_hit;
     firstStation[iTr] = frAlgo.GetInputData().GetHit(extRecoHits[start_hit]).Station();
@@ -98,9 +95,6 @@ void L1CloneMerger::Exec(Vector<Track>& extTracks, Vector<ca::HitIndex_t>& extRe
   // Max length for merging
   unsigned char maxLengthForMerge = static_cast<unsigned char>(frAlgo.GetParameters()->GetNstationsActive() - 3);
 
-#ifdef OMP
-#pragma omp parallel for
-#endif
   for (int iTr = 0; iTr < nTracks; iTr++) {
     if (extTracks[iTr].fNofHits > maxLengthForMerge) continue;
     for (int jTr = 0; jTr < nTracks; jTr++) {
diff --git a/reco/L1/L1Algo/L1CloneMerger.h b/reco/L1/L1Algo/L1CloneMerger.h
index 41a16f16a9..d115dac8c5 100644
--- a/reco/L1/L1Algo/L1CloneMerger.h
+++ b/reco/L1/L1Algo/L1CloneMerger.h
@@ -13,7 +13,6 @@
 #include "CaHit.h"   // For ca::HitIndex_t
 #include "CaSimd.h"  // TEMPORARY FOR fvec, fscal
 #include "CaVector.h"
-//#include "L1Def.h"
 
 
 using namespace cbm::algo::ca;  //TODO: remove
diff --git a/reco/L1/L1Algo/L1Def.h b/reco/L1/L1Algo/L1Def.h
deleted file mode 100644
index 3db98677f6..0000000000
--- a/reco/L1/L1Algo/L1Def.h
+++ /dev/null
@@ -1,43 +0,0 @@
-/* Copyright (C) 2010-2021 Frankfurt Institute for Advanced Studies, Goethe-Universität Frankfurt, Frankfurt
-   SPDX-License-Identifier: GPL-3.0-only
-   Authors: Maksym Zyzak, Igor Kulakov [committer], Sergey Gorbunov */
-
-#ifndef L1Def_h
-#define L1Def_h
-
-// #define FAST_CODE // FAST_CODE = more unsafe
-
-#include <iostream>
-
-#ifdef FAST_CODE
-
-#define L1_NO_ASSERT  // use with asserts, etc.
-
-#else  // FAST_CODE
-
-
-#endif  // FAST_CODE
-
-
-#if defined(NDEBUG) || defined(L1_NO_ASSERT)
-
-// Prints expression value to the std::cout
-#define L1_SHOW(expr)
-
-// Prints file and line information to the std::cout
-#define L1_SHOWF(msg)
-
-#else
-
-#define L1_SHOW(expr)                                                                                                  \
-  std::cout << __FILE__ << ":" << __LINE__ << ": \033[01;38;5;208m" << (#expr) << "\033[0m = " << (expr) << "\n"
-#define L1_SHOWF(msg)                                                                                                  \
-  std::cout << "(!) " << __FILE__ << ":" << __LINE__ << ": \033[01;38;5;208m" << (#msg) << "\033[0m\n"
-#define L1_SHOWCONTAINER(cont)                                                                                         \
-  std::cout << __FILE__ << ":" << __LINE__ << ": \033[01;38;5;208m" << (#cont) << "\033[0m: ";                         \
-  std::for_each(cont.cbegin(), cont.cend(), [](const auto& el) { std::cout << el << ' '; });                           \
-  std::cout << '\n';
-
-#endif
-
-#endif
diff --git a/reco/L1/L1Algo/L1Utils.h b/reco/L1/L1Algo/L1Utils.h
deleted file mode 100644
index cfd3f0c5c0..0000000000
--- a/reco/L1/L1Algo/L1Utils.h
+++ /dev/null
@@ -1,85 +0,0 @@
-/* Copyright (C) 2022 GSI Helmholtzzentrum fuer Schwerionenforschung, Darmstadt
-   SPDX-License-Identifier: GPL-3.0-only
-   Authors: Sergey Gorbunov, Sergei Zharko [committer] */
-
-/************************************************************************************************************
- * @file  L1Utils.h
- * @brief File contains some general purpose functions for L1Algo
- * @since 12.01.2022
- ***********************************************************************************************************/
-#ifndef L1Utils_h
-#define L1Utils_h 1
-
-#include <chrono>
-#include <iomanip>
-#include <limits>
-#include <map>
-#include <sstream>
-#include <string>
-#include <type_traits>
-#include <unordered_map>
-
-#include <cmath>
-
-#include "AlgoFairloggerCompat.h"
-#include "CaSimd.h"
-#include "CaUtils.h"
-#include "L1Def.h"
-
-// TODO: SZh 16.05.2023:  Split this class into several headers and place them into L1Algo::utils
-
-
-/// Class contains some utility functions for L1Algo
-namespace L1Utils
-{
-  /// NaN value for float
-  // TODO: SZh 16.05.2023: Replace this kNaN with L1Undef::kF
-  constexpr float kNaN {std::numeric_limits<float>::signaling_NaN()};
-
-  /// Comparison method for floats
-  /// \param  lhs  Left floating point to compare
-  /// \param  rhs  Right floating point to compare
-  /// \return      Comparison result: true - equals within epsilon
-  template<typename T, typename std::enable_if<std::is_floating_point<T>::value, T>::type* = nullptr>
-  [[gnu::always_inline]] inline bool CmpFloats(T lhs, T rhs)
-  {
-    return fabs(lhs - rhs) < 2. * std::numeric_limits<T>::epsilon() * fabs(lhs + rhs)
-           || fabs(lhs - rhs) < std::numeric_limits<T>::min();
-  }
-
-  using cbm::algo::ca::utils::CheckSimdVectorEquality;
-
-  /// Hash for unordered_map with enum class keys
-  struct EnumClassHash {
-    template<typename T>
-    int operator()(T t) const
-    {
-      return static_cast<int>(t);
-    }
-  };
-
-  /// A time profiler for measuring performace of scopes
-  class TimeProfiler {
-  public:
-    /// Constructor
-    TimeProfiler(const char* scopeName) : fScopeName(scopeName), fStart(std::chrono::high_resolution_clock::now())
-    {
-      LOG(info) << "---------- Time measurement in scope \033[1;32m" << fScopeName << "\033[0m: Start";
-    }
-
-    /// Destructor
-    ~TimeProfiler()
-    {
-      auto stop = std::chrono::high_resolution_clock::now();
-      auto time = std::chrono::duration_cast<std::chrono::nanoseconds>(stop - fStart).count();
-      LOG(info) << "---------- Time measurement in scope \033[1;32m" << fScopeName
-                << "\033[0m: Finish. Result: " << time << " ns";
-    }
-
-  private:
-    const char* fScopeName {};
-    const std::chrono::high_resolution_clock::time_point fStart {};
-  };
-}  // namespace L1Utils
-
-#endif  // L1Utils_h
diff --git a/reco/L1/L1Algo/utils/CaUvConverter.h b/reco/L1/L1Algo/utils/CaUvConverter.h
index 236ab406af..5f356f05d8 100644
--- a/reco/L1/L1Algo/utils/CaUvConverter.h
+++ b/reco/L1/L1Algo/utils/CaUvConverter.h
@@ -7,7 +7,6 @@
 
 
 #include "CaConstants.h"
-#include "L1Def.h"
 
 namespace cbm::ca
 {
diff --git a/reco/L1/L1Algo/utils/L1AlgoDraw.h b/reco/L1/L1Algo/utils/L1AlgoDraw.h
index a58c2e770a..dbb0d68b08 100644
--- a/reco/L1/L1Algo/utils/L1AlgoDraw.h
+++ b/reco/L1/L1Algo/utils/L1AlgoDraw.h
@@ -13,7 +13,6 @@
 #include "CaHit.h"
 #include "CaStation.h"
 #include "CaTriplet.h"
-#include "L1Def.h"
 
 namespace
 {
diff --git a/reco/L1/L1Algo/utils/L1AlgoEfficiencyPerformance.h b/reco/L1/L1Algo/utils/L1AlgoEfficiencyPerformance.h
index d4f0cb52b3..07656bb9c1 100644
--- a/reco/L1/L1Algo/utils/L1AlgoEfficiencyPerformance.h
+++ b/reco/L1/L1Algo/utils/L1AlgoEfficiencyPerformance.h
@@ -19,7 +19,6 @@
 #include <vector>
 
 #include "L1Algo.h"
-#include "L1Def.h"
 
 using std::cout;
 using std::endl;
diff --git a/reco/L1/L1Algo/utils/L1AlgoPulls.h b/reco/L1/L1Algo/utils/L1AlgoPulls.h
index 3b105391a9..e82bc5cf25 100644
--- a/reco/L1/L1Algo/utils/L1AlgoPulls.h
+++ b/reco/L1/L1Algo/utils/L1AlgoPulls.h
@@ -25,7 +25,6 @@ const int NStations = 0;
 
 #include "CaTrackParam.h"
 #include "L1Algo.h"
-#include "L1Def.h"
 
 using std::cout;
 using std::endl;
diff --git a/reco/L1/qa/CbmCaTrackFitQa.cxx b/reco/L1/qa/CbmCaTrackFitQa.cxx
index 7a8f8b3ee7..97875b5c4b 100644
--- a/reco/L1/qa/CbmCaTrackFitQa.cxx
+++ b/reco/L1/qa/CbmCaTrackFitQa.cxx
@@ -24,7 +24,6 @@
 #include "CaToolsField.h"
 #include "CaToolsMCData.h"
 #include "CaTrackFit.h"
-#include "L1Utils.h"
 
 using namespace cbm::algo::ca;
 
diff --git a/reco/L1/utils/CbmCaIdealHitProducerDet.h b/reco/L1/utils/CbmCaIdealHitProducerDet.h
index 0673146101..e196a63277 100644
--- a/reco/L1/utils/CbmCaIdealHitProducerDet.h
+++ b/reco/L1/utils/CbmCaIdealHitProducerDet.h
@@ -56,7 +56,6 @@
 #include "CaAlgoRandom.h"
 #include "CaConstants.h"
 #include "CaUvConverter.h"
-#include "L1Def.h"
 
 namespace cbm::ca
 {
-- 
GitLab