diff --git a/algo/detectors/tof/Calibrate.cxx b/algo/detectors/tof/Calibrate.cxx index d283475abd2eefffe7b0836e396b14fae63438d7..944677547755d5936384815daded940795d6f88e 100644 --- a/algo/detectors/tof/Calibrate.cxx +++ b/algo/detectors/tof/Calibrate.cxx @@ -46,8 +46,8 @@ namespace cbm::algo::tof continue; } - HitfindSetup::RpcCal& rpcPar = fTofConfig.rpccal.at(SmType).at(Sm * NbRpc + Rpc); - HitfindSetup::ChanCal& chanPar = rpcPar.chanPar[Chan]; + CalibrateSetup::Rpc& rpcPar = fTofConfig.rpcs.at(SmType).at(Sm * NbRpc + Rpc); + CalibrateSetup::Channel& chanPar = rpcPar.chanPar[Chan]; if (rpcPar.swapChannelSides && 5 != SmType && 8 != SmType) { pDigi.SetAddress(Sm, Rpc, Chan, (0 == Side) ? 1 : 0, SmType); diff --git a/algo/detectors/tof/Calibrate.h b/algo/detectors/tof/Calibrate.h index 1e3f2b3a7d081062a65369fcf2e5ef16c2aa7643..5703fcba2d0ec976a2e22469ea1574ce19092953 100644 --- a/algo/detectors/tof/Calibrate.h +++ b/algo/detectors/tof/Calibrate.h @@ -7,8 +7,8 @@ #include "CbmTofDigi.h" +#include "tof/CalibrateSetup.h" #include "tof/Clusterizer.h" -#include "tof/HitfindSetup.h" #include <gsl/span> #include <optional> @@ -66,7 +66,7 @@ namespace cbm::algo::tof ~Calibrate() {}; /** @brief Parameters for TOF hitfinders **/ - tof::HitfindSetup fTofConfig {}; + tof::CalibrateSetup fTofConfig {}; private: // members }; diff --git a/algo/detectors/tof/CalibrateSetup.h b/algo/detectors/tof/CalibrateSetup.h new file mode 100644 index 0000000000000000000000000000000000000000..fca2b4097b9dfc1c1a9d47d67cec8bb76713b06e --- /dev/null +++ b/algo/detectors/tof/CalibrateSetup.h @@ -0,0 +1,65 @@ +/* Copyright (C) 2023 Facility for Antiproton and Ion Research in Europe, Darmstadt + SPDX-License-Identifier: GPL-3.0-only + Authors: Dominik Smith [committer] */ +#ifndef CBM_ALGO_DETECTOR_TOF_CALIBRATE_SETUP_H +#define CBM_ALGO_DETECTOR_TOF_CALIBRATE_SETUP_H + +#include <array> +#include <map> +#include <string> +#include <vector> + +#include "Definitions.h" +#include "config/Property.h" + +namespace cbm::algo::tof +{ + /** + * @brief TOF calibration setup + */ + struct CalibrateSetup { + + struct Channel { + std::vector<double> vCPTOff; + std::vector<double> vCPTotGain; + std::vector<double> vCPTotOff; + std::vector<std::vector<double>> vCPWalk; + + static constexpr auto Properties = + std::make_tuple(config::Property(&Channel::vCPTOff, "vCPTOff", "CPT offset"), + config::Property(&Channel::vCPTotGain, "vCPTotGain", "CP time over threshold gain"), + config::Property(&Channel::vCPTotOff, "vCPTotOff", "CP time over threshold offset"), + config::Property(&Channel::vCPWalk, "vCPWalk", "CP walk correction", YAML::Block, YAML::Flow)); + }; + + struct Rpc { + i32 numClWalkBinX; + double TOTMax; + double TOTMin; + bool swapChannelSides; + double channelDeadtime; + std::vector<Channel> chanPar; + + static constexpr auto Properties = + std::make_tuple(config::Property(&Rpc::numClWalkBinX, "numClWalkBinX", "number of walk correction bins"), + config::Property(&Rpc::TOTMax, "TOTMax", "maximum time over threshold"), + config::Property(&Rpc::TOTMin, "TOTMin", "minimum time over threshold"), + config::Property(&Rpc::swapChannelSides, "swapChannelSides", "flag for swapping channel sides"), + config::Property(&Rpc::channelDeadtime, "channelDeadtime", "channel dead time"), + config::Property(&Rpc::chanPar, "chanPar", "channel parameters")); + }; + + /* Members */ + std::vector<int32_t> NbSm; + std::vector<int32_t> NbRpc; + std::vector<std::vector<Rpc>> rpcs; + + static constexpr auto Properties = std::make_tuple( + config::Property(&CalibrateSetup::NbSm, "NbSm", "Number of SMs per super module type", {}, YAML::Flow), + config::Property(&CalibrateSetup::NbRpc, "NbRpc", "Number of RPCs per super module type", {}, YAML::Flow), + config::Property(&CalibrateSetup::rpcs, "rpcs", "Parameters of RPCs")); + }; + +} // namespace cbm::algo::tof + +#endif // CBM_ALGO_DETECTOR_TOF_CALIBRATE_SETUP_H diff --git a/algo/detectors/tof/CalibratorChain.cxx b/algo/detectors/tof/CalibratorChain.cxx index 6d1b30d4894fce6d5d1297981cb14f2b4be59058..f6f422ff0a24c4f55366874aa78d502dfa4c52e8 100644 --- a/algo/detectors/tof/CalibratorChain.cxx +++ b/algo/detectors/tof/CalibratorChain.cxx @@ -10,7 +10,7 @@ using namespace cbm::algo::tof; void CalibratorChain::Init() { - auto setup = config::ReadFromFile<HitfindSetup>(Opts().ParamsDir() / "TofHitfinderPar.yaml"); + auto setup = config::ReadFromFile<CalibrateSetup>(Opts().ParamsDir() / "TofCalibratePar.yaml"); fCalibrate = std::make_unique<Calibrate>(); fCalibrate->fTofConfig = setup; } diff --git a/algo/detectors/tof/CalibratorChain.h b/algo/detectors/tof/CalibratorChain.h index e22780d3cad4964177461437a3039b47f8e0e7ba..0038eed952b89a1007ebbb1ab791600e18c944f0 100644 --- a/algo/detectors/tof/CalibratorChain.h +++ b/algo/detectors/tof/CalibratorChain.h @@ -9,7 +9,7 @@ #include <memory> #include "Calibrate.h" -#include "HitfindSetup.h" +#include "CalibrateSetup.h" #include "SubChain.h" namespace cbm::algo::tof diff --git a/algo/detectors/tof/HitfindSetup.h b/algo/detectors/tof/HitfindSetup.h index e24ce81be88500cadc61b92532d766ccaf815c90..ec4ff329c363decbfa63f9ecf7cd868dfa2816a5 100644 --- a/algo/detectors/tof/HitfindSetup.h +++ b/algo/detectors/tof/HitfindSetup.h @@ -21,8 +21,6 @@ namespace cbm::algo::tof */ struct HitfindSetup { - /* Hitfinding parameters */ - struct Cell { double sizeX; double sizeY; @@ -38,8 +36,9 @@ namespace cbm::algo::tof struct Channel { i32 address; + static constexpr auto Properties = - std::make_tuple(config::Property(&Channel::address, "address", "unique address")); + std::make_tuple(config::Property(&Channel::address, "address", "unique address", YAML::Hex)); }; struct Rpc { @@ -69,50 +68,14 @@ namespace cbm::algo::tof config::Property(&Rpc::chanPar, "chanPar", "channel parameters")); }; - /* Calibration parameters */ - - struct ChanCal { - std::vector<double> vCPTOff; - std::vector<double> vCPTotGain; - std::vector<double> vCPTotOff; - std::vector<std::vector<double>> vCPWalk; - - static constexpr auto Properties = - std::make_tuple(config::Property(&ChanCal::vCPTOff, "vCPTOff", "CPT offset"), - config::Property(&ChanCal::vCPTotGain, "vCPTotGain", "CP time over threshold gain"), - config::Property(&ChanCal::vCPTotOff, "vCPTotOff", "CP time over threshold offset"), - config::Property(&ChanCal::vCPWalk, "vCPWalk", "CP walk correction", YAML::Flow)); - }; - - struct RpcCal { - i32 numClWalkBinX; - double TOTMax; - double TOTMin; - bool swapChannelSides; - double channelDeadtime; - std::vector<ChanCal> chanPar; - - static constexpr auto Properties = std::make_tuple( - config::Property(&RpcCal::numClWalkBinX, "numClWalkBinX", "number of walk correction bins"), - config::Property(&RpcCal::TOTMax, "TOTMax", "maximum time over threshold"), - config::Property(&RpcCal::TOTMin, "TOTMin", "minimum time over threshold"), - config::Property(&RpcCal::swapChannelSides, "swapChannelSides", "flag for swapping channel sides"), - config::Property(&RpcCal::channelDeadtime, "channelDeadtime", "channel dead time"), - config::Property(&RpcCal::chanPar, "chanPar", "channel parameters")); - }; - - /* Members */ - - std::vector<std::vector<Rpc>> rpcs; - std::vector<std::vector<RpcCal>> rpccal; std::vector<int32_t> NbSm; std::vector<int32_t> NbRpc; + std::vector<std::vector<Rpc>> rpcs; static constexpr auto Properties = std::make_tuple( - config::Property(&HitfindSetup::rpcs, "rpcs", "Parameters of RPCs"), - config::Property(&HitfindSetup::rpccal, "rpccal", "Calibration parameters of RPCs"), config::Property(&HitfindSetup::NbSm, "NbSm", "Number of SMs per super module type", {}, YAML::Flow), - config::Property(&HitfindSetup::NbRpc, "NbRpc", "Number of RPCs per super module type", {}, YAML::Flow)); + config::Property(&HitfindSetup::NbRpc, "NbRpc", "Number of RPCs per super module type", {}, YAML::Flow), + config::Property(&HitfindSetup::rpcs, "rpcs", "Parameters of RPCs")); }; diff --git a/reco/tasks/CbmTaskTofClusterizer.cxx b/reco/tasks/CbmTaskTofClusterizer.cxx index f750fa4b9a66ef4f5f349b303f7c6ac3f666ab45..bdfd3ff575eff48504dfc30afac836bf7549bd1c 100644 --- a/reco/tasks/CbmTaskTofClusterizer.cxx +++ b/reco/tasks/CbmTaskTofClusterizer.cxx @@ -190,7 +190,7 @@ void CbmTaskTofClusterizer::Exec(Option_t* option) const CbmTofDigi* tDigi = fDigiMan->Get<CbmTofDigi>(iDigi); fTofDigiVec.push_back(CbmTofDigi(*tDigi)); - // if (iDigi == 10000) break; // Only use 10000 digis for now. D.Smith + //if (iDigi == 10000) break; // Only use 10000 digis for now. D.Smith } ExecEvent(option); } @@ -310,11 +310,12 @@ bool CbmTaskTofClusterizer::RegisterOutputs() bool CbmTaskTofClusterizer::InitAlgos() { // Read hitfinder parameters and initialize algo - cbm::algo::fs::path paramsPath = "TofHitfinderPar.yaml"; - YAML::Node yaml = YAML::LoadFile(paramsPath.string()); - fAlgo.fTofConfig = cbm::algo::config::Read<cbm::algo::tof::HitfindSetup>(yaml); - fCalibrate.fTofConfig = cbm::algo::config::Read<cbm::algo::tof::HitfindSetup>(yaml); + fAlgo.fTofConfig = cbm::algo::config::ReadFromFile<cbm::algo::tof::HitfindSetup>("TofHitfinderPar.yaml"); fAlgo.Init(); + + // Read calibration parameters pass to algo + fCalibrate.fTofConfig = cbm::algo::config::ReadFromFile<cbm::algo::tof::CalibrateSetup>("TofCalibratePar.yaml"); + return true; } diff --git a/reco/tasks/CbmTaskTofClusterizerParWrite.cxx b/reco/tasks/CbmTaskTofClusterizerParWrite.cxx index 03b75d98c80b67d7c495ef2e34aac2f22001e644..0908c7422948a56f50a6b2b6966733f5c171fddf 100644 --- a/reco/tasks/CbmTaskTofClusterizerParWrite.cxx +++ b/reco/tasks/CbmTaskTofClusterizerParWrite.cxx @@ -22,6 +22,7 @@ #include "FairRuntimeDb.h" #include <Logger.h> +#include "tof/CalibrateSetup.h" #include "tof/HitfindSetup.h" #include "config/Yaml.h" @@ -420,26 +421,23 @@ bool CbmTaskTofClusterizerParWrite::InitAlgos() detIdIndexMap[iUniqueId] = ind; } - cbm::algo::tof::HitfindSetup setup; + /* Hitfinding parameters */ + cbm::algo::tof::HitfindSetup setup; setup.rpcs.resize(iNbSmTypes); - setup.rpccal.resize(iNbSmTypes); - // Create one algorithm per RPC and configure it with parameters for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) { + int32_t iNbSm = fDigiBdfPar->GetNbSm(iSmType); int32_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType); setup.NbSm.push_back(iNbSm); setup.NbRpc.push_back(iNbRpc); setup.rpcs[iSmType].resize(iNbSm * iNbRpc); - setup.rpccal[iSmType].resize(iNbSm * iNbRpc); for (int32_t iSm = 0; iSm < iNbSm; iSm++) { for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) { - /* Hitfinding parameters */ - cbm::algo::tof::HitfindSetup::Rpc par; /* Cell geometry for hitfinding (can in principle be set channel-wise but is not needed for now) */ @@ -452,14 +450,13 @@ bool CbmTaskTofClusterizerParWrite::InitAlgos() gGeoManager->FindNode(channelInfo->GetX(), channelInfo->GetY(), channelInfo->GetZ()); const double* tra_ptr = gGeoManager->MakePhysicalNode()->GetMatrix()->GetTranslation(); const double* rot_ptr = gGeoManager->GetCurrentMatrix()->GetRotationMatrix(); - memcpy(par.cell.translation.data(), tra_ptr, 3 * sizeof(double)); memcpy(par.cell.rotation.data(), rot_ptr, 9 * sizeof(double)); par.cell.sizeX = channelInfo->GetSizex(); par.cell.sizeY = channelInfo->GetSizey(); - /* Other fitfinding parameters */ + /* Other hitfinding parameters */ const int32_t iDetId = CbmTofAddress::GetUniqueAddress(iSm, iRpc, 0, 0, iSmType); const int32_t iDetIndx = detIdIndexMap[iDetId]; @@ -473,47 +470,68 @@ bool CbmTaskTofClusterizerParWrite::InitAlgos() par.CPTOffY = fvCPTOffY[iSmType][iSm * iNbRpc + iRpc]; par.CPTOffYRange = fvCPTOffYRange[iSmType][iSm * iNbRpc + iRpc]; - /* Calibration paramters */ - - cbm::algo::tof::HitfindSetup::RpcCal parCal; - - parCal.numClWalkBinX = nbClWalkBinX; - parCal.TOTMax = fdTOTMax; - parCal.TOTMin = fdTOTMin; - parCal.swapChannelSides = fbSwapChannelSides; - parCal.channelDeadtime = fdChannelDeadtime; - int32_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc); par.chanPar.resize(iNbChan); - parCal.chanPar.resize(iNbChan); for (int32_t iCh = 0; iCh < iNbChan; iCh++) { + cbm::algo::tof::HitfindSetup::Channel& chan = par.chanPar[iCh]; - /* Hitfinding parameters */ + const int32_t address = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType); + chan.address = address; + } + setup.rpcs[iSmType][iSm * iNbRpc + iRpc] = par; + } + } + } - cbm::algo::tof::HitfindSetup::Channel& chan = par.chanPar[iCh]; - const int32_t address = CbmTofAddress::GetUniqueAddress(iSm, iRpc, iCh, 0, iSmType); - chan.address = address; + /* Calibration parameters */ - /* Calibration paramters */ + cbm::algo::tof::CalibrateSetup calib; + calib.rpcs.resize(iNbSmTypes); - cbm::algo::tof::HitfindSetup::ChanCal& chanCal = parCal.chanPar[iCh]; + for (int32_t iSmType = 0; iSmType < iNbSmTypes; iSmType++) { + int32_t iNbSm = fDigiBdfPar->GetNbSm(iSmType); + int32_t iNbRpc = fDigiBdfPar->GetNbRpc(iSmType); + calib.NbSm.push_back(iNbSm); + calib.NbRpc.push_back(iNbRpc); + calib.rpcs[iSmType].resize(iNbSm * iNbRpc); + + for (int32_t iSm = 0; iSm < iNbSm; iSm++) { + for (int32_t iRpc = 0; iRpc < iNbRpc; iRpc++) { + + cbm::algo::tof::CalibrateSetup::Rpc par; + par.numClWalkBinX = nbClWalkBinX; + par.TOTMax = fdTOTMax; + par.TOTMin = fdTOTMin; + par.swapChannelSides = fbSwapChannelSides; + par.channelDeadtime = fdChannelDeadtime; - chanCal.vCPTOff = fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh]; - chanCal.vCPTotGain = fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh]; - chanCal.vCPTotOff = fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh]; - chanCal.vCPWalk = fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh]; + int32_t iNbChan = fDigiBdfPar->GetNbChan(iSmType, iRpc); + par.chanPar.resize(iNbChan); + + for (int32_t iCh = 0; iCh < iNbChan; iCh++) { + cbm::algo::tof::CalibrateSetup::Channel& chan = par.chanPar[iCh]; + + chan.vCPTOff = fvCPTOff[iSmType][iSm * iNbRpc + iRpc][iCh]; + chan.vCPTotGain = fvCPTotGain[iSmType][iSm * iNbRpc + iRpc][iCh]; + chan.vCPTotOff = fvCPTotOff[iSmType][iSm * iNbRpc + iRpc][iCh]; + chan.vCPWalk = fvCPWalk[iSmType][iSm * iNbRpc + iRpc][iCh]; } - setup.rpcs[iSmType][iSm * iNbRpc + iRpc] = par; - setup.rpccal[iSmType][iSm * iNbRpc + iRpc] = parCal; + calib.rpcs[iSmType][iSm * iNbRpc + iRpc] = par; } } } + /* Write Yaml files */ + cbm::algo::config::Dump dump; std::ofstream fout("TofHitfinderPar.yaml"); fout << dump(setup); fout.close(); + std::ofstream fcalout("TofCalibratePar.yaml"); + fcalout << dump(calib); + fcalout.close(); + return true; }