From 7ea17fa881403e7b22ef5a6f912fa725c3b63ccc Mon Sep 17 00:00:00 2001
From: "s.zharko@gsi.de" <s.zharko@gsi.de>
Date: Mon, 18 Apr 2022 00:37:49 +0200
Subject: [PATCH] L1Algo: L1CAIteration added to the iterations loop

---
 reco/L1/CbmL1.cxx                       |  24 +++---
 reco/L1/L1Algo/L1CATrackFinder.cxx      |  91 +++++++++++----------
 reco/L1/L1Algo/L1ObjectInitController.h | 101 +++++++++++++-----------
 3 files changed, 120 insertions(+), 96 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index 3d17b13798..ca112aaf35 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -1001,7 +1001,7 @@ InitStatus CbmL1::Init()
       trackingIterAllPrim.SetDoubletChi2Cut(7.56327f);
       trackingIterAllPrim.SetPickGather(4.0f);
       trackingIterAllPrim.SetPickNeighbour(5.0f);
-      trackingIterAllPrim.SetMaxInvMom(1.0 / 0.5);
+      trackingIterAllPrim.SetMaxInvMom(1.0 / 0.05);
       trackingIterAllPrim.SetMaxSlopePV(1.1f);
       trackingIterAllPrim.SetMaxSlope(2.748f);
 
@@ -1021,7 +1021,7 @@ InitStatus CbmL1::Init()
       trackingIterAllSec.SetDoubletChi2Cut(7.56327f);
       trackingIterAllSec.SetPickGather(4.0f);
       trackingIterAllSec.SetPickNeighbour(5.0f);
-      trackingIterAllSec.SetMaxInvMom(1.0 / 0.5);
+      trackingIterAllSec.SetMaxInvMom(1.0 / 0.1);
       trackingIterAllSec.SetMaxSlopePV(1.5f);
       trackingIterAllSec.SetMaxSlope(2.748f);
 
@@ -1041,7 +1041,7 @@ InitStatus CbmL1::Init()
       trackingIterAllPrimJump.SetDoubletChi2Cut(7.56327f);
       trackingIterAllPrimJump.SetPickGather(4.0f);
       trackingIterAllPrimJump.SetPickNeighbour(5.0f);
-      trackingIterAllPrimJump.SetMaxInvMom(1.0 / 0.5);
+      trackingIterAllPrimJump.SetMaxInvMom(1.0 / 0.1);
       trackingIterAllPrimJump.SetMaxSlopePV(1.1f);
       trackingIterAllPrimJump.SetMaxSlope(2.748f);
 
@@ -1051,7 +1051,7 @@ InitStatus CbmL1::Init()
       trackingIterAllSecJump.SetDoubletChi2Cut(7.56327f);
       trackingIterAllSecJump.SetPickGather(4.0f);
       trackingIterAllSecJump.SetPickNeighbour(5.0f);
-      trackingIterAllSecJump.SetMaxInvMom(1.0 / 0.5);
+      trackingIterAllSecJump.SetMaxInvMom(1.0 / 0.1);
       trackingIterAllSecJump.SetMaxSlopePV(1.5f);
       trackingIterAllSecJump.SetMaxSlope(2.748f);
 
@@ -1061,7 +1061,7 @@ InitStatus CbmL1::Init()
       trackingIterAllPrimE.SetDoubletChi2Cut(7.56327f);
       trackingIterAllPrimE.SetPickGather(4.0f);
       trackingIterAllPrimE.SetPickNeighbour(5.0f);
-      trackingIterAllPrimE.SetMaxInvMom(1.0 / 0.5);
+      trackingIterAllPrimE.SetMaxInvMom(1.0 / 0.05);
       trackingIterAllPrimE.SetMaxSlopePV(1.1f);
       trackingIterAllPrimE.SetMaxSlope(2.748f);
 
@@ -1071,7 +1071,7 @@ InitStatus CbmL1::Init()
       trackingIterAllSecE.SetDoubletChi2Cut(7.56327f);
       trackingIterAllSecE.SetPickGather(4.0f);
       trackingIterAllSecE.SetPickNeighbour(5.0f);
-      trackingIterAllSecE.SetMaxInvMom(1.0 / 0.5);
+      trackingIterAllSecE.SetMaxInvMom(1.0 / 0.05);
       trackingIterAllSecE.SetMaxSlopePV(1.5f);
       trackingIterAllSecE.SetMaxSlope(2.748f);
 
@@ -1095,17 +1095,17 @@ InitStatus CbmL1::Init()
         initMan->PushBackCAIteration(trackingIterAllSec);
       }
       else {
-        initMan->SetCAIterationsNumberCrosscheck(9);
+        initMan->SetCAIterationsNumberCrosscheck(4);
         // Initialize CA track finder iterations sequence
         initMan->PushBackCAIteration(trackingIterFastPrim);
         initMan->PushBackCAIteration(trackingIterAllPrim);
         initMan->PushBackCAIteration(trackingIterAllPrimJump);
         initMan->PushBackCAIteration(trackingIterAllSec);
-        initMan->PushBackCAIteration(trackingIterAllPrimE);
-        initMan->PushBackCAIteration(trackingIterAllSecE);
-        initMan->PushBackCAIteration(trackingIterFastPrimJump);
-        initMan->PushBackCAIteration(trackingIterFastPrim2);
-        initMan->PushBackCAIteration(trackingIterAllSecJump);
+        //initMan->PushBackCAIteration(trackingIterAllPrimE);
+        //initMan->PushBackCAIteration(trackingIterAllSecE);
+        //initMan->PushBackCAIteration(trackingIterFastPrimJump);
+        //initMan->PushBackCAIteration(trackingIterFastPrim2);
+        //initMan->PushBackCAIteration(trackingIterAllSecJump);
       }
 
       // Set special cuts
diff --git a/reco/L1/L1Algo/L1CATrackFinder.cxx b/reco/L1/L1Algo/L1CATrackFinder.cxx
index 6cc6f718f7..2157c987dd 100644
--- a/reco/L1/L1Algo/L1CATrackFinder.cxx
+++ b/reco/L1/L1Algo/L1CATrackFinder.cxx
@@ -1762,7 +1762,14 @@ void L1Algo::CATrackFinder()
 
 
   // ---- Loop over Track Finder iterations ----------------------------------------------------------------//
-  for (isec = 0; isec < fNFindIterations; ++isec)  // all finder
+#ifdef FIND_GAPED_TRACKS
+  std::cout << "\033[1;32mFIND_GAPED_TRACKS\033[0m\n";
+#endif  // FIND_GAPED_TRACKS
+  std::cout << "Number of iterations:      \033[1;31m" << fNFindIterations << "\033[0m\n";
+  std::cout << "Number of iterations(new): \033[1;31m" << fParameters.CAIterationsContainer().size() << "\033[0m\n";
+  std::cout << "Tracking mode: " << fTrackingMode << '\n';
+  isec = 0;                                                            // TODO: temporary! (S.Zharko)
+  for (const auto& caIteration : fParameters.CAIterationsContainer())  // all finder
   {
     std::cout << "CA Track Finder Iteration!!" << isec << '\n';
     if (fTrackingMode == kMcbm) {
@@ -1816,51 +1823,54 @@ void L1Algo::CATrackFinder()
         // if ( (isec == kAllSecIter) || (isec == kAllSecEIter) || (isec == kAllSecJumpIter) )
         //   FIRSTCASTATION = 2;
 
-        DOUBLET_CHI2_CUT = 11.3449 * 2.f / 3.f;  // prob = 0.1
-
-        TRIPLET_CHI2_CUT = 21.1075;  // prob = 0.01%
-
-        switch (isec) {
-          case kFastPrimIter:
-            TRIPLET_CHI2_CUT = 7.815 * 3;  // prob = 0.05
-            break;
-          case kAllPrimIter:
-          case kAllPrimEIter:
-            TRIPLET_CHI2_CUT = 7.815 * 3;  // prob = 0.05
-            break;
-          case kAllPrimJumpIter:
-            TRIPLET_CHI2_CUT = 6.252 * 3;  // prob = 0.1
-            break;
-          case kAllSecIter:
-          case kAllSecEIter:
-            TRIPLET_CHI2_CUT = 6.252 * 3;  //2.706; // prob = 0.1
-            break;
-        }
-
-        Pick_gather = 3.0;  /// coefficient for size of region for attach new hits to the created track
-        if ((isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllPrimJumpIter) || (isec == kAllSecIter)
-            || (isec == kAllSecEIter) || (isec == kAllSecJumpIter))
-          Pick_gather = 4.0;
-
-        PickNeighbour = 5.0;  // (PickNeighbour < dp/dp_error)  =>  triplets are neighbours
+        DOUBLET_CHI2_CUT = caIteration.GetDoubletChi2Cut();  //11.3449 * 2.f / 3.f;  // prob = 0.1
+
+        TRIPLET_CHI2_CUT = caIteration.GetTripletChi2Cut();  //21.1075;  // prob = 0.01%
+
+        //switch (isec) {
+        //  case kFastPrimIter:
+        //    TRIPLET_CHI2_CUT = 7.815 * 3;  // prob = 0.05
+        //    break;
+        //  case kAllPrimIter:
+        //  case kAllPrimEIter:
+        //    TRIPLET_CHI2_CUT = 7.815 * 3;  // prob = 0.05
+        //    break;
+        //  case kAllPrimJumpIter:
+        //    TRIPLET_CHI2_CUT = 6.252 * 3;  // prob = 0.1
+        //    break;
+        //  case kAllSecIter:
+        //  case kAllSecEIter:
+        //    TRIPLET_CHI2_CUT = 6.252 * 3;  //2.706; // prob = 0.1
+        //    break;
+        //}
+
+        Pick_gather =
+          caIteration
+            .GetPickGather();  //3.0;  /// coefficient for size of region for attach new hits to the created track
+        //if ((isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllPrimJumpIter) || (isec == kAllSecIter)
+        //    || (isec == kAllSecEIter) || (isec == kAllSecJumpIter))
+        //  Pick_gather = 4.0;
+
+        PickNeighbour =
+          caIteration.GetPickGather();  //5.0;  // (PickNeighbour < dp/dp_error)  =>  triplets are neighbours
         // if ( (isec == kFastPrimIter) )
         //   PickNeighbour = 5.0*0.5; // TODO understand why works with 0.2
 
-        MaxInvMom = 1.0 / 0.5;  // max considered q/p
+        MaxInvMom = caIteration.GetMaxInvMom();  //1.0 / 0.5;  // max considered q/p
 
-        if (fTrackingMode == kMcbm) MaxInvMom = 1 / 0.3;  // max considered q/p
-        if ((isec == kAllPrimJumpIter) || (isec == kAllSecIter) || (isec == kAllSecJumpIter)) MaxInvMom = 1.0 / 0.1;
-        if ((isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllSecEIter)) MaxInvMom = 1. / 0.05;
+        //if (fTrackingMode == kMcbm) MaxInvMom = 1 / 0.3;  // max considered q/p
+        //if ((isec == kAllPrimJumpIter) || (isec == kAllSecIter) || (isec == kAllSecJumpIter)) MaxInvMom = 1.0 / 0.1;
+        //if ((isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllSecEIter)) MaxInvMom = 1. / 0.05;
 
-        if ((isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllSecEIter))
-          if (fTrackingMode == kMcbm) MaxInvMom = 1 / 0.1;  // max considered q/p
+        //if ((isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllSecEIter))
+        //  if (fTrackingMode == kMcbm) MaxInvMom = 1 / 0.1;  // max considered q/p
 
-        MaxSlopePV = 1.1;
-        if (  // (isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllPrimJumpIter) ||
-          (isec == kAllSecIter) || (isec == kAllSecEIter) || (isec == kAllSecJumpIter))
-          MaxSlopePV = 1.5;
+        MaxSlopePV = caIteration.GetMaxSlopePV();  //1.1;
+        //if (  // (isec == kAllPrimIter) || (isec == kAllPrimEIter) || (isec == kAllPrimJumpIter) ||
+        //  (isec == kAllSecIter) || (isec == kAllSecEIter) || (isec == kAllSecJumpIter))
+        //  MaxSlopePV = 1.5;
 
-        MaxSlope = 2.748;  // corresponds to 70 grad
+        MaxSlope = caIteration.GetMaxSlope();  //2.748;  // corresponds to 70 grad
         // define the target
         fTargX = fCbmTargetX;
         fTargY = fCbmTargetY;
@@ -2477,7 +2487,8 @@ void L1Algo::CATrackFinder()
 
 #endif  // COUNTERS
     }
-  }  // for (int isec
+    ++isec;  // TODO: temporary, to be removed! ()
+  }          // for (int isec
   // ---- Loop over Track Finder iterations: END -----------------------------------------------------------//
 
 #ifdef XXX
diff --git a/reco/L1/L1Algo/L1ObjectInitController.h b/reco/L1/L1Algo/L1ObjectInitController.h
index 1a38450890..bff4f21211 100644
--- a/reco/L1/L1Algo/L1ObjectInitController.h
+++ b/reco/L1/L1Algo/L1ObjectInitController.h
@@ -27,59 +27,72 @@ class L1ObjectInitController {
 public:
   /// Gets an initialization status of the flag placed at bitIndex
   /// \param bitIndex    index of bit
-  bool GetFlag(InitKeyEnum bitKey) const
-  {
-#ifndef FAST_CODE
-    int bitIndex = static_cast<int>(bitKey);
-    if (bitIndex >= NumberOfFlags || bitIndex < 0) {
-      LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex
-                 << " outside the range [0, " << NumberOfFlags << ']';
-      assert((!(bitIndex >= NumberOfFlags || bitIndex < 0)));
-    }
-#endif  // FAST_CODE
-    return fInitFlags[static_cast<int>(bitKey)];
-  }
-
-  /// Checks, if the object is finalized, i.e. all its fields were setup
+  bool GetFlag(InitKeyEnum bitKey) const;
+  /// Checks, if the object is finalized, i.e. all its fields were set up
   bool IsFinalized() const { return fInitFlags.size() == fInitFlags.count(); }
-
   /// Sets an initialization status of the flag placed at bitIndex
   /// \param bitIndex    index of bit
   /// \param newStatus   flag value (true is default)
-  void SetFlag(InitKeyEnum bitKey, bool newStatus = true)
-  {
-#ifndef FAST_CODE
-    int bitIndex = static_cast<int>(bitKey);
-    if (bitIndex >= NumberOfFlags || bitIndex < 0) {
-      LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex
-                 << " outside the range [0, " << NumberOfFlags << ']';
-      assert((!(bitIndex >= NumberOfFlags || bitIndex < 0)));
-    }
-#endif  // FAST_CODE
-    fInitFlags[static_cast<int>(bitKey)] = newStatus;
-  }
-
+  void SetFlag(InitKeyEnum bitKey, bool newStatus = true);
   /// String representation of initialization flags contents
   /// \param indentLevel   number of indent charachets int output
-  std::string ToString(int indentLevel = 0) const
-  {
-    std::stringstream aStream {};
-    constexpr char indentChar = '\t';
-    std::string indent(indentLevel, indentChar);
-    aStream << indent << "L1ObjectInitController: flag values";
-    aStream << '\n' << indent << "index: ";
-    for (int idx = 0; idx < NumberOfFlags; ++idx) {
-      aStream << std::setw(3) << std::setfill(' ') << idx << ' ';
-    }
-    aStream << '\n' << indent << "value: ";
-    for (int idx = 0; idx < NumberOfFlags; ++idx) {
-      aStream << "  " << static_cast<int>(fInitFlags[idx]) << ' ';
-    }
-    return aStream.str();
-  }
+  std::string ToString(int indentLevel = 0) const;
 
 private:
   std::bitset<NumberOfFlags> fInitFlags {};  ///< object of flags sets
 };
 
+//
+//------------------------------------------------------------------------------------------------------------------------
+//
+template<int NumberOfFlags, class InitKeyEnum>
+bool L1ObjectInitController<NumberOfFlags, InitKeyEnum>::GetFlag(InitKeyEnum bitKey) const
+{
+#ifndef FAST_CODE
+  int bitIndex = static_cast<int>(bitKey);
+  if (bitIndex >= NumberOfFlags || bitIndex < 0) {
+    LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex
+               << " outside the range [0, " << NumberOfFlags << ']';
+    //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0)));
+  }
+#endif  // FAST_CODE
+  return fInitFlags[static_cast<int>(bitKey)];
+}
+//
+//------------------------------------------------------------------------------------------------------------------------
+//
+template<int NumberOfFlags, class InitKeyEnum>
+void L1ObjectInitController<NumberOfFlags, InitKeyEnum>::SetFlag(InitKeyEnum bitKey, bool newStatus)
+{
+#ifndef FAST_CODE
+  int bitIndex = static_cast<int>(bitKey);
+  if (bitIndex >= NumberOfFlags || bitIndex < 0) {
+    LOG(fatal) << "L1OnjectInitController::GetFlagStatus: attempt of flag access with index = " << bitIndex
+               << " outside the range [0, " << NumberOfFlags << ']';
+    //assert((!(bitIndex >= NumberOfFlags || bitIndex < 0)));
+  }
+#endif  // FAST_CODE
+  fInitFlags[static_cast<int>(bitKey)] = newStatus;
+}
+//
+//------------------------------------------------------------------------------------------------------------------------
+//
+template<int NumberOfFlags, class InitKeyEnum>
+std::string L1ObjectInitController<NumberOfFlags, InitKeyEnum>::ToString(int indentLevel) const
+{
+  std::stringstream aStream {};
+  constexpr char indentChar = '\t';
+  std::string indent(indentLevel, indentChar);
+  aStream << indent << "L1ObjectInitController: flag values";
+  aStream << '\n' << indent << "index: ";
+  for (int idx = 0; idx < NumberOfFlags; ++idx) {
+    aStream << std::setw(3) << std::setfill(' ') << idx << ' ';
+  }
+  aStream << '\n' << indent << "value: ";
+  for (int idx = 0; idx < NumberOfFlags; ++idx) {
+    aStream << "  " << static_cast<int>(fInitFlags[idx]) << ' ';
+  }
+  return aStream.str();
+}
+
 #endif  // L1ObjectInitController_h
-- 
GitLab