Skip to content

Commit ecedf9c

Browse files
committed
more robust protection against infinite loops
1 parent eac8218 commit ecedf9c

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

RecoLocalCalo/EcalRecAlgos/src/PulseChiSqSNNLS.cc

+13-1
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ bool PulseChiSqSNNLS::NNLS() {
302302
int iter = 0;
303303
Index idxwmax = 0;
304304
double wmax = 0.0;
305+
double threshold = 1e-11;
305306
//work = PulseVector::zeros();
306307
while (true) {
307308
//can only perform this step if solution is guaranteed viable
@@ -316,7 +317,12 @@ bool PulseChiSqSNNLS::NNLS() {
316317
wmax = updatework.tail(nActive).maxCoeff(&idxwmax);
317318

318319
//convergence
319-
if (wmax<1e-11 || (idxwmax==idxwmaxprev && wmax==wmaxprev)) break;
320+
if (wmax<threshold || (idxwmax==idxwmaxprev && wmax==wmaxprev)) break;
321+
322+
//worst case protection
323+
if (iter>=500) {
324+
edm::LogWarning("PulseChiSqSNNLS::NNLS()") << "Max Iterations reached at iter " << iter << std::endl;
325+
}
320326

321327
//unconstrain parameter
322328
Index idxp = _nP + idxwmax;
@@ -384,6 +390,12 @@ bool PulseChiSqSNNLS::NNLS() {
384390
--_nP;
385391
}
386392
++iter;
393+
394+
//adaptive convergence threshold to avoid infinite loops but still
395+
//ensure best value is used
396+
if (iter%50==0) {
397+
threshold *= 10.;
398+
}
387399
}
388400

389401
return true;

0 commit comments

Comments
 (0)