3 #include "Minuit2/FCNGradientBase.h"
4 #include "Minuit2/FunctionMinimum.h"
5 #include "Minuit2/MnUserParameters.h"
10 ROOT::Minuit2::MnUserParameterState
gState;
18 const ROOT::Minuit2::MnUserParameters& pars)
20 fFunc(func), fPars(pars)
29 std::vector<double> pt =
fPars.Params();
30 const unsigned int N = pt.size();
37 double chi =
fFunc(pt);
44 std::vector<double> grad =
fFunc.Gradient(pt);
51 std::vector<double> trialpt = pt;
52 for(
unsigned int i = 0; i <
N; ++i) trialpt[i] -= grad[i]*step;
55 const double trialchi =
fFunc(trialpt);
62 const double d2 = (trialchi+gradmag*step-chi)/(step*step);
68 step = gradmag/(2*d2);
74 std::vector<double> newpt = pt;
75 for(
unsigned int i = 0; i <
N; ++i) newpt[i] -= grad[i]*step;
77 const double newchi =
fFunc(newpt);
88 return Package(pt, chi, ncalls);
93 if(chi-newchi < 1
e-5){
97 return Package(newpt, newchi, ncalls);
115 Package(
const std::vector<double>& pt,
double chi,
int ncalls)
const
119 const unsigned int N = pt.size();
120 ROOT::Minuit2::MnAlgebraicVector vec(N);
121 for(
unsigned int i = 0; i <
N; ++i) vec(i) = pt[i];
122 ROOT::Minuit2::MinimumParameters params(vec, chi);
123 ROOT::Minuit2::MinimumState
state(params, 0, ncalls);
124 ROOT::Minuit2::MnUserTransformation trans(pt, std::vector<double>(N));
125 ROOT::Minuit2::MinimumSeed
seed(state, trans);
126 return ROOT::Minuit2::FunctionMinimum(seed, {state}, chi);
133 for(
double x: xs) ret +=
x*
x;
141 for(
double&
x: xs)
x /= mag;
const ROOT::Minuit2::MnUserParameters & fPars
double Magnitude(const std::vector< double > &xs) const
ROOT::Minuit2::MnUserParameterState gState
process_name opflash particleana ie x
GradientDescent(const ROOT::Minuit2::FCNGradientBase &func, const ROOT::Minuit2::MnUserParameters &pars)
process_name opflashCryoW ana
ROOT::Minuit2::MnStrategy gStrat
ROOT::Minuit2::FunctionMinimum Package(const std::vector< double > &pt, double chi, int ncalls) const
const ROOT::Minuit2::FCNGradientBase & fFunc
virtual ROOT::Minuit2::FunctionMinimum operator()(unsigned int maxfcn, double tolerance) override
process_name largeant stream1 can override from command line with o or output physics producers generator N
void MakeUnit(std::vector< double > &xs) const