From fd7a83d095729a565510ce08f2a218df6af59b46 Mon Sep 17 00:00:00 2001
From: "se.gorbunov" <se.gorbunov@gsi.de>
Date: Fri, 24 Feb 2023 13:25:04 +0000
Subject: [PATCH] L1: remove legacy event mode

---
 reco/L1/CbmL1.cxx            | 62 ++++++++++++++----------------------
 reco/L1/CbmL1.h              | 14 ++++----
 reco/L1/CbmL1Performance.cxx | 12 +++----
 reco/L1/CbmL1ReadEvent.cxx   | 44 ++++++++++---------------
 4 files changed, 51 insertions(+), 81 deletions(-)

diff --git a/reco/L1/CbmL1.cxx b/reco/L1/CbmL1.cxx
index aa3de257a2..73ab89b513 100644
--- a/reco/L1/CbmL1.cxx
+++ b/reco/L1/CbmL1.cxx
@@ -249,7 +249,7 @@ InitStatus CbmL1::Init()
   fpMuchPoints = 0;
   fpTrdPoints  = 0;
   fpTofPoints  = 0;
-  fpMCTracks   = 0;
+  fpMcTracks   = 0;
 
   fpMvdHitMatches  = 0;
   fpTrdHitMatches  = 0;
@@ -258,18 +258,10 @@ InitStatus CbmL1::Init()
 
   fpStsClusters = 0;
 
-  fvFileEvent.clear();
-
-  if (!fLegacyEventMode) {  //  Time-slice mode selected
-    LOG(info) << GetName() << ": running in time-slice mode.";
-    fTimeSlice = NULL;
-    fTimeSlice = (CbmTimeSlice*) fairManager->GetObject("TimeSlice.");
-    if (fTimeSlice == NULL) LOG(fatal) << GetName() << ": No time slice branch in the tree!";
-
-  }     //? time-slice mode
-  else  // event mode
-    LOG(info) << GetName() << ": running in event mode.";
+  fvSelectedMcEvents.clear();
 
+  fTimeSlice = (CbmTimeSlice*) fairManager->GetObject("TimeSlice.");
+  if (!fTimeSlice) { LOG(fatal) << GetName() << ": No time slice branch in the tree!"; }
 
   fpStsClusters       = L1_DYNAMIC_CAST<TClonesArray*>(fairManager->GetObject("StsCluster"));
   fpStsHitMatches     = L1_DYNAMIC_CAST<TClonesArray*>(fairManager->GetObject("StsHitMatch"));
@@ -313,15 +305,13 @@ InitStatus CbmL1::Init()
 
     fpMcEventHeader = mcManager->GetObject("MCEventHeader.");
 
-    fpMCTracks = mcManager->InitBranch("MCTrack");
+    fpMcTracks = mcManager->InitBranch("MCTrack");
 
-    if (nullptr == fpMCTracks) LOG(fatal) << GetName() << ": No MCTrack data!";
+    if (nullptr == fpMcTracks) LOG(fatal) << GetName() << ": No MCTrack data!";
     if (nullptr == fpMcEventHeader) LOG(fatal) << GetName() << ": No MC event header data!";
 
-    if (!fLegacyEventMode) {
-      fpEventList = (CbmMCEventList*) fairManager->GetObject("MCEventList.");
-      if (nullptr == fpEventList) LOG(fatal) << GetName() << ": No MCEventList data!";
-    }
+    fpMcEventList = (CbmMCEventList*) fairManager->GetObject("MCEventList.");
+    if (nullptr == fpMcEventList) LOG(fatal) << GetName() << ": No MCEventList data!";
 
     if (fUseMVD) {
       fpMvdPoints      = mcManager->InitBranch("MvdPoint");
@@ -892,7 +882,7 @@ InitStatus CbmL1::Init()
 void CbmL1::Reconstruct(CbmEvent* event)
 {
   static int nevent = 0;
-  fvFileEvent.clear();
+  fvSelectedMcEvents.clear();
 
   // TODO: move these values to CbmL1Parameters namespace (S.Zharko)
   bool areDataLeft = true;   // whole TS processed?
@@ -932,19 +922,18 @@ void CbmL1::Reconstruct(CbmEvent* event)
   }
   // -----------------------------------------------------------------------
 
-  if (!fLegacyEventMode && fPerformance) {
-
-    int nofEvents = fpEventList->GetNofEvents();
+  if (fPerformance) {
+    int nofEvents = fpMcEventList->GetNofEvents();
     for (int iE = 0; iE < nofEvents; iE++) {
-      int fileId  = fpEventList->GetFileIdByIndex(iE);
-      int eventId = fpEventList->GetEventIdByIndex(iE);
-      fvFileEvent.insert(DFSET::value_type(fileId, eventId));
+      int fileId  = fpMcEventList->GetFileIdByIndex(iE);
+      int eventId = fpMcEventList->GetEventIdByIndex(iE);
+      fvSelectedMcEvents.insert(DFSET::value_type(fileId, eventId));
     }
   }
   else {
     Int_t iFile  = FairRunAna::Instance()->GetEventHeader()->GetInputFileId();
     Int_t iEvent = FairRunAna::Instance()->GetEventHeader()->GetMCEntryNumber();
-    fvFileEvent.insert(DFSET::value_type(iFile, iEvent));
+    fvSelectedMcEvents.insert(DFSET::value_type(iFile, iEvent));
   }
 
   if (fVerbose > 1) { cout << "\nCbmL1::Exec event " << ++nevent << " ...\n\n"; }
@@ -1027,7 +1016,6 @@ void CbmL1::Reconstruct(CbmEvent* event)
     if (fVerbose > 1) { cout << "L1 Track fitter  ok" << endl; }
 
     // save reconstructed tracks
-    if (fLegacyEventMode) vRTracksCur.clear();
     int trackFirstHit = 0;
 
     float TsStart_new = TsStart + TsLength - TsOverlap;
@@ -1061,10 +1049,7 @@ void CbmL1::Reconstruct(CbmEvent* event)
         int caHitId  = fpAlgo->fRecoHits[trackFirstHit + i];
         int cbmHitID = fpAlgo->GetInputData()->GetHit(caHitId).ID;
         double time  = fpAlgo->GetInputData()->GetHit(caHitId).t;
-        if (!fLegacyEventMode) { t.Hits.push_back(cbmHitID); }
-        else {
-          t.Hits.push_back(caHitId);
-        }
+        t.Hits.push_back(cbmHitID);
         if (time >= (TsStart + TsLength - TsOverlap)) {
           isTrackInOverlap = 1;
           if (TsStart_new > time) { TsStart_new = time; }
@@ -1073,7 +1058,7 @@ void CbmL1::Reconstruct(CbmEvent* event)
       trackFirstHit += it->NHits;
 
       // Discard tracks from overlap region
-      if ((!fLegacyEventMode) && (isTrackInOverlap == 1)) { continue; }
+      if (isTrackInOverlap == 1) { continue; }
 
       vRTracksCur.push_back(t);
     }
@@ -1084,14 +1069,14 @@ void CbmL1::Reconstruct(CbmEvent* event)
       float time    = sh->GetTime();
 
       if (TsStart_new <= time) {
-        FstHitinTs = i;  // TODO: shouldn't it be in the fLegacyEventMode == true only? (S.Zharko)
+        FstHitinTs = i;
         break;
       }
     }
 
-    if (!fLegacyEventMode) TsStart = TsStart_new;  ///Set new TS strat to earliest discarted track
+    TsStart = TsStart_new;  ///Set new TS strat to earliest discarted track
 
-    if (!fLegacyEventMode) LOG(debug) << "CA Track Finder: " << fpAlgo->fCATime << " s/sub-ts" << endl;
+    LOG(debug) << "CA Track Finder: " << fpAlgo->fCATime << " s/sub-ts" << endl;
   }
 
 
@@ -1124,8 +1109,9 @@ void CbmL1::Reconstruct(CbmEvent* event)
   fvRecoTracks.reserve(vRTracksCur.size());
   for (unsigned int iTrack = 0; iTrack < vRTracksCur.size(); iTrack++) {
 
-    for (unsigned int iHit = 0; iHit < vRTracksCur[iTrack].Hits.size(); iHit++)
-      if (!fLegacyEventMode) { vRTracksCur[iTrack].Hits[iHit] = fvSortedHitsIndexes[vRTracksCur[iTrack].Hits[iHit]]; }
+    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]);
   }
@@ -1432,7 +1418,7 @@ void CbmL1::WriteSIMDKFData()
     int jHit = 0;
     for (int iHit = 0; iHit < NHits; iHit++) {
       CbmL1HitDebugInfo& h = fvHitDebugInfo[RecTrack->Hits[iHit]];
-      st[jHit]         = h.iStation;
+      st[jHit]             = h.iStation;
       if (h.ExtIndex < 0) {
         CbmMvdHit* MvdH = (CbmMvdHit*) fpMvdHits->At(-h.ExtIndex - 1);
         x[jHit]         = MvdH->GetX();
diff --git a/reco/L1/CbmL1.h b/reco/L1/CbmL1.h
index fbdb116684..a9c08f25b7 100644
--- a/reco/L1/CbmL1.h
+++ b/reco/L1/CbmL1.h
@@ -291,7 +291,6 @@ public:
 
 
   void SetExtrapolateToTheEndOfSTS(bool b) { fExtrapolateToTheEndOfSTS = b; }
-  void SetLegacyEventMode(bool b) { fLegacyEventMode = b; }
   void SetMissingHits(bool value) { fMissingHits = value; }
   void SetStsOnlyMode() { fTrackingMode = L1Algo::TrackingMode::kSts; }
   void SetMcbmMode() { fTrackingMode = L1Algo::TrackingMode::kMcbm; }
@@ -477,7 +476,7 @@ public:
 
   L1Algo::TrackingMode fTrackingMode = L1Algo::TrackingMode::kSts;  ///< Tracking mode: kSts, kMcbm or kGlobal
 
-  DFSET fvFileEvent {};  ///< Map of fileID to eventId
+  DFSET fvSelectedMcEvents {};  ///< Set of selected MC events with fileID and eventId
 
 
   L1Vector<CbmL1Track> fvRecoTracks = {"CbmL1::fvRecoTracks"};  ///< Reconstructed tracks container
@@ -576,8 +575,8 @@ private:
   // ** MC input **
 
   // General
-  CbmMCEventList* fpEventList      = nullptr;  ///< MC event list (all)
-  CbmMCDataArray* fpMCTracks       = nullptr;  ///< MC tracks list
+  CbmMCEventList* fpMcEventList    = nullptr;  ///< MC event list (all)
+  CbmMCDataArray* fpMcTracks       = nullptr;  ///< MC tracks list
   CbmMCDataObject* fpMcEventHeader = nullptr;  ///< MC event header
 
   // MC-point arrays
@@ -614,11 +613,11 @@ private:
 
   /// 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
+
+  L1Vector<CbmL1MCTrack> fvMCTracks = {"CbmL1::fvMCTracks"};         ///< Array of MC tracks
+  L1Vector<int> fvHitPointIndexes   = {"CbmL1::fvHitPointIndexes"};  ///< Indexes of MC points vs. hit index
 
 public:
   // ** Repacked input data **
@@ -663,7 +662,6 @@ private:
     fMatBudgetFileName {};  ///< Map for material budget file names vs. detectorID
 
   bool fExtrapolateToTheEndOfSTS {false};
-  bool fLegacyEventMode {false};
 
   KFTopoPerformance* fTopoPerformance {nullptr};
   L1EventEfficiencies fEventEfficiency {};  // average efficiencies
diff --git a/reco/L1/CbmL1Performance.cxx b/reco/L1/CbmL1Performance.cxx
index c2cf4d0a2e..86378a9eb7 100644
--- a/reco/L1/CbmL1Performance.cxx
+++ b/reco/L1/CbmL1Performance.cxx
@@ -460,8 +460,7 @@ void CbmL1::EfficienciesPerformance()
     cout << "Reconstructed MC tracks/event: "
          << (double(L1_NTRA.reco.counters[L1_NTRA.indices["total"]]) / double(L1_NEVENTS)) << endl;
     cout << endl;
-    cout << "CA Track Finder: " << L1_CATIME / L1_NEVENTS << (fLegacyEventMode ? " s/ev" : " s/time slice") << endl
-         << endl;
+    cout << "CA Track Finder: " << L1_CATIME / L1_NEVENTS << " s/time slice" << endl << endl;
   }
 }  // void CbmL1::Performance()
 
@@ -1943,7 +1942,7 @@ void CbmL1::InputPerformance()
 
         double mcTime = pt->GetTime();
 
-        if (!fLegacyEventMode) mcTime += fpEventList->GetEventTime(link.GetEntry(), link.GetFile());
+        mcTime += fpMcEventList->GetEventTime(link.GetEntry(), link.GetFile());
 
         // hit pulls and residuals
 
@@ -2034,8 +2033,7 @@ void CbmL1::InputPerformance()
 
       CbmMuchPoint* pt = (CbmMuchPoint*) fpMuchPoints->Get(link.GetFile(), link.GetEntry(), link.GetIndex());
       double mcTime    = pt->GetTime();
-
-      if (!fLegacyEventMode) mcTime += fpEventList->GetEventTime(link.GetEntry(), link.GetFile());
+      mcTime += fpMcEventList->GetEventTime(link.GetEntry(), link.GetFile());
       // mcTime+=20;
 
       // hit pulls and residuals
@@ -2099,7 +2097,7 @@ void CbmL1::InputPerformance()
       CbmTrdPoint* pt = (CbmTrdPoint*) fpTrdPoints->Get(link.GetFile(), link.GetEntry(), link.GetIndex());
       double mcTime   = pt->GetTime();
 
-      if (!fLegacyEventMode) mcTime += fpEventList->GetEventTime(link.GetEntry(), link.GetFile());
+      mcTime += fpMcEventList->GetEventTime(link.GetEntry(), link.GetFile());
 
       // hit pulls and residuals
       //      if ((sh->GetPlaneId()) == 0) continue;
@@ -2161,7 +2159,7 @@ void CbmL1::InputPerformance()
       CbmTofPoint* pt = (CbmTofPoint*) fpTofPoints->Get(link.GetFile(), link.GetEntry(), link.GetIndex());
       double mcTime   = pt->GetTime();
 
-      if (!fLegacyEventMode) mcTime += fpEventList->GetEventTime(link.GetEntry(), link.GetFile());
+      mcTime += fpMcEventList->GetEventTime(link.GetEntry(), link.GetFile());
 
       // hit pulls and residuals
 
diff --git a/reco/L1/CbmL1ReadEvent.cxx b/reco/L1/CbmL1ReadEvent.cxx
index 68e4a66eaf..0fce653a9c 100644
--- a/reco/L1/CbmL1ReadEvent.cxx
+++ b/reco/L1/CbmL1ReadEvent.cxx
@@ -223,11 +223,6 @@ int CbmL1::MatchHitWithMc<L1DetectorID::kSts>(int iHit) const
       int iFile  = link.GetFile();
       int iEvent = link.GetEntry();
 
-      if (fLegacyEventMode) {
-        iFile  = fvFileEvent.begin()->first;
-        iEvent = fvFileEvent.begin()->second;
-      }
-
       auto itPoint = fmMCPointsLinksMap.find(CbmL1LinkKey(iIndex + fNpointsMvdAll, iEvent, iFile));
       assert(itPoint != fmMCPointsLinksMap.cend());
 
@@ -413,8 +408,7 @@ void CbmL1::ReadEvent(float& TsStart, float& TsLength, float& /*TsOverlap*/, int
     fNpointsTrdAll  = 0;
     fNpointsTofAll  = 0;
 
-
-    for (DFSET::iterator set_it = fvFileEvent.begin(); set_it != fvFileEvent.end(); ++set_it) {
+    for (DFSET::iterator set_it = fvSelectedMcEvents.begin(); set_it != fvSelectedMcEvents.end(); ++set_it) {
       Int_t iFile  = set_it->first;
       Int_t iEvent = set_it->second;
       if (fUseMVD) fNpointsMvdAll += fpMvdPoints->Size(iFile, iEvent);
@@ -424,7 +418,7 @@ void CbmL1::ReadEvent(float& TsStart, float& TsLength, float& /*TsOverlap*/, int
       if (fUseTOF) fNpointsTofAll += fpTofPoints->Size(iFile, iEvent);
     }
 
-    for (DFSET::iterator set_it = fvFileEvent.begin(); set_it != fvFileEvent.end(); ++set_it) {
+    for (DFSET::iterator set_it = fvSelectedMcEvents.begin(); set_it != fvSelectedMcEvents.end(); ++set_it) {
       Int_t iFile   = set_it->first;
       Int_t iEvent  = set_it->second;
       firstMvdPoint = fvMCPoints.size();
@@ -766,10 +760,7 @@ void CbmL1::ReadEvent(float& TsStart, float& TsLength, float& /*TsOverlap*/, int
       Int_t hitIndex = 0;
       hitIndex       = (event ? event->GetIndex(ECbmDataType::kStsHit, j) : j);
 
-      int hitIndexSort = 0;
-      if (!fLegacyEventMode) hitIndexSort = fvSortedStsHitsIndexes[hitIndex];
-      else
-        hitIndexSort = j;
+      int hitIndexSort = fvSortedStsHitsIndexes[hitIndex];
 
       // ***********************************
       // ** Fill the temporary hit object **
@@ -799,10 +790,7 @@ void CbmL1::ReadEvent(float& TsStart, float& TsLength, float& /*TsOverlap*/, int
         th.time = h->GetTime();
         th.dt   = h->GetTimeError();
 
-        if (!fLegacyEventMode) { th.id = nMvdHits + hitIndex; }
-        else {
-          th.id = tmpHits.size();
-        }
+        th.id = nMvdHits + hitIndex;
 
         /// stop if reco TS ends and many hits left
         if (!event) {
@@ -1331,29 +1319,29 @@ void CbmL1::Fill_vMCTracks()
   // Count the total number of tracks in this event and reserve memory
   {
     Int_t nMCTracks = 0;
-    for (DFSET::iterator set_it = fvFileEvent.begin(); set_it != fvFileEvent.end(); ++set_it) {
+    for (DFSET::iterator set_it = fvSelectedMcEvents.begin(); set_it != fvSelectedMcEvents.end(); ++set_it) {
       Int_t iFile  = set_it->first;
       Int_t iEvent = set_it->second;
-      nMCTracks += fpMCTracks->Size(iFile, iEvent);
+      nMCTracks += fpMcTracks->Size(iFile, iEvent);
     }
     fvMCTracks.reserve(nMCTracks);
   }
 
   int fileEvent = 0;
   /* Loop over MC event */
-  for (DFSET::iterator set_it = fvFileEvent.begin(); set_it != fvFileEvent.end(); ++set_it, ++fileEvent) {
+  for (DFSET::iterator set_it = fvSelectedMcEvents.begin(); set_it != fvSelectedMcEvents.end(); ++set_it, ++fileEvent) {
     Int_t iFile  = set_it->first;
     Int_t iEvent = set_it->second;
 
     auto header = dynamic_cast<FairMCEventHeader*>(fpMcEventHeader->Get(iFile, iEvent));
     assert(header);
 
-    double eventTime = fpEventList->GetEventTime(iEvent, iFile);
+    double eventTime = fpMcEventList->GetEventTime(iEvent, iFile);
 
-    Int_t nMCTrack = fpMCTracks->Size(iFile, iEvent);
+    Int_t nMCTrack = fpMcTracks->Size(iFile, iEvent);
     /* Loop over MC tracks */
     for (Int_t iMCTrack = 0; iMCTrack < nMCTrack; iMCTrack++) {
-      CbmMCTrack* MCTrack = L1_DYNAMIC_CAST<CbmMCTrack*>(fpMCTracks->Get(iFile, iEvent, iMCTrack));
+      CbmMCTrack* MCTrack = L1_DYNAMIC_CAST<CbmMCTrack*>(fpMcTracks->Get(iFile, iEvent, iMCTrack));
       if (!MCTrack) { continue; }
 
       int mother_ID = MCTrack->GetMotherId();
@@ -1399,7 +1387,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
   Int_t mcID    = -1;
   Double_t time = 0.f;
 
-  double eventTime = fpEventList->GetEventTime(event, file);
+  double eventTime = fpMcEventList->GetEventTime(event, file);
 
   if (MVD == 1) {
     CbmMvdPoint* pt = L1_DYNAMIC_CAST<CbmMvdPoint*>(fpMvdPoints->Get(file, event, iPoint));  // file, event, object
@@ -1416,7 +1404,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
   if (MVD == 0) {
     CbmStsPoint* pt = L1_DYNAMIC_CAST<CbmStsPoint*>(fpStsPoints->Get(file, event, iPoint));  // file, event, object
     if (!pt) return 1;
-    if (!fLegacyEventMode) {
+    {
       Double_t StartTime     = fTimeSlice->GetStartTime();
       Double_t EndTime       = fTimeSlice->GetEndTime();
       Double_t Time_MC_point = eventTime + pt->GetTime();
@@ -1440,7 +1428,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
   if (MVD == 2) {
     CbmMuchPoint* pt = L1_DYNAMIC_CAST<CbmMuchPoint*>(fpMuchPoints->Get(file, event, iPoint));  // file, event, object
     if (!pt) return 1;
-    if (!fLegacyEventMode) {
+    {
       Double_t StartTime     = fTimeSlice->GetStartTime();
       Double_t EndTime       = fTimeSlice->GetEndTime();
       Double_t Time_MC_point = eventTime + pt->GetTime();
@@ -1465,7 +1453,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
     CbmTrdPoint* pt = L1_DYNAMIC_CAST<CbmTrdPoint*>(fpTrdPoints->Get(file, event, iPoint));  // file, event, object
 
     if (!pt) return 1;
-    if (!fLegacyEventMode) {
+    {
       Double_t StartTime     = fTimeSlice->GetStartTime();  // not used
       Double_t EndTime       = fTimeSlice->GetEndTime();    // not used
       Double_t Time_MC_point = eventTime + pt->GetTime();   // not used
@@ -1489,7 +1477,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
   if (MVD == 4) {
     CbmTofPoint* pt = L1_DYNAMIC_CAST<CbmTofPoint*>(fpTofPoints->Get(file, event, iPoint));  // file, event, object
     if (!pt) return 1;
-    if (!fLegacyEventMode) {
+    {
       Double_t StartTime     = fTimeSlice->GetStartTime();
       Double_t EndTime       = fTimeSlice->GetEndTime();
       Double_t Time_MC_point = eventTime + pt->GetTime();
@@ -1538,7 +1526,7 @@ bool CbmL1::ReadMCPoint(CbmL1MCPoint* MC, int iPoint, int file, int event, int M
   MC->time = time;
 
   if (MC->ID < 0) return 1;
-  CbmMCTrack* MCTrack = L1_DYNAMIC_CAST<CbmMCTrack*>(fpMCTracks->Get(file, event, MC->ID));
+  CbmMCTrack* MCTrack = L1_DYNAMIC_CAST<CbmMCTrack*>(fpMcTracks->Get(file, event, MC->ID));
   if (!MCTrack) return 1;
   MC->pdg       = MCTrack->GetPdgCode();
   MC->mother_ID = MCTrack->GetMotherId();
-- 
GitLab