14#ifndef __ROOFIT_NOROOMINIMIZER
43 _funct(funct), _context(context),
45 _maxFCN(-std::numeric_limits<
double>::infinity()), _numBadNLL(0),
47 _nDim(0), _logfile(0),
70 const RooAbsArg* arg = (*_floatParamList).at(i);
71 if (!arg->IsA()->
InheritsFrom(RooAbsRealLValue::Class())) {
72 oocoutW(
_context,Minimization) <<
"RooMinimizerFcn::RooMinimizerFcn: removing parameter "
73 << arg->
GetName() <<
" from list because it is not of type RooRealVar" << endl;
92 _context(other._context),
93 _maxFCN(other._maxFCN),
94 _funcOffset(other._funcOffset),
95 _recoverFromNaNStrength(other._recoverFromNaNStrength),
96 _numBadNLL(other._numBadNLL),
97 _printEvalErrors(other._printEvalErrors),
98 _evalCounter(other._evalCounter),
100 _logfile(other._logfile),
101 _doEvalErrorWall(other._doEvalErrorWall),
102 _verbose(other._verbose)
143 if (!oldpar) continue ;
153 constStatChange=
kTRUE ;
157 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: parameter "
158 << par->
GetName() <<
" is now floating." << endl ;
164 constValChange=
kTRUE ;
166 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: value of constant parameter "
168 <<
" changed from " << oldpar->
getVal() <<
" to "
169 << par->
getVal() << endl ;
193 oocoutW(
_context,Minimization) <<
"RooMinimizerFcn::fit: Error, non-constant parameter "
195 <<
" is not of type RooRealVar, skipping" << endl ;
213 pstep= 0.1*(pmax-pmin);
216 if (pmax - par->
getVal() < 2*pstep) {
217 pstep = (pmax - par->
getVal())/2 ;
218 }
else if (par->
getVal() - pmin < 2*pstep) {
219 pstep = (par->
getVal() - pmin )/2 ;
224 pstep= 0.1*(pmax-pmin);
231 oocoutW(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: WARNING: no initial error estimate available for "
232 << par->
GetName() <<
": using " << pstep << endl;
241 if (index>=
Int_t(parameters.size())) {
254 parameters.back().SetLowerLimit(pmin);
256 parameters.back().SetUpperLimit(pmax);
263 Bool_t oldFixed = parameters[index].IsFixed();
264 Double_t oldVar = parameters[index].Value();
265 Double_t oldVerr = parameters[index].StepSize();
266 Double_t oldVlo = parameters[index].LowerLimit();
267 Double_t oldVhi = parameters[index].UpperLimit();
272 if (oldVar!=par->
getVal()) {
273 parameters[index].SetValue(par->
getVal());
275 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: value of parameter "
276 << par->
GetName() <<
" changed from " << oldVar
277 <<
" to " << par->
getVal() << endl ;
280 parameters[index].Fix();
281 constStatChange=
kTRUE ;
283 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: parameter "
284 << par->
GetName() <<
" is now fixed." << endl ;
290 if (oldVar!=par->
getVal()) {
291 parameters[index].SetValue(par->
getVal());
292 constValChange=
kTRUE ;
295 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: value of fixed parameter "
296 << par->
GetName() <<
" changed from " << oldVar
297 <<
" to " << par->
getVal() << endl ;
304 parameters[index].Release();
305 constStatChange=
kTRUE ;
308 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: parameter "
309 << par->
GetName() <<
" is now floating." << endl ;
314 if (oldVar!=par->
getVal() || oldVlo!=pmin || oldVhi != pmax || oldVerr!=pstep) {
315 parameters[index].SetValue(par->
getVal());
316 parameters[index].SetStepSize(pstep);
318 parameters[index].SetLimits(pmin,pmax);
320 parameters[index].SetLowerLimit(pmin);
322 parameters[index].SetUpperLimit(pmax);
329 if (oldVar!=par->
getVal()) {
330 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: value of parameter "
331 << par->
GetName() <<
" changed from " << oldVar <<
" to "
332 << par->
getVal() << endl ;
334 if (oldVlo!=pmin || oldVhi!=pmax) {
335 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: limits of parameter "
336 << par->
GetName() <<
" changed from [" << oldVlo <<
"," << oldVhi
337 <<
"] to [" << pmin <<
"," << pmax <<
"]" << endl ;
341 if (oldVerr!=pstep && oldVerr!=0) {
342 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: error/step size of parameter "
343 << par->
GetName() <<
" changed from " << oldVerr <<
" to " << pstep << endl ;
350 if (constStatChange) {
354 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: set of constant parameters changed, rerunning const optimizer" << endl ;
356 }
else if (constValChange) {
357 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::synchronize: constant parameter values changed, rerunning const optimizer" << endl ;
390 for (
Int_t index= 0; index <
_nDim; index++) {
401 if(eplus > 0 || eminus < 0) {
417 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::setLogFile: closing previous log file" << endl ;
422 _logfile =
new ofstream(inLogfile) ;
424 oocoutI(
_context,Minimization) <<
"RooMinimizerFcn::setLogFile: cannot open file " << inLogfile << endl ;
451 auto par =
static_cast<RooRealVar*
>(&(*_floatParamList)[index]);
453 if (par->getVal()!=value) {
471 std::ostringstream msg;
473 msg <<
"RooMinimizerFcn: Minimized function has error status." << endl
474 <<
"Returning maximum FCN so far (" <<
_maxFCN
475 <<
") to force MIGRAD to back out of this region. Error log follows.\n";
477 msg <<
"RooMinimizerFcn: Minimized function has error status but is ignored.\n";
480 msg <<
"Parameter values: " ;
482 auto var =
static_cast<const RooRealVar*
>(par);
483 msg <<
"\t" << var->
GetName() <<
"=" << var->getVal() ;
496 for (
int index = 0; index <
_nDim; index++) {
497 if (
_logfile) (*_logfile) <<
x[index] <<
" " ;
528 (*_logfile) << setprecision(15) << fvalue << setprecision(4) << endl;
530 cout <<
"\nprevFCN" << (
_funct->
isOffsetting()?
"-offset":
"") <<
" = " << setprecision(10)
531 << fvalue << setprecision(4) <<
" " ;
class containg the result of the fit and all the related information (fitted parameter values,...
double UpperError(unsigned int i) const
upper Minos error. If Minos has not run for parameter i return the parabolic error
double Error(unsigned int i) const
parameter error by index
double Value(unsigned int i) const
parameter value by index
double LowerError(unsigned int i) const
lower Minos error. If Minos has not run for parameter i return the parabolic error
Class, describing value, limits and step size of the parameters Provides functionality also to set/re...
RooAbsArg is the common abstract base class for objects that represent a value and a "shape" in RooFi...
virtual void constOptimizeTestStatistic(ConstOpCode opcode, Bool_t doAlsoTrackingOpt=kTRUE)
Interface function signaling a request to perform constant term optimization.
RooArgSet * getParameters(const RooAbsData *data, bool stripDisconnected=true) const
Create a list of leaf nodes in the arg tree starting with ourself as top node that don't match any of...
Bool_t isConstant() const
Check if the "Constant" attribute is set.
void sort(Bool_t reverse=false)
Sort collection using std::sort and name comparison.
RooAbsCollection * snapshot(Bool_t deepCopy=kTRUE) const
Take a snap shot of current collection contents.
virtual RooAbsArg * addClone(const RooAbsArg &var, Bool_t silent=kFALSE)
Add a clone of the specified argument to list.
virtual Bool_t add(const RooAbsArg &var, Bool_t silent=kFALSE)
Add the specified argument to list.
Storage_t::size_type size() const
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 setName(const char *name)
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
Get maximum of currently defined range.
Bool_t hasMax(const char *name=0) const
Check if variable has an upper bound.
Bool_t hasMin(const char *name=0) const
Check if variable has a lower bound.
virtual Double_t getMin(const char *name=0) const
Get miniminum of currently defined range.
RooAbsReal is the common abstract base class for objects that represent a real value and implements f...
virtual Bool_t isOffsetting() const
static void setHideOffset(Bool_t flag)
Double_t getVal(const RooArgSet *normalisationSet=nullptr) const
Evaluate object.
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
static void setEvalErrorLoggingMode(ErrorLoggingMode m)
Set evaluation error logging mode.
static void printEvalErrors(std::ostream &os=std::cout, Int_t maxPerNode=10000000)
Print all outstanding logged evaluation error on the given ostream.
static void clearEvalErrorLog()
Clear the stack of evaluation error messages.
RooArgList is a container object that can hold multiple RooAbsArg objects.
RooAbsArg * at(Int_t idx) const
Return object at given index, or nullptr if index is out of range.
RooArgSet is a container object that can hold multiple RooAbsArg objects.
RooMinimizerFcn is an interface to the ROOT::Math::IBaseFunctionMultiDim, a function that ROOT's mini...
RooArgList * _floatParamList
void SetPdfParamErr(Int_t index, Double_t value)
Modify PDF parameter error by ordinal index (needed by MINUIT)
RooArgList * _initFloatParamList
virtual double DoEval(const double *x) const
Evaluate function given the parameters in x.
virtual ROOT::Math::IBaseFunctionMultiDim * Clone() const
Clone a function.
Bool_t SetLogFile(const char *inLogfile)
Change the file name for logging of a RooMinimizer of all MINUIT steppings through the parameter spac...
void ApplyCovarianceMatrix(TMatrixDSym &V)
Apply results of given external covariance matrix.
virtual ~RooMinimizerFcn()
RooArgList * _constParamList
Bool_t Synchronize(std::vector< ROOT::Fit::ParameterSettings > ¶meters, Bool_t optConst, Bool_t verbose)
Internal function to synchronize TMinimizer with current information in RooAbsReal function parameter...
void BackProp(const ROOT::Fit::FitResult &results)
Transfer MINUIT fit results back into RooFit objects.
RooMinimizerFcn(RooAbsReal *funct, RooMinimizer *context, bool verbose=false)
void printEvalErrors() const
Print information about why evaluation failed.
const RooMinimizer * _context
void ClearPdfParamAsymErr(Int_t index)
Modify PDF parameter error by ordinal index (needed by MINUIT)
Bool_t SetPdfParamVal(int index, double value) const
Set value of parameter i.
RooArgList * _initConstParamList
double _recoverFromNaNStrength
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
RooRealVar represents a variable that can be changed from the outside.
Double_t getError() const
virtual const char * GetName() const
Returns name of object.
virtual Bool_t InheritsFrom(const char *classname) const
Returns kTRUE if object inherits from class "classname".
Namespace for new Math classes and functions.
tbb::task_arena is an alias of tbb::interface7::task_arena, which doesn't allow to forward declare tb...
static float unpackNaN(double val)
If val is NaN and a this NaN has been tagged as containing a payload, unpack the float from the manti...