From 8b54c71b32068f4f7fc12e65890bd933a8bd1fd3 Mon Sep 17 00:00:00 2001
From: Sergey Gorbunov <se.gorbunov@gsi.de>
Date: Thu, 1 Feb 2024 08:14:24 +0000
Subject: [PATCH] Ca: patch to the RC2

the MR should fix the issue https://redmine.cbm.gsi.de/issues/3149

It contains the following fixes to the CA tracking:

1. bugfix in the Jacobian of the track extrapolation.
   It was introduced during the rewrite of the math
2. tune binning of the hit grid.
   A little decrease of the efficiency happened after the code rewrite
3. tune the cuts for newly introduced hit ranges.
   The new formulae were not tuned
4. revert triplet cut on space + time chi2.
   After the split of space and time Chi2 in the track fit,
   the chi2 cut was changed w/o tuning. Replace it with the old cut.
---
 algo/ca/core/tracking/CaTrackFinderWindow.cxx  |  5 +++--
 algo/ca/core/tracking/CaTrackFit.cxx           | 14 +++++++++++++-
 algo/ca/core/tracking/CaTripletConstructor.cxx | 10 ++++++----
 3 files changed, 22 insertions(+), 7 deletions(-)

diff --git a/algo/ca/core/tracking/CaTrackFinderWindow.cxx b/algo/ca/core/tracking/CaTrackFinderWindow.cxx
index 0a26c0d3a3..97aff8d808 100644
--- a/algo/ca/core/tracking/CaTrackFinderWindow.cxx
+++ b/algo/ca/core/tracking/CaTrackFinderWindow.cxx
@@ -221,8 +221,9 @@ void TrackFinderWindow::CaTrackFinderSlice()
     fscal sizeY    = gridMaxY - gridMinY;
     fscal sizeX    = gridMaxX - gridMinX;
     int nBins2D    = 1 + nSliceHits;
-    fscal yStep    = sizeY / sqrt(nBins2D);
-    fscal xStep    = sizeX / sqrt(nBins2D);
+    // TODO: SG: the coefficients should be removed
+    fscal yStep = 0.3 * sizeY / sqrt(nBins2D);
+    fscal xStep = 0.8 * sizeX / sqrt(nBins2D);
 
     fscal scale = frAlgo.GetParameters().GetStation(iS).GetZ<float>() - frAlgo.GetParameters().GetTargetPositionZ()[0];
 
diff --git a/algo/ca/core/tracking/CaTrackFit.cxx b/algo/ca/core/tracking/CaTrackFit.cxx
index b39fa3b703..d0b8b74b5a 100644
--- a/algo/ca/core/tracking/CaTrackFit.cxx
+++ b/algo/ca/core/tracking/CaTrackFit.cxx
@@ -746,11 +746,23 @@ namespace cbm::algo::ca
 
     cnst stepW[5] = {0., h / fvec(6.), h / fvec(3.), h / fvec(3.), h / fvec(6.)};
 
+    fvec k[5][7][7] = {{0.}};
+    for (int step = 1; step <= 4; ++step) {
+      for (int i = 0; i < 7; i++) {
+        for (int j = 0; j < 7; j++) {
+          k[step][i][j] = F[step][i][j];
+          for (int m = 0; m < 7; m++) {
+            k[step][i][j] += stepDz[step] * F[step][i][m] * k[step - 1][m][j];
+          }
+        }
+      }
+    }
+
     for (int i = 0; i < 7; i++) {
       for (int j = 0; j < 7; j++) {
         R[i][j] = R0[i][j];
         for (int step = 1; step <= 4; step++) {
-          R[i][j] += stepW[step] * F[step][i][j];
+          R[i][j] += stepW[step] * k[step][i][j];
         }
       }
     }
diff --git a/algo/ca/core/tracking/CaTripletConstructor.cxx b/algo/ca/core/tracking/CaTripletConstructor.cxx
index e88613a7a5..529a9c4480 100644
--- a/algo/ca/core/tracking/CaTripletConstructor.cxx
+++ b/algo/ca/core/tracking/CaTripletConstructor.cxx
@@ -261,18 +261,18 @@ void TripletConstructor::FitDoublets()
 
         if ((staM().timeInfo) && (T2.NdfTime()[0] >= 0)) {
           fscal dt = T2.Time()[0] + tt * dz - hitClone.T();
-          if (fabs(dt) > sqrt(30. * T2.C55()[0]) + hitClone.RangeT()) {
+          if (!(fabs(dt) <= 3.5 * sqrt(T2.C55()[0]) + hitClone.RangeT())) {
             continue;
           }
         }
 
         fscal dx = T2.GetX()[0] + tx * dz - hitClone.X();
-        if (fabs(dx) > 1.3 * (3.5 * sqrt(T2.C00()[0]) + hitClone.RangeX())) {
+        if (!(fabs(dx) <= 3.5 * sqrt(T2.C00()[0]) + hitClone.RangeX())) {
           continue;
         }
 
         fscal dy = T2.Y()[0] + ty * dz - hitClone.Y();
-        if (fabs(dy) > 1.6 * (3.5 * sqrt(T2.C11()[0]) + hitClone.RangeY())) {
+        if (!(fabs(dy) <= 3.5 * sqrt(T2.C11()[0]) + hitClone.RangeY())) {
           continue;
         }
 
@@ -644,7 +644,9 @@ void TripletConstructor::StoreTriplets()
 
     TrackParamV& T3 = fTracks_3[i3];
 
-    fscal chi2 = T3.GetChiSq()[0];  // / T3.NDF[0];
+    // TODO: SG: normalize chi2, separate cuts on time and space
+
+    fscal chi2 = T3.GetChiSq()[0] + T3.GetChiSqTime()[0];
 
     const ca::HitIndex_t ihitl = fIhitL;
     const ca::HitIndex_t ihitm = fHitsM_3[i3];
-- 
GitLab