22#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
23#define protected public
56#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
58#define GETWS(a) a->_myws
59#define GETWSSETS(w) w->_namedSets
61#define GETWS(a) a->workspace()
62#define GETWSSETS(w) w->sets()
69#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
70#define protected public
98std::set<int> xRooNLLVar::xRooHypoPoint::allowedStatusCodes = {0};
109 fOldTitle =
fNll->get()->getStringAttribute(
"fitresultTitle");
134 std::unique_ptr<RooAbsCollection>
fSnap;
137 std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
fOldData;
141xRooNLLVar::~xRooNLLVar() {}
143xRooNLLVar::xRooNLLVar(
RooAbsPdf &pdf,
const std::pair<RooAbsData *, const RooAbsCollection *> &
data,
146 std::make_pair(std::shared_ptr<RooAbsData>(
data.first, [](
RooAbsData *) {}),
153 const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &
data,
155 : fPdf(pdf), fData(
data.first), fGlobs(
data.second)
172 for (
int i = 0; i < opts.
GetSize(); i++) {
175 if (strcmp(opts.
At(i)->
GetName(),
"GlobalObservables") == 0) {
178 auto gl =
dynamic_cast<RooCmdArg *
>(opts.
At(i))->getSet(0);
180 throw std::runtime_error(
"GlobalObservables mismatch");
182 }
else if (strcmp(opts.
At(i)->
GetName(),
"Hesse") == 0) {
184 }
else if (strcmp(opts.
At(i)->
GetName(),
"Strategy") == 0) {
186 }
else if (strcmp(opts.
At(i)->
GetName(),
"StrategySequence") == 0) {
188 }
else if (strcmp(opts.
At(i)->
GetName(),
"Tolerance") == 0) {
190 }
else if (strcmp(opts.
At(i)->
GetName(),
"PrintLevel") == 0) {
193 if (strcmp(opts.
At(i)->
GetName(),
"Optimize") == 0) {
204 auto _vars = std::unique_ptr<RooArgSet>(
fPdf->getVariables());
205 if (
auto extCon =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"ExternalConstraints"))) {
206 for (
auto con : *extCon->getSet(0)) {
207 _vars->add(*std::unique_ptr<RooArgSet>(con->getVariables()));
210 auto _funcGlobs = std::unique_ptr<RooArgSet>(
dynamic_cast<RooArgSet *
>(_vars->selectCommon(*
fGlobs)));
214 if (
auto flag =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"ReuseNLL"))) {
220 if (
auto range =
dynamic_cast<RooCmdArg *
>(
fOpts->find(
"RangeWithName"))) {
221 TString rangeName = range->getString(0);
228 std::vector<TString> chanPatterns;
230 bool hasRange(
false);
231 std::string noneCatRanges;
233 chanPatterns.emplace_back(pattern);
234 if (_cat.hasRange(chanPatterns.back())) {
237 if (!noneCatRanges.empty())
238 noneCatRanges +=
",";
239 noneCatRanges += chanPatterns.back();
246 if (noneCatRanges.empty()) {
247 fOpts->Remove(range);
250 range->setString(0, noneCatRanges.c_str());
254 std::make_shared<RooSimultaneous>(
TString::Format(
"%s_reduced", s->GetName()),
"Reduced model", _cat);
255 for (
auto &
c : _cat) {
256 auto _pdf = s->getPdf(
c.first.c_str());
259 _cat.setIndex(
c.second);
260 bool matchAny =
false;
261 for (
auto &
p : chanPatterns) {
262 if (_cat.hasRange(
p) && _cat.inRange(
p)) {
268 newPdf->addPdf(*_pdf,
c.first.c_str());
303 (opts.find(
"GlobalObservables"))
304 ? dynamic_cast<
RooCmdArg *>(opts.find(
"GlobalObservables"))->getSet(0)->snapshot()
312 std::cout <<
"PDF: ";
316 std::cout <<
"<null>" << std::endl;
318 std::cout <<
"Data: ";
322 std::cout <<
"<null>" << std::endl;
324 std::cout <<
"NLL Options: " << std::endl;
325 for (
int i = 0; i <
fOpts->GetSize(); i++) {
329 std::cout <<
" " <<
c->
GetName() <<
" : ";
330 if (
c->getString(0)) {
331 std::cout <<
c->getString(0);
332 }
else if (
c->getSet(0) && !
c->getSet(0)->empty()) {
333 std::cout << (
c->getSet(0)->contentsString());
335 std::cout <<
c->getInt(0);
337 std::cout << std::endl;
340 std::cout <<
"Fit Config: " << std::endl;
341 std::cout <<
" UseParabErrors: " << (
fFitConfig->ParabErrors() ?
"True" :
"False")
342 <<
" [toggles HESSE algorithm]" << std::endl;
343 std::cout <<
" MinimizerOptions: " << std::endl;
352 if (std::shared_ptr<RooAbsReal>::get())
353 oldName = std::shared_ptr<RooAbsReal>::get()->GetName();
358 fPdf->treeNodeServerList(&s,
nullptr,
true,
false);
360 bool isBinned =
false;
361 bool hasBinned =
false;
364 isBinned =
a->getInt(0);
366 std::map<RooAbsArg *, bool> origValues;
369 if (
a->InheritsFrom(
"RooRealSumPdf")) {
372 bool setBinned =
false;
374 std::unique_ptr<RooArgSet> obs(
a->getObservables(
fData->get()));
375 if (obs->size() == 1) {
376 auto *var =
static_cast<RooRealVar *
>(obs->first());
377 std::unique_ptr<std::list<double>> boundaries{
dynamic_cast<RooAbsReal *
>(
a)->binBoundaries(
378 *var, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())};
380 if (!std::shared_ptr<RooAbsReal>::get()) {
381 Info(
"xRooNLLVar",
"%s will be evaluated as a Binned PDF (%d bins)",
a->GetName(),
382 int(boundaries->size() - 1));
388 origValues[
a] =
a->getAttribute(
"BinnedLikelihood");
389 a->setAttribute(
"BinnedLikelihood", setBinned);
395 std::set<std::string> setNames;
398 setNames.insert(
a.first);
401 for (
auto &
a : setNames) {
405 std::set<std::string> attribs;
406 if (std::shared_ptr<RooAbsReal>::get())
407 attribs = std::shared_ptr<RooAbsReal>::get()->attributes();
408 this->reset(std::unique_ptr<RooAbsReal>{
fPdf->createNLL(*
fData, *
fOpts)}.release());
414 for (
auto &
a : attribs)
415 std::shared_ptr<RooAbsReal>::get()->setAttribute(
a.c_str());
421 std::shared_ptr<RooAbsReal>::get()->SetName(oldName);
422 if (!origValues.empty()) {
424 std::shared_ptr<RooAbsReal>::get()->getVal();
425 for (
auto &[o,
v] : origValues)
426 o->setAttribute(
"BinnedLikelihood",
v);
430 fFuncVars = std::unique_ptr<RooArgSet>{std::shared_ptr<RooAbsReal>::get()->getVariables()};
438std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
442 return std::pair(
nullptr,
nullptr);
443 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
447 fr->setConstParList(
l);
448 const_cast<RooArgList &
>(fr->constPars()).setAttribAll(
"global",
false);
450 std::unique_ptr<RooAbsCollection>(fr->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
458 fCfits(std::make_shared<std::map<std::string,
xRooFitResult>>())
482 throw std::runtime_error(
"xRooFitResult::cfit: Cannot create cfit without nll");
486 if (
auto res = fCfits->find(alias); res != fCfits->end()) {
490 if (
auto res = fCfits->find(poiValues); res != fCfits->end()) {
495 *fNll->fFuncVars =
get()->floatParsFinal();
496 fNll->fFuncVars->assignValueOnly(
get()->constPars());
497 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->floatParsFinal()))
498 ->setAttribAll(
"Constant",
false);
499 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->constPars()))->setAttribAll(
"Constant",
true);
504 fCfits->insert(std::pair((alias) ? alias : poiValues, out));
511 throw std::runtime_error(
"xRooFitResult::ifit: par not found");
520 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
521 auto _ifit = ifit(
np, up, prefit);
523 throw std::runtime_error(
"xRooFitResult::impact: null ifit");
524 if (_ifit->status() != 0)
525 fNode->Warning(
"impact",
"ifit status code is %d", _ifit->status());
526 return _ifit->floatParsFinal().getRealValue(poi) - poiHat->
getVal();
529 int iPoi =
get()->floatParsFinal().index(poi);
530 int iNp =
get()->floatParsFinal().index(
np);
532 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
534 throw std::runtime_error(
"xRooFitResult::impact: np not found");
536 dynamic_cast<RooRealVar *
>((prefit ?
get()->floatParsInit() :
get()->floatParsFinal()).find(
np));
539 return std::numeric_limits<double>::quiet_NaN();
549 for (
auto p :
get()->floatParsFinal()) {
550 if (strcmp(
p->
GetName(), poi) == 0) {
556 bool matches =
false;
559 if ((
p->getStringAttribute(
"group") && s ==
p->getStringAttribute(
"group")) ||
574 throw std::runtime_error(
TString::Format(
"Could not find poi: %s", poi));
577 fNode->Warning(
"conditionalError",
"No parameters selected by: %s", nps);
578 return (up) ?
static_cast<RooRealVar *
>(poiVar)->getErrorHi() :
static_cast<RooRealVar *
>(poiVar)->getErrorLo();
582 int idx = vars.
index(poi);
583 return sqrt(
get()->conditionalCovarianceMatrix(vars)(idx, idx));
586 auto _cfit = cfit(npNames.
Data(), nps);
588 auto _poi = _cfit->floatParsFinal().find(poi);
590 return (up) ?
static_cast<RooRealVar *
>(_poi)->getErrorHi() :
static_cast<RooRealVar *
>(_poi)->getErrorLo();
598 throw std::runtime_error(
"xRooFitResult::ranknp: poi not found");
600 std::vector<std::pair<std::string, double>> ranks;
602 for (
auto par :
get()->floatParsFinal()) {
605 ranks.emplace_back(std::pair(par->GetName(), impact(poi, par->GetName(), up, prefit,
true)));
608 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
609 if (std::isnan(left.second) && !std::isnan(right.second))
611 if (!std::isnan(left.second) && std::isnan(right.second))
613 return fabs(left.second) > fabs(right.second);
617 for (
auto &[
n,
v] : ranks) {
618 if (
v >= approxThreshold) {
620 v = impact(poi,
n.c_str(), up, prefit);
622 v = std::numeric_limits<double>::quiet_NaN();
628 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
629 if (std::isnan(left.second) && !std::isnan(right.second))
631 if (!std::isnan(left.second) && std::isnan(right.second))
633 return fabs(left.second) > fabs(right.second);
637 out.setName(
"rankings");
638 for (
auto &[
n,
v] : ranks) {
639 out.addClone(*
get()->floatParsFinal().find(
n.c_str()));
640 auto vv =
static_cast<RooRealVar *
>(out.at(out.size() - 1));
659 const_cast<RooArgList &
>(out->constPars()).setAttribAll(
"global",
false);
661 std::unique_ptr<RooAbsCollection>(out->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
663 return xRooFitResult(std::make_shared<xRooNode>(out,
fPdf), std::make_shared<xRooNLLVar>(*
this));
688 *std::unique_ptr<RooAbsCollection>(_pdf->getObservables(
_data)) = *
_data->
get(entry);
702 auto _pdf =
pdf().get();
703 *std::unique_ptr<RooAbsCollection>(_pdf->getObservables(
_data->
get())) = *
_data->
get(entry);
705 _pdf = s->getPdf(s->indexCat().getCurrentLabel());
707 std::unique_ptr<RooAbsCollection> _robs(_pdf->getObservables(
_data->
get()));
709 for (
auto o : *_robs) {
712 std::unique_ptr<std::list<double>> bins(
713 _pdf->binBoundaries(*
a, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()));
715 double lowEdge = -std::numeric_limits<double>::infinity();
716 for (
auto b : *bins) {
717 if (
b >
a->getVal()) {
718 volume *= (
b - lowEdge);
744 for (
auto c : cTerm->list()) {
749 gaus->getMean().GetName()));
754 }
else if (
auto pois =
dynamic_cast<RooPoisson *
>(
c)) {
768 std::unique_ptr<RooAbsCollection>(
pars()->selectByAttrib(
"Constant",
false))->
size();
795 return std::numeric_limits<double>::quiet_NaN();
797 bool isBinned =
false;
799 isBinned =
a->getInt(0);
812 out -=
w * std::log(
w);
827 auto out = std::shared_ptr<RooArgSet>(
get()->getVariables());
828 if (stripGlobalObs &&
fGlobs) {
829 out->remove(*
fGlobs,
true,
true);
837 return Scan(*std::unique_ptr<RooAbsCollection>(
get()->getVariables()->selectByName(scanPars)), coords, profilePars);
844 if (scanPars.
size() > 2 || scanPars.
empty())
854 std::unique_ptr<RooAbsCollection> funcVars(
get()->getVariables());
857 for (
auto &coord : coords) {
858 if (coord.size() != scanPars.
size()) {
859 throw std::runtime_error(
"Invalid coordinate");
861 for (
size_t i = 0; i < coord.size(); i++) {
865 if (profilePars.
empty()) {
884 if (sOpt ==
"sensitivity") {
889 if (sOpt ==
"floating") {
891 auto floats = std::unique_ptr<RooAbsCollection>(_pars->selectByAttrib(
"Constant",
false));
914 if (
auto a = _pars->find(s);
a)
918 if (vars.
size() == 1) {
926 bool normRange =
false;
934 out->SetName(
get()->GetName());
940 double step = (
v->getMax() -
v->getMin()) / 100;
941 double init =
v->getVal();
942 double initVal =
func()->getVal();
944 auto currTime = std::chrono::steady_clock::now();
945 while (out->GetN() < 100 && (low >
v->getMin() || high < v->getMax())) {
946 if (out->GetN() == 0) {
947 out->SetPoint(out->GetN(), low, 0);
956 if (low >
v->getMin()) {
958 auto _v =
func()->getVal();
959 if (std::isnan(_v) || std::isinf(_v)) {
960 if (bad->
GetN() == 0)
964 out->SetPoint(out->GetN(), low, _v - initVal);
968 if (high < v->getMax()) {
970 auto _v =
func()->getVal();
971 if (std::isnan(_v) || std::isinf(_v)) {
972 if (bad->
GetN() == 0)
976 out->SetPoint(out->GetN(), high, _v - initVal);
983 if (std::chrono::steady_clock::now() - currTime > std::chrono::seconds(1)) {
984 currTime = std::chrono::steady_clock::now();
993#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
994 gPad->GetCanvas()->ResetUpdated();
999 Error(
"Draw",
"Name a parameter to scan over: Draw(<name>) , choose from: %s",
1000 _pars->empty() ?
"" : _pars->contentsString().c_str());
1014 return setData(std::dynamic_pointer_cast<RooAbsData>(
data.fComp),
1015 std::shared_ptr<const RooAbsCollection>(
data.globs().argList().snapshot()));
1034 throw std::runtime_error(
"Missing globs");
1038 std::unique_ptr<RooAbsCollection> _actualGlobs(
fPdf->getObservables(s));
1041 std::unique_ptr<RooAbsCollection> _actualGlobs2(
fPdf->getObservables(s2));
1042 if (!_actualGlobs->equals(*_actualGlobs2)) {
1044 rC.
add(*_actualGlobs2);
1048 lC.
add(*_actualGlobs);
1051 throw std::runtime_error(
TString::Format(
"globs mismatch: adding %s removing %s",
r.Data(),
l.Data()));
1056 if (!std::shared_ptr<RooAbsReal>::get()) {
1063 throw std::runtime_error(
"not supported");
1079 }
catch (std::runtime_error &) {
1083 fFuncVars->setAttribAll(
"Constant",
false);
1085 std::shared_ptr<RooAbsData> __data =
fData;
1091 throw std::runtime_error(
"Unable to setData");
1098 }
else if (
auto f = std::unique_ptr<RooAbsCollection>(
fConstVars->selectByAttrib(
"Constant",
false)); !
f->empty()) {
1121 if (std::shared_ptr<RooAbsReal>::get()) {
1160 return fData->sumEntries() * log(1.0 * (s->servers().size() - 1));
1172 for (
int i = 0; i <
fData->numEntries(); i++) {
1203 bool doCLs = sWhat.
Contains(
"pcls");
1204 bool doNull = sWhat.
Contains(
"pnull");
1205 bool doAlt = sWhat.
Contains(
"palt");
1206 double nSigma = (sWhat.
Contains(
"exp"))
1211 : std::numeric_limits<double>::quiet_NaN();
1213 bool toys = sWhat.
Contains(
"toys");
1217 bool readOnly = sWhat.
Contains(
"readonly");
1224 if (getVal(sWhat +
" readonly").second != 0) {
1232 if (nullToys.size() < nToys) {
1233 addNullToys(nToys - nullToys.size());
1235 if (altToys.size() < nToysAlt) {
1236 addAltToys(nToysAlt - altToys.size());
1238 }
else if (doCLs && toys) {
1240 addCLsToys(100, 0, 0.05, nSigma);
1246 RestoreNll(std::shared_ptr<xRooNLLVar> &
v,
bool r) : rr(
r), var(
v)
1248 if (rr && var && var->get()) {
1249 _readOnly = var->get()->getAttribute(
"readOnly");
1250 var->get()->setAttribute(
"readOnly", rr);
1258 var->get()->setAttribute(
"readOnly", _readOnly);
1262 bool _readOnly =
false;
1264 std::shared_ptr<xRooNLLVar> &var;
1267 RestoreNll rest(nllVar, readOnly);
1270 return (toys) ? ts_toys(nSigma) : ts_asymp(nSigma);
1272 return (toys) ? pNull_toys(nSigma) : pNull_asymp(nSigma);
1274 return (toys) ? pAlt_toys(nSigma) : pAlt_asymp(nSigma);
1276 return (toys) ? pCLs_toys(nSigma) : pCLs_asymp(nSigma);
1278 throw std::runtime_error(std::string(
"Unknown: ") +
what);
1285 out.add(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1292 out.setName(
"alt_poi");
1293 out.addClone(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1294 for (
auto a : out) {
1298 if (
auto s =
a->getStringAttribute(
"altVal"); s && strlen(s)) {
1301 v->setVal(std::numeric_limits<double>::quiet_NaN());
1311 if (me.ufit(
true) && !allowedStatusCodes.count(me.ufit(
true)->status()))
1313 if (me.cfit_null(
true) && !allowedStatusCodes.count(me.cfit_null(
true)->status()))
1315 if (me.cfit_alt(
true) && !allowedStatusCodes.count(me.cfit_alt(
true)->status()))
1317 if (me.asimov(
true))
1318 out += me.asimov(
true)->status() << 3;
1324 std::cout <<
"POI: " <<
const_cast<xRooHypoPoint *
>(
this)->poi().contentsString()
1328 std::cout <<
" , pllType: " << fPllType << std::endl;
1330 std::cout <<
" - ufit: ";
1332 std::cout << fUfit->
GetName() <<
" " << fUfit->minNll() <<
" (status=" << fUfit->status() <<
") ("
1335 <<
const_cast<xRooHypoPoint *
>(
this)->mu_hat().getError() <<
")" << std::endl;
1337 std::cout <<
"Not calculated" << std::endl;
1339 std::cout <<
" - null cfit: ";
1341 std::cout << fNull_cfit->
GetName() <<
" " << fNull_cfit->minNll() <<
" (status=" << fNull_cfit->status() <<
")";
1343 std::cout <<
"Not calculated";
1346 std::cout << std::endl <<
" - alt cfit: ";
1348 std::cout << fAlt_cfit->GetName() <<
" " << fAlt_cfit->minNll() <<
" (status=" << fAlt_cfit->status() <<
")"
1351 std::cout <<
"Not calculated" << std::endl;
1353 std::cout <<
" sigma_mu: ";
1355 if (!fAsimov || !fAsimov->fUfit || !fAsimov->fNull_cfit) {
1356 std::cout <<
"Not calculated";
1358 std::cout << const_cast<xRooHypoPoint *>(
this)->
sigma_mu().first <<
" +/- "
1362 std::cout << std::endl;
1363 std::cout <<
" - asimov ufit: ";
1364 if (fAsimov->fUfit) {
1365 std::cout << fAsimov->
fUfit->GetName() <<
" " << fAsimov->fUfit->minNll()
1366 <<
" (status=" << fAsimov->fUfit->status() <<
")";
1368 std::cout <<
"Not calculated";
1370 std::cout << std::endl <<
" - asimov null cfit: ";
1371 if (fAsimov->fNull_cfit) {
1372 std::cout << fAsimov->fNull_cfit->GetName() <<
" " << fAsimov->fNull_cfit->minNll()
1373 <<
" (status=" << fAsimov->fNull_cfit->status() <<
")";
1375 std::cout <<
"Not calculated";
1378 std::cout << std::endl;
1380 std::cout << std::endl;
1383 std::cout <<
" - genFit: " << fGenFit->GetName() << std::endl;
1384 if (!nullToys.empty() || !altToys.empty()) {
1385 std::cout <<
" * null toys: " << nullToys.size();
1386 size_t firstToy = 0;
1387 while (firstToy < nullToys.size() && std::isnan(std::get<1>(nullToys[firstToy])))
1390 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1391 std::cout <<
" , alt toys: " << altToys.size();
1393 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1396 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1397 std::cout << std::endl;
1405 auto var =
dynamic_cast<RooRealVar *
>(ufit()->floatParsFinal().find(fPOIName()));
1409 throw std::runtime_error(
TString::Format(
"Cannot find POI: %s", fPOIName()));
1412 throw std::runtime_error(
"Unconditional fit unavailable");
1419 if (fGenFit && isExpected) {
1427 : hypoTestResult(htr)
1439 if (toys->getGlobalObservables()) {
1440 coords = std::shared_ptr<RooAbsCollection>(toys->getGlobalObservables()->snapshot());
1442 for (
int i = 0; i < toys->numEntries(); i++) {
1443 auto toy = toys->get(i);
1445 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1450 for (
int i = 0; i < toys->numEntries(); i++) {
1451 auto toy = toys->get(i);
1453 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1464 if (!fAsimov && (nllVar || hypoTestResult)) {
1465 auto theFit = (!
fData.first && fGenFit && !isExpected)
1467 : cfit_alt(readOnly);
1470 if (!theFit || allowedStatusCodes.find(theFit->status()) == allowedStatusCodes.end())
1472 fAsimov = std::make_shared<xRooHypoPoint>(*
this);
1473 fAsimov->coords.reset(fAsimov->coords->snapshot());
1474 fAsimov->hypoTestResult.reset();
1476 for (
auto p : fAsimov->poi()) {
1479 v->deleteSharedProperties();
1483 fAsimov->nullToys.clear();
1484 fAsimov->altToys.clear();
1485 fAsimov->fUfit = retrieveFit(3);
1486 fAsimov->fNull_cfit = retrieveFit(4);
1487 fAsimov->fAlt_cfit.reset();
1489 std::make_pair(
nullptr,
nullptr);
1490 fAsimov->fGenFit = theFit;
1491 fAsimov->isExpected =
true;
1500 return std::pair(1, 0);
1501 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1503 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1504 auto _sigma_mu = sigma_mu();
1506 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1509 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1512 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1513 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1519 return std::pair(1, 0);
1520 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1522 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1523 auto _sigma_mu = sigma_mu();
1525 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1528 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1531 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1533 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1538 if (fNullVal() == fAltVal())
1539 return std::pair(1, 0);
1542 return std::pair(1, 0);
1543 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1545 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1547 auto _ts_asymp = ts_asymp(nSigma);
1548 auto _sigma_mu = sigma_mu();
1550 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1553 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1556 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1558 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1561 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1564 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1566 auto nom = (nom1 == 0) ? 0 : nom1 / nom2;
1567 auto up = (up1 == 0) ? 0 : up1 / up2;
1568 auto down = (down1 == 0) ? 0 : down1 / down2;
1570 return std::make_pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1575 if (std::isnan(nSigma))
1577 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1578 auto _sigma_mu = sigma_mu();
1579 if (!first_poi || (!std::isnan(nSigma) && std::isnan(_sigma_mu.first)))
1580 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1582 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1584 _sigma_mu.first + _sigma_mu.second, first_poi->getMin(
"physical"),
1585 first_poi->getMax(
"physical"));
1587 _sigma_mu.first - _sigma_mu.second, first_poi->getMin(
"physical"),
1588 first_poi->getMax(
"physical"));
1589 return std::pair<double, double>(nom, std::max(std::abs(nom - up), std::abs(nom - down)));
1594 if (std::isnan(nSigma))
1597 size_t firstToy = 0;
1598 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1600 if (firstToy >= altToys.size())
1601 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
1604 return std::make_pair(
1605 std::get<1>(altToys[targetIdx]),
1606 (std::get<1>(altToys[std::min(
int(altToys.size()), targetIdx)]) - std::get<1>(altToys[std::max(0, targetIdx)])) /
1612 auto _ufit = ufit(readOnly);
1615 return std::make_pair(hypoTestResult->GetTestStatisticData(), 0);
1616 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1618 if (allowedStatusCodes.find(_ufit->status()) == allowedStatusCodes.end()) {
1619 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1621 if (
auto _first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1622 _first_poi && _first_poi->
getMin(
"physical") > _first_poi->getMin() &&
1623 mu_hat().getVal() < _first_poi->getMin(
"physical")) {
1625 _ufit = cfit_lbound(readOnly);
1627 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1634 return std::make_pair(0, 0);
1635 if (!cfit_null(readOnly) || allowedStatusCodes.find(cfit_null(readOnly)->status()) == allowedStatusCodes.end())
1636 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1638 return std::make_pair(2. * cFactor * (cfit_null(readOnly)->minNll() - _ufit->minNll()),
1639 2. * cFactor * sqrt(pow(cfit_null(readOnly)->edm(), 2) + pow(_ufit->edm(), 2)));
1645 if (!hypoTestResult)
1648 if (
auto fits = hypoTestResult->GetFitInfo()) {
1649 for (
int i = 0; i < fits->numEntries(); i++) {
1650 auto fit = fits->get(i);
1651 if (fit->getCatIndex(
"type") !=
type)
1655 fits->getGlobalObservables()->getStringValue(
TString::Format(
"%s.name", fit->getCatLabel(
"type")));
1658 for (
auto file : *
gROOT->GetListOfFiles()) {
1662 k->GetMotherDir()->GetList()
1665 if (
auto cachedFit = (storedFr) ? storedFr->
fr.get() : k->ReadObject<
RooFitResult>(); cachedFit) {
1668 k->GetMotherDir()->Add(storedFr);
1671 return storedFr->
fr;
1675 auto rfit = std::make_shared<RooFitResult>(_name.c_str(),
TUUID(_name.c_str()).
GetTime().
AsString());
1676 rfit->setStatus(fit->getRealValue(
"status"));
1677 rfit->setMinNLL(fit->getRealValue(
"minNll"));
1678 rfit->setEDM(fit->getRealValue(
"edm"));
1680 std::unique_ptr<RooAbsCollection> par_hats(
1681 hypoTestResult->GetFitInfo()->getGlobalObservables()->selectByName(coords->contentsString().c_str()));
1682 par_hats->setName(
"floatParsFinal");
1683 rfit->setFinalParList(*par_hats);
1690 rfit->setCovarianceMatrix(cov);
1701 if (
auto rfit = retrieveFit(0)) {
1702 return fUfit = rfit;
1704 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1706 if (!nllVar->fFuncVars)
1707 nllVar->reinitialize();
1710 if (!readOnly && isExpected && fGenFit) {
1712 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1713 nllVar->get()->setAttribute(
"readOnly");
1714 auto out = ufit(
true);
1715 nllVar->get()->setAttribute(
"readOnly", tmp);
1720 nllVar->setData(
data());
1723 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1724 nllVar->setData(
fData);
1726 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1727 *nllVar->fFuncVars = *coords;
1728 if (nllVar->fFuncGlobs)
1729 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1730 std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))
1731 ->setAttribAll(
"Constant",
false);
1734 nllVar->fFuncVars->assignValueOnly(fGenFit->constPars());
1735 nllVar->fFuncVars->assignValueOnly(fGenFit->floatParsFinal());
1737 nllVar->get()->SetName(
1738 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1740 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1742 }
else if (!std::isnan(fAltVal())) {
1744 for (
auto _poiCoord : poi()) {
1745 auto _poi =
dynamic_cast<RooRealVar *
>(nllVar->fFuncVars->find(_poiCoord->GetName()));
1747 _poi->
setVal(_poi->getStringAttribute(
"initVal") ?
TString(_poi->getStringAttribute(
"initVal")).
Atof()
1752 return (fUfit = nllVar->minimize());
1758 for (
auto &
c : coll) {
1761 out +=
c->GetName();
1777 if (
auto rfit = retrieveFit(1)) {
1778 return fNull_cfit = rfit;
1780 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1782 if (!nllVar->fFuncVars)
1783 nllVar->reinitialize();
1786 if (!readOnly && isExpected && fGenFit) {
1788 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1789 nllVar->get()->setAttribute(
"readOnly");
1790 auto out = cfit_null(
true);
1791 nllVar->get()->setAttribute(
"readOnly", tmp);
1796 nllVar->setData(
data());
1799 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1800 nllVar->setData(
fData);
1804 *nllVar->fFuncVars = fUfit->floatParsFinal();
1806 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1807 *nllVar->fFuncVars = *coords;
1808 if (nllVar->fFuncGlobs)
1809 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1811 nllVar->fFuncVars->find(fPOIName())
1812 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
1815 nllVar->get()->SetName(
1816 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1818 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1820 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(poi()).c_str());
1821 return (fNull_cfit = nllVar->minimize());
1826 auto _first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1829 if (_first_poi->getMin(
"physical") <= _first_poi->getMin())
1832 return fLbound_cfit;
1833 if (
auto rfit = retrieveFit(6)) {
1834 return fLbound_cfit = rfit;
1836 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1838 if (!nllVar->fFuncVars)
1839 nllVar->reinitialize();
1842 if (!readOnly && isExpected && fGenFit) {
1844 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1845 nllVar->get()->setAttribute(
"readOnly");
1846 auto out = cfit_lbound(
true);
1847 nllVar->get()->setAttribute(
"readOnly", tmp);
1852 nllVar->setData(
data());
1855 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1856 nllVar->setData(
fData);
1860 *nllVar->fFuncVars = fUfit->floatParsFinal();
1862 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1863 *nllVar->fFuncVars = *coords;
1864 nllVar->fFuncVars->setRealValue(_first_poi->GetName(), _first_poi->getMin(
"physical"));
1865 if (nllVar->fFuncGlobs)
1866 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1868 nllVar->fFuncVars->find(fPOIName())
1869 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
1872 nllVar->get()->SetName(
1873 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1875 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1877 nllVar->get()->setStringAttribute(
1879 collectionContents(*std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))).c_str());
1880 return (fLbound_cfit = nllVar->minimize());
1885 if (std::isnan(fAltVal()))
1889 if (
auto rfit = retrieveFit(2)) {
1890 return fAlt_cfit = rfit;
1892 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1894 if (!nllVar->fFuncVars)
1895 nllVar->reinitialize();
1898 if (!readOnly && isExpected && fGenFit) {
1900 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1901 nllVar->get()->setAttribute(
"readOnly");
1902 auto out = cfit_alt(
true);
1903 nllVar->get()->setAttribute(
"readOnly", tmp);
1908 nllVar->setData(
data());
1911 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1912 nllVar->setData(
fData);
1916 *nllVar->fFuncVars = fUfit->floatParsFinal();
1918 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1919 *nllVar->fFuncVars = *coords;
1920 if (nllVar->fFuncGlobs)
1921 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1922 *nllVar->fFuncVars = alt_poi();
1924 nllVar->get()->SetName(
1925 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1927 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1929 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(alt_poi()).c_str());
1930 return (fAlt_cfit = nllVar->minimize());
1936 auto asi = asimov(readOnly);
1939 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1942 auto out = asi->pll(readOnly);
1943 return std::make_pair(std::abs(fNullVal() - fAltVal()) / sqrt(out.first),
1944 out.second * 0.5 * std::abs(fNullVal() - fAltVal()) / (out.first * sqrt(out.first)));
1949 auto _ts = ts_toys(nSigma);
1950 if (std::isnan(_ts.first))
1953 return std::pair(1, 0);
1957 auto &_theToys = (alt) ? altToys : nullToys;
1959 if (_theToys.empty()) {
1960 return std::pair(0.5, std::numeric_limits<double>::infinity());
1967 double result_err_up = 0;
1968 double result_err_down = 0;
1969 for (
auto &toy : _theToys) {
1970 if (std::isnan(std::get<1>(toy))) {
1973 bool res = std::get<1>(toy) >= _ts.first;
1974 if (std::get<2>(toy) != 1) {
1980 result += std::get<2>(toy);
1981 if (std::get<1>(toy) >= _ts.first - _ts.second)
1982 result_err_up += std::get<2>(toy);
1983 if (std::get<1>(toy) >= _ts.first - _ts.second)
1984 result_err_down += std::get<2>(toy);
1989 result_err_down -=
result;
1990 double result_err = std::max(std::abs(result_err_up), std::abs(result_err_down));
1993 result_err /= _theToys.size();
1996 result /= (_theToys.size() - nans);
2000 return std::make_pair(
result, result_err);
2005 return pX_toys(
false, nSigma);
2010 if (!std::isnan(nSigma)) {
2013 return pX_toys(
true, nSigma);
2019 out.coords = coords;
2020 out.fPllType = fPllType;
2021 out.nllVar = nllVar;
2024 auto _cfit = cfit_null();
2027 if (!nllVar->fFuncVars)
2028 nllVar->reinitialize();
2032 out.fGenFit = _cfit;
2039 out.coords = coords;
2040 out.fPllType = fPllType;
2041 out.nllVar = nllVar;
2046 if (!nllVar->fFuncVars)
2047 nllVar->reinitialize();
2052 out.fGenFit = cfit_alt();
2057 bool targetCLs,
double relErrThreshold,
size_t maxToys)
2059 if ((alt && !cfit_alt()) || (!alt && !cfit_null())) {
2060 throw std::runtime_error(
"Cannot add toys, invalid conditional fit");
2063 auto condition = [&]() {
2066 auto obs = targetCLs ? pCLs_toys(target_nSigma) : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma));
2067 if (!std::isnan(obs.first)) {
2068 double diff = (
target < 0) ? obs.first : std::abs(obs.first -
target);
2069 double err = obs.second;
2070 if (err > 1
e-4 && diff <= relErrThreshold * obs.second) {
2074 auto pNull = pNull_toys(target_nSigma);
2075 auto pAlt = pAlt_toys(target_nSigma);
2078 alt = (pAlt.second * pNull.first > pNull.second * pAlt.first);
2079 if ((alt ? pAlt.second : pNull.second) < 1
e-4)
2088 if (!std::isnan(
target) && std::isnan(ts_toys(target_nSigma).first)) {
2089 if (std::isnan(target_nSigma)) {
2090 throw std::runtime_error(
"Cannot target obs p-value because ts value unavailable");
2092 if (targetCLs && pCLs_toys(target_nSigma).second == 0) {
2098 Info(
"addToys",
"First generating 100 alt toys in order to determine expected ts value");
2099 addToys(
true, 100, initialSeed);
2101 if (std::isnan(ts_toys(target_nSigma).first)) {
2102 throw std::runtime_error(
"Unable to determine expected ts value");
2121 size_t toysAdded(0);
2122 size_t altToysAdded(0);
2127 auto &toys = (alt) ? altToys : nullToys;
2128 if (toys.size() >= maxToys) {
2133 if (!std::isnan(
target) && !condition()) {
2136 auto currVal = std::isnan(
target) ? std::pair(0., 0.)
2137 : (targetCLs ? pCLs_toys(target_nSigma)
2138 : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma)));
2139 size_t nnToys = std::min(
size_t(nToys), (maxToys - toys.size()));
2141 for (
size_t i = 0; i < nnToys; i++) {
2143 auto toy = ((alt) ? generateAlt(seed) : generateNull(seed));
2146 toys.push_back(std::make_tuple(seed, toy.pll().first, 1.));
2148 (alt ? altToysAdded : toysAdded)++;
2149 if (std::isnan(std::get<1>(toys.back())))
2151 g->SetPoint(
g->GetN(),
g->GetN(), s.
RealTime() - lastTime);
2155 <<
TString::Format(
"Generated %d/%d %s hypothesis toys [%.2f toys/s]",
2156 int(alt ? altToysAdded : toysAdded),
int(nnToys), alt ?
"alt" :
"null",
2158 if (!std::isnan(
target)) {
2159 std::cout <<
" [current=" << currVal.first <<
"+/-" << currVal.second <<
" target=" <<
target
2160 <<
" nSigma=" << target_nSigma <<
"]";
2162 std::cout <<
"..." << std::flush;
2163 lasti = altToysAdded + toysAdded;
2178 for (
auto &t : toys) {
2179 if (std::isnan(std::get<1>(t)))
2180 std::get<1>(t) = -std::numeric_limits<double>::infinity();
2182 std::sort(toys.begin(), toys.end(),
2183 [](
const decltype(nullToys)::value_type &
a,
const decltype(nullToys)::value_type &
b) ->
bool {
2184 if (std::isnan(std::get<1>(a)))
2186 if (std::isnan(std::get<1>(b)))
2188 return std::get<1>(a) < std::get<1>(b);
2190 for (
auto &t : toys) {
2191 if (std::isinf(std::get<1>(t)))
2192 std::get<1>(t) = std::numeric_limits<double>::quiet_NaN();
2194 if (std::isnan(
target)) {
2201 }
while (condition());
2204 <<
"Finished Generating ";
2206 std::cout << toysAdded <<
" null ";
2209 std::cout << altToysAdded <<
" alt ";
2211 std::cout <<
"toys " <<
TString::Format(
"[%.2f toys/s overall]",
double(toysAdded + altToysAdded) / s2.
RealTime())
2216#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2217 gPad->GetCanvas()->ResetUpdated();
2224 std::cout <<
"Warning: " << nans <<
" toys were bad" << std::endl;
2231 addToys(
false, nToys, seed,
target, target_nSigma);
2235 addToys(
true, nToys, seed,
target, target_nSigma);
2240 addToys(
false, nToys, seed,
target, target_nSigma,
true);
2301 out.nllVar = std::make_shared<xRooNLLVar>(*
this);
2306 while (pattern.NextToken()) {
2309 double val = std::numeric_limits<double>::quiet_NaN();
2310 auto i = s.
Index(
"=");
2315 throw std::runtime_error(
"poiValues must contain value");
2320 throw std::runtime_error(
"Cannot find poi");
2321 if (!std::isnan(val))
2324 if (poiNames !=
"") {
2329 if (poiNames ==
"") {
2330 throw std::runtime_error(
"No poi");
2332 if (!std::isnan(alt_value)) {
2333 std::unique_ptr<RooAbsCollection> thePoi(
fFuncVars->selectByName(poiNames));
2334 for (
auto b : *thePoi) {
2335 if (!
static_cast<RooRealVar *
>(
b)->hasRange(
"physical")) {
2336 static_cast<RooRealVar *
>(
b)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2340 auto _snap = std::unique_ptr<RooAbsCollection>(
fFuncVars->selectByAttrib(
"Constant",
true))->snapshot();
2341 _snap->setAttribAll(
"poi",
false);
2342 std::unique_ptr<RooAbsCollection> _poi(_snap->selectByName(poiNames));
2343 _poi->setAttribAll(
"poi",
true);
2344 if (std::isnan(alt_value)) {
2345 for (
auto a : *_poi)
2346 a->setStringAttribute(
"altVal", nullptr);
2348 for (
auto a : *_poi)
2349 a->setStringAttribute(
"altVal",
TString::
Format(
"%g", alt_value));
2352 _snap->remove(*
fGlobs,
true,
true);
2353 out.coords.reset(_snap);
2355 auto _type = pllType;
2358 if (std::isnan(alt_value)) {
2360 }
else if (
dynamic_cast<RooRealVar *
>(_poi->first())->
getVal() >= alt_value) {
2367 out.fPllType = _type;
2372xRooNLLVar::xRooHypoPoint
2378 std::unique_ptr<RooAbsCollection> _poi(
fFuncVars->selectByAttrib(
"poi",
true));
2379 if (_poi->empty()) {
2380 throw std::runtime_error(
"No POI specified in model");
2381 }
else if (_poi->size() != 1) {
2382 throw std::runtime_error(
"Multiple POI specified in model");
2384 return hypoPoint(_poi->first()->GetName(),
value, alt_value, pllType);
2396 if (!nllVar && !hypoTestResult)
2401 bool hasSame = sOpt.
Contains(
"same");
2406 TH1 *hAxis =
nullptr;
2408 auto clearPad = []() {
2410 if (
gPad->GetNumber() == 0) {
2418 if (!hasSame || !pad) {
2429 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
2436 double _min = std::numeric_limits<double>::quiet_NaN();
2437 double _max = -std::numeric_limits<double>::quiet_NaN();
2439 for (
auto &
p : nullToys) {
2440 if (std::get<2>(
p) == 0)
2442 if (std::isnan(std::get<1>(
p)))
2444 _min = std::min(std::get<1>(
p), _min);
2445 _max = std::max(std::get<1>(
p), _max);
2447 for (
auto &
p : altToys) {
2448 if (std::get<2>(
p) == 0)
2450 if (std::isnan(std::get<1>(
p)))
2452 _min = std::min(std::get<1>(
p), _min);
2453 _max = std::max(std::get<1>(
p), _max);
2457 if (!std::isnan(obs.first)) {
2458 _min = std::min(obs.first - std::abs(obs.first) * 0.1, _min);
2459 _max = std::max(obs.first + std::abs(obs.first) * 0.1, _max);
2462 auto pNull = pNull_toys();
2463 auto pAlt = pAlt_toys();
2464 auto pNullA = pNull_asymp();
2465 auto pAltA = pAlt_asymp();
2467 auto asi = (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit) ? fAsimov->pll().first
2468 : std::numeric_limits<double>::quiet_NaN();
2471 _min = std::min(asi - std::abs(asi), _min);
2472 _max = std::max(asi + std::abs(asi), _max);
2477 auto _poi =
dynamic_cast<RooRealVar *
>(poi().first());
2479 auto makeHist = [&](
bool isAlt) {
2481 auto h =
new TH1D((isAlt) ?
"alt_toys" :
"null_toys",
"", 100, _min, _max + (_max - _min) * 0.01);
2482 h->SetDirectory(
nullptr);
2483 size_t nBadOrZero = 0;
2484 for (
auto &
p : (isAlt) ? altToys : nullToys) {
2485 double w = std::isnan(std::get<1>(
p)) ? 0 : std::get<2>(
p);
2488 if (!std::isnan(std::get<1>(
p)))
2489 h->Fill(std::get<1>(
p),
w);
2491 if (
h->GetEntries() > 0)
2492 h->Scale(1. /
h->Integral(0,
h->GetNbinsX() + 1));
2506 title +=
TString::Format(
"%s' = %g", fPOIName(), (isAlt) ? fAltVal() : fNullVal());
2507 title +=
TString::Format(
" , N_{toys}=%d",
int((isAlt) ? altToys.size() : nullToys.size()));
2516 h->SetMarkerSize(0);
2521 auto nullHist = makeHist(
false);
2522 auto altHist = makeHist(
true);
2525 auto h = (nullHist->GetEntries()) ? nullHist : altHist;
2528 auto axis =
static_cast<TH1 *
>(
h->Clone(
".axis"));
2530 axis->SetStats(
false);
2531 axis->Reset(
"ICES");
2533 axis->SetLineWidth(0);
2535 axis->SetMinimum(1
e-7);
2536 axis->GetYaxis()->SetRangeUser(1
e-7, 10);
2537 axis->SetMaximum(
h->GetMaximum());
2539 l =
new TLegend(0.4, 0.7, 1. -
gPad->GetRightMargin(), 1. -
gPad->GetTopMargin());
2540 l->SetName(
"legend");
2542 l->SetBorderSize(0);
2546 for (
auto o : *
gPad->GetListOfPrimitives()) {
2553 if (
h->GetEntries() > 0) {
2556 h->Draw(
"axissame");
2559 if (
h->GetEntries() > 0) {
2562 h->Draw(
"axissame");
2566 l->AddEntry(nullHist);
2567 l->AddEntry(altHist);
2570 if (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit && !std::isnan(sigma_mu().first) && !std::isnan(fAltVal())) {
2571 auto hh =
static_cast<TH1 *
>(nullHist->Clone(
"null_asymp"));
2573 hh->SetStats(
false);
2574 hh->SetLineStyle(2);
2576 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
2579 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2581 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2584 hh =
static_cast<TH1 *
>(altHist->Clone(
"alt_asymp"));
2586 hh->SetStats(
false);
2587 hh->SetLineStyle(2);
2589 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
2592 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2594 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2609 l->AddEntry(tl, label,
"l");
2611 if (!std::isnan(pNull.first) || !std::isnan(pAlt.first)) {
2612 auto pCLs = pCLs_toys();
2613 label +=
" p_{toy}=(";
2614 label += (std::isnan(pNull.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNull.first, pNull.second);
2615 label += (std::isnan(pAlt.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAlt.first, pAlt.second);
2616 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2618 if (label.Length() > 0)
2619 l->AddEntry(
"", label,
"");
2621 if (!std::isnan(pNullA.first) || !std::isnan(pAltA.first)) {
2622 auto pCLs = pCLs_asymp();
2623 label +=
" p_{asymp}=(";
2624 label += (std::isnan(pNullA.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNullA.first, pNullA.second);
2625 label += (std::isnan(pAltA.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAltA.first, pAltA.second);
2626 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2628 if (label.Length() > 0)
2629 l->AddEntry(
"", label,
"");
2631 if (
auto ax =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
".axis")))
2632 ax->GetYaxis()->SetRangeUser(1
e-7, 1);
2637 auto v =
dynamic_cast<RooRealVar *
>(poi().empty() ? nullptr : poi().first());
2639 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2649 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2653 return (inWords) ?
TString::Format(
"-2log[L(%s,#hat{#hat{#theta}})/L(#hat{%s},#hat{#theta})]",
v->GetTitle(),
2659 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2660 return (inWords) ?
TString::Format(
"Lower-Bound One-Sided Discovery PLR")
2669 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity()) {
2678 return "Test Statistic";
2684 return (poi().empty()) ? nullptr : (poi().first())->GetName();
2688 auto first_poi =
dynamic_cast<RooAbsReal *
>(poi().first());
2689 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
2693 auto _alt_poi = alt_poi();
2694 auto first_poi =
dynamic_cast<RooAbsReal *
>(_alt_poi.first());
2695 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
2703 int tsType = nPoints;
2704 double alt_val = std::numeric_limits<double>::quiet_NaN();
2711 auto out =
hypoSpace(parName, pllType, alt_val);
2718 for (
auto p : out.poi()) {
2720 dynamic_cast<RooRealVar *
>(
p)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2721 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [0,inf]",
p->
GetName());
2722 }
else if(
dynamic_cast<RooRealVar *
>(
p)->hasRange(
"physical")) {
2723 dynamic_cast<RooRealVar *
>(
p)->removeRange(
"physical");
2724 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [-inf,inf] (i.e. removed range)",
p->
GetName());
2739 if (
int(low + 0.5) > 0) {
2740 out.AddPoints(parName,
int(low + 0.5), high, alt_value);
2742 for (
auto p : out.poi()) {
2743 dynamic_cast<RooRealVar *
>(
p)->setRange(
"scan", high, alt_value);
2751 hs.
AddPoints(parName, nPoints, low, high);
2753 for (
auto p : hs.
poi()) {
2754 dynamic_cast<RooRealVar *
>(
p)->setRange(
"scan", low, high);
2763 auto _poi = std::unique_ptr<RooAbsCollection>(
2764 std::unique_ptr<RooAbsCollection>(
pdf()->getVariables())->selectByAttrib(
"poi",
true));
2766 throw std::runtime_error(
"You must specify a POI for the hypoSpace");
2767 return hypoSpace(_poi->first()->GetName(), nPoints, low, high, alt_value, pllType);
2776 if (strlen(parName)) {
2777 std::unique_ptr<RooAbsCollection> axes(s.
pars()->selectByName(parName));
2779 throw std::runtime_error(
"parameter not found");
2780 axes->setAttribAll(
"axis",
true);
2785 s.
fNlls[s.
fPdfs.begin()->second] = std::make_shared<xRooNLLVar>(*
this);
2788 for (
auto poi : s.
poi()) {
2789 poi->setStringAttribute(
"altVal", std::isnan(alt_value) ? nullptr :
TString::Format(
"%f", alt_value));
2797 if (hypoTestResult) {
2798 return *hypoTestResult;
2801 out.SetBackgroundAsAlt(
true);
2802 out.SetName(
TUUID().AsString());
2805 bool setReadonly =
false;
2806 if (nllVar && !nllVar->get()->getAttribute(
"readOnly")) {
2808 nllVar->get()->setAttribute(
"readOnly");
2811 auto ts_obs = ts_asymp();
2813 out.SetTestStatisticData(ts_obs.first);
2820 "pllType",
"test statistic type",
2821 {{
"TwoSided", 0}, {
"OneSidedPositive", 1}, {
"OneSidedNegative", 2}, {
"Uncapped", 3}, {
"Unknown", 4}}));
2823 fitMeta.
addClone(ufit()->floatParsFinal());
2832 {
"asimov_cfit_null", 4},
2834 {
"cfit_lbound", 6}}));
2839 auto fitDS =
new RooDataSet(
"fits",
"fit summary data", fitDetails);
2840 fitDS->convertToTreeStore();
2842 for (
int i = 0; i < 7; i++) {
2843 std::shared_ptr<const RooFitResult> fit;
2845 case 0: fit = ufit();
break;
2846 case 1: fit = cfit_null();
break;
2847 case 2: fit = cfit_alt();
break;
2848 case 3: fit = asimov() ? asimov()->ufit(
true) :
nullptr;
break;
2849 case 4: fit = asimov() ? asimov()->cfit_null(
true) :
nullptr;
break;
2850 case 5: fit = fGenFit;
break;
2851 case 6: fit = cfit_lbound();
break;
2861 fitDS->add(fitDetails);
2864 fitDS->setGlobalObservables(fitMeta);
2866 out.SetFitInfo(fitDS);
2875 nullToyDS->setGlobalObservables(nullMeta);
2876 if (!nullToys.empty()) {
2878 std::vector<double> values;
2879 std::vector<double> weights;
2880 values.reserve(nullToys.size());
2881 weights.reserve(nullToys.size());
2883 for (
auto &t : nullToys) {
2884 values.push_back(std::get<1>(t));
2885 weights.push_back(std::get<2>(t));
2888 nullToyDS->add(nullDetails, std::get<2>(t));
2891#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2892 out.fNullPValue = pNull_toys().first;
2893 out.fNullPValueError =
2894 pNull_toys().second;
2896 out.SetNullPValue(pNull_toys().first);
2897 out.SetNullPValueError(
2898 pNull_toys().second);
2901#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2902 out.fNullPValue = pNull_asymp().first;
2903 out.fNullPValueError = pNull_asymp().second;
2905 out.SetNullPValue(pNull_asymp().first);
2906 out.SetNullPValueError(pNull_asymp().second);
2909 out.SetNullDetailedOutput(nullToyDS);
2911 if (!altToys.empty()) {
2912 std::vector<double> values;
2913 std::vector<double> weights;
2914 values.reserve(altToys.size());
2915 weights.reserve(altToys.size());
2922 altToyDS->setGlobalObservables(altMeta);
2923 for (
auto &t : altToys) {
2924 values.push_back(std::get<1>(t));
2925 weights.push_back(std::get<2>(t));
2928 altToyDS->add(altDetails, std::get<2>(t));
2931 out.SetAltDetailedOutput(altToyDS);
2932#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2933 out.fAlternatePValue = pAlt_toys().first;
2934 out.fAlternatePValueError =
2937 out.SetAltPValue(pAlt_toys().first);
2938 out.SetAltPValueError(
2939 pAlt_toys().second);
2943#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2944 out.fAlternatePValue = pAlt_asymp().first;
2945 out.fAlternatePValueError = pAlt_asymp().second;
2947 out.SetAltPValue(pAlt_asymp().first);
2948 out.SetAltPValueError(pAlt_asymp().second);
2953 nllVar->get()->setAttribute(
"readOnly",
false);
GOFOpMode operMode() const
RooAbsData * _data
Pointer to original input dataset.
RooAbsReal * _func
Pointer to original input function.
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 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 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 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 std::shared_ptr< xRooNode > &in, const std::shared_ptr< xRooNLLVar > &nll=nullptr)
xRooFitResult cfit(const char *poiValues, const char *alias=nullptr)
std::shared_ptr< RooStats::HypoTestResult > hypoTestResult
std::pair< double, double > getVal(const char *what)
RooStats::HypoTestResult result()
std::shared_ptr< const RooFitResult > retrieveFit(int type)
std::pair< double, double > pNull_toys(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::pair< double, double > pAlt_toys(double nSigma=std::numeric_limits< double >::quiet_NaN())
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.
std::pair< double, double > ts_asymp(double nSigma=std::numeric_limits< double >::quiet_NaN())
TString tsTitle(bool inWords=false) const
std::shared_ptr< const RooFitResult > fUfit
xRooHypoPoint(std::shared_ptr< RooStats::HypoTestResult > htr=nullptr, const RooAbsCollection *_coords=nullptr)
xRooFit::Asymptotics::PLLType fPllType
std::vector< std::tuple< int, double, double > > nullToys
std::shared_ptr< xRooHypoPoint > asimov(bool readOnly=false)
std::pair< double, double > pll(bool readOnly=false)
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)
std::pair< double, double > sigma_mu(bool readOnly=false)
RooArgList alt_poi() const
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())
std::pair< double, double > pX_toys(bool alt, double 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())
std::pair< double, double > pAlt_asymp(double nSigma=std::numeric_limits< double >::quiet_NaN())
xRooHypoPoint generateAlt(int seed=0)
std::pair< double, double > ts_toys(double nSigma=std::numeric_limits< double >::quiet_NaN())
std::pair< double, double > pNull_asymp(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())
std::pair< double, double > pCLs_asymp(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)
std::shared_ptr< const RooAbsCollection > fGlobs
std::shared_ptr< RooLinkedList > fOpts
std::shared_ptr< RooAbsReal > func() const
RooAbsData * data() const
double binnedDataTerm() const
ROOT::Math::IOptions * fitConfigOptions()
RooConstraintSum * constraintTerm() const
std::shared_ptr< ROOT::Fit::FitConfig > fFitConfig
double saturatedConstraintTerm() const
double extendedTerm() const
RooNLLVar * nllTerm() const
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
const RooAbsCollection * globs() const
double saturatedNllTerm() const
void Print(Option_t *opt="")
std::string fFuncCreationLog
void Draw(Option_t *opt="")
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
std::shared_ptr< RooAbsData > fData
std::shared_ptr< RooAbsPdf > fPdf
bool setData(const std::pair< std::shared_ptr< RooAbsData >, std::shared_ptr< const RooAbsCollection > > &_data)
xRooHypoPoint hypoPoint(const char *parName, double value, double alt_value=std::numeric_limits< double >::quiet_NaN(), const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown)
xRooFitResult minimize(const std::shared_ptr< ROOT::Fit::FitConfig > &=nullptr)
The xRooNode class is designed to wrap over a TObject and provide functionality to aid with interacti...
Generic interface for defining configuration options of a numerical algorithm.
void SetValue(const char *name, double val)
generic methods for retrieving options
virtual void SetNamedValue(const char *, const char *)
Common abstract base class for objects that represent a value and a "shape" in RooFit.
TIterator Use servers() and begin()
void Print(Option_t *options=nullptr) const override
Print the object to the defaultPrintStream().
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.
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.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
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 double weight() const =0
virtual double sumEntries() const =0
Return effective number of entries in dataset, i.e., sum all weights.
virtual const RooArgSet * get() const
virtual Int_t numEntries() const
Return number of entries in dataset, i.e., count unweighted entries.
RooArgSet const * getGlobalObservables() const
Returns snapshot of global observables stored in this data.
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)
bool setData(RooAbsData &data, bool cloneData=true) override
Change dataset that is used to given one.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
Named container for two doubles, two integers two object points and three string pointers that can be...
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)
Implements a -log(likelihood) calculation from a dataset and a PDF.
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.
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.
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.
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 END_XROOFIT_NAMESPACE
void removeTopic(RooFit::MsgTopic oldTopic)
std::string collectionContents(const RooAbsCollection &coll)