From ecedf9cd37c861c5ea583fa3c506fde8a247ae12 Mon Sep 17 00:00:00 2001 From: Josh Bendavid Date: Fri, 18 Sep 2015 19:51:30 +0200 Subject: [PATCH] more robust protection against infinite loops --- RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc b/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc index 114c2aa4c9a7c..259cfcc1bed6b 100644 --- a/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc +++ b/RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc @@ -302,6 +302,7 @@ bool PulseChiSqSNNLS::NNLS() { int iter = 0; Index idxwmax = 0; double wmax = 0.0; + double threshold = 1e-11; //work = PulseVector::zeros(); while (true) { //can only perform this step if solution is guaranteed viable @@ -316,7 +317,12 @@ bool PulseChiSqSNNLS::NNLS() { wmax = updatework.tail(nActive).maxCoeff(&idxwmax); //convergence - if (wmax<1e-11 || (idxwmax==idxwmaxprev && wmax==wmaxprev)) break; + if (wmax=500) { + edm::LogWarning("PulseChiSqSNNLS::NNLS()") << "Max Iterations reached at iter " << iter << std::endl; + } //unconstrain parameter Index idxp = _nP + idxwmax; @@ -384,6 +390,12 @@ bool PulseChiSqSNNLS::NNLS() { --_nP; } ++iter; + + //adaptive convergence threshold to avoid infinite loops but still + //ensure best value is used + if (iter%50==0) { + threshold *= 10.; + } } return true;