51 return !allParams.
empty();
57 fNll->clearEvalErrorLog();
58 std::unique_ptr<RooFitResult> result{
GetMinNLL()};
61 throw std::runtime_error(
"ProfileLikelihoodTestStat: minimization unexpectedly failed!");
63 double minNll = result->minNll();
64 double status = result->status();
68 std::unique_ptr<RooArgSet> detOutput{
73 return {minNll, status};
94 double initial_mu_value = 0;
96 if (firstPOI) initial_mu_value = firstPOI->
getVal();
99 oocoutI(
nullptr,Eval) <<
"POIs: " << std::endl;
100 paramsOfInterest.
Print(
"v");
109 bool created(
false) ;
110 if (!reuse ||
fNll==
nullptr) {
111 std::unique_ptr<RooArgSet> allParams{
fPdf->getParameters(data)};
119 oocoutI(
nullptr,Eval) <<
"ProfileLikelihoodTestStat::Evaluate - Use Offset mode \""
120 <<
fLOffset <<
"\" in creating NLL" << std::endl;
124 if (
fPrintLevel > 1)
oocoutI(
nullptr,Eval) <<
"creating NLL " << &*
fNll <<
" with data = " << &data << std::endl ;
126 if (reuse && !created) {
127 if (
fPrintLevel > 1)
oocoutI(
nullptr,Eval) <<
"reusing NLL " << &*
fNll <<
" new data = " << &data << std::endl ;
128 fNll->setData(data,
false) ;
132 oocoutI(
nullptr,Eval) <<
"Data set used is: ";
138 std::unique_ptr<RooArgSet> attachedSet{
fNll->getVariables()};
140 attachedSet->assign(paramsOfInterest);
153 double createTime = tsw.
CpuTime();
158 double fit_favored_mu = 0;
162 uncondML =
fNll->getVal();
165 std::tie(uncondML, statusD) =
minimizeNLL(
"fitUncond_");
169 if (firstPOI) fit_favored_mu = attachedSet->getRealValue(firstPOI->
GetName()) ;
172 double fitTime1 = tsw.
CpuTime();
180 bool doConditionalFit = (type != 1);
186 doConditionalFit =
false;
190 if (doConditionalFit) {
196 attachedSet->assign(*snap);
200 for (
auto *tmpPar : paramsOfInterest) {
211 condML =
fNll->getVal();
215 std::tie(condML, statusN) =
minimizeNLL(
"fitCond_");
221 double fitTime2 = tsw.
CpuTime();
229 pll =
fNll->getVal();
234 }
else if (type == 2) {
241 pll = condML-uncondML;
245 if (
fPrintLevel > 0)
oocoutW(
nullptr,Eval) <<
"pll is negative - setting it to zero " << std::endl;
249 : (fit_favored_mu > initial_mu_value))
255 oocoutP(
nullptr,Eval) <<
"EvaluateProfileLikelihood - ";
257 ooccoutP(
nullptr,Eval) <<
"mu hat = " << fit_favored_mu <<
", uncond ML = " << uncondML;
259 ooccoutP(
nullptr,Eval) <<
", cond ML = " << condML;
261 ooccoutP(
nullptr,Eval) <<
" pll = " << pll;
262 ooccoutP(
nullptr,Eval) <<
" time (create/fit1/2) " << createTime <<
" , " << fitTime1 <<
" , " << fitTime2
268 attachedSet->assign(*origAttachedSet);
270 delete origAttachedSet;
279 if(statusN!=0 || statusD!=0) {
304 if (algorithm ==
"Migrad") algorithm =
"Minimize";
307 for (
int tries = 1, maxtries = 4; tries <= maxtries; ++tries) {
308 status = minim.
minimize(minimizer,algorithm);
309 if (status%1000 == 0) {
311 }
else if (tries < maxtries) {
324 minimizer =
"Minuit";
325 algorithm =
"migradimproved";
331 return std::unique_ptr<RooFitResult>{minim.
save()};
static const std::string & DefaultMinimizerAlgo()
RooAbsArg * first() const
void removeConstantParameters()
void Print(Option_t *options=nullptr) const override
This method must be overridden when a class wants to print itself.
Abstract base class for binned and unbinned datasets.
void setConstant(bool value=true)
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
static void setHideOffset(bool flag)
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooArgSet * snapshot(bool deepCopy=true) const
Use RooAbsCollection::snapshot(), but return as RooArgSet.
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
void optimizeConst(int flag)
RooFit::OwningPtr< RooFitResult > save(const char *name=nullptr, const char *title=nullptr)
Save and return a RooFitResult snapshot of current minimizer status.
void setEvalErrorWall(bool flag)
void setEps(double eps)
Change MINUIT epsilon.
void setPrintLevel(int newLevel)
Change the MINUIT internal printing level.
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.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
Variable that can be changed from the outside.
static RooArgSet * GetAsArgSet(RooFitResult *result, TString prefix="", bool withErrorsAndPulls=false)
Translate the given fit result to a RooArgSet in a generic way.
std::pair< double, int > minimizeNLL(std::string const &prefix)
std::unique_ptr< RooArgSet > fDetailedOutput
!
RooArgSet fConditionalObs
conditional observables
bool fDetailedOutputWithErrorsAndPulls
std::unique_ptr< RooAbsReal > fNll
!
static void SetAlwaysReuseNLL(bool flag)
static bool fgAlwaysReuseNll
virtual double EvaluateProfileLikelihood(int type, RooAbsData &data, RooArgSet ¶msOfInterest)
evaluate the profile likelihood ratio (type = 0) or the minimum of likelihood (type=1) or the conditi...
RooArgSet fGlobalObs
global observables
bool minimizationNeeded(RooArgSet allParams) const
Check if there are non-const parameters so it is worth to do the minimization.
std::unique_ptr< RooFitResult > GetMinNLL()
find minimum of NLL using RooMinimizer
bool fDetailedOutputEnabled
this will store a snapshot of the unconditional nuisance parameter fit.
const char * GetName() const override
Returns name of object.
void Start(Bool_t reset=kTRUE)
Start the stopwatch.
Double_t CpuTime()
Stop the stopwatch (if it is running) and return the cputime (in seconds) passed between the start an...
void Stop()
Stop the stopwatch.
RooCmdArg Offset(std::string const &mode)
RooCmdArg Constrain(const RooArgSet ¶ms)
RooCmdArg GlobalObservables(Args_t &&... argsOrArgSet)
RooCmdArg CloneData(bool flag)
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
void RemoveConstantParameters(RooArgSet *set)
RooStatsConfig & GetGlobalRooStatsConfig()
Retrieve the config object which can be used to set flags for things like offsetting the likelihood o...
void PrintListContent(const RooArgList &l, std::ostream &os=std::cout)
useful function to print in one line the content of a set with their values