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
105std::set<int> xRooNLLVar::xRooHypoPoint::allowedStatusCodes = {0};
116 fOldTitle =
fNll->get()->getStringAttribute(
"fitresultTitle");
141 std::unique_ptr<RooAbsCollection>
fSnap;
144 std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
fOldData;
148xRooNLLVar::~xRooNLLVar() {}
150xRooNLLVar::xRooNLLVar(
RooAbsPdf &pdf,
const std::pair<RooAbsData *, const RooAbsCollection *> &
data,
153 std::make_pair(std::shared_ptr<RooAbsData>(
data.first, [](
RooAbsData *) {}),
160 const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &
data,
162 : fPdf(pdf), fData(
data.first), fGlobs(
data.second)
165#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 37, 00)
182 for (
int i = 0; i < opts.
GetSize(); i++) {
185 if (strcmp(opts.
At(i)->
GetName(),
"GlobalObservables") == 0) {
188 auto gl =
dynamic_cast<RooCmdArg *
>(opts.
At(i))->getSet(0);
190 throw std::runtime_error(
"GlobalObservables mismatch");
198 auto _vars = std::unique_ptr<RooArgSet>(
fPdf->getVariables());
199 if (
auto extCon =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"ExternalConstraints"))) {
200 for (
auto con : *extCon->getSet(0)) {
201 _vars->add(*std::unique_ptr<RooArgSet>(con->getVariables()));
204 auto _funcGlobs = std::unique_ptr<RooArgSet>(
dynamic_cast<RooArgSet *
>(_vars->selectCommon(*
fGlobs)));
208 if (
auto flag =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"ReuseNLL"))) {
214 if (
auto range =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"RangeWithName"))) {
215 TString rangeName = range->getString(0);
222 std::vector<TString> chanPatterns;
224 bool hasRange(
false);
225 std::string noneCatRanges;
227 chanPatterns.emplace_back(pattern);
228 if (_cat.hasRange(chanPatterns.back())) {
231 if (!noneCatRanges.empty())
232 noneCatRanges +=
",";
233 noneCatRanges += chanPatterns.back();
240 if (noneCatRanges.empty()) {
241 fOpts->Remove(range);
244 range->setString(0, noneCatRanges.c_str());
248 std::make_shared<RooSimultaneous>(
TString::Format(
"%s_reduced", s->GetName()),
"Reduced model", _cat);
249 for (
auto &
c : _cat) {
250 auto _pdf = s->getPdf(
c.first.c_str());
253 _cat.setIndex(
c.second);
254 bool matchAny =
false;
255 for (
auto &
p : chanPatterns) {
256 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
262 newPdf->addPdf(*_pdf,
c.first.c_str());
297 (opts.find(
"GlobalObservables"))
298 ? dynamic_cast<
RooCmdArg *>(opts.find(
"GlobalObservables"))->getSet(0)->snapshot()
306 std::cout <<
"PDF: ";
310 std::cout <<
"<null>" << std::endl;
312 std::cout <<
"Data: ";
316 std::cout <<
"<null>" << std::endl;
318 std::cout <<
"NLL Options: " << std::endl;
319 for (
int i = 0; i <
fOpts->GetSize(); i++) {
323 std::cout <<
" " <<
c->
GetName() <<
" : ";
324 if (
c->getString(0)) {
325 std::cout <<
c->getString(0);
326 }
else if (
c->getSet(0) && !
c->getSet(0)->empty()) {
327 std::cout << (
c->getSet(0)->contentsString());
329 std::cout <<
c->getInt(0);
331 std::cout << std::endl;
334 std::cout <<
"Fit Config: " << std::endl;
335 std::cout <<
" UseParabErrors: " << (
fFitConfig->ParabErrors() ?
"True" :
"False")
336 <<
" [toggles HESSE algorithm]" << std::endl;
337 std::cout <<
" MinimizerOptions: " << std::endl;
340 std::cout <<
"Last Rebuild Log Output: " << std::endl <<
fFuncCreationLog << std::endl;
346 if (std::shared_ptr<RooAbsReal>::get())
347 oldName = std::shared_ptr<RooAbsReal>::get()->GetName();
352 fPdf->treeNodeServerList(&s,
nullptr,
true,
false);
354 bool isBinned =
false;
355 bool hasBinned =
false;
358 isBinned =
a->getInt(0);
360 std::map<RooAbsArg *, bool> origValues;
363 if (
a->InheritsFrom(
"RooRealSumPdf")) {
366 bool setBinned =
false;
368 std::unique_ptr<RooArgSet> obs(
a->getObservables(
fData->get()));
369 if (obs->size() == 1) {
370 auto *var =
static_cast<RooRealVar *
>(obs->first());
371 std::unique_ptr<std::list<double>> boundaries{
dynamic_cast<RooAbsReal *
>(
a)->binBoundaries(
372 *var, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())};
374 if (!std::shared_ptr<RooAbsReal>::get()) {
375 Info(
"xRooNLLVar",
"%s will be evaluated as a Binned PDF (%d bins)",
a->GetName(),
376 int(boundaries->size() - 1));
382 origValues[
a] =
a->getAttribute(
"BinnedLikelihood");
383 a->setAttribute(
"BinnedLikelihood", setBinned);
387 std::map<RooAbsPdf *, std::string> normRanges;
388 std::set<TObject *> removedOpts;
389 if (
auto range =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"RangeWithName"))) {
390 TString rangeName = range->getString(0);
391 if (
auto sr =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"SplitRange"));
393 if (
auto special =
fOpts->find(
"RangeOptimize")) {
394 removedOpts.insert(sr);
396 removedOpts.insert(range);
397 fOpts->Remove(range);
398 removedOpts.insert(special);
399 fOpts->Remove(special);
403 for (
auto cat : simPdf->indexCat()) {
404 auto subpdf = simPdf->
getPdf(cat.first.c_str());
408 srangeName.
ReplaceAll(
",",
"_" + cat.first +
",");
409 srangeName +=
"_" + cat.first;
411 subpdf->treeNodeServerList(&ss,
nullptr,
true,
false);
414 if (
a->InheritsFrom(
"RooAddPdf")) {
416 normRanges[
p] =
p->normRange() ?
p->normRange() :
"";
417 p->setNormRange(srangeName);
426 if (
a->InheritsFrom(
"RooAddPdf")) {
428 normRanges[
p] =
p->normRange() ?
p->normRange() :
"";
429 p->setNormRange(rangeName);
436 std::set<std::string> setNames;
439 setNames.insert(
a.first);
442 for (
auto &
a : setNames) {
446 std::set<std::string> attribs;
447 if (std::shared_ptr<RooAbsReal>::get())
448 attribs = std::shared_ptr<RooAbsReal>::get()->attributes();
449 this->reset(std::unique_ptr<RooAbsReal>{
fPdf->createNLL(*
fData, *
fOpts)}.release());
451 for (
auto o : removedOpts)
457 for (
auto &[k,
v] : normRanges)
458 k->setNormRange(
v ==
"" ?
nullptr :
v.c_str());
460 for (
auto &
a : attribs)
461 std::shared_ptr<RooAbsReal>::get()->setAttribute(
a.c_str());
467 std::shared_ptr<RooAbsReal>::get()->SetName(oldName);
468 if (!origValues.empty()) {
470 std::shared_ptr<RooAbsReal>::get()->getVal();
471 for (
auto &[o,
v] : origValues)
472 o->setAttribute(
"BinnedLikelihood",
v);
476 fFuncVars = std::unique_ptr<RooArgSet>{std::shared_ptr<RooAbsReal>::get()->getVariables()};
484std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
488 return std::pair(
nullptr,
nullptr);
489 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
493 fr->setConstParList(
l);
494 const_cast<RooArgList &
>(fr->constPars()).setAttribAll(
"global",
false);
496 std::unique_ptr<RooAbsCollection>(fr->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
506 fCfits(std::make_shared<std::map<std::string,
xRooFitResult>>())
530 throw std::runtime_error(
"xRooFitResult::cfit: Cannot create cfit without nll");
534 if (
auto res = fCfits->find(alias); res != fCfits->end()) {
538 if (
auto res = fCfits->find(poiValues); res != fCfits->end()) {
543 *fNll->fFuncVars =
get()->floatParsFinal();
544 fNll->fFuncVars->assignValueOnly(
get()->constPars());
545 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->floatParsFinal()))
546 ->setAttribAll(
"Constant",
false);
547 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->constPars()))->setAttribAll(
"Constant",
true);
552 fCfits->insert(std::pair((alias) ? alias : poiValues, out));
559 throw std::runtime_error(
"xRooFitResult::ifit: par not found");
568 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
569 auto _ifit = ifit(
np, up, prefit);
571 throw std::runtime_error(
"xRooFitResult::impact: null ifit");
572 if (_ifit->status() != 0)
573 fNode->Warning(
"impact",
"ifit status code is %d", _ifit->status());
574 return _ifit->floatParsFinal().getRealValue(poi) - poiHat->
getVal();
577 int iPoi =
get()->floatParsFinal().index(poi);
578 int iNp =
get()->floatParsFinal().index(
np);
580 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
582 throw std::runtime_error(
"xRooFitResult::impact: np not found");
584 dynamic_cast<RooRealVar *
>((prefit ?
get()->floatParsInit() :
get()->floatParsFinal()).find(
np));
587 return std::numeric_limits<double>::quiet_NaN();
597 for (
auto p :
get()->floatParsFinal()) {
598 if (strcmp(
p->
GetName(), poi) == 0) {
604 bool matches =
false;
607 if ((
p->getStringAttribute(
"group") && s ==
p->getStringAttribute(
"group")) ||
622 throw std::runtime_error(
TString::Format(
"Could not find poi: %s", poi));
625 fNode->Warning(
"conditionalError",
"No parameters selected by: %s", nps);
626 return (up) ?
static_cast<RooRealVar *
>(poiVar)->getErrorHi() :
static_cast<RooRealVar *
>(poiVar)->getErrorLo();
630 int idx = vars.
index(poi);
631 return sqrt(
get()->conditionalCovarianceMatrix(vars)(idx, idx));
634 auto _cfit = cfit(npNames.
Data(), nps);
636 auto _poi = _cfit->floatParsFinal().find(poi);
638 return (up) ?
static_cast<RooRealVar *
>(_poi)->getErrorHi() :
static_cast<RooRealVar *
>(_poi)->getErrorLo();
646 throw std::runtime_error(
"xRooFitResult::ranknp: poi not found");
648 std::vector<std::pair<std::string, double>> ranks;
650 for (
auto par :
get()->floatParsFinal()) {
653 ranks.emplace_back(std::pair(par->GetName(), impact(poi, par->GetName(), up, prefit,
true)));
656 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
657 if (std::isnan(left.second) && !std::isnan(right.second))
659 if (!std::isnan(left.second) && std::isnan(right.second))
661 return fabs(left.second) > fabs(right.second);
665 for (
auto &[
n,
v] : ranks) {
666 if (
v >= approxThreshold) {
668 v = impact(poi,
n.c_str(), up, prefit);
670 v = std::numeric_limits<double>::quiet_NaN();
676 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
677 if (std::isnan(left.second) && !std::isnan(right.second))
679 if (!std::isnan(left.second) && std::isnan(right.second))
681 return fabs(left.second) > fabs(right.second);
686 for (
auto &[
n,
v] : ranks) {
708 const_cast<RooArgList &
>(out->constPars()).setAttribAll(
"global",
false);
710 std::unique_ptr<RooAbsCollection>(out->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
713 if (
fOpts->find(
"GoF")) {
721 return xRooFitResult(std::make_shared<xRooNode>(out,
fPdf), std::make_shared<xRooNLLVar>(*
this));
743 if (
size_t(_data->numEntries()) <= entry)
746 *std::unique_ptr<RooAbsCollection>(_pdf->getObservables(_data)) = *_data->get(entry);
749 return (_data->weight() == 0) ? 0 : (-_data->weight() * _pdf->getLogVal(_data->get()));
754 std::set<std::string> out;
756 auto binnedOpt =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"Binned"));
760 bool allChannels =
true;
761 for (
auto c : simPdf.
bins()) {
765 c->
get<
RooAbsArg>()->treeNodeServerList(&nodes,
nullptr,
true,
false);
766 bool isBinned =
false;
767 for (
auto a : nodes) {
768 if (
a->InheritsFrom(
"RooRealSumPdf") &&
769 ((binnedOpt && binnedOpt->getInt(0)) || (!binnedOpt &&
a->getAttribute(
"BinnedLikelihood")))) {
771 out.insert(chanName(chanName.
Index(
"=") + 1, chanName.
Length()).
Data());
786 pdf()->treeNodeServerList(&nodes,
nullptr,
true,
false);
787 for (
auto a : nodes) {
788 if (
a->InheritsFrom(
"RooRealSumPdf") &&
789 ((binnedOpt && binnedOpt->getInt(0)) || (!binnedOpt &&
a->getAttribute(
"BinnedLikelihood")))) {
804 if (
size_t(_data->numEntries()) <= entry)
806 auto _pdf =
pdf().get();
807 std::unique_ptr<RooAbsCollection> _robs(_pdf->getObservables(_data->get()));
808 *_robs = *_data->get(entry);
810 _pdf = s->getPdf(s->indexCat().getCurrentLabel());
813 for (
auto o : *_robs) {
817 std::unique_ptr<std::list<double>> bins(
818 _pdf->binBoundaries(*
a, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()));
820 double lowEdge = -std::numeric_limits<double>::infinity();
821 for (
auto b : *bins) {
822 if (
b >
a->getVal()) {
823 volume *= (
b - lowEdge);
849 for (
auto c : cTerm->list()) {
850 if (std::string(
c->ClassName()) ==
"RooAbsPdf" ||
851 std::string(
c->ClassName()).find(
"RooNormalizedPdf") != std::string::npos) {
861 gaus->getMean().GetName()));
866 }
else if (
auto pois =
dynamic_cast<RooPoisson *
>(
c)) {
880 std::unique_ptr<RooAbsCollection>(
pars()->selectByAttrib(
"Constant",
false))->
size();
894 std::unique_ptr<RooAbsCollection> _floats(
pars()->selectByAttrib(
"Constant",
false));
896 _floats->remove(*std::unique_ptr<RooAbsCollection>(_constraintTerm->getVariables()));
910 return _constraintTerm->getVal();
937 return std::numeric_limits<double>::quiet_NaN();
951 double out = _data->sumEntries();
952 for (
int i = 0; i < _data->numEntries(); i++) {
954 double w = _data->weight();
957 out -=
w * std::log(
w);
958 if (_binnedChannels.count(
"*")) {
960 }
else if (_binnedChannels.empty()) {
964 if (_binnedChannels.count(_data->get()->getCatLabel(cat->
GetName()))) {
970 throw std::runtime_error(
"Cannot determine category of RooSimultaneous pdf");
981 auto out = std::shared_ptr<RooArgSet>(
get()->getVariables());
982 if (stripGlobalObs &&
fGlobs) {
983 out->remove(*
fGlobs,
true,
true);
991 return Scan(*std::unique_ptr<RooAbsCollection>(
get()->getVariables()->selectByName(scanPars)), coords, profilePars);
998 if (scanPars.
size() > 2 || scanPars.
empty())
1008 std::unique_ptr<RooAbsCollection> funcVars(
get()->getVariables());
1011 for (
auto &coord : coords) {
1012 if (coord.size() != scanPars.
size()) {
1013 throw std::runtime_error(
"Invalid coordinate");
1015 for (
size_t i = 0; i < coord.size(); i++) {
1019 if (profilePars.
empty()) {
1036 auto _pars =
pars();
1038 if (sOpt ==
"sensitivity") {
1043 if (sOpt ==
"floating") {
1045 auto floats = std::unique_ptr<RooAbsCollection>(_pars->selectByAttrib(
"Constant",
false));
1068 if (
auto a = _pars->find(s);
a)
1072 if (vars.
size() == 1) {
1080 bool normRange =
false;
1094 double step = (
v->getMax() -
v->getMin()) / 100;
1095 double init =
v->getVal();
1096 double initVal =
func()->getVal();
1098 auto currTime = std::chrono::steady_clock::now();
1099 while (out->
GetN() < 100 && (low >
v->getMin() || high < v->getMax())) {
1100 if (out->
GetN() == 0) {
1110 if (low >
v->getMin()) {
1112 auto _v =
func()->getVal();
1113 if (std::isnan(_v) || std::isinf(_v)) {
1114 if (bad->
GetN() == 0)
1122 if (high < v->getMax()) {
1124 auto _v =
func()->getVal();
1125 if (std::isnan(_v) || std::isinf(_v)) {
1126 if (bad->
GetN() == 0)
1137 if (std::chrono::steady_clock::now() - currTime > std::chrono::seconds(1)) {
1138 currTime = std::chrono::steady_clock::now();
1147#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
1148 gPad->GetCanvas()->ResetUpdated();
1153 Error(
"Draw",
"Name a parameter to scan over: Draw(<name>) , choose from: %s",
1154 _pars->empty() ?
"" : _pars->contentsString().c_str());
1168 return setData(std::dynamic_pointer_cast<RooAbsData>(
data.fComp),
1169 std::shared_ptr<const RooAbsCollection>(
data.globs().argList().snapshot()));
1172bool xRooNLLVar::setData(
const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &_data)
1175 if (
fData == _data.first &&
fGlobs == _data.second)
1180 auto _dglobs = (_data.second) ? _data.second
1181 : std::shared_ptr<const RooAbsCollection>(_data.first->getGlobalObservables(),
1184 if (
fGlobs && !(
fGlobs->empty() && !_dglobs) && _data.first &&
1188 throw std::runtime_error(
"Missing globs");
1192 std::unique_ptr<RooAbsCollection> _actualGlobs(
fPdf->getObservables(s));
1195 std::unique_ptr<RooAbsCollection> _actualGlobs2(
fPdf->getObservables(s2));
1196 if (!_actualGlobs->equals(*_actualGlobs2)) {
1198 rC.
add(*_actualGlobs2);
1202 lC.
add(*_actualGlobs);
1205 throw std::runtime_error(
TString::Format(
"globs mismatch: adding %s removing %s",
r.Data(),
l.Data()));
1210 if (!std::shared_ptr<RooAbsReal>::get()) {
1211 fData = _data.first;
1224 fFuncVars->setAttribAll(
"Constant",
false);
1226 std::shared_ptr<RooAbsData> __data =
fData;
1228 fData = _data.first;
1249 fData = _data.first;
1251 }
catch (std::runtime_error &) {
1256 fFuncVars->setAttribAll(
"Constant",
false);
1258 std::shared_ptr<RooAbsData> __data =
fData;
1260 fData = _data.first;
1264 throw std::runtime_error(
"Unable to setData");
1271 }
else if (
auto f = std::unique_ptr<RooAbsCollection>(
fConstVars->selectByAttrib(
"Constant",
false)); !
f->empty()) {
1294 if (strcmp(opt.
GetName(),
"Hesse") == 0) {
1296 }
else if (strcmp(opt.
GetName(),
"Minos") == 0) {
1298 }
else if (strcmp(opt.
GetName(),
"Strategy") == 0) {
1300 }
else if (strcmp(opt.
GetName(),
"StrategySequence") == 0) {
1302 }
else if (strcmp(opt.
GetName(),
"Tolerance") == 0) {
1304 }
else if (strcmp(opt.
GetName(),
"MaxCalls") == 0) {
1306 }
else if (strcmp(opt.
GetName(),
"MaxIterations") == 0) {
1308 }
else if (strcmp(opt.
GetName(),
"PrintLevel") == 0) {
1311#if ROOT_VERSION_CODE < ROOT_VERSION(6, 41, 00)
1312 if (strcmp(opt.
GetName(),
"Optimize") == 0) {
1318 if (
auto prevObject =
fOpts->FindObject(opt.
GetName()); prevObject) {
1320 fOpts->Replace(prevObject, opt.
Clone(
nullptr));
1326 if (std::shared_ptr<RooAbsReal>::get()) {
1399 return fData->sumEntries() * log(1.0 * (s->servers().size() - 1));
1411 for (
int i = 0; i <
fData->numEntries(); i++) {
1421 auto _func =
func();
1424 for (
auto s : _func->servers()) {
1428 for (
auto s2 : s->servers()) {
1448 bool doCLs = sWhat.
Contains(
"pcls");
1449 bool doNull = sWhat.
Contains(
"pnull");
1450 bool doAlt = sWhat.
Contains(
"palt");
1451 double nSigma = (sWhat.
Contains(
"exp"))
1456 : std::numeric_limits<double>::quiet_NaN();
1458 bool toys = sWhat.
Contains(
"toys");
1462 bool readOnly = sWhat.
Contains(
"readonly");
1464 if (toys && !readOnly) {
1469 size_t nToysAlt = 0;
1470 bool autoToys = !sWhat.
Contains(
"toys=");
1476 nToys = toyNum.
Atoi();
1477 nToysAlt = (toyNum.
Atof() - nToys) * nToys;
1478 if (nToysAlt == 0 && !toyNum.
Contains(
'.') && !doNull)
1480 if (nullToys.size() < nToys) {
1481 addNullToys(nToys - nullToys.size());
1483 if (altToys.size() < nToysAlt) {
1484 addAltToys(nToysAlt - altToys.size());
1489 auto obs = getVal(sWhat +
" readonly");
1490 double target=0.05;
double relErrThreshold = 2;
1491 double diff = (
target < 0) ? obs.first : std::abs(obs.first -
target);
1492 double err = obs.second;
1493 size_t maxToys =
gEnv->
GetValue(
"XRooFit.MaxToys",10000);
1494 size_t nAltToys = 100;
1496 if((nullToys.size() < maxToys || altToys.size()<nAltToys) && (std::isnan(err) || (err > 1
e-4 && diff <= relErrThreshold * err))) {
1498 addCLsToys(nAltToys, 0, 0.05, nSigma);
1501 throw std::runtime_error(
"Auto-generating toys for anything other than CLs not yet supported, please "
1502 "specify number of toys with 'toys=N' ");
1509 RestoreNll(std::shared_ptr<xRooNLLVar> &
v,
bool r) : rr(
r), var(
v)
1511 if (rr && var && var->get()) {
1512 _readOnly = var->get()->getAttribute(
"readOnly");
1513 var->get()->setAttribute(
"readOnly", rr);
1521 var->get()->setAttribute(
"readOnly", _readOnly);
1525 bool _readOnly =
false;
1527 std::shared_ptr<xRooNLLVar> &var;
1530 RestoreNll rest(nllVar, readOnly);
1533 return (toys) ? ts_toys(nSigma) : ts_asymp(nSigma);
1535 return (toys) ? pNull_toys(nSigma) : pNull_asymp(nSigma);
1537 return (toys) ? pAlt_toys(nSigma) : pAlt_asymp(nSigma);
1539 return (toys) ? pCLs_toys(nSigma) : pCLs_asymp(nSigma);
1541 throw std::runtime_error(std::string(
"Unknown: ") +
what);
1548 out.
add(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1556 out.
addClone(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1557 for (
auto a : out) {
1561 if (
auto s =
a->getStringAttribute(
"altVal"); s && strlen(s)) {
1564 v->setVal(std::numeric_limits<double>::quiet_NaN());
1574 if (me.ufit(
true) && !allowedStatusCodes.count(me.ufit(
true)->status()))
1576 if (me.cfit_null(
true) && !allowedStatusCodes.count(me.cfit_null(
true)->status()))
1578 if (me.cfit_alt(
true) && !allowedStatusCodes.count(me.cfit_alt(
true)->status()))
1580 if (me.asimov(
true))
1581 out += me.asimov(
true)->status() << 3;
1588 auto _alt_poi =
const_cast<xRooHypoPoint *
>(
this)->alt_poi();
1589 std::cout <<
"POI: " << _poi.contentsString() <<
" , null: ";
1591 for (
auto a : _poi) {
1600 std::cout <<
" , alt: ";
1602 bool any_alt =
false;
1603 for (
auto a : _alt_poi) {
1611 if (!std::isnan(
v->getVal()))
1614 std::cout <<
" , pllType: ";
1616 case 0: std::cout <<
"tmu";
break;
1617 case 1: std::cout <<
"qmu or qmutilde";
break;
1618 case 2: std::cout <<
"q0";
break;
1619 case 4: std::cout <<
"u0";
break;
1620 default: std::cout <<
"unknown";
break;
1622 std::cout << std::endl;
1625 std::cout <<
" obs ts: " << obs_ts <<
" +/- " << obs_ts_err << std::endl;
1628 std::cout <<
" - ufit: ";
1630 std::cout << fUfit->GetName() <<
" " << fUfit->minNll() <<
" (status=" << fUfit->status() <<
") (";
1632 for (
auto a : _poi) {
1633 auto v =
dynamic_cast<RooRealVar *
>(fUfit->floatParsFinal().find(
a->GetName()));
1638 std::cout <<
v->
GetName() <<
"_hat: " <<
v->getVal() <<
" +/- " <<
v->getError();
1641 std::cout <<
")" << std::endl;
1643 std::cout <<
"Not calculated" << std::endl;
1645 std::cout <<
" - cfit_null: ";
1647 std::cout << fNull_cfit->GetName() <<
" " << fNull_cfit->minNll() <<
" (status=" << fNull_cfit->status() <<
")";
1649 std::cout <<
"Not calculated";
1652 std::cout << std::endl <<
" - cfit_alt: ";
1654 std::cout << fAlt_cfit->GetName() <<
" " << fAlt_cfit->minNll() <<
" (status=" << fAlt_cfit->status() <<
")"
1657 std::cout <<
"Not calculated" << std::endl;
1659 std::cout <<
" sigma_mu: ";
1661 if (!fAsimov || !fAsimov->fUfit || !fAsimov->fNull_cfit) {
1662 std::cout <<
"Not calculated";
1664 std::cout << const_cast<xRooHypoPoint *>(
this)->
sigma_mu().first <<
" +/- "
1668 std::cout << std::endl;
1669 std::cout <<
" - asimov ufit: ";
1670 if (fAsimov->fUfit) {
1671 std::cout << fAsimov->
fUfit->GetName() <<
" " << fAsimov->fUfit->minNll()
1672 <<
" (status=" << fAsimov->fUfit->status() <<
")";
1674 std::cout <<
"Not calculated";
1676 std::cout << std::endl <<
" - asimov cfit_null: ";
1677 if (fAsimov->fNull_cfit) {
1678 std::cout << fAsimov->fNull_cfit->GetName() <<
" " << fAsimov->fNull_cfit->minNll()
1679 <<
" (status=" << fAsimov->fNull_cfit->status() <<
")";
1681 std::cout <<
"Not calculated";
1684 std::cout << std::endl;
1686 std::cout << std::endl;
1689 std::cout <<
" - cfit_lbound: " << fLbound_cfit->GetName() <<
" " << fLbound_cfit->minNll()
1690 <<
" (status=" << fLbound_cfit->status() <<
")" << std::endl;
1693 std::cout <<
" - gfit: " << fGenFit->GetName() << std::endl;
1694 if (!nullToys.empty() || !altToys.empty()) {
1695 std::cout <<
" * null toys: " << nullToys.size();
1696 size_t firstToy = 0;
1697 while (firstToy < nullToys.size() && std::isnan(std::get<1>(nullToys[firstToy])))
1700 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1701 std::cout <<
" , alt toys: " << altToys.size();
1703 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1706 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1707 std::cout << std::endl;
1715 auto var =
dynamic_cast<RooRealVar *
>(ufit()->floatParsFinal().find(fPOIName()));
1719 throw std::runtime_error(
TString::Format(
"Cannot find POI: %s", fPOIName()));
1722 throw std::runtime_error(
"Unconditional fit unavailable");
1729 if (fGenFit && isExpected) {
1737 : hypoTestResult(htr)
1753 if (toys->getGlobalObservables()) {
1754 coords = std::shared_ptr<RooAbsCollection>(toys->getGlobalObservables()->snapshot());
1756 for (
int i = 0; i < toys->numEntries(); i++) {
1757 auto toy = toys->get(i);
1759 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1764 for (
int i = 0; i < toys->numEntries(); i++) {
1765 auto toy = toys->get(i);
1767 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1778 if (!fAsimov && (nllVar || hypoTestResult)) {
1779 auto theFit = (!
fData.first && fGenFit && !isExpected)
1781 : cfit_alt(readOnly);
1784 if (!theFit || allowedStatusCodes.find(theFit->status()) == allowedStatusCodes.end())
1786 fAsimov = std::make_shared<xRooHypoPoint>(*
this);
1787 fAsimov->coords.reset(fAsimov->coords->snapshot());
1788 fAsimov->hypoTestResult.reset();
1790 for (
auto p : fAsimov->poi()) {
1793 v->deleteSharedProperties();
1794 if (
v->getVal() == 0) {
1800 v->setVal(theFit->constPars().getRealValue(
v->GetName()) *
gEnv->
GetValue(
"XRooFit.AsimovNullValFactor",1
e-3));
1805 fAsimov->nullToys.clear();
1806 fAsimov->altToys.clear();
1807 fAsimov->fUfit = retrieveFit(3);
1808 fAsimov->fNull_cfit = retrieveFit(4);
1809 fAsimov->fAlt_cfit.reset();
1811 std::make_pair(
nullptr,
nullptr);
1812 fAsimov->fGenFit = theFit;
1813 fAsimov->isExpected =
true;
1822 return std::pair<double, double>(1, 0);
1823 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1825 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1826 double lowBound = first_poi->getMin(
"physical");
1827 double hiBound = first_poi->getMax(
"physical");
1830 (lowBound == -std::numeric_limits<double>::infinity() && hiBound == std::numeric_limits<double>::infinity())
1831 ? std::pair<double, double>(0, 0)
1836 fNullVal(), _sigma_mu.first, lowBound, hiBound);
1838 fNullVal(), _sigma_mu.first, lowBound, hiBound);
1839 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1845 return std::pair<double, double>(1, 0);
1846 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1848 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1849 auto _sigma_mu = sigma_mu();
1851 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1854 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1857 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1859 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1864 if (fNullVal() == fAltVal())
1865 return std::pair<double, double>(1, 0);
1868 return std::pair<double, double>(1, 0);
1869 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1871 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1873 auto _ts_asymp = ts_asymp(nSigma);
1874 auto _sigma_mu = sigma_mu();
1876 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1879 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1882 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1884 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1887 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1890 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1892 auto nom = (nom1 == 0) ? 0 : nom1 / nom2;
1893 auto up = (up1 == 0) ? 0 : up1 / up2;
1894 auto down = (down1 == 0) ? 0 : down1 / down2;
1896 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1901 if (std::isnan(nSigma)) {
1905 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1906 auto _sigma_mu = sigma_mu();
1907 if (!first_poi || (!std::isnan(nSigma) && std::isnan(_sigma_mu.first)))
1908 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1910 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1912 _sigma_mu.first + _sigma_mu.second, first_poi->getMin(
"physical"),
1913 first_poi->getMax(
"physical"));
1915 _sigma_mu.first - _sigma_mu.second, first_poi->getMin(
"physical"),
1916 first_poi->getMax(
"physical"));
1917 return std::pair<double, double>(nom, std::max(std::abs(nom - up), std::abs(nom - down)));
1922 if (std::isnan(nSigma)) {
1926 size_t firstToy = 0;
1927 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1929 if (firstToy >= altToys.size())
1930 return std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
1933 return std::pair(std::get<1>(altToys[targetIdx]), (std::get<1>(altToys[std::min(
int(altToys.size()), targetIdx)]) -
1934 std::get<1>(altToys[std::max(0, targetIdx)])) /
1940 auto _ufit = ufit(readOnly);
1943 return std::pair<double, double>(hypoTestResult->GetTestStatisticData(), 0);
1944 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1946 if (allowedStatusCodes.find(_ufit->status()) == allowedStatusCodes.end()) {
1947 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1949 if (
auto _first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1950 _first_poi && _first_poi->
getMin(
"physical") > _first_poi->getMin() &&
1951 mu_hat().getVal() < _first_poi->getMin(
"physical")) {
1953 _ufit = cfit_lbound(readOnly);
1955 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1962 return std::pair<double, double>(0, 0);
1963 auto _cfit_null = cfit_null(readOnly);
1964 if (!_cfit_null || allowedStatusCodes.find(_cfit_null->status()) == allowedStatusCodes.end())
1965 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
1967 double diff = _cfit_null->minNll() - _ufit->minNll();
1971 diff += (_ufit->edm() - _cfit_null->edm());
1973 return std::pair<double, double>(2. * cFactor * diff,
1974 2. * cFactor * sqrt(pow(cfit_null(readOnly)->edm(), 2) + pow(_ufit->edm(), 2)));
1980 if (!hypoTestResult)
1983 if (
auto fits = hypoTestResult->GetFitInfo()) {
1984 for (
int i = 0; i < fits->numEntries(); i++) {
1985 auto fit = fits->get(i);
1986 if (fit->getCatIndex(
"type") !=
type)
1990 fits->getGlobalObservables()->getStringValue(
TString::Format(
"%s.name", fit->getCatLabel(
"type")));
1993 for (
auto file : *
gROOT->GetListOfFiles()) {
1997 k->GetMotherDir()->GetList()
2000 if (
auto cachedFit = (storedFr) ? storedFr->
fr.get() : k->ReadObject<
RooFitResult>(); cachedFit) {
2003 k->GetMotherDir()->Add(storedFr);
2006 return storedFr->
fr;
2010 auto rfit = std::make_shared<RooFitResult>(_name.c_str(),
TUUID(_name.c_str()).
GetTime().
AsString());
2011 rfit->setStatus(fit->getRealValue(
"status"));
2012 rfit->setMinNLL(fit->getRealValue(
"minNll"));
2013 rfit->setEDM(fit->getRealValue(
"edm"));
2015 std::unique_ptr<RooAbsCollection> par_hats(
2016 hypoTestResult->GetFitInfo()->getGlobalObservables()->selectByName(coords->contentsString().c_str()));
2017 par_hats->setName(
"floatParsFinal");
2018 rfit->setFinalParList(*par_hats);
2025 rfit->setCovarianceMatrix(cov);
2026 rfit->setCovQual(fit->getRealValue(
"covQual"));
2037 if (
auto rfit = retrieveFit(0)) {
2038 return fUfit = rfit;
2040 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2042 if (!nllVar->fFuncVars)
2043 nllVar->reinitialize();
2046 if (!readOnly && isExpected && fGenFit) {
2048 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2049 nllVar->get()->setAttribute(
"readOnly");
2050 auto out = ufit(
true);
2051 nllVar->get()->setAttribute(
"readOnly", tmp);
2056 nllVar->setData(
data());
2059 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2060 nllVar->setData(
fData);
2062 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2063 *nllVar->fFuncVars = *coords;
2064 if (nllVar->fFuncGlobs)
2065 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2066 std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))
2067 ->setAttribAll(
"Constant",
false);
2070 nllVar->fFuncVars->assignValueOnly(fGenFit->constPars());
2071 nllVar->fFuncVars->assignValueOnly(fGenFit->floatParsFinal());
2073 nllVar->get()->SetName(
2074 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2076 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2078 }
else if (!std::isnan(fAltVal())) {
2080 for (
auto _poiCoord : poi()) {
2081 auto _poi =
dynamic_cast<RooRealVar *
>(nllVar->fFuncVars->find(_poiCoord->GetName()));
2083 _poi->
setVal(_poi->getStringAttribute(
"initVal") ?
TString(_poi->getStringAttribute(
"initVal")).
Atof()
2088 return (fUfit = nllVar->minimize());
2094 for (
auto &
c : coll) {
2097 out +=
c->GetName();
2113 if (
auto rfit = retrieveFit(1)) {
2114 return fNull_cfit = rfit;
2116 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2118 if (!nllVar->fFuncVars)
2119 nllVar->reinitialize();
2122 if (!readOnly && isExpected && fGenFit) {
2124 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2125 nllVar->get()->setAttribute(
"readOnly");
2126 auto out = cfit_null(
true);
2127 nllVar->get()->setAttribute(
"readOnly", tmp);
2132 nllVar->setData(
data());
2135 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2136 nllVar->setData(
fData);
2140 *nllVar->fFuncVars = fUfit->floatParsFinal();
2142 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2143 *nllVar->fFuncVars = *coords;
2144 if (nllVar->fFuncGlobs)
2145 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2147 nllVar->fFuncVars->find(fPOIName())
2148 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2151 nllVar->get()->SetName(
2152 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2154 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2156 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(poi()).c_str());
2157 return (fNull_cfit = nllVar->minimize());
2162 auto _first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
2165 if (_first_poi->getMin(
"physical") <= _first_poi->getMin())
2168 return fLbound_cfit;
2169 if (
auto rfit = retrieveFit(6)) {
2170 return fLbound_cfit = rfit;
2172 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2174 if (!nllVar->fFuncVars)
2175 nllVar->reinitialize();
2178 if (!readOnly && isExpected && fGenFit) {
2180 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2181 nllVar->get()->setAttribute(
"readOnly");
2182 auto out = cfit_lbound(
true);
2183 nllVar->get()->setAttribute(
"readOnly", tmp);
2188 nllVar->setData(
data());
2191 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2192 nllVar->setData(
fData);
2196 *nllVar->fFuncVars = fUfit->floatParsFinal();
2198 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2199 *nllVar->fFuncVars = *coords;
2200 nllVar->fFuncVars->setRealValue(_first_poi->GetName(), _first_poi->getMin(
"physical"));
2201 if (nllVar->fFuncGlobs)
2202 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2204 nllVar->fFuncVars->find(fPOIName())
2205 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
2208 nllVar->get()->SetName(
2209 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2211 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2213 nllVar->get()->setStringAttribute(
2215 collectionContents(*std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))).c_str());
2216 return (fLbound_cfit = nllVar->minimize());
2221 if (std::isnan(fAltVal()))
2225 if (
auto rfit = retrieveFit(2)) {
2226 return fAlt_cfit = rfit;
2228 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
2230 if (!nllVar->fFuncVars)
2231 nllVar->reinitialize();
2234 if (!readOnly && isExpected && fGenFit) {
2236 bool tmp = nllVar->get()->getAttribute(
"readOnly");
2237 nllVar->get()->setAttribute(
"readOnly");
2238 auto out = cfit_alt(
true);
2239 nllVar->get()->setAttribute(
"readOnly", tmp);
2244 nllVar->setData(
data());
2247 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
2248 nllVar->setData(
fData);
2252 *nllVar->fFuncVars = fUfit->floatParsFinal();
2254 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
2255 *nllVar->fFuncVars = *coords;
2256 if (nllVar->fFuncGlobs)
2257 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
2258 *nllVar->fFuncVars = alt_poi();
2260 nllVar->get()->SetName(
2261 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
2263 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
2265 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(alt_poi()).c_str());
2266 return (fAlt_cfit = nllVar->minimize());
2272 auto asi = asimov(readOnly);
2275 return std::pair<double, double>(std::numeric_limits<double>::quiet_NaN(), 0);
2278 auto out = asi->pll(readOnly);
2279 return std::pair<double, double>(std::abs(asi->fNullVal() - fAltVal()) / sqrt(out.first),
2280 out.second * 0.5 * std::abs(asi->fNullVal() - fAltVal()) /
2281 (out.first * sqrt(out.first)));
2286 auto _ts = ts_toys(nSigma);
2287 if (std::isnan(_ts.first))
2290 return std::pair<double, double>(1, 0);
2294 auto &_theToys = (alt) ? altToys : nullToys;
2296 if (_theToys.empty()) {
2297 return std::pair(0.5, std::numeric_limits<double>::infinity());
2304 double result_err_up = 0;
2305 double result_err_down = 0;
2306 for (
auto &toy : _theToys) {
2307 if (std::isnan(std::get<1>(toy))) {
2310 bool res = std::get<1>(toy) >= _ts.first;
2311 if (std::get<2>(toy) != 1) {
2317 result += std::get<2>(toy);
2318 if (std::get<1>(toy) >= _ts.first - _ts.second)
2319 result_err_up += std::get<2>(toy);
2320 if (std::get<1>(toy) >= _ts.first - _ts.second)
2321 result_err_down += std::get<2>(toy);
2326 result_err_down -=
result;
2327 double result_err = std::max(std::abs(result_err_up), std::abs(result_err_down));
2330 result_err /= _theToys.size();
2333 result /= (_theToys.size() - nans);
2337 return std::pair<double, double>(
result, result_err);
2342 return pX_toys(
false, nSigma);
2347 if (!std::isnan(nSigma)) {
2350 return pX_toys(
true, nSigma);
2361 auto _cfit = cfit_null();
2364 if (!nllVar->fFuncVars)
2365 nllVar->reinitialize();
2383 if (!nllVar->fFuncVars)
2384 nllVar->reinitialize();
2394 bool targetCLs,
double relErrThreshold,
size_t maxToys)
2396 if ((alt && !cfit_alt()) || (!alt && !cfit_null())) {
2397 throw std::runtime_error(
"Cannot add toys, invalid conditional fit");
2400 maxToys = std::min(maxToys,(
size_t)
gEnv->
GetValue(
"XRooFit.MaxToys",10000));
2402 auto condition = [&]() {
2405 auto obs = targetCLs ? pCLs_toys(target_nSigma) : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma));
2406 if (!std::isnan(obs.first)) {
2407 double diff = (
target < 0) ? obs.first : std::abs(obs.first -
target);
2408 double err = obs.second;
2409 if (err > 1
e-4 && diff <= relErrThreshold * obs.second) {
2413 auto pNull = pNull_toys(target_nSigma);
2414 auto pAlt = pAlt_toys(target_nSigma);
2417 alt = (pAlt.second * pNull.first > pNull.second * pAlt.first);
2418 if ((alt ? pAlt.second : pNull.second) < 1
e-4)
2420 if( ((alt) ? altToys.size() : nullToys.size()) >= maxToys )
2429 if (!std::isnan(
target) && std::isnan(ts_toys(target_nSigma).first)) {
2430 if (std::isnan(target_nSigma)) {
2431 throw std::runtime_error(
"Cannot target obs p-value because ts value unavailable");
2433 if (targetCLs && pCLs_toys(target_nSigma).second == 0) {
2439 Info(
"addToys",
"First generating 100 alt toys in order to determine expected ts value");
2440 addToys(
true, 100, initialSeed);
2442 if (std::isnan(ts_toys(target_nSigma).first)) {
2443 throw std::runtime_error(
"Unable to determine expected ts value");
2462 size_t toysAdded(0);
2463 size_t altToysAdded(0);
2468 auto &toys = (alt) ? altToys : nullToys;
2469 if (toys.size() >= maxToys) {
2474 if (!std::isnan(
target) && !condition()) {
2477 auto currVal = std::isnan(
target) ? std::pair(0., 0.)
2478 : (targetCLs ? pCLs_toys(target_nSigma)
2479 : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma)));
2480 size_t nnToys = std::min(
size_t(nToys), (maxToys - toys.size()));
2482 for (
size_t i = 0; i < nnToys; i++) {
2484 auto toy = ((alt) ? generateAlt(seed) : generateNull(seed));
2487 toys.push_back(std::make_tuple(seed, toy.pll().first, 1.));
2489 (alt ? altToysAdded : toysAdded)++;
2490 if (std::isnan(std::get<1>(toys.back())))
2492 g->SetPoint(
g->GetN(),
g->GetN(), s.
RealTime() - lastTime);
2496 <<
TString::Format(
"Generated %d/%d %s hypothesis toys [%.2f toys/s]",
2497 int(alt ? altToysAdded : toysAdded),
int(nnToys), alt ?
"alt" :
"null",
2499 if (!std::isnan(
target)) {
2500 std::cout <<
" [current=" << currVal.first <<
"+/-" << currVal.second <<
" target=" <<
target
2501 <<
" nSigma=" << target_nSigma <<
"]";
2503 std::cout <<
"..." << std::flush;
2504 lasti = altToysAdded + toysAdded;
2506 if (!
gROOT->IsBatch()) {
2510#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2511 gPad->GetCanvas()->ResetUpdated();
2524 for (
auto &t : toys) {
2525 if (std::isnan(std::get<1>(t)))
2526 std::get<1>(t) = -std::numeric_limits<double>::infinity();
2528 std::sort(toys.begin(), toys.end(),
2529 [](
const decltype(nullToys)::value_type &
a,
const decltype(nullToys)::value_type &
b) ->
bool {
2530 if (std::isnan(std::get<1>(a)))
2532 if (std::isnan(std::get<1>(b)))
2534 return std::get<1>(a) < std::get<1>(b);
2536 for (
auto &t : toys) {
2537 if (std::isinf(std::get<1>(t)))
2538 std::get<1>(t) = std::numeric_limits<double>::quiet_NaN();
2540 if (std::isnan(
target)) {
2547 }
while (condition());
2550 <<
"Finished Generating ";
2552 std::cout << toysAdded <<
" null ";
2555 std::cout << altToysAdded <<
" alt ";
2557 std::cout <<
"toys " <<
TString::Format(
"[%.2f toys/s overall]",
double(toysAdded + altToysAdded) / s2.
RealTime())
2559 if (!
gROOT->IsBatch()) {
2563#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2564 gPad->GetCanvas()->ResetUpdated();
2572 std::cout <<
"Warning: " << nans <<
" toys were bad" << std::endl;
2579 addToys(
false, nToys, seed,
target, target_nSigma);
2583 addToys(
true, nToys, seed,
target, target_nSigma);
2588 addToys(
false, nToys, seed,
target, target_nSigma,
true);
2603 out.
nllVar = std::make_shared<xRooNLLVar>(*
this);
2612 while (pattern.NextToken()) {
2615 double val = std::numeric_limits<double>::quiet_NaN();
2616 auto i = s.
Index(
"=");
2621 throw std::runtime_error(
"poiValues must contain value");
2626 throw std::runtime_error(
"Cannot find poi");
2627 if (!std::isnan(val))
2630 if (poiNames !=
"") {
2635 if (poiNames ==
"") {
2636 throw std::runtime_error(
"No poi");
2639 auto _snap = std::unique_ptr<RooAbsCollection>(
fFuncVars->selectByAttrib(
"Constant",
true))->snapshot();
2640 _snap->setAttribAll(
"poi",
false);
2641 std::unique_ptr<RooAbsCollection> _poi(_snap->selectByName(poiNames));
2642 _poi->setAttribAll(
"poi",
true);
2643 if (std::isnan(alt_value)) {
2644 for (
auto a : *_poi)
2645 a->setStringAttribute(
"altVal", nullptr);
2647 for (
auto a : *_poi)
2648 a->setStringAttribute(
"altVal",
TString::
Format(
"%g", alt_value));
2651 _snap->remove(*
fGlobs,
true,
true);
2654 auto _type = pllType;
2657 if (std::isnan(alt_value)) {
2659 }
else if (
dynamic_cast<RooRealVar *
>(_poi->first())->
getVal() >= alt_value) {
2664 for (
auto b : out.poi()) {
2666 if (
r->hasRange(
"physical") &&
r->getMin() >=
r->getMin(
"physical")) {
2668 "xRooNLLVar::hypoPoint",
2669 "fitting min of %s is >= physical limit (%g), but using uncapped test-statistic, so will set to "
2671 r->GetName(),
r->getMin(
"physical"), -
r->getMax());
2672 r->setMin(-
r->getMax());
2683 std::unique_ptr<RooAbsCollection> thePoi(
fFuncVars->selectByName(poiNames));
2684 for (
auto b : *thePoi) {
2685 if (!
static_cast<RooRealVar *
>(
b)->hasRange(
"physical")) {
2686 static_cast<RooRealVar *
>(
b)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2694xRooNLLVar::xRooHypoPoint
2700 std::unique_ptr<RooAbsCollection> _poi(
fFuncVars->selectByAttrib(
"poi",
true));
2701 if (_poi->empty()) {
2702 throw std::runtime_error(
"No POI specified in model");
2703 }
else if (_poi->size() != 1) {
2704 throw std::runtime_error(
"Multiple POI specified in model");
2706 return hypoPoint(_poi->first()->GetName(),
value, alt_value, pllType);
2718 if (!nllVar && !hypoTestResult)
2723 bool hasSame = sOpt.
Contains(
"same");
2728 TH1 *hAxis =
nullptr;
2730 auto clearPad = []() {
2732 if (
gPad->GetNumber() == 0) {
2740 if (!hasSame || !pad) {
2751 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
2758 double _min = std::numeric_limits<double>::quiet_NaN();
2759 double _max = -std::numeric_limits<double>::quiet_NaN();
2761 for (
auto &
p : nullToys) {
2762 if (std::get<2>(
p) == 0)
2764 if (std::isnan(std::get<1>(
p)))
2766 _min = std::min(std::get<1>(
p), _min);
2767 _max = std::max(std::get<1>(
p), _max);
2769 for (
auto &
p : altToys) {
2770 if (std::get<2>(
p) == 0)
2772 if (std::isnan(std::get<1>(
p)))
2774 _min = std::min(std::get<1>(
p), _min);
2775 _max = std::max(std::get<1>(
p), _max);
2778 auto obs = ts_asymp();
2779 if (!std::isnan(obs.first)) {
2780 _min = std::min(obs.first - std::abs(obs.first) * 0.1, _min);
2781 _max = std::max(obs.first + std::abs(obs.first) * 0.1, _max);
2784 auto pNull = pNull_toys();
2785 auto pAlt = pAlt_toys();
2787 ? std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN())
2790 ? std::pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN())
2794 ? fAsimov->pll().first
2795 : std::numeric_limits<double>::quiet_NaN();
2796 if (!std::isnan(asi) && asi > 0) {
2798 _min = std::min(asi - std::abs(asi), _min);
2799 _max = std::max(asi + std::abs(asi), _max);
2804 auto _poi =
dynamic_cast<RooRealVar *
>(poi().first());
2806 auto makeHist = [&](
bool isAlt) {
2808 auto h =
new TH1D((isAlt) ?
"alt_toys" :
"null_toys",
"", 100, _min, _max + (_max - _min) * 0.01);
2809 h->SetDirectory(
nullptr);
2810 size_t nBadOrZero = 0;
2811 for (
auto &
p : (isAlt) ? altToys : nullToys) {
2812 double w = std::isnan(std::get<1>(
p)) ? 0 : std::get<2>(
p);
2815 if (!std::isnan(std::get<1>(
p)))
2816 h->Fill(std::get<1>(
p),
w);
2818 if (
h->GetEntries() > 0)
2819 h->Scale(1. /
h->Integral(0,
h->GetNbinsX() + 1));
2833 title +=
TString::Format(
"%s' = %g", fPOIName(), (isAlt) ? fAltVal() : fNullVal());
2834 title +=
TString::Format(
" , N_{toys}=%d",
int((isAlt) ? altToys.size() : nullToys.size()));
2843 h->SetMarkerSize(0);
2849 auto nullHist = makeHist(
false);
2850 auto altHist = makeHist(
true);
2853 auto h = (nullHist->GetEntries()) ? nullHist : altHist;
2856 auto axis =
static_cast<TH1 *
>(
h->Clone(
".axis"));
2858 axis->SetStats(
false);
2859 axis->Reset(
"ICES");
2861 axis->SetLineWidth(0);
2863 axis->SetMinimum(1
e-7);
2864 axis->GetYaxis()->SetRangeUser(1
e-7, 10);
2865 axis->SetMaximum(
h->GetMaximum());
2867 l =
new TLegend(0.4, 0.7, 1. -
gPad->GetRightMargin(), 1. -
gPad->GetTopMargin());
2868 l->SetName(
"legend");
2870 l->SetBorderSize(0);
2873 l->ConvertNDCtoPad();
2875 for (
auto o : *
gPad->GetListOfPrimitives()) {
2882 if (
h->GetEntries() > 0) {
2885 h->Draw(
"axissame");
2888 if (
h->GetEntries() > 0) {
2891 h->Draw(
"axissame");
2895 l->AddEntry(nullHist);
2896 l->AddEntry(altHist);
2899 if (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit && !std::isnan(sigma_mu().first) && !std::isnan(fAltVal())) {
2900 auto hh =
static_cast<TH1 *
>(nullHist->Clone(
"null_asymp"));
2902 hh->SetStats(
false);
2903 hh->SetLineStyle(2);
2905 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
2908 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2910 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2913 hh =
static_cast<TH1 *
>(altHist->Clone(
"alt_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")));
2938 l->AddEntry(tl, label,
"l");
2940 if (nullHist->GetEntries() || altHist->GetEntries()) {
2941 auto pCLs = pCLs_toys();
2942 label +=
" p_{toy}=(";
2943 label += (std::isnan(pNull.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNull.first, pNull.second);
2944 label += (std::isnan(pAlt.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAlt.first, pAlt.second);
2945 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2947 if (label.Length() > 0)
2948 l->AddEntry(
"", label,
"");
2950 if (!std::isnan(pNullA.first) || !std::isnan(pAltA.first)) {
2951 auto pCLs = pCLs_asymp();
2952 label +=
" p_{asymp}=(";
2953 label += (std::isnan(pNullA.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNullA.first, pNullA.second);
2954 label += (std::isnan(pAltA.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAltA.first, pAltA.second);
2955 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2957 if (label.Length() > 0)
2958 l->AddEntry(
"", label,
"");
2960 if (
auto ax =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
".axis")))
2961 ax->GetYaxis()->SetRangeUser(1
e-7, 1);
2966 auto v =
dynamic_cast<RooRealVar *
>(poi().empty() ? nullptr : poi().first());
2968 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2978 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2982 return (inWords) ?
TString::Format(
"-2log[L(%s,#hat{#hat{#theta}})/L(#hat{%s},#hat{#theta})]",
v->GetTitle(),
2988 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2989 return (inWords) ?
TString::Format(
"Lower-Bound One-Sided Discovery PLR")
2998 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
3007 return "Test Statistic";
3013 return (poi().empty()) ? nullptr : (poi().first())->GetName();
3017 auto first_poi =
dynamic_cast<RooAbsReal *
>(poi().first());
3018 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
3022 auto _alt_poi = alt_poi();
3023 auto first_poi =
dynamic_cast<RooAbsReal *
>(_alt_poi.first());
3024 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
3031 throw std::runtime_error(
"HypoPoint has no POI, cannot set null value");
3033 first_poi->setVal(val);
3037 auto first_poi =
dynamic_cast<RooAbsArg *
>(poi().first());
3039 throw std::runtime_error(
"HypoPoint has no POI, cannot set alt value");
3041 first_poi->setStringAttribute(
"altVal",
TString::Format(
"%g", val).Data());
3048 if (nPoints < 0 || tsType < 0) {
3052 nPoints =
int(low + 0.5);
3056 if (alt_value == std::numeric_limits<double>::quiet_NaN()) {
3064 auto out =
hypoSpace(parName, pllType, alt_value);
3070 for (
auto p : out.
poi()) {
3072 dynamic_cast<RooRealVar *
>(
p)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
3073 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [0,inf]",
p->
GetName());
3075 v->removeMin(
"physical");
3076 v->removeMax(
"physical");
3077 Info(
"xRooNLLVar::hypoSpace",
"Removing physical range of %s",
p->
GetName());
3091 out.AddPoints(parName, nPoints, low, high);
3094 for (
auto p : out.
poi()) {
3096 r->setRange(
"scan", std::isnan(low) ?
r->getMin() : low, std::isnan(high) ?
r->getMax() : high);
3106 hs.
AddPoints(parName, nPoints, low, high);
3109 for (
auto p : hs.
poi()) {
3111 r->setRange(
"scan", std::isnan(low) ?
r->getMin() : low, std::isnan(high) ?
r->getMax() : high);
3122 auto _poi = std::unique_ptr<RooAbsCollection>(
3123 std::unique_ptr<RooAbsCollection>(
pdf()->getVariables())->selectByAttrib(
"poi",
true));
3125 throw std::runtime_error(
"You must specify a POI for the hypoSpace");
3126 return hypoSpace(_poi->first()->GetName(), nPoints, low, high, alt_value, pllType);
3135 if (strlen(parName)) {
3136 std::unique_ptr<RooAbsCollection> axes(s.
pars()->selectByName(parName));
3138 throw std::runtime_error(
"parameter not found");
3139 axes->setAttribAll(
"axis",
true);
3144 s.
fNlls[s.
fPdfs.begin()->second] = std::make_shared<xRooNLLVar>(*
this);
3151 for (
auto poi : s.
poi()) {
3152 poi->setStringAttribute(
"altVal", std::isnan(alt_value) ? nullptr :
TString::Format(
"%f", alt_value));
3155 r->setRange(
"scan",
r->getMin(),
r->getMax());
3164 if (hypoTestResult) {
3165 return *hypoTestResult;
3172 bool setReadonly =
false;
3173 if (nllVar && !nllVar->get()->getAttribute(
"readOnly")) {
3175 nllVar->get()->setAttribute(
"readOnly");
3186 {
"OneSidedPositive", 1},
3187 {
"OneSidedNegative", 2},
3188 {
"OneSidedAbsolute", 3},
3192 fitMeta.
addClone(ufit()->floatParsFinal());
3202 {
"asimov_cfit_null", 4},
3204 {
"cfit_lbound", 6}}));
3210 auto fitDS =
new RooDataSet(
"fits",
"fit summary data", fitDetails);
3214 for (
int i = 0; i < 7; i++) {
3215 std::shared_ptr<const RooFitResult> fit;
3217 case 0: fit = ufit();
break;
3218 case 1: fit = cfit_null();
break;
3219 case 2: fit = cfit_alt();
break;
3220 case 3: fit = asimov() ? asimov()->ufit(
true) :
nullptr;
break;
3221 case 4: fit = asimov() ? asimov()->cfit_null(
true) :
nullptr;
break;
3222 case 5: fit = fGenFit;
break;
3223 case 6: fit = cfit_lbound();
break;
3234 fitDS->add(fitDetails);
3237 fitDS->setGlobalObservables(fitMeta);
3248 nullToyDS->setGlobalObservables(nullMeta);
3249 if (!nullToys.empty()) {
3251 std::vector<double> values;
3252 std::vector<double> weights;
3253 values.reserve(nullToys.size());
3254 weights.reserve(nullToys.size());
3256 for (
auto &t : nullToys) {
3257 values.push_back(std::get<1>(t));
3258 weights.push_back(std::get<2>(t));
3261 nullToyDS->add(nullDetails, std::get<2>(t));
3264#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3267 pNull_toys().second;
3271 pNull_toys().second);
3274#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3284 if (!altToys.empty()) {
3285 std::vector<double> values;
3286 std::vector<double> weights;
3287 values.reserve(altToys.size());
3288 weights.reserve(altToys.size());
3295 altToyDS->setGlobalObservables(altMeta);
3296 for (
auto &t : altToys) {
3297 values.push_back(std::get<1>(t));
3298 weights.push_back(std::get<2>(t));
3301 altToyDS->add(altDetails, std::get<2>(t));
3305#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3312 pAlt_toys().second);
3316#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
3326 nllVar->get()->setAttribute(
"readOnly",
false);
3334std::string cling::printValue(
const XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError *
v)
3337 return "xValueWithError: nullptr\n";
3338 return v->__repr__();
3340std::string cling::printValue(
const std::map<std::string, XROOFIT_NAMESPACE_NAME::xRooNLLVar::xValueWithError> *
m)
3344 std::string out =
"{\n";
3345 for (
auto [k,
v] : *
m) {
3346 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)
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())
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::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)
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())
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=-1)
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
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
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...
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.
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.
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.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
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.
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.
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.
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
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.
virtual Int_t GetValue(const char *name, Int_t dflt) const
Returns the integer value for a resource.
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 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.
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.
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.
void Clear(Option_t *option="") override
Set name and title to empty strings ("").
virtual void SetName(const char *name)
Set the name of the TNamed.
Mother of all ROOT objects.
virtual const char * GetName() const
Returns name of object.
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 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
void removeTopic(RooFit::MsgTopic oldTopic)
std::string collectionContents(const RooAbsCollection &coll)