From 8db9f68dca007c52f0116979fb252596cff5ef8c Mon Sep 17 00:00:00 2001
From: "se.gorbunov" <se.gorbunov@gsi.de>
Date: Tue, 10 Jan 2023 13:02:05 +0000
Subject: [PATCH] L1: bugfix in removing suspicious triplets

---
 reco/L1/L1Algo/L1BranchExtender.cxx |  3 +++
 reco/L1/L1Algo/L1CATrackFinder.cxx  | 11 ++++++++---
 reco/L1/L1Algo/L1HitPoint.h         | 10 ++++++++++
 3 files changed, 21 insertions(+), 3 deletions(-)

diff --git a/reco/L1/L1Algo/L1BranchExtender.cxx b/reco/L1/L1Algo/L1BranchExtender.cxx
index acf082fcd4..07e8185119 100644
--- a/reco/L1/L1Algo/L1BranchExtender.cxx
+++ b/reco/L1/L1Algo/L1BranchExtender.cxx
@@ -255,6 +255,9 @@ void L1Algo::FindMoreHits(L1Branch& t, L1TrackPar& T, const bool dir,
 
       L1HitIndex_t globalInd = HitsUnusedStartIndex[ista] + ih;
 
+      const L1HitPoint& hitPoint = (*vHitPointsUnused)[globalInd];
+      if (hitPoint.IsSuppressed()) { continue; }
+
       const L1Hit& hit = (*vHitsUnused)[globalInd];
 
       if (fabs(hit.t - T.t[0]) > sqrt(T.C55[0] + hit.dt2) * 5) continue;
diff --git a/reco/L1/L1Algo/L1CATrackFinder.cxx b/reco/L1/L1Algo/L1CATrackFinder.cxx
index dfe5662112..b8d85f96bd 100644
--- a/reco/L1/L1Algo/L1CATrackFinder.cxx
+++ b/reco/L1/L1Algo/L1CATrackFinder.cxx
@@ -319,12 +319,15 @@ inline void L1Algo::findDoubletsStep0(
 #endif  // DOUB_PERFORMANCE
   L1Vector<L1HitIndex_t>& hitsm_2)
 {
-  /// Find the doublets. Reformat data in the portion of doublets.
+  /// Find the doublets. Reformat data into portions of doublets.
+
+  assert(i1_2.size() == 0);
 
   int iStaL = &stal - fParameters.GetStations().begin();
   int iStaM = &stam - fParameters.GetStations().begin();
 
-  n2 = 0;                             // number of doublet
+  n2 = 0;  // number of doublets
+
   for (Tindex i1 = 0; i1 < n1; ++i1)  // for each singlet
   {
     unsigned int Ndoublets = 0;
@@ -694,7 +697,9 @@ inline void L1Algo::findTripletsStep0(  // input
           n3   = n3 - doubletNtriplets;
           n3_V = n3 / fvec::size();
           n3_4 = n3 % fvec::size();
-          //assert(0);
+          hitsl_3.reduce(n3);
+          hitsm_3.reduce(n3);
+          hitsr_3.reduce(n3);
           break;
         }
 
diff --git a/reco/L1/L1Algo/L1HitPoint.h b/reco/L1/L1Algo/L1HitPoint.h
index 5fd6b8111f..a7a367c7e6 100644
--- a/reco/L1/L1Algo/L1HitPoint.h
+++ b/reco/L1/L1Algo/L1HitPoint.h
@@ -29,6 +29,8 @@ struct L1HitPoint {
   fscal dV2() const { return dv2; }
   fscal dT2() const { return dt2; }
 
+  bool IsSuppressed() const { return fIsSuppressed; }
+
   void SetZ(fscal z_) { z = z_; }
   void SetU(fscal u_) { u = u_; }
   void SetV(fscal v_) { v = v_; }
@@ -44,10 +46,18 @@ struct L1HitPoint {
     du2 = du2_;
     dv2 = dv2_;
     dt2 = dt2_;
+
+    fIsSuppressed = 0;
   }
 
+  void SetIsSuppresed(bool val) { fIsSuppressed = val; }
+
 private:
   fscal z {0.}, u {0.}, v {0.}, t {0.}, du2 {0.}, dv2 {0.}, dt2 {0.};
+
+  // fIsSuppressed flag is used to suppress duplicated hits at the module overlaps
+  // TODO: collect those hits on the track instead of suppressing them
+  bool fIsSuppressed {0};  // is the hit suppressed by another hit
 };
 
 
-- 
GitLab