diff --git a/algo/detectors/tof/Clusterizer.cxx b/algo/detectors/tof/Clusterizer.cxx index 79bdd6b84eb71e455a37f6a0ab00a0efbb2ae46e..735ca8349d84c370c85ab8f35fcb6ab7c3e4a87c 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) @@ -134,6 +134,12 @@ namespace cbm::algo::tof const size_t numChan = fParams.fChanPar.size(); + //Store last position in input channels to avoid unnecessary checks in AddNextChan(). + std::vector<inputType::iterator> lastChanPos; + for (int32_t chan = 0; chan < numChan; chan++) { + lastChanPos.push_back(input[chan].begin()); + } + for (int32_t chan = 0; chan < numChan; chan++) { if (fParams.fDeadStrips & (1 << chan)) { continue; } // skip over dead channels @@ -238,7 +244,7 @@ namespace cbm::algo::tof lastChan = chan; lastPosY = pos.Y(); lastTime = time; - if (AddNextChan(input, lastChan, cluster, clustersOut)) { cluster.reset(); } + if (AddNextChan(input, lastChan, cluster, clustersOut, &lastChanPos)) { cluster.reset(); } } // while( 1 < storDigi.size() ) storDigi.clear(); //D.Smith 11.8.23: In rare cases, a single digi remains and is deleted here. } // for( int32_t chan = 0; chan < iNbCh; chan++ ) @@ -250,13 +256,12 @@ namespace cbm::algo::tof cluster.finalize(*cell, fParams); clustersOut.push_back(cluster); } - //std::cout << "hits " << fiNbHits << std::endl; return clustersOut; } bool Clusterizer::AddNextChan(std::vector<inputType>& input, int32_t lastChan, TofCluster& cluster, - std::vector<TofCluster>& clustersOut) + std::vector<TofCluster>& clustersOut, std::vector<inputType::iterator>* lastChanPos) { //D.Smith 25.8.23: Why are "C" digis (position "2") not considered here? @@ -273,18 +278,21 @@ namespace cbm::algo::tof inputType& storDigi = input[chan]; if (0 == storDigi.size()) { return false; } - for (auto i1 = storDigi.begin(); i1 < storDigi.end() - 1; i1++) { + //Store last position in input channels to avoid unnecessary checks. + //Relies on time-order to function properly. Can only be used in first-level AddNextChan() + //calls, as time-order is not guaranteed in nested calls. + for (auto i1 = (lastChanPos == nullptr) ? storDigi.begin() : (*lastChanPos)[chan]; 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; } + if (timeMax < cluster.weightedTime / cluster.weightsSum - fParams.fdMaxTimeDist) { + if (lastChanPos) { (*lastChanPos)[chan]++; } + 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* xDigiB = i2->first; @@ -335,7 +343,7 @@ namespace cbm::algo::tof return true; } - + //Iterator-based version. Faster than index-based version. Clusterizer::resultType Clusterizer::buildClustersIter(std::vector<inputType>& input) { // Hit variables @@ -352,6 +360,12 @@ namespace cbm::algo::tof const size_t numChan = fParams.fChanPar.size(); + //Store last position in input channels to avoid unnecessary checks in AddNextChan(). + std::vector<inputType::iterator> lastChanPos; + for (int32_t chan = 0; chan < numChan; chan++) { + lastChanPos.push_back(input[chan].begin()); + } + for (int32_t chan = 0; chan < numChan; chan++) { if (fParams.fDeadStrips & (1 << chan)) { continue; } // skip over dead channels @@ -432,7 +446,7 @@ namespace cbm::algo::tof lastChan = chan; lastPosY = pos.Y(); lastTime = time; - if (AddNextChan(input, lastChan, cluster, clustersOut)) { cluster.reset(); } + if (AddNextChan(input, lastChan, cluster, clustersOut, &lastChanPos)) { cluster.reset(); } } // while( 1 < storDigi.size() ) storDigi.clear(); //D.Smith 11.8.23: In rare cases, a single digi remains and is deleted here. } // for( int32_t chan = 0; chan < iNbCh; chan++ ) @@ -444,7 +458,6 @@ namespace cbm::algo::tof cluster.finalize(*cell, fParams); clustersOut.push_back(cluster); } - //std::cout << "hits " << fiNbHits << std::endl; return clustersOut; } diff --git a/algo/detectors/tof/Clusterizer.h b/algo/detectors/tof/Clusterizer.h index 9fe5bdc807ed1c6292cf1d11612e412b87be7863..7637a89d083feedc7f0412bc1c4465b1af071675 100644 --- a/algo/detectors/tof/Clusterizer.h +++ b/algo/detectors/tof/Clusterizer.h @@ -181,7 +181,7 @@ namespace cbm::algo::tof bool AddNextChan(std::vector<inputType>& input, int32_t iLastChan, TofCluster& cluster, - std::vector<TofCluster>& clustersOut); + std::vector<TofCluster>& clustersOut, std::vector<inputType::iterator>* lastChanPos = nullptr); int32_t numSameSide; // Digis quality };