3 #include "Minuit2/FCNBase.h"
4 #include "Minuit2/FunctionMinimum.h"
5 #include "Minuit2/MnHesse.h"
6 #include "Minuit2/MnMigrad.h"
7 #include "Minuit2/MnMinos.h"
8 #include "Minuit2/MnPrint.h"
9 #include "Minuit2/MnUserParameterState.h"
10 #include "Minuit2/SimplexMinimizer.h"
16 using namespace ROOT::Minuit2;
20 double TwoGauss(
double y,
double A,
double sig,
double y0) {
22 * (TMath::Exp(-(
y - y0) * (
y - y0) / 2. / sig / sig)
23 + TMath::Exp(-(
y + y0) * (
y + y0) / 2. / sig / sig));
30 const std::vector<double>& dndy_,
31 const std::vector<double>& err_)
33 , fMeasurements(dndy_)
40 double operator()(
const std::vector<double>& par)
const {
42 for (
unsigned int i = 0;
i < fPositions.size(); ++
i) {
43 double val =
TwoGauss(fPositions[
i], par[0], par[1], par[2]);
44 chi2 += (fMeasurements[
i] - val) * (fMeasurements[
i] - val) / fErrors[
i]
50 double Up()
const {
return 1.; }
66 std::vector<double> params(3, 0.);
67 params[0] = Parameters.A.value;
68 params[1] = Parameters.sig.value;
69 params[2] = Parameters.yav.value;
70 MnUserParameters upar;
88 MnMigrad migrad(mfunc, upar);
89 FunctionMinimum
min = migrad();
93 ret.
A.
value = (
min.UserParameters()).Params()[0];
94 ret.
A.
error = (
min.UserParameters()).Errors()[0];
103 std::cout <<
"A = " << params[0] <<
" "
104 <<
" sig = " << params[1] <<
" "
105 <<
" y0 = " << params[2] <<
" "
106 <<
" chi2/ndf = " << mfunc(params) / (
y.size() - nparams)
109 ret.
chi2ndf = mfunc(params) / (
y.size() - nparams);