70 #if (__GNUC__==3&&__GNUC_MINOR__==2&&__GNUC_PATCHLEVEL__==3) 121 _handleLocalErrors =
kTRUE ;
123 _printEvalErrors = 10 ;
126 _doEvalErrorWall =
kTRUE ;
134 if (_floatParamList->getSize()>1) {
135 _floatParamList->
sort() ;
137 _floatParamList->setName(
"floatParamList") ;
140 if (_constParamList->getSize()>1) {
141 _constParamList->
sort() ;
143 _constParamList->setName(
"constParamList") ;
146 TIterator* pIter = _floatParamList->createIterator() ;
151 <<
" from list because it is not of type RooRealVar" << endl ;
152 _floatParamList->remove(*arg) ;
155 _nPar = _floatParamList->getSize() ;
165 Int_t nPar= _floatParamList->getSize() + _constParamList->getSize() ;
166 if (_theFitter)
delete _theFitter ;
167 _theFitter =
new TFitter(nPar*2+1) ;
168 _theFitter->SetObjectFit(
this) ;
178 setErrorLevel(
function.defaultErrorLevel()) ;
204 delete _floatParamList ;
205 delete _initFloatParamList ;
206 delete _constParamList ;
207 delete _initConstParamList ;
224 _theFitter->ExecuteCommand(
"SET STR",&stratArg,1) ;
237 _theFitter->ExecuteCommand(
"SET ERR",&level,1);
247 _theFitter->ExecuteCommand(
"SET EPS",&eps,1) ;
257 _func->enableOffsetting(flag) ;
275 if (_floatParamList->getSize()==0) {
279 _theFitter->SetObjectFit(
this) ;
285 if (opts.
Contains(
"v")) setVerbose(1) ;
286 if (opts.
Contains(
"t")) setProfile(1) ;
287 if (opts.
Contains(
"l")) setLogFile(
Form(
"%s.log",_func->GetName())) ;
288 if (opts.
Contains(
"c")) optimizeConst(1) ;
292 if (opts.
Contains(
"0")) setStrategy(0) ;
294 if (opts.
Contains(
"0")) setStrategy(1) ;
298 return (opts.
Contains(
"r")) ? save() : 0 ;
311 if (_floatParamList->getSize()==0) {
315 _theFitter->SetObjectFit(
this) ;
318 arglist[0]= _maxEvalMult*_nPar;
321 synchronize(_verbose) ;
325 _status= _theFitter->ExecuteCommand(
"MIGRAD",arglist,2);
330 saveStatus(
"MIGRAD",_status) ;
345 if (_floatParamList->getSize()==0) {
349 _theFitter->SetObjectFit(
this) ;
352 arglist[0]= _maxEvalMult*_nPar;
354 synchronize(_verbose) ;
358 _status= _theFitter->ExecuteCommand(
"HESSE",arglist,1);
363 saveStatus(
"HESSE",_status) ;
378 if (_floatParamList->getSize()==0) {
382 _theFitter->SetObjectFit(
this) ;
385 arglist[0]= _maxEvalMult*_nPar;
387 synchronize(_verbose) ;
391 _status= _theFitter->ExecuteCommand(
"MINOS",arglist,1);
403 saveStatus(
"MINOS",_status) ;
418 if (_floatParamList->getSize()==0) {
422 _theFitter->SetObjectFit(
this) ;
427 if (minosParamList.
getSize()>0) {
433 Int_t index = _floatParamList->index(par);
435 arglist[nMinosPar]=index+1;
440 arglist[0]= _maxEvalMult*_nPar;
442 synchronize(_verbose) ;
446 _status= _theFitter->ExecuteCommand(
"MINOS",arglist,1+nMinosPar);
459 saveStatus(
"MINOS",_status) ;
474 if (_floatParamList->getSize()==0) {
478 _theFitter->SetObjectFit(
this) ;
481 arglist[0]= _maxEvalMult*_nPar;
483 synchronize(_verbose) ;
487 _status= _theFitter->ExecuteCommand(
"SEEK",arglist,1);
492 saveStatus(
"SEEK",_status) ;
507 if (_floatParamList->getSize()==0) {
511 _theFitter->SetObjectFit(
this) ;
514 arglist[0]= _maxEvalMult*_nPar;
517 synchronize(_verbose) ;
521 _status= _theFitter->ExecuteCommand(
"SIMPLEX",arglist,2);
526 saveStatus(
"SIMPLEX",_status) ;
541 if (_floatParamList->getSize()==0) {
545 _theFitter->SetObjectFit(
this) ;
548 arglist[0]= _maxEvalMult*_nPar;
550 synchronize(_verbose) ;
554 _status= _theFitter->ExecuteCommand(
"IMPROVE",arglist,1);
559 saveStatus(
"IMPROVE",_status) ;
571 Int_t ret = _printLevel ;
573 _theFitter->ExecuteCommand(
"SET PRINT",&arg,1);
574 _printLevel = newLevel ;
586 _theFitter->ExecuteCommand(
"SET NOWARNINGS",&arg,1);
597 if (newLevel==_warnLevel) {
601 Int_t ret = _warnLevel ;
605 _theFitter->ExecuteCommand(
"SET WARNINGS",&arg,1);
608 _theFitter->ExecuteCommand(
"SET NOWARNINGS",&arg2,1);
610 _warnLevel = newLevel ;
623 Int_t oldPrint = setPrintLevel(-1) ;
625 Int_t oldWarn = setWarnLevel(-1) ;
633 for(index= 0; index < _constParamList->getSize() ; index++) {
644 _constParamList->remove(*par) ;
645 _floatParamList->add(*par) ;
646 _initFloatParamList->addClone(*oldpar) ;
647 _initConstParamList->remove(*oldpar) ;
648 constStatChange=
kTRUE ;
658 constValChange=
kTRUE ;
661 <<
" changed from " << oldpar->
getVal() <<
" to " << par->
getVal() << endl ;
668 *_initConstParamList = *_constParamList ;
672 for(index= 0; index < _nPar; index++) {
685 <<
" is not of type RooRealVar, skipping" << endl ;
700 pstep= 0.1*(pmax-pmin);
703 if (pmax - par->
getVal() < 2*pstep) {
704 pstep = (pmax - par->
getVal())/2 ;
705 }
else if (par->
getVal() - pmin < 2*pstep) {
706 pstep = (par->
getVal() - pmin )/2 ;
711 pstep= 0.1*(pmax-pmin);
718 coutW(
Minimization) <<
"RooMinuit::synchronize: WARNING: no initial error estimate available for " 719 << par->
GetName() <<
": using " << pstep << endl;
728 Double_t oldVar,oldVerr,oldVlo,oldVhi ;
729 char oldParname[100] ;
730 Int_t ierr = _theFitter->GetParameter(index,oldParname,oldVar,oldVerr,oldVlo,oldVhi) ;
745 if (oldVar!=par->
getVal()) {
747 arglist[0] = index+1 ;
748 arglist[1] = par->
getVal() ;
749 _theFitter->ExecuteCommand(
"SET PAR",arglist,2) ;
751 coutI(
Minimization) <<
"RooMinuit::synchronize: value of parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
755 _theFitter->FixParameter(index) ;
756 constStatChange=
kTRUE ;
764 if (oldVar!=par->
getVal()) {
766 arglist[0] = index+1 ;
767 arglist[1] = par->
getVal() ;
768 _theFitter->ExecuteCommand(
"SET PAR",arglist,2) ;
769 constValChange=
kTRUE ;
772 coutI(
Minimization) <<
"RooMinuit::synchronize: value of fixed parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
779 _theFitter->ReleaseParameter(index) ;
780 constStatChange=
kTRUE ;
788 if (oldVar!=par->
getVal() || oldVlo!=pmin || oldVhi != pmax || oldVerr!=pstep) {
789 _theFitter->SetParameter(index, par->
GetName(), par->
getVal(), pstep, pmin, pmax);
793 if (verbose && ierr>=0) {
796 if (oldVar!=par->
getVal()) {
797 coutI(
Minimization) <<
"RooMinuit::synchronize: value of parameter " << par->
GetName() <<
" changed from " << oldVar <<
" to " << par->
getVal() << endl ;
799 if (oldVlo!=pmin || oldVhi!=pmax) {
800 coutI(
Minimization) <<
"RooMinuit::synchronize: limits of parameter " << par->
GetName() <<
" changed from [" << oldVlo <<
"," << oldVhi
801 <<
"] to [" << pmin <<
"," << pmax <<
"]" << endl ;
805 if (oldVerr!=pstep && oldVerr!=0) {
806 coutI(
Minimization) <<
"RooMinuit::synchronize: error/step size of parameter " << par->
GetName() <<
" changed from " << oldVerr <<
" to " << pstep << endl ;
814 oldWarn = setWarnLevel(oldWarn) ;
815 oldPrint = setPrintLevel(oldPrint) ;
818 if (constStatChange) {
822 coutI(
Minimization) <<
"RooMinuit::synchronize: set of constant parameters changed, rerunning const optimizer" << endl ;
824 }
else if (constValChange) {
825 coutI(
Minimization) <<
"RooMinuit::synchronize: constant parameter values changed, rerunning const optimizer" << endl ;
849 if (_optConst && !flag){
850 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: deactivating const optimization" << endl ;
853 }
else if (!_optConst && flag) {
854 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: activating const optimization" << endl ;
857 }
else if (_optConst && flag) {
858 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: const optimization already active" << endl ;
860 if (_printLevel>-1)
coutI(
Minimization) <<
"RooMinuit::optimizeConst: const optimization wasn't active" << endl ;
880 name = userName ? userName :
Form(
"%s", _func->GetName()) ;
881 title = userTitle ? userTitle :
Form(
"%s", _func->GetTitle()) ;
883 if (_floatParamList->getSize()==0) {
901 RooArgList saveFloatInitList(*_initFloatParamList) ;
902 RooArgList saveFloatFinalList(*_floatParamList) ;
903 for (i=0 ; i<_floatParamList->getSize() ; i++) {
907 saveFloatFinalList.
remove(*par) ;
908 saveConstList.
add(*par) ;
911 saveConstList.
sort() ;
918 Int_t icode = _theFitter->GetStats(minVal, edm, errdef, nvpar, nparx);
946 _theFitter->SetObjectFit(
this) ;
951 Int_t index1= _floatParamList->index(&var1);
954 <<
") ERROR: " << var1.
GetName() <<
" is not a floating parameter of " << _func->GetName() << endl ;
958 Int_t index2= _floatParamList->index(&var2);
961 <<
") ERROR: " << var2.
GetName() <<
" is not a floating parameter of PDF " << _func->GetName() << endl ;
976 n[0] = n1 ; n[1] = n2 ; n[2] = n3 ; n[3] = n4 ; n[4] = n5 ; n[5] = n6 ;
979 for (
Int_t ic = 0 ; ic<6 ; ic++) {
986 coutE(
Minimization) <<
"RooMinuit::contour(" << GetName() <<
") ERROR: MINUIT did not return a contour graph for n=" << n[ic] << endl ;
988 graph->
SetName(
Form(
"contour_%s_n%f",_func->GetName(),n[ic])) ;
1001 *_floatParamList = *paramSave ;
1018 coutI(
Minimization) <<
"RooMinuit::setLogFile: closing previous log file" << endl ;
1023 _logfile =
new ofstream(inLogfile) ;
1024 if (!_logfile->good()) {
1025 coutI(
Minimization) <<
"RooMinuit::setLogFile: cannot open file " << inLogfile << endl ;
1040 return ((
RooRealVar*)_floatParamList->at(index))->getVal() ;
1050 return ((
RooRealVar*)_floatParamList->at(index))->getError() ;
1063 if (par->
getVal()!=value) {
1064 if (verbose) cout << par->
GetName() <<
"=" << value <<
", " ;
1079 ((
RooRealVar*)_floatParamList->at(index))->setError(value) ;
1089 ((
RooRealVar*)_floatParamList->at(index))->removeAsymError() ;
1098 ((
RooRealVar*)_floatParamList->at(index))->setAsymError(loVal,hiVal) ;
1110 _cumulTimer.Start(
kFALSE) ;
1124 _cumulTimer.Stop() ;
1139 Double_t val,err,vlo,vhi, eplus, eminus, eparab, globcc;
1142 for(index= 0; index < _nPar; index++) {
1143 _theFitter->GetParameter(index, buffer, val, err, vlo, vhi);
1144 setPdfParamVal(index, val);
1145 _theFitter->GetErrors(index, eplus, eminus, eparab, globcc);
1148 setPdfParamErr(index, err);
1150 if(eplus > 0 || eminus < 0) {
1152 setPdfParamErr(index, eminus,eplus);
1155 clearPdfParamAsymErr(index) ;
1165 _floatParamVec.clear() ;
1166 RooFIter iter = _floatParamList->fwdIterator() ;
1168 _floatParamVec.resize(_floatParamList->getSize()) ;
1170 while((arg=iter.
next())) {
1171 _floatParamVec[i++] = arg ;
1186 for (
Int_t i=0 ; i<getNPar() ; i++) {
1188 if (_floatParamList->at(i)->isConstant()) {
1193 cout <<
"setting parameter " << i <<
" error to " <<
sqrt((*_extV)(i,i)) << endl ;
1194 setPdfParamErr(i,
sqrt((*_extV)(i,i))) ;
1209 ofstream* logf = context->
logfile() ;
1215 for(
Int_t index= 0; index < nPar; index++) {
1216 if (logf) (*logf) << par[index] <<
" " ;
1230 oocoutW(context,
Minimization) <<
"RooMinuitGlue: Minimized function has error status." << endl
1231 <<
"Returning maximum FCN so far (" << maxFCN
1232 <<
") to force MIGRAD to back out of this region. Error log follows" << endl ;
1234 oocoutW(context,
Minimization) <<
"RooMinuitGlue: Minimized function has error status but is ignored" << endl ;
1259 }
else if (f>maxFCN) {
1264 if (logf) (*logf) << setprecision(15) << f << setprecision(4) << endl;
1266 cout <<
"\nprevFCN" << (context->
_func->
isOffsetting()?
"-offset":
"") <<
" = " << setprecision(10) << f << setprecision(4) <<
" " ;
static TVirtualFitter * _theFitter
virtual void SetLineWidth(Width_t lwidth)
Set the line width.
std::ofstream * logfile() 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)
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents: An owning collection is returned containing clones o...
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)
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
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.
virtual void SetName(const char *name)
Set the name of the TNamed.
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)
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
virtual Double_t getMin(const char *name=0) const
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.
virtual TObject * Clone(const char *newname="") const
Make a clone of an object using the Streamer facility.
R__EXTERN TMinuit * gMinuit
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
Bool_t hasMax(const char *name=0) const
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.
TIterator * createIterator(Bool_t dir=kIterForward) const
if on multiple lines(like in C++).**The" * configuration fragment. * * The "import myobject continue
Parses the configuration file.
Double_t getVal(const RooArgSet *set=0) const
TString operator+(const TString &s1, const TString &s2)
Use the special concatenation constructor.
static void clearEvalError()
Clear the evaluation error flag.
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.
virtual Bool_t isOffsetting() const
Double_t getPdfParamErr(Int_t index)
Access PDF parameter error by ordinal index (needed by MINUIT)
void setOffsetting(Bool_t flag)
Enable internal likelihood offsetting for enhanced numeric precision.
RooAbsArg * find(const char *name) const
Find object with given name in list.
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
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 const char * GetName() const
Returns name of object.
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.
Bool_t hasMin(const char *name=0) const
Bool_t isConstant() const
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.
void RooMinuitGlue(Int_t &, Double_t *, Double_t &f, Double_t *par, Int_t)
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)
virtual void SetLineStyle(Style_t lstyle)
Set the line style.
Abstract Base Class for Fitting.
virtual Bool_t remove(const RooAbsArg &var, Bool_t silent=kFALSE, Bool_t matchByNameOnly=kFALSE)
Remove the specified argument from our list.
virtual Double_t getMax(const char *name=0) const
RooFitResult * fit(const char *options)
Parse traditional RooAbsPdf::fitTo driver options.
void profileStart()
Start profiling timer.
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
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...
void backProp()
Transfer MINUIT fit results back into RooFit objects.
Int_t improve()
Execute IMPROVE.
void setCovarianceMatrix(TMatrixDSym &V)
Store externally provided correlation matrix in this RooFitResult ;.
RooMinuit is a wrapper class around TFitter/TMinuit that provides a seamless interface between the MI...
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...
void optimizeConst(Int_t flag)
If flag is true, perform constant term optimization on function being minimized.
Double_t getError() const