From b39794665d19f3323b3468df31f1ae470e307487 Mon Sep 17 00:00:00 2001 From: "s.zharko@gsi.de" <s.zharko@gsi.de> Date: Fri, 19 Apr 2024 23:48:51 +0200 Subject: [PATCH] online: moving TrackingSetup (former SetupInterface) initialization to the Reco.cxx, since it should be used by the CbmEventSelector as well to determine the TOF layer index. --- algo/CMakeLists.txt | 2 +- algo/ca/TrackingChain.cxx | 25 ++++++++++++------- algo/ca/TrackingChain.h | 9 +++++-- .../{SetupInterface.cxx => TrackingSetup.cxx} | 18 +++++++------ algo/ca/{SetupInterface.h => TrackingSetup.h} | 14 +++++------ algo/ca/core/pars/CaParameters.h | 4 +++ algo/detectors/tof/HitfindSetup.h | 2 +- algo/detectors/tof/TrackingInterface.cxx | 8 ++++-- algo/evbuild/EventbuildChain.h | 3 +++ algo/evselector/DigiEventSelector.cxx | 9 +++---- algo/evselector/DigiEventSelector.h | 6 +++++ algo/global/Reco.cxx | 8 ++++++ algo/test/_GTestDigiEventSelector.cxx | 19 ++++++++++++-- 13 files changed, 91 insertions(+), 36 deletions(-) rename algo/ca/{SetupInterface.cxx => TrackingSetup.cxx} (63%) rename algo/ca/{SetupInterface.h => TrackingSetup.h} (86%) diff --git a/algo/CMakeLists.txt b/algo/CMakeLists.txt index 9db6cc5d37..181d7caa6e 100644 --- a/algo/CMakeLists.txt +++ b/algo/CMakeLists.txt @@ -146,7 +146,7 @@ set(SRCS qa/PadConfig.cxx qa/QaData.cxx qa/unpack/StsDigiQa.cxx - ca/SetupInterface.cxx + ca/TrackingSetup.cxx ca/TrackingChain.cxx ca/qa/CaInputQa.cxx ca/qa/CaOutputQa.cxx diff --git a/algo/ca/TrackingChain.cxx b/algo/ca/TrackingChain.cxx index 7c2f7679c2..50c8d9de1e 100644 --- a/algo/ca/TrackingChain.cxx +++ b/algo/ca/TrackingChain.cxx @@ -49,9 +49,10 @@ TrackingChain::TrackingChain(std::shared_ptr<HistogramSender> histoSender) // void TrackingChain::Init() { - // ------ Initialize setup interface - fSetup.SetContext(this->GetContext()); - fSetup.Init(); + if (fpSetup.get() == nullptr) { + throw std::runtime_error("Tracking Chain: TrackingSetup object was not registered"); + } + // ------ Read tracking chain parameters from the config fConfig = yaml::ReadFromFile<TrackingChainConfig>(Opts().ParamsDir() / "TrackingChainConfig.yaml"); @@ -75,6 +76,11 @@ void TrackingChain::Init() auto parameters = manager.TakeParameters(); L_(info) << "Tracking Chain: parameters object: \n" << parameters.ToString(1) << '\n'; + // ------ Used detector subsystem flags + fbDetUsed.fill(false); + fbDetUsed[EDetectorID::Sts] = Opts().Has(fles::Subsystem::STS) && parameters.IsActive(EDetectorID::Sts); + fbDetUsed[EDetectorID::Tof] = Opts().Has(fles::Subsystem::TOF) && parameters.IsActive(EDetectorID::Tof); + // ------ Initialize CA framework fCaMonitor.Reset(); fCaFramework.SetNofThreads(Opts().NumOMPThreads() == std::nullopt ? 1 : *(Opts().NumOMPThreads())); @@ -138,8 +144,12 @@ void TrackingChain::PrepareInput(Input_t recoResults) fCaDataManager.ResetInputData(nHitsTot); faHitExternalIndices.clear(); faHitExternalIndices.reserve(nHitsTot); - ReadHits<EDetectorID::Sts>(recoResults.stsHits); - ReadHits<EDetectorID::Tof>(recoResults.tofHits); + if (fbDetUsed[EDetectorID::Sts]) { + ReadHits<EDetectorID::Sts>(recoResults.stsHits); + } + if (fbDetUsed[EDetectorID::Tof]) { + ReadHits<EDetectorID::Tof>(recoResults.tofHits); + } faHitExternalIndices.shrink_to_fit(); fCaDataManager.SetNhitKeys(fNofHitKeys); L_(info) << "Tracking chain:" << fCaDataManager.GetNofHits() << " hits will be passed to the ca::Framework"; @@ -255,10 +265,7 @@ void TrackingChain::ReadHits(PartitionedSpan<const ca::HitTypes_t::at<DetID>> hi iStLocal = (extHitAddress >> 4) & 0xF; } if constexpr (IsTof) { - iStLocal = fSetup.GetTrackingStation<DetID>(extHitAddress); - if (tof::Config::IsBmon(extHitAddress)) { - continue; - } // skip hits from Bmon + iStLocal = fpSetup->GetTrackingStation<DetID>(extHitAddress); } int iStActive = (iStLocal != -1) ? fCaFramework.GetParameters().GetStationIndexActive(iStLocal, DetID) : -1; diff --git a/algo/ca/TrackingChain.h b/algo/ca/TrackingChain.h index 6f04c432c9..d6ec739a6e 100644 --- a/algo/ca/TrackingChain.h +++ b/algo/ca/TrackingChain.h @@ -19,10 +19,10 @@ #include "HistogramSender.h" #include "PartitionedSpan.h" #include "RecoResults.h" -#include "SetupInterface.h" #include "SubChain.h" #include "TrackingChainConfig.h" #include "TrackingDefs.h" +#include "TrackingSetup.h" #include "sts/Hit.h" #include "tof/Hit.h" @@ -72,6 +72,9 @@ namespace cbm::algo /// \brief Provides action in the initialization of the run void Init(); + /// \brief Registers tracking setup + void RegisterSetup(std::shared_ptr<TrackingSetup> pSetup) { fpSetup = pSetup; } + /// \brief Provides action for a given time-slice /// \param recoResults Structure of reconstruction results /// \return A pair (vector of tracks, tracking monitor) @@ -108,7 +111,9 @@ namespace cbm::algo ca::InputQa fInputQa; ///< CA input QA builder ca::OutputQa fOutputQa; ///< CA output QA builder - SetupInterface fSetup; ///< setup interface + std::shared_ptr<TrackingSetup> fpSetup = nullptr; ///< setup interface + + ca::DetIdArray_t<bool> fbDetUsed; ///< Flags of detector subsystems used in tracking // ************************ // ** Auxilary variables diff --git a/algo/ca/SetupInterface.cxx b/algo/ca/TrackingSetup.cxx similarity index 63% rename from algo/ca/SetupInterface.cxx rename to algo/ca/TrackingSetup.cxx index 566330e712..168b93f23c 100644 --- a/algo/ca/SetupInterface.cxx +++ b/algo/ca/TrackingSetup.cxx @@ -2,20 +2,24 @@ SPDX-License-Identifier: GPL-3.0-only Authors: Sergei Zharko [committer] */ -/// \file SetupInterface.h +/// \file TrackingSetup.h /// \date 19.04.2024 /// \brief A detector setup interface used for tracking input data initialization (source) /// \author Sergei Zharko <s.zharko@gsi.de> -#include "SetupInterface.h" +#include "TrackingSetup.h" -using cbm::algo::SetupInterface; +#include "Definitions.h" + +using cbm::algo::TrackingSetup; +using fles::Subsystem; // --------------------------------------------------------------------------------------------------------------------- // -void SetupInterface::Init() +void TrackingSetup::Init() { - - fTof.SetContext(this->GetContext()); - fTof.Init(); + if (Opts().Has(Subsystem::TOF)) { + fTof.SetContext(this->GetContext()); + fTof.Init(); + } } diff --git a/algo/ca/SetupInterface.h b/algo/ca/TrackingSetup.h similarity index 86% rename from algo/ca/SetupInterface.h rename to algo/ca/TrackingSetup.h index cb80c33021..3e090dc006 100644 --- a/algo/ca/SetupInterface.h +++ b/algo/ca/TrackingSetup.h @@ -2,7 +2,7 @@ SPDX-License-Identifier: GPL-3.0-only Authors: Sergei Zharko [committer] */ -/// \file SetupInterface.h +/// \file TrackingSetup.h /// \date 19.04.2024 /// \brief A detector setup interface used for tracking input data initialization (header) /// \author Sergei Zharko <s.zharko@gsi.de> @@ -19,9 +19,9 @@ namespace cbm::algo { - /// \class SetupInterface + /// \class TrackingSetup /// \brief A detector setup interface class for tracking input data initialization - class SetupInterface : public SubChain { + class TrackingSetup : public SubChain { private: /// \brief A helper temporary function to enable a method for a given detector subsystem template<ca::EDetectorID DetID> @@ -32,16 +32,16 @@ namespace cbm::algo public: /// \brief Default constructor - SetupInterface() = default; + TrackingSetup() = default; /// \brief Copy constructor - SetupInterface(const SetupInterface&) = delete; + TrackingSetup(const TrackingSetup&) = delete; /// \brief Move constructor - SetupInterface(SetupInterface&&) = delete; + TrackingSetup(TrackingSetup&&) = delete; /// \brief Destructor - ~SetupInterface() = default; + ~TrackingSetup() = default; /// \brief Initializer function void Init(); diff --git a/algo/ca/core/pars/CaParameters.h b/algo/ca/core/pars/CaParameters.h index 8831beb334..a7809c1155 100644 --- a/algo/ca/core/pars/CaParameters.h +++ b/algo/ca/core/pars/CaParameters.h @@ -305,6 +305,10 @@ namespace cbm::algo::ca /// \brief Provides access to the misalignment of the detector systems in Time const std::array<float, constants::size::MaxNdetectors> GetMisalignmentT() const { return fMisalignmentT; } + /// \brief Checks, if the detector subsystem active + /// \param detId Detector ID + bool IsActive(EDetectorID detId) const { return GetNstationsActive(detId) != 0; } + /// \brief Class invariant checker void CheckConsistency() const; diff --git a/algo/detectors/tof/HitfindSetup.h b/algo/detectors/tof/HitfindSetup.h index ebbdad71b8..c3138ad7d3 100644 --- a/algo/detectors/tof/HitfindSetup.h +++ b/algo/detectors/tof/HitfindSetup.h @@ -47,7 +47,7 @@ namespace cbm::algo::tof double sigVel; double timeRes; Cell cell; - int trackingStationId; + i32 trackingStationId; double CPTOffYBinWidth; double CPTOffYRange; std::vector<double> CPTOffY; diff --git a/algo/detectors/tof/TrackingInterface.cxx b/algo/detectors/tof/TrackingInterface.cxx index a669b2dcca..87d65119d5 100644 --- a/algo/detectors/tof/TrackingInterface.cxx +++ b/algo/detectors/tof/TrackingInterface.cxx @@ -48,8 +48,12 @@ void TrackingInterface::Init() int TrackingInterface::GetTrackingStation(uint32_t address) const { int iSmType = CbmTofAddress::GetSmType(address); - int iSm = CbmTofAddress::GetSmId(address); - int iRpc = CbmTofAddress::GetRpcId(address); + if (5 == iSmType) { + return -1; // Bmon hit + } + + int iSm = CbmTofAddress::GetSmId(address); + int iRpc = CbmTofAddress::GetRpcId(address); if (iSmType < fvNofSm.size()) { if (iSm < fvNofSm[iSmType] && iRpc < fvNofRpc[iSmType]) { return fvTrackingStationId[iSmType][iSm * fvNofRpc[iSmType] + iRpc]; diff --git a/algo/evbuild/EventbuildChain.h b/algo/evbuild/EventbuildChain.h index 15bac22c69..5c9c6c1709 100644 --- a/algo/evbuild/EventbuildChain.h +++ b/algo/evbuild/EventbuildChain.h @@ -57,6 +57,9 @@ namespace cbm::algo::evbuild /** @brief Status info to logger **/ void Status() const; + /** @brief Registers tracking setup **/ + void RegisterTrackingSetup(std::shared_ptr<TrackingSetup> pSetup) { fSelector.RegisterTrackingSetup(pSetup); } + private: // members ECbmModuleId fTriggerDet = ECbmModuleId::kNotExist; ///< Trigger detector TimeClusterTrigger fTrigger; ///< Trigger algorithm diff --git a/algo/evselector/DigiEventSelector.cxx b/algo/evselector/DigiEventSelector.cxx index 96aa65f083..a8626aac73 100644 --- a/algo/evselector/DigiEventSelector.cxx +++ b/algo/evselector/DigiEventSelector.cxx @@ -6,7 +6,6 @@ #include "AlgoFairloggerCompat.h" #include "CbmStsDigi.h" -#include "tof/Config.h" #include <gsl/span> #include <iterator> @@ -109,10 +108,10 @@ namespace cbm::algo::evbuild if (digi.GetSide() != strip->second) { // Found other end => full strip, insert into counter set const int32_t rpcAddr = CbmTofAddress::GetRpcFullId(digiAddr); if (rpcs.count(rpcAddr) == 0) { // new RPC activated - const int32_t smId = CbmTofAddress::GetSmId(digiAddr); // Super-module ID - const int32_t smType = CbmTofAddress::GetSmType(digiAddr); // Super-module type - const int32_t rpcId = CbmTofAddress::GetRpcId(digiAddr); // RPC ID - const int32_t TofStationId = tof::Config::GetTofTrackingStation(smType, smId, rpcId); + const int32_t TofStationId = fpTrackingSetup->GetTrackingStation<ca::EDetectorID::Tof>(digiAddr); + if (TofStationId < 0) { + continue; + } // unused tracking station (BMON) stations.insert(TofStationId); if (stations.size() == minNum) break; } diff --git a/algo/evselector/DigiEventSelector.h b/algo/evselector/DigiEventSelector.h index d017cac7fa..a8ba4d7a95 100644 --- a/algo/evselector/DigiEventSelector.h +++ b/algo/evselector/DigiEventSelector.h @@ -7,6 +7,7 @@ #include "DigiData.h" #include "DigiEventSelectorConfig.h" +#include "TrackingSetup.h" #include <cstdint> #include <gsl/span> @@ -48,6 +49,10 @@ namespace cbm::algo::evbuild **/ bool operator()(const DigiEvent& event) const; + /** @brief Registers tracking setup + ** @param pSetup The tracking setup instance + **/ + void RegisterTrackingSetup(std::shared_ptr<TrackingSetup> pSetup) { fpTrackingSetup = pSetup; } /** @brief Info to string **/ std::string ToString() const; @@ -71,6 +76,7 @@ namespace cbm::algo::evbuild private: // members DigiEventSelectorConfig fConfig; ///< Configuration / parameters + std::shared_ptr<TrackingSetup> fpTrackingSetup = nullptr; ///< Tracking setup (access to stations info) }; } // namespace cbm::algo::evbuild diff --git a/algo/global/Reco.cxx b/algo/global/Reco.cxx index a935c3e1f3..56865335c7 100644 --- a/algo/global/Reco.cxx +++ b/algo/global/Reco.cxx @@ -9,6 +9,7 @@ #include "Exceptions.h" #include "HistogramSender.h" #include "StsDigiQa.h" +#include "TrackingSetup.h" #include "bmon/Unpack.h" #include "ca/TrackingChain.h" #include "compat/OpenMP.h" @@ -151,11 +152,17 @@ void Reco::Init(const Options& opts) fTrd2dUnpack = std::make_unique<trd2d::Unpack>(cfg); } + // --- Tracking setup + auto pTrackingSetup = std::make_shared<TrackingSetup>(); + pTrackingSetup->SetContext(&fContext); + pTrackingSetup->Init(); + // --- Event building if (Opts().Has(Step::DigiTrigger)) { fs::path configFile = opts.ParamsDir() / "EventbuildConfig.yaml"; evbuild::Config config(YAML::LoadFile(configFile.string())); fEventBuild = std::make_unique<evbuild::EventbuildChain>(config, fSender); + fEventBuild->RegisterTrackingSetup(pTrackingSetup); } // STS Hitfinder @@ -185,6 +192,7 @@ void Reco::Init(const Options& opts) // Tracking if (Opts().Has(Step::Tracking)) { fTracking = std::make_unique<TrackingChain>(fSender); + fTracking->RegisterSetup(pTrackingSetup); fTracking->SetContext(&fContext); fTracking->Init(); } diff --git a/algo/test/_GTestDigiEventSelector.cxx b/algo/test/_GTestDigiEventSelector.cxx index 32a8ae5a54..ebe68eabde 100644 --- a/algo/test/_GTestDigiEventSelector.cxx +++ b/algo/test/_GTestDigiEventSelector.cxx @@ -6,7 +6,6 @@ #include "DigiEventSelectorConfig.h" #include "gtest/gtest-spi.h" #include "gtest/gtest.h" -#include "tof/Config.h" #include <unordered_set> @@ -197,6 +196,17 @@ TEST(_GTestDigiEventSelector, CheckDigiEventSelectorAlgorithmSimple) const uint8_t numSmTypes = 10; const uint8_t numRpc[numSmTypes] = {5, 3, 5, 1, 1, 1, 2, 2, 1, 2}; const uint8_t numSm[numSmTypes] = {5, 0, 1, 0, 0, 1, 1, 1, 2, 1}; + std::vector<std::vector<uint8_t>> trkStationId = { + {0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 3, 3, 3, 3, 3, 0, 0, 0, 0, 0, 3, 3, 3, 3, 3}, + {0, 0, 0, 0, 0}, + {2, 2, 2, 2, 2}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {1, 1, 0, 0, 0}, + {1, 1, 0, 0, 0}, + {0, 0, 0, 0, 0}, + {2, 2, 2, 2, 0}}; std::unordered_set<int32_t> setTofStation; for (uint smType = 0; smType < numSmTypes; smType++) { @@ -208,7 +218,12 @@ TEST(_GTestDigiEventSelector, CheckDigiEventSelectorAlgorithmSimple) eventIn.fTof.push_back(CbmTofDigi(addrFront, 0.0, 0.0)); eventIn.fTof.push_back(CbmTofDigi(addrBack, 0.0, 0.0)); - const int32_t TofStationId = cbm::algo::tof::Config::GetTofTrackingStation(smType, sm, rpc); + int32_t TofStationId = -1; + if (smType < numSmTypes) { + if (sm < numSm[smType] && rpc < numRpc[smType]) { + TofStationId = trkStationId[smType][sm * numRpc[smType] + rpc]; + } + } setTofStation.insert(TofStationId); YAML::Node node2; -- GitLab