39 #ifndef __ROOFIT_NOROOMINIMIZER 73 #if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3) 124 _minimizerType =
"Minuit";
126 if (_theFitter)
delete _theFitter ;
129 _theFitter->Config().SetMinimizer(_minimizerType.c_str());
132 _theFitter->Config().MinimizerOptions().SetMaxIterations(500*_fcn->NDim());
133 _theFitter->Config().MinimizerOptions().SetMaxFunctionCalls(500*_fcn->NDim());
139 setErrorLevel(_func->defaultErrorLevel()) ;
142 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
143 _optConst,_verbose) ;
180 _theFitter->Config().MinimizerOptions().SetStrategy(istrat);
192 _theFitter->Config().MinimizerOptions().SetMaxIterations(n);
204 _theFitter->Config().MinimizerOptions().SetMaxFunctionCalls(n);
218 _theFitter->Config().MinimizerOptions().SetErrorDef(level);
229 _theFitter->Config().MinimizerOptions().SetTolerance(eps);
239 _func->enableOffsetting(flag) ;
250 _minimizerType =
type;
288 TString opts(options) ;
292 if (opts.Contains(
"v")) setVerbose(1) ;
293 if (opts.Contains(
"t")) setProfile(1) ;
294 if (opts.Contains(
"l")) setLogFile(
Form(
"%s.log",_func->GetName())) ;
295 if (opts.Contains(
"c")) optimizeConst(1) ;
298 if (opts.Contains(
"0")) setStrategy(0) ;
300 if (opts.Contains(
"0")) setStrategy(1) ;
301 if (opts.Contains(
"h")||!opts.Contains(
"m")) hesse() ;
302 if (!opts.Contains(
"m")) minos() ;
304 return (opts.Contains(
"r")) ? save() : 0 ;
314 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
315 _optConst,_verbose) ;
317 _theFitter->Config().SetMinimizer(type,alg);
323 bool ret = _theFitter->FitFCN(*_fcn);
324 _status = ((ret) ? _theFitter->Result().Status() : -1);
328 _fcn->BackProp(_theFitter->Result());
330 saveStatus(
"MINIMIZE",_status) ;
345 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
346 _optConst,_verbose) ;
351 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),
"migrad");
352 bool ret = _theFitter->FitFCN(*_fcn);
353 _status = ((ret) ? _theFitter->Result().Status() : -1);
357 _fcn->BackProp(_theFitter->Result());
359 saveStatus(
"MIGRAD",_status) ;
374 if (_theFitter->GetMinimizer()==0) {
381 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
382 _optConst,_verbose) ;
387 _theFitter->Config().SetMinimizer(_minimizerType.c_str());
388 bool ret = _theFitter->CalculateHessErrors();
389 _status = ((ret) ? _theFitter->Result().Status() : -1);
393 _fcn->BackProp(_theFitter->Result());
395 saveStatus(
"HESSE",_status) ;
411 if (_theFitter->GetMinimizer()==0) {
418 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
419 _optConst,_verbose) ;
424 _theFitter->Config().SetMinimizer(_minimizerType.c_str());
425 bool ret = _theFitter->CalculateMinosErrors();
426 _status = ((ret) ? _theFitter->Result().Status() : -1);
430 _fcn->BackProp(_theFitter->Result());
432 saveStatus(
"MINOS",_status) ;
449 if (_theFitter->GetMinimizer()==0) {
454 else if (minosParamList.
getSize()>0) {
456 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
457 _optConst,_verbose) ;
465 std::vector<unsigned int> paramInd;
469 Int_t index = _fcn->GetFloatParamList()->index(par);
470 paramInd.push_back(index);
475 if (paramInd.size()) {
477 _theFitter->Config().SetMinosErrors(paramInd);
479 _theFitter->Config().SetMinimizer(_minimizerType.c_str());
480 bool ret = _theFitter->CalculateMinosErrors();
481 _status = ((ret) ? _theFitter->Result().Status() : -1);
483 _theFitter->Config().SetMinosErrors(
kFALSE);
489 _fcn->BackProp(_theFitter->Result());
491 saveStatus(
"MINOS",_status) ;
508 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
509 _optConst,_verbose) ;
514 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),
"seek");
515 bool ret = _theFitter->FitFCN(*_fcn);
516 _status = ((ret) ? _theFitter->Result().Status() : -1);
520 _fcn->BackProp(_theFitter->Result());
522 saveStatus(
"SEEK",_status) ;
537 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
538 _optConst,_verbose) ;
543 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),
"simplex");
544 bool ret = _theFitter->FitFCN(*_fcn);
545 _status = ((ret) ? _theFitter->Result().Status() : -1);
549 _fcn->BackProp(_theFitter->Result());
551 saveStatus(
"SEEK",_status) ;
566 _fcn->Synchronize(_theFitter->Config().ParamsSettings(),
567 _optConst,_verbose) ;
572 _theFitter->Config().SetMinimizer(_minimizerType.c_str(),
"migradimproved");
573 bool ret = _theFitter->FitFCN(*_fcn);
574 _status = ((ret) ? _theFitter->Result().Status() : -1);
578 _fcn->BackProp(_theFitter->Result());
580 saveStatus(
"IMPROVE",_status) ;
592 Int_t ret = _printLevel ;
593 _theFitter->Config().MinimizerOptions().SetPrintLevel(newLevel+1);
594 _printLevel = newLevel+1 ;
606 if (_optConst && !flag){
607 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinimizer::optimizeConst: deactivating const optimization" << endl ;
610 }
else if (!_optConst && flag) {
611 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinimizer::optimizeConst: activating const optimization" << endl ;
614 }
else if (_optConst && flag) {
615 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinimizer::optimizeConst: const optimization already active" << endl ;
617 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinimizer::optimizeConst: const optimization wasn't active" << endl ;
636 if (_theFitter->GetMinimizer()==0) {
643 name = userName ? userName :
Form(
"%s", _func->GetName()) ;
644 title = userTitle ? userTitle :
Form(
"%s", _func->GetTitle()) ;
649 RooArgList saveConstList(*(_fcn->GetConstParamList())) ;
650 RooArgList saveFloatInitList(*(_fcn->GetInitFloatParamList())) ;
651 RooArgList saveFloatFinalList(*(_fcn->GetFloatParamList())) ;
652 for (i=0 ; i<_fcn->GetFloatParamList()->getSize() ; i++) {
653 RooAbsArg* par = _fcn->GetFloatParamList()->at(i) ;
656 saveFloatFinalList.
remove(*par) ;
657 saveConstList.
add(*par) ;
660 saveConstList.
sort() ;
662 fitRes->setConstParList(saveConstList) ;
663 fitRes->setInitParList(saveFloatInitList) ;
665 fitRes->setStatus(_status) ;
666 fitRes->setCovQual(_theFitter->GetMinimizer()->CovMatrixStatus()) ;
667 fitRes->setMinNLL(_theFitter->Result().MinFcnValue()) ;
668 fitRes->setNumInvalidNLL(_fcn->GetNumInvalidNLL()) ;
669 fitRes->setEDM(_theFitter->Result().Edm()) ;
670 fitRes->setFinalParList(saveFloatFinalList) ;
672 std::vector<double> globalCC;
673 TMatrixDSym corrs(_theFitter->Result().Parameters().size()) ;
674 TMatrixDSym covs(_theFitter->Result().Parameters().size()) ;
675 for (
UInt_t ic=0; ic<_theFitter->Result().Parameters().size(); ic++) {
676 globalCC.push_back(_theFitter->Result().GlobalCC(ic));
677 for (
UInt_t ii=0; ii<_theFitter->Result().Parameters().size(); ii++) {
678 corrs(ic,ii) = _theFitter->Result().Correlation(ic,ii);
679 covs(ic,ii) = _theFitter->Result().CovMatrix(ic,ii);
682 fitRes->fillCorrMatrix(globalCC,corrs,covs) ;
684 fitRes->setCovarianceMatrix(*_extV) ;
687 fitRes->setStatusHistory(_statusHistory) ;
703 RooArgList* params = _fcn->GetFloatParamList() ;
707 Int_t index1= _fcn->GetFloatParamList()->index(&var1);
710 <<
") ERROR: " << var1.
GetName()
711 <<
" is not a floating parameter of " 712 << _func->GetName() << endl ;
716 Int_t index2= _fcn->GetFloatParamList()->index(&var2);
719 <<
") ERROR: " << var2.
GetName()
720 <<
" is not a floating parameter of PDF " 721 << _func->GetName() << endl ;
734 if (_theFitter->GetMinimizer()==0) {
735 coutW(
Minimization) <<
"RooMinimizer::contour: Error, run Migrad before contours!" 742 Double_t errdef= _theFitter->GetMinimizer()->ErrorDef();
745 n[0] = n1 ; n[1] = n2 ; n[2] = n3 ; n[3] = n4 ; n[4] = n5 ; n[5] = n6 ;
746 unsigned int npoints(50);
748 for (
Int_t ic = 0 ; ic<6 ; ic++) {
752 _theFitter->GetMinimizer()->SetErrorDef(n[ic]*n[ic]*errdef);
757 bool ret = _theFitter->GetMinimizer()->Contour(index1,index2,npoints,xcoor,ycoor);
762 <<
") ERROR: MINUIT did not return a contour graph for n=" 765 xcoor[npoints] = xcoor[0];
766 ycoor[npoints] = ycoor[0];
769 graph->
SetName(
Form(
"contour_%s_n%f",_func->GetName(),n[ic])) ;
783 _theFitter->Config().MinimizerOptions().SetErrorDef(errdef);
786 *params = *paramSave ;
802 _profileStart =
kTRUE ;
832 _fcn->ApplyCovarianceMatrix(*_extV);
843 if (_theFitter==0 || _theFitter->GetMinimizer()==0) {
850 if (varList.
getSize()>0 && varList.
getSize()!=
Int_t(_theFitter->Result().NTotalParameters())) {
852 <<
"RooMinimizer::lastMinuitFit: ERROR: supplied variable list must be either empty " << endl
853 <<
" or match the number of variables of the last fit (" 854 << _theFitter->Result().NTotalParameters() <<
")" << endl ;
863 if (!dynamic_cast<RooRealVar*>(arg)) {
865 << arg->
GetName() <<
"' is not of type RooRealVar" << endl ;
879 for (i = 0; i < _theFitter->Result().NTotalParameters(); ++i) {
881 TString varName(_theFitter->Result().GetParameterName(i));
882 Bool_t isConst(_theFitter->Result().IsParameterFixed(i)) ;
884 Double_t xlo = _theFitter->Config().ParSettings(i).LowerLimit();
885 Double_t xhi = _theFitter->Config().ParSettings(i).UpperLimit();
886 Double_t xerr = _theFitter->Result().Error(i);
887 Double_t xval = _theFitter->Result().Value(i);
892 if ((xlo<xhi) && !isConst) {
893 var =
new RooRealVar(varName,varName,xval,xlo,xhi) ;
907 if (varName.CompareTo(var->
GetName())) {
908 oocoutI((
TObject*)0,
Eval) <<
"RooMinimizer::lastMinuitFit: fit parameter '" << varName
909 <<
"' stored in variable '" << var->
GetName() <<
"'" << endl ;
925 res->
setMinNLL(_theFitter->Result().MinFcnValue()) ;
926 res->
setEDM(_theFitter->Result().Edm()) ;
927 res->
setCovQual(_theFitter->GetMinimizer()->CovMatrixStatus()) ;
928 res->
setStatus(_theFitter->Result().Status()) ;
929 std::vector<double> globalCC;
930 TMatrixDSym corrs(_theFitter->Result().Parameters().size()) ;
931 TMatrixDSym covs(_theFitter->Result().Parameters().size()) ;
932 for (
UInt_t ic=0; ic<_theFitter->Result().Parameters().size(); ic++) {
933 globalCC.push_back(_theFitter->Result().GlobalCC(ic));
934 for (
UInt_t ii=0; ii<_theFitter->Result().Parameters().size(); ii++) {
935 corrs(ic,ii) = _theFitter->Result().Correlation(ic,ii);
936 covs(ic,ii) = _theFitter->Result().CovMatrix(ic,ii);
virtual const char * GetName() const
Returns name of object.
std::string GetName(const std::string &scope_name)
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
TIterator * createIterator(Bool_t dir=kIterForward) const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
void sort(Bool_t reverse=kFALSE)
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
Int_t seek()
Execute SEEK.
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
virtual ~RooMinimizer()
Destructor.
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
virtual Bool_t addOwned(RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Double_t getVal(const RooArgSet *set=0) const
Int_t improve()
Execute IMPROVE.
void setStatus(Int_t val)
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
virtual TObject * Clone(const char *newname=0) const
Make a clone of an object using the Streamer facility.
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
static RooMsgService & instance()
Return reference to singleton instance.
void setInitParList(const RooArgList &list)
Fill the list of initial values of the floating parameters.
Iterator abstract base class.
void setMinimizerType(const char *type)
Choose the minimzer algorithm.
void setEps(Double_t eps)
Change MINUIT epsilon.
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
void setEDM(Double_t val)
Int_t simplex()
Execute SIMPLEX.
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
Bool_t silentMode() const
virtual void SetName(const char *name="")
Set graph name.
RooMinimizer(RooAbsReal &function)
Construct MINUIT interface to given function.
void function(const Char_t *name_, T fun, const Char_t *docstring=0)
void setMaxIterations(Int_t n)
Change maximum number of MINUIT iterations (RooMinimizer default 500 * #parameters) ...
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
RooRealVar represents a fundamental (non-derived) real valued object.
void setMinNLL(Double_t val)
virtual void setVal(Double_t value)
Set value of variable to 'value'.
virtual void SetLineColor(Color_t lcolor)
Set the line color.
void setMaxFunctionCalls(Int_t n)
Change maximum number of likelihood function calss from MINUIT (RooMinimizer default 500 * #parameter...
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
RooAbsArg * at(Int_t idx) const
void setConstant(Bool_t value=kTRUE)
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snaphot of current minimizer status.
Fitter class, entry point for performing all type of fits.
char * Form(const char *fmt,...)
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
Int_t migrad()
Execute MIGRAD.
A RooPlot is a plot frame and a container for graphics objects within that frame. ...
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
void setConstParList(const RooArgList &list)
Fill the list of constant parameters.
RooAbsArg * find(const char *name) const
Find object with given name in list.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
Int_t minos()
Execute MINOS.
void setErrorLevel(Double_t level)
Set the level for MINUIT error analysis to the given value.
Int_t minimize(const char *type, const char *alg=0)
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
void profileStop()
Stop profiling timer and report results of last session.
void setRange(const char *name, Double_t min, Double_t max)
Set range named 'name to [min,max].
Mother of all ROOT objects.
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
Int_t hesse()
Execute HESSE.
RooPlot * contour(RooRealVar &var1, RooRealVar &var2, Double_t n1=1, Double_t n2=2, Double_t n3=0, Double_t n4=0, Double_t n5=0, Double_t n6=0)
Create and draw a TH2 with the error contours in parameters var1 and v2 at up to 6 'sigma' settings w...
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
virtual TObject * Next()=0
A Graph is a graphics object made of two arrays X and Y with npoints each.
void setCovQual(Int_t val)
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
static ROOT::Fit::Fitter * _theFitter
RooAbsArg is the common abstract base class for objects that represent a value (of arbitrary type) an...
void fillCorrMatrix()
Internal utility method to extract the correlation matrix and the global correlation coefficients fro...
void setOffsetting(Bool_t flag)
Enable internal likelihood offsetting for enhanced numeric precision.
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
static RooFitResult * lastMinuitFit(const RooArgList &varList=RooArgList())
void profileStart()
Start profiling timer.
Bool_t isConstant() const
void setError(Double_t value)