From b085b17d5a883fb8254a5783e3977c5604a049c9 Mon Sep 17 00:00:00 2001 From: Dominik Smith <smith@th.physik.uni-frankfurt.de> Date: Mon, 11 Sep 2023 15:39:56 +0200 Subject: [PATCH] cbm::algo::Clusterizer: Optimized double loop in AddNextChan(). --- algo/detectors/tof/Clusterizer.cxx | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/algo/detectors/tof/Clusterizer.cxx b/algo/detectors/tof/Clusterizer.cxx index 9b23eb627e..79bdd6b84e 100644 --- a/algo/detectors/tof/Clusterizer.cxx +++ b/algo/detectors/tof/Clusterizer.cxx @@ -20,8 +20,8 @@ namespace cbm::algo::tof { //std::vector<inputType> input = calibrateDigis(digisIn); std::vector<inputType> input = chanSortDigis(digisIn); - //return buildClusters(input); - return buildClustersIter(input); //Iterator based implementation + return buildClusters(input); + //return buildClustersIter(input); //Iterator based implementation } std::vector<Clusterizer::inputType> Clusterizer::chanSortDigis(inputType& digisIn) @@ -153,7 +153,6 @@ namespace cbm::algo::tof offset++; } */ - storDigi.erase(storDigi.begin() + offset); if (2 > storDigi.size()) { break; } } // same condition side end @@ -276,13 +275,18 @@ namespace cbm::algo::tof for (auto i1 = storDigi.begin(); i1 < storDigi.end() - 1; i1++) { + const CbmTofDigi* xDigiA = i1->first; + const double timeMax = + xDigiA->GetTime() + fParams.fChanPar[chan].cell.sizeY * fParams.fPosYMaxScal / fParams.fSigVel; + + if (timeMax < cluster.weightedTime / cluster.weightsSum - fParams.fdMaxTimeDist) { continue; } auto i2 = i1; + //D.Smith 7.9.23: Do we really need to loop through all remaining digis? //Maybe break at i2 == i1 + 2 ? //D.Smith 8.9.23: Adding the break condition below probably makes this redundant. while (++i2 < storDigi.end()) { - const CbmTofDigi* xDigiA = i1->first; const CbmTofDigi* xDigiB = i2->first; if (xDigiA->GetSide() == xDigiB->GetSide()) { continue; } @@ -292,12 +296,12 @@ namespace cbm::algo::tof // The optimization relies on time-order. //if (std::abs(time - cluster.weightedTime / cluster.weightsSum) >= fParams.fdMaxTimeDist) { continue; } - //Break if digis are in the future of cluster time - if (time - cluster.weightedTime / cluster.weightsSum >= fParams.fdMaxTimeDist) { break; } - //Continue if digis are in the past of cluster time if (cluster.weightedTime / cluster.weightsSum - time >= fParams.fdMaxTimeDist) { continue; } + //Break if digis are in the future of cluster time + if (time - cluster.weightedTime / cluster.weightsSum >= fParams.fdMaxTimeDist) { break; } + const double timeDif = xDigiA->GetTime() - xDigiB->GetTime(); double posY = fParams.fSigVel * timeDif * 0.5; if (1 != xDigiA->GetSide()) { posY *= -1.; } @@ -319,6 +323,7 @@ namespace cbm::algo::tof return true; // signal hit was already added } i1 = storDigi.end(); // jump to end of outer loop + break; } } -- GitLab