From 6ebc32e7962a6590652f1245133d7edb3fc68c9b Mon Sep 17 00:00:00 2001
From: Pascal Raisig <praisig@ikf.uni-frankfurt.de>
Date: Wed, 14 Jul 2021 21:04:44 +0200
Subject: [PATCH] Add multi hit extraction function to TrdDigi

---
 core/data/trd/CbmTrdDigi.cxx | 13 +++++++++++++
 core/data/trd/CbmTrdDigi.h   |  8 ++++++++
 2 files changed, 21 insertions(+)

diff --git a/core/data/trd/CbmTrdDigi.cxx b/core/data/trd/CbmTrdDigi.cxx
index 60a685cba7..4a47dcd776 100644
--- a/core/data/trd/CbmTrdDigi.cxx
+++ b/core/data/trd/CbmTrdDigi.cxx
@@ -13,6 +13,7 @@
 #include <iomanip>  // for operator<<, setprecision, setw
 #include <sstream>  // for operator<<, basic_ostream, stringstream
 #include <string>   // for char_traits
+#include <utility>
 
 using std::endl;
 using std::string;
@@ -171,6 +172,18 @@ Double_t CbmTrdDigi::GetCharge(Double_t& tilt, Int_t& dt) const
 //_________________________________________________________________________________
 Double_t CbmTrdDigi::GetChargeError() const { return 0; }
 
+//_________________________________________________________________________________
+std::pair<CbmTrdDigi::eTriggerType, bool> CbmTrdDigi::GetTriggerPair(const Int_t triggerValue)
+{
+  // First get the trigger type kSelf or kNeighbor it is written to the first bit of the trigger bits.
+  eTriggerType type = static_cast<eTriggerType>(triggerValue & 1);
+
+  // Now extract if we had a multihit or not the info is written two the next bit
+  bool isMultihit = static_cast<bool>((triggerValue >> 1) & 1);
+
+  return std::make_pair(type, isMultihit);
+}
+
 //_________________________________________________________________________________
 Bool_t CbmTrdDigi::IsFlagged(const Int_t iflag) const
 {
diff --git a/core/data/trd/CbmTrdDigi.h b/core/data/trd/CbmTrdDigi.h
index 55e3166f54..da8df65c5b 100644
--- a/core/data/trd/CbmTrdDigi.h
+++ b/core/data/trd/CbmTrdDigi.h
@@ -151,6 +151,14 @@ public:
   }
   /** \brief Channel trigger type. SPADIC specific see CbmTrdTriggerType*/
   Int_t GetTriggerType() const { return (fInfo >> fgkTrgOffset) & 0x3; }
+
+  /**
+   * @brief Get the trigger combination, i.e. St or Nt and is multihit or not (true/false)
+   * @param[in] Int_t trigger value of a digi as stored in fInfo
+   * @return std::pair<eTriggerType, bool> <St or Nt, multihit or not>
+  */
+  static std::pair<eTriggerType, bool> GetTriggerPair(const Int_t triggerValue);
+
   /** \brief Channel FEE SPADIC/FASP according to CbmTrdAsicType*/
   eCbmTrdAsicType GetType() const
   {
-- 
GitLab