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,
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;
317 std::cout <<
"Data: ";
321 std::cout <<
"<null>" << std::endl;
322 std::cout <<
"NLL Options: " << std::endl;
323 for (
int i = 0; i <
fOpts->GetSize(); i++) {
327 std::cout <<
" " <<
c->
GetName() <<
" : ";
329 std::cout <<
c->getString(0);
330 else if (
c->getSet(0) && !
c->getSet(0)->empty())
331 std::cout << (
c->getSet(0)->contentsString());
333 std::cout <<
c->getInt(0);
334 std::cout << std::endl;
337 std::cout <<
"Fit Config: " << std::endl;
338 std::cout <<
" UseParabErrors: " << (
fFitConfig->ParabErrors() ?
"True" :
"False")
339 <<
" [toggles HESSE algorithm]" << std::endl;
340 std::cout <<
" MinimizerOptions: " << std::endl;
349 if (std::shared_ptr<RooAbsReal>::get())
350 oldName = std::shared_ptr<RooAbsReal>::get()->GetName();
355 fPdf->treeNodeServerList(&s,
nullptr,
true,
false);
357 bool isBinned =
false;
358 bool hasBinned =
false;
361 isBinned =
a->getInt(0);
363 std::map<RooAbsArg *, bool> origValues;
366 if (
a->InheritsFrom(
"RooRealSumPdf")) {
369 bool setBinned =
false;
371 std::unique_ptr<RooArgSet> obs(
a->getObservables(
fData->get()));
372 if (obs->size() == 1) {
373 auto *var =
static_cast<RooRealVar *
>(obs->first());
374 std::unique_ptr<std::list<double>> boundaries{
dynamic_cast<RooAbsReal *
>(
a)->binBoundaries(
375 *var, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity())};
377 if (!std::shared_ptr<RooAbsReal>::get())
378 Info(
"xRooNLLVar",
"%s will be evaluated as a Binned PDF (%d bins)",
a->GetName(),
379 int(boundaries->size() - 1));
384 origValues[
a] =
a->getAttribute(
"BinnedLikelihood");
385 a->setAttribute(
"BinnedLikelihood", setBinned);
391 std::set<std::string> setNames;
394 setNames.insert(
a.first);
397 for (
auto &
a : setNames) {
401 std::set<std::string> attribs;
402 if (std::shared_ptr<RooAbsReal>::get())
403 attribs = std::shared_ptr<RooAbsReal>::get()->attributes();
404 this->reset(std::unique_ptr<RooAbsReal>{
fPdf->createNLL(*
fData, *
fOpts)}.release());
410 for (
auto &
a : attribs)
411 std::shared_ptr<RooAbsReal>::get()->setAttribute(
a.c_str());
417 std::shared_ptr<RooAbsReal>::get()->SetName(oldName);
418 if (!origValues.empty()) {
420 std::shared_ptr<RooAbsReal>::get()->getVal();
421 for (
auto &[o,
v] : origValues)
422 o->setAttribute(
"BinnedLikelihood",
v);
426 fFuncVars = std::unique_ptr<RooArgSet>{std::shared_ptr<RooAbsReal>::get()->getVariables()};
434std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
438 return std::pair(
nullptr,
nullptr);
439 auto fr = std::make_shared<RooFitResult>(
TUUID().AsString());
443 fr->setConstParList(
l);
444 const_cast<RooArgList &
>(fr->constPars()).setAttribAll(
"global",
false);
446 std::unique_ptr<RooAbsCollection>(fr->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
454 fCfits(std::make_shared<std::map<std::string,
xRooFitResult>>())
478 throw std::runtime_error(
"xRooFitResult::cfit: Cannot create cfit without nll");
482 if (
auto res = fCfits->find(alias); res != fCfits->end()) {
486 if (
auto res = fCfits->find(poiValues); res != fCfits->end()) {
491 *fNll->fFuncVars =
get()->floatParsFinal();
492 fNll->fFuncVars->assignValueOnly(
get()->constPars());
493 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->floatParsFinal()))
494 ->setAttribAll(
"Constant",
false);
495 std::unique_ptr<RooAbsCollection>(fNll->fFuncVars->selectCommon(
get()->constPars()))->setAttribAll(
"Constant",
true);
500 fCfits->insert(std::pair((alias) ? alias : poiValues, out));
507 throw std::runtime_error(
"xRooFitResult::ifit: par not found");
516 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
517 auto _ifit = ifit(
np, up, prefit);
519 throw std::runtime_error(
"xRooFitResult::impact: null ifit");
520 if (_ifit->status() != 0)
521 fNode->Warning(
"impact",
"ifit status code is %d", _ifit->status());
522 return _ifit->floatParsFinal().getRealValue(poi) - poiHat->
getVal();
525 int iPoi =
get()->floatParsFinal().index(poi);
526 int iNp =
get()->floatParsFinal().index(
np);
528 throw std::runtime_error(
"xRooFitResult::impact: poi not found");
530 throw std::runtime_error(
"xRooFitResult::impact: np not found");
532 dynamic_cast<RooRealVar *
>((prefit ?
get()->floatParsInit() :
get()->floatParsFinal()).find(
np));
535 return std::numeric_limits<double>::quiet_NaN();
545 for (
auto p :
get()->floatParsFinal()) {
546 if (strcmp(
p->
GetName(), poi) == 0) {
552 bool matches =
false;
555 if ((
p->getStringAttribute(
"group") && s ==
p->getStringAttribute(
"group")) ||
570 throw std::runtime_error(
TString::Format(
"Could not find poi: %s", poi));
573 fNode->Warning(
"conditionalError",
"No parameters selected by: %s", nps);
574 return (up) ?
static_cast<RooRealVar *
>(poiVar)->getErrorHi() :
static_cast<RooRealVar *
>(poiVar)->getErrorLo();
578 int idx = vars.
index(poi);
579 return sqrt(
get()->conditionalCovarianceMatrix(vars)(idx, idx));
582 auto _cfit = cfit(npNames.
Data(), nps);
584 auto _poi = _cfit->floatParsFinal().find(poi);
586 return (up) ?
static_cast<RooRealVar *
>(_poi)->getErrorHi() :
static_cast<RooRealVar *
>(_poi)->getErrorLo();
594 throw std::runtime_error(
"xRooFitResult::ranknp: poi not found");
596 std::vector<std::pair<std::string, double>> ranks;
598 for (
auto par :
get()->floatParsFinal()) {
601 ranks.emplace_back(std::pair(par->GetName(), impact(poi, par->GetName(), up, prefit,
true)));
604 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
605 if (std::isnan(left.second) && !std::isnan(right.second))
607 if (!std::isnan(left.second) && std::isnan(right.second))
609 return fabs(left.second) > fabs(right.second);
613 for (
auto &[
n,
v] : ranks) {
614 if (
v >= approxThreshold) {
616 v = impact(poi,
n.c_str(), up, prefit);
618 v = std::numeric_limits<double>::quiet_NaN();
624 std::sort(ranks.begin(), ranks.end(), [](
auto &left,
auto &right) {
625 if (std::isnan(left.second) && !std::isnan(right.second))
627 if (!std::isnan(left.second) && std::isnan(right.second))
629 return fabs(left.second) > fabs(right.second);
633 out.setName(
"rankings");
634 for (
auto &[
n,
v] : ranks) {
635 out.addClone(*
get()->floatParsFinal().find(
n.c_str()));
636 auto vv =
static_cast<RooRealVar *
>(out.at(out.size() - 1));
655 const_cast<RooArgList &
>(out->constPars()).setAttribAll(
"global",
false);
657 std::unique_ptr<RooAbsCollection>(out->constPars().selectCommon(*
fGlobs))->
setAttribAll(
"global",
true);
659 return xRooFitResult(std::make_shared<xRooNode>(out,
fPdf), std::make_shared<xRooNLLVar>(*
this));
681 if (
size_t(_data->numEntries()) <= entry)
684 *std::unique_ptr<RooAbsCollection>(_pdf->getObservables(_data)) = *_data->get(entry);
687 return -_data->weight() * _pdf->getLogVal(_data->get());
696 if (
size_t(_data->numEntries()) <= entry)
698 auto _pdf =
pdf().get();
699 *std::unique_ptr<RooAbsCollection>(_pdf->getObservables(_data->get())) = *_data->get(entry);
701 _pdf = s->getPdf(s->indexCat().getCurrentLabel());
703 std::unique_ptr<RooAbsCollection> _robs(_pdf->getObservables(_data->get()));
705 for (
auto o : *_robs) {
708 std::unique_ptr<std::list<double>> bins(
709 _pdf->binBoundaries(*
a, -std::numeric_limits<double>::infinity(), std::numeric_limits<double>::infinity()));
711 double lowEdge = -std::numeric_limits<double>::infinity();
712 for (
auto b : *bins) {
713 if (
b >
a->getVal()) {
714 volume *= (
b - lowEdge);
740 for (
auto c : cTerm->list()) {
745 gaus->getMean().GetName()));
750 }
else if (
auto pois =
dynamic_cast<RooPoisson *
>(
c)) {
764 std::unique_ptr<RooAbsCollection>(
pars()->selectByAttrib(
"Constant",
false))->
size();
791 return std::numeric_limits<double>::quiet_NaN();
793 bool isBinned =
false;
795 isBinned =
a->getInt(0);
804 double out = _data->sumEntries();
805 for (
int i = 0; i < _data->numEntries(); i++) {
807 double w = _data->weight();
808 out -=
w * std::log(
w);
822 auto out = std::shared_ptr<RooArgSet>(
get()->getVariables());
823 if (stripGlobalObs &&
fGlobs) {
824 out->remove(*
fGlobs,
true,
true);
832 return Scan(*std::unique_ptr<RooAbsCollection>(
get()->getVariables()->selectByName(scanPars)), coords, profilePars);
839 if (scanPars.
size() > 2 || scanPars.
empty())
849 std::unique_ptr<RooAbsCollection> funcVars(
get()->getVariables());
852 for (
auto &coord : coords) {
853 if (coord.size() != scanPars.
size()) {
854 throw std::runtime_error(
"Invalid coordinate");
856 for (
size_t i = 0; i < coord.size(); i++) {
860 if (profilePars.
empty()) {
879 if (sOpt ==
"sensitivity") {
884 if (sOpt ==
"floating") {
886 auto floats = std::unique_ptr<RooAbsCollection>(_pars->selectByAttrib(
"Constant",
false));
909 if (
auto a = _pars->find(s);
a)
913 if (vars.
size() == 1) {
921 bool normRange =
false;
929 out->SetName(
get()->GetName());
935 double step = (
v->getMax() -
v->getMin()) / 100;
936 double init =
v->getVal();
937 double initVal =
func()->getVal();
939 auto currTime = std::chrono::steady_clock::now();
940 while (out->GetN() < 100 && (low >
v->getMin() || high < v->getMax())) {
941 if (out->GetN() == 0) {
942 out->SetPoint(out->GetN(), low, 0);
951 if (low >
v->getMin()) {
953 auto _v =
func()->getVal();
954 if (std::isnan(_v) || std::isinf(_v)) {
955 if (bad->
GetN() == 0)
959 out->SetPoint(out->GetN(), low, _v - initVal);
963 if (high < v->getMax()) {
965 auto _v =
func()->getVal();
966 if (std::isnan(_v) || std::isinf(_v)) {
967 if (bad->
GetN() == 0)
971 out->SetPoint(out->GetN(), high, _v - initVal);
978 if (std::chrono::steady_clock::now() - currTime > std::chrono::seconds(1)) {
979 currTime = std::chrono::steady_clock::now();
988#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
989 gPad->GetCanvas()->ResetUpdated();
994 Error(
"Draw",
"Name a parameter to scan over: Draw(<name>) , choose from: %s",
995 _pars->empty() ?
"" : _pars->contentsString().c_str());
999std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
xRooNLLVar::getData()
const
1009 return setData(std::dynamic_pointer_cast<RooAbsData>(
data.fComp),
1010 std::shared_ptr<const RooAbsCollection>(
data.globs().argList().snapshot()));
1013bool xRooNLLVar::setData(
const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &_data)
1016 if (
fData == _data.first &&
fGlobs == _data.second)
1021 auto _dglobs = (_data.second) ? _data.second
1022 : std::shared_ptr<const RooAbsCollection>(_data.first->getGlobalObservables(),
1025 if (
fGlobs && !(
fGlobs->empty() && !_dglobs) && _data.first &&
1029 throw std::runtime_error(
"Missing globs");
1033 std::unique_ptr<RooAbsCollection> _actualGlobs(
fPdf->getObservables(s));
1036 std::unique_ptr<RooAbsCollection> _actualGlobs2(
fPdf->getObservables(s2));
1037 if (!_actualGlobs->equals(*_actualGlobs2)) {
1039 rC.
add(*_actualGlobs2);
1043 lC.
add(*_actualGlobs);
1046 throw std::runtime_error(
TString::Format(
"globs mismatch: adding %s removing %s",
r.Data(),
l.Data()));
1051 if (!std::shared_ptr<RooAbsReal>::get()) {
1052 fData = _data.first;
1058 throw std::runtime_error(
"not supported");
1062 if (_data.first->getGlobalObservables()) {
1072 fData = _data.first;
1074 }
catch (std::runtime_error &) {
1078 fFuncVars->setAttribAll(
"Constant",
false);
1080 std::shared_ptr<RooAbsData> __data =
fData;
1082 fData = _data.first;
1086 throw std::runtime_error(
"Unable to setData");
1093 }
else if (
auto f = std::unique_ptr<RooAbsCollection>(
fConstVars->selectByAttrib(
"Constant",
false)); !
f->empty()) {
1116 if (std::shared_ptr<RooAbsReal>::get())
1135 auto _func =
func();
1136 if (
auto a =
dynamic_cast<RooNLLVar *
>(_func.get());
a)
1138 for (
auto s : _func->servers()) {
1154 return fData->sumEntries() * log(1.0 * (s->servers().size() - 1));
1166 for (
int i = 0; i <
fData->numEntries(); i++) {
1176 auto _func =
func();
1179 for (
auto s : _func->servers()) {
1197 bool doCLs = sWhat.
Contains(
"pcls");
1198 bool doNull = sWhat.
Contains(
"pnull");
1199 bool doAlt = sWhat.
Contains(
"palt");
1200 double nSigma = (sWhat.
Contains(
"exp"))
1205 : std::numeric_limits<double>::quiet_NaN();
1207 bool toys = sWhat.
Contains(
"toys");
1211 bool readOnly = sWhat.
Contains(
"readonly");
1218 if (getVal(sWhat +
" readonly").second != 0) {
1226 if (nullToys.size() < nToys) {
1227 addNullToys(nToys - nullToys.size());
1229 if (altToys.size() < nToysAlt) {
1230 addAltToys(nToysAlt - altToys.size());
1232 }
else if (doCLs && toys) {
1234 addCLsToys(100, 0, 0.05, nSigma);
1240 RestoreNll(std::shared_ptr<xRooNLLVar> &
v,
bool r) : rr(
r), var(
v)
1242 if (rr && var && var->get()) {
1243 _readOnly = var->get()->getAttribute(
"readOnly");
1244 var->get()->setAttribute(
"readOnly", rr);
1252 var->get()->setAttribute(
"readOnly", _readOnly);
1256 bool _readOnly =
false;
1258 std::shared_ptr<xRooNLLVar> &var;
1261 RestoreNll rest(nllVar, readOnly);
1264 return (toys) ? ts_toys(nSigma) : ts_asymp(nSigma);
1266 return (toys) ? pNull_toys(nSigma) : pNull_asymp(nSigma);
1268 return (toys) ? pAlt_toys(nSigma) : pAlt_asymp(nSigma);
1270 return (toys) ? pCLs_toys(nSigma) : pCLs_asymp(nSigma);
1272 throw std::runtime_error(std::string(
"Unknown: ") +
what);
1279 out.add(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1286 out.setName(
"alt_poi");
1287 out.addClone(*std::unique_ptr<RooAbsCollection>(coords->selectByAttrib(
"poi",
true)));
1288 for (
auto a : out) {
1292 if (
auto s =
a->getStringAttribute(
"altVal"); s && strlen(s)) {
1295 v->setVal(std::numeric_limits<double>::quiet_NaN());
1305 if (me.ufit(
true) && !allowedStatusCodes.count(me.ufit(
true)->status()))
1307 if (me.cfit_null(
true) && !allowedStatusCodes.count(me.cfit_null(
true)->status()))
1309 if (me.cfit_alt(
true) && !allowedStatusCodes.count(me.cfit_alt(
true)->status()))
1311 if (me.asimov(
true))
1312 out += me.asimov(
true)->status() << 3;
1318 std::cout <<
"POI: " <<
const_cast<xRooHypoPoint *
>(
this)->poi().contentsString()
1322 std::cout <<
" , pllType: " << fPllType << std::endl;
1324 std::cout <<
" - ufit: ";
1326 std::cout << fUfit->
GetName() <<
" " << fUfit->minNll() <<
" (status=" << fUfit->status() <<
") ("
1329 <<
const_cast<xRooHypoPoint *
>(
this)->mu_hat().getError() <<
")" << std::endl;
1331 std::cout <<
"Not calculated" << std::endl;
1333 std::cout <<
" - null cfit: ";
1335 std::cout << fNull_cfit->
GetName() <<
" " << fNull_cfit->minNll() <<
" (status=" << fNull_cfit->status() <<
")";
1337 std::cout <<
"Not calculated";
1340 std::cout << std::endl <<
" - alt cfit: ";
1342 std::cout << fAlt_cfit->GetName() <<
" " << fAlt_cfit->minNll() <<
" (status=" << fAlt_cfit->status() <<
")"
1345 std::cout <<
"Not calculated" << std::endl;
1347 std::cout <<
" sigma_mu: ";
1349 if (!fAsimov || !fAsimov->fUfit || !fAsimov->fNull_cfit) {
1350 std::cout <<
"Not calculated";
1352 std::cout << const_cast<xRooHypoPoint *>(
this)->
sigma_mu().first <<
" +/- "
1356 std::cout << std::endl;
1357 std::cout <<
" - asimov ufit: ";
1359 std::cout << fAsimov->
fUfit->GetName() <<
" " << fAsimov->fUfit->minNll()
1360 <<
" (status=" << fAsimov->fUfit->status() <<
")";
1362 std::cout <<
"Not calculated";
1363 std::cout << std::endl <<
" - asimov null cfit: ";
1364 if (fAsimov->fNull_cfit)
1365 std::cout << fAsimov->fNull_cfit->GetName() <<
" " << fAsimov->fNull_cfit->minNll()
1366 <<
" (status=" << fAsimov->fNull_cfit->status() <<
")";
1368 std::cout <<
"Not calculated";
1370 std::cout << std::endl;
1372 std::cout << std::endl;
1375 std::cout <<
" - genFit: " << fGenFit->GetName() << std::endl;
1376 if (!nullToys.empty() || !altToys.empty()) {
1377 std::cout <<
" * null toys: " << nullToys.size();
1378 size_t firstToy = 0;
1379 while (firstToy < nullToys.size() && std::isnan(std::get<1>(nullToys[firstToy])))
1382 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1383 std::cout <<
" , alt toys: " << altToys.size();
1385 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1388 std::cout <<
" [ of which " << firstToy <<
" are bad]";
1389 std::cout << std::endl;
1397 auto var =
dynamic_cast<RooRealVar *
>(ufit()->floatParsFinal().find(fPOIName()));
1401 throw std::runtime_error(
TString::Format(
"Cannot find POI: %s",fPOIName()));
1403 throw std::runtime_error(
"Unconditional fit unavailable");
1410 if (fGenFit && isExpected) {
1418 :
TNamed(), hypoTestResult(htr)
1430 if (toys->getGlobalObservables()) {
1431 coords = std::shared_ptr<RooAbsCollection>(toys->getGlobalObservables()->snapshot());
1433 for (
int i = 0; i < toys->numEntries(); i++) {
1434 auto toy = toys->get(i);
1436 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1441 for (
int i = 0; i < toys->numEntries(); i++) {
1442 auto toy = toys->get(i);
1444 std::make_tuple(
int(toy->getRealValue(
"seed")), toy->getRealValue(
"ts"), toys->weight()));
1455 if (!fAsimov && (nllVar || hypoTestResult)) {
1456 auto theFit = (!
fData.first && fGenFit && !isExpected)
1458 : cfit_alt(readOnly);
1461 if (!theFit || allowedStatusCodes.find(theFit->status()) == allowedStatusCodes.end())
1463 fAsimov = std::make_shared<xRooHypoPoint>(*
this);
1464 fAsimov->coords.reset(fAsimov->coords->snapshot());
1465 fAsimov->hypoTestResult.reset();
1467 for (
auto p : fAsimov->poi()) {
1470 v->deleteSharedProperties();
1474 fAsimov->nullToys.clear();
1475 fAsimov->altToys.clear();
1476 fAsimov->fUfit = retrieveFit(3);
1477 fAsimov->fNull_cfit = retrieveFit(4);
1478 fAsimov->fAlt_cfit.reset();
1480 std::make_pair(
nullptr,
nullptr);
1481 fAsimov->fGenFit = theFit;
1482 fAsimov->isExpected =
true;
1491 return std::pair(1, 0);
1492 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1494 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1495 auto _sigma_mu = sigma_mu();
1497 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1500 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1503 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1504 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1510 return std::pair(1, 0);
1511 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1513 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1514 auto _sigma_mu = sigma_mu();
1516 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1519 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1522 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1524 return std::pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1529 if (fNullVal() == fAltVal())
1530 return std::pair(1, 0);
1533 return std::pair(1, 0);
1534 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1536 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1538 auto _ts_asymp = ts_asymp(nSigma);
1539 auto _sigma_mu = sigma_mu();
1541 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1544 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1547 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1549 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1552 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1555 first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1557 auto nom = (nom1 == 0) ? 0 : nom1 / nom2;
1558 auto up = (up1 == 0) ? 0 : up1 / up2;
1559 auto down = (down1 == 0) ? 0 : down1 / down2;
1561 return std::make_pair(nom, std::max(std::abs(up - nom), std::abs(down - nom)));
1566 if (std::isnan(nSigma))
1568 auto first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1569 auto _sigma_mu = sigma_mu();
1570 if (!first_poi || (!std::isnan(nSigma) && std::isnan(_sigma_mu.first)))
1571 return std::pair(std::numeric_limits<double>::quiet_NaN(), 0);
1573 _sigma_mu.first, first_poi->getMin(
"physical"), first_poi->getMax(
"physical"));
1575 _sigma_mu.first + _sigma_mu.second, first_poi->getMin(
"physical"),
1576 first_poi->getMax(
"physical"));
1578 _sigma_mu.first - _sigma_mu.second, first_poi->getMin(
"physical"),
1579 first_poi->getMax(
"physical"));
1580 return std::pair<double, double>(nom, std::max(std::abs(nom - up), std::abs(nom - down)));
1585 if (std::isnan(nSigma))
1588 size_t firstToy = 0;
1589 while (firstToy < altToys.size() && std::isnan(std::get<1>(altToys[firstToy])))
1591 if (firstToy >= altToys.size())
1592 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), std::numeric_limits<double>::quiet_NaN());
1595 return std::make_pair(
1596 std::get<1>(altToys[targetIdx]),
1597 (std::get<1>(altToys[std::min(
int(altToys.size()), targetIdx)]) - std::get<1>(altToys[std::max(0, targetIdx)])) /
1603 auto _ufit = ufit(readOnly);
1606 return std::make_pair(hypoTestResult->GetTestStatisticData(), 0);
1607 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1609 if (allowedStatusCodes.find(_ufit->status()) == allowedStatusCodes.end()) {
1610 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1613 _first_poi && _first_poi->
getMin(
"physical") > _first_poi->getMin() &&
1614 mu_hat().getVal() < _first_poi->getMin(
"physical")) {
1616 _ufit = cfit_lbound(readOnly);
1618 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1625 return std::make_pair(0, 0);
1626 if (!cfit_null(readOnly) || allowedStatusCodes.find(cfit_null(readOnly)->status()) == allowedStatusCodes.end())
1627 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1629 return std::make_pair(2. * cFactor * (cfit_null(readOnly)->minNll() - _ufit->minNll()),
1630 2. * cFactor * sqrt(pow(cfit_null(readOnly)->edm(), 2) + pow(_ufit->edm(), 2)));
1636 if (!hypoTestResult)
1639 if (
auto fits = hypoTestResult->GetFitInfo()) {
1640 for (
int i = 0; i < fits->numEntries(); i++) {
1641 auto fit = fits->get(i);
1642 if (fit->getCatIndex(
"type") !=
type)
1646 fits->getGlobalObservables()->getStringValue(
TString::Format(
"%s.name", fit->getCatLabel(
"type")));
1649 for (
auto file : *
gROOT->GetListOfFiles()) {
1653 k->GetMotherDir()->GetList()
1656 if (
auto cachedFit = (storedFr) ? storedFr->
fr.get() : k->ReadObject<
RooFitResult>(); cachedFit) {
1659 k->GetMotherDir()->Add(storedFr);
1662 return storedFr->
fr;
1666 auto rfit = std::make_shared<RooFitResult>(_name.c_str(),
TUUID(_name.c_str()).
GetTime().
AsString());
1667 rfit->setStatus(fit->getRealValue(
"status"));
1668 rfit->setMinNLL(fit->getRealValue(
"minNll"));
1669 rfit->setEDM(fit->getRealValue(
"edm"));
1671 std::unique_ptr<RooAbsCollection> par_hats(
1672 hypoTestResult->GetFitInfo()->getGlobalObservables()->selectByName(coords->contentsString().c_str()));
1673 par_hats->setName(
"floatParsFinal");
1674 rfit->setFinalParList(*par_hats);
1681 rfit->setCovarianceMatrix(cov);
1692 if (
auto rfit = retrieveFit(0)) {
1693 return fUfit = rfit;
1695 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1697 if (!nllVar->fFuncVars)
1698 nllVar->reinitialize();
1701 if (!readOnly && isExpected && fGenFit) {
1703 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1704 nllVar->get()->setAttribute(
"readOnly");
1705 auto out = ufit(
true);
1706 nllVar->get()->setAttribute(
"readOnly", tmp);
1711 nllVar->setData(
data());
1714 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1715 nllVar->setData(
fData);
1717 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1718 *nllVar->fFuncVars = *coords;
1719 if (nllVar->fFuncGlobs)
1720 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1721 std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))
1722 ->setAttribAll(
"Constant",
false);
1725 nllVar->fFuncVars->assignValueOnly(fGenFit->constPars());
1726 nllVar->fFuncVars->assignValueOnly(fGenFit->floatParsFinal());
1728 nllVar->get()->SetName(
1729 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1731 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1733 }
else if (!std::isnan(fAltVal())) {
1735 for (
auto _poiCoord : poi()) {
1736 auto _poi =
dynamic_cast<RooRealVar *
>(nllVar->fFuncVars->find(_poiCoord->GetName()));
1738 _poi->
setVal(_poi->getStringAttribute(
"initVal") ?
TString(_poi->getStringAttribute(
"initVal")).
Atof()
1743 return (fUfit = nllVar->minimize());
1749 for (
auto &
c : coll) {
1752 out +=
c->GetName();
1767 if (
auto rfit = retrieveFit(1)) {
1768 return fNull_cfit = rfit;
1770 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1772 if (!nllVar->fFuncVars)
1773 nllVar->reinitialize();
1776 if (!readOnly && isExpected && fGenFit) {
1778 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1779 nllVar->get()->setAttribute(
"readOnly");
1780 auto out = cfit_null(
true);
1781 nllVar->get()->setAttribute(
"readOnly", tmp);
1786 nllVar->setData(
data());
1789 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1790 nllVar->setData(
fData);
1794 *nllVar->fFuncVars = fUfit->floatParsFinal();
1796 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1797 *nllVar->fFuncVars = *coords;
1798 if (nllVar->fFuncGlobs)
1799 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1801 nllVar->fFuncVars->find(fPOIName())
1802 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
1804 nllVar->get()->SetName(
1805 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1807 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1809 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(poi()).c_str());
1810 return (fNull_cfit = nllVar->minimize());
1815 auto _first_poi =
dynamic_cast<RooRealVar *
>(poi().first());
1818 if (_first_poi->getMin(
"physical") <= _first_poi->getMin())
1821 return fLbound_cfit;
1822 if (
auto rfit = retrieveFit(6)) {
1823 return fLbound_cfit = rfit;
1825 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1827 if (!nllVar->fFuncVars)
1828 nllVar->reinitialize();
1831 if (!readOnly && isExpected && fGenFit) {
1833 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1834 nllVar->get()->setAttribute(
"readOnly");
1835 auto out = cfit_lbound(
true);
1836 nllVar->get()->setAttribute(
"readOnly", tmp);
1841 nllVar->setData(
data());
1844 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1845 nllVar->setData(
fData);
1849 *nllVar->fFuncVars = fUfit->floatParsFinal();
1851 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1852 *nllVar->fFuncVars = *coords;
1853 nllVar->fFuncVars->setRealValue(_first_poi->GetName(), _first_poi->getMin(
"physical"));
1854 if (nllVar->fFuncGlobs)
1855 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1857 nllVar->fFuncVars->find(fPOIName())
1858 ->setStringAttribute(
"altVal", (!std::isnan(fAltVal())) ?
TString::Format(
"%g", fAltVal()) :
nullptr);
1860 nllVar->get()->SetName(
1861 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1863 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1865 nllVar->get()->setStringAttribute(
1867 collectionContents(*std::unique_ptr<RooAbsCollection>(nllVar->fFuncVars->selectCommon(poi()))).c_str());
1868 return (fLbound_cfit = nllVar->minimize());
1873 if (std::isnan(fAltVal()))
1877 if (
auto rfit = retrieveFit(2)) {
1878 return fAlt_cfit = rfit;
1880 if (!nllVar || (readOnly && nllVar->get() && !nllVar->get()->getAttribute(
"readOnly")))
1882 if (!nllVar->fFuncVars)
1883 nllVar->reinitialize();
1886 if (!readOnly && isExpected && fGenFit) {
1888 bool tmp = nllVar->get()->getAttribute(
"readOnly");
1889 nllVar->get()->setAttribute(
"readOnly");
1890 auto out = cfit_alt(
true);
1891 nllVar->get()->setAttribute(
"readOnly", tmp);
1896 nllVar->setData(
data());
1899 }
else if (!nllVar->get()->getAttribute(
"readOnly")) {
1900 nllVar->setData(
fData);
1904 *nllVar->fFuncVars = fUfit->floatParsFinal();
1906 nllVar->fFuncVars->setAttribAll(
"Constant",
false);
1907 *nllVar->fFuncVars = *coords;
1908 if (nllVar->fFuncGlobs)
1909 nllVar->fFuncGlobs->setAttribAll(
"Constant",
true);
1910 *nllVar->fFuncVars = alt_poi();
1912 nllVar->get()->SetName(
1913 TString::Format(
"%s/%s_%s", nllVar->get()->GetName(), fGenFit->GetName(), (isExpected) ?
"asimov" :
"toys"));
1915 nllVar->get()->SetName(
TString::Format(
"%s/%s", nllVar->get()->GetName(),
fData.first->GetName()));
1917 nllVar->get()->setStringAttribute(
"fitresultTitle",
collectionContents(alt_poi()).c_str());
1918 return (fAlt_cfit = nllVar->minimize());
1924 auto asi = asimov(readOnly);
1927 return std::make_pair(std::numeric_limits<double>::quiet_NaN(), 0);
1930 auto out = asi->pll(readOnly);
1931 return std::make_pair(std::abs(fNullVal() - fAltVal()) / sqrt(out.first),
1932 out.second * 0.5 * std::abs(fNullVal() - fAltVal()) / (out.first * sqrt(out.first)));
1937 auto _ts = ts_toys(nSigma);
1938 if (std::isnan(_ts.first))
1941 return std::pair(1, 0);
1945 auto &_theToys = (alt) ? altToys : nullToys;
1947 if (_theToys.empty()) {
1948 return std::pair(0.5, std::numeric_limits<double>::infinity());
1955 double result_err_up = 0;
1956 double result_err_down = 0;
1957 for (
auto &toy : _theToys) {
1958 if (std::isnan(std::get<1>(toy)))
1961 bool res = std::get<1>(toy) >= _ts.first;
1962 if (std::get<2>(toy) != 1)
1967 result += std::get<2>(toy);
1968 if (std::get<1>(toy) >= _ts.first - _ts.second)
1969 result_err_up += std::get<2>(toy);
1970 if (std::get<1>(toy) >= _ts.first - _ts.second)
1971 result_err_down += std::get<2>(toy);
1976 result_err_down -=
result;
1977 double result_err = std::max(std::abs(result_err_up), std::abs(result_err_down));
1980 result_err /= _theToys.size();
1983 result /= (_theToys.size() - nans);
1987 return std::make_pair(
result, result_err);
1992 return pX_toys(
false, nSigma);
1997 if (!std::isnan(nSigma)) {
2000 return pX_toys(
true, nSigma);
2006 out.coords = coords;
2007 out.fPllType = fPllType;
2008 out.nllVar = nllVar;
2011 auto _cfit = cfit_null();
2014 if (!nllVar->fFuncVars)
2015 nllVar->reinitialize();
2019 out.fGenFit = _cfit;
2026 out.coords = coords;
2027 out.fPllType = fPllType;
2028 out.nllVar = nllVar;
2033 if (!nllVar->fFuncVars)
2034 nllVar->reinitialize();
2039 out.fGenFit = cfit_alt();
2044 bool targetCLs,
double relErrThreshold,
size_t maxToys)
2046 if ((alt && !cfit_alt()) || (!alt && !cfit_null())) {
2047 throw std::runtime_error(
"Cannot add toys, invalid conditional fit");
2050 auto condition = [&]() {
2053 auto obs = targetCLs ? pCLs_toys(target_nSigma) : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma));
2054 if (!std::isnan(obs.first)) {
2055 double diff = (
target < 0) ? obs.first : std::abs(obs.first -
target);
2056 double err = obs.second;
2057 if (err > 1
e-4 && diff <= relErrThreshold * obs.second) {
2061 auto pNull = pNull_toys(target_nSigma);
2062 auto pAlt = pAlt_toys(target_nSigma);
2065 alt = (pAlt.second * pNull.first > pNull.second * pAlt.first);
2066 if ((alt ? pAlt.second : pNull.second) < 1
e-4)
2075 if (!std::isnan(
target) && std::isnan(ts_toys(target_nSigma).
first)) {
2076 if (std::isnan(target_nSigma)) {
2077 throw std::runtime_error(
"Cannot target obs p-value because ts value unavailable");
2079 if (targetCLs && pCLs_toys(target_nSigma).second == 0) {
2085 Info(
"addToys",
"First generating 100 alt toys in order to determine expected ts value");
2086 addToys(
true, 100, initialSeed);
2088 if (std::isnan(ts_toys(target_nSigma).
first)) {
2089 throw std::runtime_error(
"Unable to determine expected ts value");
2108 size_t toysAdded(0);
2109 size_t altToysAdded(0);
2114 auto &toys = (alt) ? altToys : nullToys;
2115 if (toys.size() >= maxToys) {
2120 if (!std::isnan(
target) && !condition()) {
2123 auto currVal = std::isnan(
target) ? std::pair(0., 0.)
2124 : (targetCLs ? pCLs_toys(target_nSigma)
2125 : (alt ? pAlt_toys(target_nSigma) : pNull_toys(target_nSigma)));
2126 size_t nnToys = std::min(
size_t(nToys), (maxToys - toys.size()));
2128 for (
size_t i = 0; i < nnToys; i++) {
2130 auto toy = ((alt) ? generateAlt(seed) : generateNull(seed));
2133 toys.push_back(std::make_tuple(seed, toy.pll().first, 1.));
2135 (alt ? altToysAdded : toysAdded)++;
2136 if (std::isnan(std::get<1>(toys.back())))
2138 g->SetPoint(
g->GetN(),
g->GetN(), s.
RealTime() - lastTime);
2142 <<
TString::Format(
"Generated %d/%d %s hypothesis toys [%.2f toys/s]",
2143 int(alt ? altToysAdded : toysAdded),
int(nnToys), alt ?
"alt" :
"null",
2145 if (!std::isnan(
target)) {
2146 std::cout <<
" [current=" << currVal.first <<
"+/-" << currVal.second <<
" target=" <<
target
2147 <<
" nSigma=" << target_nSigma <<
"]";
2149 std::cout <<
"..." << std::flush;
2150 lasti = altToysAdded + toysAdded;
2165 for (
auto &t : toys) {
2166 if (std::isnan(std::get<1>(t)))
2167 std::get<1>(t) = -std::numeric_limits<double>::infinity();
2169 std::sort(toys.begin(), toys.end(),
2170 [](
const decltype(nullToys)::value_type &
a,
const decltype(nullToys)::value_type &
b) ->
bool {
2171 if (std::isnan(std::get<1>(a)))
2173 if (std::isnan(std::get<1>(b)))
2175 return std::get<1>(a) < std::get<1>(b);
2177 for (
auto &t : toys) {
2178 if (std::isinf(std::get<1>(t)))
2179 std::get<1>(t) = std::numeric_limits<double>::quiet_NaN();
2181 if (std::isnan(
target)) {
2188 }
while (condition());
2191 <<
"Finished Generating ";
2193 std::cout << toysAdded <<
" null ";
2196 std::cout << altToysAdded <<
" alt ";
2198 std::cout <<
"toys " <<
TString::Format(
"[%.2f toys/s overall]",
double(toysAdded + altToysAdded) / s2.
RealTime())
2203#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 30, 00)
2204 gPad->GetCanvas()->ResetUpdated();
2211 std::cout <<
"Warning: " << nans <<
" toys were bad" << std::endl;
2218 addToys(
false, nToys, seed,
target, target_nSigma);
2222 addToys(
true, nToys, seed,
target, target_nSigma);
2227 addToys(
false, nToys, seed,
target, target_nSigma,
true);
2288 out.nllVar = std::make_shared<xRooNLLVar>(*
this);
2293 while (pattern.NextToken()) {
2296 double val = std::numeric_limits<double>::quiet_NaN();
2297 auto i = s.
Index(
"=");
2302 throw std::runtime_error(
"poiValues must contain value");
2307 throw std::runtime_error(
"Cannot find poi");
2308 if (!std::isnan(val))
2311 if (poiNames !=
"") {
2316 if (poiNames ==
"") {
2317 throw std::runtime_error(
"No poi");
2319 if (!std::isnan(alt_value)) {
2320 std::unique_ptr<RooAbsCollection> thePoi(
fFuncVars->selectByName(poiNames));
2321 for (
auto b : *thePoi) {
2322 if (!
static_cast<RooRealVar *
>(
b)->hasRange(
"physical")) {
2323 static_cast<RooRealVar *
>(
b)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2327 auto _snap = std::unique_ptr<RooAbsCollection>(
fFuncVars->selectByAttrib(
"Constant",
true))->snapshot();
2328 _snap->setAttribAll(
"poi",
false);
2329 std::unique_ptr<RooAbsCollection> _poi(_snap->selectByName(poiNames));
2330 _poi->setAttribAll(
"poi",
true);
2331 if (std::isnan(alt_value)) {
2332 for (
auto a : *_poi)
2333 a->setStringAttribute(
"altVal", nullptr);
2335 for (
auto a : *_poi)
2336 a->setStringAttribute(
"altVal",
TString::
Format(
"%g", alt_value));
2339 _snap->remove(*
fGlobs,
true,
true);
2340 out.coords.reset(_snap);
2342 auto _type = pllType;
2345 if (std::isnan(alt_value))
2353 out.fPllType = _type;
2358xRooNLLVar::xRooHypoPoint
2364 std::unique_ptr<RooAbsCollection> _poi(
fFuncVars->selectByAttrib(
"poi",
true));
2365 if (_poi->empty()) {
2366 throw std::runtime_error(
"No POI specified in model");
2367 }
else if (_poi->size() != 1) {
2368 throw std::runtime_error(
"Multiple POI specified in model");
2370 return hypoPoint(_poi->first()->GetName(),
value, alt_value, pllType);
2382 if (!nllVar && !hypoTestResult)
2387 bool hasSame = sOpt.
Contains(
"same");
2392 TH1 *hAxis =
nullptr;
2394 auto clearPad = []() {
2396 if (
gPad->GetNumber() == 0) {
2404 if (!hasSame || !pad) {
2415 if (hAxis =
dynamic_cast<TH1 *
>(o); hAxis)
2422 double _min = std::numeric_limits<double>::quiet_NaN();
2423 double _max = -std::numeric_limits<double>::quiet_NaN();
2425 for (
auto &
p : nullToys) {
2426 if (std::get<2>(
p) == 0)
2428 if (std::isnan(std::get<1>(
p)))
2430 _min = std::min(std::get<1>(
p), _min);
2431 _max = std::max(std::get<1>(
p), _max);
2433 for (
auto &
p : altToys) {
2434 if (std::get<2>(
p) == 0)
2436 if (std::isnan(std::get<1>(
p)))
2438 _min = std::min(std::get<1>(
p), _min);
2439 _max = std::max(std::get<1>(
p), _max);
2443 if (!std::isnan(obs.first)) {
2444 _min = std::min(obs.first - std::abs(obs.first) * 0.1, _min);
2445 _max = std::max(obs.first + std::abs(obs.first) * 0.1, _max);
2448 auto pNull = pNull_toys();
2449 auto pAlt = pAlt_toys();
2450 auto pNullA = pNull_asymp();
2451 auto pAltA = pAlt_asymp();
2453 auto asi = (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit) ? fAsimov->pll().first
2454 : std::numeric_limits<double>::quiet_NaN();
2457 _min = std::min(asi - std::abs(asi), _min);
2458 _max = std::max(asi + std::abs(asi), _max);
2463 auto _poi =
dynamic_cast<RooRealVar *
>(poi().first());
2465 auto makeHist = [&](
bool isAlt) {
2467 auto h =
new TH1D((isAlt) ?
"alt_toys" :
"null_toys",
"", 100, _min, _max + (_max - _min) * 0.01);
2469 size_t nBadOrZero = 0;
2470 for (
auto &
p : (isAlt) ? altToys : nullToys) {
2471 double w = std::isnan(std::get<1>(
p)) ? 0 : std::get<2>(
p);
2474 if (!std::isnan(std::get<1>(
p)))
2475 h->Fill(std::get<1>(
p),
w);
2477 if (
h->GetEntries() > 0)
2478 h->Scale(1. /
h->Integral(0,
h->GetNbinsX() + 1));
2492 title +=
TString::Format(
"%s' = %g", fPOIName(), (isAlt) ? fAltVal() : fNullVal());
2493 title +=
TString::Format(
" , N_{toys}=%d",
int((isAlt) ? altToys.size() : nullToys.size()));
2502 h->SetMarkerSize(0);
2507 auto nullHist = makeHist(
false);
2508 auto altHist = makeHist(
true);
2511 auto h = (nullHist->GetEntries()) ? nullHist : altHist;
2514 auto axis =
static_cast<TH1 *
>(
h->Clone(
".axis"));
2516 axis->SetStats(
false);
2517 axis->Reset(
"ICES");
2519 axis->SetLineWidth(0);
2521 axis->SetMinimum(1
e-7);
2522 axis->GetYaxis()->SetRangeUser(1
e-7, 10);
2523 axis->SetMaximum(
h->GetMaximum());
2525 l =
new TLegend(0.4, 0.7, 1. -
gPad->GetRightMargin(), 1. -
gPad->GetTopMargin());
2526 l->SetName(
"legend");
2528 l->SetBorderSize(0);
2532 for (
auto o : *
gPad->GetListOfPrimitives()) {
2539 if (
h->GetEntries() > 0)
2542 h->Draw(
"axissame");
2544 if (
h->GetEntries() > 0)
2547 h->Draw(
"axissame");
2550 l->AddEntry(nullHist);
2551 l->AddEntry(altHist);
2554 if (fAsimov && fAsimov->fUfit && fAsimov->fNull_cfit && !std::isnan(sigma_mu().first) && !std::isnan(fAltVal())) {
2555 auto hh =
static_cast<TH1 *
>(nullHist->Clone(
"null_asymp"));
2557 hh->SetStats(
false);
2558 hh->SetLineStyle(2);
2560 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
2563 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2565 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2568 hh =
static_cast<TH1 *
>(altHist->Clone(
"alt_asymp"));
2570 hh->SetStats(
false);
2571 hh->SetLineStyle(2);
2573 for (
int i = 1; i <= hh->GetNbinsX(); i++) {
2576 _poi->getMin(
"physical"), _poi->getMax(
"physical")) -
2578 sigma_mu().first, _poi->getMin(
"physical"), _poi->getMax(
"physical")));
2593 l->AddEntry(tl, label,
"l");
2595 if (!std::isnan(pNull.first) || !std::isnan(pAlt.first)) {
2596 auto pCLs = pCLs_toys();
2597 label +=
" p_{toy}=(";
2598 label += (std::isnan(pNull.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNull.first, pNull.second);
2599 label += (std::isnan(pAlt.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAlt.first, pAlt.second);
2600 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2602 if (label.Length() > 0)
2603 l->AddEntry(
"", label,
"");
2605 if (!std::isnan(pNullA.first) || !std::isnan(pAltA.first)) {
2606 auto pCLs = pCLs_asymp();
2607 label +=
" p_{asymp}=(";
2608 label += (std::isnan(pNullA.first)) ?
"-" :
TString::Format(
"%.4f #pm %.4f", pNullA.first, pNullA.second);
2609 label += (std::isnan(pAltA.first)) ?
",-" :
TString::Format(
",%.4f #pm %.4f", pAltA.first, pAltA.second);
2610 label += (std::isnan(pCLs.first)) ?
",-)" :
TString::Format(
",%.4f #pm %.4f)", pCLs.first, pCLs.second);
2612 if (label.Length() > 0)
2613 l->AddEntry(
"", label,
"");
2615 if (
auto ax =
dynamic_cast<TH1 *
>(
gPad->GetPrimitive(
".axis")))
2616 ax->GetYaxis()->SetRangeUser(1
e-7, 1);
2621 auto v =
dynamic_cast<RooRealVar *
>(poi().empty() ? nullptr : poi().first());
2623 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity())
2632 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity())
2636 return (inWords) ?
TString::Format(
"-2log[L(%s,#hat{#hat{#theta}})/L(#hat{%s},#hat{#theta})]",
v->GetTitle(),
2642 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity())
2643 return (inWords) ?
TString::Format(
"Lower-Bound One-Sided Discovery PLR")
2651 if (
v &&
v->hasRange(
"physical") &&
v->getMin(
"physical") != -std::numeric_limits<double>::infinity())
2659 return "Test Statistic";
2665 return (poi().empty()) ? nullptr : (poi().first())->GetName();
2669 auto first_poi =
dynamic_cast<RooAbsReal *
>(poi().first());
2670 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
2674 auto _alt_poi = alt_poi();
2675 auto first_poi =
dynamic_cast<RooAbsReal *
>(_alt_poi.first());
2676 return (first_poi ==
nullptr) ? std::numeric_limits<double>::quiet_NaN() : first_poi->getVal();
2684 int tsType = nPoints;
2685 double alt_val = std::numeric_limits<double>::quiet_NaN();
2692 auto out =
hypoSpace(parName, pllType, alt_val);
2699 for (
auto p : out.poi()) {
2701 dynamic_cast<RooRealVar *
>(
p)->setRange(
"physical", 0, std::numeric_limits<double>::infinity());
2702 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [0,inf]",
p->
GetName());
2703 }
else if(
dynamic_cast<RooRealVar *
>(
p)->hasRange(
"physical")) {
2704 dynamic_cast<RooRealVar *
>(
p)->removeRange(
"physical");
2705 Info(
"xRooNLLVar::hypoSpace",
"Setting physical range of %s to [-inf,inf] (i.e. removed range)",
p->
GetName());
2720 if (
int(low + 0.5) > 0) {
2721 out.AddPoints(parName,
int(low + 0.5), high, alt_value);
2723 for (
auto p : out.poi()) {
2724 dynamic_cast<RooRealVar *
>(
p)->setRange(
"scan", high, alt_value);
2732 hs.
AddPoints(parName, nPoints, low, high);
2734 for (
auto p : hs.
poi()) {
2735 dynamic_cast<RooRealVar *
>(
p)->setRange(
"scan", low, high);
2744 auto _poi = std::unique_ptr<RooAbsCollection>(
2745 std::unique_ptr<RooAbsCollection>(
pdf()->getVariables())->selectByAttrib(
"poi",
true));
2747 throw std::runtime_error(
"You must specify a POI for the hypoSpace");
2748 return hypoSpace(_poi->first()->GetName(), nPoints, low, high, alt_value, pllType);
2757 if (strlen(parName)) {
2758 std::unique_ptr<RooAbsCollection> axes(s.
pars()->selectByName(parName));
2760 throw std::runtime_error(
"parameter not found");
2761 axes->setAttribAll(
"axis",
true);
2766 s.
fNlls[s.
fPdfs.begin()->second] = std::make_shared<xRooNLLVar>(*
this);
2769 for (
auto poi : s.
poi()) {
2770 poi->setStringAttribute(
"altVal", std::isnan(alt_value) ? nullptr :
TString::Format(
"%f", alt_value));
2778 if (hypoTestResult) {
2779 return *hypoTestResult;
2782 out.SetBackgroundAsAlt(
true);
2783 out.SetName(
TUUID().AsString());
2786 bool setReadonly =
false;
2787 if (nllVar && !nllVar->get()->getAttribute(
"readOnly")) {
2789 nllVar->get()->setAttribute(
"readOnly");
2792 auto ts_obs = ts_asymp();
2794 out.SetTestStatisticData(ts_obs.first);
2801 "pllType",
"test statistic type",
2802 {{
"TwoSided", 0}, {
"OneSidedPositive", 1}, {
"OneSidedNegative", 2}, {
"Uncapped", 3}, {
"Unknown", 4}}));
2804 fitMeta.
addClone(ufit()->floatParsFinal());
2813 {
"asimov_cfit_null", 4},
2815 {
"cfit_lbound", 6}}));
2820 auto fitDS =
new RooDataSet(
"fits",
"fit summary data", fitDetails);
2821 fitDS->convertToTreeStore();
2823 for (
int i = 0; i < 7; i++) {
2824 std::shared_ptr<const RooFitResult> fit;
2826 case 0: fit = ufit();
break;
2827 case 1: fit = cfit_null();
break;
2828 case 2: fit = cfit_alt();
break;
2829 case 3: fit = asimov() ? asimov()->ufit(
true) :
nullptr;
break;
2830 case 4: fit = asimov() ? asimov()->cfit_null(
true) :
nullptr;
break;
2831 case 5: fit = fGenFit;
break;
2832 case 6: fit = cfit_lbound();
break;
2842 fitDS->add(fitDetails);
2845 fitDS->setGlobalObservables(fitMeta);
2847 out.SetFitInfo(fitDS);
2855 auto nullToyDS =
new RooDataSet(
"nullToys",
"nullToys", nullDetails,
"weight");
2856 nullToyDS->setGlobalObservables(nullMeta);
2857 if (!nullToys.empty()) {
2859 std::vector<double> values;
2860 std::vector<double> weights;
2861 values.reserve(nullToys.size());
2862 weights.reserve(nullToys.size());
2864 for (
auto &t : nullToys) {
2865 values.push_back(std::get<1>(t));
2866 weights.push_back(std::get<2>(t));
2869 nullToyDS->add(nullDetails, std::get<2>(t));
2872#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2873 out.fNullPValue = pNull_toys().first;
2874 out.fNullPValueError =
2875 pNull_toys().second;
2877 out.SetNullPValue(pNull_toys().
first);
2878 out.SetNullPValueError(
2879 pNull_toys().second);
2882#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2883 out.fNullPValue = pNull_asymp().first;
2884 out.fNullPValueError = pNull_asymp().second;
2886 out.SetNullPValue(pNull_asymp().
first);
2887 out.SetNullPValueError(pNull_asymp().second);
2890 out.SetNullDetailedOutput(nullToyDS);
2892 if (!altToys.empty()) {
2893 std::vector<double> values;
2894 std::vector<double> weights;
2895 values.reserve(altToys.size());
2896 weights.reserve(altToys.size());
2902 auto altToyDS =
new RooDataSet(
"altToys",
"altToys", altDetails,
"weight");
2903 altToyDS->setGlobalObservables(altMeta);
2904 for (
auto &t : altToys) {
2905 values.push_back(std::get<1>(t));
2906 weights.push_back(std::get<2>(t));
2909 altToyDS->add(altDetails, std::get<2>(t));
2912 out.SetAltDetailedOutput(altToyDS);
2913#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2914 out.fAlternatePValue = pAlt_toys().first;
2915 out.fAlternatePValueError =
2918 out.SetAltPValue(pAlt_toys().
first);
2919 out.SetAltPValueError(
2920 pAlt_toys().second);
2924#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00)
2925 out.fAlternatePValue = pAlt_asymp().first;
2926 out.fAlternatePValueError = pAlt_asymp().second;
2928 out.SetAltPValue(pAlt_asymp().
first);
2929 out.SetAltPValueError(pAlt_asymp().second);
2934 nllVar->get()->setAttribute(
"readOnly",
false);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
void Info(const char *location, const char *msgfmt,...)
Use this function for informational messages.
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
winID h TVirtualViewer3D TVirtualGLPainter p
winID h TVirtualViewer3D vv
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t target
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t np
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t r
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t result
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t type
static char * Format(const char *format, va_list ap)
Format a string in a circular formatting buffer (using a printf style format descriptor).
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.
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 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.
RooAbsRealLValue is the common abstract base class for objects that represent a real value that may a...
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...
RooDataSet is a container class to hold unbinned data.
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
RooLinkedList is an collection class for internal use, storing a collection of RooAbsArg pointers in ...
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)
Class RooNLLVar implements a -log(likelihood) calculation from a dataset and a PDF.
static TRandom * randomGenerator()
Return a pointer to a singleton random-number generator implementation.
RooRealVar represents a 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.
RooStringVar is 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 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)