Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
ProfileLikelihoodTestStat.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id$
2 // Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
3 // Additional Contributions: Giovanni Petrucciani
4 /*************************************************************************
5  * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. *
6  * All rights reserved. *
7  * *
8  * For the licensing terms see $ROOTSYS/LICENSE. *
9  * For the list of contributors see $ROOTSYS/README/CREDITS. *
10  *************************************************************************/
11 
12 #ifndef ROOSTATS_ProfileLikelihoodTestStat
13 #define ROOSTATS_ProfileLikelihoodTestStat
14 
15 
16 #include "Rtypes.h"
17 
18 #include "RooStats/TestStatistic.h"
19 
20 
21 #include "RooRealVar.h"
22 
23 #include "RooNLLVar.h"
24 
25 #include "Math/MinimizerOptions.h"
26 
27 #include "RooStats/RooStatsUtils.h"
28 
29 
30 namespace RooStats {
31 
32  class ProfileLikelihoodTestStat : public TestStatistic{
33 
34  enum LimitType {twoSided, oneSided, oneSidedDiscovery};
35 
36  public:
37  ProfileLikelihoodTestStat() {
38  // Proof constructor. Do not use.
39  fPdf = 0;
40  fNll = 0;
41  fCachedBestFitParams = 0;
42  fLastData = 0;
43  fLimitType = twoSided;
44  fSigned = false;
45  fDetailedOutputWithErrorsAndPulls = false;
46  fDetailedOutputEnabled = false;
47  fDetailedOutput = NULL;
48  fLOffset = RooStats::IsNLLOffset() ;
49 
50  fVarName = "Profile Likelihood Ratio";
51  fReuseNll = false;
52  fMinimizer=::ROOT::Math::MinimizerOptions::DefaultMinimizerType().c_str();
53  fStrategy=::ROOT::Math::MinimizerOptions::DefaultStrategy();
54  fTolerance=TMath::Max(1.,::ROOT::Math::MinimizerOptions::DefaultTolerance());
55  fPrintLevel=::ROOT::Math::MinimizerOptions::DefaultPrintLevel();
56 
57  }
58  ProfileLikelihoodTestStat(RooAbsPdf& pdf) {
59  fPdf = &pdf;
60  fNll = 0;
61  fCachedBestFitParams = 0;
62  fLastData = 0;
63  fLimitType = twoSided;
64  fSigned = false;
65  fDetailedOutputWithErrorsAndPulls = false;
66  fDetailedOutputEnabled = false;
67  fDetailedOutput = NULL;
68  fLOffset = RooStats::IsNLLOffset() ;
69 
70  fVarName = "Profile Likelihood Ratio";
71  fReuseNll = false;
72  fMinimizer=::ROOT::Math::MinimizerOptions::DefaultMinimizerType().c_str();
73  fStrategy=::ROOT::Math::MinimizerOptions::DefaultStrategy();
74  // avoid default tolerance to be too small (1. is default in RooMinimizer)
75  fTolerance=TMath::Max(1.,::ROOT::Math::MinimizerOptions::DefaultTolerance());
76  fPrintLevel=::ROOT::Math::MinimizerOptions::DefaultPrintLevel();
77  }
78 
79  virtual ~ProfileLikelihoodTestStat() {
80  if(fNll) delete fNll;
81  if(fCachedBestFitParams) delete fCachedBestFitParams;
82  if(fDetailedOutput) delete fDetailedOutput;
83  }
84 
85  //LM use default copy constructor and assignment copying the pointers. Is this what we want ?
86 
87  void SetOneSided(Bool_t flag=true) {fLimitType = (flag ? oneSided : twoSided);}
88  void SetOneSidedDiscovery(Bool_t flag=true) {fLimitType = (flag ? oneSidedDiscovery : twoSided);}
89  void SetSigned(Bool_t flag=true) {fSigned = flag;} // +/- t_mu instead of t_mu>0 with one-sided settings
90  //void SetOneSidedDiscovery(Bool_t flag=true) {fOneSidedDiscovery = flag;}
91 
92  bool IsTwoSided() const { return fLimitType == twoSided; }
93  bool IsOneSidedDiscovery() const { return fLimitType == oneSidedDiscovery; }
94 
95  static void SetAlwaysReuseNLL(Bool_t flag);
96 
97  void SetReuseNLL(Bool_t flag) { fReuseNll = flag ; }
98  void SetLOffset(Bool_t flag=kTRUE) { fLOffset = flag ; }
99 
100  void SetMinimizer(const char* minimizer){ fMinimizer=minimizer;}
101  void SetStrategy(Int_t strategy){fStrategy=strategy;}
102  void SetTolerance(double tol){fTolerance=tol;}
103  void SetPrintLevel(Int_t printlevel){fPrintLevel=printlevel;}
104 
105  // Main interface to evaluate the test statistic on a dataset
106  virtual Double_t Evaluate(RooAbsData& data, RooArgSet& paramsOfInterest) {
107  return EvaluateProfileLikelihood(0, data, paramsOfInterest);
108  }
109 
110  // evaluate the profile likelihood ratio (type = 0) or the minimum of likelihood (type=1) or the conditional LL (type = 2)
111  virtual Double_t EvaluateProfileLikelihood(int type, RooAbsData &data, RooArgSet & paramsOfInterest);
112 
113  virtual void EnableDetailedOutput( bool e=true, bool withErrorsAndPulls=false ) {
114  fDetailedOutputEnabled = e;
115  fDetailedOutputWithErrorsAndPulls = withErrorsAndPulls;
116  delete fDetailedOutput;
117  fDetailedOutput = NULL;
118  }
119  virtual const RooArgSet* GetDetailedOutput(void) const {
120  // Returns detailed output. The value returned by this function is updated after each call to Evaluate().
121  // The returned RooArgSet contains the following:
122  // <ul>
123  // <li> the minimum nll, fitstatus and convergence quality for each fit </li>
124  // <li> for each fit and for each non-constant parameter, the value, error and pull of the parameter are stored </li>
125  // </ul>
126  return fDetailedOutput;
127  }
128 
129  // set the conditional observables which will be used when creating the NLL
130  // so the pdf's will not be normalized on the conditional observables when computing the NLL
131  virtual void SetConditionalObservables(const RooArgSet& set) {fConditionalObs.removeAll(); fConditionalObs.add(set);}
132 
133  // set the global observables which will be used when creating the NLL
134  // so the constraint pdf's will be normalized correctly on the global observables when computing the NLL
135  virtual void SetGlobalObservables(const RooArgSet& set) {fGlobalObs.removeAll(); fGlobalObs.add(set);}
136 
137  virtual void SetVarName(const char* name) { fVarName = name; }
138  virtual const TString GetVarName() const {return fVarName;}
139 
140  virtual RooAbsPdf * GetPdf() const { return fPdf; }
141 
142 
143  // const bool PValueIsRightTail(void) { return false; } // overwrites default
144 
145  private:
146 
147  RooFitResult* GetMinNLL();
148 
149  private:
150 
151  RooAbsPdf* fPdf;
152  RooAbsReal* fNll; //!
153  const RooArgSet* fCachedBestFitParams;
154  RooAbsData* fLastData;
155  // Double_t fLastMLE;
156  LimitType fLimitType;
157  Bool_t fSigned;
158 
159  // this will store a snapshot of the unconditional nuisance
160  // parameter fit.
161  bool fDetailedOutputEnabled;
162  bool fDetailedOutputWithErrorsAndPulls;
163  RooArgSet* fDetailedOutput; //!
164  RooArgSet fConditionalObs; // conditional observables
165  RooArgSet fGlobalObs; // global observables
166 
167  TString fVarName;
168 
169  static Bool_t fgAlwaysReuseNll ;
170  Bool_t fReuseNll ;
171  TString fMinimizer;
172  Int_t fStrategy;
173  Double_t fTolerance;
174  Int_t fPrintLevel;
175  Bool_t fLOffset ;
176 
177  protected:
178 
179  ClassDef(ProfileLikelihoodTestStat,10) // implements the profile likelihood ratio as a test statistic to be used with several tools
180  };
181 }
182 
183 
184 #endif