From 159f6e36f5edbc6335542583da4f8216e80be7ba Mon Sep 17 00:00:00 2001
From: sgorbuno <se.gorbunov@gsi.de>
Date: Thu, 21 Jan 2021 12:58:26 +0000
Subject: [PATCH] remove artefacts at the L1 input

---
 reco/L1/CbmL1.cxx                  | 148 +++++++++++--------------
 reco/L1/CbmL1ReadEvent.cxx         | 168 ++++++++---------------------
 reco/L1/L1Algo/L1Algo.cxx          |   8 +-
 reco/L1/L1Algo/L1Algo.h            |  28 ++---
 reco/L1/L1Algo/L1CATrackFinder.cxx |  17 ++-
 reco/L1/L1Algo/L1Grid.cxx          |   7 +-
 reco/L1/L1Algo/L1Grid.h            |   3 +-
 reco/L1/L1Algo/L1TrackExtender.cxx |   2 +-
 reco/L1/L1AlgoInputData.cxx        |  38 +++----
 reco/L1/L1AlgoInputData.h          |  19 ++--
 10 files changed, 146 insertions(+), 292 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index ba01d106ef..c953718bca 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -1324,8 +1324,9 @@ void CbmL1::Reconstruct(CbmEvent* event) {
   }
 
 
-  if (fVerbose > 1)
+  if (fVerbose > 1) {
     cout << endl << "CbmL1::Exec event " << ++nevent << " ..." << endl << endl;
+  }
 #ifdef _OPENMP
   omp_set_num_threads(1);
 #endif
@@ -1337,11 +1338,9 @@ void CbmL1::Reconstruct(CbmEvent* event) {
     fData->ReadHitsFromFile(fSTAPDataDir.Data(), 1, fVerbose);
 
     algo->SetData(fData->GetStsHits(),
-                  fData->GetNStsStripsF(),
-                  fData->GetNStsStripsB(),
+                  fData->GetNStsStrips(),
                   fData->GetStsZPos(),
                   fData->GetSFlag(),
-                  fData->GetSFlagB(),
                   fData->GetStsHitsStartIndex(),
                   fData->GetStsHitsStopIndex());
   } else
@@ -1349,9 +1348,8 @@ void CbmL1::Reconstruct(CbmEvent* event) {
 
   if (0) {  // correct hits on MC // dbg
     TRandom3 random;
-    vector<int> sF, sB, zP;
-    sF.clear();
-    sB.clear();
+    vector<int> strips, zP;
+    strips.clear();
     zP.clear();
     for (unsigned int iH = 0; iH < (*algo->vStsHits).size(); ++iH) {
       L1StsHit& h = const_cast<L1StsHit&>((*algo->vStsHits)[iH]);
@@ -1367,23 +1365,23 @@ void CbmL1::Reconstruct(CbmEvent* event) {
 #endif
       const int ista       = (*algo->vSFlag)[h.f] / 4;
       const L1Station& sta = algo->vStations[ista];
-      if (std::find(sF.begin(), sF.end(), h.f)
-          != sF.end()) {  // separate strips
+      if (std::find(strips.begin(), strips.end(), h.f)
+          != strips.end()) {  // separate strips
 
         const_cast<vector<unsigned char>*>(algo->vSFlag)
           ->push_back((*algo->vSFlag)[h.f]);
 
-        h.f = algo->NStsStripsF;
-        algo->NStsStripsF++;
+        h.f = algo->NStsStrips;
+        algo->NStsStrips++;
       }
-      sF.push_back(h.f);
-      if (std::find(sB.begin(), sB.end(), h.b) != sB.end()) {
-        const_cast<vector<unsigned char>*>(algo->vSFlagB)
-          ->push_back((*algo->vSFlagB)[h.b]);
-        h.b = algo->NStsStripsB;
-        algo->NStsStripsB++;
+      strips.push_back(h.f);
+      if (std::find(strips.begin(), strips.end(), h.b) != strips.end()) {
+        const_cast<vector<unsigned char>*>(algo->vSFlag)
+          ->push_back((*algo->vSFlag)[h.b]);
+        h.b = algo->NStsStrips;
+        algo->NStsStrips++;
       }
-      sB.push_back(h.b);
+      strips.push_back(h.b);
       if (std::find(zP.begin(), zP.end(), h.iz)
           != zP.end()) {  // TODO why do we need it??gives prob=0
         h.iz = (*algo->vStsZPos).size();
@@ -1470,12 +1468,12 @@ void CbmL1::Reconstruct(CbmEvent* event) {
   }
 
 
-  if (fVerbose > 1) cout << "L1 Track finder..." << endl;
+  if (fVerbose > 1) { cout << "L1 Track finder..." << endl; }
   algo->CATrackFinder();
   // IdealTrackFinder();
 
 
-  if (fVerbose > 1) cout << "L1 Track finder ok" << endl;
+  if (fVerbose > 1) { cout << "L1 Track finder ok" << endl; }
   //  algo->L1KFTrackFitter( fExtrapolateToTheEndOfSTS );
 
 
@@ -1502,7 +1500,7 @@ void CbmL1::Reconstruct(CbmEvent* event) {
   }
 
 
-  if (fVerbose > 1) cout << "L1 Track fitter  ok" << endl;
+  if (fVerbose > 1) { cout << "L1 Track fitter  ok" << endl; }
 
   // save recontstructed tracks
   vRTracks.clear();
@@ -1570,7 +1568,7 @@ void CbmL1::Reconstruct(CbmEvent* event) {
   }
   // output performance
   if (fPerformance) {
-    if (fVerbose > 1) cout << "Performance..." << endl;
+    if (fVerbose > 1) { cout << "Performance..." << endl; }
     //HitMatch();
     TrackMatch();
   }
@@ -1583,7 +1581,7 @@ void CbmL1::Reconstruct(CbmEvent* event) {
     // TimeHist();
     ///    WriteSIMDKFData();
   }
-  if (fVerbose > 1) cout << "End of L1" << endl;
+  if (fVerbose > 1) { cout << "End of L1" << endl; }
 
   static bool ask = 0;
   char symbol;
@@ -1727,26 +1725,22 @@ void CbmL1::WriteSTAPAlgoData()  // must be called after ReadEvent
            << " ";
     fadata << vNEvent << endl;
     // write vStsStrips
-    int n = algo->NStsStripsF;
+    int n = algo->NStsStrips;
     fadata << n << endl;
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vStsStrips[" << n << "]"
            << " have been written." << endl;
-    // write vStsStripsB
-    n = algo->NStsStripsB;
-    fadata << n << endl;
-    if (fVerbose >= 4)
-      cout << "vStsStripsB[" << n << "]"
-           << " have been written." << endl;
+    }
     // write vStsZPos
     n = (*algo->vStsZPos).size();
     fadata << n << endl;
     for (int i = 0; i < n; i++) {
       fadata << (*algo->vStsZPos)[i] << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vStsZPos[" << n << "]"
            << " have been written." << endl;
+    }
     // write vSFlag
     n = (*algo->vSFlag).size();
     fadata << n << endl;
@@ -1755,19 +1749,14 @@ void CbmL1::WriteSTAPAlgoData()  // must be called after ReadEvent
       element = (*algo->vSFlag)[i];
       fadata << static_cast<int>(element) << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vSFlag[" << n << "]"
            << " have been written." << endl;
-    // write vSFlagB
-    n = (*algo->vSFlagB).size();
-    fadata << n << endl;
-    for (int i = 0; i < n; i++) {
-      element = (*algo->vSFlagB)[i];
-      fadata << static_cast<int>(element) << endl;
-    };
-    if (fVerbose >= 4)
+    }
+    if (fVerbose >= 4) {
       cout << "vSFlagB[" << n << "]"
            << " have been written." << endl;
+    }
     // write vStsHits
     n = (*algo->vStsHits).size();
     fadata << n << endl;
@@ -1784,9 +1773,10 @@ void CbmL1::WriteSTAPAlgoData()  // must be called after ReadEvent
       // fadata  << (*algo->vStsHits)[i].time << endl;
       fadata << h.t_reco << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vStsHits[" << n << "]"
            << " have been written." << endl;
+    }
     // write StsHitsStartIndex and StsHitsStopIndex
     n = 20;
     for (int i = 0; i < n; i++) {
@@ -1864,10 +1854,10 @@ void CbmL1::WriteSTAPPerfData()  // must be called after ReadEvent
       };
       fpdata << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vMCPoints[" << n << "]"
            << " have been written." << endl;
-
+    }
     // write vMCTracks  . without Points
     n = vMCTracks.size();  // number of elements
     fpdata << n << endl;
@@ -1908,20 +1898,20 @@ void CbmL1::WriteSTAPPerfData()  // must be called after ReadEvent
       fpdata << vMCTracks[i].maxNStaHits << " ";
       fpdata << vMCTracks[i].nStations << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vMCTracks[" << n << "]"
            << " have been written." << endl;
-
+    }
     // write vHitMCRef
     n = vHitMCRef.size();  // number of elements
     fpdata << n << endl;
     for (int i = 0; i < n; i++) {
       fpdata << vHitMCRef[i] << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vHitMCRef[" << n << "]"
            << " have been written." << endl;
-
+    }
     // write vHitStore
     n = vHitStore.size();  // number of elements
     fpdata << n << endl;
@@ -1932,10 +1922,10 @@ void CbmL1::WriteSTAPPerfData()  // must be called after ReadEvent
       fpdata << vHitStore[i].x << " ";
       fpdata << vHitStore[i].y << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vHitStore[" << n << "]"
            << " have been written." << endl;
-
+    }
     // write vStsHits
     n = vStsHits.size();  // number of elements
     fpdata << n << endl;
@@ -1950,10 +1940,10 @@ void CbmL1::WriteSTAPPerfData()  // must be called after ReadEvent
       };
       fpdata << endl;
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vStsHits[" << n << "]"
            << " have been written." << endl;
-
+    }
     fpdata.close();
   }
   cout << "-I- CbmL1: Data for performance of event number " << vNEvent
@@ -2001,13 +1991,10 @@ void CbmL1::ReadSTAPAlgoData() {
 
     if (algo->vStsHits)
       const_cast<std::vector<L1StsHit>*>(algo->vStsHits)->clear();
-    algo->NStsStripsF = 0;
-    algo->NStsStripsB = 0;
+    algo->NStsStrips = 0;
     if (algo->vStsZPos)
       const_cast<std::vector<float>*>(algo->vStsZPos)->clear();
     if (algo->vSFlag) const_cast<vector<unsigned char>*>(algo->vSFlag)->clear();
-    if (algo->vSFlagB)
-      const_cast<vector<unsigned char>*>(algo->vSFlagB)->clear();
 
     // check correct position in file
     char s[] = "Event:  ";
@@ -2022,16 +2009,11 @@ void CbmL1::ReadSTAPAlgoData() {
     // read algo->vStsStrips
     fadata >> n;
     cout << " n " << n << endl;
-    algo->NStsStripsF = n;
-    if (fVerbose >= 4)
+    algo->NStsStrips = n;
+    if (fVerbose >= 4) {
       cout << "vStsStrips[" << n << "]"
            << " have been read." << endl;
-    // read algo->vStsStripsB
-    fadata >> n;
-    algo->NStsStripsB = n;
-    if (fVerbose >= 4)
-      cout << "vStsStripsB[" << n << "]"
-           << " have been read." << endl;
+    }
     // read algo->vStsZPos
     fadata >> n;
     for (int i = 0; i < n; i++) {
@@ -2039,9 +2021,10 @@ void CbmL1::ReadSTAPAlgoData() {
       fadata >> element;
       const_cast<std::vector<float>*>(algo->vStsZPos)->push_back(element);
     }
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vStsZPos[" << n << "]"
            << " have been read." << endl;
+    }
     // read algo->vSFlag
     fadata >> n;
     for (int i = 0; i < n; i++) {
@@ -2050,20 +2033,10 @@ void CbmL1::ReadSTAPAlgoData() {
       const_cast<vector<unsigned char>*>(algo->vSFlag)
         ->push_back(static_cast<unsigned char>(element));
     }
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vSFlag[" << n << "]"
            << " have been read." << endl;
-    // read algo->vSFlagB
-    fadata >> n;
-    for (int i = 0; i < n; i++) {
-      int element;
-      fadata >> element;
-      const_cast<vector<unsigned char>*>(algo->vSFlagB)
-        ->push_back(static_cast<unsigned char>(element));
     }
-    if (fVerbose >= 4)
-      cout << "vSFlagB[" << n << "]"
-           << " have been read." << endl;
     // read algo->vStsHits
     fadata >> n;
     int element_f;  // for convert
@@ -2079,9 +2052,10 @@ void CbmL1::ReadSTAPAlgoData() {
       element.iz = static_cast<TZPosI>(element_iz);
       const_cast<std::vector<L1StsHit>*>(algo->vStsHits)->push_back(element);
     }
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vStsHits[" << n << "]"
            << " have been read." << endl;
+    }
     // read StsHitsStartIndex and StsHitsStopIndex
     n = 20;
     for (int i = 0; i < n; i++) {
@@ -2169,10 +2143,10 @@ void CbmL1::ReadSTAPPerfData() {
 
       vMCPoints.push_back(element);
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vMCPoints[" << n << "]"
            << " have been read." << endl;
-
+    }
     // vMCTracks . without Points
     fpdata >> n;
     for (int i = 0; i < n; i++) {
@@ -2217,10 +2191,10 @@ void CbmL1::ReadSTAPPerfData() {
       element.CalculateIsReconstructable();
       vMCTracks.push_back(element);
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vMCTracks[" << n << "]"
            << " have been read." << endl;
-
+    }
     // vHitMCRef
     fpdata >> n;
     for (int i = 0; i < n; i++) {
@@ -2228,10 +2202,10 @@ void CbmL1::ReadSTAPPerfData() {
       fpdata >> element;
       vHitMCRef.push_back(element);
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vHitMCRef[" << n << "]"
            << " have been read." << endl;
-
+    }
     // vHitStore
     fpdata >> n;
     for (int i = 0; i < n; i++) {
@@ -2243,10 +2217,10 @@ void CbmL1::ReadSTAPPerfData() {
       fpdata >> element.y;
       vHitStore.push_back(element);
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vHitStore[" << n << "]"
            << " have been read." << endl;
-
+    }
     // vStsHits
     fpdata >> n;
     for (int i = 0; i < n; i++) {
@@ -2263,10 +2237,10 @@ void CbmL1::ReadSTAPPerfData() {
       };
       vStsHits.push_back(element);
     };
-    if (fVerbose >= 4)
+    if (fVerbose >= 4) {
       cout << "vStsHits[" << n << "]"
            << " have been read." << endl;
-
+    }
 
     //    if (nEvent == maxNEvent) { // file open on begin of all work class and close at end
     //       fpdata.close();
diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index 0ba139b384..462520bff6 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -56,14 +56,11 @@ static bool compareZ(const int& a, const int& b) {
   return l1->Get_Z_vMCPoint(a) < l1->Get_Z_vMCPoint(b);
 }
 
-
 struct TmpHit {  // used for sort Hits before writing in the normal arrays
   int iStripF,
-    iStripB;  // indices of real-strips, sts-strips (one got from detector. They consist from parts with differen positions, so will be divided before using)
-  int indStripF, indStripB;  // indices of L1-strips, indices in TmpStrip arrays
+    iStripB;  // indices of strips
   int iStation;
   int ExtIndex;  // index of hit in the TClonesArray array ( negative for MVD )
-  bool isStrip;
   double u_front, u_back;  // positions of strips
   double x, y;             // position of hit
   double dx, dy, dxy;
@@ -79,15 +76,6 @@ struct TmpHit {  // used for sort Hits before writing in the normal arrays
   }
 };
 
-struct TmpStrip {
-  fscal u;
-  fscal time;
-  int iStation;
-  int iStrip;
-  bool isStrip;
-  int effIndex;  // used for unefficiency
-};
-
 /// Repack data from Clones Arrays to L1 arrays
 void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
   if (fVerbose >= 10) cout << "ReadEvent: start." << endl;
@@ -105,8 +93,6 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
   if (fVerbose >= 10) cout << "ReadEvent: clear is done." << endl;
 
   vector<TmpHit> tmpHits;
-  vector<TmpStrip> tmpStrips;
-  vector<TmpStrip> tmpStripsB;
 
   // -- produce Sts hits from space points --
 
@@ -385,6 +371,8 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
   }  //fPerformance
 
 
+  int NStrips = 0;
+
   // get MVD hits
 
   if (listMvdHits) {
@@ -395,6 +383,8 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
     //       for(int iMc=0; iMc<nMC; iMc++) isUsedMvdPoint[iMc]=0;
     //     }
 
+    int firstDetStrip = NStrips;
+
     for (int j = 0; j < listMvdHits->GetEntries(); j++) {
       TmpHit th;
       {
@@ -402,12 +392,10 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
         th.ExtIndex   = -(1 + j);
         th.iStation   = mh->GetStationNr();
         //   th.iSector  = 0;
-        th.isStrip = 0;
-        th.iStripF = j;
-        th.iStripB = -1;
-        if (th.iStripF < 0) continue;
-        if (th.iStripF >= 0 && th.iStripB >= 0) th.isStrip = 1;
-        if (th.iStripB < 0) th.iStripB = th.iStripF;
+        int iStripF = j;
+        th.iStripF  = firstDetStrip + iStripF;
+        th.iStripB  = th.iStripF;
+        if (NStrips <= iStripF) { NStrips = iStripF + 1; }
 
         TVector3 pos, err;
         mh->Position(pos);
@@ -502,6 +490,8 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
       nEnt = (event ? event->GetNofData(ECbmDataType::kStsHit)
                     : listStsHits->GetEntries());
 
+    int firstDetStrip = NStrips;
+
     for (Int_t j = 0; j < nEnt; j++) {
       Int_t hitIndex = 0;
       if (fTimesliceMode)
@@ -519,9 +509,11 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
         th.iStation   = NMvdStations
                       + CbmStsSetup::Instance()->GetStationNumber(
                         mh->GetAddress());  //mh->GetStationNr() - 1;
-        th.isStrip = 0;
-        th.iStripF = mh->GetFrontClusterId();
-        th.iStripB = mh->GetBackClusterId();
+        th.iStripF = firstDetStrip + mh->GetFrontClusterId();
+        th.iStripB = firstDetStrip + mh->GetBackClusterId();
+
+        if (NStrips <= th.iStripF) { NStrips = th.iStripF + 1; }
+        if (NStrips <= th.iStripB) { NStrips = th.iStripB + 1; }
 
         //Get time
         th.time = mh->GetTime();
@@ -616,6 +608,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
 
     Int_t nEnt = fMuchPixelHits->GetEntries();
 
+    int firstDetStrip = NStrips;
 
     for (int j = 0; j < nEnt; j++) {
       TmpHit th;
@@ -642,15 +635,9 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
 
 
         //   th.iSector  = 0;
-        th.isStrip = 0;
-        th.iStripF = j;
-        th.iStripB = -1;
-        if (th.iStripF < 0) continue;
-        if (th.iStripF >= 0 && th.iStripB >= 0) th.isStrip = 1;
-        if (th.iStripB < 0) th.iStripB = th.iStripF;
-
-        th.iStripF += nMvdHits + nStsHits;
-        th.iStripB += nMvdHits + nStsHits;
+        th.iStripF = firstDetStrip + j;
+        th.iStripB = th.iStripF;
+        if (NStrips <= th.iStripF) { NStrips = th.iStripF + 1; }
 
         th.x = mh->GetX();
         th.y = mh->GetY();
@@ -731,6 +718,8 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
 
   if (listTrdHits) {
 
+    int firstDetStrip = NStrips;
+
     for (int j = 0; j < listTrdHits->GetEntries(); j++) {
       TmpHit th;
 
@@ -759,12 +748,9 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
       th.t_er = mh->GetTimeError();
 
       //   th.iSector  = 0;
-      th.isStrip = 0;
-      th.iStripF = j;
-      th.iStripB = -1;  //TrdHitsOnStationIndex[num+1][k];
-
-      th.iStripF += nMvdHits + nStsHits + nMuchHits;
-      th.iStripB += nMvdHits + nStsHits + nMuchHits;
+      th.iStripF = firstDetStrip + j;
+      th.iStripB = th.iStripF;  //TrdHitsOnStationIndex[num+1][k];
+      if (NStrips <= th.iStripF) { NStrips = th.iStripF + 1; }
 
       TVector3 pos, err;
       mh->Position(pos);
@@ -879,6 +865,8 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
 
   if (fTofHits) {
 
+    int firstDetStrip = NStrips;
+
     for (int j = 0; j < fTofHits->GetEntries(); j++) {
       TmpHit th;
 
@@ -900,15 +888,9 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
       th.dv = mh->GetDy();
 
       //   th.iSector  = 0;
-      th.isStrip = 0;
-      th.iStripF = j;
-      th.iStripB = -1;
-      if (th.iStripF < 0) continue;
-      if (th.iStripF >= 0 && th.iStripB >= 0) th.isStrip = 1;
-      if (th.iStripB < 0) th.iStripB = th.iStripF;
-
-      th.iStripF += nMvdHits + nStsHits + nMuchHits + nTrdHits;
-      th.iStripB += nMvdHits + nStsHits + nMuchHits + nTrdHits;
+      th.iStripF = firstDetStrip + j;
+      th.iStripB = th.iStripF;
+      if (NStrips <= th.iStripF) { NStrips = th.iStripF + 1; }
 
       TVector3 pos, err;
       mh->Position(pos);
@@ -964,7 +946,7 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
       nTofHits++;
 
     }  // for j
-  }    // if listTrdHits
+  }    // if listTofHits
 
   if (fVerbose >= 10) cout << "ReadEvent: sts hits are gotten." << endl;
 
@@ -973,76 +955,17 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
 
   sort(tmpHits.begin(), tmpHits.end(), TmpHit::Compare);
 
-  // -- create strips --
-  int NStrips = 0, NStripsB = 0;
+  // save strips in L1Algo
+  fData_->NStsStrips = NStrips;
+  fData_->vSFlag.resize(NStrips, 0);
   for (int ih = 0; ih < nHits; ih++) {
     TmpHit& th = tmpHits[ih];
-
-    // try to find the respective front and back strip from the already created
-    th.indStripF = -1;
-    th.indStripB = -1;
-    for (int is = 0; is < NStrips; is++) {
-      TmpStrip& s = tmpStrips[is];
-      if (s.iStation != th.iStation) continue;
-      if (s.iStrip != th.iStripF) continue;
-      //if (fabs(s.time - th.time) > 30) continue;
-      //if (fabs(s.u - th.u_front) > 1.e-4) continue;
-      th.indStripF = is;
-    }
-    for (int is = 0; is < NStripsB; is++) {
-      TmpStrip& s = tmpStripsB[is];
-      if (s.iStation != th.iStation) continue;
-      if (s.iStrip != th.iStripB) continue;
-      //if (fabs(s.time - th.time) > 30) continue;
-      //if (fabs(s.u - th.u_back) > 1.e-4) continue;
-      th.indStripB = is;
-    }
-    // create new strips
-    if (th.indStripF < 0) {
-      TmpStrip tmp;
-      tmp.iStation = th.iStation;
-      tmp.iStrip   = th.iStripF;
-      tmp.u        = th.u_front;
-      tmp.time     = th.time;
-      tmp.isStrip  = th.isStrip;
-      tmpStrips.push_back(tmp);
-      th.indStripF = NStrips++;
-    }
-    if (th.indStripB < 0) {
-      TmpStrip tmp1;
-      tmp1.iStation = th.iStation;
-      tmp1.iStrip   = th.iStripB;
-      tmp1.isStrip  = th.isStrip;
-      tmp1.u        = th.u_back;
-      tmp1.time     = th.time;
-      tmpStripsB.push_back(tmp1);
-      th.indStripB = NStripsB++;
-    }
+    char flag                  = th.iStation * 4;
+    fData_->vSFlag[th.iStripF] = flag;
+    fData_->vSFlag[th.iStripB] = flag;
   }  // ih
 
-  // take into account unefficiency and save strips in L1Algo
-  Int_t NEffStrips = 0, NEffStripsB = 0;
-  for (int i = 0; i < NStrips; i++) {
-    TmpStrip& ts = tmpStrips[i];
-    //     if( ts.effIndex == -1 ){
-    ts.effIndex = NEffStrips++;
-    char flag   = ts.iStation * 4;
-
-    fData_->NStsStripsF++;
-    fData_->vSFlag.push_back(flag);
-  }
-  for (int i = 0; i < NStripsB; i++) {
-    TmpStrip& ts = tmpStripsB[i];
-    //     if( ts.effIndex == -1 ){
-    ts.effIndex = NEffStripsB++;
-    char flag   = ts.iStation * 4;
-
-    fData_->NStsStripsB++;
-    fData_->vSFlagB.push_back(flag);
-  }
-
-
-  if (fVerbose >= 10) cout << "ReadEvent: strips are read." << endl;
+  if (fVerbose >= 10) { cout << "ReadEvent: strips are read." << endl; }
 
   // -- save hits --
   int nEffHits = 0;
@@ -1062,15 +985,12 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
     s.dxy      = th.dxy;
     s.time     = th.time;
 
-    if (th.indStripF < 0 || th.indStripF >= NStrips) continue;
-    if (th.indStripB < 0 || th.indStripB >= NStripsB) continue;
-
-    TmpStrip& tsF = tmpStrips[th.indStripF];
-    TmpStrip& tsB = tmpStripsB[th.indStripB];
+    assert(th.iStripF >= 0 || th.iStripF < NStrips);
+    assert(th.iStripB >= 0 || th.iStripB < NStrips);
 
     L1StsHit h;
-    h.f = tsF.effIndex;
-    h.b = tsB.effIndex;
+    h.f = th.iStripF;
+    h.b = th.iStripB;
 
     h.t_reco = th.time;
     h.t_er   = th.t_er;
@@ -1241,11 +1161,9 @@ void CbmL1::ReadEvent(L1AlgoInputData* fData_, CbmEvent* event) {
   if (fVerbose >= 10) cout << "ReadEvent: z-pos are saved." << endl;
 
   algo->SetData(fData_->GetStsHits(),
-                fData_->GetNStsStripsF(),
-                fData_->GetNStsStripsB(),
+                fData_->GetNStsStrips(),
                 fData_->GetStsZPos(),
                 fData_->GetSFlag(),
-                fData_->GetSFlagB(),
                 fData_->GetStsHitsStartIndex(),
                 fData_->GetStsHitsStopIndex());
 
diff --git a/reco/L1/L1Algo/L1Algo.cxx b/reco/L1/L1Algo/L1Algo.cxx
index 260c930120..c1d14ab25f 100644
--- a/reco/L1/L1Algo/L1Algo.cxx
+++ b/reco/L1/L1Algo/L1Algo.cxx
@@ -177,20 +177,16 @@ void L1Algo::Init(const vector<fscal>& geo,
 
 
 void L1Algo::SetData(const vector<L1StsHit>& StsHits_,
-                     int nStsStripsF_,
-                     int nStsStripsB_,
+                     int nStsStrips_,
                      const vector<fscal>& StsZPos_,
                      const vector<unsigned char>& SFlag_,
-                     const vector<unsigned char>& SFlagB_,
                      const THitI* StsHitsStartIndex_,
                      const THitI* StsHitsStopIndex_) {
 
   vStsHits    = &StsHits_;
-  NStsStripsF = nStsStripsF_;
-  NStsStripsB = nStsStripsB_;
+  NStsStrips  = nStsStrips_;
   vStsZPos    = &StsZPos_;
   vSFlag      = &SFlag_;
-  vSFlagB     = &SFlagB_;
 
   StsHitsStartIndex = StsHitsStartIndex_;
   StsHitsStopIndex  = StsHitsStopIndex_;
diff --git a/reco/L1/L1Algo/L1Algo.h b/reco/L1/L1Algo/L1Algo.h
index af0bda373d..ed290e6353 100644
--- a/reco/L1/L1Algo/L1Algo.h
+++ b/reco/L1/L1Algo/L1Algo.h
@@ -94,17 +94,11 @@ public:
     NStsStations(0)
     , NFStations(0)
     , fRadThick()
-    , NStsStripsF(0)
-    ,  // strips positions created from hits. Front strips
-    NStsStripsB(0)
-    ,  // back strips
-    vStsZPos(0)
-    ,  // all possible z-positions of hits
-    vStsHits(0)
-    ,  // hits as a combination of front-, backstrips and z-position
-    vSFlag(0)
-    ,  // information of hits station & using hits in tracks(),
-    vSFlagB(0)
+    , NStsStrips(0)  // strips positions created from hits
+    , vStsZPos(0)
+    ,            // all possible z-positions of hits
+    vStsHits(0)  // hits as a combination of front-, backstrips and z-position
+    , vSFlag(0)  // information of hits station & using hits in tracks(),
     , CATime(0)
     ,  // time of trackfinding
     vTracks(40000)
@@ -291,11 +285,9 @@ public:
   Init(const vector<fscal>& geo, const bool UseHitErrors, const bool mCBMmode);
 
   void SetData(const vector<L1StsHit>& StsHits_,
-               int nStsStripsF_,
-               int nStsStripsB_,
+               int nStsStrips_,
                const vector<fscal>& StsZPos_,
                const vector<unsigned char>& SFlag_,
-               const vector<unsigned char>& SFlagB_,
                const THitI* StsHitsStartIndex_,
                const THitI* StsHitsStopIndex_
 
@@ -325,8 +317,7 @@ public:
   L1Station vStations[MaxNStations] _fvecalignment;  // station info
   vector<L1Material> fRadThick;  // material for each station
 
-  int NStsStripsF;                // number of front strips
-  int NStsStripsB;                // number of back strips
+  int NStsStrips;                 // number of strips
   const vector<fscal>* vStsZPos;  // all possible z-positions of hits
   const vector<L1StsHit>*
     vStsHits;  // hits as a combination of front-, backstrips and z-position
@@ -334,9 +325,8 @@ public:
     [MaxNStations];  // hits as a combination of front-, backstrips and z-position
   L1Grid vGridTime[MaxNStations];
 
-  const vector<unsigned char>
-    *vSFlag,  // information of hits station & using hits in tracks;
-    *vSFlagB;
+  const vector<unsigned char>*
+    vSFlag;  // information of hits station & using hits in tracks;
 
   double CATime;  // time of trackfinding
 
diff --git a/reco/L1/L1Algo/L1CATrackFinder.cxx b/reco/L1/L1Algo/L1CATrackFinder.cxx
index 0c1e18ae19..2eea1c3ed4 100644
--- a/reco/L1/L1Algo/L1CATrackFinder.cxx
+++ b/reco/L1/L1Algo/L1CATrackFinder.cxx
@@ -1951,7 +1951,7 @@ void L1Algo::CATrackFinder() {
     for (THitI ih = StsHitsStartIndex[ist]; ih < StsHitsStopIndex[ist]; ++ih) {
       L1StsHit& h = *(const_cast<L1StsHit*>(&((*vStsHits)[ih])));
       SetFUnUsed(const_cast<unsigned char&>((*vSFlag)[h.f]));
-      SetFUnUsed(const_cast<unsigned char&>((*vSFlagB)[h.b]));
+      SetFUnUsed(const_cast<unsigned char&>((*vSFlag)[h.b]));
     }
 
   for (int ista = 0; ista < NStations; ++ista) {
@@ -2431,7 +2431,7 @@ void L1Algo::CATrackFinder() {
 
             if (GetFUsed(
                   (*vSFlag)[(*vStsHitsUnused)[first_trip.GetLHit()].f]
-                  | (*vSFlagB)[(*vStsHitsUnused)[first_trip.GetLHit()].b]))
+                  | (*vSFlag)[(*vStsHitsUnused)[first_trip.GetLHit()].b]))
               continue;
 
 
@@ -2652,7 +2652,7 @@ void L1Algo::CATrackFinder() {
 
 
                 SetFUsed(const_cast<unsigned char&>((*vSFlag)[h.f]));
-                SetFUsed(const_cast<unsigned char&>((*vSFlagB)[h.b]));
+                SetFUsed(const_cast<unsigned char&>((*vSFlag)[h.b]));
 
 
                 vRecoHits_local[num_thread][SavedHits[num_thread]] = (*phIt);
@@ -2747,8 +2747,7 @@ void L1Algo::CATrackFinder() {
           NHitsOnStation,
           ista,
           *this,
-          vSFlag,
-          vSFlagB);
+          vSFlag);
         StsHitsUnusedStartIndex[ista] = NHitsOnStationTmp;
         StsHitsUnusedStopIndex[ista]  = NHitsOnStation;
       }
@@ -2927,7 +2926,7 @@ inline void L1Algo::CAFindTrack(int ista,
 
 
     if (!GetFUsed((*vSFlag)[(*vStsHitsUnused)[ihitm].f]
-                  | (*vSFlagB)[(*vStsHitsUnused)[ihitm].b])) {
+                  | (*vSFlag)[(*vStsHitsUnused)[ihitm].b])) {
 
       //        curr_tr.StsHits.push_back((*RealIHitP)[ihitm]);
 
@@ -2939,7 +2938,7 @@ inline void L1Algo::CAFindTrack(int ista,
     }
 
     if (!GetFUsed((*vSFlag)[(*vStsHitsUnused)[ihitr].f]
-                  | (*vSFlagB)[(*vStsHitsUnused)[ihitr].b])) {
+                  | (*vSFlag)[(*vStsHitsUnused)[ihitr].b])) {
 
       //curr_tr.StsHits.push_back((*RealIHitP)[ihitr]);
       curr_tr.StsHits[curr_tr.NHits] = ((*RealIHitP)[ihitr]);
@@ -3031,8 +3030,8 @@ inline void L1Algo::CAFindTrack(int ista,
 
 
       if (GetFUsed((*vSFlag)[(*vStsHitsUnused)[new_trip.GetLHit()].f]
-                   | (*vSFlagB)[(*vStsHitsUnused)[new_trip.GetLHit()]
-                                  .b])) {  //hits are used
+                   | (*vSFlag)[(*vStsHitsUnused)[new_trip.GetLHit()]
+                                 .b])) {  //hits are used
         //  no used hits allowed -> compare and store track
         if ((curr_L > best_L)
             || ((curr_L == best_L) && (curr_chi2 < best_chi2))) {
diff --git a/reco/L1/L1Algo/L1Grid.cxx b/reco/L1/L1Algo/L1Grid.cxx
index 9bab260130..c99d6cd102 100644
--- a/reco/L1/L1Algo/L1Grid.cxx
+++ b/reco/L1/L1Algo/L1Grid.cxx
@@ -41,8 +41,7 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements,
                             int& NHitsOnStation,
                             char iS,
                             L1Algo& Algo,
-                            const vector<unsigned char>* vSFlag,
-                            const vector<unsigned char>* vSFlagB) {
+                            const vector<unsigned char>* vSFlag) {
 
   fFirstHitInBin.assign(fN + 2, 0);
 
@@ -56,7 +55,7 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements,
 
     const L1StsHit& hit = hits[x];
 
-    if (!L1Algo::GetFUsed((*vSFlag)[hit.f] | (*vSFlagB)[hit.b])) {
+    if (!L1Algo::GetFUsed((*vSFlag)[hit.f] | (*vSFlag)[hit.b])) {
       Algo.GetHitCoor(hit, xs, ys, iS);
 
       const THitI& bin = GetBinBounded(xs, ys, hit.t_reco);
@@ -98,7 +97,7 @@ void L1Grid::UpdateIterGrid(unsigned int Nelements,
   for (THitI x = 0; x < Nelements; x++) {
 
     const L1StsHit& hit = hits[x];
-    if (!L1Algo::GetFUsed((*vSFlag)[hit.f] | (*vSFlagB)[hit.b])) {
+    if (!L1Algo::GetFUsed((*vSFlag)[hit.f] | (*vSFlag)[hit.b])) {
       Algo.GetHitCoor(hit, xs, ys, iS);
 
 
diff --git a/reco/L1/L1Algo/L1Grid.h b/reco/L1/L1Algo/L1Grid.h
index d1f8254885..ded163f098 100644
--- a/reco/L1/L1Algo/L1Grid.h
+++ b/reco/L1/L1Algo/L1Grid.h
@@ -201,8 +201,7 @@ public:
                       int& NHitsOnStation,
                       char iS,
                       L1Algo& Algo,
-                      const vector<unsigned char>* vSFlag,
-                      const vector<unsigned char>* vSFlagB);
+                      const vector<unsigned char>* vSFlag);
 
 
 private:
diff --git a/reco/L1/L1Algo/L1TrackExtender.cxx b/reco/L1/L1Algo/L1TrackExtender.cxx
index 489b02dc3d..8a31f5310d 100644
--- a/reco/L1/L1Algo/L1TrackExtender.cxx
+++ b/reco/L1/L1Algo/L1TrackExtender.cxx
@@ -296,7 +296,7 @@ void L1Algo::FindMoreHits(L1Branch& t,
       const L1StsHit& hit = (*vStsHitsUnused)[ih];
       if (fabs(hit.t_reco - T.t[0]) > sqrt(T.C55[0] + hit.t_er) * 5) continue;
 
-      if (GetFUsed((*vSFlag)[hit.f] | (*vSFlagB)[hit.b])) continue;  // if used
+      if (GetFUsed((*vSFlag)[hit.f] | (*vSFlag)[hit.b])) continue;  // if used
 
       fscal xh, yh, zh;
       GetHitCoor(hit, xh, yh, zh, sta);  // faster
diff --git a/reco/L1/L1AlgoInputData.cxx b/reco/L1/L1AlgoInputData.cxx
index 09106d96cb..8d69341059 100644
--- a/reco/L1/L1AlgoInputData.cxx
+++ b/reco/L1/L1AlgoInputData.cxx
@@ -81,11 +81,10 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100],
   if (nEvent <= maxNEvent) {
 
     vStsHits.clear();
-    NStsStripsF = 0;
-    NStsStripsB = 0;
+    NStsStrips = 0;
+
     vStsZPos.clear();
     vSFlag.clear();
-    vSFlagB.clear();
 
     // check correct position in file
     char s[] = "Event:  ";
@@ -103,17 +102,11 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100],
       // read algo->vStsStrips
     fadata >> n;
     //     cout << n<<  " vStsStrips"<<endl;
-    NStsStripsF = n;
-    if (iVerbose >= 4)
+    NStsStrips = n;
+    if (iVerbose >= 4) {
       cout << "vStsStrips[" << n << "]"
            << " have been read." << endl;
-    // read algo->vStsStripsB
-    fadata >> n;
-    //  cout << n<<  " vStsStripsB"<<endl;
-    NStsStripsB = n;
-    if (iVerbose >= 4)
-      cout << "vStsStripsB[" << n << "]"
-           << " have been read." << endl;
+    }
     // read algo->vStsZPos
     fadata >> n;
     //   cout << n<<  " vStsZPos"<<endl;
@@ -122,9 +115,10 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100],
       fadata >> element;
       vStsZPos.push_back(element);
     }
-    if (iVerbose >= 4)
+    if (iVerbose >= 4) {
       cout << "vStsZPos[" << n << "]"
            << " have been read." << endl;
+    }
     // read algo->vSFlag
     fadata >> n;
     //  cout << n<<  " vSFlagB"<<endl;
@@ -133,20 +127,10 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100],
       fadata >> element;
       vSFlag.push_back(static_cast<unsigned char>(element));
     }
-    if (iVerbose >= 4)
+    if (iVerbose >= 4) {
       cout << "vSFlag[" << n << "]"
            << " have been read." << endl;
-    // read algo->vSFlagB
-    fadata >> n;
-    // cout << n<<  " vSFlagB"<<endl;
-    for (int i = 0; i < n; i++) {
-      int element;
-      fadata >> element;
-      vSFlagB.push_back(static_cast<unsigned char>(element));
     }
-    if (iVerbose >= 4)
-      cout << "vSFlagB[" << n << "]"
-           << " have been read." << endl;
     // read algo->vStsHits
     fadata >> n;
     //   cout << n<<  " vStsHits"<<endl;
@@ -166,9 +150,10 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100],
       element.iz     = static_cast<TZPosI>(element_iz);
       vStsHits.push_back(element);
     }
-    if (iVerbose >= 4)
+    if (iVerbose >= 4) {
       cout << "vStsHits[" << n << "]"
            << " have been read." << endl;
+    }
     // read StsHitsStartIndex and StsHitsStopIndex
     n = 20;
     for (int i = 0; i < n; i++) {
@@ -187,9 +172,10 @@ bool L1AlgoInputData::ReadHitsFromFile(const char work_dir[100],
       //   cout << tmp<<  " tmp"<<endl;
     }
 
-    if (iVerbose >= 2)
+    if (iVerbose >= 2) {
       cout << "-I- CbmL1: CATrackFinder data for event " << nEvent
            << " has been read from file " << fname << " successfully." << endl;
+    }
     //    if (nEvent == maxNEvent) fadata.close();
   }
   nEvent++;
diff --git a/reco/L1/L1AlgoInputData.h b/reco/L1/L1AlgoInputData.h
index 71de6b95e5..86739300f5 100644
--- a/reco/L1/L1AlgoInputData.h
+++ b/reco/L1/L1AlgoInputData.h
@@ -16,11 +16,9 @@ class L1AlgoInputData {
 public:
   L1AlgoInputData()
     : vStsHits()
-    , NStsStripsF(0)
-    , NStsStripsB(0)
+    , NStsStrips(0)
     , vStsZPos()
     , vSFlag()
-    , vSFlagB()
   //  MaxNStations(12)
 
   {
@@ -32,11 +30,9 @@ public:
   ~L1AlgoInputData() {};
 
   const vector<L1StsHit>& GetStsHits() const { return vStsHits; }
-  int GetNStsStripsF() const { return NStsStripsF; }
-  int GetNStsStripsB() const { return NStsStripsB; }
+  int GetNStsStrips() const { return NStsStrips; }
   const vector<fscal>& GetStsZPos() const { return vStsZPos; }
   const L1Vector<unsigned char>& GetSFlag() const { return vSFlag; }
-  const L1Vector<unsigned char>& GetSFlagB() const { return vSFlagB; }
   const THitI* GetStsHitsStartIndex() const { return StsHitsStartIndex; }
   const THitI* GetStsHitsStopIndex() const { return StsHitsStopIndex; }
 
@@ -65,11 +61,9 @@ public:
   void Clear() {
 
     vStsHits.clear();
-    NStsStripsF = 0;
-    NStsStripsB = 0;
+    NStsStrips = 0;
     vStsZPos.clear();
     vSFlag.clear();
-    vSFlagB.clear();
 
     {
       for (int i = 0; i < MaxNStations + 1; ++i)
@@ -88,13 +82,12 @@ public:
   enum { MaxNStations = 25 };
   vector<L1StsHit>
     vStsHits;  // hits as a combination of front-, backstrips and z-position
-  int NStsStripsF,         // Number of front strips in sts
-    NStsStripsB;           // Number of back strips in sts
+  int NStsStrips;          // Number of strips in sts
   vector<fscal> vStsZPos;  // all possible z-positions of hits
 
   L1Vector<unsigned char>
-    vSFlag,  // information of hits station & using hits in tracks;
-    vSFlagB;
+    vSFlag;  // information of hits station & using hits in tracks;
+
   THitI StsHitsStartIndex[MaxNStations + 1],
     StsHitsStopIndex[MaxNStations + 1];  // station-bounders in vStsHits array
 
-- 
GitLab