From 8ff49cb8f0877b10e5e90236d29dba2d158cc109 Mon Sep 17 00:00:00 2001
From: P-A Loizeau <p.-a.loizeau@gsi.de>
Date: Wed, 30 Nov 2022 10:38:00 +0100
Subject: [PATCH] [mCBM] Add CbmTimeSlice to unp out + rem. legacy mode for L1
 in 2022 reco

---
 macro/beamtime/mcbm2022/mcbm_digievent_reco.C |  1 -
 macro/beamtime/mcbm2022/mcbm_event_reco.C     |  1 -
 macro/beamtime/mcbm2022/mcbm_event_reco_L1.C  |  1 -
 macro/beamtime/mcbm2022/mcbm_reco.C           | 12 ++++++++++--
 reco/steer/CbmRecoUnpack.cxx                  |  7 +++++++
 reco/steer/CbmRecoUnpack.h                    |  4 ++++
 6 files changed, 21 insertions(+), 5 deletions(-)

diff --git a/macro/beamtime/mcbm2022/mcbm_digievent_reco.C b/macro/beamtime/mcbm2022/mcbm_digievent_reco.C
index 1fd5200de6..b404b52458 100644
--- a/macro/beamtime/mcbm2022/mcbm_digievent_reco.C
+++ b/macro/beamtime/mcbm2022/mcbm_digievent_reco.C
@@ -474,7 +474,6 @@ Bool_t mcbm_digievent_reco(UInt_t uRunId               = 2365,
     run->AddTask(kalman);
 
     CbmL1* l1 = new CbmL1();
-    l1->SetLegacyEventMode(1);
     l1->SetMcbmMode();
     //    if (strcmp(geoSetupTag.data(), "mcbm_beam_2021_07_surveyed") == 0) l1->SetMissingHits(1);
 
diff --git a/macro/beamtime/mcbm2022/mcbm_event_reco.C b/macro/beamtime/mcbm2022/mcbm_event_reco.C
index 547cdd8563..bc684474d8 100644
--- a/macro/beamtime/mcbm2022/mcbm_event_reco.C
+++ b/macro/beamtime/mcbm2022/mcbm_event_reco.C
@@ -850,7 +850,6 @@ Bool_t mcbm_event_reco(UInt_t uRunId                   = 2391,
   run->AddTask(kalman);
 
   CbmL1* l1 = new CbmL1();
-  l1->SetLegacyEventMode(1);
   l1->SetMcbmMode();
 
   // --- Material budget file names
diff --git a/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C b/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C
index 4d90c4acc7..169b1fd751 100644
--- a/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C
+++ b/macro/beamtime/mcbm2022/mcbm_event_reco_L1.C
@@ -560,7 +560,6 @@ Bool_t mcbm_event_reco_L1(UInt_t uRunId                   = 2391,
     run->AddTask(kalman);
 
     CbmL1* l1 = new CbmL1();
-    l1->SetLegacyEventMode(1);
     l1->SetMcbmMode();
 
     //    if (strcmp(geoSetupTag.data(), "mcbm_beam_2021_07_surveyed") == 0) l1->SetMissingHits(1);
diff --git a/macro/beamtime/mcbm2022/mcbm_reco.C b/macro/beamtime/mcbm2022/mcbm_reco.C
index 81b2303318..4f128847f6 100644
--- a/macro/beamtime/mcbm2022/mcbm_reco.C
+++ b/macro/beamtime/mcbm2022/mcbm_reco.C
@@ -197,6 +197,10 @@ Bool_t mcbm_reco(UInt_t uRunId                   = 2391,
   // -----   FairRunAna   ---------------------------------------------------
   FairRunAna* run             = new FairRunAna();
   FairFileSource* inputSource = new FairFileSource(inFile);
+  if ("" != sUnpFile) {
+    LOG(info) << "Adding unpacked digis file to input: " << sUnpFile;
+    inputSource->AddFriend(sUnpFile);
+  }
   run->SetSource(inputSource);
 
   FairRootFileSink* outputSink = new FairRootFileSink(outFile);
@@ -267,7 +271,6 @@ Bool_t mcbm_reco(UInt_t uRunId                   = 2391,
                  << "\n Exiting";
       return kFALSE;
     }
-    inputSource->AddFriend(sUnpFile);
   }
   // ------------------------------------------------------------------------
 
@@ -478,13 +481,18 @@ Bool_t mcbm_reco(UInt_t uRunId                   = 2391,
   // ===                             L1                                    ===
   // =========================================================================
   if (bL1) {
+    if ("" == sUnpFile) {
+      LOG(error) << "To run with L1, an unpack file full name also has to be provided to get a CbmTimeSlice object."
+                 << "\n Exiting";
+      return kFALSE;
+    }
+
     run->AddTask(new CbmTrackingDetectorInterfaceInit());
 
     CbmKF* kalman = new CbmKF();
     run->AddTask(kalman);
 
     CbmL1* l1 = new CbmL1("L1", 0);  // <= Disable verbose mode
-    l1->SetLegacyEventMode(1);
     l1->SetMcbmMode();
     //    if (strcmp(geoSetupTag.data(), "mcbm_beam_2021_07_surveyed") == 0) l1->SetMissingHits(1);
 
diff --git a/reco/steer/CbmRecoUnpack.cxx b/reco/steer/CbmRecoUnpack.cxx
index d913b4652e..b62a7e6daa 100644
--- a/reco/steer/CbmRecoUnpack.cxx
+++ b/reco/steer/CbmRecoUnpack.cxx
@@ -11,6 +11,7 @@
 #include "CbmRecoUnpack.h"
 
 #include "CbmRecoUnpackConfig.tmpl"
+#include "CbmTimeSlice.h"
 #include "CbmTrdDigi.h"
 #include "CbmTsEventHeader.h"
 
@@ -71,6 +72,9 @@ Bool_t CbmRecoUnpack::Init()
       << "CbmRecoUnpack::Init() no CbmTsEventHeader was added to the run. Without it, we can not store the UTC of the "
          "Timeslices correctly. Hence, this causes a fatal. Please add it in the steering macro to the Run.";
 
+  fTimeSlice = new CbmTimeSlice(0., 1.28e8 + 1.28e6);  // FIXME: hardcoded TS length + overlap of mCBM 2022 becnhmark
+  ioman->Register("TimeSlice.", "DAQ", fTimeSlice, kTRUE);
+
   // --- Psd
   if (fPsdConfig) {
     fPsdConfig->InitOutput();
@@ -362,6 +366,7 @@ void CbmRecoUnpack::Reset()
 {
   // Reset the event header for a new timeslice
   fCbmTsEventHeader->Reset();
+  fTimeSlice->Reset(0., 1.28e8 + 1.28e6);  // FIXME: hardcoded TS length + overlap of mCBM 2022 becnhmark
 
   // Reset the unpackers for a new timeslice, e.g. clear the output vectors
 
@@ -399,6 +404,8 @@ void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts)
   fCbmTsEventHeader->SetTsIndex(ts->index());
   fCbmTsEventHeader->SetTsStartTime(ts->start_time());
 
+  fTimeSlice->SetStartTime(ts->start_time());
+
   uint64_t nComponents = ts->num_components();
   // if (fDoDebugPrints) LOG(info) << "Unpack: TS index " << ts->index() << " components " << nComponents;
   LOG(info) << "Unpack: TS index " << ts->index() << " components " << nComponents;
diff --git a/reco/steer/CbmRecoUnpack.h b/reco/steer/CbmRecoUnpack.h
index a49798972e..1bf6850586 100644
--- a/reco/steer/CbmRecoUnpack.h
+++ b/reco/steer/CbmRecoUnpack.h
@@ -41,6 +41,7 @@
 #include <utility>
 #include <vector>
 
+class CbmTimeSlice;
 class TH1;
 class TStopwatch;
 
@@ -403,6 +404,9 @@ private:
   }
   // ----------------------------------------------------------------------------
 
+  /** @brief CbmTimeslice object, mostly redundant with the TsEventHeader, needed by L1 to switch timeslice mode **/
+  CbmTimeSlice* fTimeSlice;  //! Current time slice
+
   /** @brief Configuration of the Much unpacker. Provides the configured algorithm */
   std::shared_ptr<CbmMuchUnpackConfig> fMuchConfig = nullptr;  //!
 
-- 
GitLab