43 _allParams.add(paramList);
51 if (!param->isConstant() && !canBeFloating(*param)) {
52 oocoutW(_context, Minimization) <<
"RooAbsMinimizerFcn::RooAbsMinimizerFcn: removing parameter "
53 << param->
GetName() <<
" from list because it is not of type RooRealVar"
58 _allParams.snapshot(_allParamsInit,
false);
60 std::size_t iParam = 0;
62 if (!treatAsConstant(*param)) {
63 _floatableParamIndices.push_back(iParam);
71bool RooAbsMinimizerFcn::synchronizeParameterSettings(std::vector<ROOT::Fit::ParameterSettings> ¶meters)
75 for (std::size_t i = 0; i < _allParams.size(); ++i) {
76 if (treatAsConstant(_allParamsInit[i]) && !treatAsConstant(_allParams[i])) {
78 ss <<
"RooMinimzer: the parameter named " << _allParams[i].GetName()
79 <<
" is not constant anymore, but it was constant at the time where the RooMinimizer was constructed."
80 " This is illegal. The other way around is supported: you can always change the constant flag of "
81 "parameters that were floating at the time the minimizer was instantiated.";
82 oocxcoutF(
nullptr, LinkStateMgmt) << ss.str() << std::endl;
83 throw std::runtime_error(ss.str());
87 std::vector<ROOT::Fit::ParameterSettings> oldParameters = parameters;
92 auto &par = floatableParam(
index);
100 double pmin = par.hasMin() ? par.getMin() : 0.0;
101 double pmax = par.hasMax() ? par.getMax() : 0.0;
104 double pstep = par.getError();
107 if (par.hasMin() && par.hasMax()) {
108 pstep = 0.1 * (pmax - pmin);
111 if (pmax - par.getVal() < 2 * pstep) {
112 pstep = (pmax - par.getVal()) / 2;
113 }
else if (par.getVal() - pmin < 2 * pstep) {
114 pstep = (par.getVal() - pmin) / 2;
119 pstep = 0.1 * (pmax - pmin);
126 oocoutW(_context, Minimization)
127 <<
"RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for " << par.GetName()
128 <<
": using " << pstep << std::endl;
132 if (par.hasMin() && par.hasMax()) {
133 parameters.emplace_back(par.GetName(), par.getVal(), pstep, pmin, pmax);
135 parameters.emplace_back(par.GetName(), par.getVal(), pstep);
137 parameters.back().SetLowerLimit(pmin);
138 }
else if (par.hasMax()) {
139 parameters.back().SetUpperLimit(pmax);
143 par.isConstant() ? parameters.back().Fix() : parameters.back().Release();
149bool RooAbsMinimizerFcn::Synchronize(std::vector<ROOT::Fit::ParameterSettings> ¶meters)
151 return synchronizeParameterSettings(parameters);
155void RooAbsMinimizerFcn::BackProp()
157 auto const &results = _context->fitter()->Result();
161 auto ¶m = floatableParam(
index);
167 double err = results.fErrors[
index];
170 double eminus = results.lowerError(
index);
171 double eplus = results.upperError(
index);
173 if (eplus > 0 || eminus < 0) {
175 param.setAsymError(eminus, eplus);
178 param.removeAsymError();
186bool RooAbsMinimizerFcn::SetLogFile(
const char *inLogfile)
189 oocoutI(_context, Minimization) <<
"RooAbsMinimizerFcn::setLogFile: closing previous log file" << std::endl;
194 _logfile =
new std::ofstream(inLogfile);
195 if (!_logfile->good()) {
196 oocoutI(_context, Minimization) <<
"RooAbsMinimizerFcn::setLogFile: cannot open file " << inLogfile << std::endl;
208void RooAbsMinimizerFcn::ApplyCovarianceMatrix(
TMatrixDSym &V)
210 for (
unsigned int i = 0; i < getNDim(); i++) {
211 floatableParam(i).setError(std::sqrt(V(i, i)));
216bool RooAbsMinimizerFcn::SetPdfParamVal(
int index,
double value)
const
218 auto &par = floatableParam(
index);
220 if (par.getVal() !=
value) {
222 std::cout << par.GetName() <<
"=" <<
value <<
", ";
234void RooAbsMinimizerFcn::printEvalErrors()
const
236 if (cfg().printEvalErrors < 0)
239 std::ostringstream msg;
240 if (cfg().doEEWall) {
241 msg <<
"RooAbsMinimizerFcn: Minimized function has error status." << std::endl
242 <<
"Returning maximum FCN so far (" << _maxFCN
243 <<
") to force MIGRAD to back out of this region. Error log follows.\n";
245 msg <<
"RooAbsMinimizerFcn: Minimized function has error status but is ignored.\n";
248 msg <<
"Parameter values: ";
249 for (std::size_t i = 0; i < getNDim(); ++i) {
250 auto &var = floatableParam(i);
251 msg <<
"\t" << var.GetName() <<
"=" << var.getVal();
256 ooccoutW(_context, Minimization) << msg.str() << std::endl;
265double RooAbsMinimizerFcn::applyEvalErrorHandling(
double fvalue)
const
272 if (cfg().doEEWall) {
274 fvalue = (std::isfinite(_maxFCN) ? _maxFCN : 0.) + cfg().recoverFromNaN *
badness;
277 if (_evalCounter > 0 && _evalCounter == _numBadNLL) {
281 _funcOffset = -fvalue;
283 fvalue += _funcOffset;
284 _maxFCN = std::max(fvalue, _maxFCN);
289void RooAbsMinimizerFcn::finishDoEval()
const
294RooArgList RooAbsMinimizerFcn::floatParams()
const
298 if (!treatAsConstant(*param))
304RooArgList RooAbsMinimizerFcn::constParams()
const
308 if (treatAsConstant(*param))
314RooArgList RooAbsMinimizerFcn::initFloatParams()
const
318 for (
RooAbsArg *param : _allParamsInit) {
319 if (!treatAsConstant(*param))
320 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.
const char * GetName() const override
Returns name of object.
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...
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...