// Class RooProfileLL implements the profile likelihood estimator for
// a given likelihood and set of parameters of interest. The value return by
// RooProfileLL is the input likelihood nll minimized w.r.t all nuisance parameters
// (which are all parameters except for those listed in the constructor) minus
// the -log(L) of the best fit. Note that this function is slow to evaluate
// as a MIGRAD minimization step is executed for each function evaluation
// END_HTML
#include "Riostream.h"
#include "RooFit.h"
#include "RooProfileLL.h"
#include "RooAbsReal.h"
#include "RooMinuit.h"
#include "RooMsgService.h"
#include "RooRealVar.h"
#include "RooMsgService.h"
using namespace std ;
ClassImp(RooProfileLL)
RooProfileLL::RooProfileLL(const char *name, const char *title,
RooAbsReal& nllIn, const RooArgSet& observables) :
RooAbsReal(name,title),
_nll("input","-log(L) function",this,nllIn),
_obs("paramOfInterest","Parameters of interest",this),
_par("nuisanceParam","Nuisance parameters",this,kFALSE,kFALSE),
_startFromMin(kTRUE),
_minuit(0),
_absMinValid(kFALSE),
_absMin(0)
{
RooArgSet* actualObs = nllIn.getObservables(observables) ;
RooArgSet* actualPars = nllIn.getParameters(observables) ;
_obs.add(*actualObs) ;
_par.add(*actualPars) ;
delete actualObs ;
delete actualPars ;
_piter = _par.createIterator() ;
_oiter = _obs.createIterator() ;
}
RooProfileLL::RooProfileLL(const RooProfileLL& other, const char* name) :
RooAbsReal(other,name),
_nll("nll",this,other._nll),
_obs("obs",this,other._obs),
_par("par",this,other._par),
_startFromMin(other._startFromMin),
_minuit(0),
_absMinValid(kFALSE),
_absMin(0),
_paramFixed(other._paramFixed)
{
_piter = _par.createIterator() ;
_oiter = _obs.createIterator() ;
}
RooProfileLL::~RooProfileLL()
{
if (_minuit) {
delete _minuit ;
}
delete _piter ;
delete _oiter ;
}
const RooArgSet& RooProfileLL::bestFitParams() const
{
validateAbsMin() ;
return _paramAbsMin ;
}
RooAbsReal* RooProfileLL::createProfile(const RooArgSet& paramsOfInterest)
{
return nll().createProfile(paramsOfInterest) ;
}
Double_t RooProfileLL::evaluate() const
{
if (!_minuit) {
coutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") Creating instance of MINUIT" << endl ;
_minuit = new RooMinuit(const_cast<RooAbsReal&>(_nll.arg())) ;
_minuit->setPrintLevel(-999) ;
_minuit->setNoWarn() ;
}
RooArgSet* obsSetOrig = (RooArgSet*) _obs.snapshot() ;
validateAbsMin() ;
const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",kTRUE) ;
ccoutP(Eval) << "." ; ccoutP(Eval).flush() ;
if (_startFromMin) {
const_cast<RooProfileLL&>(*this)._par = _paramAbsMin ;
}
_minuit->migrad() ;
TIterator* iter = obsSetOrig->createIterator() ;
RooRealVar* var ;
while((var=(RooRealVar*)iter->Next())) {
RooRealVar* target = (RooRealVar*) _obs.find(var->GetName()) ;
target->setVal(var->getVal()) ;
target->setConstant(var->isConstant()) ;
}
delete iter ;
delete obsSetOrig ;
return _nll - _absMin ;
}
void RooProfileLL::validateAbsMin() const
{
if (_absMinValid) {
_piter->Reset() ;
RooAbsArg* par ;
while((par=(RooAbsArg*)_piter->Next())) {
if (_paramFixed[par->GetName()] != par->isConstant()) {
cxcoutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") constant status of parameter " << par->GetName() << " has changed from "
<< (_paramFixed[par->GetName()]?"fixed":"floating") << " to " << (par->isConstant()?"fixed":"floating")
<< ", recalculating absolute minimum" << endl ;
_absMinValid = kFALSE ;
break ;
}
}
}
if (!_absMinValid) {
cxcoutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") determining minimum likelihood for current configurations w.r.t all observable" << endl ;
const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",kFALSE) ;
_minuit->migrad() ;
_absMin = _nll ;
_absMinValid = kTRUE ;
_paramAbsMin.removeAll() ;
_paramAbsMin.addClone(_par) ;
_piter->Reset() ;
RooAbsArg* par ;
while((par=(RooAbsArg*)_piter->Next())) {
_paramFixed[par->GetName()] = par->isConstant() ;
}
if (dologI(Minimization)) {
cxcoutI(Minimization) << "RooProfileLL::evaluate(" << GetName() << ") minimum found at (" ;
RooAbsReal* arg ;
Bool_t first=kTRUE ;
_oiter->Reset() ;
while ((arg=(RooAbsReal*)_oiter->Next())) {
ccxcoutI(Minimization) << (first?"":", ") << arg->GetName() << "=" << arg->getVal() ;
first=kFALSE ;
}
ccxcoutI(Minimization) << ")" << endl ;
}
}
}
Last change: Fri Nov 21 10:53:32 2008
Last generated: 2008-11-21 10:53
This page has been automatically generated. If you have any comments or suggestions about the page layout send a mail to ROOT support, or contact the developers with any questions or problems regarding ROOT.