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();
67 if (fDetailedOutputEnabled) {
68 std::unique_ptr<RooArgSet> detOutput{
70 fDetailedOutput->
addOwned(*detOutput);
73 return {minNll, status};
85 if (fDetailedOutputEnabled) {
86 fDetailedOutput = std::make_unique<RooArgSet>();
94 double initial_mu_value = 0;
96 if (firstPOI) initial_mu_value = firstPOI->
getVal();
98 if (fPrintLevel > 1) {
99 oocoutI(
nullptr,Eval) <<
"POIs: " << std::endl;
100 paramsOfInterest.
Print(
"v");
107 bool reuse=(fReuseNll || fgAlwaysReuseNll) ;
109 bool created(
false) ;
110 if (!reuse || fNll==
nullptr) {
111 std::unique_ptr<RooArgSet> allParams{fPdf->getParameters(
data)};
118 if (fPrintLevel > 0) {
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) ;
131 if (fPrintLevel > 1 &&
data.numEntries() == 1) {
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;
161 if (!minimizationNeeded(*attachedSet)) {
162 uncondML = fNll->getVal();
164 if (fPrintLevel>1)
oocoutI(
nullptr,Eval) <<
"Do unconditional fit" << std::endl;
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);
183 if (!fSigned &&
type==0 &&
184 ((fLimitType==oneSided && fit_favored_mu >= initial_mu_value) ||
185 (fLimitType==oneSidedDiscovery && fit_favored_mu <= initial_mu_value))) {
186 doConditionalFit =
false;
190 if (doConditionalFit) {
192 if (fPrintLevel>1)
oocoutI(
nullptr,Eval) <<
"Do conditional fit " << std::endl;
196 attachedSet->assign(*snap);
200 for (
auto *tmpPar : paramsOfInterest) {
208 if (!minimizationNeeded(*attachedSet)) {
211 condML = fNll->getVal();
215 std::tie(condML, statusN) = minimizeNLL(
"fitCond_");
221 double fitTime2 = tsw.
CpuTime();
227 if (fLOffset ==
"initial") {
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;
248 if (fLimitType==oneSidedDiscovery ? (fit_favored_mu < initial_mu_value)
249 : (fit_favored_mu > initial_mu_value))
254 if (fPrintLevel > 0) {
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) {
297 int level = (fPrintLevel == 0) ? -1 : fPrintLevel -2;
300 TString minimizer = fMinimizer;
302 if (algorithm ==
"Migrad") algorithm =
"Minimize";
305 for (
int tries = 1, maxtries = 4; tries <= maxtries; ++tries) {
306 status = minim.
minimize(minimizer,algorithm);
307 if (status%1000 == 0) {
309 }
else if (tries < maxtries) {
313 if (fStrategy == 0 ) {
322 minimizer =
"Minuit";
323 algorithm =
"migradimproved";
329 return std::unique_ptr<RooFitResult>{minim.
save()};
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 result
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 const std::string & DefaultMinimizerAlgo()
RooAbsArg * first() const
void removeConstantParameters()
virtual bool addOwned(RooAbsArg &var, bool silent=false)
Add an argument and transfer the ownership to the collection.
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...
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)
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...
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
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