00001 // @(#)root/roostats:$Id$ 00002 // Author: Kyle Cranmer June 2010 00003 /************************************************************************* 00004 * Copyright (C) 1995-2008, Rene Brun and Fons Rademakers. * 00005 * All rights reserved. * 00006 * * 00007 * For the licensing terms see $ROOTSYS/LICENSE. * 00008 * For the list of contributors see $ROOTSYS/README/CREDITS. * 00009 *************************************************************************/ 00010 00011 #ifndef ROOSTATS_MaxLikelihoodEstimateTestStat 00012 #define ROOSTATS_MaxLikelihoodEstimateTestStat 00013 00014 //_________________________________________________ 00015 /* 00016 BEGIN_HTML 00017 <p> 00018 MaxLikelihoodEstimateTestStat: TestStatistic that returns maximum likelihood estimate of a specified parameter. 00019 </p> 00020 END_HTML 00021 */ 00022 // 00023 00024 #ifndef ROOT_Rtypes 00025 #include "Rtypes.h" 00026 #endif 00027 00028 #ifndef ROO_NLL_VAR 00029 #include "RooNLLVar.h" 00030 #endif 00031 00032 #include "RooFitResult.h" 00033 #include "RooStats/TestStatistic.h" 00034 #include "RooAbsPdf.h" 00035 #include "RooRealVar.h" 00036 00037 namespace RooStats { 00038 00039 class MaxLikelihoodEstimateTestStat: public TestStatistic { 00040 00041 public: 00042 00043 //__________________________________ 00044 MaxLikelihoodEstimateTestStat() : 00045 fPdf(NULL),fParameter(NULL), fUpperLimit(true) 00046 { 00047 // constructor 00048 // fPdf = pdf; 00049 // fParameter = parameter; 00050 } 00051 //__________________________________ 00052 MaxLikelihoodEstimateTestStat(RooAbsPdf& pdf, RooRealVar& parameter) : 00053 fPdf(&pdf),fParameter(¶meter), fUpperLimit(true) 00054 { 00055 // constructor 00056 // fPdf = pdf; 00057 // fParameter = parameter; 00058 } 00059 00060 //______________________________ 00061 virtual Double_t Evaluate(RooAbsData& data, RooArgSet& /*nullPOI*/) { 00062 00063 00064 RooFit::MsgLevel msglevel = RooMsgService::instance().globalKillBelow(); 00065 RooMsgService::instance().setGlobalKillBelow(RooFit::FATAL); 00066 00067 /* 00068 // this is more straight forward, but produces a lot of messages 00069 RooFitResult* res = fPdf.fitTo(data, RooFit::CloneData(kFALSE),RooFit::Minos(0),RooFit::Hesse(false), RooFit::Save(1),RooFit::PrintLevel(-1),RooFit::PrintEvalErrors(0)); 00070 RooRealVar* mle = (RooRealVar*) res->floatParsFinal().find(fParameter.GetName()); 00071 double ret = mle->getVal(); 00072 delete res; 00073 return ret; 00074 */ 00075 00076 RooAbsReal* nll = fPdf->createNLL(data, RooFit::CloneData(false)); 00077 RooAbsReal* profile = nll->createProfile(RooArgSet()); 00078 profile->getVal(); 00079 RooArgSet* vars = profile->getVariables(); 00080 RooMsgService::instance().setGlobalKillBelow(msglevel); 00081 double ret = vars->getRealValue(fParameter->GetName()); 00082 delete vars; 00083 delete nll; 00084 delete profile; 00085 return ret; 00086 00087 } 00088 00089 virtual const TString GetVarName() const { 00090 TString varName = Form("Maximum Likelihood Estimate of %s",fParameter->GetName()); 00091 return varName; 00092 } 00093 00094 00095 virtual void PValueIsRightTail(bool isright) { fUpperLimit = isright; } 00096 virtual bool PValueIsRightTail(void) const { return fUpperLimit; } 00097 00098 00099 private: 00100 RooAbsPdf *fPdf; 00101 RooRealVar *fParameter; 00102 bool fUpperLimit; 00103 00104 protected: 00105 ClassDef(MaxLikelihoodEstimateTestStat,1) 00106 }; 00107 00108 } 00109 00110 00111 #endif