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

Switched from std::sort to insert-sort in cbm::algo::tof::Calibrate (faster for pre-sorted data).

parent 7c451e71
No related branches found
No related tags found
1 merge request!1483Replacement of std::unordered_map in cbm::algo::tof::Calibrate.
......@@ -52,8 +52,7 @@ namespace cbm::algo::tof
std::fill(mChannelDeadTime.begin(), mChannelDeadTime.end(), std::numeric_limits<double>::quiet_NaN());
for (const auto& entry : digiIn) {
CbmTofDigi digi = entry;
for (const auto& digi : digiIn) {
const double SmType = digi.GetType();
const double Sm = digi.GetSm();
const double Rpc = digi.GetRpc();
......@@ -81,14 +80,14 @@ namespace cbm::algo::tof
}
mChannelDeadTime[chanIdx] = digi.GetTime() + rpcPar.channelDeadtime;
// Create calibrated digi
CbmTofDigi& pCalDigi = calDigiOut.emplace_back(digi);
// Check if channel sides need to be swapped
if (rpcPar.swapChannelSides && 5 != SmType && 8 != SmType) {
digi.SetAddress(Sm, Rpc, Chan, (0 == Side) ? 1 : 0, SmType);
pCalDigi.SetAddress(Sm, Rpc, Chan, (0 == Side) ? 1 : 0, SmType);
}
// Create calibrated digi
CbmTofDigi& pCalDigi = calDigiOut.emplace_back(digi);
// calibrate Digi Time
pCalDigi.SetTime(pCalDigi.GetTime() - chanPar.vCPTOff[Side]);
......@@ -120,8 +119,20 @@ namespace cbm::algo::tof
}
/// Sort the buffers of hits due to the time offsets applied
std::sort(calDigiOut.begin(), calDigiOut.end(),
[](const CbmTofDigi& a, const CbmTofDigi& b) -> bool { return a.GetTime() < b.GetTime(); });
// (insert-sort faster than std::sort due to pre-sorting)
for (std::size_t i = 1; i < calDigiOut.size(); ++i) {
CbmTofDigi digi = calDigiOut[i];
std::size_t j = i;
while (j > 0 && calDigiOut[j - 1].GetTime() > digi.GetTime()) {
calDigiOut[j] = calDigiOut[j - 1];
--j;
}
calDigiOut[j] = digi;
}
// Kept for possible unsorted input
// std::sort(calDigiOut.begin(), calDigiOut.end(),
// [](const CbmTofDigi& a, const CbmTofDigi& b) -> bool { return a.GetTime() < b.GetTime(); });
monitor.fTime = xpu::pop_timer();
//L_(info) << MakeReport("CalibrateTime", monitor.fTime);
......
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