From cc158d61e276af01c8f195fd0ed0302f2c1f5021 Mon Sep 17 00:00:00 2001
From: Felix Weiglhofer <weiglhofer@fias.uni-frankfurt.de>
Date: Mon, 26 Jun 2023 13:44:18 +0000
Subject: [PATCH] algo::Unpack: Add flag to toggle walk correction.

---
 algo/unpack/Unpack.cxx      |  5 +++--
 algo/unpack/Unpack.h        | 11 +++++++++--
 algo/unpack/UnpackChain.cxx |  2 ++
 3 files changed, 14 insertions(+), 4 deletions(-)

diff --git a/algo/unpack/Unpack.cxx b/algo/unpack/Unpack.cxx
index 0bfd734e67..f4cd2c884b 100644
--- a/algo/unpack/Unpack.cxx
+++ b/algo/unpack/Unpack.cxx
@@ -153,7 +153,7 @@ namespace cbm::algo
         elinkPar.fTimeOffset = fSystemTimeOffset[fles::SubsystemIdentifier::STS];
         elinkPar.fAdcOffset  = 1.;
         elinkPar.fAdcGain    = 1.;
-        elinkPar.fWalk       = fStsConfig.WalkMap(elinkPar.fAddress, elinkPar.fAsicNr);
+        if (fApplyWalkCorrection) elinkPar.fWalk = fStsConfig.WalkMap(elinkPar.fAddress, elinkPar.fAsicNr);
         // TODO: Add parameters for time and ADC calibration
         par->fElinkParams.push_back(elinkPar);
       }
@@ -274,7 +274,8 @@ namespace cbm::algo
       L_(debug) << "--- Configured equipment " << equip << " with " << numAsics << " asics";
     }
 
-    L_(info) << "--- Configured " << fAlgoSts.size() << " unpacker algorithms for STS.";
+    L_(info) << "--- Configured " << fAlgoSts.size()
+             << " unpacker algorithms for STS. (Walk correction = " << fApplyWalkCorrection << ")";
     L_(debug) << "Readout map:" << fStsConfig.PrintReadoutMap();
     L_(info) << "--- Configured " << fAlgoMuch.size() << " unpacker algorithms for MUCH.";
     L_(info) << "--- Configured " << fAlgoRich.size() << " unpacker algorithms for RICH.";
diff --git a/algo/unpack/Unpack.h b/algo/unpack/Unpack.h
index 2d875b490a..72b10e66a5 100644
--- a/algo/unpack/Unpack.h
+++ b/algo/unpack/Unpack.h
@@ -101,6 +101,12 @@ namespace cbm::algo
     /** @brief Parameters for RICH unpackers **/
     RichReadoutConfig fRichConfig {};
 
+
+    /**
+     * @brief Set whether to apply walk correction. Must be set before Init(). (default: true)
+    **/
+    void SetApplyWalkCorrection(bool applyWalkCorrection) { fApplyWalkCorrection = applyWalkCorrection; }
+
     /** @brief Initialize unpackers and fill parameters from config objects
      * @param subIds: vector of subsystem identifiers to unpack, default: all
      * @see Init()
@@ -128,8 +134,9 @@ namespace cbm::algo
                 std::vector<MonitorData>* monitorMs, uint8_t sys_ver);
 
 
-  private:                                                // members
-    std::vector<fles::SubsystemIdentifier> fSubIds = {};  ///< Detector identifiers to unpack
+  private:                                                  // members
+    bool fApplyWalkCorrection                      = true;  ///< Apply walk correction
+    std::vector<fles::SubsystemIdentifier> fSubIds = {};    ///< Detector identifiers to unpack
 
     /** @brief STS unpackers **/
     std::map<uint16_t, UnpackSts> fAlgoSts = {};
diff --git a/algo/unpack/UnpackChain.cxx b/algo/unpack/UnpackChain.cxx
index b0c56787eb..670964be01 100644
--- a/algo/unpack/UnpackChain.cxx
+++ b/algo/unpack/UnpackChain.cxx
@@ -7,6 +7,8 @@ using namespace cbm::algo;
 
 void UnpackChain::Init()
 {
+  // Disable walk correction for now. 2022 data crashes unpacker with hardcoded 2021 params.
+  fUnpack.SetApplyWalkCorrection(false);
   fUnpack.Init(std::vector<fles::SubsystemIdentifier> {
     fles::SubsystemIdentifier::STS,
     // fles::SubsystemIdentifier::MUCH,
-- 
GitLab