386 double initialNll = nll.getVal();
387 std::auto_ptr<RooArgSet> pars;
389 for (
int tries = 0, maxtries = 4; tries <= maxtries; ++tries) {
390 int status = minim.minimize(ROOT::Math::MinimizerOptions::DefaultMinimizerType().c_str(), ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
392 if (status == 0 && nll.getVal() > initialNll + 0.02) {
393 std::auto_ptr<RooFitResult> res(minim.save());
395 DBG(DBG_PLTestStat_main, (printf(
"\n --> false minimum, status %d, cov. quality %d, edm %10.7f, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, res->covQual(), res->edm(), initialNll, nll.getVal(), initialNll - nll.getVal())))
396 if (pars.get() == 0) pars.reset(nll.getParameters((
const RooArgSet*)0));
397 *pars = res->floatParsInit();
399 COUNT_ONE(
"nllutils::robustMinimize: false minimum (first try)")
400 DBG(DBG_PLTestStat_main, (printf(" ----> Doing
a re-scan and re-trying\
n")))
401 minim.minimize("Minuit2","Scan");
402 } else
if (tries == 1) {
403 COUNT_ONE(
"nllutils::robustMinimize: false minimum (second try)")
404 DBG(DBG_PLTestStat_main, (printf(" ----> Re-trying with strategy = 1\
n")))
405 minim.setStrategy(1);
406 } else
if (tries == 2) {
407 COUNT_ONE(
"nllutils::robustMinimize: false minimum (third try)")
408 DBG(DBG_PLTestStat_main, (printf(" ----> Re-trying with strategy = 2\
n")))
409 minim.setStrategy(2);
411 COUNT_ONE(
"nllutils::robustMinimize: false minimum (third try)")
412 DBG(DBG_PLTestStat_main, (printf(" ----> Last attempt: simplex
method \
n")))
413 status = minim.minimize("Minuit2","Simplex");
414 if (nll.getVal() < initialNll + 0.02) {
415 DBG(DBG_PLTestStat_main, (printf(
"\n --> success: status %d, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, initialNll, nll.getVal(), initialNll - nll.getVal())))
416 if (do_debug) printf("\
n -->
success: status %d, nll initial % 10.4
f, nll final % 10.4f, change %10.5f\
n", status, initialNll, nll.getVal(), initialNll - nll.getVal());
421 COUNT_ONE(
"nllutils::robustMinimize: final fail")
422 DBG(DBG_PLTestStat_main, (printf("\n --> final
fail: status %d, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, initialNll, nll.getVal(), initialNll - nll.getVal())))
423 if (do_debug) printf("\n --> final
fail: status %d, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, initialNll, nll.getVal(), initialNll - nll.getVal());
427 } else
if (status == 0) {
428 DBG(DBG_PLTestStat_main, (printf(
"\n --> success: status %d, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, initialNll, nll.getVal(), initialNll - nll.getVal())))
429 if (do_debug) printf("\n -->
success: status %d, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, initialNll, nll.getVal(), initialNll - nll.getVal());
433 } else
if (tries != maxtries) {
434 std::auto_ptr<RooFitResult> res(do_debug ? minim.save() : 0);
436 if (tries > 0 && minim.edm() < 0.05*ROOT::Math::MinimizerOptions::DefaultTolerance()) {
437 DBG(DBG_PLTestStat_main, (printf(
"\n --> acceptable: status %d, edm %10.7f, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, res->edm(), initialNll, nll.getVal(), initialNll - nll.getVal())))
438 if (do_debug) printf("\n --> acceptable: status %d, edm %10.7f, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, res->edm(), initialNll, nll.getVal(), initialNll - nll.getVal());
444 DBG(DBG_PLTestStat_main, (printf("\n --> partial
fail: status %d, cov. quality %d, edm %10.7f, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, res->covQual(), res->edm(), initialNll, nll.getVal(), initialNll - nll.getVal())))
446 COUNT_ONE(
"nllutils::robustMinimize: failed first attempt")
447 DBG(DBG_PLTestStat_main, (printf(" ----> Doing
a re-scan
first, and switching
to strategy 1\n")))
448 minim.minimize("Minuit2","Scan");
449 minim.setStrategy(1);
452 COUNT_ONE(
"nllutils::robustMinimize: failed second attempt")
453 DBG(DBG_PLTestStat_main, (printf(" ----> trying with strategy = 2\n")))
454 minim.minimize("Minuit2","Scan");
455 minim.setStrategy(2);
458 std::auto_ptr<RooFitResult> res(do_debug ? minim.save() : 0);
459 DBG(DBG_PLTestStat_main, (printf(
"\n --> final fail: status %d, cov. quality %d, edm %10.7f, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, res->covQual(), res->edm(), initialNll, nll.getVal(), initialNll - nll.getVal())))
460 if (do_debug) printf("\n --> final
fail: status %d, cov. quality %d, edm %10.7f, nll initial % 10.4f, nll final % 10.4f, change %10.5f\n", status, res->covQual(), res->edm(), initialNll, nll.getVal(), initialNll - nll.getVal());
bool robustMinimize(RooAbsReal &nll, RooMinimizerOpt &minimizer, int verbosity=0)
int get(const char *name)
int bad(Items const &cont)
perl if(1 lt scalar(@::datatypes))