From 28ba28cc19c5201da591187383a071d5914463ad Mon Sep 17 00:00:00 2001
From: "se.gorbunov" <se.gorbunov@gsi.de>
Date: Tue, 28 Feb 2023 23:14:13 +0000
Subject: [PATCH] L1: cleanup Mvd hit indexing

---
 reco/L1/CbmL1.cxx                             | 80 ++---------------
 reco/L1/CbmL1.h                               |  9 +-
 reco/L1/CbmL1ReadEvent.cxx                    | 86 ++++++-------------
 .../CbmL1GlobalTrackFinder.cxx                | 12 +--
 .../OffLineInterface/CbmL1GlobalTrackFinder.h |  2 +-
 .../OffLineInterface/CbmL1StsTrackFinder.cxx  | 16 +---
 6 files changed, 46 insertions(+), 159 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index 1d85bdef90..0f956a441c 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -884,35 +884,6 @@ void CbmL1::Reconstruct(CbmEvent* event)
   static int nevent = 0;
   fvSelectedMcEvents.clear();
 
-  // TODO: Refactor this part, check usage ---------------------------------
-  int nStsHits = (fUseSTS && fpStsHits ? fpStsHits->GetEntriesFast() : 0);
-
-  if (!event) {
-    /// sort input hits by time
-    L1Vector<std::pair<double, int>> SortHits("CbmL1::SortHits");
-    SortHits.reserve(nStsHits);
-    for (Int_t j = 0; j < nStsHits; j++) {
-      CbmStsHit* sh = L1_DYNAMIC_CAST<CbmStsHit*>(fpStsHits->At(j));
-      double t      = sh->GetTime();
-      SortHits.push_back(std::pair<double, int>(t, j));
-    }
-    std::sort(SortHits.begin(), SortHits.end());
-    fvSortedStsHitsIndexes.clear();
-    fvSortedStsHitsIndexes.reserve(SortHits.size());
-    for (unsigned int i = 0; i < SortHits.size(); i++) {
-      int j = SortHits[i].second;
-      fvSortedStsHitsIndexes.push_back(j);
-    };
-  }
-  else {
-    fvSortedStsHitsIndexes.clear();
-    fvSortedStsHitsIndexes.reserve(nStsHits);
-    for (int i = 0; i < nStsHits; i++) {
-      fvSortedStsHitsIndexes.push_back(i);
-    }
-  }
-  // -----------------------------------------------------------------------
-
   if (fPerformance) {
     int nofEvents = fpMcEventList->GetNofEvents();
     for (int iE = 0; iE < nofEvents; iE++) {
@@ -926,25 +897,6 @@ void CbmL1::Reconstruct(CbmEvent* event)
 #ifdef _OPENMP
   omp_set_num_threads(1);
 #endif
-  // repack data
-
-  L1Vector<CbmL1Track> vRTracksCur("CbmL1::vRTracksCur");
-  // FIXME: Update the following code block in order to account for MuCh, TRD and TOF (S.Zharko)
-  {
-    int nHits = 0;
-    int nSta  = 1;
-    if (fUseMVD && fpMvdHits) {
-      nHits += fpMvdHits->GetEntriesFast();
-      nSta += fNMvdStations;
-    }
-    if (fUseSTS && fpStsHits) {
-      nHits += fpStsHits->GetEntriesFast();
-      nSta += fNStsStations;
-    }
-    vRTracksCur.reserve(10 + (2 * nHits) / nSta);
-  }
-
-  fTrackingTime = 0;
 
   // ----- Read data from branches and send data from IODataManager to L1Algo ----------------------------------------
   ReadEvent(event);
@@ -966,11 +918,15 @@ void CbmL1::Reconstruct(CbmEvent* event)
   if (fVerbose > 1) { cout << "L1 Track finder..." << endl; }
   fpAlgo->CaTrackFinder();
   //       IdealTrackFinder();
-  fTrackingTime += fpAlgo->fCaRecoTime;
+  fTrackingTime = fpAlgo->fCaRecoTime;
 
   if (fVerbose > 1) { cout << "L1 Track finder ok" << endl; }
 
   // save reconstructed tracks
+
+  fvRecoTracks.clear();
+  fvRecoTracks.reserve(fpAlgo->fRecoTracks.size());
+
   int trackFirstHit = 0;
 
   for (L1Vector<L1Track>::iterator it = fpAlgo->fRecoTracks.begin(); it != fpAlgo->fRecoTracks.end();
@@ -995,40 +951,18 @@ void CbmL1::Reconstruct(CbmEvent* event)
     t.Hits.clear();
     t.mass        = fpAlgo->fDefaultMass;  // pion mass
     t.is_electron = 0;
-    t.SetId(vRTracksCur.size());
+    t.SetId(fvRecoTracks.size());
 
     for (int i = 0; i < it->NHits; i++) {
       int caHitId  = fpAlgo->fRecoHits[trackFirstHit + i];
       int cbmHitID = fpAlgo->GetInputData().GetHit(caHitId).ID;
       t.Hits.push_back(cbmHitID);
     }
-    vRTracksCur.push_back(t);
+    fvRecoTracks.push_back(t);
   }
 
   LOG(debug) << "CA Track Finder: " << fpAlgo->fCaRecoTime << " s/sub-ts" << endl;
 
-  //
-  //   if (fSTAPDataMode % 2 == 1) {  // 1,3
-  //     WriteSTAPAlgoData();
-  //     WriteSTAPPerfData();
-  //   };
-  //   if (fSTAPDataMode >= 2) {  // 2,3
-  //     //ReadSTAPAlgoData();
-  //
-  //     ReadSTAPPerfData();
-  //   };
-
-  fvRecoTracks.clear();
-  fvRecoTracks.reserve(vRTracksCur.size());
-  for (unsigned int iTrack = 0; iTrack < vRTracksCur.size(); iTrack++) {
-
-    for (unsigned int iHit = 0; iHit < vRTracksCur[iTrack].Hits.size(); iHit++) {
-      vRTracksCur[iTrack].Hits[iHit] = fvSortedHitsIndexes[vRTracksCur[iTrack].Hits[iHit]];
-    }
-
-    fvRecoTracks.push_back(vRTracksCur[iTrack]);
-  }
-
 
   if ((fPerformance) && (fSTAPDataMode < 2)) { InputPerformance(); }
 
diff --git a/reco/L1/CbmL1.h b/reco/L1/CbmL1.h
index c82075d770..35c65a33b2 100644
--- a/reco/L1/CbmL1.h
+++ b/reco/L1/CbmL1.h
@@ -351,10 +351,10 @@ private:
   /// \param   iPoint   Index of the point into the input MC points CbmMCDataArray object for the particular detector
   /// \param   file     Index of the input file
   /// \param   event    Index of the input event
-  /// \param   MVD      Index of the detector subsystem
+  /// \param   iDet     Index of the detector subsystem
   /// \return  flag: false - success, true - some errors occurred
   // TODO: Probably, we should replace input parameter MVD with the template  (S.Zharko)
-  bool ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int MVD);
+  bool ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int iDet);
 
   //   static bool compareZ(const int &a, const int &b );
   //   bool compareZ(const int &a, const int &b );
@@ -605,11 +605,6 @@ private:
 
   vector<vector<int>> fTofPointToTrack;  ///<
 
-  /// Indexes of hits after hits sorting (used only with fLegacyEventMode = true)
-  L1Vector<int> fvSortedHitsIndexes = {"CbmL1::fvSortedHitsIndexes"};
-  /// Indexes of STS hits in fpStsHits array after hits sorting (used only with fLegacyEventMode = true)
-  L1Vector<int> fvSortedStsHitsIndexes = {"CbmL1::fvSortedStsHitsIndexes"};
-
   L1Vector<CbmL1MCTrack> fvMCTracks = {"CbmL1::fvMCTracks"};         ///< Array of MC tracks
   L1Vector<int> fvHitPointIndexes   = {"CbmL1::fvHitPointIndexes"};  ///< Indexes of MC points vs. hit index
 
diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index 95c4f62365..7c8762b088 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -90,7 +90,6 @@ struct TmpHit {
   double time = 0.;    ///< time of the hit [ns]
   double dt   = 1.e4;  ///< time error of the hit [ns]
   int Det;
-  int id;  ///< index of hit before hits sorting
   int track;
 
   /// Provides comparison of two hits.
@@ -108,17 +107,15 @@ struct TmpHit {
   /// Creates a hit from the CbmL1MCPoint object
   /// \param point  constant reference to the input MC-point
   /// \param det
-  /// \param nTmpHits
   /// \param nStripF
   /// \param ip
   /// \param NStrips
   /// \param st       reference to the station info object
-  void CreateHitFromPoint(const CbmL1MCPoint& point, int ip, int det, int nTmpHits, int& NStrips, const L1Station& st,
-                          double du_, double dv_, double dt_, bool doSmear)
+  void CreateHitFromPoint(const CbmL1MCPoint& point, int ip, int det, int& NStrips, const L1Station& st, double du_,
+                          double dv_, double dt_, bool doSmear)
   {
     ExtIndex = 0;
     Det      = det;
-    id       = nTmpHits;
     iStation = point.iStation;
 
     dt   = dt_;
@@ -178,7 +175,7 @@ int CbmL1::MatchHitWithMc<L1DetectorID::kMvd>(int iHit) const
 {
   int iPoint = -1;
   if (fpMvdHitMatches) {
-    int iHitExt          = -(1 + iHit);  // TODO: SZh 28.08.2022: this should be replaced with iHitExt = hit.extIdex
+    int iHitExt          = iHit;
     const auto* hitMatch = dynamic_cast<CbmMatch*>(fpMvdHitMatches->At(iHitExt));
     assert(hitMatch);
     if (hitMatch->GetNofLinks() > 0 && hitMatch->GetLink(0).GetIndex() < fNpointsMvd) {
@@ -423,7 +420,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
         double maxDeviation      = 0;
         for (Int_t iMC = 0; iMC < fNpointsMvdInEvent; iMC++) {
           CbmL1MCPoint MC;
-          if (!ReadMCPoint(&MC, iMC, iFile, iEvent, 1)) {
+          if (!ReadMCPoint(&MC, iMC, iFile, iEvent, 0)) {
             MC.iStation          = -1;
             const L1Station* sta = fpAlgo->GetParameters()->GetStations().begin();
             double bestDist      = 1.e20;
@@ -464,7 +461,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
         double maxDeviation = 0;
         for (Int_t iMC = 0; iMC < nMC; iMC++) {
           CbmL1MCPoint MC;
-          if (!ReadMCPoint(&MC, iMC, iFile, iEvent, 0)) {
+          if (!ReadMCPoint(&MC, iMC, iFile, iEvent, 1)) {
             MC.iStation          = -1;
             const L1Station* sta = fpAlgo->GetParameters()->GetStations().begin();
             double bestDist      = 1.e20;
@@ -683,8 +680,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
       TmpHit th;
       {
         CbmMvdHit* h = L1_DYNAMIC_CAST<CbmMvdHit*>(fpMvdHits->At(j));
-        th.ExtIndex  = -(1 + j);
-        th.id        = tmpHits.size();
+        th.ExtIndex  = j;
         th.iStation  = h->GetStationNr();
 
         int stIdx = fpAlgo->GetParameters()->GetStationIndexActive(h->GetStationNr(), L1DetectorID::kMvd);
@@ -734,8 +730,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
       int DetId = 0;
       double du = 5.e-4;
       double dt = 1000.;
-      th.CreateHitFromPoint(p, ip, DetId, tmpHits.size(), NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du,
-                            du, dt, true);
+      th.CreateHitFromPoint(p, ip, DetId, NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du, du, dt, true);
       tmpHits.push_back(th);
       nMvdHits++;
     }
@@ -751,10 +746,8 @@ void CbmL1::ReadEvent(CbmEvent* event)
     int firstDetStrip = NStrips;
 
     for (Int_t j = 0; j < nEntSts; j++) {
-      Int_t hitIndex = 0;
-      hitIndex       = (event ? event->GetIndex(ECbmDataType::kStsHit, j) : j);
 
-      int hitIndexSort = fvSortedStsHitsIndexes[hitIndex];
+      Int_t hitIndex = (event ? event->GetIndex(ECbmDataType::kStsHit, j) : j);
 
       // ***********************************
       // ** Fill the temporary hit object **
@@ -764,8 +757,8 @@ void CbmL1::ReadEvent(CbmEvent* event)
 
       // Fill reconstructed information
       {
-        CbmStsHit* h = L1_DYNAMIC_CAST<CbmStsHit*>(fpStsHits->At(hitIndexSort));
-        th.ExtIndex  = hitIndexSort;
+        CbmStsHit* h = L1_DYNAMIC_CAST<CbmStsHit*>(fpStsHits->At(hitIndex));
+        th.ExtIndex  = hitIndex;
         th.Det       = 1;
         int stIdx    = fpAlgo->GetParameters()->GetStationIndexActive(
           CbmStsSetup::Instance()->GetStationNumber(h->GetAddress()), L1DetectorID::kSts);
@@ -784,8 +777,6 @@ void CbmL1::ReadEvent(CbmEvent* event)
         th.time = h->GetTime();
         th.dt   = h->GetTimeError();
 
-        th.id = nMvdHits + hitIndex;
-
         TVector3 pos, err;
         h->Position(pos);
         h->PositionError(err);
@@ -805,7 +796,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
         th.u                = th.x * st.frontInfo.cos_phi[0] + th.y * st.frontInfo.sin_phi[0];
         th.v                = th.x * st.backInfo.cos_phi[0] + th.y * st.backInfo.sin_phi[0];
       }
-      th.iMC = fPerformance ? MatchHitWithMc<L1DetectorID::kSts>(hitIndexSort) : -1;
+      th.iMC = fPerformance ? MatchHitWithMc<L1DetectorID::kSts>(hitIndex) : -1;
 
       if (1 == fStsUseMcHit && th.iMC >= 0) {
         th.SetHitFromPoint(fvMCPoints[th.iMC], th.iMC, fpAlgo->GetParameters()->GetStation(th.iStation));
@@ -832,8 +823,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
       int DetId = 1;
       double du = 10.e-4;
       double dt = 5.;
-      th.CreateHitFromPoint(p, ip, DetId, tmpHits.size(), NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du,
-                            du, dt, true);
+      th.CreateHitFromPoint(p, ip, DetId, NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du, du, dt, true);
       tmpHits.push_back(th);
       nStsHits++;
     }
@@ -853,16 +843,12 @@ void CbmL1::ReadEvent(CbmEvent* event)
     for (int j = 0; j < nEnt; j++) {
       TmpHit th;
       {
-
-
-        Int_t hitIndex = 0;
-        hitIndex       = (event ? event->GetIndex(ECbmDataType::kMuchPixelHit, j) : j);
+        Int_t hitIndex = (event ? event->GetIndex(ECbmDataType::kMuchPixelHit, j) : j);
 
         CbmMuchPixelHit* h = static_cast<CbmMuchPixelHit*>(fpMuchPixelHits->At(hitIndex));
 
         th.ExtIndex = hitIndex;
         th.Det      = 2;
-        th.id       = tmpHits.size();
 
         Int_t stationNumber = CbmMuchGeoScheme::GetStationIndex(h->GetAddress());
         Int_t layerNumber   = CbmMuchGeoScheme::GetLayerIndex(h->GetAddress());
@@ -948,8 +934,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
       int DetId = 2;
       double du = 100.e-4;
       double dt = 3.9;
-      th.CreateHitFromPoint(p, ip, DetId, tmpHits.size(), NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du,
-                            du, dt, true);
+      th.CreateHitFromPoint(p, ip, DetId, NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du, du, dt, true);
 
       tmpHits.push_back(th);
       nMuchHits++;
@@ -972,8 +957,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
     for (int iHit = 0; iHit < nEntTrd; iHit++) {
       TmpHit th;
 
-      Int_t hitIndex = 0;
-      hitIndex       = (event ? event->GetIndex(ECbmDataType::kTrdHit, iHit) : iHit);
+      Int_t hitIndex = (event ? event->GetIndex(ECbmDataType::kTrdHit, iHit) : iHit);
 
       CbmTrdHit* h = L1_DYNAMIC_CAST<CbmTrdHit*>(fpTrdHits->At(hitIndex));
 
@@ -984,8 +968,6 @@ void CbmL1::ReadEvent(CbmEvent* event)
 
       th.ExtIndex = hitIndex;
       th.Det      = 3;
-      th.id       = tmpHits.size();
-
 
       int stIdx = fpAlgo->GetParameters()->GetStationIndexActive(h->GetPlaneId(), L1DetectorID::kTrd);
       assert(stIdx != -1);
@@ -1082,8 +1064,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
       int DetId = 3;
       double du = 0.1;
       double dt = 10.;
-      th.CreateHitFromPoint(p, ip, DetId, tmpHits.size(), NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du,
-                            du, dt, true);
+      th.CreateHitFromPoint(p, ip, DetId, NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du, du, dt, true);
       tmpHits.push_back(th);
       nTrdHits++;
     }
@@ -1100,9 +1081,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
 
     for (int j = 0; j < nEntTof; j++) {
 
-
-      Int_t hitIndex = 0;
-      hitIndex       = (event ? event->GetIndex(ECbmDataType::kTofHit, j) : j);
+      Int_t hitIndex = (event ? event->GetIndex(ECbmDataType::kTofHit, j) : j);
 
       TmpHit th;
 
@@ -1112,8 +1091,6 @@ void CbmL1::ReadEvent(CbmEvent* event)
       th.ExtIndex = hitIndex;
       th.Det      = 4;
 
-      th.id = tmpHits.size();
-
       if (0x00202806 == h->GetAddress() || 0x00002806 == h->GetAddress()) continue;  // TODO: Why? (S.Zharko)
 
       if (5 == CbmTofAddress::GetSmType(h->GetAddress())) continue;
@@ -1182,8 +1159,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
       int DetId = 4;
       double du = 0.1;
       double dt = 0.075;
-      th.CreateHitFromPoint(p, ip, DetId, tmpHits.size(), NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du,
-                            du, dt, true);
+      th.CreateHitFromPoint(p, ip, DetId, NStrips, fpAlgo->GetParameters()->GetStation(p.iStation), du, du, dt, true);
       tmpHits.push_back(th);
       nTofHits++;
     }
@@ -1211,19 +1187,10 @@ void CbmL1::ReadEvent(CbmEvent* event)
   //
   sort(tmpHits.begin(), tmpHits.end(), TmpHit::Compare);
 
-  // ----- Save strips into L1Algo
-  int maxHitIndex = 0;
-
-  for (int ih = 0; ih < nHits; ih++) {
-    TmpHit& th = tmpHits[ih];
-    if (maxHitIndex < th.id) { maxHitIndex = th.id; }
-  }  // ih
-
   if (fVerbose >= 10) { cout << "ReadEvent: strips are read." << endl; }
 
 
   // ----- Fill and save fvExternalHits, fvHitDebugInfo and fvHitPointIndexes vectors as well as fpData->vHits
-  fvSortedHitsIndexes.reset(maxHitIndex + 1);
 
   fvExternalHits.reserve(nHits);
   fvHitDebugInfo.reserve(nHits);
@@ -1249,8 +1216,6 @@ void CbmL1::ReadEvent(CbmEvent* event)
     s.dxy      = th.dxy;
     s.time     = th.time;
 
-    fvSortedHitsIndexes[th.id] = iHit;
-
     assert(th.iStripF >= 0 || th.iStripF < NStrips);
     assert(th.iStripB >= 0 || th.iStripB < NStrips);
 
@@ -1258,7 +1223,7 @@ void CbmL1::ReadEvent(CbmEvent* event)
     h.iSt = th.iStation;
     h.f   = th.iStripF;
     h.b   = th.iStripB;
-    h.ID  = th.id;
+    h.ID  = iHit;
     h.z   = th.z;
     h.u   = th.u;
     h.v   = th.v;
@@ -1367,7 +1332,7 @@ void CbmL1::Fill_vMCTracks()
 //--------------------------------------------------------------------------------------------------
 //
 // TODO: Probably, we should reduce code here, rewriting this funciton as a template from CbmMvdPoint (S.Zharko)
-bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int MVD)
+bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int iDet)
 {
   TVector3 xyzI, PI, xyzO, PO;
   Int_t mcID    = -1;
@@ -1375,7 +1340,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
 
   double eventTime = fpMcEventList->GetEventTime(event, file);
 
-  if (MVD == 1) {
+  if (iDet == 0) {
     CbmMvdPoint* pt = L1_DYNAMIC_CAST<CbmMvdPoint*>(fpMvdPoints->Get(file, event, iPoint));  // file, event, object
     //CbmMvdPoint *pt = L1_DYNAMIC_CAST<CbmMvdPoint*> (Point);
 
@@ -1387,7 +1352,8 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
     mcID = pt->GetTrackID();
     time = eventTime + pt->GetTime();
   }
-  if (MVD == 0) {
+
+  if (iDet == 1) {
     CbmStsPoint* pt = L1_DYNAMIC_CAST<CbmStsPoint*>(fpStsPoints->Get(file, event, iPoint));  // file, event, object
     if (!pt) return 1;
     {
@@ -1411,7 +1377,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
   }
 
 
-  if (MVD == 2) {
+  if (iDet == 2) {
     CbmMuchPoint* pt = L1_DYNAMIC_CAST<CbmMuchPoint*>(fpMuchPoints->Get(file, event, iPoint));  // file, event, object
     if (!pt) return 1;
     {
@@ -1435,7 +1401,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
   }
 
 
-  if (MVD == 3) {
+  if (iDet == 3) {
     CbmTrdPoint* pt = L1_DYNAMIC_CAST<CbmTrdPoint*>(fpTrdPoints->Get(file, event, iPoint));  // file, event, object
 
     if (!pt) return 1;
@@ -1460,7 +1426,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
     time = eventTime + pt->GetTime();
   }
 
-  if (MVD == 4) {
+  if (iDet == 4) {
     CbmTofPoint* pt = L1_DYNAMIC_CAST<CbmTofPoint*>(fpTofPoints->Get(file, event, iPoint));  // file, event, object
     if (!pt) return 1;
     {
diff --git a/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.cxx b/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.cxx
index ceef89a204..27f0629d7e 100644
--- a/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.cxx
+++ b/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.cxx
@@ -111,12 +111,12 @@ Int_t CbmL1GlobalTrackFinder::CopyL1Tracks(CbmEvent* event)
     for (vector<int>::iterator ih = it->Hits.begin(); ih != it->Hits.end(); ++ih) {
       const CbmL1HitId& h = L1->fvExternalHits[*ih];
 
-      if (h.detId == 1 && hasStsHits == false) {
+      if (h.detId <= 1 && hasStsHits == false) {
         hasStsHits         = true;
         CbmStsTrack* track = new ((*fStsTracks)[stsTrackIndex]) CbmStsTrack();
         t->SetStsTrackIndex(stsTrackIndex);
         if (event) event->AddData(ECbmDataType::kStsTrack, stsTrackIndex);
-        CbmL1TrackToCbmStsTrack(T, track, h.detId);
+        CbmL1TrackToCbmStsTrack(T, track);
         stsTrackIndex++;
       }
       if (h.detId == 2 && hasMuchHits == false) {
@@ -183,7 +183,7 @@ void CbmL1GlobalTrackFinder::CbmL1TrackToCbmTrack(CbmL1Track l1track, CbmTrack*
 // -------------------------------------------------------------------------
 
 // -----   Public method CbmL1TrackToCbmStsTrack   ------------------------------------------
-void CbmL1GlobalTrackFinder::CbmL1TrackToCbmStsTrack(CbmL1Track l1track, CbmStsTrack* track, int systemIdT)
+void CbmL1GlobalTrackFinder::CbmL1TrackToCbmStsTrack(CbmL1Track l1track, CbmStsTrack* track)
 {
   Int_t ndf = 0;
 
@@ -193,8 +193,10 @@ void CbmL1GlobalTrackFinder::CbmL1TrackToCbmStsTrack(CbmL1Track l1track, CbmStsT
 
   for (vector<int>::iterator ih = T->Hits.begin(); ih != T->Hits.end(); ++ih) {
     CbmL1HitId& h = L1->fvExternalHits[*ih];
-    if (h.detId != systemIdT) continue;
-    track->AddHit(h.hitId, kSTSHIT);
+    if (h.detId == 0) { track->AddMvdHit(h.hitId); }
+    else if (h.detId == 1) {
+      track->AddHit(h.hitId, kSTSHIT);
+    }
   }
 
   ndf -= 5;
diff --git a/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.h b/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.h
index 02e7a5f02a..a5a899094d 100644
--- a/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.h
+++ b/reco/L1/OffLineInterface/CbmL1GlobalTrackFinder.h
@@ -88,7 +88,7 @@ private:
   /** Convert detector specific track info to a detector track
    **/
   void CbmL1TrackToCbmTrack(CbmL1Track T, CbmTrack* track, int systemIdT);
-  void CbmL1TrackToCbmStsTrack(CbmL1Track T, CbmStsTrack* track, int systemIdT);
+  void CbmL1TrackToCbmStsTrack(CbmL1Track T, CbmStsTrack* track);
   void CbmL1TrackToCbmMuchTrack(CbmL1Track T, CbmMuchTrack* track, int systemIdT);
   void CbmL1TrackToCbmTrdTrack(CbmL1Track T, CbmTrdTrack* track, int systemIdT);
   void CbmL1TrackToCbmTofTrack(CbmL1Track T, CbmTofTrack* track, int systemIdT);
diff --git a/reco/L1/OffLineInterface/CbmL1StsTrackFinder.cxx b/reco/L1/OffLineInterface/CbmL1StsTrackFinder.cxx
index dfd28eec7d..d61263b4a1 100644
--- a/reco/L1/OffLineInterface/CbmL1StsTrackFinder.cxx
+++ b/reco/L1/OffLineInterface/CbmL1StsTrackFinder.cxx
@@ -93,19 +93,9 @@ Int_t CbmL1StsTrackFinder::CopyL1Tracks(CbmEvent* event)
 
     for (vector<int>::iterator ih = it->Hits.begin(); ih != it->Hits.end(); ++ih) {
       CbmL1HitId& h = L1->fvExternalHits[*ih];
-      // 	  double zref = L1->fpAlgo->vStations[h.iStation].z[0];
-      if (h.detId > 1) {  // not MVD or STS hit
-        continue;
-      }
-      if (h.hitId < 0) {
-        // CbmMvdHit tmp;
-        // tmp.SetZ(zref);
-        t->AddMvdHit(-h.hitId - 1);  //, &tmp );
-      }
-      else {
-        //CbmStsHit tmp;
-        //tmp.SetZ(zref);
-        t->AddHit(h.hitId, kSTSHIT);  //, &tmp );
+      if (h.detId == 0) { t->AddMvdHit(h.hitId); }
+      else if (h.detId == 1) {
+        t->AddHit(h.hitId, kSTSHIT);
       }
     }
   }
-- 
GitLab