Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
RatioOfProfiledLikelihoodsTestStat.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Authors: Kyle Cranmer, Sven Kreiss 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_RatioOfProfiledLikelihoodsTestStat
12 #define ROOSTATS_RatioOfProfiledLikelihoodsTestStat
13 
14 
15 #include "Rtypes.h"
16 
17 #include "RooNLLVar.h"
18 
19 #include "RooStats/TestStatistic.h"
20 
22 
23 
24 namespace RooStats {
25 
26  class RatioOfProfiledLikelihoodsTestStat: public TestStatistic {
27 
28  public:
29 
30  RatioOfProfiledLikelihoodsTestStat() :
31  fNullProfile(),
32  fAltProfile(),
33  fAltPOI(NULL),
34  fSubtractMLE(true),
35  fDetailedOutputEnabled(false),
36  fDetailedOutput(NULL)
37  {
38  // Proof constructor. Don't use.
39  }
40 
41  RatioOfProfiledLikelihoodsTestStat(RooAbsPdf& nullPdf, RooAbsPdf& altPdf,
42  const RooArgSet* altPOI=0) :
43  fNullProfile(nullPdf),
44  fAltProfile(altPdf),
45  fSubtractMLE(true),
46  fDetailedOutputEnabled(false),
47  fDetailedOutput(NULL)
48  {
49  // Calculates the ratio of profiled likelihoods.
50 
51  if(altPOI)
52  fAltPOI = (RooArgSet*) altPOI->snapshot();
53  else
54  fAltPOI = new RooArgSet(); // empty set
55 
56  }
57 
58  //__________________________________________
59  ~RatioOfProfiledLikelihoodsTestStat(void) {
60  if(fAltPOI) delete fAltPOI;
61  if(fDetailedOutput) delete fDetailedOutput;
62  }
63 
64 
65  // returns -logL(poi, conditional MLE of nuisance params)
66  // it does not subtract off the global MLE
67  // because nuisance parameters of null and alternate may not
68  // be the same.
69  Double_t ProfiledLikelihood(RooAbsData& data, RooArgSet& poi, RooAbsPdf& pdf);
70 
71  // evaluate the ratio of profile likelihood
72  virtual Double_t Evaluate(RooAbsData& data, RooArgSet& nullParamsOfInterest);
73 
74  virtual void EnableDetailedOutput( bool e=true ) {
75  fDetailedOutputEnabled = e;
76  fNullProfile.EnableDetailedOutput(fDetailedOutputEnabled);
77  fAltProfile.EnableDetailedOutput(fDetailedOutputEnabled);
78  }
79 
80  static void SetAlwaysReuseNLL(Bool_t flag);
81 
82  void SetReuseNLL(Bool_t flag) {
83  fNullProfile.SetReuseNLL(flag);
84  fAltProfile.SetReuseNLL(flag);
85  }
86 
87  void SetMinimizer(const char* minimizer){
88  fNullProfile.SetMinimizer(minimizer);
89  fAltProfile.SetMinimizer(minimizer);
90  }
91  void SetStrategy(Int_t strategy){
92  fNullProfile.SetStrategy(strategy);
93  fAltProfile.SetStrategy(strategy);
94  }
95  void SetTolerance(Double_t tol){
96  fNullProfile.SetTolerance(tol);
97  fAltProfile.SetTolerance(tol);
98  }
99  void SetPrintLevel(Int_t printLevel){
100  fNullProfile.SetPrintLevel(printLevel);
101  fAltProfile.SetPrintLevel(printLevel);
102  }
103 
104  // set the conditional observables which will be used when creating the NLL
105  // so the pdf's will not be normalized on the conditional observables when computing the NLL
106  virtual void SetConditionalObservables(const RooArgSet& set) {
107  fNullProfile.SetConditionalObservables(set);
108  fAltProfile.SetConditionalObservables(set);
109  }
110 
111  // set the global observables which will be used when creating the NLL
112  // so the constraint pdf's will be normalized correctly on the global observables when computing the NLL
113  virtual void SetGlobalObservables(const RooArgSet& set) {
114  fNullProfile.SetGlobalObservables(set);
115  fAltProfile.SetGlobalObservables(set);
116  }
117 
118  virtual const RooArgSet* GetDetailedOutput(void) const {
119  // Returns detailed output. The value returned by this function is updated after each call to Evaluate().
120  // The returned RooArgSet contains the following for the alternative and null hypotheses:
121  // - the minimum nll, fitstatus and convergence quality for each fit
122  // - for each fit and for each non-constant parameter, the value, error and pull of the parameter are stored
123  return fDetailedOutput;
124  }
125 
126 
127 
128 
129  virtual const TString GetVarName() const { return "log(L(#mu_{1},#hat{#nu}_{1}) / L(#mu_{0},#hat{#nu}_{0}))"; }
130 
131  // const bool PValueIsRightTail(void) { return false; } // overwrites default
132 
133  void SetSubtractMLE(bool subtract){fSubtractMLE = subtract;}
134 
135  private:
136 
137  ProfileLikelihoodTestStat fNullProfile;
138  ProfileLikelihoodTestStat fAltProfile;
139 
140  RooArgSet* fAltPOI;
141  Bool_t fSubtractMLE;
142  static Bool_t fgAlwaysReuseNll ;
143 
144  bool fDetailedOutputEnabled;
145  RooArgSet* fDetailedOutput;
146 
147 
148  protected:
149  ClassDef(RatioOfProfiledLikelihoodsTestStat,3) // implements the ratio of profiled likelihood as test statistic
150  };
151 
152 }
153 
154 
155 #endif