20#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00) 
   21#define protected public 
   69std::shared_ptr<RooLinkedList> xRooFit::sDefaultNLLOptions = 
nullptr;
 
   70std::shared_ptr<ROOT::Fit::FitConfig> xRooFit::sDefaultFitConfig = 
nullptr;
 
   72const char *xRooFit::GetVersion()
 
 
   76const char *xRooFit::GetVersionDate()
 
 
   83   return RooCmdArg(
"ReuseNLL", 
flag, 0, 0, 0, 
nullptr, 
nullptr, 
nullptr, 
nullptr);
 
 
   93   return RooCmdArg(
"StrategySequence", 0, 0, 0, 0, val);
 
 
  101xRooNLLVar xRooFit::createNLL(
const std::shared_ptr<RooAbsPdf> pdf, 
const std::shared_ptr<RooAbsData> 
data,
 
 
  109   return createNLL(std::shared_ptr<RooAbsPdf>(&pdf, [](
RooAbsPdf *) {}),
 
 
  127   return createNLL(pdf, 
data, 
l);
 
 
  130std::shared_ptr<const RooFitResult>
 
  132               const std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> &
data,
 
 
  140std::shared_ptr<const RooFitResult> xRooFit::fitTo(
RooAbsPdf &pdf,
 
  141                                                   const std::pair<RooAbsData *, const RooAbsCollection *> &
data,
 
 
  149std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>>
 
  153   std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooAbsCollection>> out;
 
  159   auto _allVars = std::unique_ptr<RooAbsCollection>(pdf.
getVariables());
 
  160   auto _snap = std::unique_ptr<RooAbsCollection>(_allVars->snapshot());
 
  161   *_allVars = fr->constPars();
 
  162   *_allVars = fr->floatParsFinal();
 
  165   auto _globs = std::unique_ptr<RooAbsCollection>(fr->constPars().selectByAttrib(
"global", 
true));
 
  176   std::function<std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooArgSet>>(
RooAbsPdf *)> 
genSubPdf;
 
  179      std::pair<std::shared_ptr<RooAbsData>, std::shared_ptr<const RooArgSet>> 
_out;
 
  182      std::unique_ptr<RooArgSet> _obs(_pdf->getVariables());
 
  183      _obs->remove(fr->constPars(), 
true, 
true);
 
  184      _obs->remove(fr->floatParsFinal(), 
true, 
true); 
 
  191         std::unique_ptr<RooArgSet> globs(_pdf->getObservables(t));
 
  197               *
toy_gobs = *std::unique_ptr<RooDataSet>(_pdf->generate(*globs, 1))->get();
 
  202                  for (
auto thePdf : pp->pdfList()) {
 
  203                     auto gob = std::unique_ptr<RooArgSet>(
thePdf->getObservables(*globs));
 
  206                     if (
gob->size() > 1) {
 
  207                        Warning(
"generate", 
"%s contains multiple global obs: %s", 
thePdf->GetName(),
 
  208                                gob->contentsString().c_str());
 
  212                     std::unique_ptr<RooArgSet> 
cpars(
thePdf->getParameters(*globs));
 
  225                           << 
"AsymptoticCalculator::MakeAsimovData:constraint term " << 
thePdf->GetName()
 
  226                           << 
" of type " << className << 
" is a non-supported type - result might be not correct " 
  234                        pois->setNoRounding(
true);
 
  245                              << 
"AsymptoticCalculator::MakeAsimovData:constraint term " << 
thePdf->GetName()
 
  246                              << 
" has no direct dependence on global observable- cannot generate it " << std::endl;
 
  266                              << 
"AsymptoticCalculator::MakeAsimovData:constraint term " << 
thePdf->GetName()
 
  267                              << 
" is a Gamma distribution and no server named theta is found. Assume that the Gamma " 
  275                            (!
rrv2->isConstant() || !
rrv2->InheritsFrom(
"RooConstVar"))) {
 
  280                                 << 
"AsymptoticCalculator::MakeAsimovData:constraint term " << 
thePdf->GetName()
 
  281                                 << 
" constraint term has more server depending on nuisance- cannot generate it " 
  297                           << 
"AsymptoticCalculator::MakeAsimovData - can't find nuisance for constraint term - global " 
  298                              "observables will not be set to Asimov value " 
  299                           << 
thePdf->GetName() << std::endl;
 
  300                        std::cerr << 
"Parameters: " << std::endl;
 
  302                        std::cerr << 
"Observables: " << std::endl;
 
  307                  Error(
"generate", 
"Cannot generate global observables, pdf is: %s::%s", _pdf->ClassName(),
 
  320         _out.first = std::make_unique<RooDataSet>(
 
  324         for (
auto &
c : s->indexCat()) {
 
  325#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 22, 00) 
  328            std::string 
cLabel = 
c->GetName();
 
  330            auto p = s->getPdf(
cLabel.c_str());
 
  336            _obs->setCatLabel(s->indexCat().GetName(), 
cLabel.c_str());
 
  337            for (
int i = 0; i < 
toy.first->numEntries(); i++) {
 
  338               *_obs = *
toy.first->get(i);
 
  339               _out.first->add(*_obs, 
toy.first->weight());
 
  345      std::map<RooRealVar *, std::shared_ptr<RooAbsBinning>> 
binnings;
 
  347      for (
auto &o : *_obs) {
 
  351         if (
auto res = _pdf->binBoundaries(*
r, -std::numeric_limits<double>::infinity(),
 
  352                                            std::numeric_limits<double>::infinity())) {
 
  353            binnings[
r] = std::shared_ptr<RooAbsBinning>(
r->getBinning().clone(
r->getBinning().GetName()));
 
  355            std::vector<double> boundaries;
 
  356            boundaries.reserve(res->size());
 
  357            for (
auto &
rr : *res) {
 
  358               if (boundaries.empty() || std::abs(boundaries.back() - 
rr) > 1
e-3 ||
 
  359                   std::abs(boundaries.back() - 
rr) > 1
e-5 * boundaries.back())
 
  360                  boundaries.push_back(
rr);
 
  362            r->setBinning(
RooBinning(boundaries.size() - 1, &boundaries[0]));
 
  364         } 
else if (
r->numBins(
r->getBinning().GetName()) == 0 && 
expected) {
 
  366            binnings[
r] = std::shared_ptr<RooAbsBinning>(
r->getBinning().clone(
r->getBinning().GetName()));
 
  380         if (_pdf->canBeExtended()) {
 
  398         auto binning = 
b.second;
 
  399         v->setBinning(*binning);
 
  403         auto r = 
x->getRange();
 
  404         if (
r.first > binning->lowBound())
 
  405            x->setMin(binning->lowBound());
 
  406         if (
r.second < binning->highBound())
 
  407            x->setMax(binning->highBound());
 
  413   out.first->SetName(
expected ? (
TString(fr->GetName()) + 
"_asimov") : uuid);
 
  417      out.first->setGlobalObservables(*out.second);
 
  421#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 26, 00) 
  424      w->setStringAttribute(
"fitResult", fr->GetName());
 
  435#if ROOT_VERSION_CODE < ROOT_VERSION(6, 27, 00) 
  436   auto _ws = pdf.
_myws;
 
  443      for (
auto obj : _ws->components()) {
 
  444         for (
int i = 0; i < obj->numCaches(); i++) {
 
  450            p->setNormRange(
p->normRange());
 
  452         obj->setValueDirty();
 
 
  460std::shared_ptr<RooLinkedList> xRooFit::createNLLOptions()
 
  466   for (
auto opt : *defaultNLLOptions()) {
 
  467      out->Add(opt->Clone(
nullptr)); 
 
 
  473std::shared_ptr<RooLinkedList> xRooFit::defaultNLLOptions()
 
  475   if (sDefaultNLLOptions)
 
  476      return sDefaultNLLOptions;
 
  484   return sDefaultNLLOptions;
 
 
  487std::shared_ptr<ROOT::Fit::FitConfig> xRooFit::createFitConfig()
 
  489   return std::make_shared<ROOT::Fit::FitConfig>(*defaultFitConfig());
 
 
  492std::shared_ptr<ROOT::Fit::FitConfig> xRooFit::defaultFitConfig()
 
  494   if (sDefaultFitConfig)
 
  495      return sDefaultFitConfig;
 
  496   sDefaultFitConfig = std::make_shared<ROOT::Fit::FitConfig>();
 
  497   auto &fitConfig = *sDefaultFitConfig;
 
  498   fitConfig.SetParabErrors(
true); 
 
  499   fitConfig.MinimizerOptions().SetMinimizerType(
"Minuit2");
 
  500   fitConfig.MinimizerOptions().SetErrorDef(0.5); 
 
  501   fitConfig.SetParabErrors(
true);                
 
  502   fitConfig.SetMinosErrors(
true); 
 
  503   fitConfig.MinimizerOptions().SetMaxFunctionCalls(
 
  505   fitConfig.MinimizerOptions().SetMaxIterations(-1); 
 
  506   fitConfig.MinimizerOptions().SetStrategy(-1);      
 
  510   fitConfig.MinimizerOptions().SetPrintLevel(-2);
 
  516#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 29, 00) 
  517   extraOpts->SetValue(
"StrategySequence", 
"0s01s12s2s3m");
 
  518   extraOpts->SetValue(
"HesseStrategySequence", 
"23");
 
  520   extraOpts->SetValue(
"StrategySequence", 
"0s01s12s2m");
 
  521   extraOpts->SetValue(
"HesseStrategySequence", 
"2");
 
  529   extraOpts->SetValue(
"TrackProgress", 30);               
 
  536   return sDefaultFitConfig;
 
 
  541   return const_cast<ROOT::Math::IOptions *
>(defaultFitConfig()->MinimizerOptions().ExtraOptions());
 
 
  552         std::cout << 
"Minimization interrupted ... will exit as soon as possible" << std::endl;
 
 
  569      vars.reset(std::unique_ptr<RooAbsCollection>(
f.getVariables())->selectByAttrib(
"Constant", 
false));
 
 
  606         throw std::runtime_error(
"Keyboard interrupt");
 
  607         return std::numeric_limits<double>::quiet_NaN();
 
  610      if (
prevMin == std::numeric_limits<double>::infinity()) {
 
  614      if (!std::isnan(out)) {
 
  626         std::stringstream 
sout;
 
  646            std::vector<std::pair<double, std::string>> 
parDeltas;
 
  649               parDeltas.emplace_back(std::pair<double, std::string>(
 
  653                      [](
auto &left, 
auto &right) { return std::abs(left.first) > std::abs(right.first); });
 
  655            for (i = 0; i < std::min(3, 
int(
parDeltas.size())); i++) {
 
  669         if (
gROOT->FromPopUp() && 
gROOT->GetListOfBrowsers()->At(0)) {
 
  671            std::string status = 
sout.str();
 
  675               if (status.find(
" : ") != std::string::npos) {
 
  676                  status_part = status.substr(0, status.find(
" : "));
 
  677                  status = status.substr(status.find(
" : ") + 3);
 
  687         std::cerr << 
sout.str() << std::endl;
 
 
  703   mutable double minVal = std::numeric_limits<double>::infinity();
 
  704   mutable double prevMin = std::numeric_limits<double>::infinity();
 
  710   std::shared_ptr<RooAbsCollection> 
vars;
 
 
  723                                                      const std::shared_ptr<ROOT::Fit::FitConfig> &
_fitConfig,
 
  724                                                      const std::shared_ptr<RooLinkedList> &
nllOpts)
 
  739   if (nll.getStringAttribute(
"userPars")) {
 
  741      while (
st.NextToken()) {
 
  752   auto _nllVars = std::unique_ptr<RooAbsCollection>(_nll->getVariables());
 
  754   std::unique_ptr<RooAbsCollection> constPars(
_nllVars->selectByAttrib(
"Constant", 
true));
 
  756   std::unique_ptr<RooAbsCollection> 
floatPars(
_nllVars->selectByAttrib(
"Constant", 
false));
 
  763#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 29, 00) 
  768   if (fitConfig.MinimizerOptions().ExtraOptions()) {
 
  769      fitConfig.MinimizerOptions().ExtraOptions()->GetNamedValue(
"StrategySequence", s);
 
  770      fitConfig.MinimizerOptions().ExtraOptions()->GetIntValue(
"TrackProgress", 
_progress);
 
  771      fitConfig.MinimizerOptions().ExtraOptions()->GetRealValue(
"BoundaryCheck", 
boundaryCheck);
 
  772      fitConfig.MinimizerOptions().ExtraOptions()->GetIntValue(
"LogSize", 
logSize);
 
  773      fitConfig.MinimizerOptions().ExtraOptions()->GetIntValue(
"HesseStrategy", 
hesseStrategy);
 
  774      fitConfig.MinimizerOptions().ExtraOptions()->GetNamedValue(
"HesseStrategySequence", 
hs);
 
  785         if (
auto keys = 
nllDir->GetListOfKeys(); keys) {
 
  786            for (
auto &&k : *keys) {
 
  788               if (cl->InheritsFrom(
"RooFitResult")) {
 
  805                        for (
auto &
p : *constPars) {
 
  812                                     _p->getCurrentIndex() != 
c->getCurrentIndex()) {
 
  824                              if (!_p->getAttribute(
"global") && std::abs(_p->getVal() - 
v->getVal()) > 1
e-12) {
 
  847   if (nll.getAttribute(
"readOnly"))
 
  850   int printLevel = fitConfig.MinimizerOptions().PrintLevel();
 
  856   if (
floatPars->empty() || fitConfig.MinimizerOptions().MaxFunctionCalls() == 1) {
 
  857      std::shared_ptr<RooFitResult> 
result;
 
  861      result = std::make_shared<RooFitResult>(); 
 
  869      result->setCovarianceMatrix(
d);
 
  871      result->setMinNLL(_nll->getVal());
 
  881         if (!
cacheDir->GetDirectory(nll.GetName()))
 
  883         if (
auto dir = 
cacheDir->GetDirectory(nll.GetName()); dir) {
 
  889               if (!dir->FindKey(
nllOpts->GetName())) {
 
  902   std::shared_ptr<RooFitResult> out;
 
  907      if (
p->isCategory()) {
 
  916      std::shared_ptr<const RooFitResult> 
bestFr;
 
  917      for (
auto c : allCats) {
 
  919         Info(
"minimize", 
"Minimizing with discrete %s", 
c.first.c_str());
 
  922            Warning(
"minimize", 
"Minimization with discrete %s failed", 
c.first.c_str());
 
  930      floatCats.setAttribAll(
"Constant", 
false);
 
  936      out = std::make_shared<RooFitResult>(*
bestFr);
 
  937      const_cast<RooArgList &
>(out->floatParsFinal())
 
  938         .addClone(*std::unique_ptr<RooAbsCollection>(out->constPars().selectCommon(
floatCats)));
 
  944   bool restore = !fitConfig.UpdateAfterFit();
 
  945   bool minos = fitConfig.MinosErrors();
 
  948      int strategy = fitConfig.MinimizerOptions().Strategy();
 
  956      _minimizer.
fitter()->Config() = fitConfig;
 
  968      bool autoMaxCalls = (_minimizer.
fitter()->Config().MinimizerOptions().MaxFunctionCalls() == 0);
 
  970         _minimizer.
fitter()->Config().MinimizerOptions().SetMaxFunctionCalls(
 
  973      if (_minimizer.
fitter()->Config().MinimizerOptions().MaxIterations() == 0) {
 
  974         _minimizer.
fitter()->Config().MinimizerOptions().SetMaxIterations(500 * 
floatPars->size());
 
  977      bool hesse = _minimizer.
fitter()->Config().ParabErrors();
 
  978      _minimizer.
fitter()->Config().SetParabErrors(
 
  980      _minimizer.
fitter()->Config().SetMinosErrors(
false);
 
  981      _minimizer.
fitter()->Config().SetUpdateAfterFit(
true); 
 
  993      _minimizer.
fitter()->Config().MinimizerOptions().ExtraOptions()->GetValue(
"OptimizeConst", 
constOptimize);
 
 1015      if (
minim == 
"Minuit2") {
 
 1022            Warning(
"minimize", 
"Strategy %d not specified in StrategySequence %s ... defaulting to start of sequence",
 
 1026      } 
else if (
minim == 
"Minuit")
 
 1035            algo = 
"migradImproved";
 
 1047            fff->fState = 
minim + 
algo + std::to_string(_minimizer.
fitter()->Config().MinimizerOptions().Strategy());
 
 1051         } 
catch (
const std::exception &
e) {
 
 1052            std::cerr << 
"Exception while minimizing: " << 
e.what() << std::endl;
 
 1061            throw std::runtime_error(
"Keyboard interrupt while minimizing");
 
 1065         status = _minimizer.
fitter()
 
 1068         minim = _minimizer.
fitter()->Config().MinimizerType(); 
 
 1070                                       _minimizer.
fitter()->Config().MinimizerAlgoType() +
 
 1071                                       std::to_string(_minimizer.
fitter()->Config().MinimizerOptions().Strategy()),
 
 1073         if (status % 1000 == 0)
 
 1076         if (status == 4 && 
minim != 
"Minuit") {
 
 1078               Warning(
"fitTo", 
"%s Hit max function calls of %d", 
fitName.Data(),
 
 1079                       _minimizer.
fitter()->Config().MinimizerOptions().MaxFunctionCalls());
 
 1083                  Warning(
"fitTo", 
"will try doubling this");
 
 1084               _minimizer.
fitter()->Config().MinimizerOptions().SetMaxFunctionCalls(
 
 1085                  _minimizer.
fitter()->Config().MinimizerOptions().MaxFunctionCalls() * 2);
 
 1086               _minimizer.
fitter()->Config().MinimizerOptions().SetMaxIterations(
 
 1087                  _minimizer.
fitter()->Config().MinimizerOptions().MaxIterations() * 2);
 
 1096            Warning(
"fitTo", 
"%s %s%s Status=%d (edm=%f, tol=%f, strat=%d), tries=#%d...", 
fitName.Data(),
 
 1097                    _minimizer.
fitter()->Config().MinimizerType().c_str(),
 
 1098                    _minimizer.
fitter()->Config().MinimizerAlgoType().c_str(), status,
 
 1099                    _minimizer.
fitter()->Result().Edm(), _minimizer.
fitter()->Config().MinimizerOptions().Tolerance(),
 
 1100                    _minimizer.
fitter()->Config().MinimizerOptions().Strategy(), 
tries);
 
 1124         Warning(
"fitTo", 
"%s final status is %d", 
fitName.Data(), status);
 
 1133      int miniStrat = _minimizer.
fitter()->Config().MinimizerOptions().Strategy();
 
 1134      double dCovar = std::numeric_limits<double>::quiet_NaN();
 
 1172                    "HesseStrategy %d not specified in HesseStrategySequence %s ... defaulting to start of sequence",
 
 1176         while (
sIdx != -1) {
 
 1181               if (_minimizer.
fitter()->GetMinimizer()->CovMatrixStatus() == 3) {
 
 1197               fff->counter2 = 
fff->counter;
 
 1205            auto _status = _minimizer.
hesse(); 
 
 1233               throw std::runtime_error(
"Keyboard interrupt while hesse calculating");
 
 1235            if ((_status != 0 || _minimizer.
fitter()->GetMinimizer()->CovMatrixStatus() != 3) && status == 0 &&
 
 1237               Warning(
"fitTo", 
"%s hesse status is %d, covQual=%d", 
fitName.Data(), _status,
 
 1238                       _minimizer.
fitter()->GetMinimizer()->CovMatrixStatus());
 
 1245            if (_status == 0 && _minimizer.
fitter()->GetMinimizer()->CovMatrixStatus() == 3) {
 
 1248            } 
else if (_status == 0) {
 
 1257      if (status == 0 && 
minos) {
 
 1258         if (std::unique_ptr<RooAbsCollection> 
mpars(
floatPars->selectByAttrib(
"minos", 
true)); !
mpars->empty()) {
 
 1260               fff->fState = 
"Minos";
 
 1277      if (out->status() == 0 && out->covQual() != 3 && hesse) {
 
 1278         if (out->covQual() == 2) { 
 
 1286      if(
miniStrat < _minimizer.
fitter()->Config().MinimizerOptions().Strategy() && hesse && out->edm() > _minimizer.
fitter()->Config().MinimizerOptions().Tolerance()*1
e-3 && out->status() != 3) {
 
 1289         std::cerr << 
"Warning: post-Hesse edm greater than allowed by tolerance. Consider increasing minimization strategy" << std::endl;
 
 1300      if (!std::isnan(
dCovar)) {
 
 1302            .addClone(
RooRealVar(
".dCovar", 
"dCovar from minimization", 
dCovar), 
true);
 
 1313            double vRange = 
v->getMax() - 
v->getMin();
 
 1319               auto tmp = 
v->getVal();
 
 1320               v->setVal(
v->getMin());
 
 1323                  static_cast<RooRealVar *
>(out->floatParsFinal().find(
v->GetName()))->
setVal(
v->getMin());
 
 1332               if (
v->hasRange(
"physical"))
 
 1337                       (
v->getMin() > 
v->getVal() - 
v->getError() || 
v->getMax() < 
v->getVal() + 
v->getError())) {
 
 1339                  Info(
"minimize", 
"PARLIM: %s (%f +/- %f) range (%f - %f)", 
v->GetName(), 
v->getVal(), 
v->getError(),
 
 1340                       v->getMin(), 
v->getMax());
 
 1347               Warning(
"minimize", 
"BOUNDCHK: Parameters within %g%% limit in fit result: %s", 
boundaryCheck * 100,
 
 1352               Warning(
"minimize", 
"BOUNDCHK: Parameters near limit in fit result");
 
 1384      out->setMinNLL(_nll->getVal());
 
 1387      for (
auto o : out->floatParsFinal()) {
 
 1389             v && !
v->
getAttribute(
"minos") && !
v->getAttribute(
"xminos") && !
v->getAttribute(
"xMinos"))
 
 1390            v->removeAsymError();
 
 1403   if(out && out->status() == 0 && 
minos) {
 
 1405      for (
auto label : {
"xminos", 
"xMinos"}) {
 
 1406         std::unique_ptr<RooAbsCollection> pars(
floatPars->selectByAttrib(label, 
true));
 
 1407         for (
auto p : *pars) {
 
 1408            Info(
"minimize", 
"Computing xminos error for %s", 
p->GetName());
 
 1420   if (out && !
logs.empty()) {
 
 1422#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 28, 00) 
 1423      const_cast<RooArgList &
>(out->constPars()).addOwned(std::make_unique<RooStringVar>(
".log", 
"log", 
logs.c_str()));
 
 1432      if (!
cacheDir->GetDirectory(nll.GetName()))
 
 1434      if (
auto dir = 
cacheDir->GetDirectory(nll.GetName()); dir) {
 
 1440            if (!dir->FindKey(
nllOpts->GetName())) {
 
 1447         if (!fitConfig.MinimizerOptions().ExtraOptions()->GetValue(
"Name", 
configName)) {
 
 1453            dir->WriteObject(&fitConfig, 
configName.data());
 
 1456#if ROOT_VERSION_CODE >= ROOT_VERSION(6, 28, 00) 
 1458            .addOwned(std::make_unique<RooStringVar>(
".fitConfigName", 
"fitConfigName", 
configName.c_str()));
 
 1463         dir->WriteObject(out.get(), out->GetName());
 
 
 1477                   const std::shared_ptr<ROOT::Fit::FitConfig> &
_fitConfig)
 
 1480   auto par = 
dynamic_cast<RooRealVar *
>(std::unique_ptr<RooArgSet>(nll.getVariables())->find(
parName));
 
 1491   bool pErrs = fitConfig.ParabErrors();
 
 1492   fitConfig.SetParabErrors(
false);
 
 1493   double mErrs = fitConfig.MinosErrors();
 
 1494   fitConfig.SetMinosErrors(
false);
 
 1503   bool isConst = par->isConstant();
 
 1504   par->setConstant(
true);
 
 1526            return std::numeric_limits<double>::quiet_NaN();
 
 1529         status += 
result->status() * 10;
 
 1535            std::cout << 
"Warning: Alternative best-fit of " << par->GetName() << 
" @ " << 
val_guess << 
" vs " 
 1536                      << 
val_best << 
" (delta=" << tmu / 2. << 
")" << std::endl;
 
 1542            status = (status / 10) * 10 + 1;
 
 1555            std::cout << 
"NLL min: " << 
nll_min << std::endl;
 
 1556            std::cout << 
"N_sigma*sigma(pre):   " << std::abs(
val_pre - 
val_best) << std::endl;
 
 1557            std::cout << 
"sigma(guess):   " << 
sigma_guess << std::endl;
 
 1558            std::cout << 
"par(guess):     " << 
val_guess + 
corr << std::endl;
 
 1559            std::cout << 
"true val:       " << 
val_best << std::endl;
 
 1560            std::cout << 
"tmu:            " << tmu << std::endl;
 
 1561            std::cout << 
"Precision:      " << 
sigma_guess * precision << std::endl;
 
 1562            std::cout << 
"Correction:     " << (-
corr < 0 ? 
" " : 
"") << -
corr << std::endl;
 
 1563            std::cout << 
"N_sigma*sigma(guess): " << std::abs(
val_guess - 
val_best) << std::endl;
 
 1564            std::cout << std::endl;
 
 1589            status = (status / 10) * 10 + 3;
 
 1597         status = (status / 10) * 10 + 2;
 
 1601         status = (status / 10) * 10 + 2;
 
 1607         std::cout << 
"Finished in " << 
nrItr << 
" iterations." << std::endl;
 
 1609         std::cout << std::endl;
 
 1615   par_hat->setError(std::numeric_limits<double>::quiet_NaN());
 
 1616   double lo = 
par_hat->getErrorLo();
 
 1618   if (std::isnan(
hi)) {
 
 1624   if (std::isnan(lo)) {
 
 1631   fitConfig.SetParabErrors(
pErrs);
 
 1632   fitConfig.SetMinosErrors(
mErrs);
 
 
 1653   std::deque<RooAbsArg *> 
topPdfs;
 
 1655   for (
auto p : 
w.allPdfs()) {
 
 1656      if (
p->hasClients())
 
 1659      if (
p->getAttribute(
"hypoTest")) {
 
 1666      Error(
"hypoTest", 
"Cannot find top-level pdf in workspace");
 
 1668   } 
else if (
topPdfs.size() > 1) {
 
 1671         Error(
"hypoTest", 
"Multiple top-level pdfs. Flag which one to test with " 
 1672                           "w->pdf(\"pdfName\")->setAttribute(\"hypoTest\",true)");
 
 1675         Error(
"hypoTest", 
"Multiple top-level pdfs flagged for hypoTest -- pick one.");
 
 1681   Info(
"hypoTest", 
"Using PDF: %s", model->
GetName());
 
 1687   std::shared_ptr<RooArgSet> 
obsGlobs = 
nullptr;
 
 1689   for (
auto p : 
w.allData()) {
 
 1691         Error(
"hypoTest", 
"Multiple datasets in workspace. Flag which one to test with " 
 1692                           "w->data(\"dataName\")->setAttribute(\"hypoTest\",true)");
 
 1699      Error(
"hypoTest", 
"No data -- cannot determine observables");
 
 1703   Info(
"hypoTest", 
"Using Dataset: %s", 
obsData->GetName());
 
 1706      auto _globs = xRooNode(
w).datasets()[
obsData->GetName()]->globs(); 
 
 1707      obsGlobs = std::make_shared<RooArgSet>();
 
 1709      Info(
"hypoTest", 
"Using Globs: %s", (
obsGlobs->empty()) ? 
" <NONE>" : 
obsGlobs->contentsString().c_str());
 
 1714   auto _vars = std::unique_ptr<RooArgSet>(model->
getVariables());
 
 1717   for (
auto _v : *_vars) {
 
 1722   if (poi.
size() > 1) {
 
 1727   if (!args.
empty()) {
 
 1731      Error(
"hypoTest", 
"No POI detected: add the hypoPoints binning to at least one non-const model parameter e.g.:\n " 
 1732                        "w->var(\"mu\")->setBinning(RooUniformBinning(0.5,10.5,10),\"hypoPoints\"))");
 
 1738   TCanvas::MakeDefCanvas();
 
 1745   nll.SetFitConfig(fitConfig);
 
 1747   if (poi.
size() == 1) {
 
 1750      double altVal = (mu->getStringAttribute(
"altVal")) ? 
TString(mu->getStringAttribute(
"altVal")).Atof()
 
 1751                                                         : std::numeric_limits<double>::quiet_NaN();
 
 1753      if (std::isnan(
altVal) && mu->hasRange(
"physical")) {
 
 1755         altVal = mu->getMin(
"physical");
 
 1756         Info(
"hypoTest", 
"No altVal specified - using min of given physical range = %g", 
altVal);
 
 1758         if (!std::isnan(
altVal)) {
 
 1759            Info(
"hypoTest", 
"alt hypo: %g - CLs activated", 
altVal);
 
 1761            Info(
"hypoTest", 
"No altVal found - to specify setStringAttribute(\"altVal\",\"<value>\") on POI or set " 
 1762                             "the physical range");
 
 1765      bool doCLs = !std::isnan(
altVal) && std::abs(mu->getMin(
"hypoPoints")) > 
altVal &&
 
 1766                   std::abs(mu->getMax(
"hypoPoints")) > 
altVal;
 
 1768      const char *
sCL = (
doCLs) ? 
"CLs" : 
"null";
 
 1769      Info(
"hypoTest", 
"%s testing active", 
sCL);
 
 1779      std::vector<int> 
expSig = {-2, -1, 0, 1, 2};
 
 1782      std::map<int, TGraphErrors> 
exp_pcls;
 
 1783      std::map<int, TGraphErrors> 
exp_cls;
 
 1792         double _out = std::numeric_limits<double>::quiet_NaN();
 
 1794         for (
int i = 0; i < 
pValues.GetN(); i++) {
 
 1800                                                    ((1. - 
CL) - 
pValues.GetPointY(i - 1)) /
 
 1820                                 (
doCLs) ? 
hp.pCLs_asymp(s).first : 
hp.pNull_asymp(s).first);
 
 1823            Info(
"hypoTest", 
"%s=%g: %s=%g sigma_mu=%g %s=%g", mu->GetName(), 
testVal, 
obs_ts->GetName(),
 
 1827            Info(
"hypoTest", 
"%s=%g: %s=%g %s=%g", mu->GetName(), 
testVal, 
obs_ts->GetName(),
 
 1832      if (mu->getBins(
"hypoPoints") <= 0) {
 
 1837         testPoint((mu->getMax(
"hypoPoints") + mu->getMin(
"hypoPoints")) / 2.);
 
 1861         for (
int i = 0; i <= mu->getBins(
"hypoPoints"); i++) {
 
 1862            testPoint((i == mu->getBins(
"hypoPoints")) ? mu->getBinning(
"hypoPoints").binHigh(i - 1)
 
 1863                                                       : mu->getBinning(
"hypoPoints").binLow(i));
 
 1875         band2->SetNameTitle(
".pCLs_2sigma", 
"2 sigma band");
 
 1877         band2up->SetNameTitle(
".pCLs_2sigma_upUncert", 
"");
 
 1879         band2down->SetNameTitle(
".pCLs_2sigma_downUncert", 
"");
 
 1885         for (
int i = 0; i < 
exp_pcls[2].GetN(); i++) {
 
 1891         for (
int i = 
exp_pcls[2].GetN() - 1; i >= 0; i--) {
 
 1895         for (
int i = 0; i < 
exp_pcls[-2].GetN(); i++) {
 
 1899         for (
int i = 
exp_pcls[-2].GetN() - 1; i >= 0; i--) {
 
 1918         band2->SetNameTitle(
".pCLs_1sigma", 
"1 sigma band");
 
 1920         band2up->SetNameTitle(
".pCLs_1sigma_upUncert", 
"");
 
 1922         band2down->SetNameTitle(
".pCLs_1sigma_downUncert", 
"");
 
 1928         for (
int i = 0; i < 
exp_pcls[1].GetN(); i++) {
 
 1934         for (
int i = 
exp_pcls[1].GetN() - 1; i >= 0; i--) {
 
 1938         for (
int i = 0; i < 
exp_pcls[-1].GetN(); i++) {
 
 1942         for (
int i = 
exp_pcls[-1].GetN() - 1; i >= 0; i--) {
 
 1964      obs_pcls->Draw(
gPad->GetListOfPrimitives()->IsEmpty() ? 
"ALP" : 
"LP");
 
 1971      auto l = 
new TLegend(0.5, 0.6, 1. - 
gPad->GetRightMargin(), 1. - 
gPad->GetTopMargin());
 
 1972      l->SetName(
"legend");
 
 1976         l->AddEntry(
expPlot, 
"Expected", 
"LFE");
 
 1984         exp_cls[s].SetMarkerStyle(29);
 
 1985         exp_cls[s].SetEditable(
false);
 
 2000   double factor = pow(10.0, 
digits - ceil(log10(std::abs(
value))));
 
 2001   return std::round(
value * factor) / factor;
 
 
 2013   if (!std::isinf(out.second)) {
 
 2014      auto tmp = out.second;
 
 2016      int expo = (out.second == 0) ? 0 : (
int)std::floor(std::log10(std::abs(out.second)));
 
 2020      } 
else if (out.second != 0) {
 
 
static void indent(ostringstream &buf, int indent_level)
 
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
 
void Error(const char *location, const char *msgfmt,...)
Use this function in case an error occurred.
 
void Warning(const char *location, const char *msgfmt,...)
Use this function in warning situations.
 
winID h TVirtualViewer3D TVirtualGLPainter p
 
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
 
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
 
R__EXTERN TSystem * gSystem
 
double getValV(const RooArgSet *) const override
Return value of object.
 
double evaluate() const override
Evaluate this PDF / function / constant. Needs to be overridden by all derived classes.
 
bool setData(RooAbsData &data, bool cloneData) override
 
ProgressMonitor(const ProgressMonitor &other, const char *name=nullptr)
 
~ProgressMonitor() override
 
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Interface for detailed printing of object.
 
TObject * clone(const char *newname) const override
 
std::shared_ptr< RooAbsCollection > vars
 
bool getParameters(const RooArgSet *observables, RooArgSet &outputSet, bool stripDisconnected) const override
Fills a list with leaf nodes in the arg tree starting with ourself as top node that don't match any o...
 
void applyWeightSquared(bool flag) override
Disables or enables the usage of squared weights.
 
void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt) override
Interface function signaling a request to perform constant term optimization.
 
ProgressMonitor(RooAbsReal &f, int interval=30)
 
static ProgressMonitor * me
 
double defaultErrorLevel() const override
 
static void interruptHandler(int signum)
 
StoredFitResult(RooFitResult *_fr)
 
std::shared_ptr< RooFitResult > fr
 
static int minos(RooAbsReal &nll, const RooFitResult &ufit, const char *parName="", const std::shared_ptr< ROOT::Fit::FitConfig > &_fitConfig=nullptr)
 
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::shared_ptr< RooLinkedList > createNLLOptions()
 
static TCanvas * hypoTest(RooWorkspace &w, const xRooFit::Asymptotics::PLLType &pllType=xRooFit::Asymptotics::Unknown)
 
static std::shared_ptr< ROOT::Fit::FitConfig > createFitConfig()
 
static std::pair< double, double > matchPrecision(const std::pair< double, double > &in)
 
This xRooNLLVar object has several special methods, e.g.
 
xRooFitResult minimize(const std::shared_ptr< ROOT::Fit::FitConfig > &=nullptr)
 
Class describing the configuration of the fit, options and parameter settings using the ROOT::Fit::Pa...
 
class implementing generic options for a numerical algorithm Just store the options in a map of strin...
 
Generic interface for defining configuration options of a numerical algorithm.
 
const_iterator begin() const
 
const_iterator end() const
 
Common abstract base class for objects that represent a value and a "shape" in RooFit.
 
RooWorkspace * _myws
Prevent 'AlwaysDirty' mode for this node.
 
RooFit::OwningPtr< RooArgSet > getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
 
RooWorkspace * workspace() const
 
virtual void constOptimizeTestStatistic(ConstOpCode opcode, bool doAlsoTrackingOpt=true)
Interface function signaling a request to perform constant term optimization.
 
bool getAttribute(const Text_t *name) const
Check if a named attribute is set. By default, all attributes are unset.
 
RooFit::OwningPtr< RooArgSet > getVariables(bool stripDisconnected=true) const
Return RooArgSet with all variables (tree leaf nodes of expression tree)
 
virtual void applyWeightSquared(bool flag)
Disables or enables the usage of squared weights.
 
A space to attach TBranches.
 
double getRealValue(const char *name, double defVal=0.0, bool verbose=false) const
Get value of a RooAbsReal stored in set with given name.
 
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
 
void assignFast(const RooAbsCollection &other, bool setValDirty=true) const
Functional equivalent of assign() but assumes this and other collection have same layout.
 
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
 
Storage_t::size_type size() const
 
RooAbsArg * first() const
 
virtual RooAbsArg * addClone(const RooAbsArg &var, bool silent=false)
Add a clone of the specified argument to list.
 
std::string contentsString() const
Return comma separated list of contained object names as STL string.
 
Abstract base class for binned and unbinned datasets.
 
Abstract interface for all probability density functions.
 
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 double defaultErrorLevel() const
 
virtual bool setData(RooAbsData &, bool=true)
 
void printMultiline(std::ostream &os, Int_t contents, bool verbose=false, TString indent="") const override
Structure printing.
 
RooArgList is a container object that can hold multiple RooAbsArg objects.
 
RooArgSet is a container object that can hold multiple RooAbsArg objects.
 
RooArgSet * selectByAttrib(const char *name, bool value) const
Use RooAbsCollection::selectByAttrib(), but return as RooArgSet.
 
Implements a RooAbsBinning in terms of an array of boundary values, posing no constraints on the choi...
 
Named container for two doubles, two integers two object points and three string pointers that can be...
 
Container class to hold unbinned data.
 
RooRealVar * weightVar() const
Returns a pointer to the weight variable (if set).
 
RooFitResult is a container class to hold the input and output of a PDF fit to a dataset.
 
Int_t statusCodeHistory(UInt_t icycle) const
 
const char * statusLabelHistory(UInt_t icycle) const
 
const RooArgList & floatParsFinal() const
Return list of floating parameters after fit.
 
Int_t status() const
Return MINUIT status code.
 
UInt_t numStatusHistory() const
 
double minNll() const
Return minimized -log(L) value.
 
Collection class for internal use, storing a collection of RooAbsArg pointers in a doubly linked list...
 
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
 
void optimizeConst(int flag)
If flag is true, perform constant term optimization on function being minimized.
 
auto fitter()
Return underlying ROOT fitter object.
 
RooFit::OwningPtr< RooFitResult > save(const char *name=nullptr, const char *title=nullptr)
Save and return a RooFitResult snapshot of current minimizer status.
 
int minos()
Execute MINOS.
 
int hesse()
Execute HESSE.
 
int minimize(const char *type, const char *alg=nullptr)
Minimise the function passed in the constructor.
 
void setStrategy(int istrat)
Change MINUIT strategy to istrat.
 
static RooMsgService & instance()
Return reference to singleton instance.
 
Implementation of a RooCacheManager<RooAbsCacheElement> that specializes in the storage of cache elem...
 
Efficient implementation of a product of PDFs of the form.
 
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'.
 
bool hasBinning(const char *name) const override
Returns true if variable has a binning named 'name'.
 
Facilitates simultaneous fitting of multiple PDFs to subsets of a given dataset.
 
static RooAbsData * GenerateAsimovData(const RooAbsPdf &pdf, const RooArgSet &observables)
generate the asimov data for the observables (not the global ones) need to deal with the case of a si...
 
A RooAbsArg implementing string values.
 
Joins several RooAbsCategoryLValue objects into a single category.
 
bool setIndex(value_type index, bool printError=true) override
Set the value of the super category to the specified index.
 
Persistable container for RooFit projects.
 
Using a TBrowser one can browse all ROOT objects.
 
static TCanvas * MakeDefCanvas()
Static function to build a default canvas.
 
TClass instances represent classes, structs and namespaces in the ROOT type system.
 
static TClass * GetClass(const char *name, Bool_t load=kTRUE, Bool_t silent=kFALSE)
Static method returning pointer to TClass of the specified class name.
 
This class stores the date and time with a precision of one second in an unsigned 32 bit word (950130...
 
const char * AsString() const
Return the date & time as a string (ctime() format).
 
Describe directory structure in memory.
 
A TGraphErrors is a TGraph with error bars.
 
A TGraph is an object made of two arrays X and Y with npoints each.
 
Book space in a file, create I/O buffers, to fill them, (un)compress them.
 
This class displays a legend box (TPaveText) containing several legend entries.
 
TMatrixTBase< Element > & ResizeTo(Int_t nrows, Int_t ncols, Int_t=-1) override
Set size of the matrix to nrows x ncols New dynamic elements are created, the overlapping part of the...
 
The TNamed class is the base class for all named ROOT classes.
 
const char * GetName() const override
Returns name of object.
 
Mother of all ROOT objects.
 
virtual void Delete(Option_t *option="")
Delete this object.
 
void SetBit(UInt_t f, Bool_t set)
Set or unset the user status bits as specified in f.
 
virtual void Draw(Option_t *option="")
Default Draw method for all objects.
 
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.
 
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
 
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.
 
const char * AsString() const
Return UUID as string. Copy string immediately since it will be reused.
 
RooCmdArg WeightVar(const char *name="weight", bool reinterpretAsWeight=false)
 
RooCmdArg Offset(std::string const &mode)
 
RooCmdArg Optimize(Int_t flag=2)
 
RooCmdArg Extended(bool flag=true)
 
RooCmdArg ExpectedData(bool flag=true)
 
double nll(double pdf, double weight, int binnedL, int doBinOffset)
 
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
 
void Sort(Index n, const Element *a, Index *index, Bool_t down=kTRUE)
Sort the n elements of the array a of generic templated type Element.
 
#define BEGIN_XROOFIT_NAMESPACE
 
#define END_XROOFIT_NAMESPACE
 
double round_to_decimal(double value, int decimal_places)
 
double round_to_digits(double value, int digits)