40using std::setprecision;
62 unsigned int nDim = getNDim();
65 _gradientOutput.resize(_allParams.size());
66 _multiGenFcn = std::make_unique<ROOT::Math::GradFunctor>(
this, &RooMinimizerFcn::operator(),
67 &RooMinimizerFcn::evaluateGradient, nDim);
69 _multiGenFcn = std::make_unique<ROOT::Math::Functor>(std::cref(*
this), getNDim());
72 _hessianOutput.resize(_allParams.size() * _allParams.size());
78 _funct->constOptimizeTestStatistic(opcode, doAlsoTrackingOpt);
82double RooMinimizerFcn::operator()(
const double *
x)
const
85 for (
unsigned index = 0; index < getNDim(); index++) {
87 (*_logfile) <<
x[index] <<
" ";
88 SetPdfParamVal(index,
x[index]);
93 double fvalue = _funct->getVal();
96 fvalue = applyEvalErrorHandling(fvalue);
100 (*_logfile) << setprecision(15) << fvalue << setprecision(4) << std::endl;
102 std::cout <<
"\nprevFCN" << (_funct->isOffsetting() ?
"-offset" :
"") <<
" = " << setprecision(10) << fvalue
103 << setprecision(4) <<
" ";
112void RooMinimizerFcn::evaluateGradient(
const double *
x,
double *out)
const
115 for (
unsigned index = 0; index < getNDim(); index++) {
117 (*_logfile) <<
x[index] <<
" ";
118 SetPdfParamVal(index,
x[index]);
121 _funct->gradient(_gradientOutput.data());
123 std::size_t iAll = 0;
124 std::size_t iFloating = 0;
125 for (
RooAbsArg *param : _allParamsInit) {
126 if (!treatAsConstant(*param)) {
127 out[iFloating] = _gradientOutput[iAll];
135 std::cout <<
"\n gradient = ";
136 for (std::size_t i = 0; i < getNDim(); ++i) {
137 std::cout << out[i] <<
", ";
142std::string RooMinimizerFcn::getFunctionName()
const
144 return _funct->GetName();
147std::string RooMinimizerFcn::getFunctionTitle()
const
149 return _funct->GetTitle();
152void RooMinimizerFcn::setOffsetting(
bool flag)
154 _funct->enableOffsetting(flag);
157RooArgSet RooMinimizerFcn::freezeDisconnectedParameters()
const
163 _funct->getParameters(
nullptr, paramsDisconnected,
false);
164 _funct->getParameters(
nullptr, paramsConnected,
true);
166 paramsDisconnected.
remove(paramsConnected,
true,
true);
173 if (
v && !
v->isConstant()) {
176 }
else if (cv && !cv->isConstant()) {
185bool RooMinimizerFcn::evaluateHessian(std::span<const double>
x,
double *out)
const
188 for (
unsigned index = 0; index < getNDim(); index++) {
190 (*_logfile) <<
x[index] <<
" ";
191 SetPdfParamVal(index,
x[index]);
194 _funct->hessian(_hessianOutput.data());
196 std::size_t
m = _allParamsInit.size();
197 std::size_t
n = getNDim();
198 std::size_t iAll = 0;
199 std::size_t iFloating = 0;
200 for (
RooAbsArg *param_i : _allParamsInit) {
201 if (!treatAsConstant(*param_i)) {
202 std::size_t jAll = 0;
203 std::size_t jFloating = 0;
204 for (
RooAbsArg *param_j : _allParamsInit) {
205 if (!treatAsConstant(*param_j)) {
206 out[iFloating *
n + jFloating] = _hessianOutput[iAll *
m + jAll];
218 std::cout <<
"\n hessian = " << std::endl;
219 for (std::size_t i = 0; i < getNDim(); ++i) {
220 for (std::size_t j = 0; j < getNDim(); ++j) {
221 std::cout << out[i *
n + j] <<
", ";
223 std::cout << std::endl;
234 std::bind(&RooMinimizerFcn::evaluateHessian,
this, std::placeholders::_1, std::placeholders::_2));
Abstract Minimizer class, defining the interface for the various minimizer (like Minuit2,...
virtual void SetHessianFunction(std::function< bool(std::span< const double >, double *)>)
Set the function implementing Hessian computation (re-implemented by Minimizer using it).
virtual void SetFunction(const ROOT::Math::IMultiGenFunction &func)=0
Set the function to minimize.
Common abstract base class for objects that represent a value and a "shape" in RooFit.
RooFit::OwningPtr< 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...
virtual bool remove(const RooAbsArg &var, bool silent=false, bool matchByNameOnly=false)
Remove the specified argument from our list.
virtual bool add(const RooAbsArg &var, bool silent=false)
Add the specified argument to list.
Abstract base class for objects that represent a real value and implements functionality common to al...
virtual bool hasGradient() const
static void setHideOffset(bool flag)
RooArgSet is a container object that can hold multiple RooAbsArg objects.
Object to represent discrete states.
Wrapper class around ROOT::Math::Minimizer that provides a seamless interface between the minimizer f...
RooMinimizer::Config _cfg
Variable that can be changed from the outside.