diff --git a/algo/detectors/tof/Calibrate.cxx b/algo/detectors/tof/Calibrate.cxx index be30ee715b515676a64f56c9eb788f1dc0ac1766..b94cdc8cc1799388ab687c8b73a461e5e1869598 100644 --- a/algo/detectors/tof/Calibrate.cxx +++ b/algo/detectors/tof/Calibrate.cxx @@ -7,6 +7,7 @@ #include <chrono> #include "log.hpp" +#include "util/TimingsFormat.h" using namespace std; using fles::Subsystem; @@ -24,6 +25,7 @@ namespace cbm::algo::tof auto& calDigiOut = result.first; auto& monitor = result.second; + calDigiOut.reserve(digiIn.size()); // channel deadtime map std::map<int32_t, double> mChannelDeadTime; @@ -94,11 +96,8 @@ namespace cbm::algo::tof calDigiOut.push_back(pCalDigi); } - /// 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(); }); - monitor.fTime = xpu::pop_timer(); + L_(debug) << MakeReport("Calibrate", monitor.fTime); return result; } diff --git a/algo/detectors/tof/Clusterizer.cxx b/algo/detectors/tof/Clusterizer.cxx index ee370d980c6dc0f72d5bf1efe81ccf29209d84a3..ca9b4726a3b90b4ded5746472fc7353dbe6a7a1c 100644 --- a/algo/detectors/tof/Clusterizer.cxx +++ b/algo/detectors/tof/Clusterizer.cxx @@ -27,12 +27,21 @@ namespace cbm::algo::tof { std::vector<inputType> result(fParams.fChanPar.size()); //[nbCh][nDigis] + // Bucket-sort by channel for (size_t iDigi = 0; iDigi < digisIn.size(); iDigi++) { CbmTofDigi* pDigi = digisIn[iDigi].first; const int32_t index = digisIn[iDigi].second; const double chan = pDigi->GetChannel(); result[chan].push_back(std::make_pair(new CbmTofDigi(*pDigi), index)); } + + /// Sort channel-wise by time + for (size_t chan = 0; chan < fParams.fChanPar.size(); chan++) { + std::sort(result[chan].begin(), result[chan].end(), + [](const std::pair<CbmTofDigi*, int32_t>& a, const std::pair<CbmTofDigi*, int32_t>& b) -> bool { + return a.first->GetTime() < b.first->GetTime(); + }); + } return result; } @@ -104,7 +113,6 @@ namespace cbm::algo::tof result[chan].push_back(std::make_pair(pCalDigi, index)); } - // D.Smith 10.8.23: Sorting below might not be needed. Check with P.A. /// Sort the buffers of hits due to the time offsets applied for (size_t chan = 0; chan < fParams.fChanPar.size(); chan++) { std::sort(result[chan].begin(), result[chan].end(), diff --git a/algo/detectors/tof/Hitfind.cxx b/algo/detectors/tof/Hitfind.cxx index d789c8367d79416dfc949daec56b968e1075cc96..92bee7da8a0d63622462310ff94e0caa2a1be345 100644 --- a/algo/detectors/tof/Hitfind.cxx +++ b/algo/detectors/tof/Hitfind.cxx @@ -7,6 +7,7 @@ #include <chrono> #include "log.hpp" +#include "util/TimingsFormat.h" using namespace std; using fles::Subsystem; @@ -24,17 +25,11 @@ namespace cbm::algo::tof auto& clusterTs = std::get<0>(result); auto& monitor = std::get<1>(result); - //auto& calDigi = std::get<2>(result); - - // Do calibration globally (optional, should not be used together with RPC-wise calibration) - //calDigi = CalibRawDigis(digiIn, monitor); - - auto& calDigi = digiIn; // Loop over the digis array and store the Digis in separate vectors for // each RPC modules - for (int32_t idigi = 0; idigi < calDigi.size(); idigi++) { - CbmTofDigi* pDigi = &(calDigi[idigi]); + for (int32_t idigi = 0; idigi < digiIn.size(); idigi++) { + CbmTofDigi* pDigi = &(digiIn[idigi]); // These are doubles in the digi class const double SmType = pDigi->GetType(); @@ -86,6 +81,7 @@ namespace cbm::algo::tof monitor.fTime = xpu::pop_timer(); monitor.fNumDigis = digiIn.size(); monitor.fNumHits = clustersFlat.size(); + L_(debug) << MakeReport("Hitfind", monitor.fTime); // Create ouput vector clusterTs = PartitionedVector(std::move(clustersFlat), rpcSizes, rpcAddresses); @@ -162,85 +158,4 @@ namespace cbm::algo::tof } // ---------------------------------------------------------------------------- - - // -------------------------- Calibration ------------------------------------- - std::vector<CbmTofDigi> Hitfind::CalibRawDigis(gsl::span<CbmTofDigi> digiVec, HitfindMonitorData& monitor) - { - // channel deadtime map - std::map<int32_t, double> mChannelDeadTime; - std::vector<CbmTofDigi> calDigiVecOut; - - for (size_t iDigi = 0; iDigi < digiVec.size(); iDigi++) { - - CbmTofDigi pDigi = digiVec[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 = fNbRpc[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 - calDigiVecOut.push_back(pCalDigi); - } - - /// Sort the buffers of hits due to the time offsets applied - std::sort(calDigiVecOut.begin(), calDigiVecOut.end(), - [](const CbmTofDigi& a, const CbmTofDigi& b) -> bool { return a.GetTime() < b.GetTime(); }); - - return calDigiVecOut; - } - } // namespace cbm::algo::tof