From 7d643fc9d80b0837efd7940e5b2610bf08f1945d Mon Sep 17 00:00:00 2001
From: Pascal Raisig <praisig@ikf.uni-frankfurt.de>
Date: Wed, 14 Jul 2021 22:23:15 +0200
Subject: [PATCH] Get PSD algo running

---
 macro/run/run_unpack_tsa.C                    |  8 ++---
 .../detectors/psd/unpack/CbmPsdUnpackAlgo.cxx | 30 +++++++++----------
 .../psd/unpack/CbmPsdUnpackConfig.cxx         |  3 ++
 reco/steer/CMakeLists.txt                     |  4 +++
 reco/steer/CbmRecoUnpack.cxx                  | 19 ++++++------
 5 files changed, 34 insertions(+), 30 deletions(-)

diff --git a/macro/run/run_unpack_tsa.C b/macro/run/run_unpack_tsa.C
index c30f704ef8..1e598aacc7 100644
--- a/macro/run/run_unpack_tsa.C
+++ b/macro/run/run_unpack_tsa.C
@@ -113,8 +113,8 @@ void run_unpack_tsa(std::string infile = "test.tsa", UInt_t runid = 0, const cha
   // psdconfig->SetDebugState();
   psdconfig->SetDoWriteOutput();
   // psdconfig->SetDoWriteOptOutA("CbmPsdDsp");
-  std::string parfilesbasepath = Form("%s/macro/beamtime/mcbm2021/", srcDir.Data());
-  psdconfig->SetParFilesBasePath("");
+  std::string parfilesbasepathPsd = Form("%s/macro/beamtime/mcbm2021/", srcDir.Data());
+  psdconfig->SetParFilesBasePath(parfilesbasepathPsd);
   // -------------
 
   // ---- TRD ----
@@ -127,8 +127,8 @@ void run_unpack_tsa(std::string infile = "test.tsa", UInt_t runid = 0, const cha
   trdconfig->SetDoWriteOptOutA(CbmTrdRawMessageSpadic::GetBranchName());
   // trdconfig->SetDoWriteOptOutB("SpadicInfoMessages"); // SpadicInfoMessages
 
-  std::string parfilesbasepath = Form("%s/parameters/trd", srcDir.Data());
-  trdconfig->SetParFilesBasePath(parfilesbasepath);
+  std::string parfilesbasepathTrd = Form("%s/parameters/trd", srcDir.Data());
+  trdconfig->SetParFilesBasePath(parfilesbasepathTrd);
   trdconfig->SetMonitor(GetTrdMonitor(outfilename));
   // Get the spadic configuration true = avg baseline active / false plain sample 0
   trdconfig->SetSpadicObject(GetTrdSpadic(true));
diff --git a/reco/detectors/psd/unpack/CbmPsdUnpackAlgo.cxx b/reco/detectors/psd/unpack/CbmPsdUnpackAlgo.cxx
index ca67b1904c..6655db4a17 100644
--- a/reco/detectors/psd/unpack/CbmPsdUnpackAlgo.cxx
+++ b/reco/detectors/psd/unpack/CbmPsdUnpackAlgo.cxx
@@ -17,7 +17,6 @@
 #include "raw/PsdGbtReader-v0.00.h"
 #include "raw/PsdGbtReader-v1.00.h"
 
-
 CbmPsdUnpackAlgo::CbmPsdUnpackAlgo() : CbmRecoUnpackAlgo(fgkFlesSubsystemIdTrdR, "CbmPsdUnpackAlgo") {}
 
 // ----- Channel address
@@ -73,34 +72,34 @@ Bool_t CbmPsdUnpackAlgo::initParSet(CbmMcbm2018PsdPar* parset)
   LOG(debug) << fName << "::initParSetAsic - ";
 
   fuRawDataVersion = parset->GetDataVersion();
-  LOG(info) << "Data Version: " << fuRawDataVersion;
+  LOG(debug) << "Data Version: " << fuRawDataVersion;
 
   UInt_t uNrOfGdpbs = parset->GetNrOfGdpbs();
-  LOG(info) << "Nr. of Tof GDPBs: " << uNrOfGdpbs;
+  LOG(debug) << "Nr. of Tof GDPBs: " << uNrOfGdpbs;
 
   UInt_t uNrOfFeePerGdpb = parset->GetNrOfFeesPerGdpb();
-  LOG(info) << "Nr. of FEEs per Psd GDPB: " << uNrOfFeePerGdpb;
+  LOG(debug) << "Nr. of FEEs per Psd GDPB: " << uNrOfFeePerGdpb;
 
   UInt_t uNrOfChannelsPerFee = parset->GetNrOfChannelsPerFee();
-  LOG(info) << "Nr. of channels per FEE: " << uNrOfChannelsPerFee;
+  LOG(debug) << "Nr. of channels per FEE: " << uNrOfChannelsPerFee;
 
   auto uNrOfChannelsPerGdpb = uNrOfChannelsPerFee * uNrOfFeePerGdpb;
-  LOG(info) << "Nr. of channels per GDPB: " << uNrOfChannelsPerGdpb;
+  LOG(debug) << "Nr. of channels per GDPB: " << uNrOfChannelsPerGdpb;
 
   fGdpbIdIndexMap.clear();
   for (UInt_t i = 0; i < uNrOfGdpbs; ++i) {
     fGdpbIdIndexMap[parset->GetGdpbId(i)] = i;
-    LOG(info) << "GDPB Id of PSD  " << i << " : " << std::hex << parset->GetGdpbId(i) << std::dec;
+    LOG(debug) << "GDPB Id of PSD  " << i << " : " << std::hex << parset->GetGdpbId(i) << std::dec;
   }  // for( UInt_t i = 0; i < fuNrOfGdpbs; ++i )
 
   fuNrOfGbtx = parset->GetNrOfGbtx();
-  LOG(info) << "Nr. of GBTx: " << fuNrOfGbtx;
+  LOG(debug) << "Nr. of GBTx: " << fuNrOfGbtx;
 
   //Temporary until creation of full psd map
-  UInt_t uNrOfModules  = 1;
-  UInt_t uNrOfSections = 32;
+  UInt_t uNrOfModules  = parset->GetNrOfModules();
+  UInt_t uNrOfSections = parset->GetNrOfSections();
   UInt_t uNrOfChannels = uNrOfModules * uNrOfSections;
-  LOG(info) << "Nr. of possible Psd channels: " << uNrOfChannels;
+  LOG(debug) << "Nr. of possible Psd channels: " << uNrOfChannels;
   fviPsdChUId.resize(uNrOfChannels);
 
   UInt_t iCh = 0;
@@ -147,7 +146,7 @@ bool CbmPsdUnpackAlgo::unpack(const fles::Timeslice* ts, std::uint16_t icomp, UI
   auto msidx     = msDescriptor.idx;
 
   auto mstime = static_cast<double>(msidx);
-  LOG(debug) << "Microslice: " << msidx << " from EqId " << std::hex << eqid << std::dec << " has size: " << uSize;
+  LOG(debug4) << "Microslice: " << msidx << " from EqId " << std::hex << eqid << std::dec << " has size: " << uSize;
 
   if (0 == fvbMaskedComponents.size()) fvbMaskedComponents.resize(ts->num_components(), kFALSE);
 
@@ -298,11 +297,10 @@ bool CbmPsdUnpackAlgo::unpack(const fles::Timeslice* ts, std::uint16_t icomp, UI
 
                                   dFitAmpl, dFitZL, dFitEdep, dFitR2, dFitTimeMax, uFitWfm);
 
-        //DEBUG
-        //if (fdTime < prev_hit_time) printf("negative time btw hits! %f after %f \n", fdTime, prev_hit_time);
-        //DEBUG END
+        // Create the actual digi and move it to the output vector
+        makeDigi(dsp);
+
         prev_hit_time = dTime;
-        //DEBUG
 
       }  // for (uint64_t hit_iter = 0; hit_iter < PsdReader.VectHitHdr.size(); hit_iter++) {
     }
diff --git a/reco/detectors/psd/unpack/CbmPsdUnpackConfig.cxx b/reco/detectors/psd/unpack/CbmPsdUnpackConfig.cxx
index 4fa6254bf1..38a4761dad 100644
--- a/reco/detectors/psd/unpack/CbmPsdUnpackConfig.cxx
+++ b/reco/detectors/psd/unpack/CbmPsdUnpackConfig.cxx
@@ -33,6 +33,9 @@ void CbmPsdUnpackConfig::InitUnpacker()
   // First choose the derived unpacking algorithm to be used and pass the raw to digi method
   auto algo = chooseAlgo();
 
+  if (fDoLog) LOG(info) << fName << "::Init - SetParFilesBasePath";
+  algo->SetParFilesBasePath(fParFilesBasePath);
+
   // Initialise the parameter containers required by the unpacker algo. Includes loading the corresponding ascii files
   auto reqparvec = algo->GetParContainerRequest(fGeoSetupTag, fRunId);
   initOk &= initParContainers(reqparvec);
diff --git a/reco/steer/CMakeLists.txt b/reco/steer/CMakeLists.txt
index 3006f4e33e..21669fb81f 100644
--- a/reco/steer/CMakeLists.txt
+++ b/reco/steer/CMakeLists.txt
@@ -21,6 +21,7 @@ set(INCLUDE_DIRECTORIES
 ${CBMROOT_SOURCE_DIR}/reco/steer
 ${CBMROOT_SOURCE_DIR}/reco/base
 
+${CBMROOT_SOURCE_DIR}/reco/detectors/psd
 ${CBMROOT_SOURCE_DIR}/reco/detectors/psd/unpack
 ${CBMROOT_SOURCE_DIR}/reco/detectors/rich/unpack
 ${CBMROOT_SOURCE_DIR}/reco/detectors/sts/unpack
@@ -31,6 +32,7 @@ ${CBMROOT_SOURCE_DIR}/reco/detectors/trd/unpack
 
 ${CBMROOT_SOURCE_DIR}/core/base
 ${CBMROOT_SOURCE_DIR}/core/data
+${CBMROOT_SOURCE_DIR}/core/data/raw
 ${CBMROOT_SOURCE_DIR}/core/data/base
 ${CBMROOT_SOURCE_DIR}/core/data/psd
 ${CBMROOT_SOURCE_DIR}/core/detectors/psd
@@ -41,6 +43,8 @@ ${CBMROOT_SOURCE_DIR}/core/data/trd
 ${CBMROOT_SOURCE_DIR}/core/detectors/trd
 
 
+
+
 )
 
 set(SYSTEM_INCLUDE_DIRECTORIES
diff --git a/reco/steer/CbmRecoUnpack.cxx b/reco/steer/CbmRecoUnpack.cxx
index b9483deef8..b59fba60fb 100644
--- a/reco/steer/CbmRecoUnpack.cxx
+++ b/reco/steer/CbmRecoUnpack.cxx
@@ -30,8 +30,6 @@ using std::unique_ptr;
 CbmRecoUnpack::CbmRecoUnpack() {}
 // ----------------------------------------------------------------------------
 
-// ----------------------------------------------------------------------------
-
 
 // -----   Initialisation   ---------------------------------------------------
 void CbmRecoUnpack::Finish()
@@ -93,17 +91,17 @@ void CbmRecoUnpack::Reset()
   // Reset the unpackers for a new timeslice, e.g. clear the output vectors
 
   // ---- Psd ----
-  if (fPsdConfig) fPsdConfig->GetUnpacker()->Finish();
+  if (fPsdConfig) fPsdConfig->Reset();
   // ---- Rich ----
-  if (fRichConfig) fRichConfig->GetUnpacker()->Finish();
+  if (fRichConfig) fRichConfig->Reset();
   // ---- Sts ----
-  if (fStsConfig) fStsConfig->GetUnpacker()->Finish();
+  if (fStsConfig) fStsConfig->Reset();
   // ---- Tof ----
-  // if (fTofConfig) fTofConfig->GetUnpacker()->Finish();
+  // if (fTofConfig) fTofConfig->Reset();
   // ---- Trd ----
-  if (fTrdConfig) fTrdConfig->GetUnpacker()->Finish();
+  if (fTrdConfig) fTrdConfig->Reset();
   // ---- Trd2D ----
-  if (fTrdConfig2D) fTrdConfig2D->GetUnpacker()->Finish();
+  if (fTrdConfig2D) fTrdConfig2D->Reset();
 }
 
 // ----------------------------------------------------------------------------
@@ -117,7 +115,8 @@ void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts)
   fCbmTsEventHeader->SetTsStartTime(ts->start_time());
 
   uint64_t nComponents = ts->num_components();
-  if (fDoDebugPrints) LOG(info) << "Unpack: TS index " << ts->index() << " components " << nComponents;
+  // if (fDoDebugPrints) LOG(info) << "Unpack: TS index " << ts->index() << " components " << nComponents;
+  LOG(info) << "Unpack: TS index " << ts->index() << " components " << nComponents;
 
   for (uint64_t component = 0; component < nComponents; component++) {
 
@@ -126,7 +125,7 @@ void CbmRecoUnpack::Unpack(unique_ptr<Timeslice> ts)
     switch (systemId) {
       case fkFlesPsd: {
         if (fPsdConfig)
-          fCbmTsEventHeader->SetNDigisTrd(
+          fCbmTsEventHeader->SetNDigisPsd(
             unpack(&timeslice, component, fPsdConfig, fPsdConfig->GetOptOutAVec(), fPsdConfig->GetOptOutBVec()));
         break;
       }
-- 
GitLab