#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& nll, const RooArgSet& observables) :
RooAbsReal(name,title),
_nll("nll","-log(L) function",this,nll),
_obs("obs","observables",this),
_par("par","parameters",this,kFALSE,kFALSE),
_minuit(0),
_absMinValid(kFALSE),
_absMin(0)
{
RooArgSet* actualObs = nll.getObservables(observables) ;
RooArgSet* actualPars = nll.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),
_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 ;
}
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() ;
}
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 ;
}
}
}
RooArgSet* obsSetOrig = (RooArgSet*) _obs.snapshot() ;
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 ;
_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 ;
}
}
const_cast<RooSetProxy&>(_obs).setAttribAll("Constant",kTRUE) ;
ccoutW(Eval) << "." ; ccoutW(Eval).flush() ;
_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 ;
}
Last update: Thu Jan 17 08:45:37 2008
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.