Logo ROOT   6.30.04
Reference Guide
 All Namespaces Files Pages
MinNLLTestStat.h
Go to the documentation of this file.
1 // @(#)root/roostats:$Id: MinNLLTestStat.h 43035 2012-02-16 16:48:57Z sven $
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_MinNLLTestStat
13 #define ROOSTATS_MinNLLTestStat
14 
15 
16 
17 
18 #include "Rtypes.h"
19 
20 #include <vector>
21 
22 #include "RooStats/RooStatsUtils.h"
23 
24 //#include "RooStats/DistributionCreator.h"
26 #include "RooStats/TestStatistic.h"
27 
28 #include "RooStats/RooStatsUtils.h"
29 
30 #include "RooRealVar.h"
31 #include "RooProfileLL.h"
32 #include "RooNLLVar.h"
33 #include "RooMsgService.h"
34 
35 #include "RooMinuit.h"
36 #include "RooMinimizer.h"
37 #include "Math/MinimizerOptions.h"
38 #include "TStopwatch.h"
40 
41 namespace RooStats {
42 
43 /** \class MinNLLTestStat
44  \ingroup Roostats
45 
46 MinNLLTestStat is an implementation of the TestStatistic interface that
47 calculates the minimum value of the negative log likelihood
48 function and returns it as a test statistic.
49 Internally it operates by delegating to a MinNLLTestStat object.
50 
51 */
52 
53  class MinNLLTestStat : public TestStatistic{
54 
55  public:
56  MinNLLTestStat() {
57  // Proof constructor. Do not use.
58  fProflts = 0;
59  }
60  MinNLLTestStat(RooAbsPdf& pdf) {
61  fProflts = new ProfileLikelihoodTestStat(pdf);
62  }
63 
64  MinNLLTestStat(const MinNLLTestStat& rhs) : TestStatistic(rhs), fProflts(0) {
65  RooAbsPdf * pdf = rhs.fProflts->GetPdf();
66  if (pdf) fProflts = new ProfileLikelihoodTestStat(*pdf);
67  }
68 
69  MinNLLTestStat & operator=(const MinNLLTestStat& rhs) {
70  if (this == &rhs) return *this;
71  RooAbsPdf * pdf = rhs.fProflts->GetPdf();
72  if (fProflts) delete fProflts;
73  fProflts = NULL;
74  if (pdf) fProflts = new ProfileLikelihoodTestStat(*pdf);
75  return *this;
76  }
77 
78  virtual ~MinNLLTestStat() {
79  delete fProflts;
80  }
81 
82  void SetOneSided(Bool_t flag=true) {fProflts->SetOneSided(flag);}
83  void SetOneSidedDiscovery(Bool_t flag=true) {fProflts->SetOneSidedDiscovery(flag);}
84  void SetReuseNLL(Bool_t flag) { fProflts->SetReuseNLL(flag); }
85  void SetMinimizer(const char* minimizer){ fProflts->SetMinimizer(minimizer); }
86  void SetStrategy(Int_t strategy){ fProflts->SetStrategy(strategy); }
87  void SetTolerance(double tol){ fProflts->SetTolerance(tol); }
88  void SetPrintLevel(Int_t printlevel){ fProflts->SetPrintLevel(printlevel); }
89  void SetLOffset(Bool_t flag=kTRUE) { fProflts->SetLOffset(flag) ; }
90 
91  // Main interface to evaluate the test statistic on a dataset
92  virtual Double_t Evaluate(RooAbsData& data, RooArgSet& paramsOfInterest) {
93  return fProflts->EvaluateProfileLikelihood(1, data, paramsOfInterest); //find unconditional NLL minimum
94  }
95 
96  virtual void EnableDetailedOutput( bool e=true ) { fProflts->EnableDetailedOutput(e); }
97 
98  virtual const RooArgSet* GetDetailedOutput(void) const {
99  // Returns detailed output. The value returned by this function is updated after each call to Evaluate().
100  // The returned RooArgSet contains the following:
101  //
102  // - the minimum nll, fitstatus and convergence quality for each fit </li>
103  // - for all non-constant parameters their value, error and pull </li>
104  return fProflts->GetDetailedOutput();
105  }
106 
107  virtual void SetVarName(const char* name) { fProflts->SetVarName(name); }
108 
109  virtual const TString GetVarName() const { return fProflts->GetVarName(); }
110 
111  private:
112  ProfileLikelihoodTestStat* fProflts;
113 
114  protected:
115  ClassDef(MinNLLTestStat,1) // implements the minimum NLL as a test statistic to be used with several tools
116  };
117 }
118 
119 
120 #endif