40using std::endl, std::ofstream, std::cout;
59 const RooAbsArg *arg = (*_floatParamList).at(i);
61 oocoutW(
_context, Minimization) <<
"RooAbsMinimizerFcn::RooAbsMinimizerFcn: removing parameter "
62 << arg->
GetName() <<
" from list because it is not of type RooRealVar" << endl;
79 : _context(other._context),
80 _maxFCN(other._maxFCN),
81 _funcOffset(other._funcOffset),
82 _numBadNLL(other._numBadNLL),
83 _evalCounter(other._evalCounter),
85 _optConst(other._optConst),
86 _floatParamList(std::make_unique<
RooArgList>(*other._floatParamList)),
87 _constParamList(std::make_unique<
RooArgList>(*other._constParamList)),
88 _initFloatParamList(std::make_unique<
RooArgList>()),
89 _initConstParamList(std::make_unique<
RooArgList>()),
90 _logfile(other._logfile)
101 bool constValChange(
false);
102 bool constStatChange(
false);
123 constStatChange =
true;
128 <<
"RooAbsMinimizerFcn::synchronize: parameter " << par->
GetName() <<
" is now floating." << endl;
134 constValChange =
true;
137 <<
"RooAbsMinimizerFcn::synchronize: value of constant parameter " << par->
GetName() <<
" changed from "
162 oocoutW(
_context, Minimization) <<
"RooAbsMinimizerFcn::fit: Error, non-constant parameter "
163 << par->
GetName() <<
" is not of type RooRealVar, skipping" << endl;
185 pstep = 0.1 * (pmax - pmin);
188 if (pmax - par->
getVal() < 2 * pstep) {
189 pstep = (pmax - par->
getVal()) / 2;
190 }
else if (par->
getVal() - pmin < 2 * pstep) {
191 pstep = (par->
getVal() - pmin) / 2;
196 pstep = 0.1 * (pmax - pmin);
204 <<
"RooAbsMinimizerFcn::synchronize: WARNING: no initial error estimate available for "
205 << par->
GetName() <<
": using " << pstep << endl;
214 if (
index >= parameters.size()) {
217 parameters.emplace_back(par->
GetName(), par->
getVal(), pstep, pmin, pmax);
219 parameters.emplace_back(par->
GetName(), par->
getVal(), pstep);
221 parameters.back().SetLowerLimit(pmin);
222 }
else if (par->
hasMax()) {
223 parameters.back().SetUpperLimit(pmax);
230 bool oldFixed = parameters[
index].IsFixed();
231 double oldVar = parameters[
index].Value();
232 double oldVerr = parameters[
index].StepSize();
233 double oldVlo = parameters[
index].LowerLimit();
234 double oldVhi = parameters[
index].UpperLimit();
239 if (oldVar != par->
getVal()) {
243 <<
"RooAbsMinimizerFcn::synchronize: value of parameter " << par->
GetName() <<
" changed from "
244 << oldVar <<
" to " << par->
getVal() << endl;
247 parameters[
index].Fix();
248 constStatChange =
true;
251 <<
"RooAbsMinimizerFcn::synchronize: parameter " << par->
GetName() <<
" is now fixed." << endl;
257 if (oldVar != par->
getVal()) {
259 constValChange =
true;
263 <<
"RooAbsMinimizerFcn::synchronize: value of fixed parameter " << par->
GetName() <<
" changed from "
264 << oldVar <<
" to " << par->
getVal() << endl;
271 parameters[
index].Release();
272 constStatChange =
true;
276 <<
"RooAbsMinimizerFcn::synchronize: parameter " << par->
GetName() <<
" is now floating." << endl;
281 if (oldVar != par->
getVal() || oldVlo != pmin || oldVhi != pmax || oldVerr != pstep) {
283 parameters[
index].SetStepSize(pstep);
285 parameters[
index].SetLimits(pmin, pmax);
286 }
else if (par->
hasMin()) {
287 parameters[
index].SetLowerLimit(pmin);
288 }
else if (par->
hasMax()) {
289 parameters[
index].SetUpperLimit(pmax);
297 if (oldVar != par->
getVal()) {
299 <<
"RooAbsMinimizerFcn::synchronize: value of parameter " << par->
GetName() <<
" changed from "
300 << oldVar <<
" to " << par->
getVal() << endl;
302 if (oldVlo != pmin || oldVhi != pmax) {
304 <<
"RooAbsMinimizerFcn::synchronize: limits of parameter " << par->
GetName() <<
" changed from ["
305 << oldVlo <<
"," << oldVhi <<
"] to [" << pmin <<
"," << pmax <<
"]" << endl;
309 if (oldVerr != pstep && oldVerr != 0) {
311 <<
"RooAbsMinimizerFcn::synchronize: error/step size of parameter " << par->
GetName()
312 <<
" changed from " << oldVerr <<
" to " << pstep << endl;
362 if (eplus > 0 || eminus < 0) {
378 oocoutI(
_context, Minimization) <<
"RooAbsMinimizerFcn::setLogFile: closing previous log file" << endl;
385 oocoutI(
_context, Minimization) <<
"RooAbsMinimizerFcn::setLogFile: cannot open file " << inLogfile << endl;
399 for (
unsigned int i = 0; i <
_nDim; i++) {
413 if (par->getVal() !=
value) {
432 std::ostringstream msg;
433 if (
cfg().doEEWall) {
434 msg <<
"RooAbsMinimizerFcn: Minimized function has error status." << endl
435 <<
"Returning maximum FCN so far (" <<
_maxFCN
436 <<
") to force MIGRAD to back out of this region. Error log follows.\n";
438 msg <<
"RooAbsMinimizerFcn: Minimized function has error status but is ignored.\n";
441 msg <<
"Parameter values: ";
443 auto var =
static_cast<const RooRealVar *
>(par);
444 msg <<
"\t" << var->
GetName() <<
"=" << var->getVal();
465 if (
cfg().doEEWall) {
488 const char *
name =
"minimizer_log_dataset";
504 oocoutI(
_context, Minimization) <<
"RooAbsMinimizerFcn::setOptimizeConst: deactivating const optimization"
511 oocoutI(
_context, Minimization) <<
"RooAbsMinimizerFcn::setOptimizeConst: activating const optimization"
518 oocoutI(
_context, Minimization) <<
"RooAbsMinimizerFcn::setOptimizeConst: const optimization already active"
523 oocoutI(
_context, Minimization) <<
"RooAbsMinimizerFcn::setOptimizeConst: const optimization wasn't active"
533 if (constStatChange) {
536 <<
"RooAbsMinimizerFcn::optimizeConstantTerms: set of constant parameters changed, rerunning const optimizer"
539 }
else if (constValChange) {
541 <<
"RooAbsMinimizerFcn::optimizeConstantTerms: constant parameter values changed, rerunning const optimizer"
550 std::vector<double> values;
551 values.reserve(
_nDim);
555 values.push_back(par->
getVal());
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
class containing 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
Common abstract base class for objects that represent a value and a "shape" in RooFit.
bool isConstant() const
Check if the "Constant" attribute is set.
void setValueDirty()
Mark the element dirty. This forces a re-evaluation when a value is requested.
RooAbsCollection * selectByAttrib(const char *name, bool value) const
Create a subset of the current collection, consisting only of those elements with the specified attri...
void setOptimizeConst(Int_t flag)
std::unique_ptr< RooArgList > _floatParamList
bool SetLogFile(const char *inLogfile)
Change the file name for logging of a RooMinimizer of all MINUIT steppings through the parameter spac...
RooAbsMinimizerFcn(RooArgList paramList, RooMinimizer *context)
virtual bool Synchronize(std::vector< ROOT::Fit::ParameterSettings > ¶meters)
Like synchronizeParameterSettings, Synchronize informs Minuit through its parameter_settings vector o...
double applyEvalErrorHandling(double fvalue) const
Apply corrections on the fvalue if errors were signaled.
virtual void setOptimizeConstOnFunction(RooAbsArg::ConstOpCode opcode, bool doAlsoTrackingOpt)=0
This function must be overridden in the derived class to pass on constant term optimization configura...
void BackProp(const ROOT::Fit::FitResult &results)
Put Minuit results back into RooFit objects.
RooMinimizer::Config const & cfg() const
void finishDoEval() const
void optimizeConstantTerms(bool constStatChange, bool constValChange)
void printEvalErrors() const
Print information about why evaluation failed.
void ClearPdfParamAsymErr(Int_t index)
Modify PDF parameter error by ordinal index (needed by MINUIT)
std::vector< double > getParameterValues() const
void SetPdfParamErr(Int_t index, double value)
Modify PDF parameter error by ordinal index (needed by MINUIT)
bool synchronizeParameterSettings(std::vector< ROOT::Fit::ParameterSettings > ¶meters, bool optConst)
Informs Minuit through its parameter_settings vector of RooFit parameter properties.
void ApplyCovarianceMatrix(TMatrixDSym &V)
Set different external covariance matrix.
std::unique_ptr< RooArgList > _initConstParamList
std::unique_ptr< RooArgList > _constParamList
bool SetPdfParamVal(int index, double value) const
Set value of parameter i.
std::unique_ptr< RooArgList > _initFloatParamList
virtual double getMax(const char *name=nullptr) const
Get maximum of currently defined range.
bool hasMax(const char *name=nullptr) const
Check if variable has an upper bound.
virtual double getMin(const char *name=nullptr) const
Get minimum of currently defined range.
bool hasMin(const char *name=nullptr) const
Check if variable has a lower bound.
double 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 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::Fit:Fitter that provides a seamless interface between the minimizer functi...
static int getPrintLevel()
Get the MINUIT internal printing level.
std::unique_ptr< RooDataSet > _logDataSet
std::unique_ptr< RooAbsReal::EvalErrorContext > makeEvalErrorContext() const
Variable that can be changed from the outside.
TClass * IsA() const override
Bool_t InheritsFrom(const char *cl) const override
Return kTRUE if this class inherits from a class with name "classname".
const char * GetName() const override
Returns name of object.
TClass * IsA() const override
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...