Skip to content
Snippets Groups Projects
Commit 14758e79 authored by Dominik Smith's avatar Dominik Smith Committed by Dominik Smith
Browse files

Switched to RAII scheme in cbm::algo::tof::Hitfind.

parent 6e4a9f37
No related branches found
No related tags found
1 merge request!1485RAII scheme for TOF online algorithms.
......@@ -14,6 +14,67 @@ using fles::Subsystem;
namespace cbm::algo::tof
{
// ----- Constructor ------------------------------------------------------
Hitfind::Hitfind(tof::HitfindSetup setup)
{
//Number of SMs per super module type
fNbSm = setup.NbSm;
//Number of RPCs per super module type
fNbRpc = setup.NbRpc;
//Prepare digi storage
fStorDigi.resize(fNbSm.size());
// Create one algorithm per RPC for TOF and configure it with parametersa
for (uint32_t SmType = 0; SmType < fNbSm.size(); SmType++) {
int32_t NbSm = fNbSm[SmType];
int32_t NbRpc = fNbRpc[SmType];
fStorDigi[SmType].resize(NbSm * NbRpc);
for (int32_t Sm = 0; Sm < NbSm; Sm++) {
for (int32_t Rpc = 0; Rpc < NbRpc; Rpc++) {
std::unique_ptr<cbm::algo::tof::ClusterizerRpcPar> par(new cbm::algo::tof::ClusterizerRpcPar());
HitfindSetup::Rpc rpcPar = setup.rpcs[SmType][Sm * NbRpc + Rpc];
par->fDeadStrips = rpcPar.deadStrips;
par->fPosYMaxScal = rpcPar.posYMaxScal;
par->fdMaxTimeDist = rpcPar.maxTimeDist;
par->fdMaxSpaceDist = rpcPar.maxSpaceDist;
par->fSigVel = rpcPar.sigVel;
par->fCPTOffYBinWidth = rpcPar.CPTOffYBinWidth;
par->fCPTOffY = rpcPar.CPTOffY;
par->fCPTOffYRange = rpcPar.CPTOffYRange;
par->fTimeRes = rpcPar.timeRes;
//geometry information, can in principle be done channel-wise but not needed for now
const double* tra_ptr = rpcPar.cell.translation.data();
const double* rot_ptr = rpcPar.cell.rotation.data();
//channel parameters
int32_t NbChan = rpcPar.chanPar.size();
par->fChanPar.resize(NbChan);
for (int32_t Ch = 0; Ch < NbChan; Ch++) {
HitfindSetup::Channel chanPar = rpcPar.chanPar[Ch];
par->fChanPar[Ch].address = chanPar.address;
par->fChanPar[Ch].cell.pos = ROOT::Math::XYZVector(tra_ptr[0], tra_ptr[1], tra_ptr[2]);
par->fChanPar[Ch].cell.rotation = ROOT::Math::Rotation3D(&rot_ptr[0], &rot_ptr[9]);
par->fChanPar[Ch].cell.sizeX = rpcPar.cell.sizeX;
par->fChanPar[Ch].cell.sizeY = rpcPar.cell.sizeY;
}
fAlgo[SmType][Sm * NbRpc + Rpc].SetParams(std::move(par));
}
}
}
L_(info) << "--- Configured hitfinder algorithms for TOF.";
L_(info) << "==================================================";
}
// ----------------------------------------------------------------------------
// ----- Execution -------------------------------------------------------
Hitfind::resultType Hitfind::operator()(gsl::span<CbmTofDigi> digiIn)
{
......@@ -101,65 +162,4 @@ namespace cbm::algo::tof
}
// ----------------------------------------------------------------------------
// ----- Initialisation ---------------------------------------------------
void Hitfind::Init()
{
//Number of SMs per super module type
fNbSm = fTofConfig.NbSm;
//Number of RPCs per super module type
fNbRpc = fTofConfig.NbRpc;
//Prepare digi storage
fStorDigi.resize(fNbSm.size());
// Create one algorithm per RPC for TOF and configure it with parametersa
for (uint32_t SmType = 0; SmType < fNbSm.size(); SmType++) {
int32_t NbSm = fNbSm[SmType];
int32_t NbRpc = fNbRpc[SmType];
fStorDigi[SmType].resize(NbSm * NbRpc);
for (int32_t Sm = 0; Sm < NbSm; Sm++) {
for (int32_t Rpc = 0; Rpc < NbRpc; Rpc++) {
std::unique_ptr<cbm::algo::tof::ClusterizerRpcPar> par(new cbm::algo::tof::ClusterizerRpcPar());
HitfindSetup::Rpc rpcPar = fTofConfig.rpcs[SmType][Sm * NbRpc + Rpc];
par->fDeadStrips = rpcPar.deadStrips;
par->fPosYMaxScal = rpcPar.posYMaxScal;
par->fdMaxTimeDist = rpcPar.maxTimeDist;
par->fdMaxSpaceDist = rpcPar.maxSpaceDist;
par->fSigVel = rpcPar.sigVel;
par->fCPTOffYBinWidth = rpcPar.CPTOffYBinWidth;
par->fCPTOffY = rpcPar.CPTOffY;
par->fCPTOffYRange = rpcPar.CPTOffYRange;
par->fTimeRes = rpcPar.timeRes;
//geometry information, can in principle be done channel-wise but not needed for now
const double* tra_ptr = rpcPar.cell.translation.data();
const double* rot_ptr = rpcPar.cell.rotation.data();
//channel parameters
int32_t NbChan = rpcPar.chanPar.size();
par->fChanPar.resize(NbChan);
for (int32_t Ch = 0; Ch < NbChan; Ch++) {
HitfindSetup::Channel chanPar = rpcPar.chanPar[Ch];
par->fChanPar[Ch].address = chanPar.address;
par->fChanPar[Ch].cell.pos = ROOT::Math::XYZVector(tra_ptr[0], tra_ptr[1], tra_ptr[2]);
par->fChanPar[Ch].cell.rotation = ROOT::Math::Rotation3D(&rot_ptr[0], &rot_ptr[9]);
par->fChanPar[Ch].cell.sizeX = rpcPar.cell.sizeX;
par->fChanPar[Ch].cell.sizeY = rpcPar.cell.sizeY;
}
fAlgo[SmType][Sm * NbRpc + Rpc].SetParams(std::move(par));
}
}
}
L_(info) << "--- Configured hitfinder algorithms for TOF.";
L_(info) << "==================================================";
}
// ----------------------------------------------------------------------------
} // namespace cbm::algo::tof
......@@ -61,19 +61,12 @@ namespace cbm::algo::tof
**/
resultType operator()(gsl::span<CbmTofDigi> digiIn);
/** @brief Default constructor **/
Hitfind() {};
/** @brief Constructor **/
Hitfind(tof::HitfindSetup);
/** @brief Destructor **/
~Hitfind() {};
/** @brief Parameters for TOF hitfinders **/
tof::HitfindSetup fTofConfig {};
/** @brief Initialize hitfinder and fill parameters from config object
**/
void Init();
private: // members
/** @brief TOF hitfinders **/
std::map<uint32_t, std::map<uint32_t, tof::Clusterizer>> fAlgo = {}; //[nbType][nbSm*nbRpc]
......
......@@ -10,10 +10,8 @@ using namespace cbm::algo::tof;
void HitfinderChain::Init()
{
auto setup = config::ReadFromFile<HitfindSetup>(Opts().ParamsDir() / "TofHitfinderPar.yaml");
fHitfind = std::make_unique<Hitfind>();
fHitfind->fTofConfig = setup;
fHitfind->Init();
auto setup = config::ReadFromFile<HitfindSetup>(Opts().ParamsDir() / "TofHitfinderPar.yaml");
fHitfind = std::make_unique<Hitfind>(setup);
}
HitfinderChain::ReturnType HitfinderChain::Run(gsl::span<CbmTofDigi> digis)
......
......@@ -310,8 +310,8 @@ bool CbmTaskTofClusterizer::RegisterOutputs()
bool CbmTaskTofClusterizer::InitAlgos()
{
// Read hitfinder parameters and initialize algo
fAlgo.fTofConfig = cbm::algo::config::ReadFromFile<cbm::algo::tof::HitfindSetup>("TofHitfinderPar.yaml");
fAlgo.Init();
fAlgo = std::make_unique<cbm::algo::tof::Hitfind>(
cbm::algo::config::ReadFromFile<cbm::algo::tof::HitfindSetup>("TofHitfinderPar.yaml"));
// Read calibration parameters pass to algo
fCalibrate.fTofConfig = cbm::algo::config::ReadFromFile<cbm::algo::tof::CalibrateSetup>("TofCalibratePar.yaml");
......@@ -353,7 +353,7 @@ bool CbmTaskTofClusterizer::BuildClusters()
*fTofCalDigiVec = fCalibrate(fTofDigiVec).first;
//Call cluster finder
auto clusterOut = fAlgo(*fTofCalDigiVec);
auto clusterOut = (*fAlgo)(*fTofCalDigiVec);
auto& clusters = std::get<0>(clusterOut);
auto& indices = std::get<2>(clusterOut);
size_t indexOffset = 0;
......
......@@ -128,7 +128,7 @@ private:
bool InitAlgos();
// Hit finder algo
cbm::algo::tof::Hitfind fAlgo;
std::unique_ptr<cbm::algo::tof::Hitfind> fAlgo;
// Calibrator algo
cbm::algo::tof::Calibrate fCalibrate;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment