Skip to content

Commit 6b61295

Browse files
committed
more updates
1 parent a905f3b commit 6b61295

3 files changed

Lines changed: 48 additions & 27 deletions

File tree

roofit/xroofit/src/xRooFit.cxx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -548,9 +548,9 @@ void printCerr(const char *msg)
548548
{
549549
if (Py_IsInitialized()) {
550550
PySys_WriteStderr("%s\n", msg);
551-
if (PyObject *sys_stdout = PySys_GetObject("stderr"); sys_stdout != nullptr) {
552-
Py_XDECREF(PyObject_CallMethod(sys_stdout, "flush", nullptr));
553-
}
551+
// if (PyObject *sys_stdout = PySys_GetObject("stderr"); sys_stdout != nullptr) {
552+
// Py_XDECREF(PyObject_CallMethod(sys_stdout, "flush", nullptr));
553+
// }
554554
} else {
555555
std::cerr << msg << std::endl;
556556
}
@@ -559,9 +559,9 @@ void printCout(const char *msg)
559559
{
560560
if (Py_IsInitialized()) {
561561
PySys_WriteStdout("%s\n", msg);
562-
if (PyObject *sys_stdout = PySys_GetObject("stdout"); sys_stdout != nullptr) {
563-
Py_XDECREF(PyObject_CallMethod(sys_stdout, "flush", nullptr));
564-
}
562+
// if (PyObject *sys_stdout = PySys_GetObject("stdout"); sys_stdout != nullptr) {
563+
// Py_XDECREF(PyObject_CallMethod(sys_stdout, "flush", nullptr));
564+
// }
565565
} else {
566566
std::cout << msg << std::endl;
567567
}
@@ -975,7 +975,7 @@ std::shared_ptr<const RooFitResult> xRooFit::minimize(RooAbsReal &nll,
975975
if (!out) {
976976
int strategy = fitConfig.MinimizerOptions().Strategy();
977977
// Note: AsymptoticCalculator enforces not less than 1 on tolerance - should we do so too?
978-
if (_progress && printLevel>=-1) {
978+
if (_progress && printLevel >= -2) {
979979
_nll = new ProgressMonitor(*_nll, _progress);
980980
ProgressMonitor::fInterrupt = false;
981981
}
@@ -1271,17 +1271,18 @@ std::shared_ptr<const RooFitResult> xRooFit::minimize(RooAbsReal &nll,
12711271
.Data());
12721272
}
12731273

1274-
if (sIdx >= m_hessestrategy.Length() - 1) {
1275-
break; // run out of strategies to try, stop
1276-
}
1277-
12781274
if (_status == 0 && _minimizer.fitter()->GetMinimizer()->CovMatrixStatus() == 3) {
12791275
// covariance is valid!
12801276
break;
12811277
} else if (_status == 0) {
12821278
// set the statusHistory to the cov status, since that's more informative
12831279
statusHistory.back().second = _minimizer.fitter()->GetMinimizer()->CovMatrixStatus();
12841280
}
1281+
1282+
if (sIdx >= m_hessestrategy.Length() - 1) {
1283+
break; // run out of strategies to try, stop
1284+
}
1285+
12851286
sIdx++;
12861287
} // end of hesse attempt loop
12871288
}
@@ -1317,7 +1318,7 @@ std::shared_ptr<const RooFitResult> xRooFit::minimize(RooAbsReal &nll,
13171318
}
13181319
}
13191320

1320-
if (printLevel>=-1 && miniStrat < _minimizer.fitter()->Config().MinimizerOptions().Strategy() && hesse &&
1321+
if (printLevel >= -2 && miniStrat < _minimizer.fitter()->Config().MinimizerOptions().Strategy() && hesse &&
13211322
out->edm() > _minimizer.fitter()->Config().MinimizerOptions().Tolerance() * 1e-3 && out->status() != 3) {
13221323
// hesse may have updated edm by using a better strategy than used in the minimization
13231324
// so print a warning about this
@@ -1434,7 +1435,7 @@ std::shared_ptr<const RooFitResult> xRooFit::minimize(RooAbsReal &nll,
14341435
fitConfig.MinimizerOptions().SetMinimizerType(actualFirstMinimizer);
14351436
}
14361437

1437-
if (_progress && printLevel>=-1) {
1438+
if (_progress && printLevel >= -2) {
14381439
delete _nll;
14391440
}
14401441
}

roofit/xroofit/src/xRooHypoSpace.cxx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -648,9 +648,9 @@ xRooNLLVar::xRooHypoPoint &xRooNLLVar::xRooHypoSpace::AddPoint(const char *coord
648648
if (Py_IsInitialized()) {
649649
auto s = TString::Format("Info in <xRooHypoSpace::AddPoint>: Added new point @ %s", coordString.c_str());
650650
PySys_WriteStdout("%s\n", s.Data());
651-
if (PyObject *sys_stdout = PySys_GetObject("stdout"); sys_stdout != nullptr) {
652-
Py_XDECREF(PyObject_CallMethod(sys_stdout, "flush", nullptr));
653-
}
651+
// if (PyObject *sys_stdout = PySys_GetObject("stdout"); sys_stdout != nullptr) {
652+
// Py_XDECREF(PyObject_CallMethod(sys_stdout, "flush", nullptr));
653+
// }
654654
} else {
655655
::Info("xRooHypoSpace::AddPoint", "Added new point @ %s", coordString.c_str());
656656
}

roofit/xroofit/src/xRooNLLVar.cxx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1597,7 +1597,7 @@ void xRooNLLVar::xRooHypoPoint::Print(Option_t *) const
15971597
}
15981598
std::cout << " , pllType: ";
15991599
switch (fPllType) {
1600-
case 0: std::cout << "qmu"; break;
1600+
case 0: std::cout << "tmu"; break;
16011601
case 1: std::cout << "qmu or qmutilde"; break; // should check for 'physical' to decide if is latter
16021602
case 2: std::cout << "q0"; break;
16031603
case 4: std::cout << "u0"; break;
@@ -1775,6 +1775,14 @@ std::shared_ptr<xRooNLLVar::xRooHypoPoint> xRooNLLVar::xRooHypoPoint::asimov(boo
17751775
// dynamic_cast<RooRealVar *>(p)->removeRange("physical"); -- can't use this as will modify shared property
17761776
if (auto v = dynamic_cast<RooRealVar *>(p)) {
17771777
v->deleteSharedProperties(); // effectively removes all custom ranges
1778+
if (v->getVal() == 0) {
1779+
// for discovery tests, we generate asimov at mu!=0 and then evaluate the two sided
1780+
// at some value of mu. Normally we would use mu=0 but if we have a bin
1781+
// with only signal contribution (no bkg) will get asimov data in that bin
1782+
// and no prediction ... the cfit(mu=0) will never succeed on this
1783+
// so lets move to half the alt value instead (the value used to generate)
1784+
v->setVal(theFit->constPars().getRealValue(v->GetName()) * 0.5);
1785+
}
17781786
}
17791787
}
17801788

@@ -1799,15 +1807,19 @@ xRooNLLVar::xValueWithError xRooNLLVar::xRooHypoPoint::pNull_asymp(double nSigma
17991807
auto first_poi = dynamic_cast<RooRealVar *>(poi().first());
18001808
if (!first_poi)
18011809
return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1802-
auto _sigma_mu = sigma_mu();
1810+
double lowBound = first_poi->getMin("physical");
1811+
double hiBound = first_poi->getMax("physical");
1812+
// don't need to calculate sigma_mu if physical boundaries at infinity, PValue doesn't depend on it
1813+
auto _sigma_mu =
1814+
(lowBound == -std::numeric_limits<double>::infinity() && hiBound == std::numeric_limits<double>::infinity())
1815+
? std::pair<double, double>(0, 0)
1816+
: sigma_mu();
18031817
double nom = xRooFit::Asymptotics::PValue(fPllType, ts_asymp(nSigma).first, fNullVal(), fNullVal(), _sigma_mu.first,
1804-
first_poi->getMin("physical"), first_poi->getMax("physical"));
1805-
double up =
1806-
xRooFit::Asymptotics::PValue(fPllType, ts_asymp(nSigma).first + ts_asymp(nSigma).second, fNullVal(), fNullVal(),
1807-
_sigma_mu.first, first_poi->getMin("physical"), first_poi->getMax("physical"));
1808-
double down =
1809-
xRooFit::Asymptotics::PValue(fPllType, ts_asymp(nSigma).first - ts_asymp(nSigma).second, fNullVal(), fNullVal(),
1810-
_sigma_mu.first, first_poi->getMin("physical"), first_poi->getMax("physical"));
1818+
lowBound, hiBound);
1819+
double up = xRooFit::Asymptotics::PValue(fPllType, ts_asymp(nSigma).first + ts_asymp(nSigma).second, fNullVal(),
1820+
fNullVal(), _sigma_mu.first, lowBound, hiBound);
1821+
double down = xRooFit::Asymptotics::PValue(fPllType, ts_asymp(nSigma).first - ts_asymp(nSigma).second, fNullVal(),
1822+
fNullVal(), _sigma_mu.first, lowBound, hiBound);
18111823
return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
18121824
}
18131825

@@ -2248,8 +2260,8 @@ xRooNLLVar::xValueWithError xRooNLLVar::xRooHypoPoint::sigma_mu(bool readOnly)
22482260
}
22492261

22502262
auto out = asi->pll(readOnly);
2251-
return std::pair<double, double>(std::abs(fNullVal() - fAltVal()) / sqrt(out.first),
2252-
out.second * 0.5 * std::abs(fNullVal() - fAltVal()) /
2263+
return std::pair<double, double>(std::abs(asi->fNullVal() - fAltVal()) / sqrt(out.first),
2264+
out.second * 0.5 * std::abs(asi->fNullVal() - fAltVal()) /
22532265
(out.first * sqrt(out.first)));
22542266
}
22552267

@@ -2615,6 +2627,10 @@ xRooNLLVar::hypoPoint(const char *poiValues, double alt_value, const xRooFit::As
26152627
AutoRestorer snap(*fFuncVars);
26162628

26172629
out.nllVar = std::make_shared<xRooNLLVar>(*this);
2630+
// clear the underlying RooAbsReal, so that we don't accidentally alter it (e.g. setAttribute readOnly)
2631+
// and therefore alter the xRooNLLVar object we are creating this hypoPoint from
2632+
// basically ensure the hypoPoint has an independent version of the function
2633+
out.nllVar->reset();
26182634
out.fData = getData();
26192635

26202636
TStringToken pattern(poiValues, ",");
@@ -3151,6 +3167,10 @@ xRooNLLVar::hypoSpace(const char *parName, const xRooFit::Asymptotics::PLLType &
31513167
throw std::runtime_error("You must specify at least one POI for the hypoSpace");
31523168
}*/
31533169
s.fNlls[s.fPdfs.begin()->second] = std::make_shared<xRooNLLVar>(*this);
3170+
// clear the underlying RooAbsReal, so that we don't accidentally alter it (e.g. setAttribute readOnly)
3171+
// and therefore alter the xRooNLLVar object we are creating this hypoPoint from
3172+
// basically ensure the hypoPoint has an independent version of the function
3173+
s.fNlls[s.fPdfs.begin()->second]->reset();
31543174
s.fTestStatType = pllType;
31553175

31563176
for (auto poi : s.poi()) {

0 commit comments

Comments
 (0)