diff --git a/reco/detectors/CMakeLists.txt b/reco/detectors/CMakeLists.txt index 54d8ba995c71a93097399ed4f3101ece605f0c02..e8daeaa9d41b037b222c9a2dc539f55d0ecc6182 100644 --- a/reco/detectors/CMakeLists.txt +++ b/reco/detectors/CMakeLists.txt @@ -7,4 +7,5 @@ add_subdirectory(rich) add_subdirectory(sts) add_subdirectory(tof) add_subdirectory(trd) +add_subdirectory(tzd) diff --git a/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h b/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h index f4f7cd0ce3d4a7b299bb40d37696dc514fe14de8..f2f1a2d7cbd310d2973566287d716ad70c8e0a2f 100644 --- a/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h +++ b/reco/detectors/tof/unpack/CbmTofUnpackAlgo.h @@ -89,7 +89,16 @@ public: /** @brief Set a predefined monitor @param monitor predefined unpacking monitor */ void SetMonitor(std::shared_ptr<CbmTofUnpackMonitor> monitor) { fMonitor = monitor; } -protected: + /** + * @brief Get a reference to the output vector. Used by TZD encapsulating algo to access output. + * + * @return std::vector<CbmTofDigi>& + */ + std::vector<CbmTofDigi>& GetOutputVec() { return fOutputVec; } + +public: + /// Raise permissions for access to these protected methods to allow access in encapsulating TZD algo + /** @brief Finish function for this algorithm base clase */ void finish() { diff --git a/reco/detectors/tzd/CMakeLists.txt b/reco/detectors/tzd/CMakeLists.txt new file mode 100644 index 0000000000000000000000000000000000000000..edfef61a2896f413a7c0fa143bd179c9339f8fef --- /dev/null +++ b/reco/detectors/tzd/CMakeLists.txt @@ -0,0 +1,51 @@ +set(INCLUDE_DIRECTORIES + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/unpack + ) + + +set(SRCS + unpack/CbmTzdUnpackAlgo.cxx + unpack/CbmTzdUnpackConfig.cxx +) + + +set(LIBRARY_NAME CbmTzdReco) +set(LINKDEF ${LIBRARY_NAME}LinkDef.h) +set(PUBLIC_DEPENDENCIES + CbmBase + CbmData + CbmRecoBase + CbmTofBase + CbmTofReco + FairLogger::FairLogger + FairRoot::Base + ROOT::Core + ROOT::Graf3d + ROOT::Hist + ROOT::MathCore + ROOT::Minuit + ) + +set(PRIVATE_DEPENDENCIES + CbmDisplay + CbmFlibFlesTools + FairRoot::EventDisplay + FairRoot::ParBase + ROOT::Eve + ROOT::Geom + ROOT::Gpad + ROOT::Graf + ROOT::Matrix + ROOT::Physics + ROOT::RHTTP + ROOT::RIO + ROOT::Spectrum + ) + +set(INTERFACE_DEPENDENCIES + external::fles_ipc + ) + + +generate_cbm_library() diff --git a/reco/detectors/tzd/CbmTzdRecoLinkDef.h b/reco/detectors/tzd/CbmTzdRecoLinkDef.h new file mode 100644 index 0000000000000000000000000000000000000000..8e3111176baa1be4f5d1ed6e012f1eb571afa86a --- /dev/null +++ b/reco/detectors/tzd/CbmTzdRecoLinkDef.h @@ -0,0 +1,14 @@ +/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#ifdef __CINT__ + +#pragma link off all globals; +#pragma link off all classes; +#pragma link off all functions; + +#pragma link C++ class CbmTzdUnpackAlgo + ; +#pragma link C++ class CbmTzdUnpackConfig + ; + +#endif diff --git a/reco/detectors/tzd/unpack/CbmTzdUnpackAlgo.cxx b/reco/detectors/tzd/unpack/CbmTzdUnpackAlgo.cxx new file mode 100644 index 0000000000000000000000000000000000000000..701c2d322f166fbc6d0a788aa6708c7c7805a98b --- /dev/null +++ b/reco/detectors/tzd/unpack/CbmTzdUnpackAlgo.cxx @@ -0,0 +1,11 @@ +/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#include "CbmTzdUnpackAlgo.h" + +CbmTzdUnpackAlgo::CbmTzdUnpackAlgo() : CbmRecoUnpackAlgo("CbmTzdUnpackAlgo") {} + +CbmTzdUnpackAlgo::~CbmTzdUnpackAlgo() {} + +ClassImp(CbmTzdUnpackAlgo) diff --git a/reco/detectors/tzd/unpack/CbmTzdUnpackAlgo.h b/reco/detectors/tzd/unpack/CbmTzdUnpackAlgo.h new file mode 100644 index 0000000000000000000000000000000000000000..33ee79d01009079ba9b82966e90a7e6a2874e2bd --- /dev/null +++ b/reco/detectors/tzd/unpack/CbmTzdUnpackAlgo.h @@ -0,0 +1,292 @@ +/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#ifndef CbmTzdUnpackAlgo_H +#define CbmTzdUnpackAlgo_H + +#include "CbmErrorMessage.h" +#include "CbmMcbm2018TofPar.h" +#include "CbmRecoUnpackAlgo.tmpl" +#include "CbmTofDigi.h" +#include "CbmTofUnpackAlgo.h" +#include "CbmTofUnpackMonitor.h" +#include "CbmTzdDigi.h" + +#include "Timeslice.hpp" // timeslice + +#include <Logger.h> + +#include <Rtypes.h> // for types +#include <RtypesCore.h> + +#include <cstddef> +#include <cstdint> +#include <memory> +#include <utility> + +class CbmTzdUnpackAlgo : public CbmRecoUnpackAlgo<CbmTzdDigi, CbmErrorMessage> { +public: + /** @brief Create the Cbm Trd Unpack AlgoBase object */ + CbmTzdUnpackAlgo(); + + /** @brief Destroy the Cbm Trd Unpack Task object */ + virtual ~CbmTzdUnpackAlgo(); + + /** @brief Copy constructor - not implemented **/ + CbmTzdUnpackAlgo(const CbmTzdUnpackAlgo&) = delete; + + /** @brief Assignment operator - not implemented **/ + CbmTzdUnpackAlgo& operator=(const CbmTzdUnpackAlgo&) = delete; + + /** + * @brief Initialisation at begin of run. Forwards to TOF unpacker algo instance. + * + * @retval Bool_t initOk If not kTRUE, task will be set inactive. + */ + Bool_t Init() + { + LOG(info) << fName << "::Init()"; + + return fTofAlgo.Init(); + } + + /** + * @brief Unpack a given timeslice component. Overload to forward inner calls to TOF unpacker algo instance. + * + * @param ts timeslice pointer + * @param icomp index to the component to be unpacked + * @return true + * @return false + * + * @remark The content of the component can only be accessed via the timeslice. Hence, we need to pass the pointer to the full timeslice + */ + std::vector<CbmTzdDigi> Unpack(const fles::Timeslice* ts, std::uint16_t icomp) + { + + bool unpackOk = true; + + // Clear the default return vector + fOutputVec.clear(); + fTofAlgo.GetOutputVec().clear(); + + /// On first TS, extract the TS parameters from header (by definition stable over time). + if (fIsFirstTs) getTimesliceParams(ts); + + // Get the index of the current timeslice + fTsIndex = ts->index(); + + // Get the number of the current timeslice (the index increases currently via nthTimeslice* fNrCoreMsPerTs) + size_t itimeslice = fTsIndex / fNrCoreMsPerTs; + + // Set further parameters required by the explicit algorithm + setDerivedTsParameters(itimeslice); + + auto nrMsToLoop = fDoIgnoreOverlappMs ? fNrCoreMsPerTs : fNrMsPerTs; + + /// Loop over choosen microslices (all or core only) + for (UInt_t imslice = 0; imslice < nrMsToLoop; imslice++) { + unpackOk &= fTofAlgo.unpack(ts, icomp, imslice); + if (!unpackOk) { + /** @todo add potential counter for corrupted microslices */ + continue; + } + } + + /// Give opportunity to finalize component (e.g. copy from temp buffers) if necessary + FinalizeComponent(); + + auto ndigis = fOutputVec.size(); + fNrCreatedDigis += ndigis; + + // Get the input(output) data sizes + fSumInDataSize += ts->size_component(icomp) / 1.0e6; + fSumOutDataSize += ndigis * GetOutputObjSize() / 1.0e6; + + ++fNrProcessedTs; + return fOutputVec; + } + + // Getters + /** + * @brief Get the requested parameter containers. To be defined in the derived classes! + * Return the required parameter containers together with the paths to the ascii + * files to. + * Forwards to TOF unpacker algo instance. + * + * @param[in] std::string geoTag as used in CbmSetup + * @param[in] std::uint32_t runId for runwise defined parameters + * @return fParContVec + */ + virtual std::vector<std::pair<std::string, std::shared_ptr<FairParGenericSet>>>* + GetParContainerRequest(std::string geoTag, std::uint32_t runId) + { + return fTofAlgo.GetParContainerRequest(geoTag, runId); + }; + + /** + * @brief Get a given output vector connected to the tree, if called after calling InitUnpacker(). + * Forwards to TOF unpacker algo instance. + * + * @return std::vector<CbmErrorMessage>* + */ + std::vector<CbmErrorMessage>* GetOptOutAVec() { return fTofAlgo.GetOptOutAVec(); } + + /** + * @brief Get a given output vector connected to the tree, if called after calling InitUnpacker(). + * Forwards to TOF unpacker algo instance. + * + * @return std::vector<std::nullptr_t>* + */ + std::vector<std::nullptr_t>* GetOptOutBVec() { return fTofAlgo.GetOptOutBVec(); } + + /** + * @brief Get the Output Obj Size + * + * @return size_t + */ + static size_t GetOutputObjSize() { return sizeof(CbmTzdDigi); } + + /** @brief Get the global system time offset + * Forwards to TOF unpacker algo instance. + * + * @remark in princible this should go to parameters + */ + int32_t GetSystemTimeOffset() { return fTofAlgo.GetSystemTimeOffset(); } + + // Setters + /** + * @brief Set the Do Ignore Overlapp µslices flag + * + * @param value + */ + void SetDoIgnoreOverlappMs(bool value = false) { fTofAlgo.SetDoIgnoreOverlappMs(value); } + + /** @brief Set the optional output A vector @param vec */ + void SetOptOutAVec(std::vector<CbmErrorMessage>* vec) { fTofAlgo.SetOptOutAVec(vec); } + + /** @brief Set the optional output B vector @param vec */ + void SetOptOutBVec(std::vector<std::nullptr_t>* vec) { fTofAlgo.SetOptOutBVec(vec); } + + /** + * @brief Set the base path to the parameter containers. + * + * @param value + */ + void SetParFilesBasePath(std::string value) { fTofAlgo.SetParFilesBasePath(value); } + + /** @brief Set the global system time offset @remark in princible this should go to parameters */ + void SetSystemTimeOffset(int32_t value) { fTofAlgo.SetSystemTimeOffset(value); } + + /** @brief Set the start time of the current TS */ + void SetTsStartTime(size_t value) { fTofAlgo.SetTsStartTime(value); } + + /** + * @brief Sets the flag enabling the epoch offset hack for the July 2021 data. Default is enable. + * Forwards to TOF unpacker algo instance. + * + * @param[in] Optional: boolean flag value, default is true + */ + void SetFlagEpochCountHack2021(bool bFlagin = true) { fTofAlgo.SetFlagEpochCountHack2021(bFlagin); } + + /** + * @brief Sets the flag switching to a request of CbmMcbm2018BmonPar. Default is enable. + * Forwards to TOF unpacker algo instance. + * + * @param[in] Optional: boolean flag value, default is true + */ + void SetFlagBmonParMode(bool bFlagin = true) { fTofAlgo.SetFlagBmonParMode(bFlagin); } + + /** + * @brief Sets the name of the parameter file to be used. + * Forwards to TOF unpacker algo instance. + * + * @param[in] std:string, path should not be included as set in the Config class + */ + void SetParFileName(std::string sNewName) { fTofAlgo.SetParFileName(sNewName); } + + /** @brief Set a predefined monitor @param monitor predefined unpacking monitor + * Forwards to TOF unpacker algo instance. + */ + void SetMonitor(std::shared_ptr<CbmTofUnpackMonitor> monitor) { fTofAlgo.SetMonitor(monitor); } + +protected: + /** @brief Finish function for this algorithm base clase. Forwards to TOF unpacker algo instance. */ + void finish() { fTofAlgo.finish(); } + + /** @brief Function that allows special calls during Finish in the derived algos. + * Forwards to TOF unpacker algo instance. + */ + void finishDerived() { fTofAlgo.finishDerived(); } + + /** + * @brief Initialisation at begin of run. Forwards to TOF unpacker algo instance. + * + * @retval Bool_t initOk + */ + Bool_t init() { return fTofAlgo.init(); } + + /** + * @brief Handles the distribution of the hidden derived classes to their explicit functions. + * Forwards to TOF unpacker algo instance. + * + * @param parset + * @return Bool_t initOk + */ + Bool_t initParSet(FairParGenericSet* parset) { return fTofAlgo.initParSet(parset); } + + /** + * @brief Handles the distribution of the hidden derived classes to their explicit functions. + * Forwards to TOF unpacker algo instance. + * + * @param parset + * @return Bool_t initOk + */ + Bool_t initParSet(CbmMcbm2018TofPar* parset) { return fTofAlgo.initParSet(parset); } + + + /** + * @brief Set the Derived Ts Parameters + * + * In this function parameters required by the explicit algo connected to the timeslice can be set. + * + * @param itimeslice + * @return true + * @return false + */ + bool setDerivedTsParameters(size_t /*itimeslice*/) { return true; } + + /** + * @brief Copy the buffer from the internal (TOF) algo to the new Digi Type storage + */ + virtual void FinalizeComponent() + { + fOutputVec.reserve(fTofAlgo.GetOutputVec().size()); + for (CbmTofDigi internalDigi : fTofAlgo.GetOutputVec()) { + fOutputVec.push_back(CbmTzdDigi(internalDigi)); + } + return; + } + + /** + * @brief Unpack a given microslice. To be implemented in the derived unpacker algos. + * Unused as "Unpack(timeslice, component)" is overloaded, but necessary to avoir pure virtual class. + * + * @param ts timeslice pointer + * @param icomp index to the component to be unpacked + * @param imslice index of the microslice to be unpacked + * @return true + * @return false + * + * @remark The content of the µslice can only be accessed via the timeslice. Hence, we need to pass the pointer to the full timeslice + */ + virtual bool unpack(const fles::Timeslice* /*ts*/, std::uint16_t /*icomp*/, UInt_t /*imslice*/) { return true; } + +private: + /** @brief Actual unpacker algo */ + CbmTofUnpackAlgo fTofAlgo; + + ClassDef(CbmTzdUnpackAlgo, 1) +}; + +#endif // CbmTzdUnpackAlgo_H diff --git a/reco/detectors/tzd/unpack/CbmTzdUnpackConfig.cxx b/reco/detectors/tzd/unpack/CbmTzdUnpackConfig.cxx new file mode 100644 index 0000000000000000000000000000000000000000..aed2425070b801f3a8c11e033c84510f87192e84 --- /dev/null +++ b/reco/detectors/tzd/unpack/CbmTzdUnpackConfig.cxx @@ -0,0 +1,58 @@ +/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#include "CbmTzdUnpackConfig.h" + +#include "CbmTofDigi.h" +#include "CbmTzdUnpackAlgo.h" + +#include <Logger.h> + +#include <Rtypes.h> +#include <RtypesCore.h> + +#include <memory> +#include <vector> + +CbmTzdUnpackConfig::CbmTzdUnpackConfig(std::string detGeoSetupTag, UInt_t runid) + : CbmRecoUnpackConfig("CbmTzdUnpackConfig", detGeoSetupTag, runid) +{ + SetFlagBmonParMode(); +} + +CbmTzdUnpackConfig::~CbmTzdUnpackConfig() {} + +// ---- Init ---- +void CbmTzdUnpackConfig::InitAlgo() +{ + fAlgo->SetFlagEpochCountHack2021(fbEpochCountHack2021); + + if (fMonitor) { fAlgo->SetMonitor(fMonitor); } + + // Now we have all information required to initialise the algorithm + fAlgo->Init(); +} + +// ---- chooseAlgo ---- +std::shared_ptr<CbmTzdUnpackAlgo> CbmTzdUnpackConfig::chooseAlgo() +{ + if (fDoLog) LOG(info) << fName << "::Init - chooseAlgo"; + + // Default unpacker selection + // Unpacker algo from mcbm 2021 on and hopefully default for a long time. + auto algo = std::make_shared<CbmTzdUnpackAlgo>(); + LOG(info) << fName << "::chooseAlgo() - selected algo = " << algo->Class_Name(); + if (fbBmonParMode) { + LOG(info) << fName << "::chooseAlgo - Setting the new algo in BMon Par mode"; + algo->SetFlagBmonParMode(fbBmonParMode); + } + + return algo; + + LOG(error) << fName + << "::Init - chooseAlgo() - no algorithm created something went wrong. We can not work like this!"; + return nullptr; +} + +ClassImp(CbmTzdUnpackConfig) diff --git a/reco/detectors/tzd/unpack/CbmTzdUnpackConfig.h b/reco/detectors/tzd/unpack/CbmTzdUnpackConfig.h new file mode 100644 index 0000000000000000000000000000000000000000..00d99d44e3b347ca8f2c96ea0adead92d7ac0b1a --- /dev/null +++ b/reco/detectors/tzd/unpack/CbmTzdUnpackConfig.h @@ -0,0 +1,105 @@ +/* Copyright (C) 2022 Facility for Antiproton and Ion Research in Europe, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Pierre-Alain Loizeau [committer] */ + +#ifndef CbmTzdUnpackConfig_H +#define CbmTzdUnpackConfig_H + +#include "CbmErrorMessage.h" +#include "CbmRecoUnpackConfig.tmpl" +#include "CbmTofUnpackMonitor.h" +#include "CbmTzdDigi.h" +#include "CbmTzdUnpackAlgo.h" + +#include <Rtypes.h> +#include <RtypesCore.h> + +#include <cstddef> +#include <cstdint> +#include <memory> +#include <vector> + +class CbmTzdUnpackConfig : public CbmRecoUnpackConfig<CbmTzdUnpackAlgo, CbmTzdDigi, CbmErrorMessage> { + +public: + /** + * @brief Create the Cbm Tof Unpack Task object + * + * @param geoSetupTag Geometry setup tag for the given detector as used by CbmSetup objects + * @param runid set if unpacker is rerun on a special run with special parameters + *@remark We use the string instead of CbmSetup here, to not having to link against sim/steer... + */ + CbmTzdUnpackConfig(std::string detGeoSetupTag, UInt_t runid = 0); + + /** + * @brief Destroy the Cbm Tof Unpack Task object + * + */ + virtual ~CbmTzdUnpackConfig(); + + /** @brief Copy constructor - not implemented **/ + CbmTzdUnpackConfig(const CbmTzdUnpackConfig&) = delete; + + /** @brief Assignment operator - not implemented **/ + CbmTzdUnpackConfig& operator=(const CbmTzdUnpackConfig&) = delete; + + // Getters + + /** + * @brief Initialize the algorithm, should include all steps needing te parameter objects to be present. + * In this function most initialization steps of the unpacker algorithms happen. + */ + void InitAlgo(); + + + // Setters + /** + * @brief Sets the flag enabling the epoch offset hack for the July 2021 data. Default is enable. + * + * @param[in] Optional: boolean flag value, default is true + */ + void SetFlagEpochCountHack2021(bool bFlagin = true) { fbEpochCountHack2021 = bFlagin; } + + /** + * @brief Sets the flag switching to a request of CbmMcbm2018BmonPar. Default is enable. + * + * @param[in] Optional: boolean flag value, default is true + */ + void SetFlagBmonParMode(bool bFlagin = true) { fbBmonParMode = bFlagin; } + + /** + * @brief Sets the name of the parameter file to be used. + * + * @param[in] std:string, path should not be included as set in the Config class + */ + void SetParFileName(std::string sNewName) { fsParFileName = sNewName; } + void LoadParFileName() { fAlgo->SetParFileName(fsParFileName); } + + /** @brief Add a monitor to the unpacker. @param value CbmStsUnpackMonitor */ + void SetMonitor(std::shared_ptr<CbmTofUnpackMonitor> value) { fMonitor = value; } + + /** @brief Returns the monitor of the unpacker if any. @return value CbmTofUnpackMonitor */ + std::shared_ptr<CbmTofUnpackMonitor> GetMonitor() { return fMonitor; } + +protected: + /** + * @brief Choose the derived unpacker algorithm to be used for the DAQ output to Digi translation. If algo was already set manually by the user this algorithm is used. + * + * @return Bool_t initOk + */ + virtual std::shared_ptr<CbmTzdUnpackAlgo> chooseAlgo(); + +private: + /// Control flags + bool fbEpochCountHack2021 = false; + bool fbBmonParMode = false; + /// Parameter file name + std::string fsParFileName = "mTofCriPar.par"; + + /** @brief pointer to the monitor object */ + std::shared_ptr<CbmTofUnpackMonitor> fMonitor = nullptr; + + ClassDef(CbmTzdUnpackConfig, 1) +}; + +#endif // CbmTzdUnpackConfig_H