42using std::cout, std::endl;
57 if (fDetailedOutputEnabled) {
58 fDetailedOutput = std::make_unique<RooArgSet>();
66 double initial_mu_value = 0;
68 if (firstPOI) initial_mu_value = firstPOI->
getVal();
70 if (fPrintLevel > 1) {
71 cout <<
"POIs: " << endl;
72 paramsOfInterest.
Print(
"v");
79 bool reuse=(fReuseNll || fgAlwaysReuseNll) ;
82 if (!reuse || fNll==
nullptr) {
83 std::unique_ptr<RooArgSet> allParams{fPdf->getParameters(
data)};
90 if (fPrintLevel > 0 && fLOffset) cout <<
"ProfileLikelihoodTestStat::Evaluate - Use Offset in creating NLL " << endl ;
93 if (fPrintLevel > 1) cout <<
"creating NLL " << &*fNll <<
" with data = " << &
data << endl ;
95 if (reuse && !created) {
96 if (fPrintLevel > 1) cout <<
"reusing NLL " << &*fNll <<
" new data = " << &
data << endl ;
97 fNll->setData(
data,
false) ;
100 if (fPrintLevel > 1 &&
data.numEntries() == 1) {
101 std::cout <<
"Data set used is: ";
107 std::unique_ptr<RooArgSet> attachedSet{fNll->getVariables()};
109 attachedSet->assign(paramsOfInterest);
122 double createTime = tsw.
CpuTime();
127 double fit_favored_mu = 0;
132 fNll->clearEvalErrorLog();
133 if (fPrintLevel>1) std::cout <<
"Do unconditional fit" << std::endl;
134 std::unique_ptr<RooFitResult>
result{GetMinNLL()};
136 uncondML =
result->minNll();
137 statusD =
result->status();
140 if (firstPOI) fit_favored_mu = attachedSet->getRealValue(firstPOI->
GetName()) ;
143 if( fDetailedOutputEnabled ) {
145 fDetailedOutput->addOwned(*detOutput);
154 double fitTime1 = tsw.
CpuTime();
162 bool doConditionalFit = (
type != 1);
165 if (!fSigned &&
type==0 &&
166 ((fLimitType==oneSided && fit_favored_mu >= initial_mu_value) ||
167 (fLimitType==oneSidedDiscovery && fit_favored_mu <= initial_mu_value))) {
168 doConditionalFit =
false;
172 if (doConditionalFit) {
174 if (fPrintLevel>1) std::cout <<
"Do conditional fit " << std::endl;
178 attachedSet->assign(*snap);
182 for (
auto *tmpPar : paramsOfInterest) {
194 if (allParams.
empty() ) {
197 condML = fNll->getVal();
201 fNll->clearEvalErrorLog();
202 std::unique_ptr<RooFitResult>
result{GetMinNLL()};
204 condML =
result->minNll();
205 statusN =
result->status();
206 if( fDetailedOutputEnabled ) {
208 fDetailedOutput->addOwned(*detOutput);
220 double fitTime2 = tsw.
CpuTime();
228 pll = fNll->getVal();
233 }
else if (
type == 2) {
240 pll = condML-uncondML;
244 if (fPrintLevel > 0) std::cout <<
"pll is negative - setting it to zero " << std::endl;
247 if (fLimitType==oneSidedDiscovery ? (fit_favored_mu < initial_mu_value)
248 : (fit_favored_mu > initial_mu_value))
253 if (fPrintLevel > 0) {
254 std::cout <<
"EvaluateProfileLikelihood - ";
256 std::cout <<
"mu hat = " << fit_favored_mu <<
", uncond ML = " << uncondML;
258 std::cout <<
", cond ML = " << condML;
260 std::cout <<
" pll = " << pll;
261 std::cout <<
" time (create/fit1/2) " << createTime <<
" , " << fitTime1 <<
" , " << fitTime2
267 attachedSet->assign(*origAttachedSet);
269 delete origAttachedSet;
278 if(statusN!=0 || statusD!=0) {
296 int level = (fPrintLevel == 0) ? -1 : fPrintLevel -2;
301 TString minimizer = fMinimizer;
303 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) {
310 cout <<
" ----> Doing a re-scan first" << endl;
313 if (fStrategy == 0 ) {
314 cout <<
" ----> trying with strategy = 1" << endl;;
321 cout <<
" ----> trying with improve" << endl;;
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 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::Fit:Fitter that provides a seamless interface between the minimizer functi...
void optimizeConst(int flag)
If flag is true, perform constant term optimization on function being minimized.
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.
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...
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
Double_t SignalingNaN()
Returns a signaling NaN as defined by IEEE 754](http://en.wikipedia.org/wiki/NaN#Signaling_NaN).