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) {
184 auto gl =
dynamic_cast<RooCmdArg *
>(opts.
At(i))->getSet(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());
217 if (
auto extCon =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"ExternalConstraints"))) {
218 for (
auto con : *extCon->getSet(0)) {
219 _vars->add(*std::unique_ptr<RooArgSet>(con->getVariables()));
222 auto _funcGlobs = std::unique_ptr<RooArgSet>(
dynamic_cast<RooArgSet *
>(_vars->selectCommon(*
fGlobs)));
226 if (
auto flag =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"ReuseNLL"))) {
232 if (
auto range =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"RangeWithName"))) {
233 TString rangeName = range->getString(0);
240 std::vector<TString> chanPatterns;
242 bool hasRange(
false);
243 std::string noneCatRanges;
245 chanPatterns.emplace_back(pattern);
246 if (_cat.hasRange(chanPatterns.back())) {
249 if (!noneCatRanges.empty())
250 noneCatRanges +=
",";
251 noneCatRanges += chanPatterns.back();
258 if (noneCatRanges.empty()) {
259 fOpts->Remove(range);
262 range->setString(0, noneCatRanges.c_str());
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);
272 bool matchAny =
false;
273 for (
auto &
p : chanPatterns) {
274 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
280 newPdf->addPdf(*_pdf,
c.first.c_str());
315 (opts.find(
"GlobalObservables"))
316 ? dynamic_cast<
RooCmdArg *>(opts.find(
"GlobalObservables"))->getSet(0)->snapshot()
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);
372 bool isBinned =
false;
373 bool hasBinned =
false;
376 isBinned =
a->getInt(0);
378 std::map<RooAbsArg *, bool> origValues;
381 if (
a->InheritsFrom(
"RooRealSumPdf")) {
384 bool setBinned =
false;
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));
400 origValues[
a] =
a->getAttribute(
"BinnedLikelihood");
401 a->setAttribute(
"BinnedLikelihood", setBinned);
405 std::map<RooAbsPdf *, std::string> normRanges;
406 if (
auto range =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"RangeWithName"))) {
407 TString rangeName = range->getString(0);
408 if (
auto sr =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"SplitRange"));
412 for (
auto cat : simPdf->indexCat()) {
413 auto subpdf = simPdf->
getPdf(cat.first.c_str());
417 srangeName.
ReplaceAll(
",",
"_" + cat.first +
",");
418 srangeName +=
"_" + cat.first;
420 subpdf->treeNodeServerList(&ss,
nullptr,
true,
false);
423 if (
a->InheritsFrom(
"RooAddPdf")) {
425 normRanges[
p] =
p->normRange() ?
p->normRange() :
"";
426 p->setNormRange(srangeName);
435 if (
a->InheritsFrom(
"RooAddPdf")) {
437 normRanges[
p] =
p->normRange() ?
p->normRange() :
"";
438 p->setNormRange(rangeName);
445 std::set<std::string> setNames;
448 setNames.insert(
a.first);
451 for (
auto &
a : setNames) {
455 std::set<std::string> attribs;
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());
464 for (
auto &[k,
v] : normRanges)
465 k->setNormRange(
v ==
"" ?
nullptr :
v.c_str());
467 for (
auto &
a : attribs)
468 std::shared_ptr<RooAbsReal>::get()->setAttribute(
a.c_str());
474 std::shared_ptr<RooAbsReal>::get()->SetName(oldName);
475 if (!origValues.empty()) {
477 std::shared_ptr<RooAbsReal>::get()->getVal();
478 for (
auto &[o,
v] : origValues)
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);
513 fCfits(std::make_shared<std::map<std::string,
xRooFitResult>>())
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);
559 fCfits->insert(std::pair((alias) ? alias : poiValues, out));
566 throw std::runtime_error(
"xRooFitResult::ifit: par not found");
575 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
576 auto _ifit = ifit(
np, up, prefit);
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");
591 dynamic_cast<RooRealVar *
>((prefit ?
get()->floatParsInit() :
get()->floatParsFinal()).find(
np));
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);
633 return (up) ?
static_cast<RooRealVar *
>(poiVar)->getErrorHi() :
static_cast<RooRealVar *
>(poiVar)->getErrorLo();
637 int idx = vars.
index(poi);
638 return sqrt(
get()->conditionalCovarianceMatrix(vars)(idx, idx));
641 auto _cfit = cfit(npNames.
Data(), nps);
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)));
663 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
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);
672 for (
auto &[
n,
v] : ranks) {
673 if (
v >= approxThreshold) {
675 v = impact(poi,
n.c_str(), up, prefit);
677 v = std::numeric_limits<double>::quiet_NaN();
683 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
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");
693 for (
auto &[
n,
v] : ranks) {
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;
753 auto binnedOpt =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"Binned"));
757 bool allChannels =
true;
758 for (
auto c : simPdf.
bins()) {
762 c->
get<
RooAbsArg>()->treeNodeServerList(&nodes,
nullptr,
true,
false);
763 bool isBinned =
false;
764 for (
auto a : nodes) {
765 if (
a->InheritsFrom(
"RooRealSumPdf") &&
766 ((binnedOpt && binnedOpt->getInt(0)) || (!binnedOpt &&
a->getAttribute(
"BinnedLikelihood")))) {
768 out.insert(chanName(chanName.
Index(
"=") + 1, chanName.
Length()).
Data());
783 pdf()->treeNodeServerList(&nodes,
nullptr,
true,
false);
784 for (
auto a : nodes) {
785 if (
a->InheritsFrom(
"RooRealSumPdf") &&
786 ((binnedOpt && binnedOpt->getInt(0)) || (!binnedOpt &&
a->getAttribute(
"BinnedLikelihood")))) {
801 if (
size_t(_data->numEntries()) <= entry)
803 auto _pdf =
pdf().get();
804 std::unique_ptr<RooAbsCollection> _robs(_pdf->getObservables(_data->get()));
805 *_robs = *_data->get(entry);
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()) {
820 volume *= (
b - lowEdge);
846 for (
auto c : cTerm->list()) {
847 if (std::string(
c->ClassName()) ==
"RooAbsPdf") {
856 gaus->getMean().GetName()));
861 }
else if (
auto pois =
dynamic_cast<RooPoisson *
>(
c)) {
875 std::unique_ptr<RooAbsCollection>(
pars()->selectByAttrib(
"Constant",
false))->
size();
889 std::unique_ptr<RooAbsCollection> _floats(
pars()->selectByAttrib(
"Constant",
false));
891 _floats->remove(*std::unique_ptr<RooAbsCollection>(_constraintTerm->getVariables()));
905 return _constraintTerm->getVal();
932 return std::numeric_limits<double>::quiet_NaN();
946 double out = _data->sumEntries();
947 for (
int i = 0; i < _data->numEntries(); i++) {
949 double w = _data->weight();
952 out -=
w * std::log(
w);
953 if (_binnedChannels.count(
"*")) {
955 }
else if (_binnedChannels.empty()) {
959 if (_binnedChannels.count(_data->get()->getCatLabel(cat->
GetName()))) {
965 throw std::runtime_error(
"Cannot determine category of RooSimultaneous pdf");
976 auto out = std::shared_ptr<RooArgSet>(
get()->getVariables());
977 if (stripGlobalObs &&
fGlobs) {
978 out->remove(*
fGlobs,
true,
true);
986 return Scan(*std::unique_ptr<RooAbsCollection>(
get()->getVariables()->selectByName(scanPars)), coords, profilePars);
993 if (scanPars.
size() > 2 || scanPars.
empty())
1003 std::unique_ptr<RooAbsCollection> funcVars(
get()->getVariables());
1006 for (
auto &coord : coords) {
1007 if (coord.size() != scanPars.
size()) {
1008 throw std::runtime_error(
"Invalid coordinate");
1010 for (
size_t i = 0; i < coord.size(); i++) {
1014 if (profilePars.
empty()) {
1031 auto _pars =
pars();
1033 if (sOpt ==
"sensitivity") {
1038 if (sOpt ==
"floating") {
1040 auto floats = std::unique_ptr<RooAbsCollection>(_pars->selectByAttrib(
"Constant",
false));
1063 if (
auto a = _pars->find(s);
a)
1067 if (vars.
size() == 1) {
1075 bool normRange =
false;
1083 out->SetName(
get()->GetName());
1089 double step = (
v->getMax() -
v->getMin()) / 100;
1090 double init =
v->getVal();
1091 double initVal =
func()->getVal();
1093 auto currTime = std::chrono::steady_clock::now();
1094 while (out->GetN() < 100 && (low >
v->getMin() || high < v->getMax())) {
1095 if (out->GetN() == 0) {
1096 out->SetPoint(out->GetN(), low, 0);
1105 if (low >
v->getMin()) {
1107 auto _v =
func()->getVal();
1108 if (std::isnan(_v) || std::isinf(_v)) {
1109 if (bad->
GetN() == 0)
1113 out->SetPoint(out->GetN(), low, _v - initVal);
1117 if (high < v->getMax()) {
1119 auto _v =
func()->getVal();
1120 if (std::isnan(_v) || std::isinf(_v)) {
1121 if (bad->
GetN() == 0)
1125 out->SetPoint(out->GetN(), high, _v - initVal);
1132 if (std::chrono::steady_clock::now() - currTime > std::chrono::seconds(1)) {
1133 currTime = std::chrono::steady_clock::now();
1142#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
1143 gPad->GetCanvas()->ResetUpdated();
1148 Error(
"Draw",
"Name a parameter to scan over: Draw(<name>) , choose from: %s",
1149 _pars->empty() ?
"" : _pars->contentsString().c_str());
1163 return setData(std::dynamic_pointer_cast<RooAbsData>(
data.fComp),
1164 std::shared_ptr<const RooAbsCollection>(
data.globs().argList().snapshot()));
1167bool xRooNLLVar::setData(
const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &_data)
1170 if (
fData == _data.first &&
fGlobs == _data.second)
1175 auto _dglobs = (_data.second) ? _data.second
1176 : std::shared_ptr<const RooAbsCollection>(_data.first->getGlobalObservables(),
1179 if (
fGlobs && !(
fGlobs->empty() && !_dglobs) && _data.first &&
1183 throw std::runtime_error(
"Missing globs");
1187 std::unique_ptr<RooAbsCollection> _actualGlobs(
fPdf->getObservables(s));
1190 std::unique_ptr<RooAbsCollection> _actualGlobs2(
fPdf->getObservables(s2));
1191 if (!_actualGlobs->equals(*_actualGlobs2)) {
1193 rC.
add(*_actualGlobs2);
1197 lC.
add(*_actualGlobs);
1200 throw std::runtime_error(
TString::Format(
"globs mismatch: adding %s removing %s",
r.Data(),
l.Data()));
1205 if (!std::shared_ptr<RooAbsReal>::get()) {
1206 fData = _data.first;
1219 fFuncVars->setAttribAll(
"Constant",
false);
1221 std::shared_ptr<RooAbsData> __data =
fData;
1223 fData = _data.first;
1244 fData = _data.first;
1246 }
catch (std::runtime_error &) {
1251 fFuncVars->setAttribAll(
"Constant",
false);
1253 std::shared_ptr<RooAbsData> __data =
fData;
1255 fData = _data.first;
1259 throw std::runtime_error(
"Unable to setData");
1266 }
else if (
auto f = std::unique_ptr<RooAbsCollection>(
fConstVars->selectByAttrib(
"Constant",
false)); !
f->empty()) {
1289 if (std::shared_ptr<RooAbsReal>::get()) {
1357 return fData->sumEntries() * log(1.0 * (s->servers().size() - 1));
1369 for (
int i = 0; i <
fData->numEntries(); i++) {
1379 auto _func =
func();
1382 for (
auto s : _func->servers()) {
1386 for (
auto s2 : s->servers()) {
1405 bool doCLs = sWhat.
Contains(
"pcls");
1406 bool doNull = sWhat.
Contains(
"pnull");
1407 bool doAlt = sWhat.
Contains(
"palt");
1408 double nSigma = (sWhat.
Contains(
"exp"))
1413 : std::numeric_limits<double>::quiet_NaN();
1415 bool toys = sWhat.
Contains(
"toys");
1419 bool readOnly = sWhat.
Contains(
"readonly");
1426 if (getVal(sWhat +
" readonly").second != 0) {
1434 if (nullToys.size() < nToys) {
1435 addNullToys(nToys - nullToys.size());
1437 if (altToys.size() < nToysAlt) {
1438 addAltToys(nToysAlt - altToys.size());
1440 }
else if (doCLs && toys) {
1442 addCLsToys(100, 0, 0.05, nSigma);
1448 RestoreNll(std::shared_ptr<xRooNLLVar> &
v,
bool r) : rr(
r), var(
v)
1450 if (rr && var && var->get()) {
1451 _readOnly = var->get()->getAttribute(
"readOnly");
1452 var->get()->setAttribute(
"readOnly", rr);
1460 var->get()->setAttribute(
"readOnly", _readOnly);
1464 bool _readOnly =
false;
1466 std::shared_ptr<xRooNLLVar> &var;
1469 RestoreNll rest(nllVar, readOnly);
1472 return (toys) ? ts_toys(nSigma) : ts_asymp(nSigma);
1474 return (toys) ? pNull_toys(nSigma) : pNull_asymp(nSigma);
1476 return (toys) ? pAlt_toys(nSigma) : pAlt_asymp(nSigma);
1478 return (toys) ? pCLs_toys(nSigma) : pCLs_asymp(nSigma);
1480 throw std::runtime_error(std::string(
"Unknown: ") +
what);
1487 out.add(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1494 out.setName(
"alt_poi");
1495 out.addClone(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1496 for (
auto a : out) {
1500 if (
auto s =
a->getStringAttribute(
"altVal"); s && strlen(s)) {
1503 v->setVal(std::numeric_limits<double>::quiet_NaN());
1513 if (me.ufit(
true) && !allowedStatusCodes.count(me.ufit(
true)->status()))
1515 if (me.cfit_null(
true) && !allowedStatusCodes.count(me.cfit_null(
true)->status()))
1517 if (me.cfit_alt(
true) && !allowedStatusCodes.count(me.cfit_alt(
true)->status()))
1519 if (me.asimov(
true))
1520 out += me.asimov(
true)->status() << 3;
1527 auto _alt_poi =
const_cast<xRooHypoPoint *
>(
this)->alt_poi();
1528 std::cout <<
"POI: " << _poi.contentsString() <<
" , null: ";
1530 for (
auto a : _poi) {
1539 std::cout <<
" , alt: ";
1541 bool any_alt =
false;
1542 for (
auto a : _alt_poi) {
1550 if (!std::isnan(
v->getVal()))
1553 std::cout <<
" , pllType: " << fPllType << std::endl;
1555 std::cout <<
" - ufit: ";
1557 std::cout << fUfit->GetName() <<
" " << fUfit->minNll() <<
" (status=" << fUfit->status() <<
") (";
1559 for (
auto a : _poi) {
1560 auto v =
dynamic_cast<RooRealVar *
>(fUfit->floatParsFinal().find(
a->GetName()));
1565 std::cout <<
v->
GetName() <<
"_hat: " <<
v->getVal() <<
" +/- " <<
v->getError();
1568 std::cout <<
")" << std::endl;
1570 std::cout <<
"Not calculated" << std::endl;
1572 std::cout <<
" - cfit_null: ";
1574 std::cout << fNull_cfit->GetName() <<
" " << fNull_cfit->minNll() <<
" (status=" << fNull_cfit->status() <<
")";
1576 std::cout <<
"Not calculated";
1579 std::cout << std::endl <<
" - cfit_alt: ";
1581 std::cout << fAlt_cfit->GetName() <<
" " << fAlt_cfit->minNll() <<
" (status=" << fAlt_cfit->status() <<
")"
1584 std::cout <<
"Not calculated" << std::endl;
1586 std::cout <<
" sigma_mu: ";
1588 if (!fAsimov || !fAsimov->fUfit || !fAsimov->fNull_cfit) {
1589 std::cout <<
"Not calculated";
1591 std::cout << const_cast<xRooHypoPoint *>(
this)->
sigma_mu().first <<
" +/- "
1595 std::cout << std::endl;
1596 std::cout <<
" - asimov ufit: ";
1597 if (fAsimov->fUfit) {
1598 std::cout << fAsimov->
fUfit->GetName() <<
" " << fAsimov->fUfit->minNll()
1599 <<
" (status=" << fAsimov->fUfit->status() <<
")";
1601 std::cout <<
"Not calculated";
1603 std::cout << std::endl <<
" - asimov cfit_null: ";
1604 if (fAsimov->fNull_cfit) {
1605 std::cout << fAsimov->fNull_cfit->GetName() <<
" " << fAsimov->fNull_cfit->minNll()
1606 <<
" (status=" << fAsimov->fNull_cfit->status() <<
")";
1608 std::cout <<
"Not calculated";
1611 std::cout << std::endl;
1613 std::cout << std::endl;
1616 std::cout <<
" - cfit_lbound: " << fLbound_cfit->GetName() <<
" " << fLbound_cfit->minNll()
1617 <<
" (status=" << fLbound_cfit->status() <<
")";
1620 std::cout <<
" - gfit: " << fGenFit->GetName() << std::endl;
1621 if (!nullToys.empty() || !altToys.empty()) {
1622 std::cout <<
" * null toys: " << nullToys.size();
1623 size_t firstToy = 0;
1624 while (firstToy < nullToys.size() && std::isnan(std::get<1>(nullToys[firstToy])))
1627 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1628 std::cout <<
" , alt toys: " << altToys.size();
1630 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1633 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1634 std::cout << std::endl;
1642 auto var =
dynamic_cast<RooRealVar *
>(ufit()->floatParsFinal().find(fPOIName()));
1646 throw std::runtime_error(
TString::Format(
"Cannot find POI: %s", fPOIName()));
1649 throw std::runtime_error(
"Unconditional fit unavailable");
1656 if (fGenFit && isExpected) {
1664 : hypoTestResult(htr)
1676 if (toys->getGlobalObservables()) {
1677 coords = std::shared_ptr<RooAbsCollection>(toys->getGlobalObservables()->snapshot());
1679 for (
int i = 0; i < toys->numEntries(); i++) {
1680 auto toy = toys->get(i);
1682 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1687 for (
int i = 0; i < toys->numEntries(); i++) {
1688 auto toy = toys->get(i);
1690 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1701 if (!fAsimov && (nllVar || hypoTestResult)) {
1702 auto theFit = (!
fData.first && fGenFit && !isExpected)
1704 : cfit_alt(readOnly);
1707 if (!theFit || allowedStatusCodes.find(theFit->status()) == allowedStatusCodes.end())
1709 fAsimov = std::make_shared<xRooHypoPoint>(*
this);
1710 fAsimov->coords.reset(fAsimov->coords->snapshot());
1711 fAsimov->hypoTestResult.reset();
1713 for (
auto p : fAsimov->poi()) {
1716 v->deleteSharedProperties();
1720 fAsimov->nullToys.clear();
1721 fAsimov->altToys.clear();
1722 fAsimov->fUfit = retrieveFit(3);
1723 fAsimov->fNull_cfit = retrieveFit(4);
1724 fAsimov->fAlt_cfit.reset();
1726 std::make_pair(
nullptr,
nullptr);
1727 fAsimov->fGenFit = theFit;
1728 fAsimov->isExpected =
true;
1737 return std::pair<double, double>(1, 0);
1738 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1740 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1741 auto _sigma_mu = sigma_mu();
1743 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1746 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1749 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1750 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1756 return std::pair<double, double>(1, 0);
1757 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1759 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1760 auto _sigma_mu = sigma_mu();
1762 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1765 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1768 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1770 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1775 if (fNullVal() == fAltVal())
1776 return std::pair<double, double>(1, 0);
1779 return std::pair<double, double>(1, 0);
1780 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1782 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1784 auto _ts_asymp = ts_asymp(nSigma);
1785 auto _sigma_mu = sigma_mu();
1787 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1790 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1793 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1795 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1798 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1801 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1803 auto nom = (nom1 == 0) ? 0 : nom1 / nom2;
1804 auto up = (up1 == 0) ? 0 : up1 / up2;
1805 auto down = (down1 == 0) ? 0 : down1 / down2;
1807 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1812 if (std::isnan(nSigma))
1814 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1815 auto _sigma_mu = sigma_mu();
1816 if (!first_poi || (!std::isnan(nSigma) && std::isnan(_sigma_mu.first)))
1817 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1819 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1821 _sigma_mu.first + _sigma_mu.second, first_poi->getMin(
"physical"),
1822 first_poi->getMax(
"physical"));
1824 _sigma_mu.first - _sigma_mu.second, first_poi->getMin(
"physical"),
1825 first_poi->getMax(
"physical"));
1826 return std::pair<double, double>(nom, std::max(std::abs(nom - up), std::abs(nom - down)));
1831 if (std::isnan(nSigma))
1834 size_t firstToy = 0;
1835 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1837 if (firstToy >= altToys.size())
1838 return std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
1841 return std::pair(std::get<1>(altToys[targetIdx]), (std::get<1>(altToys[std::min(
int(altToys.size()), targetIdx)]) -
1842 std::get<1>(altToys[std::max(0, targetIdx)])) /
1848 auto _ufit = ufit(readOnly);
1851 return std::pair<double, double>(hypoTestResult->GetTestStatisticData(), 0);
1852 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1854 if (allowedStatusCodes.find(_ufit->status()) == allowedStatusCodes.end()) {
1855 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1857 if (
auto _first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1858 _first_poi && _first_poi->
getMin(
"physical") > _first_poi->getMin() &&
1859 mu_hat().getVal() < _first_poi->getMin(
"physical")) {
1861 _ufit = cfit_lbound(readOnly);
1863 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1870 return std::pair<double, double>(0, 0);
1871 if (!cfit_null(readOnly) || allowedStatusCodes.find(cfit_null(readOnly)->status()) == allowedStatusCodes.end())
1872 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1874 return std::pair<double, double>(2. * cFactor * (cfit_null(readOnly)->minNll() - _ufit->minNll()),
1875 2. * cFactor * sqrt(pow(cfit_null(readOnly)->edm(), 2) + pow(_ufit->edm(), 2)));
1881 if (!hypoTestResult)
1884 if (
auto fits = hypoTestResult->GetFitInfo()) {
1885 for (
int i = 0; i < fits->numEntries(); i++) {
1886 auto fit = fits->get(i);
1887 if (fit->getCatIndex(
"type") !=
type)
1891 fits->getGlobalObservables()->getStringValue(
TString::Format(
"%s.name", fit->getCatLabel(
"type")));
1894 for (
auto file : *
gROOT->GetListOfFiles()) {
1898 k->GetMotherDir()->GetList()
1901 if (
auto cachedFit = (storedFr) ? storedFr->
fr.get() : k->ReadObject<
RooFitResult>(); cachedFit) {
1904 k->GetMotherDir()->Add(storedFr);
1907 return storedFr->
fr;
1911 auto rfit = std::make_shared<RooFitResult>(_name.c_str(),
TUUID(_name.c_str()).
GetTime().
AsString());
1912 rfit->setStatus(fit->getRealValue(
"status"));
1913 rfit->setMinNLL(fit->getRealValue(
"minNll"));
1914 rfit->setEDM(fit->getRealValue(
"edm"));
1915 rfit->setCovQual(fit->getRealValue(
"covQual"));
1917 std::unique_ptr<RooAbsCollection> par_hats(
1918 hypoTestResult->GetFitInfo()->getGlobalObservables()->selectByName(coords->contentsString().c_str()));
1919 par_hats->setName(
"floatParsFinal");
1920 rfit->setFinalParList(*par_hats);
1927 rfit->setCovarianceMatrix(cov);
1938 if (
auto rfit = retrieveFit(0)) {
1939 return fUfit = rfit;
1941 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1943 if (!nllVar->fFuncVars)
1944 nllVar->reinitialize();
1947 if (!readOnly && isExpected && fGenFit) {
1949 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1950 nllVar->get()->setAttribute(
"readOnly");
1951 auto out = ufit(
true);
1952 nllVar->get()->setAttribute(
"readOnly", tmp);
1957 nllVar->setData(
data());
1960 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1961 nllVar->setData(
fData);
1963 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1964 *nllVar->fFuncVars = *coords;
1965 if (nllVar->fFuncGlobs)
1966 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1967 std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))
1968 ->setAttribAll(
"Constant",
false);
1971 nllVar->fFuncVars->assignValueOnly(fGenFit->constPars());
1972 nllVar->fFuncVars->assignValueOnly(fGenFit->floatParsFinal());
1974 nllVar->get()->SetName(
1975 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1977 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1979 }
else if (!std::isnan(fAltVal())) {
1981 for (
auto _poiCoord : poi()) {
1982 auto _poi =
dynamic_cast<RooRealVar *
>(nllVar->fFuncVars->find(_poiCoord->GetName()));
1984 _poi->
setVal(_poi->getStringAttribute(
"initVal") ?
TString(_poi->getStringAttribute(
"initVal")).
Atof()
1989 return (fUfit = nllVar->minimize());
1995 for (
auto &
c : coll) {
1998 out +=
c->GetName();
2014 if (
auto rfit = retrieveFit(1)) {
2015 return fNull_cfit = rfit;
2017 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2019 if (!nllVar->fFuncVars)
2020 nllVar->reinitialize();
2023 if (!readOnly && isExpected && fGenFit) {
2025 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2026 nllVar->get()->setAttribute(
"readOnly");
2027 auto out = cfit_null(
true);
2028 nllVar->get()->setAttribute(
"readOnly", tmp);
2033 nllVar->setData(
data());
2036 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2037 nllVar->setData(
fData);
2041 *nllVar->fFuncVars = fUfit->floatParsFinal();
2043 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2044 *nllVar->fFuncVars = *coords;
2045 if (nllVar->fFuncGlobs)
2046 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2048 nllVar->fFuncVars->find(fPOIName())
2049 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2052 nllVar->get()->SetName(
2053 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2055 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2057 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(poi()).c_str());
2058 return (fNull_cfit = nllVar->minimize());
2063 auto _first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
2066 if (_first_poi->getMin(
"physical") <= _first_poi->getMin())
2069 return fLbound_cfit;
2070 if (
auto rfit = retrieveFit(6)) {
2071 return fLbound_cfit = rfit;
2073 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2075 if (!nllVar->fFuncVars)
2076 nllVar->reinitialize();
2079 if (!readOnly && isExpected && fGenFit) {
2081 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2082 nllVar->get()->setAttribute(
"readOnly");
2083 auto out = cfit_lbound(
true);
2084 nllVar->get()->setAttribute(
"readOnly", tmp);
2089 nllVar->setData(
data());
2092 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2093 nllVar->setData(
fData);
2097 *nllVar->fFuncVars = fUfit->floatParsFinal();
2099 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2100 *nllVar->fFuncVars = *coords;
2101 nllVar->fFuncVars->setRealValue(_first_poi->GetName(), _first_poi->getMin(
"physical"));
2102 if (nllVar->fFuncGlobs)
2103 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2105 nllVar->fFuncVars->find(fPOIName())
2106 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2109 nllVar->get()->SetName(
2110 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2112 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2114 nllVar->get()->setStringAttribute(
2116 collectionContents(*std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))).c_str());
2117 return (fLbound_cfit = nllVar->minimize());
2122 if (std::isnan(fAltVal()))
2126 if (
auto rfit = retrieveFit(2)) {
2127 return fAlt_cfit = rfit;
2129 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2131 if (!nllVar->fFuncVars)
2132 nllVar->reinitialize();
2135 if (!readOnly && isExpected && fGenFit) {
2137 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2138 nllVar->get()->setAttribute(
"readOnly");
2139 auto out = cfit_alt(
true);
2140 nllVar->get()->setAttribute(
"readOnly", tmp);
2145 nllVar->setData(
data());
2148 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2149 nllVar->setData(
fData);
2153 *nllVar->fFuncVars = fUfit->floatParsFinal();
2155 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2156 *nllVar->fFuncVars = *coords;
2157 if (nllVar->fFuncGlobs)
2158 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2159 *nllVar->fFuncVars = alt_poi();
2161 nllVar->get()->SetName(
2162 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2164 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2166 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(alt_poi()).c_str());
2167 return (fAlt_cfit = nllVar->minimize());
2173 auto asi = asimov(readOnly);
2176 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
2179 auto out = asi->pll(readOnly);
2180 return std::pair<double, double>(std::abs(fNullVal() - fAltVal()) / sqrt(out.first),
2181 out.second * 0.5 * std::abs(fNullVal() - fAltVal()) /
2182 (out.first * sqrt(out.first)));
2187 auto _ts = ts_toys(nSigma);
2188 if (std::isnan(_ts.first))
2191 return std::pair<double, double>(1, 0);
2195 auto &_theToys = (alt) ? altToys : nullToys;
2197 if (_theToys.empty()) {
2198 return std::pair(0.5, std::numeric_limits<double>::infinity());
2205 double result_err_up = 0;
2206 double result_err_down = 0;
2207 for (
auto &toy : _theToys) {
2208 if (std::isnan(std::get<1>(toy))) {
2211 bool res = std::get<1>(toy) >= _ts.first;
2212 if (std::get<2>(toy) != 1) {
2218 result += std::get<2>(toy);
2219 if (std::get<1>(toy) >= _ts.first - _ts.second)
2220 result_err_up += std::get<2>(toy);
2221 if (std::get<1>(toy) >= _ts.first - _ts.second)
2222 result_err_down += std::get<2>(toy);
2227 result_err_down -=
result;
2228 double result_err = std::max(std::abs(result_err_up), std::abs(result_err_down));
2231 result_err /= _theToys.size();
2234 result /= (_theToys.size() - nans);
2238 return std::pair<double, double>(
result, result_err);
2243 return pX_toys(
false, nSigma);
2248 if (!std::isnan(nSigma)) {
2251 return pX_toys(
true, nSigma);
2257 out.coords = coords;
2258 out.fPllType = fPllType;
2259 out.nllVar = nllVar;
2262 auto _cfit = cfit_null();
2265 if (!nllVar->fFuncVars)
2266 nllVar->reinitialize();
2270 out.fGenFit = _cfit;
2277 out.coords = coords;
2278 out.fPllType = fPllType;
2279 out.nllVar = nllVar;
2284 if (!nllVar->fFuncVars)
2285 nllVar->reinitialize();
2290 out.fGenFit = cfit_alt();
2295 bool targetCLs,
double relErrThreshold,
size_t maxToys)
2297 if ((alt && !cfit_alt()) || (!alt && !cfit_null())) {
2298 throw std::runtime_error(
"Cannot add toys, invalid conditional fit");
2301 auto condition = [&]() {
2304 auto obs = targetCLs ? pCLs_toys(target_nSigma) : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma));
2305 if (!std::isnan(obs.first)) {
2306 double diff = (
target < 0) ? obs.first : std::abs(obs.first -
target);
2307 double err = obs.second;
2308 if (err > 1
e-4 && diff <= relErrThreshold * obs.second) {
2312 auto pNull = pNull_toys(target_nSigma);
2313 auto pAlt = pAlt_toys(target_nSigma);
2316 alt = (pAlt.second * pNull.first > pNull.second * pAlt.first);
2317 if ((alt ? pAlt.second : pNull.second) < 1
e-4)
2326 if (!std::isnan(
target) && std::isnan(ts_toys(target_nSigma).first)) {
2327 if (std::isnan(target_nSigma)) {
2328 throw std::runtime_error(
"Cannot target obs p-value because ts value unavailable");
2330 if (targetCLs && pCLs_toys(target_nSigma).second == 0) {
2336 Info(
"addToys",
"First generating 100 alt toys in order to determine expected ts value");
2337 addToys(
true, 100, initialSeed);
2339 if (std::isnan(ts_toys(target_nSigma).first)) {
2340 throw std::runtime_error(
"Unable to determine expected ts value");
2359 size_t toysAdded(0);
2360 size_t altToysAdded(0);
2365 auto &toys = (alt) ? altToys : nullToys;
2366 if (toys.size() >= maxToys) {
2371 if (!std::isnan(
target) && !condition()) {
2374 auto currVal = std::isnan(
target) ? std::pair(0., 0.)
2375 : (targetCLs ? pCLs_toys(target_nSigma)
2376 : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma)));
2377 size_t nnToys = std::min(
size_t(nToys), (maxToys - toys.size()));
2379 for (
size_t i = 0; i < nnToys; i++) {
2381 auto toy = ((alt) ? generateAlt(seed) : generateNull(seed));
2384 toys.push_back(std::make_tuple(seed, toy.pll().first, 1.));
2386 (alt ? altToysAdded : toysAdded)++;
2387 if (std::isnan(std::get<1>(toys.back())))
2389 g->SetPoint(
g->GetN(),
g->GetN(), s.
RealTime() - lastTime);
2393 <<
TString::Format(
"Generated %d/%d %s hypothesis toys [%.2f toys/s]",
2394 int(alt ? altToysAdded : toysAdded),
int(nnToys), alt ?
"alt" :
"null",
2396 if (!std::isnan(
target)) {
2397 std::cout <<
" [current=" << currVal.first <<
"+/-" << currVal.second <<
" target=" <<
target
2398 <<
" nSigma=" << target_nSigma <<
"]";
2400 std::cout <<
"..." << std::flush;
2401 lasti = altToysAdded + toysAdded;
2416 for (
auto &t : toys) {
2417 if (std::isnan(std::get<1>(t)))
2418 std::get<1>(t) = -std::numeric_limits<double>::infinity();
2420 std::sort(toys.begin(), toys.end(),
2421 [](
const decltype(nullToys)::value_type &
a,
const decltype(nullToys)::value_type &
b) ->
bool {
2422 if (std::isnan(std::get<1>(a)))
2424 if (std::isnan(std::get<1>(b)))
2426 return std::get<1>(a) < std::get<1>(b);
2428 for (
auto &t : toys) {
2429 if (std::isinf(std::get<1>(t)))
2430 std::get<1>(t) = std::numeric_limits<double>::quiet_NaN();
2432 if (std::isnan(
target)) {
2439 }
while (condition());
2442 <<
"Finished Generating ";
2444 std::cout << toysAdded <<
" null ";
2447 std::cout << altToysAdded <<
" alt ";
2449 std::cout <<
"toys " <<
TString::Format(
"[%.2f toys/s overall]",
double(toysAdded + altToysAdded) / s2.
RealTime())
2454#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2455 gPad->GetCanvas()->ResetUpdated();
2462 std::cout <<
"Warning: " << nans <<
" toys were bad" << std::endl;
2469 addToys(
false, nToys, seed,
target, target_nSigma);
2473 addToys(
true, nToys, seed,
target, target_nSigma);
2478 addToys(
false, nToys, seed,
target, target_nSigma,
true);
2539 out.nllVar = std::make_shared<xRooNLLVar>(*
this);
2544 while (pattern.NextToken()) {
2547 double val = std::numeric_limits<double>::quiet_NaN();
2548 auto i = s.
Index(
"=");
2553 throw std::runtime_error(
"poiValues must contain value");
2558 throw std::runtime_error(
"Cannot find poi");
2559 if (!std::isnan(val))
2562 if (poiNames !=
"") {
2567 if (poiNames ==
"") {
2568 throw std::runtime_error(
"No poi");
2570 if (!std::isnan(alt_value)) {
2571 std::unique_ptr<RooAbsCollection> thePoi(
fFuncVars->selectByName(poiNames));
2572 for (
auto b : *thePoi) {
2573 if (!
static_cast<RooRealVar *
>(
b)->hasRange(
"physical")) {
2574 static_cast<RooRealVar *
>(
b)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2578 auto _snap = std::unique_ptr<RooAbsCollection>(
fFuncVars->selectByAttrib(
"Constant",
true))->snapshot();
2579 _snap->setAttribAll(
"poi",
false);
2580 std::unique_ptr<RooAbsCollection> _poi(_snap->selectByName(poiNames));
2581 _poi->setAttribAll(
"poi",
true);
2582 if (std::isnan(alt_value)) {
2583 for (
auto a : *_poi)
2584 a->setStringAttribute(
"altVal", nullptr);
2586 for (
auto a : *_poi)
2587 a->setStringAttribute(
"altVal",
TString::
Format(
"%g", alt_value));
2590 _snap->remove(*
fGlobs,
true,
true);
2591 out.coords.reset(_snap);
2593 auto _type = pllType;
2596 if (std::isnan(alt_value)) {
2598 }
else if (
dynamic_cast<RooRealVar *
>(_poi->first())->
getVal() >= alt_value) {
2605 out.fPllType = _type;
2610xRooNLLVar::xRooHypoPoint
2616 std::unique_ptr<RooAbsCollection> _poi(
fFuncVars->selectByAttrib(
"poi",
true));
2617 if (_poi->empty()) {
2618 throw std::runtime_error(
"No POI specified in model");
2619 }
else if (_poi->size() != 1) {
2620 throw std::runtime_error(
"Multiple POI specified in model");
2622 return hypoPoint(_poi->first()->GetName(),
value, alt_value, pllType);
2634 if (!nllVar && !hypoTestResult)
2639 bool hasSame = sOpt.
Contains(
"same");
2644 TH1 *hAxis =
nullptr;
2646 auto clearPad = []() {
2648 if (
gPad->GetNumber() == 0) {
2656 if (!hasSame || !pad) {
2667 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
2674 double _min = std::numeric_limits<double>::quiet_NaN();
2675 double _max = -std::numeric_limits<double>::quiet_NaN();
2677 for (
auto &
p : nullToys) {
2678 if (std::get<2>(
p) == 0)
2680 if (std::isnan(std::get<1>(
p)))
2682 _min = std::min(std::get<1>(
p), _min);
2683 _max = std::max(std::get<1>(
p), _max);
2685 for (
auto &
p : altToys) {
2686 if (std::get<2>(
p) == 0)
2688 if (std::isnan(std::get<1>(
p)))
2690 _min = std::min(std::get<1>(
p), _min);
2691 _max = std::max(std::get<1>(
p), _max);
2695 if (!std::isnan(obs.first)) {
2696 _min = std::min(obs.first - std::abs(obs.first) * 0.1, _min);
2697 _max = std::max(obs.first + std::abs(obs.first) * 0.1, _max);
2700 auto pNull = pNull_toys();
2701 auto pAlt = pAlt_toys();
2702 auto pNullA = pNull_asymp();
2703 auto pAltA = pAlt_asymp();
2705 auto asi = (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit) ? fAsimov->pll().first
2706 : std::numeric_limits<double>::quiet_NaN();
2709 _min = std::min(asi - std::abs(asi), _min);
2710 _max = std::max(asi + std::abs(asi), _max);
2715 auto _poi =
dynamic_cast<RooRealVar *
>(poi().first());
2717 auto makeHist = [&](
bool isAlt) {
2719 auto h =
new TH1D((isAlt) ?
"alt_toys" :
"null_toys",
"", 100, _min, _max + (_max - _min) * 0.01);
2720 h->SetDirectory(
nullptr);
2721 size_t nBadOrZero = 0;
2722 for (
auto &
p : (isAlt) ? altToys : nullToys) {
2723 double w = std::isnan(std::get<1>(
p)) ? 0 : std::get<2>(
p);
2726 if (!std::isnan(std::get<1>(
p)))
2727 h->Fill(std::get<1>(
p),
w);
2729 if (
h->GetEntries() > 0)
2730 h->Scale(1. /
h->Integral(0,
h->GetNbinsX() + 1));
2744 title +=
TString::Format(
"%s' = %g", fPOIName(), (isAlt) ? fAltVal() : fNullVal());
2745 title +=
TString::Format(
" , N_{toys}=%d",
int((isAlt) ? altToys.size() : nullToys.size()));
2754 h->SetMarkerSize(0);
2759 auto nullHist = makeHist(
false);
2760 auto altHist = makeHist(
true);
2763 auto h = (nullHist->GetEntries()) ? nullHist : altHist;
2766 auto axis =
static_cast<TH1 *
>(
h->Clone(
".axis"));
2768 axis->SetStats(
false);
2769 axis->Reset(
"ICES");
2771 axis->SetLineWidth(0);
2773 axis->SetMinimum(1
e-7);
2774 axis->GetYaxis()->SetRangeUser(1
e-7, 10);
2775 axis->SetMaximum(
h->GetMaximum());
2777 l =
new TLegend(0.4, 0.7, 1. -
gPad->GetRightMargin(), 1. -
gPad->GetTopMargin());
2778 l->SetName(
"legend");
2780 l->SetBorderSize(0);
2784 for (
auto o : *
gPad->GetListOfPrimitives()) {
2791 if (
h->GetEntries() > 0) {
2794 h->Draw(
"axissame");
2797 if (
h->GetEntries() > 0) {
2800 h->Draw(
"axissame");
2804 l->AddEntry(nullHist);
2805 l->AddEntry(altHist);
2808 if (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit && !std::isnan(sigma_mu().first) && !std::isnan(fAltVal())) {
2809 auto hh =
static_cast<TH1 *
>(nullHist->Clone(
"null_asymp"));
2811 hh->SetStats(
false);
2812 hh->SetLineStyle(2);
2814 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
2817 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2819 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2822 hh =
static_cast<TH1 *
>(altHist->Clone(
"alt_asymp"));
2824 hh->SetStats(
false);
2825 hh->SetLineStyle(2);
2827 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
2830 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2832 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2847 l->AddEntry(tl, label,
"l");
2849 if (!std::isnan(pNull.first) || !std::isnan(pAlt.first)) {
2850 auto pCLs = pCLs_toys();
2851 label +=
" p_{toy}=(";
2852 label += (std::isnan(pNull.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNull.first, pNull.second);
2853 label += (std::isnan(pAlt.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAlt.first, pAlt.second);
2854 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2856 if (label.Length() > 0)
2857 l->AddEntry(
"", label,
"");
2859 if (!std::isnan(pNullA.first) || !std::isnan(pAltA.first)) {
2860 auto pCLs = pCLs_asymp();
2861 label +=
" p_{asymp}=(";
2862 label += (std::isnan(pNullA.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNullA.first, pNullA.second);
2863 label += (std::isnan(pAltA.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAltA.first, pAltA.second);
2864 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2866 if (label.Length() > 0)
2867 l->AddEntry(
"", label,
"");
2869 if (
auto ax =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
".axis")))
2870 ax->GetYaxis()->SetRangeUser(1
e-7, 1);
2875 auto v =
dynamic_cast<RooRealVar *
>(poi().empty() ? nullptr : poi().first());
2877 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2887 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2891 return (inWords) ?
TString::Format(
"-2log[L(%s,#hat{#hat{#theta}})/L(#hat{%s},#hat{#theta})]",
v->GetTitle(),
2897 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2898 return (inWords) ?
TString::Format(
"Lower-Bound One-Sided Discovery PLR")
2907 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2916 return "Test Statistic";
2922 return (poi().empty()) ? nullptr : (poi().first())->GetName();
2926 auto first_poi =
dynamic_cast<RooAbsReal *
>(poi().first());
2927 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
2931 auto _alt_poi = alt_poi();
2932 auto first_poi =
dynamic_cast<RooAbsReal *
>(_alt_poi.first());
2933 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
2941 int tsType = nPoints;
2942 double alt_val = std::numeric_limits<double>::quiet_NaN();
2949 auto out =
hypoSpace(parName, pllType, alt_val);
2955 for (
auto p : out.poi()) {
2957 dynamic_cast<RooRealVar *
>(
p)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2958 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [0,inf]",
p->
GetName());
2959 }
else if (
dynamic_cast<RooRealVar *
>(
p)->hasRange(
"physical")) {
2960 dynamic_cast<RooRealVar *
>(
p)->removeRange(
"physical");
2961 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [-inf,inf] (i.e. removed range)",
2976 if (
int(low + 0.5) > 0) {
2977 out.AddPoints(parName,
int(low + 0.5), high, alt_value);
2979 if (!std::isnan(high) && !std::isnan(alt_value) && !(std::isinf(high) && std::isinf(alt_value))) {
2980 for (
auto p : out.poi()) {
2981 dynamic_cast<RooRealVar *
>(
p)->setRange(
"scan", high, alt_value);
2990 hs.
AddPoints(parName, nPoints, low, high);
2992 if (!std::isnan(low) && !std::isnan(high) && !(std::isinf(low) && std::isinf(high))) {
2993 for (
auto p : hs.
poi()) {
2994 dynamic_cast<RooRealVar *
>(
p)->setRange(
"scan", low, high);
3004 auto _poi = std::unique_ptr<RooAbsCollection>(
3005 std::unique_ptr<RooAbsCollection>(
pdf()->getVariables())->selectByAttrib(
"poi",
true));
3007 throw std::runtime_error(
"You must specify a POI for the hypoSpace");
3008 return hypoSpace(_poi->first()->GetName(), nPoints, low, high, alt_value, pllType);
3017 if (strlen(parName)) {
3018 std::unique_ptr<RooAbsCollection> axes(s.
pars()->selectByName(parName));
3020 throw std::runtime_error(
"parameter not found");
3021 axes->setAttribAll(
"axis",
true);
3026 s.
fNlls[s.
fPdfs.begin()->second] = std::make_shared<xRooNLLVar>(*
this);
3029 for (
auto poi : s.
poi()) {
3030 poi->setStringAttribute(
"altVal", std::isnan(alt_value) ? nullptr :
TString::Format(
"%f", alt_value));
3038 if (hypoTestResult) {
3039 return *hypoTestResult;
3042 out.SetBackgroundAsAlt(
true);
3043 out.SetName(
TUUID().AsString());
3046 bool setReadonly =
false;
3047 if (nllVar && !nllVar->get()->getAttribute(
"readOnly")) {
3049 nllVar->get()->setAttribute(
"readOnly");
3052 auto ts_obs = ts_asymp();
3054 out.SetTestStatisticData(ts_obs.first);
3061 "pllType",
"test statistic type",
3062 {{
"TwoSided", 0}, {
"OneSidedPositive", 1}, {
"OneSidedNegative", 2}, {
"Uncapped", 3}, {
"Unknown", 4}}));
3064 fitMeta.
addClone(ufit()->floatParsFinal());
3073 {
"asimov_cfit_null", 4},
3075 {
"cfit_lbound", 6}}));
3081 auto fitDS =
new RooDataSet(
"fits",
"fit summary data", fitDetails);
3085 for (
int i = 0; i < 7; i++) {
3086 std::shared_ptr<const RooFitResult> fit;
3088 case 0: fit = ufit();
break;
3089 case 1: fit = cfit_null();
break;
3090 case 2: fit = cfit_alt();
break;
3091 case 3: fit = asimov() ? asimov()->ufit(
true) :
nullptr;
break;
3092 case 4: fit = asimov() ? asimov()->cfit_null(
true) :
nullptr;
break;
3093 case 5: fit = fGenFit;
break;
3094 case 6: fit = cfit_lbound();
break;
3105 fitDS->add(fitDetails);
3108 fitDS->setGlobalObservables(fitMeta);
3110 out.SetFitInfo(fitDS);
3119 nullToyDS->setGlobalObservables(nullMeta);
3120 if (!nullToys.empty()) {
3122 std::vector<double> values;
3123 std::vector<double> weights;
3124 values.reserve(nullToys.size());
3125 weights.reserve(nullToys.size());
3127 for (
auto &t : nullToys) {
3128 values.push_back(std::get<1>(t));
3129 weights.push_back(std::get<2>(t));
3132 nullToyDS->add(nullDetails, std::get<2>(t));
3135#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3136 out.fNullPValue = pNull_toys().first;
3137 out.fNullPValueError =
3138 pNull_toys().second;
3140 out.SetNullPValue(pNull_toys().first);
3141 out.SetNullPValueError(
3142 pNull_toys().second);
3145#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3146 out.fNullPValue = pNull_asymp().first;
3147 out.fNullPValueError = pNull_asymp().second;
3149 out.SetNullPValue(pNull_asymp().first);
3150 out.SetNullPValueError(pNull_asymp().second);
3153 out.SetNullDetailedOutput(nullToyDS);
3155 if (!altToys.empty()) {
3156 std::vector<double> values;
3157 std::vector<double> weights;
3158 values.reserve(altToys.size());
3159 weights.reserve(altToys.size());
3166 altToyDS->setGlobalObservables(altMeta);
3167 for (
auto &t : altToys) {
3168 values.push_back(std::get<1>(t));
3169 weights.push_back(std::get<2>(t));
3172 altToyDS->add(altDetails, std::get<2>(t));
3175 out.SetAltDetailedOutput(altToyDS);
3176#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3177 out.fAlternatePValue = pAlt_toys().first;
3178 out.fAlternatePValueError =
3181 out.SetAltPValue(pAlt_toys().first);
3182 out.SetAltPValueError(
3183 pAlt_toys().second);
3187#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3188 out.fAlternatePValue = pAlt_asymp().first;
3189 out.fAlternatePValueError = pAlt_asymp().second;
3191 out.SetAltPValue(pAlt_asymp().first);
3192 out.SetAltPValueError(pAlt_asymp().second);
3197 nllVar->get()->setAttribute(
"readOnly",
false);
3206 return "xValueWithError: nullptr\n";
3207 return Form(
"%f +/- %f",
v->first,
v->second);
3209std::string cling::printValue(
const std::map<std::string, xRooNLLVar::xValueWithError> *
m)
3213 std::string out =
"{\n";
3214 for (
auto [k,
v] : *
m) {
3215 out +=
"\"" + k +
"\" => " + printValue(&
v) +
"\n";
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
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).
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())
std::shared_ptr< RooFitResult > fr
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
int AddPoints(const char *parName, size_t nPoints, double low, double high)
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...
xRooNode bins() const
bins of a channel or sample, or channels of a multi-channel pdf
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 *)
Common abstract base class for objects that represent a value and a "shape" in RooFit.
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
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.
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
Storage_t const & get() const
Const access to the underlying stl container.
RooAbsCollection * snapshot(bool deepCopy=true) const
Take a snap shot of current collection contents.
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
RooAbsArg * first() const
bool setCatIndex(const char *name, Int_t newVal=0, bool verbose=false)
Set index value of a RooAbsCategoryLValue stored in set with given name to newVal.
bool setRealValue(const char *name, double newVal=0.0, bool verbose=false)
Set value of a RooAbsRealLValue stored in set with given name to newVal No error messages are printed...
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
const char * getCatLabel(const char *name, const char *defVal="", bool verbose=false) const
Get state name of a RooAbsCategory stored in set with given name.
std::string contentsString() const
Return comma separated list of contained object names as STL string.
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.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
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.
RooArgSet * selectCommon(const RooAbsCollection &refColl) const
Use RooAbsCollection::selecCommon(), but return as RooArgSet.
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...
TObject * At(int index) const
Return object stored in sequential position given by index.
static RooMsgService & instance()
Return reference to singleton instance.
StreamConfig & getStream(Int_t id)
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'.
double getErrorLo() const
double getErrorHi() const
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
RooAbsPdf * getPdf(RooStringView catName) const
Return the p.d.f associated with the given index category name.
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.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
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.
virtual void SetPoint(Int_t point, Double_t x, Double_t y, Double_t z)
Sets point number n.
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 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.
virtual Double_t GetMinimum(Double_t minval=-FLT_MAX) const
Return minimum value larger than minval of bins in the range, unless the value has been overridden by...
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.
void Clear(Option_t *option="") override
Set name and title to empty strings ("").
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
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.
virtual void SetSeed(ULong_t seed=0)
Set the random generator seed.
virtual UInt_t Integer(UInt_t imax)
Returns a random integer uniformly distributed on the interval [ 0, imax-1 ].
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.
void ToLower()
Change string to lower-case.
Int_t Atoi() const
Return integer value of string.
Double_t Atof() const
Return floating-point value contained in string.
Bool_t IsFloat() const
Returns kTRUE if string contains a floating point or integer number.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
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.
virtual TList * GetListOfPrimitives() const =0
virtual TObject * GetPrimitive(const char *name) const =0
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
void removeTopic(RooFit::MsgTopic oldTopic)
std::string collectionContents(const RooAbsCollection &coll)