Logo ROOT   6.07/09
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 #ifndef ROOT_Rtypes
18 #include "Rtypes.h"
19 #endif
20 
21 #ifndef ROO_NLL_VAR
22 #include "RooNLLVar.h"
23 #endif
24 
25 #include "RooFitResult.h"
26 #include "RooStats/TestStatistic.h"
27 #include "RooAbsPdf.h"
28 #include "RooRealVar.h"
29 #include "RooMinimizer.h"
30 #include "Math/MinimizerOptions.h"
31 #include "RooStats/RooStatsUtils.h"
32 
33 
34 
35 namespace RooStats {
36 
37  /**
38  MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood estimate of a specified parameter.
39  \ingroup Roostats
40  */
41 
42 
44 
45  public:
46 
47  //__________________________________
50  {
51  /// constructor
52  /// fPdf = pdf;
53  /// fParameter = parameter;
54 
58 
59  }
60  //__________________________________
62  fPdf(&pdf),fParameter(&parameter), fUpperLimit(true)
63  {
64  // constructor
65  // fPdf = pdf;
66  // fParameter = parameter;
70 
71  }
72 
73  //______________________________
74  virtual Double_t Evaluate(RooAbsData& data, RooArgSet& /*nullPOI*/) {
75 
76 
79 
80  /*
81  // this is more straight forward, but produces a lot of messages
82  RooFitResult* res = fPdf.fitTo(data, RooFit::CloneData(kFALSE),RooFit::Minos(0),RooFit::Hesse(false), RooFit::Save(1),RooFit::PrintLevel(-1),RooFit::PrintEvalErrors(0));
83  RooRealVar* mle = (RooRealVar*) res->floatParsFinal().find(fParameter.GetName());
84  double ret = mle->getVal();
85  delete res;
86  return ret;
87  */
88 
89  RooArgSet* allParams = fPdf->getParameters(data);
91 
92  // need to call constrain for RooSimultaneous until stripDisconnected problem fixed
94 
95  //RooAbsReal* nll = fPdf->createNLL(data, RooFit::CloneData(false));
96 
97  // RooAbsReal* profile = nll->createProfile(RooArgSet());
98  // profile->getVal();
99  // RooArgSet* vars = profile->getVariables();
100  // RooMsgService::instance().setGlobalKillBelow(msglevel);
101  // double ret = vars->getRealValue(fParameter->GetName());
102  // delete vars;
103  // delete nll;
104  // delete profile;
105  // return ret;
106 
107 
108  RooMinimizer minim(*nll);
109  minim.setStrategy(fStrategy);
110  //LM: RooMinimizer.setPrintLevel has +1 offset - so subtruct here -1
111  minim.setPrintLevel(fPrintLevel-1);
112  int status = -1;
113  // minim.optimizeConst(true);
114  for (int tries = 0, maxtries = 4; tries <= maxtries; ++tries) {
115  // status = minim.minimize(fMinimizer, ROOT::Math::MinimizerOptions::DefaultMinimizerAlgo().c_str());
116  status = minim.minimize(fMinimizer, "Minimize");
117  if (status == 0) {
118  break;
119  } else {
120  if (tries > 1) {
121  printf(" ----> Doing a re-scan first\n");
122  minim.minimize(fMinimizer,"Scan");
123  }
124  if (tries > 2) {
125  printf(" ----> trying with strategy = 1\n");
126  minim.setStrategy(1);
127  }
128  }
129  }
130  //std::cout << "BEST FIT values " << std::endl;
131  //allParams->Print("V");
132 
134  delete nll;
135 
136  if (status != 0) return -1;
137  return fParameter->getVal();
138 
139 
140  }
141 
142  virtual const TString GetVarName() const {
143  TString varName = Form("Maximum Likelihood Estimate of %s",fParameter->GetName());
144  return varName;
145  }
146 
147 
148  virtual void PValueIsRightTail(bool isright) { fUpperLimit = isright; }
149  virtual bool PValueIsRightTail(void) const { return fUpperLimit; }
150 
151  // set the conditional observables which will be used when creating the NLL
152  // so the pdf's will not be normalized on the conditional observables when computing the NLL
154 
155 
156  private:
164 
165 
166 
167  protected:
169 };
170 
171 }
172 
173 
174 #endif
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:777
RooCmdArg CloneData(Bool_t flag)
Basic string class.
Definition: TString.h:137
int Int_t
Definition: RtypesCore.h:41
const Bool_t kFALSE
Definition: Rtypes.h:92
static RooMsgService & instance()
Return reference to singleton instance.
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
virtual void SetConditionalObservables(const RooArgSet &set)
#define ClassDef(name, id)
Definition: Rtypes.h:254
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
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&#39;t match any of...
Definition: RooAbsArg.cxx:560
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:37
RooFit::MsgLevel globalKillBelow() const
static const std::string & DefaultMinimizerType()
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...
char * Form(const char *fmt,...)
void setGlobalKillBelow(RooFit::MsgLevel level)
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:51
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
Namespace for the RooStats classes.
Definition: Asimov.h:20
double Double_t
Definition: RtypesCore.h:55
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Definition: RooAbsReal.h:53
MaxLikelihoodEstimateTestStat(RooAbsPdf &pdf, RooRealVar &parameter)
Int_t minimize(const char *type, const char *alg=0)
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood estimate of a specified ...
void RemoveConstantParameters(RooArgSet *set)
Definition: RooStatsUtils.h:73
RooAbsPdf is the abstract interface for all probability density functions The class provides hybrid a...
Definition: RooAbsPdf.h:41
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
Definition: RooMinimizer.h:38
#define NULL
Definition: Rtypes.h:82
RooCmdArg ConditionalObservables(const RooArgSet &set)
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:33
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add element to non-owning set.
Definition: RooArgSet.cxx:448
RooCmdArg Constrain(const RooArgSet &params)