Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
MaxLikelihoodEstimateTestStat.h
Go to the documentation of this file.
1// @(#)root/roostats:$Id$
2// Author: Kyle Cranmer June 2010
3/*************************************************************************
4 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
5 * All rights reserved. *
6 * *
7 * For the licensing terms see $ROOTSYS/LICENSE. *
8 * For the list of contributors see $ROOTSYS/README/CREDITS. *
9 *************************************************************************/
10
11#ifndef ROOSTATS_MaxLikelihoodEstimateTestStat
12#define ROOSTATS_MaxLikelihoodEstimateTestStat
13
14
15
16
17#include "Rtypes.h"
18
19#include "RooFitResult.h"
21#include "RooAbsPdf.h"
22#include "RooRealVar.h"
23#include "RooMinimizer.h"
26
27
28
29namespace RooStats {
30
31/** \class MaxLikelihoodEstimateTestStat
32 \ingroup Roostats
33MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood
34estimate of a specified parameter.
35*/
36
38
39 public:
40
41 //__________________________________
43 fPdf(nullptr),fParameter(nullptr), fUpperLimit(true)
44 {
45 /// constructor
46 /// fPdf = pdf;
47 /// fParameter = parameter;
48
51
52 }
53 //__________________________________
55 fPdf(&pdf),fParameter(&parameter), fUpperLimit(true)
56 {
57 // constructor
58 // fPdf = pdf;
59 // fParameter = parameter;
62
63 }
64
65 //______________________________
66 double Evaluate(RooAbsData& data, RooArgSet& /*nullPOI*/) override {
67
68
71
72 /*
73 // this is more straight forward, but produces a lot of messages
74 RooFitResult* res = fPdf.fitTo(data, RooFit::CloneData(false),RooFit::Minos(0),RooFit::Hesse(false), RooFit::Save(1),RooFit::PrintLevel(-1),RooFit::PrintEvalErrors(0));
75 RooRealVar* mle = (RooRealVar*) res->floatParsFinal().find(fParameter.GetName());
76 double ret = mle->getVal();
77 delete res;
78 return ret;
79 */
80
81 std::unique_ptr<RooArgSet> allParams{fPdf->getParameters(data)};
83
84 // need to call constrain for RooSimultaneous until stripDisconnected problem fixed
85 std::unique_ptr<RooAbsReal> nll{fPdf->createNLL(data, RooFit::CloneData(false),RooFit::Constrain(*allParams),RooFit::ConditionalObservables(fConditionalObs))};
86
87 //RooAbsReal* nll = fPdf->createNLL(data, RooFit::CloneData(false));
88
89 // RooAbsReal* profile = nll->createProfile(RooArgSet());
90 // profile->getVal();
91 // RooArgSet* vars = profile->getVariables();
92 // RooMsgService::instance().setGlobalKillBelow(msglevel);
93 // double ret = vars->getRealValue(fParameter->GetName());
94 // return ret;
95
96
97 RooMinimizer minim(*nll);
99 //LM: RooMinimizer.setPrintLevel has +1 offset - so subtract here -1
100 minim.setPrintLevel(fPrintLevel-1);
101 int status = -1;
102 // minim.optimizeConst(true);
103 for (int tries = 0, maxtries = 4; tries <= maxtries; ++tries) {
104 // status = minim.minimize(fMinimizer, ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
105 status = minim.minimize(fMinimizer, "Minimize");
106 if (status == 0) {
107 break;
108 } else {
109 if (tries > 1) {
110 printf(" ----> Doing a re-scan first\n");
111 minim.minimize(fMinimizer,"Scan");
112 }
113 if (tries > 2) {
114 printf(" ----> trying with strategy = 1\n");
115 minim.setStrategy(1);
116 }
117 }
118 }
119 //std::cout << "BEST FIT values " << std::endl;
120 //allParams->Print("V");
121
123
124 if (status != 0) return -1;
125 return fParameter->getVal();
126
127
128 }
129
130 const TString GetVarName() const override {
131 TString varName = Form("Maximum Likelihood Estimate of %s",fParameter->GetName());
132 return varName;
133 }
134
135
136 virtual void PValueIsRightTail(bool isright) { fUpperLimit = isright; }
137 bool PValueIsRightTail(void) const override { return fUpperLimit; }
138
139 // set the conditional observables which will be used when creating the NLL
140 // so the pdf's will not be normalized on the conditional observables when computing the NLL
142
143
144 private:
152
153
154
155 protected:
157};
158
159}
160
161
162#endif
#define ClassDefOverride(name, id)
Definition Rtypes.h:341
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void data
char * Form(const char *fmt,...)
Formats a string in a circular formatting buffer.
Definition TString.cxx:2467
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...
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:59
virtual RooFit::OwningPtr< RooAbsReal > createNLL(RooAbsData &data, const RooLinkedList &cmdList={})
Construct representation of -log(L) of PDF with given dataset.
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:91
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
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 strat)
Change MINUIT strategy to istrat.
static RooMsgService & instance()
Return reference to singleton instance.
void setGlobalKillBelow(RooFit::MsgLevel level)
RooFit::MsgLevel globalKillBelow() const
RooRealVar represents a variable that can be changed from the outside.
Definition RooRealVar.h:40
MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood estimate of a specified ...
bool PValueIsRightTail(void) const override
Defines the sign convention of the test statistic. Overwrite function if necessary.
void SetConditionalObservables(const RooArgSet &set) override
interface to set conditional observables. If a test statistics needs them it will re-implement this f...
double Evaluate(RooAbsData &data, RooArgSet &) override
Main interface to evaluate the test statistic on a dataset given the values for the Null Parameters O...
MaxLikelihoodEstimateTestStat(RooAbsPdf &pdf, RooRealVar &parameter)
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
const char * GetName() const override
Returns name of object.
Definition TNamed.h:47
Basic string class.
Definition TString.h:139
RooCmdArg Constrain(const RooArgSet &params)
RooCmdArg CloneData(bool flag)
RooCmdArg ConditionalObservables(Args_t &&... argsOrArgSet)
Create a RooCmdArg to declare conditional observables.
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Namespace for the RooStats classes.
Definition Asimov.h:19
void RemoveConstantParameters(RooArgSet *set)