Logo ROOT   6.14/05
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"
22 #include "RooStats/TestStatistic.h"
23 #include "RooAbsPdf.h"
24 #include "RooRealVar.h"
25 #include "RooMinimizer.h"
26 #include "Math/MinimizerOptions.h"
27 #include "RooStats/RooStatsUtils.h"
28 
29 
30 
31 namespace RooStats {
32 
33 /** \class MaxLikelihoodEstimateTestStat
34  \ingroup Roostats
35 MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood
36 estimate 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
virtual RooAbsReal * createNLL(RooAbsData &data, const RooLinkedList &cmdList)
Construct representation of -log(L) of PDFwith given dataset.
Definition: RooAbsPdf.cxx:778
virtual const char * GetName() const
Returns name of object.
Definition: TNamed.h:47
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:86
RooCmdArg CloneData(Bool_t flag)
Double_t getVal(const RooArgSet *set=0) const
Definition: RooAbsReal.h:64
RooFit::MsgLevel globalKillBelow() const
Basic string class.
Definition: TString.h:131
int Int_t
Definition: RtypesCore.h:41
static RooMsgService & instance()
Return reference to singleton instance.
virtual bool PValueIsRightTail(void) const
Defines the sign convention of the test statistic. Overwrite function if necessary.
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
virtual void SetConditionalObservables(const RooArgSet &set)
interface to set conditional observables. If a test statistics needs them it will re-implement this f...
#define ClassDef(name, id)
Definition: Rtypes.h:320
virtual void removeAll()
Remove all arguments from our set, deleting them if we own them.
RooRealVar represents a fundamental (non-derived) real valued object.
Definition: RooRealVar.h:36
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)
RooAbsData is the common abstract base class for binned and unbinned datasets.
Definition: RooAbsData.h:37
const Bool_t kFALSE
Definition: RtypesCore.h:88
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
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:532
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:62
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
RooCmdArg ConditionalObservables(const RooArgSet &set)
TestStatistic is an interface class to provide a facility for construction test statistics distributi...
Definition: TestStatistic.h:31
RooCmdArg Constrain(const RooArgSet &params)