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 "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 RooArgSet* allParams = fPdf->getParameters(data);
83
84 // need to call constrain for RooSimultaneous until stripDisconnected problem fixed
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 // delete vars;
95 // delete nll;
96 // delete profile;
97 // return ret;
98
99
100 RooMinimizer minim(*nll);
101 minim.setStrategy(fStrategy);
102 //LM: RooMinimizer.setPrintLevel has +1 offset - so subtract here -1
103 minim.setPrintLevel(fPrintLevel-1);
104 int status = -1;
105 // minim.optimizeConst(true);
106 for (int tries = 0, maxtries = 4; tries <= maxtries; ++tries) {
107 // status = minim.minimize(fMinimizer, ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
108 status = minim.minimize(fMinimizer, "Minimize");
109 if (status == 0) {
110 break;
111 } else {
112 if (tries > 1) {
113 printf(" ----> Doing a re-scan first\n");
114 minim.minimize(fMinimizer,"Scan");
115 }
116 if (tries > 2) {
117 printf(" ----> trying with strategy = 1\n");
118 minim.setStrategy(1);
119 }
120 }
121 }
122 //std::cout << "BEST FIT values " << std::endl;
123 //allParams->Print("V");
124
126 delete nll;
127
128 if (status != 0) return -1;
129 return fParameter->getVal();
130
131
132 }
133
134 const TString GetVarName() const override {
135 TString varName = Form("Maximum Likelihood Estimate of %s",fParameter->GetName());
136 return varName;
137 }
138
139
140 virtual void PValueIsRightTail(bool isright) { fUpperLimit = isright; }
141 bool PValueIsRightTail(void) const override { return fUpperLimit; }
142
143 // set the conditional observables which will be used when creating the NLL
144 // so the pdf's will not be normalized on the conditional observables when computing the NLL
146
147
148 private:
156
157
158
159 protected:
161};
162
163}
164
165
166#endif
#define ClassDefOverride(name, id)
Definition: Rtypes.h:339
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:2452
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...
Definition: RooAbsArg.cxx:541
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:62
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:995
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:62
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:56
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:43
int 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...
Definition: TestStatistic.h:31
const char * GetName() const override
Returns name of object.
Definition: TNamed.h:47
Basic string class.
Definition: TString.h:136
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.
Definition: RooGlobalFunc.h:61
Namespace for the RooStats classes.
Definition: Asimov.h:19
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:67