22#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
23#define protected public
28#if ROOT_VERSION_CODE < ROOT_VERSION(6, 33, 00)
61#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
63#define GETWS(a) a->_myws
64#define GETWSSETS(w) w->_namedSets
66#define GETWS(a) a->workspace()
67#define GETWSSETS(w) w->sets()
74#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
75#define protected public
104std::set<int> xRooNLLVar::xRooHypoPoint::allowedStatusCodes = {0};
115 fOldTitle =
fNll->get()->getStringAttribute(
"fitresultTitle");
140 std::unique_ptr<RooAbsCollection>
fSnap;
143 std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
fOldData;
147xRooNLLVar::~xRooNLLVar() {}
149xRooNLLVar::xRooNLLVar(
RooAbsPdf &pdf,
const std::pair<RooAbsData *, const RooAbsCollection *> &
data,
152 std::make_pair(std::shared_ptr<RooAbsData>(
data.first, [](
RooAbsData *) {}),
159 const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &
data,
161 : fPdf(pdf), fData(
data.first), fGlobs(
data.second)
178 for (
int i = 0; i <
opts.GetSize(); i++) {
181 if (
strcmp(
opts.At(i)->GetName(),
"GlobalObservables") == 0) {
186 throw std::runtime_error(
"GlobalObservables mismatch");
188 }
else if (
strcmp(
opts.At(i)->GetName(),
"Hesse") == 0) {
190 }
else if (
strcmp(
opts.At(i)->GetName(),
"Minos") == 0) {
192 }
else if (
strcmp(
opts.At(i)->GetName(),
"Strategy") == 0) {
194 }
else if (
strcmp(
opts.At(i)->GetName(),
"StrategySequence") == 0) {
196 }
else if (
strcmp(
opts.At(i)->GetName(),
"Tolerance") == 0) {
198 }
else if (
strcmp(
opts.At(i)->GetName(),
"MaxCalls") == 0) {
200 }
else if (
strcmp(
opts.At(i)->GetName(),
"MaxIterations") == 0) {
202 }
else if (
strcmp(
opts.At(i)->GetName(),
"PrintLevel") == 0) {
205 if (
strcmp(
opts.At(i)->GetName(),
"Optimize") == 0) {
216 auto _vars = std::unique_ptr<RooArgSet>(
fPdf->getVariables());
219 _vars->add(*std::unique_ptr<RooArgSet>(
con->getVariables()));
242 bool hasRange(
false);
266 std::make_shared<RooSimultaneous>(
TString::Format(
"%s_reduced", s->GetName()),
"Reduced model", _cat);
267 for (
auto &
c : _cat) {
268 auto _pdf = s->getPdf(
c.first.c_str());
271 _cat.setIndex(
c.second);
274 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
280 newPdf->addPdf(*_pdf,
c.first.c_str());
315 (
opts.find(
"GlobalObservables"))
324 std::cout <<
"PDF: ";
328 std::cout <<
"<null>" << std::endl;
330 std::cout <<
"Data: ";
334 std::cout <<
"<null>" << std::endl;
336 std::cout <<
"NLL Options: " << std::endl;
337 for (
int i = 0; i <
fOpts->GetSize(); i++) {
341 std::cout <<
" " <<
c->
GetName() <<
" : ";
342 if (
c->getString(0)) {
343 std::cout <<
c->getString(0);
344 }
else if (
c->getSet(0) && !
c->getSet(0)->empty()) {
345 std::cout << (
c->getSet(0)->contentsString());
347 std::cout <<
c->getInt(0);
349 std::cout << std::endl;
352 std::cout <<
"Fit Config: " << std::endl;
353 std::cout <<
" UseParabErrors: " << (
fFitConfig->ParabErrors() ?
"True" :
"False")
354 <<
" [toggles HESSE algorithm]" << std::endl;
355 std::cout <<
" MinimizerOptions: " << std::endl;
364 if (std::shared_ptr<RooAbsReal>::get())
365 oldName = std::shared_ptr<RooAbsReal>::get()->GetName();
370 fPdf->treeNodeServerList(&s,
nullptr,
true,
false);
381 if (
a->InheritsFrom(
"RooRealSumPdf")) {
386 std::unique_ptr<RooArgSet> obs(
a->getObservables(
fData->get()));
387 if (obs->size() == 1) {
388 auto *var =
static_cast<RooRealVar *
>(obs->first());
389 std::unique_ptr<std::list<double>> boundaries{
dynamic_cast<RooAbsReal *
>(
a)->binBoundaries(
390 *var, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())};
392 if (!std::shared_ptr<RooAbsReal>::get()) {
393 Info(
"xRooNLLVar",
"%s will be evaluated as a Binned PDF (%d bins)",
a->GetName(),
394 int(boundaries->size() - 1));
401 a->setAttribute(
"BinnedLikelihood",
setBinned);
405 std::map<RooAbsPdf *, std::string>
normRanges;
408 if (
auto sr =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"SplitRange"));
412 for (
auto cat :
simPdf->indexCat()) {
417 srangeName.ReplaceAll(
",",
"_" + cat.first +
",");
420 subpdf->treeNodeServerList(&
ss,
nullptr,
true,
false);
423 if (
a->InheritsFrom(
"RooAddPdf")) {
435 if (
a->InheritsFrom(
"RooAddPdf")) {
456 if (std::shared_ptr<RooAbsReal>::get())
457 attribs = std::shared_ptr<RooAbsReal>::get()->attributes();
458 this->reset(std::unique_ptr<RooAbsReal>{
fPdf->createNLL(*
fData, *
fOpts)}.release());
465 k->setNormRange(
v ==
"" ?
nullptr :
v.c_str());
468 std::shared_ptr<RooAbsReal>::get()->setAttribute(
a.c_str());
474 std::shared_ptr<RooAbsReal>::get()->SetName(
oldName);
477 std::shared_ptr<RooAbsReal>::get()->getVal();
479 o->setAttribute(
"BinnedLikelihood",
v);
483 fFuncVars = std::unique_ptr<RooArgSet>{std::shared_ptr<RooAbsReal>::get()->getVariables()};
491std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
495 return std::pair(
nullptr,
nullptr);
496 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
500 fr->setConstParList(
l);
501 const_cast<RooArgList &
>(fr->constPars()).setAttribAll(
"global",
false);
503 std::unique_ptr<RooAbsCollection>(fr->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
537 throw std::runtime_error(
"xRooFitResult::cfit: Cannot create cfit without nll");
541 if (
auto res = fCfits->find(
alias); res != fCfits->end()) {
545 if (
auto res = fCfits->find(
poiValues); res != fCfits->end()) {
550 *fNll->fFuncVars =
get()->floatParsFinal();
551 fNll->fFuncVars->assignValueOnly(
get()->constPars());
552 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->floatParsFinal()))
553 ->setAttribAll(
"Constant",
false);
554 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->constPars()))->setAttribAll(
"Constant",
true);
566 throw std::runtime_error(
"xRooFitResult::ifit: par not found");
575 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
578 throw std::runtime_error(
"xRooFitResult::impact: null ifit");
579 if (
_ifit->status() != 0)
580 fNode->Warning(
"impact",
"ifit status code is %d",
_ifit->status());
581 return _ifit->floatParsFinal().getRealValue(poi) -
poiHat->getVal();
584 int iPoi =
get()->floatParsFinal().index(poi);
585 int iNp =
get()->floatParsFinal().index(
np);
587 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
589 throw std::runtime_error(
"xRooFitResult::impact: np not found");
594 return std::numeric_limits<double>::quiet_NaN();
604 for (
auto p :
get()->floatParsFinal()) {
605 if (
strcmp(
p->GetName(), poi) == 0) {
611 bool matches =
false;
614 if ((
p->getStringAttribute(
"group") && s ==
p->getStringAttribute(
"group")) ||
629 throw std::runtime_error(
TString::Format(
"Could not find poi: %s", poi));
632 fNode->Warning(
"conditionalError",
"No parameters selected by: %s",
nps);
637 int idx = vars.
index(poi);
638 return sqrt(
get()->conditionalCovarianceMatrix(vars)(idx, idx));
643 auto _poi =
_cfit->floatParsFinal().find(poi);
645 return (
up) ?
static_cast<RooRealVar *
>(_poi)->getErrorHi() :
static_cast<RooRealVar *
>(_poi)->getErrorLo();
653 throw std::runtime_error(
"xRooFitResult::ranknp: poi not found");
655 std::vector<std::pair<std::string, double>>
ranks;
657 for (
auto par :
get()->floatParsFinal()) {
660 ranks.emplace_back(std::pair(par->GetName(), impact(poi, par->GetName(),
up,
prefit,
true)));
664 if (std::isnan(left.second) && !std::isnan(right.second))
666 if (!std::isnan(left.second) && std::isnan(right.second))
668 return fabs(left.second) > fabs(right.second);
677 v = std::numeric_limits<double>::quiet_NaN();
684 if (std::isnan(left.second) && !std::isnan(right.second))
686 if (!std::isnan(left.second) && std::isnan(right.second))
688 return fabs(left.second) > fabs(right.second);
692 out.setName(
"rankings");
694 out.addClone(*
get()->floatParsFinal().find(
n.c_str()));
695 auto vv =
static_cast<RooRealVar *
>(out.at(out.size() - 1));
714 const_cast<RooArgList &
>(out->constPars()).setAttribAll(
"global",
false);
716 std::unique_ptr<RooAbsCollection>(out->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
718 return xRooFitResult(std::make_shared<xRooNode>(out,
fPdf), std::make_shared<xRooNLLVar>(*
this));
740 if (
size_t(_data->numEntries()) <=
entry)
743 *std::unique_ptr<RooAbsCollection>(_pdf->getObservables(_data)) = *_data->get(
entry);
746 return -_data->weight() * _pdf->getLogVal(_data->get());
751 std::set<std::string> out;
762 c->
get<
RooAbsArg>()->treeNodeServerList(&nodes,
nullptr,
true,
false);
764 for (
auto a : nodes) {
765 if (
a->InheritsFrom(
"RooRealSumPdf") &&
783 pdf()->treeNodeServerList(&nodes,
nullptr,
true,
false);
784 for (
auto a : nodes) {
785 if (
a->InheritsFrom(
"RooRealSumPdf") &&
801 if (
size_t(_data->numEntries()) <=
entry)
803 auto _pdf =
pdf().get();
804 std::unique_ptr<RooAbsCollection>
_robs(_pdf->getObservables(_data->get()));
807 _pdf = s->getPdf(s->indexCat().getCurrentLabel());
810 for (
auto o : *
_robs) {
814 std::unique_ptr<std::list<double>> bins(
815 _pdf->binBoundaries(*
a, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()));
817 double lowEdge = -std::numeric_limits<double>::infinity();
818 for (
auto b : *bins) {
819 if (
b >
a->getVal()) {
846 for (
auto c :
cTerm->list()) {
847 if (std::string(
c->ClassName()) ==
"RooAbsPdf" || std::string(
c->ClassName()).find(
"RooNormalizedPdf")!=std::string::npos) {
857 gaus->getMean().GetName()));
876 std::unique_ptr<RooAbsCollection>(
pars()->selectByAttrib(
"Constant",
false))->
size();
890 std::unique_ptr<RooAbsCollection>
_floats(
pars()->selectByAttrib(
"Constant",
false));
933 return std::numeric_limits<double>::quiet_NaN();
947 double out = _data->sumEntries();
948 for (
int i = 0; i < _data->numEntries(); i++) {
950 double w = _data->weight();
953 out -=
w * std::log(
w);
966 throw std::runtime_error(
"Cannot determine category of RooSimultaneous pdf");
977 auto out = std::shared_ptr<RooArgSet>(
get()->getVariables());
979 out->remove(*
fGlobs,
true,
true);
1004 std::unique_ptr<RooAbsCollection>
funcVars(
get()->getVariables());
1007 for (
auto &
coord : coords) {
1009 throw std::runtime_error(
"Invalid coordinate");
1011 for (
size_t i = 0; i <
coord.size(); i++) {
1034 if (
sOpt ==
"sensitivity") {
1039 if (
sOpt ==
"floating") {
1041 auto floats = std::unique_ptr<RooAbsCollection>(
_pars->selectByAttrib(
"Constant",
false));
1064 if (
auto a =
_pars->find(s);
a)
1068 if (vars.
size() == 1) {
1074 bad->SetMarkerStyle(5);
1076 bool normRange =
false;
1084 out->SetName(
get()->GetName());
1090 double step = (
v->getMax() -
v->getMin()) / 100;
1091 double init =
v->getVal();
1094 auto currTime = std::chrono::steady_clock::now();
1095 while (out->GetN() < 100 && (low >
v->getMin() ||
high < v->getMax())) {
1096 if (out->GetN() == 0) {
1097 out->SetPoint(out->GetN(), low, 0);
1106 if (low >
v->getMin()) {
1108 auto _v =
func()->getVal();
1109 if (std::isnan(
_v) || std::isinf(
_v)) {
1110 if (
bad->GetN() == 0)
1112 bad->SetPoint(
bad->GetN(), low, out->GetPointY(0));
1114 out->SetPoint(out->GetN(), low,
_v -
initVal);
1120 auto _v =
func()->getVal();
1121 if (std::isnan(
_v) || std::isinf(
_v)) {
1122 if (
bad->GetN() == 0)
1124 bad->SetPoint(
bad->GetN(), high, out->GetPointY(0));
1126 out->SetPoint(out->GetN(), high,
_v -
initVal);
1133 if (std::chrono::steady_clock::now() -
currTime > std::chrono::seconds(1)) {
1134 currTime = std::chrono::steady_clock::now();
1143#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
1144 gPad->GetCanvas()->ResetUpdated();
1149 Error(
"Draw",
"Name a parameter to scan over: Draw(<name>) , choose from: %s",
1150 _pars->empty() ?
"" :
_pars->contentsString().c_str());
1164 return setData(std::dynamic_pointer_cast<RooAbsData>(
data.fComp),
1165 std::shared_ptr<const RooAbsCollection>(
data.globs().argList().snapshot()));
1168bool xRooNLLVar::setData(
const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &_data)
1171 if (
fData == _data.first &&
fGlobs == _data.second)
1176 auto _dglobs = (_data.second) ? _data.second
1177 : std::shared_ptr<const RooAbsCollection>(_data.first->getGlobalObservables(),
1184 throw std::runtime_error(
"Missing globs");
1195 rC.remove(*std::unique_ptr<RooAbsCollection>(
rC.selectCommon(*
_actualGlobs)));
1201 throw std::runtime_error(
TString::Format(
"globs mismatch: adding %s removing %s",
r.Data(),
l.Data()));
1206 if (!std::shared_ptr<RooAbsReal>::get()) {
1207 fData = _data.first;
1220 fFuncVars->setAttribAll(
"Constant",
false);
1224 fData = _data.first;
1245 fData = _data.first;
1247 }
catch (std::runtime_error &) {
1252 fFuncVars->setAttribAll(
"Constant",
false);
1256 fData = _data.first;
1260 throw std::runtime_error(
"Unable to setData");
1267 }
else if (
auto f = std::unique_ptr<RooAbsCollection>(
fConstVars->selectByAttrib(
"Constant",
false)); !
f->empty()) {
1290 if (std::shared_ptr<RooAbsReal>::get()) {
1362 return fData->sumEntries() * log(1.0 * (s->servers().size() - 1));
1374 for (
int i = 0; i <
fData->numEntries(); i++) {
1384 auto _func =
func();
1387 for (
auto s : _func->servers()) {
1391 for (
auto s2 : s->servers()) {
1418 : std::numeric_limits<double>::quiet_NaN();
1431 if (getVal(
sWhat +
" readonly").second != 0) {
1432 if (
sWhat.Contains(
"toys=")) {
1441 if (nullToys.size() <
nToys) {
1442 addNullToys(
nToys - nullToys.size());
1445 addAltToys(
nToysAlt - altToys.size());
1449 addCLsToys(100, 0, 0.05,
nSigma);
1451 throw std::runtime_error(
"Auto-generating toys for anything other than CLs not yet supported, please specify number of toys with 'toys=N' ");
1459 if (
rr && var && var->get()) {
1460 _readOnly = var->get()->getAttribute(
"readOnly");
1461 var->get()->setAttribute(
"readOnly",
rr);
1469 var->get()->setAttribute(
"readOnly",
_readOnly);
1475 std::shared_ptr<xRooNLLVar> &var;
1489 throw std::runtime_error(std::string(
"Unknown: ") +
what);
1496 out.add(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1503 out.setName(
"alt_poi");
1504 out.addClone(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1505 for (
auto a : out) {
1509 if (
auto s =
a->getStringAttribute(
"altVal"); s &&
strlen(s)) {
1512 v->setVal(std::numeric_limits<double>::quiet_NaN());
1522 if (me.ufit(
true) && !allowedStatusCodes.count(me.ufit(
true)->status()))
1524 if (me.cfit_null(
true) && !allowedStatusCodes.count(me.cfit_null(
true)->status()))
1526 if (me.cfit_alt(
true) && !allowedStatusCodes.count(me.cfit_alt(
true)->status()))
1528 if (me.asimov(
true))
1529 out += me.asimov(
true)->status() << 3;
1537 std::cout <<
"POI: " << _poi.contentsString() <<
" , null: ";
1539 for (
auto a : _poi) {
1548 std::cout <<
" , alt: ";
1559 if (!std::isnan(
v->getVal()))
1562 std::cout <<
" , pllType: " << fPllType << std::endl;
1564 std::cout <<
" - ufit: ";
1566 std::cout << fUfit->GetName() <<
" " << fUfit->minNll() <<
" (status=" << fUfit->status() <<
") (";
1568 for (
auto a : _poi) {
1569 auto v =
dynamic_cast<RooRealVar *
>(fUfit->floatParsFinal().find(
a->GetName()));
1574 std::cout <<
v->
GetName() <<
"_hat: " <<
v->getVal() <<
" +/- " <<
v->getError();
1577 std::cout <<
")" << std::endl;
1579 std::cout <<
"Not calculated" << std::endl;
1581 std::cout <<
" - cfit_null: ";
1583 std::cout << fNull_cfit->GetName() <<
" " << fNull_cfit->minNll() <<
" (status=" << fNull_cfit->status() <<
")";
1585 std::cout <<
"Not calculated";
1588 std::cout << std::endl <<
" - cfit_alt: ";
1590 std::cout << fAlt_cfit->GetName() <<
" " << fAlt_cfit->minNll() <<
" (status=" << fAlt_cfit->status() <<
")"
1593 std::cout <<
"Not calculated" << std::endl;
1595 std::cout <<
" sigma_mu: ";
1597 if (!fAsimov || !fAsimov->fUfit || !fAsimov->fNull_cfit) {
1598 std::cout <<
"Not calculated";
1600 std::cout << const_cast<xRooHypoPoint *>(
this)->
sigma_mu().first <<
" +/- "
1604 std::cout << std::endl;
1605 std::cout <<
" - asimov ufit: ";
1606 if (fAsimov->fUfit) {
1607 std::cout << fAsimov->
fUfit->GetName() <<
" " << fAsimov->fUfit->minNll()
1608 <<
" (status=" << fAsimov->fUfit->status() <<
")";
1610 std::cout <<
"Not calculated";
1612 std::cout << std::endl <<
" - asimov cfit_null: ";
1613 if (fAsimov->fNull_cfit) {
1614 std::cout << fAsimov->fNull_cfit->GetName() <<
" " << fAsimov->fNull_cfit->minNll()
1615 <<
" (status=" << fAsimov->fNull_cfit->status() <<
")";
1617 std::cout <<
"Not calculated";
1620 std::cout << std::endl;
1622 std::cout << std::endl;
1625 std::cout <<
" - cfit_lbound: " << fLbound_cfit->GetName() <<
" " << fLbound_cfit->minNll()
1626 <<
" (status=" << fLbound_cfit->status() <<
")";
1629 std::cout <<
" - gfit: " << fGenFit->GetName() << std::endl;
1630 if (!nullToys.empty() || !altToys.empty()) {
1631 std::cout <<
" * null toys: " << nullToys.size();
1633 while (
firstToy < nullToys.size() && std::isnan(std::get<1>(nullToys[
firstToy])))
1636 std::cout <<
" [ of which " <<
firstToy <<
" are bad]";
1637 std::cout <<
" , alt toys: " << altToys.size();
1639 while (
firstToy < altToys.size() && std::isnan(std::get<1>(altToys[
firstToy])))
1642 std::cout <<
" [ of which " <<
firstToy <<
" are bad]";
1643 std::cout << std::endl;
1651 auto var =
dynamic_cast<RooRealVar *
>(ufit()->floatParsFinal().find(fPOIName()));
1655 throw std::runtime_error(
TString::Format(
"Cannot find POI: %s", fPOIName()));
1658 throw std::runtime_error(
"Unconditional fit unavailable");
1665 if (fGenFit && isExpected) {
1673 : hypoTestResult(
htr)
1685 if (
toys->getGlobalObservables()) {
1686 coords = std::shared_ptr<RooAbsCollection>(
toys->getGlobalObservables()->snapshot());
1688 for (
int i = 0; i <
toys->numEntries(); i++) {
1691 std::make_tuple(
int(
toy->getRealValue(
"seed")),
toy->getRealValue(
"ts"),
toys->weight()));
1696 for (
int i = 0; i <
toys->numEntries(); i++) {
1699 std::make_tuple(
int(
toy->getRealValue(
"seed")),
toy->getRealValue(
"ts"),
toys->weight()));
1710 if (!fAsimov && (nllVar || hypoTestResult)) {
1711 auto theFit = (!
fData.first && fGenFit && !isExpected)
1716 if (!
theFit || allowedStatusCodes.find(
theFit->status()) == allowedStatusCodes.
end())
1718 fAsimov = std::make_shared<xRooHypoPoint>(*
this);
1719 fAsimov->coords.reset(fAsimov->coords->snapshot());
1720 fAsimov->hypoTestResult.reset();
1722 for (
auto p : fAsimov->poi()) {
1725 v->deleteSharedProperties();
1729 fAsimov->nullToys.clear();
1730 fAsimov->altToys.clear();
1731 fAsimov->fUfit = retrieveFit(3);
1732 fAsimov->fNull_cfit = retrieveFit(4);
1733 fAsimov->fAlt_cfit.reset();
1735 std::make_pair(
nullptr,
nullptr);
1736 fAsimov->fGenFit =
theFit;
1737 fAsimov->isExpected =
true;
1746 return std::pair<double, double>(1, 0);
1749 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1759 return std::pair(
nom, std::max(std::abs(
up -
nom), std::abs(
down -
nom)));
1765 return std::pair<double, double>(1, 0);
1768 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1779 return std::pair(
nom, std::max(std::abs(
up -
nom), std::abs(
down -
nom)));
1784 if (fNullVal() == fAltVal())
1785 return std::pair<double, double>(1, 0);
1788 return std::pair<double, double>(1, 0);
1791 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1816 return std::pair(
nom, std::max(std::abs(
up -
nom), std::abs(
down -
nom)));
1826 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1835 return std::pair<double, double>(
nom, std::max(std::abs(
nom -
up), std::abs(
nom -
down)));
1844 while (
firstToy < altToys.size() && std::isnan(std::get<1>(altToys[
firstToy])))
1847 return std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
1850 return std::pair(std::get<1>(altToys[
targetIdx]), (std::get<1>(altToys[std::min(
int(altToys.size()),
targetIdx)]) -
1851 std::get<1>(altToys[std::max(0,
targetIdx)])) /
1860 return std::pair<double, double>(hypoTestResult->GetTestStatisticData(), 0);
1861 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1863 if (allowedStatusCodes.find(
_ufit->status()) == allowedStatusCodes.end()) {
1864 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1868 mu_hat().getVal() <
_first_poi->getMin(
"physical")) {
1872 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1879 return std::pair<double, double>(0, 0);
1880 if (!cfit_null(
readOnly) || allowedStatusCodes.find(cfit_null(
readOnly)->status()) == allowedStatusCodes.end())
1881 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1883 return std::pair<double, double>(2. * cFactor * (cfit_null(
readOnly)->minNll() -
_ufit->minNll()),
1884 2. * cFactor * sqrt(pow(cfit_null(
readOnly)->edm(), 2) + pow(
_ufit->edm(), 2)));
1890 if (!hypoTestResult)
1893 if (
auto fits = hypoTestResult->GetFitInfo()) {
1894 for (
int i = 0; i <
fits->numEntries(); i++) {
1895 auto fit =
fits->get(i);
1896 if (fit->getCatIndex(
"type") !=
type)
1900 fits->getGlobalObservables()->getStringValue(
TString::Format(
"%s.name", fit->getCatLabel(
"type")));
1903 for (
auto file : *
gROOT->GetListOfFiles()) {
1907 k->GetMotherDir()->GetList()
1921 rfit->setStatus(fit->getRealValue(
"status"));
1922 rfit->setMinNLL(fit->getRealValue(
"minNll"));
1923 rfit->setEDM(fit->getRealValue(
"edm"));
1925 std::unique_ptr<RooAbsCollection>
par_hats(
1926 hypoTestResult->GetFitInfo()->getGlobalObservables()->selectByName(coords->contentsString().c_str()));
1927 par_hats->setName(
"floatParsFinal");
1935 rfit->setCovarianceMatrix(
cov);
1936 rfit->setCovQual(fit->getRealValue(
"covQual"));
1947 if (
auto rfit = retrieveFit(0)) {
1948 return fUfit =
rfit;
1950 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1952 if (!nllVar->fFuncVars)
1953 nllVar->reinitialize();
1956 if (!
readOnly && isExpected && fGenFit) {
1958 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1959 nllVar->get()->setAttribute(
"readOnly");
1960 auto out = ufit(
true);
1961 nllVar->get()->setAttribute(
"readOnly", tmp);
1966 nllVar->setData(
data());
1969 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1970 nllVar->setData(
fData);
1972 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1973 *nllVar->fFuncVars = *coords;
1974 if (nllVar->fFuncGlobs)
1975 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1976 std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))
1977 ->setAttribAll(
"Constant",
false);
1980 nllVar->fFuncVars->assignValueOnly(fGenFit->constPars());
1981 nllVar->fFuncVars->assignValueOnly(fGenFit->floatParsFinal());
1983 nllVar->get()->SetName(
1984 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1986 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1988 }
else if (!std::isnan(fAltVal())) {
1993 _poi->
setVal(_poi->getStringAttribute(
"initVal") ?
TString(_poi->getStringAttribute(
"initVal")).
Atof()
1998 return (fUfit = nllVar->minimize());
2004 for (
auto &
c :
coll) {
2007 out +=
c->GetName();
2023 if (
auto rfit = retrieveFit(1)) {
2024 return fNull_cfit =
rfit;
2026 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2028 if (!nllVar->fFuncVars)
2029 nllVar->reinitialize();
2032 if (!
readOnly && isExpected && fGenFit) {
2034 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2035 nllVar->get()->setAttribute(
"readOnly");
2036 auto out = cfit_null(
true);
2037 nllVar->get()->setAttribute(
"readOnly", tmp);
2042 nllVar->setData(
data());
2045 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2046 nllVar->setData(
fData);
2050 *nllVar->fFuncVars = fUfit->floatParsFinal();
2052 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2053 *nllVar->fFuncVars = *coords;
2054 if (nllVar->fFuncGlobs)
2055 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2057 nllVar->fFuncVars->find(fPOIName())
2058 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2061 nllVar->get()->SetName(
2062 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2064 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2066 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(poi()).c_str());
2067 return (fNull_cfit = nllVar->minimize());
2078 return fLbound_cfit;
2079 if (
auto rfit = retrieveFit(6)) {
2080 return fLbound_cfit =
rfit;
2082 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2084 if (!nllVar->fFuncVars)
2085 nllVar->reinitialize();
2088 if (!
readOnly && isExpected && fGenFit) {
2090 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2091 nllVar->get()->setAttribute(
"readOnly");
2092 auto out = cfit_lbound(
true);
2093 nllVar->get()->setAttribute(
"readOnly", tmp);
2098 nllVar->setData(
data());
2101 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2102 nllVar->setData(
fData);
2106 *nllVar->fFuncVars = fUfit->floatParsFinal();
2108 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2109 *nllVar->fFuncVars = *coords;
2111 if (nllVar->fFuncGlobs)
2112 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2114 nllVar->fFuncVars->find(fPOIName())
2115 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2118 nllVar->get()->SetName(
2119 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2121 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2123 nllVar->get()->setStringAttribute(
2125 collectionContents(*std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))).c_str());
2126 return (fLbound_cfit = nllVar->minimize());
2131 if (std::isnan(fAltVal()))
2135 if (
auto rfit = retrieveFit(2)) {
2136 return fAlt_cfit =
rfit;
2138 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2140 if (!nllVar->fFuncVars)
2141 nllVar->reinitialize();
2144 if (!
readOnly && isExpected && fGenFit) {
2146 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2147 nllVar->get()->setAttribute(
"readOnly");
2148 auto out = cfit_alt(
true);
2149 nllVar->get()->setAttribute(
"readOnly", tmp);
2154 nllVar->setData(
data());
2157 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2158 nllVar->setData(
fData);
2162 *nllVar->fFuncVars = fUfit->floatParsFinal();
2164 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2165 *nllVar->fFuncVars = *coords;
2166 if (nllVar->fFuncGlobs)
2167 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2168 *nllVar->fFuncVars = alt_poi();
2170 nllVar->get()->SetName(
2171 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2173 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2175 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(alt_poi()).c_str());
2176 return (fAlt_cfit = nllVar->minimize());
2185 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
2189 return std::pair<double, double>(std::abs(fNullVal() - fAltVal()) / sqrt(out.first),
2190 out.second * 0.5 * std::abs(fNullVal() - fAltVal()) /
2191 (out.first * sqrt(out.first)));
2197 if (std::isnan(
_ts.first))
2200 return std::pair<double, double>(1, 0);
2207 return std::pair(0.5, std::numeric_limits<double>::infinity());
2217 if (std::isnan(std::get<1>(
toy))) {
2220 bool res = std::get<1>(
toy) >=
_ts.first;
2221 if (std::get<2>(
toy) != 1) {
2228 if (std::get<1>(
toy) >=
_ts.first -
_ts.second)
2230 if (std::get<1>(
toy) >=
_ts.first -
_ts.second)
2252 return pX_toys(
false,
nSigma);
2257 if (!std::isnan(
nSigma)) {
2260 return pX_toys(
true,
nSigma);
2266 out.coords = coords;
2267 out.fPllType = fPllType;
2268 out.nllVar = nllVar;
2271 auto _cfit = cfit_null();
2274 if (!nllVar->fFuncVars)
2275 nllVar->reinitialize();
2279 out.fGenFit =
_cfit;
2286 out.coords = coords;
2287 out.fPllType = fPllType;
2288 out.nllVar = nllVar;
2293 if (!nllVar->fFuncVars)
2294 nllVar->reinitialize();
2299 out.fGenFit = cfit_alt();
2306 if ((
alt && !cfit_alt()) || (!
alt && !cfit_null())) {
2307 throw std::runtime_error(
"Cannot add toys, invalid conditional fit");
2310 auto condition = [&]() {
2314 if (!std::isnan(obs.first)) {
2316 double err = obs.second;
2337 throw std::runtime_error(
"Cannot target obs p-value because ts value unavailable");
2345 Info(
"addToys",
"First generating 100 alt toys in order to determine expected ts value");
2349 throw std::runtime_error(
"Unable to determine expected ts value");
2374 auto &
toys = (
alt) ? altToys : nullToys;
2380 if (!std::isnan(
target) && !condition()) {
2388 for (
size_t i = 0; i <
nnToys; i++) {
2390 auto toy = ((
alt) ? generateAlt(seed) : generateNull(seed));
2393 toys.push_back(std::make_tuple(seed,
toy.pll().first, 1.));
2396 if (std::isnan(std::get<1>(
toys.back())))
2402 <<
TString::Format(
"Generated %d/%d %s hypothesis toys [%.2f toys/s]",
2405 if (!std::isnan(
target)) {
2409 std::cout <<
"..." << std::flush;
2412 if(!
gROOT->IsBatch()) {
2416#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2417 gPad->GetCanvas()->ResetUpdated();
2430 for (
auto &t :
toys) {
2431 if (std::isnan(std::get<1>(t)))
2432 std::get<1>(t) = -std::numeric_limits<double>::infinity();
2435 [](
const decltype(nullToys)::value_type &
a,
const decltype(nullToys)::value_type &
b) ->
bool {
2436 if (std::isnan(std::get<1>(a)))
2438 if (std::isnan(std::get<1>(b)))
2440 return std::get<1>(a) < std::get<1>(b);
2442 for (
auto &t :
toys) {
2443 if (std::isinf(std::get<1>(t)))
2444 std::get<1>(t) = std::numeric_limits<double>::quiet_NaN();
2446 if (std::isnan(
target)) {
2453 }
while (condition());
2456 <<
"Finished Generating ";
2465 if(!
gROOT->IsBatch()) {
2469#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2470 gPad->GetCanvas()->ResetUpdated();
2478 std::cout <<
"Warning: " <<
nans <<
" toys were bad" << std::endl;
2555 out.nllVar = std::make_shared<xRooNLLVar>(*
this);
2560 while (pattern.NextToken()) {
2563 double val = std::numeric_limits<double>::quiet_NaN();
2564 auto i = s.
Index(
"=");
2568 if (!
cVal.IsFloat())
2569 throw std::runtime_error(
"poiValues must contain value");
2574 throw std::runtime_error(
"Cannot find poi");
2575 if (!std::isnan(val))
2584 throw std::runtime_error(
"No poi");
2589 if (!
static_cast<RooRealVar *
>(
b)->hasRange(
"physical")) {
2590 static_cast<RooRealVar *
>(
b)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2594 auto _snap = std::unique_ptr<RooAbsCollection>(
fFuncVars->selectByAttrib(
"Constant",
true))->snapshot();
2595 _snap->setAttribAll(
"poi",
false);
2596 std::unique_ptr<RooAbsCollection> _poi(
_snap->selectByName(
poiNames));
2597 _poi->setAttribAll(
"poi",
true);
2599 for (
auto a : *_poi)
2600 a->setStringAttribute(
"altVal", nullptr);
2602 for (
auto a : *_poi)
2621 out.fPllType = _type;
2626xRooNLLVar::xRooHypoPoint
2632 std::unique_ptr<RooAbsCollection> _poi(
fFuncVars->selectByAttrib(
"poi",
true));
2633 if (_poi->empty()) {
2634 throw std::runtime_error(
"No POI specified in model");
2635 }
else if (_poi->size() != 1) {
2636 throw std::runtime_error(
"Multiple POI specified in model");
2650 if (!nllVar && !hypoTestResult)
2656 sOpt.ReplaceAll(
"same",
"");
2664 if (
gPad->GetNumber() == 0) {
2680 hAxis =
dynamic_cast<TH1 *
>(
pad->GetPrimitive(
".axis"));
2682 for (
auto o : *
pad->GetListOfPrimitives()) {
2690 double _min = std::numeric_limits<double>::quiet_NaN();
2691 double _max = -std::numeric_limits<double>::quiet_NaN();
2693 for (
auto &
p : nullToys) {
2694 if (std::get<2>(
p) == 0)
2696 if (std::isnan(std::get<1>(
p)))
2699 _max = std::max(std::get<1>(
p), _max);
2701 for (
auto &
p : altToys) {
2702 if (std::get<2>(
p) == 0)
2704 if (std::isnan(std::get<1>(
p)))
2707 _max = std::max(std::get<1>(
p), _max);
2711 if (!std::isnan(obs.first)) {
2712 _min = std::min(obs.first - std::abs(obs.first) * 0.1,
_min);
2713 _max = std::max(obs.first + std::abs(obs.first) * 0.1, _max);
2716 auto pNull = pNull_toys();
2717 auto pAlt = pAlt_toys();
2718 auto pNullA = pNull_asymp();
2719 auto pAltA = pAlt_asymp();
2721 auto asi = (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit) ? fAsimov->pll().first
2722 : std::numeric_limits<double>::quiet_NaN();
2726 _max = std::max(
asi + std::abs(
asi), _max);
2731 auto _poi =
dynamic_cast<RooRealVar *
>(poi().first());
2735 auto h =
new TH1D((
isAlt) ?
"alt_toys" :
"null_toys",
"", 100,
_min, _max + (_max -
_min) * 0.01);
2736 h->SetDirectory(
nullptr);
2738 for (
auto &
p : (
isAlt) ? altToys : nullToys) {
2739 double w = std::isnan(std::get<1>(
p)) ? 0 : std::get<2>(
p);
2742 if (!std::isnan(std::get<1>(
p)))
2743 h->Fill(std::get<1>(
p),
w);
2745 if (
h->GetEntries() > 0)
2746 h->Scale(1. /
h->Integral(0,
h->GetNbinsX() + 1));
2770 h->SetMarkerSize(0);
2782 auto axis =
static_cast<TH1 *
>(
h->Clone(
".axis"));
2784 axis->SetStats(
false);
2785 axis->Reset(
"ICES");
2787 axis->SetLineWidth(0);
2789 axis->SetMinimum(1
e-7);
2790 axis->GetYaxis()->SetRangeUser(1
e-7, 10);
2791 axis->SetMaximum(
h->GetMaximum());
2793 l =
new TLegend(0.4, 0.7, 1. -
gPad->GetRightMargin(), 1. -
gPad->GetTopMargin());
2794 l->SetName(
"legend");
2796 l->SetBorderSize(0);
2799 l->ConvertNDCtoPad();
2801 for (
auto o : *
gPad->GetListOfPrimitives()) {
2808 if (
h->GetEntries() > 0) {
2811 h->Draw(
"axissame");
2814 if (
h->GetEntries() > 0) {
2817 h->Draw(
"axissame");
2825 if (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit && !std::isnan(sigma_mu().first) && !std::isnan(fAltVal())) {
2826 auto hh =
static_cast<TH1 *
>(
nullHist->Clone(
"null_asymp"));
2828 hh->SetStats(
false);
2829 hh->SetLineStyle(2);
2831 for (
int i = 1; i <=
hh->GetNbinsX(); i++) {
2834 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2836 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2841 hh->SetStats(
false);
2842 hh->SetLineStyle(2);
2844 for (
int i = 1; i <=
hh->GetNbinsX(); i++) {
2847 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2849 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2859 auto tl = ll.
DrawLine(obs.first,
hAxis->GetMinimum(), obs.first, 0.1);
2864 l->AddEntry(
tl, label,
"l");
2867 auto pCLs = pCLs_toys();
2868 label +=
" p_{toy}=(";
2873 if (label.Length() > 0)
2874 l->AddEntry(
"", label,
"");
2876 if (!std::isnan(
pNullA.first) || !std::isnan(
pAltA.first)) {
2877 auto pCLs = pCLs_asymp();
2878 label +=
" p_{asymp}=(";
2883 if (label.Length() > 0)
2884 l->AddEntry(
"", label,
"");
2886 if (
auto ax =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
".axis")))
2887 ax->GetYaxis()->SetRangeUser(1
e-7, 1);
2892 auto v =
dynamic_cast<RooRealVar *
>(poi().empty() ? nullptr : poi().first());
2894 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2904 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2914 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2924 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2933 return "Test Statistic";
2939 return (poi().empty()) ? nullptr : (poi().first())->GetName();
2944 return (
first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() :
first_poi->getVal();
2950 return (
first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() :
first_poi->getVal();
2959 double alt_val = std::numeric_limits<double>::quiet_NaN();
2972 for (
auto p : out.poi()) {
2974 dynamic_cast<RooRealVar *
>(
p)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2975 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [0,inf]",
p->GetName());
2976 }
else if (
dynamic_cast<RooRealVar *
>(
p)->hasRange(
"physical")) {
2977 dynamic_cast<RooRealVar *
>(
p)->removeRange(
"physical");
2978 Info(
"xRooNLLVar::hypoSpace",
"Removing physical range of %s",
2993 if (
int(low + 0.5) > 0) {
2996 if (!std::isnan(high) && !std::isnan(
alt_value) && !(std::isinf(high) && std::isinf(
alt_value))) {
2997 for (
auto p : out.poi()) {
3009 if (!std::isnan(low) && !std::isnan(high) && !(std::isinf(low) && std::isinf(high))) {
3010 for (
auto p :
hs.poi()) {
3011 dynamic_cast<RooRealVar *
>(
p)->setRange(
"scan", low, high);
3021 auto _poi = std::unique_ptr<RooAbsCollection>(
3022 std::unique_ptr<RooAbsCollection>(
pdf()->getVariables())->selectByAttrib(
"poi",
true));
3024 throw std::runtime_error(
"You must specify a POI for the hypoSpace");
3035 std::unique_ptr<RooAbsCollection> axes(s.
pars()->selectByName(
parName));
3037 throw std::runtime_error(
"parameter not found");
3038 axes->setAttribAll(
"axis",
true);
3043 s.
fNlls[s.
fPdfs.begin()->second] = std::make_shared<xRooNLLVar>(*
this);
3046 for (
auto poi : s.
poi()) {
3055 if (hypoTestResult) {
3056 return *hypoTestResult;
3059 out.SetBackgroundAsAlt(
true);
3060 out.SetName(
TUUID().AsString());
3064 if (nllVar && !nllVar->get()->getAttribute(
"readOnly")) {
3066 nllVar->get()->setAttribute(
"readOnly");
3069 auto ts_obs = ts_asymp();
3071 out.SetTestStatisticData(
ts_obs.first);
3078 "pllType",
"test statistic type",
3079 {{
"TwoSided", 0}, {
"OneSidedPositive", 1}, {
"OneSidedNegative", 2}, {
"Uncapped", 3}, {
"Unknown", 4}}));
3081 fitMeta.addClone(ufit()->floatParsFinal());
3083 fitMeta.setCatIndex(
"pllType",
int(fPllType));
3090 {
"asimov_cfit_null", 4},
3092 {
"cfit_lbound", 6}}));
3102 for (
int i = 0; i < 7; i++) {
3103 std::shared_ptr<const RooFitResult> fit;
3105 case 0: fit = ufit();
break;
3106 case 1: fit = cfit_null();
break;
3107 case 2: fit = cfit_alt();
break;
3108 case 3: fit = asimov() ? asimov()->ufit(
true) :
nullptr;
break;
3109 case 4: fit = asimov() ? asimov()->cfit_null(
true) :
nullptr;
break;
3110 case 5: fit = fGenFit;
break;
3111 case 6: fit = cfit_lbound();
break;
3116 fitDetails.getCatLabel(
"type"), fit->GetName()));
3118 fitDetails.setRealValue(
"status", fit->status());
3119 fitDetails.setRealValue(
"minNll", fit->minNll());
3121 fitDetails.setRealValue(
"covQual", fit->covQual());
3127 out.SetFitInfo(
fitDS);
3137 if (!nullToys.empty()) {
3139 std::vector<double> values;
3140 std::vector<double> weights;
3141 values.reserve(nullToys.size());
3142 weights.reserve(nullToys.size());
3144 for (
auto &t : nullToys) {
3145 values.push_back(std::get<1>(t));
3146 weights.push_back(std::get<2>(t));
3152#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3153 out.fNullPValue = pNull_toys().first;
3154 out.fNullPValueError =
3155 pNull_toys().second;
3157 out.SetNullPValue(pNull_toys().first);
3158 out.SetNullPValueError(
3159 pNull_toys().second);
3162#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3163 out.fNullPValue = pNull_asymp().first;
3164 out.fNullPValueError = pNull_asymp().second;
3166 out.SetNullPValue(pNull_asymp().first);
3167 out.SetNullPValueError(pNull_asymp().second);
3172 if (!altToys.empty()) {
3173 std::vector<double> values;
3174 std::vector<double> weights;
3175 values.reserve(altToys.size());
3176 weights.reserve(altToys.size());
3184 for (
auto &t : altToys) {
3185 values.push_back(std::get<1>(t));
3186 weights.push_back(std::get<2>(t));
3187 altDetails.setRealValue(
"seed", std::get<0>(t));
3188 altDetails.setRealValue(
"ts", std::get<1>(t));
3192 out.SetAltDetailedOutput(
altToyDS);
3193#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3194 out.fAlternatePValue = pAlt_toys().first;
3195 out.fAlternatePValueError =
3198 out.SetAltPValue(pAlt_toys().first);
3199 out.SetAltPValueError(
3200 pAlt_toys().second);
3204#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3205 out.fAlternatePValue = pAlt_asymp().first;
3206 out.fAlternatePValueError = pAlt_asymp().second;
3208 out.SetAltPValue(pAlt_asymp().first);
3209 out.SetAltPValueError(pAlt_asymp().second);
3214 nllVar->get()->setAttribute(
"readOnly",
false);
3223 return "xValueWithError: nullptr\n";
3224 return Form(
"%f +/- %f",
v->first,
v->second);
3226std::string cling::printValue(
const std::map<std::string, xRooNLLVar::xValueWithError> *
m)
3230 std::string out =
"{\n";
3231 for (
auto [k,
v] : *
m) {
3232 out +=
"\"" + k +
"\" => " + printValue(&
v) +
"\n";
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
winID h TVirtualViewer3D TVirtualGLPainter p
winID h TVirtualViewer3D vv
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
static char * Format(const char *format, va_list ap)
Format a string in a circular formatting buffer (using a printf style format descriptor).
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
R__EXTERN TStyle * gStyle
R__EXTERN TSystem * gSystem
AutoRestorer(const RooAbsCollection &s, xRooNLLVar *nll=nullptr)
std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > fOldData
std::unique_ptr< RooAbsCollection > fSnap
static double k(const IncompatFunc &compatRegions, double pValue, double poiVal, double poiPrimeVal, double sigma_mu=0, double mu_low=-std::numeric_limits< double >::infinity(), double mu_high=std::numeric_limits< double >::infinity())
static int CompatFactor(const IncompatFunc &func, double mu_hat)
static double PValue(const IncompatFunc &compatRegions, double k, double mu, double mu_prime, double sigma_mu=0, double mu_low=-std::numeric_limits< double >::infinity(), double mu_high=std::numeric_limits< double >::infinity())
static std::shared_ptr< const RooFitResult > minimize(RooAbsReal &nll, const std::shared_ptr< ROOT::Fit::FitConfig > &fitConfig=nullptr, const std::shared_ptr< RooLinkedList > &nllOpts=nullptr)
static std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > generateFrom(RooAbsPdf &pdf, const RooFitResult &fr, bool expected=false, int seed=0)
static std::shared_ptr< ROOT::Fit::FitConfig > createFitConfig()
double impact(const char *poi, const char *np, bool up=true, bool prefit=false, bool approx=false)
const RooFitResult * operator->() const
void Draw(Option_t *opt="")
xRooFitResult ifit(const char *np, bool up, bool prefit=false)
double conditionalError(const char *poi, const char *nps, bool up=true, bool approx=false)
RooArgList ranknp(const char *poi, bool up=true, bool prefit=false, double approxThreshold=std::numeric_limits< double >::infinity())
xRooFitResult(const RooFitResult &fr)
xRooFitResult cfit(const char *poiValues, const char *alias=nullptr)
xValueWithError pll(bool readOnly=false)
std::shared_ptr< RooStats::HypoTestResult > hypoTestResult
RooStats::HypoTestResult result()
std::shared_ptr< const RooFitResult > retrieveFit(int type)
std::vector< std::tuple< int, double, double > > altToys
std::shared_ptr< const RooAbsCollection > coords
std::shared_ptr< const RooFitResult > cfit_lbound(bool readOnly=false)
void Draw(Option_t *opt="") override
Default Draw method for all objects.
TString tsTitle(bool inWords=false) const
xValueWithError ts_toys(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::shared_ptr< const RooFitResult > fUfit
xRooHypoPoint(std::shared_ptr< RooStats::HypoTestResult > htr=nullptr, const RooAbsCollection *_coords=nullptr)
xRooFit::Asymptotics::PLLType fPllType
xValueWithError sigma_mu(bool readOnly=false)
xValueWithError pAlt_asymp(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::vector< std::tuple< int, double, double > > nullToys
std::shared_ptr< xRooHypoPoint > asimov(bool readOnly=false)
xValueWithError pAlt_toys(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::shared_ptr< const RooFitResult > ufit(bool readOnly=false)
void Print(Option_t *opt="") const override
Print TNamed name and title.
std::shared_ptr< const RooFitResult > cfit_null(bool readOnly=false)
std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > data()
xRooHypoPoint generateNull(int seed=0)
RooArgList alt_poi() const
xValueWithError pCLs_asymp(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::shared_ptr< const RooFitResult > cfit_alt(bool readOnly=false)
size_t addToys(bool alt, int nToys, int initialSeed=0, double target=std::numeric_limits< double >::quiet_NaN(), double target_nSigma=std::numeric_limits< double >::quiet_NaN(), bool targetCLs=false, double relErrThreshold=2., size_t maxToys=10000)
void addAltToys(int nToys=1, int seed=0, double target=std::numeric_limits< double >::quiet_NaN(), double target_nSigma=std::numeric_limits< double >::quiet_NaN())
void addCLsToys(int nToys=1, int seed=0, double target=std::numeric_limits< double >::quiet_NaN(), double target_nSigma=std::numeric_limits< double >::quiet_NaN())
xRooHypoPoint generateAlt(int seed=0)
xValueWithError pX_toys(bool alt, double nSigma=std::numeric_limits< double >::quiet_NaN())
void addNullToys(int nToys=1, int seed=0, double target=std::numeric_limits< double >::quiet_NaN(), double target_nSigma=std::numeric_limits< double >::quiet_NaN())
xValueWithError ts_asymp(double nSigma=std::numeric_limits< double >::quiet_NaN())
xValueWithError getVal(const char *what)
xValueWithError pNull_asymp(double nSigma=std::numeric_limits< double >::quiet_NaN())
xValueWithError pNull_toys(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::shared_ptr< RooArgSet > pars() const
xRooFit::Asymptotics::PLLType fTestStatType
bool AddModel(const xRooNode &pdf, const char *validity="")
std::map< std::shared_ptr< xRooNode >, std::shared_ptr< xRooNLLVar > > fNlls
std::set< std::pair< std::shared_ptr< RooArgList >, std::shared_ptr< xRooNode > > > fPdfs
This xRooNLLVar object has several special methods, e.g.
std::shared_ptr< RooAbsCollection > fFuncGlobs
void AddOption(const RooCmdArg &opt)
double binnedDataTermVal() const
double saturatedConstraintTermVal() const
std::shared_ptr< const RooAbsCollection > fGlobs
std::shared_ptr< RooLinkedList > fOpts
std::shared_ptr< RooAbsReal > func() const
RooAbsData * data() const
std::set< std::string > binnedChannels() const
ROOT::Math::IOptions * fitConfigOptions()
RooConstraintSum * constraintTerm() const
std::shared_ptr< ROOT::Fit::FitConfig > fFitConfig
xRooHypoSpace hypoSpace(const char *parName, int nPoints, double low, double high, double alt_value=std::numeric_limits< double >::quiet_NaN(), const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown)
TObject * Scan(const RooArgList &scanPars, const std::vector< std::vector< double > > &coords, const RooArgList &profilePars=RooArgList())
std::shared_ptr< RooAbsCollection > fConstVars
xRooNLLVar(RooAbsPdf &pdf, const std::pair< RooAbsData *, const RooAbsCollection * > &data, const RooLinkedList &nllOpts=RooLinkedList())
std::shared_ptr< RooAbsPdf > pdf() const
double mainTermPgof() const
double extendedTermVal() const
double constraintTermVal() const
double simTermVal() const
void Print(Option_t *opt="")
std::string fFuncCreationLog
void Draw(Option_t *opt="")
double saturatedMainTermVal() const
std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > generate(bool expected=false, int seed=0)
std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > getData() const
double getEntryVal(size_t entry) const
double saturatedVal() const
std::shared_ptr< RooAbsCollection > fFuncVars
double getEntryBinWidth(size_t entry) const
std::shared_ptr< ROOT::Fit::FitConfig > fitConfig()
std::shared_ptr< RooArgSet > pars(bool stripGlobalObs=true) const
double mainTermVal() const
std::shared_ptr< RooAbsData > fData
double mainTermNdof() const
std::shared_ptr< RooAbsPdf > fPdf
bool setData(const std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > &_data)
xRooHypoPoint hypoPoint(const char *parName, double value, double alt_value=std::numeric_limits< double >::quiet_NaN(), const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown)
xRooFitResult minimize(const std::shared_ptr< ROOT::Fit::FitConfig > &=nullptr)
The xRooNode class is designed to wrap over a TObject and provide functionality to aid with interacti...
Generic interface for defining configuration options of a numerical algorithm.
void SetValue(const char *name, double val)
generic methods for retrieving options
virtual void SetNamedValue(const char *, const char *)
const_iterator begin() const
const_iterator end() const
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool dependsOn(const RooAbsCollection &serverList, const RooAbsArg *ignoreArg=nullptr, bool valueOnly=false) const
Test whether we depend on (ie, are served by) any object in the specified collection.
Abstract base class for objects that represent a discrete value that can be set from the outside,...
A space to attach TBranches.
Abstract container object that can hold multiple RooAbsArg objects.
Storage_t const & get() const
Const access to the underlying stl container.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
void setAttribAll(const Text_t *name, bool value=true)
Set given attribute in each element of the collection by calling each elements setAttribute() functio...
Int_t index(const RooAbsArg *arg) const
Returns index of given arg, or -1 if arg is not in the collection.
Storage_t::size_type size() const
Abstract base class for binned and unbinned datasets.
virtual const RooArgSet * get() const
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
Abstract interface for all probability density functions.
Abstract base class for objects that represent a real value that may appear on the left hand side of ...
virtual void setVal(double value)=0
Set the current value of the object. Needs to be overridden by implementations.
Abstract base class for objects that represent a real value and implements functionality common to al...
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
virtual bool setData(RooAbsData &, bool=true)
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
Named container for two doubles, two integers two object points and three string pointers that can be...
double getDouble(Int_t idx) const
Return double stored in slot idx.
Int_t getInt(Int_t idx) const
TObject * Clone(const char *newName=nullptr) const override
Make a clone of an object using the Streamer facility.
const char * getString(Int_t idx) const
Return string stored in slot idx.
Calculates the sum of the -(log) likelihoods of a set of RooAbsPfs that represent constraint function...
Container class to hold unbinned data.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
static RooMsgService & instance()
Return reference to singleton instance.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
Variable that can be changed from the outside.
void setVal(double value) override
Set value of variable to 'value'.
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
HypoTestResult is a base class for results from hypothesis tests.
This class simply holds a sampling distribution of some test statistic.
A RooAbsArg implementing string values.
Draw all kinds of Arrows.
virtual TArrow * DrawArrow(Double_t x1, Double_t y1, Double_t x2, Double_t y2, Float_t arrowsize=0, Option_t *option="")
Draw this arrow with new coordinates.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
const char * AsString() const
Return the date & time as a string (ctime() format).
Describe directory structure in memory.
virtual TKey * FindKeyAny(const char *) const
Class to handle efficiency histograms.
void FillWeighted(Bool_t bPassed, Double_t weight, Double_t x, Double_t y=0, Double_t z=0)
This function is used for filling the two histograms with a weight.
Double_t GetEfficiencyErrorUp(Int_t bin) const
Returns the upper error on the efficiency in the given global bin.
void Fill(Bool_t bPassed, Double_t x, Double_t y=0, Double_t z=0)
This function is used for filling the two histograms.
Graphics object made of three arrays X, Y and Z with the same number of points each.
A TGraph is an object made of two arrays X and Y with npoints each.
virtual void Add(TF1 *f, Double_t c1=1)
Performs the operation: y = y + c1*f(x,y) Errors are not recalculated.
void SetName(const char *name="") override
Set graph name.
void Draw(Option_t *chopt="") override
Draw this graph with its current attributes.
void SetTitle(const char *title="") override
Change (i.e.
void SetNameTitle(const char *name="", const char *title="") override
Set graph name and title.
1-D histogram with a double per channel (see TH1 documentation)
TH1 is the base class of all histogram classes in ROOT.
This class displays a legend box (TPaveText) containing several legend entries.
void Draw(Option_t *option="") override
Draw this legend with its current attributes.
Use the TLine constructor to create a simple line.
virtual TLine * DrawLine(Double_t x1, Double_t y1, Double_t x2, Double_t y2)
Draw this line with new coordinates.
A TMultiGraph is a collection of TGraph (or derived) objects.
The TNamed class is the base class for all named ROOT classes.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
Mother of all ROOT objects.
virtual void Delete(Option_t *option="")
Delete this object.
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
Regular expression class.
Double_t RealTime()
Stop the stopwatch (if it is running) and return the realtime (in seconds) passed between the start a...
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
void Continue()
Resume a stopped stopwatch.
Provides iteration through tokens of a given string.
Bool_t NextToken()
Get the next token, it is stored in this TString.
Double_t Atof() const
Return floating-point value contained in string.
const char * Data() const
Bool_t BeginsWith(const char *s, ECaseCompare cmp=kExact) const
static TString Format(const char *fmt,...)
Static method which formats a string using a printf style format descriptor and return a TString.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Ssiz_t Index(const char *pat, Ssiz_t i=0, ECaseCompare cmp=kExact) const
Float_t GetPadRightMargin() const
Float_t GetPadLeftMargin() const
Float_t GetPadBottomMargin() const
Float_t GetPadTopMargin() const
virtual Bool_t ProcessEvents()
Process pending events (GUI, timers, sockets).
This class defines a UUID (Universally Unique IDentifier), also known as GUIDs (Globally Unique IDent...
TDatime GetTime() const
Get time from UUID.
TVirtualPad is an abstract base class for the Pad and Canvas classes.
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg GlobalObservablesSource(const char *sourceName)
double gaussian_pdf(double x, double sigma=1, double x0=0)
Probability density function of the normal (Gaussian) distribution with mean x0 and standard deviatio...
double gaussian_cdf(double x, double sigma=1, double x0=0)
Alternative name for same function.
Double_t Prob(Double_t chi2, Int_t ndf)
Computation of the probability for a certain Chi-squared (chi2) and number of degrees of freedom (ndf...
Double_t Poisson(Double_t x, Double_t par)
Computes the Poisson distribution function for (x,par).
Double_t LnGamma(Double_t z)
Computation of ln[gamma(z)] for all z.
#define BEGIN_XROOFIT_NAMESPACE
#define END_XROOFIT_NAMESPACE
std::string collectionContents(const RooAbsCollection &coll)