// @(#)root/roostats:$Id: MinNLLTestStat.h 43035 2012-02-16 16:48:57Z sven $
// Author: Kyle Cranmer, Lorenzo Moneta, Gregory Schott, Wouter Verkerke
// Additional Contributions: Giovanni Petrucciani 
/*************************************************************************
 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers.               *
 * All rights reserved.                                                  *
 *                                                                       *
 * For the licensing terms see $ROOTSYS/LICENSE.                         *
 * For the list of contributors see $ROOTSYS/README/CREDITS.             *
 *************************************************************************/

#ifndef ROOSTATS_MinNLLTestStat
#define ROOSTATS_MinNLLTestStat

//_________________________________________________
/*
BEGIN_HTML
<p>
MinNLLTestStat is an implementation of the TestStatistic interface that calculates the minimum value of the negative log likelihood
function and returns it as a test statistic.
Internaly it operates by delegating to a MinNLLTestStat object.
</p>
END_HTML
*/
//

#ifndef ROOT_Rtypes
#include "Rtypes.h"
#endif

#include <vector>

#include "RooStats/RooStatsUtils.h"

//#include "RooStats/DistributionCreator.h"
#include "RooStats/SamplingDistribution.h"
#include "RooStats/TestStatistic.h"

#include "RooStats/RooStatsUtils.h"

#include "RooRealVar.h"
#include "RooProfileLL.h"
#include "RooNLLVar.h"
#include "RooMsgService.h"

#include "RooMinuit.h"
#include "RooMinimizer.h"
#include "Math/MinimizerOptions.h"
#include "TStopwatch.h"
#include "ProfileLikelihoodTestStat.h"

namespace RooStats {

  class MinNLLTestStat : public TestStatistic{

   public:
     MinNLLTestStat() {
        // Proof constructor. Do not use.
	fProflts = 0;
     }
     MinNLLTestStat(RooAbsPdf& pdf) {
	fProflts = new ProfileLikelihoodTestStat(pdf);
     }

     MinNLLTestStat(const MinNLLTestStat& rhs) : TestStatistic(rhs), fProflts(0) {
        RooAbsPdf * pdf = rhs.fProflts->GetPdf();
        if (pdf)  fProflts = new ProfileLikelihoodTestStat(*pdf);
     }

     MinNLLTestStat & operator=(const MinNLLTestStat& rhs)  {
        if (this == &rhs) return *this;
        RooAbsPdf * pdf = rhs.fProflts->GetPdf();
        if (fProflts) delete fProflts;
        fProflts = NULL;
        if (pdf)  fProflts = new ProfileLikelihoodTestStat(*pdf);
        return *this;
     }

     virtual ~MinNLLTestStat() {
	delete fProflts;
     }

     void SetOneSided(Bool_t flag=true) {fProflts->SetOneSided(flag);}
     void SetOneSidedDiscovery(Bool_t flag=true) {fProflts->SetOneSidedDiscovery(flag);}
     void SetReuseNLL(Bool_t flag) { fProflts->SetReuseNLL(flag); }
     void SetMinimizer(const char* minimizer){ fProflts->SetMinimizer(minimizer); }
     void SetStrategy(Int_t strategy){ fProflts->SetStrategy(strategy); }
     void SetTolerance(double tol){ fProflts->SetTolerance(tol); }
     void SetPrintLevel(Int_t printlevel){ fProflts->SetPrintLevel(printlevel); }
     void SetLOffset(Bool_t flag=kTRUE) { fProflts->SetLOffset(flag) ; }
    
     // Main interface to evaluate the test statistic on a dataset
     virtual Double_t Evaluate(RooAbsData& data, RooArgSet& paramsOfInterest) {
       return fProflts->EvaluateProfileLikelihood(1, data, paramsOfInterest); //find unconditional NLL minimum
     }

     virtual void EnableDetailedOutput( bool e=true ) { fProflts->EnableDetailedOutput(e); }

     virtual const RooArgSet* GetDetailedOutput(void) const {
	     // Returns detailed output. The value returned by this function is updated after each call to Evaluate().
	     // The returned RooArgSet contains the following:
	     // <ul>
	     // <li> the minimum nll, fitstatus and convergence quality for each fit </li> 
	     // <li> for all non-constant parameters their value, error and pull </li>
	     // </ul>
	     return fProflts->GetDetailedOutput();
     }
    
     virtual void SetVarName(const char* name) { fProflts->SetVarName(name); }

     virtual const TString GetVarName() const { return fProflts->GetVarName(); }

   private:
     ProfileLikelihoodTestStat* fProflts;

   protected:
      ClassDef(MinNLLTestStat,1)   // implements the minimum NLL as a test statistic to be used with several tools
   };
}


#endif
 MinNLLTestStat.h:1
 MinNLLTestStat.h:2
 MinNLLTestStat.h:3
 MinNLLTestStat.h:4
 MinNLLTestStat.h:5
 MinNLLTestStat.h:6
 MinNLLTestStat.h:7
 MinNLLTestStat.h:8
 MinNLLTestStat.h:9
 MinNLLTestStat.h:10
 MinNLLTestStat.h:11
 MinNLLTestStat.h:12
 MinNLLTestStat.h:13
 MinNLLTestStat.h:14
 MinNLLTestStat.h:15
 MinNLLTestStat.h:16
 MinNLLTestStat.h:17
 MinNLLTestStat.h:18
 MinNLLTestStat.h:19
 MinNLLTestStat.h:20
 MinNLLTestStat.h:21
 MinNLLTestStat.h:22
 MinNLLTestStat.h:23
 MinNLLTestStat.h:24
 MinNLLTestStat.h:25
 MinNLLTestStat.h:26
 MinNLLTestStat.h:27
 MinNLLTestStat.h:28
 MinNLLTestStat.h:29
 MinNLLTestStat.h:30
 MinNLLTestStat.h:31
 MinNLLTestStat.h:32
 MinNLLTestStat.h:33
 MinNLLTestStat.h:34
 MinNLLTestStat.h:35
 MinNLLTestStat.h:36
 MinNLLTestStat.h:37
 MinNLLTestStat.h:38
 MinNLLTestStat.h:39
 MinNLLTestStat.h:40
 MinNLLTestStat.h:41
 MinNLLTestStat.h:42
 MinNLLTestStat.h:43
 MinNLLTestStat.h:44
 MinNLLTestStat.h:45
 MinNLLTestStat.h:46
 MinNLLTestStat.h:47
 MinNLLTestStat.h:48
 MinNLLTestStat.h:49
 MinNLLTestStat.h:50
 MinNLLTestStat.h:51
 MinNLLTestStat.h:52
 MinNLLTestStat.h:53
 MinNLLTestStat.h:54
 MinNLLTestStat.h:55
 MinNLLTestStat.h:56
 MinNLLTestStat.h:57
 MinNLLTestStat.h:58
 MinNLLTestStat.h:59
 MinNLLTestStat.h:60
 MinNLLTestStat.h:61
 MinNLLTestStat.h:62
 MinNLLTestStat.h:63
 MinNLLTestStat.h:64
 MinNLLTestStat.h:65
 MinNLLTestStat.h:66
 MinNLLTestStat.h:67
 MinNLLTestStat.h:68
 MinNLLTestStat.h:69
 MinNLLTestStat.h:70
 MinNLLTestStat.h:71
 MinNLLTestStat.h:72
 MinNLLTestStat.h:73
 MinNLLTestStat.h:74
 MinNLLTestStat.h:75
 MinNLLTestStat.h:76
 MinNLLTestStat.h:77
 MinNLLTestStat.h:78
 MinNLLTestStat.h:79
 MinNLLTestStat.h:80
 MinNLLTestStat.h:81
 MinNLLTestStat.h:82
 MinNLLTestStat.h:83
 MinNLLTestStat.h:84
 MinNLLTestStat.h:85
 MinNLLTestStat.h:86
 MinNLLTestStat.h:87
 MinNLLTestStat.h:88
 MinNLLTestStat.h:89
 MinNLLTestStat.h:90
 MinNLLTestStat.h:91
 MinNLLTestStat.h:92
 MinNLLTestStat.h:93
 MinNLLTestStat.h:94
 MinNLLTestStat.h:95
 MinNLLTestStat.h:96
 MinNLLTestStat.h:97
 MinNLLTestStat.h:98
 MinNLLTestStat.h:99
 MinNLLTestStat.h:100
 MinNLLTestStat.h:101
 MinNLLTestStat.h:102
 MinNLLTestStat.h:103
 MinNLLTestStat.h:104
 MinNLLTestStat.h:105
 MinNLLTestStat.h:106
 MinNLLTestStat.h:107
 MinNLLTestStat.h:108
 MinNLLTestStat.h:109
 MinNLLTestStat.h:110
 MinNLLTestStat.h:111
 MinNLLTestStat.h:112
 MinNLLTestStat.h:113
 MinNLLTestStat.h:114
 MinNLLTestStat.h:115
 MinNLLTestStat.h:116
 MinNLLTestStat.h:117
 MinNLLTestStat.h:118
 MinNLLTestStat.h:119
 MinNLLTestStat.h:120
 MinNLLTestStat.h:121
 MinNLLTestStat.h:122