Logo ROOT  
Reference Guide
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 "RooNLLVar.h"
20
21#include "RooFitResult.h"
23#include "RooAbsPdf.h"
24#include "RooRealVar.h"
25#include "RooMinimizer.h"
28
29
30
31namespace RooStats {
32
33/** \class MaxLikelihoodEstimateTestStat
34 \ingroup Roostats
35MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood
36estimate of a specified parameter.
37*/
38
40
41 public:
42
43 //__________________________________
45 fPdf(NULL),fParameter(NULL), fUpperLimit(true)
46 {
47 /// constructor
48 /// fPdf = pdf;
49 /// fParameter = parameter;
50
54
55 }
56 //__________________________________
58 fPdf(&pdf),fParameter(&parameter), fUpperLimit(true)
59 {
60 // constructor
61 // fPdf = pdf;
62 // fParameter = parameter;
66
67 }
68
69 //______________________________
70 virtual Double_t Evaluate(RooAbsData& data, RooArgSet& /*nullPOI*/) {
71
72
75
76 /*
77 // this is more straight forward, but produces a lot of messages
78 RooFitResult* res = fPdf.fitTo(data, RooFit::CloneData(kFALSE),RooFit::Minos(0),RooFit::Hesse(false), RooFit::Save(1),RooFit::PrintLevel(-1),RooFit::PrintEvalErrors(0));
79 RooRealVar* mle = (RooRealVar*) res->floatParsFinal().find(fParameter.GetName());
80 double ret = mle->getVal();
81 delete res;
82 return ret;
83 */
84
85 RooArgSet* allParams = fPdf->getParameters(data);
87
88 // need to call constrain for RooSimultaneous until stripDisconnected problem fixed
90
91 //RooAbsReal* nll = fPdf->createNLL(data, RooFit::CloneData(false));
92
93 // RooAbsReal* profile = nll->createProfile(RooArgSet());
94 // profile->getVal();
95 // RooArgSet* vars = profile->getVariables();
96 // RooMsgService::instance().setGlobalKillBelow(msglevel);
97 // double ret = vars->getRealValue(fParameter->GetName());
98 // delete vars;
99 // delete nll;
100 // delete profile;
101 // return ret;
102
103
104 RooMinimizer minim(*nll);
105 minim.setStrategy(fStrategy);
106 //LM: RooMinimizer.setPrintLevel has +1 offset - so subtract here -1
107 minim.setPrintLevel(fPrintLevel-1);
108 int status = -1;
109 // minim.optimizeConst(true);
110 for (int tries = 0, maxtries = 4; tries <= maxtries; ++tries) {
111 // status = minim.minimize(fMinimizer, ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
112 status = minim.minimize(fMinimizer, "Minimize");
113 if (status == 0) {
114 break;
115 } else {
116 if (tries > 1) {
117 printf(" ----> Doing a re-scan first\n");
118 minim.minimize(fMinimizer,"Scan");
119 }
120 if (tries > 2) {
121 printf(" ----> trying with strategy = 1\n");
122 minim.setStrategy(1);
123 }
124 }
125 }
126 //std::cout << "BEST FIT values " << std::endl;
127 //allParams->Print("V");
128
130 delete nll;
131
132 if (status != 0) return -1;
133 return fParameter->getVal();
134
135
136 }
137
138 virtual const TString GetVarName() const {
139 TString varName = Form("Maximum Likelihood Estimate of %s",fParameter->GetName());
140 return varName;
141 }
142
143
144 virtual void PValueIsRightTail(bool isright) { fUpperLimit = isright; }
145 virtual bool PValueIsRightTail(void) const { return fUpperLimit; }
146
147 // set the conditional observables which will be used when creating the NLL
148 // so the pdf's will not be normalized on the conditional observables when computing the NLL
150
151
152 private:
160
161
162
163 protected:
165};
166
167}
168
169
170#endif
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: RtypesCore.h:88
double Double_t
Definition: RtypesCore.h:55
#define ClassDef(name, id)
Definition: Rtypes.h:326
char * Form(const char *fmt,...)
static const std::string & DefaultMinimizerType()
RooArgSet * getParameters(const RooAbsData *data, Bool_t stripDisconnected=kTRUE) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Definition: RooAbsArg.cxx:548
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:39
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:957
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:59
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition: RooAbsReal.h:87
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition: RooArgSet.h:28
virtual Bool_t add(const RooAbsCollection &col, Bool_t silent=kFALSE)
Add a collection of arguments to this collection by calling add() for each element in the source coll...
Definition: RooArgSet.h:88
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:38
Int_t minimize(const char *type, const char *alg=0)
Minimise the function passed in the constructor.
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
void setStrategy(Int_t 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:35
MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood estimate of a specified ...
virtual void SetConditionalObservables(const RooArgSet &set)
interface to set conditional observables. If a test statistics needs them it will re-implement this f...
virtual Double_t Evaluate(RooAbsData &data, RooArgSet &)
Main interface to evaluate the test statistic on a dataset given the values for the Null Parameters O...
MaxLikelihoodEstimateTestStat(RooAbsPdf &pdf, RooRealVar &parameter)
virtual bool PValueIsRightTail(void) const
Defines the sign convention of the test statistic. Overwrite function if necessary.
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
Definition: TestStatistic.h:31
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:131
RooCmdArg Constrain(const RooArgSet &params)
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Definition: RooGlobalFunc.h:65
RooCmdArg CloneData(Bool_t flag)
RooCmdArg ConditionalObservables(const RooArgSet &set)
Namespace for the RooStats classes.
Definition: Asimov.h:20
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:68