22namespace TestStatistics {
29 MinuitGradFunctor(MinuitFcnGrad
const &fcn) :
_fcn{fcn} {}
33 unsigned int NDim()
const override {
return _fcn.NDim(); }
35 void Gradient(
const double *
x,
double *grad)
const override {
return _fcn.Gradient(
x, grad); }
37 void GradientWithPrevResult(
const double *
x,
double *grad,
double *previous_grad,
double *previous_g2,
38 double *previous_gstep)
const override
40 return _fcn.GradientWithPrevResult(
x, grad, previous_grad, previous_g2, previous_gstep);
43 bool returnsInMinuit2ParameterSpace()
const override {
return _fcn.returnsInMinuit2ParameterSpace(); }
46 double DoEval(
const double *
x)
const override {
return _fcn(
x); }
48 double DoDerivative(
double const * ,
unsigned int )
const override
50 throw std::runtime_error(
"MinuitFcnGrad::DoDerivative is not implemented, please use Gradient instead.");
83 std::vector<ROOT::Fit::ParameterSettings> ¶meters,
LikelihoodMode likelihoodMode,
86 _minuitInternalX(NDim(), 0),
87 _minuitExternalX(NDim(), 0),
88 _multiGenFcn{std::make_unique<MinuitGradFunctor>(*this)}
118 likelihoodHere.evaluate();
119 double fvalue = likelihoodHere.getResult().Sum();
123 if (!parameters_changed) {
132 oocoutW(
nullptr,
Eval) <<
"MinuitFcnGrad: Minimized function has error status." << std::endl
133 <<
"Returning maximum FCN so far (" <<
_maxFCN
134 <<
") to force MIGRAD to back out of this region. Error log follows" << std::endl;
136 oocoutW(
nullptr,
Eval) <<
"MinuitFcnGrad: Minimized function has error status but is ignored" << std::endl;
141 for (
auto *var : static_range_cast<const RooRealVar *>(*
_floatParamList)) {
147 ooccoutW(
nullptr,
Eval) << var->GetName() <<
"=" << var->getVal();
155 if (
cfg().doEEWall) {
167 std::cout <<
"\nprevFCN" << (likelihoodHere.isOffsetting() ?
"-offset" :
"") <<
" = " << std::setprecision(10)
168 << fvalue << std::setprecision(4) <<
" ";
215 bool aParamWasUpdated =
false;
216 if (minuit_internal) {
218 throw std::logic_error(
"Updating Minuit-internal parameters only makes sense for (gradient) calculators that "
219 "are defined in Minuit-internal parameter space.");
222 for (std::size_t ix = 0; ix <
NDim(); ++ix) {
224 if (parameter_changed) {
227 aParamWasUpdated |= parameter_changed;
230 if (aParamWasUpdated) {
236 bool aParamIsMismatched =
false;
238 for (std::size_t ix = 0; ix <
NDim(); ++ix) {
248 aParamWasUpdated |= parameter_changed;
249 aParamIsMismatched |=
255 if (aParamWasUpdated) {
261 return aParamWasUpdated;
273 double *previous_gstep)
const
277 _gradient->fillGradientWithPrevResult(grad, previous_grad, previous_g2, previous_gstep);
285 _gradient->synchronizeParameterSettings(parameters);
MinuitFcnGrad const & _fcn
ROOT::Math::MinimizerOptions & MinimizerOptions()
access to the minimizer control parameter (non const method)
const FitConfig & Config() const
access to the fit configuration (const method)
Interface (abstract class) for multi-dimensional functions providing a gradient calculation.
std::unique_ptr< RooArgList > _floatParamList
RooMinimizer::Config const & cfg() const
void finishDoEval() const
void printEvalErrors() const
Print information about why evaluation failed.
bool synchronizeParameterSettings(std::vector< ROOT::Fit::ParameterSettings > ¶meters, bool optConst)
Informs Minuit through its parameter_settings vector of RooFit parameter properties.
unsigned int NDim() const
bool SetPdfParamVal(int index, double value) const
Set value of parameter i.
unsigned int getNDim() const
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.
static std::unique_ptr< LikelihoodGradientWrapper > create(LikelihoodGradientMode likelihoodGradientMode, std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculationIsClean, std::size_t nDim, RooMinimizer *minimizer)
Factory method.
static std::unique_ptr< LikelihoodWrapper > create(LikelihoodMode likelihoodMode, std::shared_ptr< RooAbsL > likelihood, std::shared_ptr< WrapperCalculationCleanFlags > calculationIsClean)
Factory method.
void GradientWithPrevResult(const double *x, double *grad, double *previous_grad, double *previous_g2, double *previous_gstep) const
double operator()(const double *x) const
std::unique_ptr< LikelihoodWrapper > _likelihoodInGradient
bool Synchronize(std::vector< ROOT::Fit::ParameterSettings > ¶meter_settings) override
Overridden from RooAbsMinimizerFcn to include gradient strategy synchronization.
void Gradient(const double *x, double *grad) const
IMultiGradFunction overrides necessary for Minuit.
std::vector< double > _minuitInternalX
ROOT::Math::IMultiGenFunction * getMultiGenFcn() override
bool syncParameterValuesFromMinuitCalls(const double *x, bool minuit_internal) const
Minuit calls (via FcnAdapters etc) DoEval or Gradient with a set of parameters x.
bool _minuitInternalRooFitXMismatch
std::unique_ptr< LikelihoodGradientWrapper > _gradient
std::unique_ptr< LikelihoodWrapper > _likelihood
std::shared_ptr< WrapperCalculationCleanFlags > _calculationIsClean
bool _calculatingGradient
std::vector< double > _minuitExternalX
void applyToLikelihood(Func &&func) const
MinuitFcnGrad(const std::shared_ptr< RooFit::TestStatistics::RooAbsL > &absL, RooMinimizer *context, std::vector< ROOT::Fit::ParameterSettings > ¶meters, LikelihoodMode likelihoodMode, LikelihoodGradientMode likelihoodGradientMode)
bool returnsInMinuit2ParameterSpace() const
RooMinimizer is a wrapper class around ROOT::Fit:Fitter that provides a seamless interface between th...
ROOT::Fit::Fitter * fitter()
Return underlying ROOT fitter object.
RooRealVar represents a variable that can be changed from the outside.
The namespace RooFit contains mostly switches that change the behaviour of functions of PDFs (or othe...