43 _allParams.add(paramList);
49 if (!param->isConstant() && !canBeFloating(*param)) {
50 oocoutW(_context, Minimization) <<
"RooAbsMinimizerFcn::RooAbsMinimizerFcn: removing parameter "
51 << param->
GetName() <<
" from list because it is not of type RooRealVar"
56 _allParams.snapshot(_allParamsInit,
false);
58 std::size_t iParam = 0;
60 if (!treatAsConstant(*param)) {
61 _floatableParamIndices.push_back(iParam);
69bool RooAbsMinimizerFcn::synchronizeParameterSettings(std::vector<ROOT::Fit::ParameterSettings> ¶meters)
73 for (std::size_t i = 0; i < _allParams.size(); ++i) {
74 if (treatAsConstant(_allParamsInit[i]) && !treatAsConstant(_allParams[i])) {
76 ss <<
"RooMinimzer: the parameter named " << _allParams[i].GetName()
77 <<
" is not constant anymore, but it was constant at the time where the RooMinimizer was constructed."
78 " This is illegal. The other way around is supported: you can always change the constant flag of "
79 "parameters that were floating at the time the minimizer was instantiated.";
80 oocxcoutF(
nullptr, LinkStateMgmt) << ss.str() << std::endl;
81 throw std::runtime_error(ss.str());
89 auto &par = floatableParam(
index);
97 double pmin = par.hasMin() ? par.getMin() : 0.0;
98 double pmax = par.hasMax() ? par.getMax() : 0.0;
101 double pstep = par.getError();
104 if (par.hasMin() && par.hasMax()) {
105 pstep = 0.1 * (pmax - pmin);
108 if (pmax - par.getVal() < 2 * pstep) {
109 pstep = (pmax - par.getVal()) / 2;
110 }
else if (par.getVal() - pmin < 2 * pstep) {
111 pstep = (par.getVal() - pmin) / 2;
116 pstep = 0.1 * (pmax - pmin);
123 oocoutW(_context, Minimization)
124 <<
"RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for " << par.GetName()
125 <<
": using " << pstep << std::endl;
129 if (par.hasMin() && par.hasMax()) {
130 parameters.emplace_back(par.GetName(), par.getVal(), pstep, pmin, pmax);
132 parameters.emplace_back(par.GetName(), par.getVal(), pstep);
134 parameters.back().SetLowerLimit(pmin);
135 }
else if (par.hasMax()) {
136 parameters.back().SetUpperLimit(pmax);
140 par.isConstant() ? parameters.back().Fix() : parameters.back().Release();
146bool RooAbsMinimizerFcn::Synchronize(std::vector<ROOT::Fit::ParameterSettings> ¶meters)
148 return synchronizeParameterSettings(parameters);
152void RooAbsMinimizerFcn::BackProp()
154 auto const &results = _context->fitter()->Result();
158 auto ¶m = floatableParam(
index);
164 double err = results.fErrors[
index];
167 double eminus = results.lowerError(
index);
168 double eplus = results.upperError(
index);
170 if (eplus > 0 || eminus < 0) {
172 param.setAsymError(eminus, eplus);
175 param.removeAsymError();
183bool RooAbsMinimizerFcn::SetLogFile(
const char *inLogfile)
186 oocoutI(_context, Minimization) <<
"RooAbsMinimizerFcn::setLogFile: closing previous log file" << std::endl;
191 _logfile =
new std::ofstream(inLogfile);
192 if (!_logfile->good()) {
193 oocoutI(_context, Minimization) <<
"RooAbsMinimizerFcn::setLogFile: cannot open file " << inLogfile << std::endl;
205void RooAbsMinimizerFcn::ApplyCovarianceMatrix(
TMatrixDSym &V)
207 for (
unsigned int i = 0; i < getNDim(); i++) {
208 floatableParam(i).setError(std::sqrt(V(i, i)));
213bool RooAbsMinimizerFcn::SetPdfParamVal(
int index,
double value)
const
215 auto &par = floatableParam(
index);
217 if (par.getVal() !=
value) {
219 std::cout << par.GetName() <<
"=" <<
value <<
", ";
231void RooAbsMinimizerFcn::printEvalErrors()
const
233 if (cfg().printEvalErrors < 0)
236 std::ostringstream msg;
237 if (cfg().doEEWall) {
238 msg <<
"RooAbsMinimizerFcn: Minimized function has error status." << std::endl
239 <<
"Returning maximum FCN so far (" << _maxFCN
240 <<
") to force MIGRAD to back out of this region. Error log follows.\n";
242 msg <<
"RooAbsMinimizerFcn: Minimized function has error status but is ignored.\n";
245 msg <<
"Parameter values: ";
246 for (std::size_t i = 0; i < getNDim(); ++i) {
247 auto &var = floatableParam(i);
248 msg <<
"\t" << var.GetName() <<
"=" << var.getVal();
253 ooccoutW(_context, Minimization) << msg.str() << std::endl;
262double RooAbsMinimizerFcn::applyEvalErrorHandling(
double fvalue)
const
269 if (cfg().doEEWall) {
271 fvalue = (std::isfinite(_maxFCN) ? _maxFCN : 0.) + cfg().recoverFromNaN *
badness;
274 if (_evalCounter > 0 && _evalCounter == _numBadNLL) {
278 _funcOffset = -fvalue;
280 fvalue += _funcOffset;
281 _maxFCN = std::max(fvalue, _maxFCN);
286void RooAbsMinimizerFcn::finishDoEval()
const
291RooArgList RooAbsMinimizerFcn::floatParams()
const
295 if (!treatAsConstant(*param))
301RooArgList RooAbsMinimizerFcn::constParams()
const
305 if (treatAsConstant(*param))
311RooArgList RooAbsMinimizerFcn::initFloatParams()
const
315 for (
RooAbsArg *param : _allParamsInit) {
316 if (!treatAsConstant(*param))
317 initFloatableParams.
add(*param);
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t index
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void value
Common abstract base class for objects that represent a value and a "shape" in RooFit.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
bool selectCommon(const RooAbsCollection &refColl, RooAbsCollection &outColl) const
Create a subset of the current collection, consisting only of those elements that are contained as we...
static Int_t numEvalErrors()
Return the number of logged evaluation errors since the last clearing.
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.
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
virtual const char * GetName() const
Returns name of object.
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...