Skip to content
Snippets Groups Projects

Separated TOF calibration from hitfinding. Integrated new calibrator class into cbm::algo::Reco.

Merged Dominik Smith requested to merge d.smith/cbmroot:TofCalibrate into master
Files
13
+ 104
0
/* Copyright (C) 2023 Facility for Antiproton and Ion Research in Europe, Darmstadt
SPDX-License-Identifier: GPL-3.0-only
Authors: Dominik Smith [committer] */
#include "Calibrate.h"
#include <chrono>
#include "log.hpp"
#include "util/TimingsFormat.h"
using namespace std;
using fles::Subsystem;
namespace cbm::algo::tof
{
// ----- Execution -------------------------------------------------------
Calibrate::resultType Calibrate::operator()(gsl::span<const CbmTofDigi> digiIn)
{
xpu::push_timer("TofCalibrate");
xpu::t_add_bytes(digiIn.size_bytes());
// --- Output data
resultType result = {};
auto& calDigiOut = result.first;
auto& monitor = result.second;
calDigiOut.reserve(digiIn.size());
// channel deadtime map
std::map<int32_t, double> mChannelDeadTime;
for (size_t iDigi = 0; iDigi < digiIn.size(); iDigi++) {
CbmTofDigi pDigi = digiIn[iDigi];
const double SmType = pDigi.GetType();
const double Sm = pDigi.GetSm();
const double Rpc = pDigi.GetRpc();
const double Chan = pDigi.GetChannel();
const double Side = pDigi.GetSide();
const int NbRpc = fTofConfig.NbRpc[SmType];
auto& rpcs = fTofConfig.rpcs;
if (SmType >= rpcs.size() || Sm * NbRpc + Rpc >= rpcs.at(SmType).size()) {
monitor.fDigiCalibUnknownRPC++;
continue;
}
HitfindSetup::Rpc& rpcPar = fTofConfig.rpcs.at(SmType).at(Sm * NbRpc + Rpc);
HitfindSetup::Channel& chanPar = rpcPar.chanPar[Chan];
if (rpcPar.swapChannelSides && 5 != SmType && 8 != SmType) {
pDigi.SetAddress(Sm, Rpc, Chan, (0 == Side) ? 1 : 0, SmType);
}
// Check dead time
const int32_t iAddr = pDigi.GetAddress();
auto it = mChannelDeadTime.find(iAddr);
if (it != mChannelDeadTime.end() && pDigi.GetTime() <= it->second) {
it->second = pDigi.GetTime() + rpcPar.channelDeadtime;
continue;
}
mChannelDeadTime[iAddr] = pDigi.GetTime() + rpcPar.channelDeadtime;
// Create calibrated digi
CbmTofDigi pCalDigi(pDigi);
// calibrate Digi Time
pCalDigi.SetTime(pCalDigi.GetTime() - chanPar.vCPTOff[Side]);
// subtract Offset
double dTot = pCalDigi.GetTot() - chanPar.vCPTotOff[Side];
if (dTot < 0.001) dTot = 0.001;
// calibrate Digi ToT
pCalDigi.SetTot(dTot * chanPar.vCPTotGain[Side]);
// walk correction
std::vector<double>& walk = chanPar.vCPWalk[Side];
const double dTotBinSize = (rpcPar.TOTMax - rpcPar.TOTMin) / rpcPar.numClWalkBinX;
int32_t iWx = (int32_t)((pCalDigi.GetTot() - rpcPar.TOTMin) / dTotBinSize);
if (0 > iWx) { iWx = 0; }
if (iWx >= rpcPar.numClWalkBinX) { iWx = rpcPar.numClWalkBinX - 1; }
const double dDTot = (pCalDigi.GetTot() - rpcPar.TOTMin) / dTotBinSize - (double) iWx - 0.5;
double dWT = walk[iWx];
// linear interpolation to next bin
if (dDTot > 0) {
if (iWx < rpcPar.numClWalkBinX - 1) { dWT += dDTot * (walk[iWx + 1] - walk[iWx]); }
}
else {
if (0 < iWx) { dWT -= dDTot * (walk[iWx - 1] - walk[iWx]); }
}
pCalDigi.SetTime(pCalDigi.GetTime() - dWT); // calibrate Digi Time
calDigiOut.push_back(pCalDigi);
}
monitor.fTime = xpu::pop_timer();
return result;
}
} // namespace cbm::algo::tof
Loading