56 #include "TDirectory.h" 72 #if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3) 123 _handleLocalErrors =
kTRUE ;
125 _printEvalErrors = 10 ;
128 _doEvalErrorWall =
kTRUE ;
136 if (_floatParamList->getSize()>1) {
137 _floatParamList->
sort() ;
139 _floatParamList->setName(
"floatParamList") ;
142 if (_constParamList->getSize()>1) {
143 _constParamList->
sort() ;
145 _constParamList->setName(
"constParamList") ;
148 TIterator* pIter = _floatParamList->createIterator() ;
153 <<
" from list because it is not of type RooRealVar" << endl ;
154 _floatParamList->remove(*arg) ;
157 _nPar = _floatParamList->getSize() ;
167 Int_t nPar= _floatParamList->getSize() + _constParamList->getSize() ;
168 if (_theFitter)
delete _theFitter ;
169 _theFitter =
new TFitter(nPar*2+1) ;
170 _theFitter->SetObjectFit(
this) ;
180 setErrorLevel(
function.defaultErrorLevel()) ;
206 delete _floatParamList ;
207 delete _initFloatParamList ;
208 delete _constParamList ;
209 delete _initConstParamList ;
226 _theFitter->ExecuteCommand(
"SET STR",&stratArg,1) ;
239 _theFitter->ExecuteCommand(
"SET ERR",&level,1);
249 _theFitter->ExecuteCommand(
"SET EPS",&eps,1) ;
259 _func->enableOffsetting(flag) ;
277 if (_floatParamList->getSize()==0) {
281 _theFitter->SetObjectFit(
this) ;
287 if (opts.
Contains(
"v")) setVerbose(1) ;
288 if (opts.
Contains(
"t")) setProfile(1) ;
289 if (opts.
Contains(
"l")) setLogFile(
Form(
"%s.log",_func->GetName())) ;
290 if (opts.
Contains(
"c")) optimizeConst(1) ;
294 if (opts.
Contains(
"0")) setStrategy(0) ;
296 if (opts.
Contains(
"0")) setStrategy(1) ;
300 return (opts.
Contains(
"r")) ? save() : 0 ;
313 if (_floatParamList->getSize()==0) {
317 _theFitter->SetObjectFit(
this) ;
320 arglist[0]= _maxEvalMult*_nPar;
323 synchronize(_verbose) ;
327 _status= _theFitter->ExecuteCommand(
"MIGRAD",arglist,2);
332 saveStatus(
"MIGRAD",_status) ;
347 if (_floatParamList->getSize()==0) {
351 _theFitter->SetObjectFit(
this) ;
354 arglist[0]= _maxEvalMult*_nPar;
356 synchronize(_verbose) ;
360 _status= _theFitter->ExecuteCommand(
"HESSE",arglist,1);
365 saveStatus(
"HESSE",_status) ;
380 if (_floatParamList->getSize()==0) {
384 _theFitter->SetObjectFit(
this) ;
387 arglist[0]= _maxEvalMult*_nPar;
389 synchronize(_verbose) ;
393 _status= _theFitter->ExecuteCommand(
"MINOS",arglist,1);
405 saveStatus(
"MINOS",_status) ;
420 if (_floatParamList->getSize()==0) {
424 _theFitter->SetObjectFit(
this) ;
429 if (minosParamList.
getSize()>0) {
435 Int_t index = _floatParamList->index(par);
437 arglist[nMinosPar]=index+1;
442 arglist[0]= _maxEvalMult*_nPar;
444 synchronize(_verbose) ;
448 _status= _theFitter->ExecuteCommand(
"MINOS",arglist,1+nMinosPar);
461 saveStatus(
"MINOS",_status) ;
476 if (_floatParamList->getSize()==0) {
480 _theFitter->SetObjectFit(
this) ;
483 arglist[0]= _maxEvalMult*_nPar;
485 synchronize(_verbose) ;
489 _status= _theFitter->ExecuteCommand(
"SEEK",arglist,1);
494 saveStatus(
"SEEK",_status) ;
509 if (_floatParamList->getSize()==0) {
513 _theFitter->SetObjectFit(
this) ;
516 arglist[0]= _maxEvalMult*_nPar;
519 synchronize(_verbose) ;
523 _status= _theFitter->ExecuteCommand(
"SIMPLEX",arglist,2);
528 saveStatus(
"SIMPLEX",_status) ;
543 if (_floatParamList->getSize()==0) {
547 _theFitter->SetObjectFit(
this) ;
550 arglist[0]= _maxEvalMult*_nPar;
552 synchronize(_verbose) ;
556 _status= _theFitter->ExecuteCommand(
"IMPROVE",arglist,1);
561 saveStatus(
"IMPROVE",_status) ;
573 Int_t ret = _printLevel ;
575 _theFitter->ExecuteCommand(
"SET PRINT",&arg,1);
576 _printLevel = newLevel ;
588 _theFitter->ExecuteCommand(
"SET NOWARNINGS",&arg,1);
599 if (newLevel==_warnLevel) {
603 Int_t ret = _warnLevel ;
607 _theFitter->ExecuteCommand(
"SET WARNINGS",&arg,1);
610 _theFitter->ExecuteCommand(
"SET NOWARNINGS",&arg2,1);
612 _warnLevel = newLevel ;
625 Int_t oldPrint = setPrintLevel(-1) ;
627 Int_t oldWarn = setWarnLevel(-1) ;
635 for(index= 0; index < _constParamList->getSize() ; index++) {
646 _constParamList->remove(*par) ;
647 _floatParamList->add(*par) ;
648 _initFloatParamList->addClone(*oldpar) ;
649 _initConstParamList->remove(*oldpar) ;
650 constStatChange=
kTRUE ;
660 constValChange=
kTRUE ;
663 <<
" changed from " << oldpar->
getVal() <<
" to " << par->
getVal() << endl ;
670 *_initConstParamList = *_constParamList ;
674 for(index= 0; index < _nPar; index++) {
687 <<
" is not of type RooRealVar, skipping" << endl ;
702 pstep= 0.1*(pmax-pmin);
705 if (pmax - par->
getVal() < 2*pstep) {
706 pstep = (pmax - par->
getVal())/2 ;
707 }
else if (par->
getVal() - pmin < 2*pstep) {
708 pstep = (par->
getVal() - pmin )/2 ;
713 pstep= 0.1*(pmax-pmin);
720 coutW(
Minimization) <<
"RooMinuit::synchronize: WARNING: no initial error estimate available for " 721 << par->
GetName() <<
": using " << pstep << endl;
730 Double_t oldVar,oldVerr,oldVlo,oldVhi ;
731 char oldParname[100] ;
732 Int_t ierr = _theFitter->GetParameter(index,oldParname,oldVar,oldVerr,oldVlo,oldVhi) ;
747 if (oldVar!=par->
getVal()) {
749 arglist[0] = index+1 ;
750 arglist[1] = par->
getVal() ;
751 _theFitter->ExecuteCommand(
"SET PAR",arglist,2) ;
753 coutI(
Minimization) <<
"RooMinuit::synchronize: value of parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
757 _theFitter->FixParameter(index) ;
758 constStatChange=
kTRUE ;
766 if (oldVar!=par->
getVal()) {
768 arglist[0] = index+1 ;
769 arglist[1] = par->
getVal() ;
770 _theFitter->ExecuteCommand(
"SET PAR",arglist,2) ;
771 constValChange=
kTRUE ;
774 coutI(
Minimization) <<
"RooMinuit::synchronize: value of fixed parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
781 _theFitter->ReleaseParameter(index) ;
782 constStatChange=
kTRUE ;
790 if (oldVar!=par->
getVal() || oldVlo!=pmin || oldVhi != pmax || oldVerr!=pstep) {
791 _theFitter->SetParameter(index, par->
GetName(), par->
getVal(), pstep, pmin, pmax);
795 if (verbose && ierr>=0) {
798 if (oldVar!=par->
getVal()) {
799 coutI(
Minimization) <<
"RooMinuit::synchronize: value of parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
801 if (oldVlo!=pmin || oldVhi!=pmax) {
802 coutI(
Minimization) <<
"RooMinuit::synchronize: limits of parameter " << par->
GetName() <<
" changed from [" << oldVlo <<
"," << oldVhi
803 <<
"] to [" << pmin <<
"," << pmax <<
"]" << endl ;
807 if (oldVerr!=pstep && oldVerr!=0) {
808 coutI(
Minimization) <<
"RooMinuit::synchronize: error/step size of parameter " << par->
GetName() <<
" changed from " << oldVerr <<
" to " << pstep << endl ;
816 oldWarn = setWarnLevel(oldWarn) ;
817 oldPrint = setPrintLevel(oldPrint) ;
820 if (constStatChange) {
824 coutI(
Minimization) <<
"RooMinuit::synchronize: set of constant parameters changed, rerunning const optimizer" << endl ;
826 }
else if (constValChange) {
827 coutI(
Minimization) <<
"RooMinuit::synchronize: constant parameter values changed, rerunning const optimizer" << endl ;
851 if (_optConst && !flag){
852 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: deactivating const optimization" << endl ;
855 }
else if (!_optConst && flag) {
856 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: activating const optimization" << endl ;
859 }
else if (_optConst && flag) {
860 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: const optimization already active" << endl ;
862 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: const optimization wasn't active" << endl ;
882 name = userName ? userName :
Form(
"%s", _func->GetName()) ;
883 title = userTitle ? userTitle :
Form(
"%s", _func->GetTitle()) ;
885 if (_floatParamList->getSize()==0) {
903 RooArgList saveFloatInitList(*_initFloatParamList) ;
904 RooArgList saveFloatFinalList(*_floatParamList) ;
905 for (i=0 ; i<_floatParamList->getSize() ; i++) {
909 saveFloatFinalList.
remove(*par) ;
910 saveConstList.
add(*par) ;
913 saveConstList.
sort() ;
920 Int_t icode = _theFitter->GetStats(minVal, edm, errdef, nvpar, nparx);
948 _theFitter->SetObjectFit(
this) ;
953 Int_t index1= _floatParamList->index(&var1);
956 <<
") ERROR: " << var1.
GetName() <<
" is not a floating parameter of " << _func->GetName() << endl ;
960 Int_t index2= _floatParamList->index(&var2);
963 <<
") ERROR: " << var2.
GetName() <<
" is not a floating parameter of PDF " << _func->GetName() << endl ;
978 n[0] = n1 ; n[1] = n2 ; n[2] = n3 ; n[3] = n4 ; n[4] = n5 ; n[5] = n6 ;
981 for (
Int_t ic = 0 ; ic<6 ; ic++) {
988 coutE(
Minimization) <<
"RooMinuit::contour(" << GetName() <<
") ERROR: MINUIT did not return a contour graph for n=" << n[ic] << endl ;
990 graph->
SetName(
Form(
"contour_%s_n%f",_func->GetName(),n[ic])) ;
1003 *_floatParamList = *paramSave ;
1020 coutI(
Minimization) <<
"RooMinuit::setLogFile: closing previous log file" << endl ;
1025 _logfile =
new ofstream(inLogfile) ;
1026 if (!_logfile->good()) {
1027 coutI(
Minimization) <<
"RooMinuit::setLogFile: cannot open file " << inLogfile << endl ;
1042 return ((
RooRealVar*)_floatParamList->at(index))->getVal() ;
1052 return ((
RooRealVar*)_floatParamList->at(index))->getError() ;
1066 if (verbose) cout << par->
GetName() <<
"=" << value <<
", " ;
1081 ((
RooRealVar*)_floatParamList->at(index))->setError(value) ;
1091 ((
RooRealVar*)_floatParamList->at(index))->removeAsymError() ;
1100 ((
RooRealVar*)_floatParamList->at(index))->setAsymError(loVal,hiVal) ;
1112 _cumulTimer.Start(
kFALSE) ;
1126 _cumulTimer.Stop() ;
1141 Double_t val,err,vlo,vhi, eplus, eminus, eparab, globcc;
1144 for(index= 0; index < _nPar; index++) {
1145 _theFitter->GetParameter(index, buffer, val, err, vlo, vhi);
1146 setPdfParamVal(index, val);
1147 _theFitter->GetErrors(index, eplus, eminus, eparab, globcc);
1150 setPdfParamErr(index, err);
1152 if(eplus > 0 || eminus < 0) {
1154 setPdfParamErr(index, eminus,eplus);
1157 clearPdfParamAsymErr(index) ;
1167 _floatParamVec.clear() ;
1168 RooFIter iter = _floatParamList->fwdIterator() ;
1170 _floatParamVec.resize(_floatParamList->getSize()) ;
1172 while((arg=iter.
next())) {
1173 _floatParamVec[i++] = arg ;
1188 for (
Int_t i=0 ; i<getNPar() ; i++) {
1190 if (_floatParamList->at(i)->isConstant()) {
1195 cout <<
"setting parameter " << i <<
" error to " <<
sqrt((*_extV)(i,i)) << endl ;
1196 setPdfParamErr(i,
sqrt((*_extV)(i,i))) ;
1211 ofstream* logf = context->
logfile() ;
1217 for(
Int_t index= 0; index < nPar; index++) {
1218 if (logf) (*logf) << par[index] <<
" " ;
1232 oocoutW(context,
Minimization) <<
"RooMinuitGlue: Minimized function has error status." << endl
1233 <<
"Returning maximum FCN so far (" << maxFCN
1234 <<
") to force MIGRAD to back out of this region. Error log follows" << endl ;
1236 oocoutW(context,
Minimization) <<
"RooMinuitGlue: Minimized function has error status but is ignored" << endl ;
1261 }
else if (f>maxFCN) {
1266 if (logf) (*logf) << setprecision(15) << f << setprecision(4) << endl;
1268 cout <<
"\nprevFCN" << (context->
_func->
isOffsetting()?
"-offset":
"") <<
" = " << setprecision(10) << f << setprecision(4) <<
" " ;
virtual Double_t getMin(const char *name=0) const
virtual const char * GetName() const
Returns name of object.
virtual void SetLineWidth(Width_t lwidth)
TIterator * createIterator(Bool_t dir=kIterForward) const
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Int_t seek()
Execute SEEK.
void sort(Bool_t reverse=kFALSE)
Bool_t hasMin(const char *name=0) const
virtual Double_t getMax(const char *name=0) const
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...
void sort(Bool_t ascend=kTRUE)
Int_t simplex()
Execute SIMPLEX.
void setStatusHistory(std::vector< std::pair< std::string, int > > &hist)
void addObject(TObject *obj, Option_t *drawOptions="", Bool_t invisible=kFALSE)
Add a generic object to this plot.
Int_t hesse()
Execute HESSE.
Double_t getVal(const RooArgSet *set=0) const
virtual void SetName(const char *name)
Change (i.e.
Bool_t synchronize(Bool_t verbose)
Internal function to synchronize TMinuit with current information in RooAbsReal function parameters...
void setNumInvalidNLL(Int_t val)
Int_t minos()
Execute MINOS.
void setStatus(Int_t val)
Bool_t hasMax(const char *name=0) const
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
void ToLower()
Change string to lower-case.
void setEps(Double_t eps)
Change MINUIT epsilon.
static RooMsgService & instance()
Return reference to singleton instance.
Int_t migrad()
Execute MIGRAD.
void setStrategy(Int_t strat)
Change MINUIT strategy to istrat.
void setInitParList(const RooArgList &list)
Fill the list of initial values of the floating parameters.
static void setHideOffset(Bool_t flag)
Double_t getPdfParamVal(Int_t index)
Access PDF parameter value by ordinal index (needed by MINUIT)
void profileStop()
Stop profiling timer and report results of last session.
Iterator abstract base class.
void setEDM(Double_t val)
void setErrorLevel(Double_t level)
Set the level for MINUIT error analysis to the given value.
R__EXTERN TMinuit * gMinuit
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
void applyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
virtual Bool_t setPdfParamVal(Int_t index, Double_t value, Bool_t verbose=kFALSE)
Modify PDF parameter value by ordinal index (needed by MINUIT)
Int_t setPrintLevel(Int_t newLevel)
Change the MINUIT internal printing level.
virtual TObject * Contour(Int_t npoints=10, Int_t pa1=0, Int_t pa2=1)
Creates a TGraph object describing the n-sigma contour of a TMinuit fit.
RooAbsCollection * selectByAttrib(const char *name, Bool_t value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
if on multiple lines(like in C++). **The " * configuration fragment. * * The "import myobject continue
Parses the configuration file.
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
static void clearEvalError()
Clear the evaluation error flag.
void setMinNLL(Double_t val)
virtual void setVal(Double_t value)
Set value of variable to 'value'.
virtual void SetLineColor(Color_t lcolor)
Double_t getPdfParamErr(Int_t index)
Access PDF parameter error by ordinal index (needed by MINUIT)
void function(const char *name_, T fun, const char *docstring=0)
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
void setOffsetting(Bool_t flag)
Enable internal likelihood offsetting for enhanced numeric precision.
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
static void cleanup()
Cleanup method called by atexit handler installed by RooSentinel to delete all global heap objects wh...
char * Form(const char *fmt,...)
virtual Int_t SetErrorDef(Double_t up)
To get the n-sigma contour the error def parameter "up" has to set to n^2.
void setFinalParList(const RooArgList &list)
Fill the list of final values of the floating parameters.
static void printEvalErrors(std::ostream &os=std::cout, Int_t maxPerNode=10000000)
Print all outstanding logged evaluation error on the given ostream.
RooArgList * _floatParamList
virtual ~RooMinuit()
Destructor.
Int_t setWarnLevel(Int_t newLevel)
Set MINUIT warning level to given level.
RooMinuit(RooAbsReal &function)
Construct MINUIT interface to given function.
static void activate()
Install atexit handler that calls CleanupRooFitAtExit() on program termination.
void setConstParList(const RooArgList &list)
Fill the list of constant parameters.
void RooMinuitGlue(Int_t &, Double_t *, Double_t &f, Double_t *par, Int_t)
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...
RooFitResult * save(const char *name=0, const char *title=0)
Save and return a RooFitResult snaphot of current minimizer status.
void clearPdfParamAsymErr(Int_t index)
Modify PDF parameter error by ordinal index (needed by MINUIT)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
virtual void SetLineStyle(Style_t lstyle)
Abstract Base Class for Fitting.
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.
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
void profileStart()
Start profiling timer.
static Bool_t evalError()
Return the evaluation error flag.
virtual TObject * Next()=0
A Graph is a graphics object made of two arrays X and Y with npoints each.
void setPdfParamErr(Int_t index, Double_t value)
Modify PDF parameter error by ordinal index (needed by MINUIT)
void setCovQual(Int_t val)
Bool_t setLogFile(const char *logfile=0)
Change the file name for logging of a RooMinuit of all MINUIT steppings through the parameter space...
void setNoWarn()
Instruct MINUIT to suppress warnings.
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...
Double_t getError() const
void backProp()
Transfer MINUIT fit results back into RooFit objects.
Int_t improve()
Execute IMPROVE.
virtual Bool_t isOffsetting() const
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
Bool_t isConstant() const
std::ofstream * logfile() const
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.