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
39public:
41 : fStrategy(::ROOT::Math::MinimizerOptions::DefaultStrategy()),
42 fPrintLevel(::ROOT::Math::MinimizerOptions::DefaultPrintLevel())
43 {
44 }
45
47 : fPdf(&pdf),
48 fParameter(&parameter),
49 fStrategy(::ROOT::Math::MinimizerOptions::DefaultStrategy()),
50 fPrintLevel(::ROOT::Math::MinimizerOptions::DefaultPrintLevel())
51 {
52 }
53
54 //______________________________
55 double Evaluate(RooAbsData& data, RooArgSet& /*nullPOI*/) override {
56
57
60
61 /*
62 // this is more straight forward, but produces a lot of messages
63 RooFitResult* res = fPdf.fitTo(data, RooFit::CloneData(false),RooFit::Minos(0),RooFit::Hesse(false), RooFit::Save(1),RooFit::PrintLevel(-1),RooFit::PrintEvalErrors(0));
64 RooRealVar* mle = (RooRealVar*) res->floatParsFinal().find(fParameter.GetName());
65 double ret = mle->getVal();
66 delete res;
67 return ret;
68 */
69
70 std::unique_ptr<RooArgSet> allParams{fPdf->getParameters(data)};
72
73 // need to call constrain for RooSimultaneous until stripDisconnected problem fixed
74 std::unique_ptr<RooAbsReal> nll{fPdf->createNLL(data, RooFit::CloneData(false),RooFit::Constrain(*allParams),RooFit::ConditionalObservables(fConditionalObs))};
75
76 //RooAbsReal* nll = fPdf->createNLL(data, RooFit::CloneData(false));
77
78 // RooAbsReal* profile = nll->createProfile(RooArgSet());
79 // profile->getVal();
80 // RooArgSet* vars = profile->getVariables();
81 // RooMsgService::instance().setGlobalKillBelow(msglevel);
82 // double ret = vars->getRealValue(fParameter->GetName());
83 // return ret;
84
85
86 RooMinimizer minim(*nll);
88 //LM: RooMinimizer.setPrintLevel has +1 offset - so subtract here -1
90 int status = -1;
91 // minim.optimizeConst(true);
92 for (int tries = 0, maxtries = 4; tries <= maxtries; ++tries) {
93 // status = minim.minimize(fMinimizer, ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
94 status = minim.minimize(fMinimizer, "Minimize");
95 if (status == 0) {
96 break;
97 } else {
98 if (tries > 1) {
99 printf(" ----> Doing a re-scan first\n");
100 minim.minimize(fMinimizer,"Scan");
101 }
102 if (tries > 2) {
103 printf(" ----> trying with strategy = 1\n");
104 minim.setStrategy(1);
105 }
106 }
107 }
108 //std::cout << "BEST FIT values " << std::endl;
109 //allParams->Print("V");
110
112
113 if (status != 0) return -1;
114 return fParameter->getVal();
115
116
117 }
118
119 const TString GetVarName() const override {
120 TString varName = Form("Maximum Likelihood Estimate of %s",fParameter->GetName());
121 return varName;
122 }
123
124
125 virtual void PValueIsRightTail(bool isright) { fUpperLimit = isright; }
126 bool PValueIsRightTail(void) const override { return fUpperLimit; }
127
128 // set the conditional observables which will be used when creating the NLL
129 // so the pdf's will not be normalized on the conditional observables when computing the NLL
131
132
133 private:
134 RooAbsPdf *fPdf = nullptr;
137 bool fUpperLimit = true;
141
142
143
144 protected:
146};
147
148}
149
150
151#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:2489
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.
Abstract base class for binned and unbinned datasets.
Definition RooAbsData.h:57
Abstract interface for all probability density functions.
Definition RooAbsPdf.h:40
RooFit::OwningPtr< RooAbsReal > createNLL(RooAbsData &data, CmdArgs_t const &... cmdArgs)
Construct representation of -log(L) of PDF with given dataset.
Definition RooAbsPdf.h:163
double getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
Definition RooAbsReal.h:103
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Definition RooArgSet.h:55
Wrapper class around ROOT::Fit:Fitter that provides a seamless interface between the minimizer functi...
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.
Definition RooRealVar.h:37
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.
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
MsgLevel
Verbosity level for RooMsgService::StreamConfig in RooMsgService.
Namespace for the RooStats classes.
Definition Asimov.h:19
void RemoveConstantParameters(RooArgSet *set)