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)
164#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 37, 00)
181 for (
int i = 0; i <
opts.GetSize(); i++) {
184 if (
strcmp(
opts.At(i)->GetName(),
"GlobalObservables") == 0) {
189 throw std::runtime_error(
"GlobalObservables mismatch");
197 auto _vars = std::unique_ptr<RooArgSet>(
fPdf->getVariables());
200 _vars->add(*std::unique_ptr<RooArgSet>(
con->getVariables()));
223 bool hasRange(
false);
247 std::make_shared<RooSimultaneous>(
TString::Format(
"%s_reduced", s->GetName()),
"Reduced model", _cat);
248 for (
auto &
c : _cat) {
249 auto _pdf = s->getPdf(
c.first.c_str());
252 _cat.setIndex(
c.second);
255 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
261 newPdf->addPdf(*_pdf,
c.first.c_str());
296 (
opts.find(
"GlobalObservables"))
305 std::cout <<
"PDF: ";
309 std::cout <<
"<null>" << std::endl;
311 std::cout <<
"Data: ";
315 std::cout <<
"<null>" << std::endl;
317 std::cout <<
"NLL Options: " << std::endl;
318 for (
int i = 0; i <
fOpts->GetSize(); i++) {
322 std::cout <<
" " <<
c->
GetName() <<
" : ";
323 if (
c->getString(0)) {
324 std::cout <<
c->getString(0);
325 }
else if (
c->getSet(0) && !
c->getSet(0)->empty()) {
326 std::cout << (
c->getSet(0)->contentsString());
328 std::cout <<
c->getInt(0);
330 std::cout << std::endl;
333 std::cout <<
"Fit Config: " << std::endl;
334 std::cout <<
" UseParabErrors: " << (
fFitConfig->ParabErrors() ?
"True" :
"False")
335 <<
" [toggles HESSE algorithm]" << std::endl;
336 std::cout <<
" MinimizerOptions: " << std::endl;
345 if (std::shared_ptr<RooAbsReal>::get())
346 oldName = std::shared_ptr<RooAbsReal>::get()->GetName();
351 fPdf->treeNodeServerList(&s,
nullptr,
true,
false);
362 if (
a->InheritsFrom(
"RooRealSumPdf")) {
367 std::unique_ptr<RooArgSet> obs(
a->getObservables(
fData->get()));
368 if (obs->size() == 1) {
369 auto *var =
static_cast<RooRealVar *
>(obs->first());
370 std::unique_ptr<std::list<double>> boundaries{
dynamic_cast<RooAbsReal *
>(
a)->binBoundaries(
371 *var, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())};
373 if (!std::shared_ptr<RooAbsReal>::get()) {
374 Info(
"xRooNLLVar",
"%s will be evaluated as a Binned PDF (%d bins)",
a->GetName(),
375 int(boundaries->size() - 1));
382 a->setAttribute(
"BinnedLikelihood",
setBinned);
386 std::map<RooAbsPdf *, std::string>
normRanges;
390 if (
auto sr =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"SplitRange"));
402 for (
auto cat :
simPdf->indexCat()) {
407 srangeName.ReplaceAll(
",",
"_" + cat.first +
",");
410 subpdf->treeNodeServerList(&
ss,
nullptr,
true,
false);
413 if (
a->InheritsFrom(
"RooAddPdf")) {
425 if (
a->InheritsFrom(
"RooAddPdf")) {
446 if (std::shared_ptr<RooAbsReal>::get())
447 attribs = std::shared_ptr<RooAbsReal>::get()->attributes();
448 this->reset(std::unique_ptr<RooAbsReal>{
fPdf->createNLL(*
fData, *
fOpts)}.release());
457 k->setNormRange(
v ==
"" ?
nullptr :
v.c_str());
460 std::shared_ptr<RooAbsReal>::get()->setAttribute(
a.c_str());
466 std::shared_ptr<RooAbsReal>::get()->SetName(
oldName);
469 std::shared_ptr<RooAbsReal>::get()->getVal();
471 o->setAttribute(
"BinnedLikelihood",
v);
475 fFuncVars = std::unique_ptr<RooArgSet>{std::shared_ptr<RooAbsReal>::get()->getVariables()};
483std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
487 return std::pair(
nullptr,
nullptr);
488 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
492 fr->setConstParList(
l);
493 const_cast<RooArgList &
>(fr->constPars()).setAttribAll(
"global",
false);
495 std::unique_ptr<RooAbsCollection>(fr->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
529 throw std::runtime_error(
"xRooFitResult::cfit: Cannot create cfit without nll");
533 if (
auto res = fCfits->find(
alias); res != fCfits->end()) {
537 if (
auto res = fCfits->find(
poiValues); res != fCfits->end()) {
542 *fNll->fFuncVars =
get()->floatParsFinal();
543 fNll->fFuncVars->assignValueOnly(
get()->constPars());
544 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->floatParsFinal()))
545 ->setAttribAll(
"Constant",
false);
546 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->constPars()))->setAttribAll(
"Constant",
true);
558 throw std::runtime_error(
"xRooFitResult::ifit: par not found");
567 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
570 throw std::runtime_error(
"xRooFitResult::impact: null ifit");
571 if (
_ifit->status() != 0)
572 fNode->Warning(
"impact",
"ifit status code is %d",
_ifit->status());
573 return _ifit->floatParsFinal().getRealValue(poi) -
poiHat->getVal();
576 int iPoi =
get()->floatParsFinal().index(poi);
577 int iNp =
get()->floatParsFinal().index(
np);
579 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
581 throw std::runtime_error(
"xRooFitResult::impact: np not found");
586 return std::numeric_limits<double>::quiet_NaN();
596 for (
auto p :
get()->floatParsFinal()) {
597 if (
strcmp(
p->GetName(), poi) == 0) {
603 bool matches =
false;
606 if ((
p->getStringAttribute(
"group") && s ==
p->getStringAttribute(
"group")) ||
621 throw std::runtime_error(
TString::Format(
"Could not find poi: %s", poi));
624 fNode->Warning(
"conditionalError",
"No parameters selected by: %s",
nps);
629 int idx = vars.
index(poi);
630 return sqrt(
get()->conditionalCovarianceMatrix(vars)(idx, idx));
635 auto _poi =
_cfit->floatParsFinal().find(poi);
637 return (
up) ?
static_cast<RooRealVar *
>(_poi)->getErrorHi() :
static_cast<RooRealVar *
>(_poi)->getErrorLo();
645 throw std::runtime_error(
"xRooFitResult::ranknp: poi not found");
647 std::vector<std::pair<std::string, double>>
ranks;
649 for (
auto par :
get()->floatParsFinal()) {
652 ranks.emplace_back(std::pair(par->GetName(), impact(poi, par->GetName(),
up,
prefit,
true)));
656 if (std::isnan(left.second) && !std::isnan(right.second))
658 if (!std::isnan(left.second) && std::isnan(right.second))
660 return fabs(left.second) > fabs(right.second);
669 v = std::numeric_limits<double>::quiet_NaN();
676 if (std::isnan(left.second) && !std::isnan(right.second))
678 if (!std::isnan(left.second) && std::isnan(right.second))
680 return fabs(left.second) > fabs(right.second);
707 const_cast<RooArgList &
>(out->constPars()).setAttribAll(
"global",
false);
709 std::unique_ptr<RooAbsCollection>(out->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
712 if (
fOpts->find(
"GoF")) {
720 return xRooFitResult(std::make_shared<xRooNode>(out,
fPdf), std::make_shared<xRooNLLVar>(*
this));
742 if (
size_t(_data->numEntries()) <=
entry)
745 *std::unique_ptr<RooAbsCollection>(_pdf->getObservables(_data)) = *_data->get(
entry);
748 return (_data->weight() == 0) ? 0 : (-_data->weight() * _pdf->getLogVal(_data->get()));
753 std::set<std::string> out;
764 c->
get<
RooAbsArg>()->treeNodeServerList(&nodes,
nullptr,
true,
false);
766 for (
auto a : nodes) {
767 if (
a->InheritsFrom(
"RooRealSumPdf") &&
785 pdf()->treeNodeServerList(&nodes,
nullptr,
true,
false);
786 for (
auto a : nodes) {
787 if (
a->InheritsFrom(
"RooRealSumPdf") &&
803 if (
size_t(_data->numEntries()) <=
entry)
805 auto _pdf =
pdf().get();
806 std::unique_ptr<RooAbsCollection>
_robs(_pdf->getObservables(_data->get()));
809 _pdf = s->getPdf(s->indexCat().getCurrentLabel());
812 for (
auto o : *
_robs) {
816 std::unique_ptr<std::list<double>> bins(
817 _pdf->binBoundaries(*
a, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()));
819 double lowEdge = -std::numeric_limits<double>::infinity();
820 for (
auto b : *bins) {
821 if (
b >
a->getVal()) {
848 for (
auto c :
cTerm->list()) {
849 if (std::string(
c->ClassName()) ==
"RooAbsPdf" ||
850 std::string(
c->ClassName()).find(
"RooNormalizedPdf") != std::string::npos) {
860 gaus->getMean().GetName()));
879 std::unique_ptr<RooAbsCollection>(
pars()->selectByAttrib(
"Constant",
false))->
size();
893 std::unique_ptr<RooAbsCollection>
_floats(
pars()->selectByAttrib(
"Constant",
false));
936 return std::numeric_limits<double>::quiet_NaN();
950 double out = _data->sumEntries();
951 for (
int i = 0; i < _data->numEntries(); i++) {
953 double w = _data->weight();
956 out -=
w * std::log(
w);
969 throw std::runtime_error(
"Cannot determine category of RooSimultaneous pdf");
980 auto out = std::shared_ptr<RooArgSet>(
get()->getVariables());
982 out->remove(*
fGlobs,
true,
true);
1007 std::unique_ptr<RooAbsCollection>
funcVars(
get()->getVariables());
1010 for (
auto &
coord : coords) {
1012 throw std::runtime_error(
"Invalid coordinate");
1014 for (
size_t i = 0; i <
coord.size(); i++) {
1037 if (
sOpt ==
"sensitivity") {
1042 if (
sOpt ==
"floating") {
1044 auto floats = std::unique_ptr<RooAbsCollection>(
_pars->selectByAttrib(
"Constant",
false));
1067 if (
auto a =
_pars->find(s);
a)
1071 if (vars.
size() == 1) {
1077 bad->SetMarkerStyle(5);
1079 bool normRange =
false;
1093 double step = (
v->getMax() -
v->getMin()) / 100;
1094 double init =
v->getVal();
1097 auto currTime = std::chrono::steady_clock::now();
1098 while (out->
GetN() < 100 && (low >
v->getMin() ||
high < v->getMax())) {
1099 if (out->
GetN() == 0) {
1109 if (low >
v->getMin()) {
1111 auto _v =
func()->getVal();
1112 if (std::isnan(
_v) || std::isinf(
_v)) {
1113 if (
bad->GetN() == 0)
1123 auto _v =
func()->getVal();
1124 if (std::isnan(
_v) || std::isinf(
_v)) {
1125 if (
bad->GetN() == 0)
1136 if (std::chrono::steady_clock::now() -
currTime > std::chrono::seconds(1)) {
1137 currTime = std::chrono::steady_clock::now();
1146#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
1147 gPad->GetCanvas()->ResetUpdated();
1152 Error(
"Draw",
"Name a parameter to scan over: Draw(<name>) , choose from: %s",
1153 _pars->empty() ?
"" :
_pars->contentsString().c_str());
1167 return setData(std::dynamic_pointer_cast<RooAbsData>(
data.fComp),
1168 std::shared_ptr<const RooAbsCollection>(
data.globs().argList().snapshot()));
1171bool xRooNLLVar::setData(
const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &_data)
1174 if (
fData == _data.first &&
fGlobs == _data.second)
1179 auto _dglobs = (_data.second) ? _data.second
1180 : std::shared_ptr<const RooAbsCollection>(_data.first->getGlobalObservables(),
1187 throw std::runtime_error(
"Missing globs");
1198 rC.remove(*std::unique_ptr<RooAbsCollection>(
rC.selectCommon(*
_actualGlobs)));
1204 throw std::runtime_error(
TString::Format(
"globs mismatch: adding %s removing %s",
r.Data(),
l.Data()));
1209 if (!std::shared_ptr<RooAbsReal>::get()) {
1210 fData = _data.first;
1223 fFuncVars->setAttribAll(
"Constant",
false);
1227 fData = _data.first;
1248 fData = _data.first;
1250 }
catch (std::runtime_error &) {
1255 fFuncVars->setAttribAll(
"Constant",
false);
1259 fData = _data.first;
1263 throw std::runtime_error(
"Unable to setData");
1270 }
else if (
auto f = std::unique_ptr<RooAbsCollection>(
fConstVars->selectByAttrib(
"Constant",
false)); !
f->empty()) {
1292 }
else if (
strcmp(opt.
GetName(),
"StrategySequence") == 0) {
1311 if (std::shared_ptr<RooAbsReal>::get()) {
1384 return fData->sumEntries() * log(1.0 * (s->servers().size() - 1));
1396 for (
int i = 0; i <
fData->numEntries(); i++) {
1406 auto _func =
func();
1409 for (
auto s : _func->servers()) {
1413 for (
auto s2 : s->servers()) {
1431 sWhat.ReplaceAll(
" =",
"=").ReplaceAll(
"= ",
"=");
1441 : std::numeric_limits<double>::quiet_NaN();
1454 if (getVal(
sWhat +
" readonly").second != 0) {
1455 if (
sWhat.Contains(
"toys=")) {
1464 if (nullToys.size() <
nToys) {
1465 addNullToys(
nToys - nullToys.size());
1468 addAltToys(
nToysAlt - altToys.size());
1472 addCLsToys(100, 0, 0.05,
nSigma);
1474 throw std::runtime_error(
"Auto-generating toys for anything other than CLs not yet supported, please "
1475 "specify number of toys with 'toys=N' ");
1483 if (
rr && var && var->get()) {
1484 _readOnly = var->get()->getAttribute(
"readOnly");
1485 var->get()->setAttribute(
"readOnly",
rr);
1493 var->get()->setAttribute(
"readOnly",
_readOnly);
1499 std::shared_ptr<xRooNLLVar> &var;
1513 throw std::runtime_error(std::string(
"Unknown: ") +
what);
1520 out.
add(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1528 out.
addClone(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1529 for (
auto a : out) {
1533 if (
auto s =
a->getStringAttribute(
"altVal"); s &&
strlen(s)) {
1536 v->setVal(std::numeric_limits<double>::quiet_NaN());
1546 if (me.ufit(
true) && !allowedStatusCodes.count(me.ufit(
true)->status()))
1548 if (me.cfit_null(
true) && !allowedStatusCodes.count(me.cfit_null(
true)->status()))
1550 if (me.cfit_alt(
true) && !allowedStatusCodes.count(me.cfit_alt(
true)->status()))
1552 if (me.asimov(
true))
1553 out += me.asimov(
true)->status() << 3;
1561 std::cout <<
"POI: " << _poi.contentsString() <<
" , null: ";
1563 for (
auto a : _poi) {
1572 std::cout <<
" , alt: ";
1583 if (!std::isnan(
v->getVal()))
1586 std::cout <<
" , pllType: ";
1588 case 0: std::cout <<
"tmu";
break;
1589 case 1: std::cout <<
"qmu or qmutilde";
break;
1590 case 2: std::cout <<
"q0";
break;
1591 case 4: std::cout <<
"u0";
break;
1592 default: std::cout <<
"unknown";
break;
1594 std::cout << std::endl;
1597 std::cout <<
" obs ts: " << obs_ts <<
" +/- " << obs_ts_err << std::endl;
1600 std::cout <<
" - ufit: ";
1602 std::cout << fUfit->GetName() <<
" " << fUfit->minNll() <<
" (status=" << fUfit->status() <<
") (";
1604 for (
auto a : _poi) {
1605 auto v =
dynamic_cast<RooRealVar *
>(fUfit->floatParsFinal().find(
a->GetName()));
1610 std::cout <<
v->
GetName() <<
"_hat: " <<
v->getVal() <<
" +/- " <<
v->getError();
1613 std::cout <<
")" << std::endl;
1615 std::cout <<
"Not calculated" << std::endl;
1617 std::cout <<
" - cfit_null: ";
1619 std::cout << fNull_cfit->GetName() <<
" " << fNull_cfit->minNll() <<
" (status=" << fNull_cfit->status() <<
")";
1621 std::cout <<
"Not calculated";
1624 std::cout << std::endl <<
" - cfit_alt: ";
1626 std::cout << fAlt_cfit->GetName() <<
" " << fAlt_cfit->minNll() <<
" (status=" << fAlt_cfit->status() <<
")"
1629 std::cout <<
"Not calculated" << std::endl;
1631 std::cout <<
" sigma_mu: ";
1633 if (!fAsimov || !fAsimov->fUfit || !fAsimov->fNull_cfit) {
1634 std::cout <<
"Not calculated";
1636 std::cout << const_cast<xRooHypoPoint *>(
this)->
sigma_mu().first <<
" +/- "
1640 std::cout << std::endl;
1641 std::cout <<
" - asimov ufit: ";
1642 if (fAsimov->fUfit) {
1643 std::cout << fAsimov->
fUfit->GetName() <<
" " << fAsimov->fUfit->minNll()
1644 <<
" (status=" << fAsimov->fUfit->status() <<
")";
1646 std::cout <<
"Not calculated";
1648 std::cout << std::endl <<
" - asimov cfit_null: ";
1649 if (fAsimov->fNull_cfit) {
1650 std::cout << fAsimov->fNull_cfit->GetName() <<
" " << fAsimov->fNull_cfit->minNll()
1651 <<
" (status=" << fAsimov->fNull_cfit->status() <<
")";
1653 std::cout <<
"Not calculated";
1656 std::cout << std::endl;
1658 std::cout << std::endl;
1661 std::cout <<
" - cfit_lbound: " << fLbound_cfit->GetName() <<
" " << fLbound_cfit->minNll()
1662 <<
" (status=" << fLbound_cfit->status() <<
")" << std::endl;
1665 std::cout <<
" - gfit: " << fGenFit->GetName() << std::endl;
1666 if (!nullToys.empty() || !altToys.empty()) {
1667 std::cout <<
" * null toys: " << nullToys.size();
1669 while (
firstToy < nullToys.size() && std::isnan(std::get<1>(nullToys[
firstToy])))
1672 std::cout <<
" [ of which " <<
firstToy <<
" are bad]";
1673 std::cout <<
" , alt toys: " << altToys.size();
1675 while (
firstToy < altToys.size() && std::isnan(std::get<1>(altToys[
firstToy])))
1678 std::cout <<
" [ of which " <<
firstToy <<
" are bad]";
1679 std::cout << std::endl;
1687 auto var =
dynamic_cast<RooRealVar *
>(ufit()->floatParsFinal().find(fPOIName()));
1691 throw std::runtime_error(
TString::Format(
"Cannot find POI: %s", fPOIName()));
1694 throw std::runtime_error(
"Unconditional fit unavailable");
1701 if (fGenFit && isExpected) {
1709 : hypoTestResult(
htr)
1725 if (
toys->getGlobalObservables()) {
1726 coords = std::shared_ptr<RooAbsCollection>(
toys->getGlobalObservables()->snapshot());
1728 for (
int i = 0; i <
toys->numEntries(); i++) {
1731 std::make_tuple(
int(
toy->getRealValue(
"seed")),
toy->getRealValue(
"ts"),
toys->weight()));
1736 for (
int i = 0; i <
toys->numEntries(); i++) {
1739 std::make_tuple(
int(
toy->getRealValue(
"seed")),
toy->getRealValue(
"ts"),
toys->weight()));
1750 if (!fAsimov && (nllVar || hypoTestResult)) {
1751 auto theFit = (!
fData.first && fGenFit && !isExpected)
1756 if (!
theFit || allowedStatusCodes.find(
theFit->status()) == allowedStatusCodes.
end())
1758 fAsimov = std::make_shared<xRooHypoPoint>(*
this);
1759 fAsimov->coords.reset(fAsimov->coords->snapshot());
1760 fAsimov->hypoTestResult.reset();
1762 for (
auto p : fAsimov->poi()) {
1765 v->deleteSharedProperties();
1766 if (
v->getVal() == 0) {
1772 v->setVal(
theFit->constPars().getRealValue(
v->GetName()) * 0.5);
1777 fAsimov->nullToys.clear();
1778 fAsimov->altToys.clear();
1779 fAsimov->fUfit = retrieveFit(3);
1780 fAsimov->fNull_cfit = retrieveFit(4);
1781 fAsimov->fAlt_cfit.reset();
1783 std::make_pair(
nullptr,
nullptr);
1784 fAsimov->fGenFit =
theFit;
1785 fAsimov->isExpected =
true;
1794 return std::pair<double, double>(1, 0);
1797 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1798 double lowBound =
first_poi->getMin(
"physical");
1802 (lowBound == -std::numeric_limits<double>::infinity() &&
hiBound == std::numeric_limits<double>::infinity())
1803 ? std::pair<double, double>(0, 0)
1811 return std::pair(
nom, std::max(std::abs(
up -
nom), std::abs(
down -
nom)));
1817 return std::pair<double, double>(1, 0);
1820 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1831 return std::pair(
nom, std::max(std::abs(
up -
nom), std::abs(
down -
nom)));
1836 if (fNullVal() == fAltVal())
1837 return std::pair<double, double>(1, 0);
1840 return std::pair<double, double>(1, 0);
1843 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1868 return std::pair(
nom, std::max(std::abs(
up -
nom), std::abs(
down -
nom)));
1873 if (std::isnan(
nSigma)) {
1880 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1889 return std::pair<double, double>(
nom, std::max(std::abs(
nom -
up), std::abs(
nom -
down)));
1894 if (std::isnan(
nSigma)) {
1899 while (
firstToy < altToys.size() && std::isnan(std::get<1>(altToys[
firstToy])))
1902 return std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
1905 return std::pair(std::get<1>(altToys[
targetIdx]), (std::get<1>(altToys[std::min(
int(altToys.size()),
targetIdx)]) -
1906 std::get<1>(altToys[std::max(0,
targetIdx)])) /
1915 return std::pair<double, double>(hypoTestResult->GetTestStatisticData(), 0);
1916 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1918 if (allowedStatusCodes.find(
_ufit->status()) == allowedStatusCodes.end()) {
1919 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1923 mu_hat().getVal() <
_first_poi->getMin(
"physical")) {
1927 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1934 return std::pair<double, double>(0, 0);
1937 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1945 return std::pair<double, double>(2. * cFactor *
diff,
1946 2. * cFactor * sqrt(pow(cfit_null(
readOnly)->edm(), 2) + pow(
_ufit->edm(), 2)));
1952 if (!hypoTestResult)
1955 if (
auto fits = hypoTestResult->GetFitInfo()) {
1956 for (
int i = 0; i <
fits->numEntries(); i++) {
1957 auto fit =
fits->get(i);
1958 if (fit->getCatIndex(
"type") !=
type)
1962 fits->getGlobalObservables()->getStringValue(
TString::Format(
"%s.name", fit->getCatLabel(
"type")));
1965 for (
auto file : *
gROOT->GetListOfFiles()) {
1969 k->GetMotherDir()->GetList()
1983 rfit->setStatus(fit->getRealValue(
"status"));
1984 rfit->setMinNLL(fit->getRealValue(
"minNll"));
1985 rfit->setEDM(fit->getRealValue(
"edm"));
1987 std::unique_ptr<RooAbsCollection>
par_hats(
1988 hypoTestResult->GetFitInfo()->getGlobalObservables()->selectByName(coords->contentsString().c_str()));
1989 par_hats->setName(
"floatParsFinal");
1997 rfit->setCovarianceMatrix(
cov);
1998 rfit->setCovQual(fit->getRealValue(
"covQual"));
2009 if (
auto rfit = retrieveFit(0)) {
2010 return fUfit =
rfit;
2012 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2014 if (!nllVar->fFuncVars)
2015 nllVar->reinitialize();
2018 if (!
readOnly && isExpected && fGenFit) {
2020 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2021 nllVar->get()->setAttribute(
"readOnly");
2022 auto out = ufit(
true);
2023 nllVar->get()->setAttribute(
"readOnly",
tmp);
2028 nllVar->setData(
data());
2031 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2032 nllVar->setData(
fData);
2034 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2035 *nllVar->fFuncVars = *coords;
2036 if (nllVar->fFuncGlobs)
2037 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2038 std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))
2039 ->setAttribAll(
"Constant",
false);
2042 nllVar->fFuncVars->assignValueOnly(fGenFit->constPars());
2043 nllVar->fFuncVars->assignValueOnly(fGenFit->floatParsFinal());
2045 nllVar->get()->SetName(
2046 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2048 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2050 }
else if (!std::isnan(fAltVal())) {
2055 _poi->
setVal(_poi->getStringAttribute(
"initVal") ?
TString(_poi->getStringAttribute(
"initVal")).
Atof()
2060 return (fUfit = nllVar->minimize());
2066 for (
auto &
c :
coll) {
2069 out +=
c->GetName();
2085 if (
auto rfit = retrieveFit(1)) {
2086 return fNull_cfit =
rfit;
2088 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2090 if (!nllVar->fFuncVars)
2091 nllVar->reinitialize();
2094 if (!
readOnly && isExpected && fGenFit) {
2096 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2097 nllVar->get()->setAttribute(
"readOnly");
2098 auto out = cfit_null(
true);
2099 nllVar->get()->setAttribute(
"readOnly",
tmp);
2104 nllVar->setData(
data());
2107 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2108 nllVar->setData(
fData);
2112 *nllVar->fFuncVars = fUfit->floatParsFinal();
2114 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2115 *nllVar->fFuncVars = *coords;
2116 if (nllVar->fFuncGlobs)
2117 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2119 nllVar->fFuncVars->find(fPOIName())
2120 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2123 nllVar->get()->SetName(
2124 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2126 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2128 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(poi()).c_str());
2129 return (fNull_cfit = nllVar->minimize());
2140 return fLbound_cfit;
2141 if (
auto rfit = retrieveFit(6)) {
2142 return fLbound_cfit =
rfit;
2144 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2146 if (!nllVar->fFuncVars)
2147 nllVar->reinitialize();
2150 if (!
readOnly && isExpected && fGenFit) {
2152 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2153 nllVar->get()->setAttribute(
"readOnly");
2154 auto out = cfit_lbound(
true);
2155 nllVar->get()->setAttribute(
"readOnly",
tmp);
2160 nllVar->setData(
data());
2163 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2164 nllVar->setData(
fData);
2168 *nllVar->fFuncVars = fUfit->floatParsFinal();
2170 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2171 *nllVar->fFuncVars = *coords;
2173 if (nllVar->fFuncGlobs)
2174 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2176 nllVar->fFuncVars->find(fPOIName())
2177 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2180 nllVar->get()->SetName(
2181 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2183 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2185 nllVar->get()->setStringAttribute(
2187 collectionContents(*std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))).c_str());
2188 return (fLbound_cfit = nllVar->minimize());
2193 if (std::isnan(fAltVal()))
2197 if (
auto rfit = retrieveFit(2)) {
2198 return fAlt_cfit =
rfit;
2200 if (!nllVar || (
readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2202 if (!nllVar->fFuncVars)
2203 nllVar->reinitialize();
2206 if (!
readOnly && isExpected && fGenFit) {
2208 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2209 nllVar->get()->setAttribute(
"readOnly");
2210 auto out = cfit_alt(
true);
2211 nllVar->get()->setAttribute(
"readOnly",
tmp);
2216 nllVar->setData(
data());
2219 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2220 nllVar->setData(
fData);
2224 *nllVar->fFuncVars = fUfit->floatParsFinal();
2226 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2227 *nllVar->fFuncVars = *coords;
2228 if (nllVar->fFuncGlobs)
2229 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2230 *nllVar->fFuncVars = alt_poi();
2232 nllVar->get()->SetName(
2233 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2235 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2237 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(alt_poi()).c_str());
2238 return (fAlt_cfit = nllVar->minimize());
2247 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
2251 return std::pair<double, double>(std::abs(
asi->fNullVal() - fAltVal()) / sqrt(out.first),
2252 out.second * 0.5 * std::abs(
asi->fNullVal() - fAltVal()) /
2253 (out.first * sqrt(out.first)));
2259 if (std::isnan(
_ts.first))
2262 return std::pair<double, double>(1, 0);
2269 return std::pair(0.5, std::numeric_limits<double>::infinity());
2279 if (std::isnan(std::get<1>(
toy))) {
2282 bool res = std::get<1>(
toy) >=
_ts.first;
2283 if (std::get<2>(
toy) != 1) {
2290 if (std::get<1>(
toy) >=
_ts.first -
_ts.second)
2292 if (std::get<1>(
toy) >=
_ts.first -
_ts.second)
2314 return pX_toys(
false,
nSigma);
2319 if (!std::isnan(
nSigma)) {
2322 return pX_toys(
true,
nSigma);
2333 auto _cfit = cfit_null();
2336 if (!nllVar->fFuncVars)
2337 nllVar->reinitialize();
2355 if (!nllVar->fFuncVars)
2356 nllVar->reinitialize();
2368 if ((
alt && !cfit_alt()) || (!
alt && !cfit_null())) {
2369 throw std::runtime_error(
"Cannot add toys, invalid conditional fit");
2372 auto condition = [&]() {
2376 if (!std::isnan(obs.first)) {
2378 double err = obs.second;
2399 throw std::runtime_error(
"Cannot target obs p-value because ts value unavailable");
2407 Info(
"addToys",
"First generating 100 alt toys in order to determine expected ts value");
2411 throw std::runtime_error(
"Unable to determine expected ts value");
2436 auto &
toys = (
alt) ? altToys : nullToys;
2442 if (!std::isnan(
target) && !condition()) {
2450 for (
size_t i = 0; i <
nnToys; i++) {
2452 auto toy = ((
alt) ? generateAlt(seed) : generateNull(seed));
2455 toys.push_back(std::make_tuple(seed,
toy.pll().first, 1.));
2458 if (std::isnan(std::get<1>(
toys.back())))
2464 <<
TString::Format(
"Generated %d/%d %s hypothesis toys [%.2f toys/s]",
2467 if (!std::isnan(
target)) {
2471 std::cout <<
"..." << std::flush;
2474 if (!
gROOT->IsBatch()) {
2478#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2479 gPad->GetCanvas()->ResetUpdated();
2492 for (
auto &t :
toys) {
2493 if (std::isnan(std::get<1>(t)))
2494 std::get<1>(t) = -std::numeric_limits<double>::infinity();
2497 [](
const decltype(nullToys)::value_type &
a,
const decltype(nullToys)::value_type &
b) ->
bool {
2498 if (std::isnan(std::get<1>(a)))
2500 if (std::isnan(std::get<1>(b)))
2502 return std::get<1>(a) < std::get<1>(b);
2504 for (
auto &t :
toys) {
2505 if (std::isinf(std::get<1>(t)))
2506 std::get<1>(t) = std::numeric_limits<double>::quiet_NaN();
2508 if (std::isnan(
target)) {
2515 }
while (condition());
2518 <<
"Finished Generating ";
2527 if (!
gROOT->IsBatch()) {
2531#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2532 gPad->GetCanvas()->ResetUpdated();
2540 std::cout <<
"Warning: " <<
nans <<
" toys were bad" << std::endl;
2617 out.
nllVar = std::make_shared<xRooNLLVar>(*
this);
2626 while (pattern.NextToken()) {
2629 double val = std::numeric_limits<double>::quiet_NaN();
2630 auto i = s.
Index(
"=");
2634 if (!
cVal.IsFloat())
2635 throw std::runtime_error(
"poiValues must contain value");
2640 throw std::runtime_error(
"Cannot find poi");
2641 if (!std::isnan(val))
2650 throw std::runtime_error(
"No poi");
2653 auto _snap = std::unique_ptr<RooAbsCollection>(
fFuncVars->selectByAttrib(
"Constant",
true))->snapshot();
2654 _snap->setAttribAll(
"poi",
false);
2655 std::unique_ptr<RooAbsCollection> _poi(
_snap->selectByName(
poiNames));
2656 _poi->setAttribAll(
"poi",
true);
2658 for (
auto a : *_poi)
2659 a->setStringAttribute(
"altVal", nullptr);
2661 for (
auto a : *_poi)
2678 for (
auto b : out.poi()) {
2680 if (
r->hasRange(
"physical") &&
r->getMin() >=
r->getMin(
"physical")) {
2682 "xRooNLLVar::hypoPoint",
2683 "fitting min of %s is >= physical limit (%g), but using uncapped test-statistic, so will set to "
2685 r->GetName(),
r->getMin(
"physical"), -
r->getMax());
2686 r->setMin(-
r->getMax());
2699 if (!
static_cast<RooRealVar *
>(
b)->hasRange(
"physical")) {
2700 static_cast<RooRealVar *
>(
b)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2708xRooNLLVar::xRooHypoPoint
2714 std::unique_ptr<RooAbsCollection> _poi(
fFuncVars->selectByAttrib(
"poi",
true));
2715 if (_poi->empty()) {
2716 throw std::runtime_error(
"No POI specified in model");
2717 }
else if (_poi->size() != 1) {
2718 throw std::runtime_error(
"Multiple POI specified in model");
2732 if (!nllVar && !hypoTestResult)
2738 sOpt.ReplaceAll(
"same",
"");
2746 if (
gPad->GetNumber() == 0) {
2762 hAxis =
dynamic_cast<TH1 *
>(
pad->GetPrimitive(
".axis"));
2764 for (
auto o : *
pad->GetListOfPrimitives()) {
2772 double _min = std::numeric_limits<double>::quiet_NaN();
2773 double _max = -std::numeric_limits<double>::quiet_NaN();
2775 for (
auto &
p : nullToys) {
2776 if (std::get<2>(
p) == 0)
2778 if (std::isnan(std::get<1>(
p)))
2781 _max = std::max(std::get<1>(
p), _max);
2783 for (
auto &
p : altToys) {
2784 if (std::get<2>(
p) == 0)
2786 if (std::isnan(std::get<1>(
p)))
2789 _max = std::max(std::get<1>(
p), _max);
2792 auto obs = ts_asymp();
2793 if (!std::isnan(obs.first)) {
2794 _min = std::min(obs.first - std::abs(obs.first) * 0.1,
_min);
2795 _max = std::max(obs.first + std::abs(obs.first) * 0.1, _max);
2798 auto pNull = pNull_toys();
2799 auto pAlt = pAlt_toys();
2801 ? std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN())
2804 ? std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN())
2808 ? fAsimov->pll().first
2809 : std::numeric_limits<double>::quiet_NaN();
2810 if (!std::isnan(
asi) &&
asi > 0) {
2813 _max = std::max(
asi + std::abs(
asi), _max);
2818 auto _poi =
dynamic_cast<RooRealVar *
>(poi().first());
2822 auto h =
new TH1D((
isAlt) ?
"alt_toys" :
"null_toys",
"", 100,
_min, _max + (_max -
_min) * 0.01);
2823 h->SetDirectory(
nullptr);
2825 for (
auto &
p : (
isAlt) ? altToys : nullToys) {
2826 double w = std::isnan(std::get<1>(
p)) ? 0 : std::get<2>(
p);
2829 if (!std::isnan(std::get<1>(
p)))
2830 h->Fill(std::get<1>(
p),
w);
2832 if (
h->GetEntries() > 0)
2833 h->Scale(1. /
h->Integral(0,
h->GetNbinsX() + 1));
2857 h->SetMarkerSize(0);
2869 auto axis =
static_cast<TH1 *
>(
h->Clone(
".axis"));
2871 axis->SetStats(
false);
2872 axis->Reset(
"ICES");
2874 axis->SetLineWidth(0);
2876 axis->SetMinimum(1
e-7);
2877 axis->GetYaxis()->SetRangeUser(1
e-7, 10);
2878 axis->SetMaximum(
h->GetMaximum());
2880 l =
new TLegend(0.4, 0.7, 1. -
gPad->GetRightMargin(), 1. -
gPad->GetTopMargin());
2881 l->SetName(
"legend");
2883 l->SetBorderSize(0);
2886 l->ConvertNDCtoPad();
2888 for (
auto o : *
gPad->GetListOfPrimitives()) {
2895 if (
h->GetEntries() > 0) {
2898 h->Draw(
"axissame");
2901 if (
h->GetEntries() > 0) {
2904 h->Draw(
"axissame");
2912 if (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit && !std::isnan(sigma_mu().first) && !std::isnan(fAltVal())) {
2913 auto hh =
static_cast<TH1 *
>(
nullHist->Clone(
"null_asymp"));
2915 hh->SetStats(
false);
2916 hh->SetLineStyle(2);
2918 for (
int i = 1; i <=
hh->GetNbinsX(); i++) {
2921 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2923 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2928 hh->SetStats(
false);
2929 hh->SetLineStyle(2);
2931 for (
int i = 1; i <=
hh->GetNbinsX(); i++) {
2934 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2936 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2946 auto tl =
ll.DrawLine(obs.first,
hAxis->GetMinimum(), obs.first, 0.1);
2951 l->AddEntry(
tl, label,
"l");
2954 auto pCLs = pCLs_toys();
2955 label +=
" p_{toy}=(";
2960 if (label.Length() > 0)
2961 l->AddEntry(
"", label,
"");
2963 if (!std::isnan(
pNullA.first) || !std::isnan(
pAltA.first)) {
2964 auto pCLs = pCLs_asymp();
2965 label +=
" p_{asymp}=(";
2970 if (label.Length() > 0)
2971 l->AddEntry(
"", label,
"");
2973 if (
auto ax =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
".axis")))
2974 ax->GetYaxis()->SetRangeUser(1
e-7, 1);
2979 auto v =
dynamic_cast<RooRealVar *
>(poi().empty() ? nullptr : poi().first());
2981 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2991 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
3001 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
3011 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
3020 return "Test Statistic";
3026 return (poi().empty()) ? nullptr : (poi().first())->GetName();
3031 return (
first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() :
first_poi->getVal();
3037 return (
first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() :
first_poi->getVal();
3044 throw std::runtime_error(
"HypoPoint has no POI, cannot set null value");
3052 throw std::runtime_error(
"HypoPoint has no POI, cannot set alt value");
3069 if (
alt_value == std::numeric_limits<double>::quiet_NaN()) {
3083 for (
auto p : out.
poi()) {
3085 dynamic_cast<RooRealVar *
>(
p)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
3086 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [0,inf]",
p->GetName());
3088 v->removeMin(
"physical");
3089 v->removeMax(
"physical");
3090 Info(
"xRooNLLVar::hypoSpace",
"Removing physical range of %s",
p->GetName());
3107 for (
auto p : out.
poi()) {
3109 r->setRange(
"scan", std::isnan(low) ?
r->getMin() : low, std::isnan(high) ?
r->getMax() : high);
3122 for (
auto p :
hs.poi()) {
3124 r->setRange(
"scan", std::isnan(low) ?
r->getMin() : low, std::isnan(high) ?
r->getMax() : high);
3135 auto _poi = std::unique_ptr<RooAbsCollection>(
3136 std::unique_ptr<RooAbsCollection>(
pdf()->getVariables())->selectByAttrib(
"poi",
true));
3138 throw std::runtime_error(
"You must specify a POI for the hypoSpace");
3149 std::unique_ptr<RooAbsCollection> axes(s.
pars()->selectByName(
parName));
3151 throw std::runtime_error(
"parameter not found");
3152 axes->setAttribAll(
"axis",
true);
3157 s.
fNlls[s.
fPdfs.begin()->second] = std::make_shared<xRooNLLVar>(*
this);
3164 for (
auto poi : s.
poi()) {
3168 r->setRange(
"scan",
r->getMin(),
r->getMax());
3177 if (hypoTestResult) {
3178 return *hypoTestResult;
3186 if (nllVar && !nllVar->get()->getAttribute(
"readOnly")) {
3188 nllVar->get()->setAttribute(
"readOnly");
3199 {
"OneSidedPositive", 1},
3200 {
"OneSidedNegative", 2},
3201 {
"OneSidedAbsolute", 3},
3205 fitMeta.addClone(ufit()->floatParsFinal());
3207 fitMeta.setCatIndex(
"pllType",
int(fPllType));
3215 {
"asimov_cfit_null", 4},
3217 {
"cfit_lbound", 6}}));
3227 for (
int i = 0; i < 7; i++) {
3228 std::shared_ptr<const RooFitResult> fit;
3230 case 0: fit = ufit();
break;
3231 case 1: fit = cfit_null();
break;
3232 case 2: fit = cfit_alt();
break;
3233 case 3: fit = asimov() ? asimov()->ufit(
true) :
nullptr;
break;
3234 case 4: fit = asimov() ? asimov()->cfit_null(
true) :
nullptr;
break;
3235 case 5: fit = fGenFit;
break;
3236 case 6: fit = cfit_lbound();
break;
3241 fitDetails.getCatLabel(
"type"), fit->GetName()));
3243 fitDetails.setRealValue(
"status", fit->status());
3244 fitDetails.setRealValue(
"minNll", fit->minNll());
3246 fitDetails.setRealValue(
"covQual", fit->covQual());
3262 if (!nullToys.empty()) {
3264 std::vector<double> values;
3265 std::vector<double> weights;
3266 values.reserve(nullToys.size());
3267 weights.reserve(nullToys.size());
3269 for (
auto &t : nullToys) {
3270 values.push_back(std::get<1>(t));
3271 weights.push_back(std::get<2>(t));
3277#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3280 pNull_toys().second;
3284 pNull_toys().second);
3287#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3297 if (!altToys.empty()) {
3298 std::vector<double> values;
3299 std::vector<double> weights;
3300 values.reserve(altToys.size());
3301 weights.reserve(altToys.size());
3309 for (
auto &t : altToys) {
3310 values.push_back(std::get<1>(t));
3311 weights.push_back(std::get<2>(t));
3312 altDetails.setRealValue(
"seed", std::get<0>(t));
3313 altDetails.setRealValue(
"ts", std::get<1>(t));
3318#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3325 pAlt_toys().second);
3329#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3339 nllVar->get()->setAttribute(
"readOnly",
false);
3347std::string cling::printValue(
const XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError *
v)
3350 return "xValueWithError: nullptr\n";
3351 return v->__repr__();
3353std::string cling::printValue(
const std::map<std::string, XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError> *
m)
3357 std::string out =
"{\n";
3358 for (
auto [k,
v] : *
m) {
3359 out +=
"\"" + k +
"\" => " + printValue(&
v) +
"\n";
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
const char Option_t
Option string (const char)
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
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).
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::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > fData
std::vector< std::tuple< int, double, double > > altToys
std::shared_ptr< const RooAbsCollection > coords
std::shared_ptr< const RooFitResult > cfit_lbound(bool readOnly=false)
std::shared_ptr< xRooNLLVar > nllVar
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)
void setAltVal(double val)
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())
std::shared_ptr< const RooFitResult > fGenFit
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())
void setNullVal(double val)
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
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, int tsType=0)
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
void SetOption(const RooCmdArg &opt)
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.
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
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
void setName(const char *name)
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.
bool hasRange(const char *name) const override
Check if variable has a binning with given name.
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.
void SetAltDetailedOutput(RooDataSet *d)
double fNullPValue
p-value for the null hypothesis (small number means disfavoured)
double fAlternatePValueError
error of p-value for the alternate hypothesis (small number means disfavoured)
void SetNullDetailedOutput(RooDataSet *d)
void SetBackgroundAsAlt(bool l=true)
void SetAltPValue(double pvalue)
void SetNullDistribution(SamplingDistribution *null)
void SetTestStatisticData(const double tsd)
void SetAltPValueError(double err)
void SetFitInfo(RooDataSet *d)
double fNullPValueError
error of p-value for the null hypothesis (small number means disfavoured)
void SetAltDistribution(SamplingDistribution *alt)
double fAlternatePValue
p-value for the alternate hypothesis (small number means disfavoured)
void SetNullPValue(double pvalue)
void SetNullPValueError(double err)
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.
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
const char * AsString() const
Return the date & time as a string (ctime() format).
TDirectory::TContext keeps track and restore the current directory.
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 SetPoint(Int_t i, Double_t x, Double_t y)
Set x and y values for point number i.
virtual void Sort(Bool_t(*greater)(const TGraph *, Int_t, Int_t)=&TGraph::CompareX, Bool_t ascending=kTRUE, Int_t low=0, Int_t high=-1111)
Sorts the points of this TGraph using in-place quicksort (see e.g.
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.
virtual Double_t GetPointY(Int_t i) const
Get y value for point i.
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.
A TMultiGraph is a collection of TGraph (or derived) objects.
The TNamed class is the base class for all named ROOT classes.
virtual void SetTitle(const char *title="")
Set the title of the TNamed.
const char * GetName() const override
Returns name of object.
const char * GetTitle() const override
Returns title of object.
virtual void SetName(const char *name)
Set the name of the TNamed.
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 gaussian_cdf_c(double x, double sigma=1, double x0=0)
Alternative name for same function.
static constexpr auto NumIntegration
Alias of MsgLevel::NumericIntegration for backwards compatibility.
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)