41 int ma = func->GetNpar();
52 std::cout <<
"Setting the parameters..." << std::endl;
53 for(
int i = 0; i < func->GetNpar(); ++i) {
54 a[i] = func->GetParameter(i);
58 func->GetParLimits(i, min, max);
68 for(
int i = 0; i < ma; ++i) {
69 std::cout <<
"par[" << i <<
"] = " <<
fFunction->GetParameter(i) << std::endl;
71 double func_range_min = 0.;
72 double func_range_max = 0.;
73 func->GetRange(func_range_min, func_range_max);
74 std::cout <<
"function range: " << func_range_min <<
" to " << func_range_max << std::endl;
75 SetFitterRange(
static_cast<int>(func_range_min),
static_cast<int>(func_range_max));
76 int bin_min =
hist->FindBin(func_range_min);
77 int bin_max =
hist->FindBin(func_range_max);
79 int nBins =
hist->GetNbinsX();
87 std::cout <<
"Setting bin values..." << std::endl;
88 std::cout <<
"Range is " << bin_min <<
" to " << bin_max << std::endl;
89 for(
int i = 0; i <
hist->GetNbinsX(); ++i) {
90 x[i] =
hist->GetXaxis()->GetBinUpEdge(i + 1) *
hist->GetXaxis()->GetBinWidth(1);
91 y[i] =
hist->GetBinContent(i + 1);
92 v[i] =
hist->GetBinError(i + 1) *
hist->GetBinError(i + 1);
101 mrqmin(x, y, sig, a, ia, covar, alpha, chisq, W, alamda);
102 std::cout <<
"out of mrqmin" << std::endl;
106 std::cout << std::endl
107 <<
"Iteration #" << std::setw(3) << k;
108 std::cout << std::setw(18) <<
"chi-squared:" << std::setw(13) << chisq;
109 std::cout << std::setw(11) <<
"alamda:" << std::setw(10) << alamda << std::endl;
110 for(
int i = 0; i < ma; ++i) {
111 std::cout <<
"par[" << i <<
"] = " <<
fFunction->GetParameter(i) << std::endl;
113 std::cout << std::endl;
116 mrqmin(x, y, sig, a, ia, covar, alpha, chisq, W, alamda);
117 std::fabs(ochisq - chisq) < 0.0001 ? itst++ : itst = 0;
122 mrqmin(x, y, sig, a, ia, covar, alpha, chisq, W, alamda);
123 std::cout <<
"Uncertainties:" << std::endl;
124 for(
int i = 0; i < ma; ++i) {
125 std::cout <<
" " << std::sqrt(covar[i][i]);
127 std::cout << std::endl;
130 std::cout <<
"Chis2/ndf: " << chisq << std::endl;
133 for(
int i = 0; i < ma; ++i) {
135 fFunction->SetParError(i, std::sqrt(covar[i][i]));
218 static double ochisq;
219 static double chisqexp;
223 std::cerr << __PRETTY_FUNCTION__ <<
": vector a is empty, not doing anything!" << std::endl;
235 for(
int j = 0; j < ma; j++) {
241 mrqcof(x, y, sig, a, ia, alpha, *beta_p, chisq, W, chisqexp);
243 for(j = 0; j < ma; j++) {
254 for(
int j = 0; j < mfit; j++) {
255 for(
int k = 0; k < mfit; k++) {
256 covar[j][k] = alpha[j][k];
258 covar[j][j] = alpha[j][j] * (1.0 + alamda);
259 for(
int k = 0; k < mfit; k++) {
260 temp[j][k] = covar[j][k];
262 oneda[j][0] = beta[j];
265 for(
int j = 0; j < mfit; j++) {
266 for(
int k = 0; k < mfit; k++) {
267 covar[j][k] = temp[j][k];
282 for(
int j = 0, l = 0; l < ma; l++) {
284 atry[l] = a[l] + da[j++];
287 mrqcof(x, y, sig, atry, ia, covar, da, chisq, W, chisqexp);
291 for(
int j = 0; j < mfit; j++) {
292 for(
int k = 0; k < mfit; k++) {
293 alpha[j][k] = covar[j][k];
297 for(
int l = 0; l < ma; l++) {
315 int ndata = x.
size();
320 for(
int j = 0; j < ma; j++) {
325 for(
int j = 0; j < mfit; j++) {
326 for(
int k = 0; k <= j; k++) {
335 double sig2i = 1.0 / (sig[i] * sig[i]);
336 double dy = y[i] - yfit[i];
337 for(
int j = 0, l = 0; l < ma; l++) {
341 double wt = dyda[l] * sig2i;
342 for(
int k = 0, m = 0; m < l + 1; m++) {
344 if(chisqnumber == 0) {
345 alpha[j][k++] += wt * dyda[m] * (1.0 + dy / yfit[i]) * (1.0 + dy / yfit[i]) * W[i];
347 alpha[j][k++] += wt * dyda[m] * W[i];
351 if(chisqnumber == 0) {
352 beta[j++] += dy * wt * (1.0 + dy / (2.0 * yfit[i])) * W[i];
354 beta[j++] += dy * wt * W[i];
358 if((chisqnumber == 0) || (chisqnumber == 1) || (chisqnumber == 2)) {
359 chisq += dy * dy * sig2i * W[i];
362 if(chisqnumber == 3) {
364 chisq += 2.0 * (yfit[i] - y[i]) * W[i];
366 chisq += 2.0 * (yfit[i] - y[i] + y[i] * log(y[i] / yfit[i])) * W[i];
371 chisqexp += -2.0 * yfit[i] * std::log(yfit[i]) + std::pow(yfit[i], 2.0) * std::log(4.0) -
372 std::pow(yfit[i], 3.0) * std::log(4.0 / 3.0) +
373 (1.0 / 3.0) * std::pow(yfit[i], 4.0) * std::log(32.0 / 27.0) -
374 (1.0 / 12.0) * std::pow(yfit[i], 5.0) * std::log(4096.0 / 3645.0) +
375 1442.633448 * std::pow(yfit[i], 6.0) / std::pow(10.0, 6.0) -
376 1782.46047 * std::pow(yfit[i], 7.0) / std::pow(10.0, 7.0) +
377 1588.98494 * std::pow(yfit[i], 8.0) / std::pow(10.0, 8.0) -
378 716.19428 * std::pow(yfit[i], 9.0) / std::pow(10.0, 9.0);
380 chisqexp += 1.0 + 1.0 / (6.0 * yfit[i]) + 1.0 / (6.0 * std::pow(yfit[i], 2.0)) +
381 19.0 / (60.0 * std::pow(yfit[i], 3.0)) + 9.0 / (10.0 * std::pow(yfit[i], 4.0)) -
382 31.9385 / std::pow(yfit[i], 5.0) + 741.3189 / std::pow(yfit[i], 6.0) -
383 3928.1260 / std::pow(yfit[i], 7.0) + 6158.3381 / std::pow(yfit[i], 8.0);
389 for(
int j = 1; j < mfit; j++) {
390 for(
int k = 0; k < j; k++) {
391 alpha[k][j] = alpha[j][k];
435 for(
int j = 0; j < n; j++) {
440 for(
int i = 0; i < n; i++) {
442 for(
int j = 0; j < n; j++) {
444 for(
int k = 0; k < n; k++) {
446 if(std::fabs(a[j][k]) >= big) {
447 big = std::fabs(a[j][k]);
457 for(
int l = 0; l < n; l++) {
458 SWAP(a[irow][l], a[icol][l]);
460 for(
int l = 0; l < m; l++) {
461 SWAP(b[irow][l], b[icol][l]);
466 if(a[icol][icol] == 0.0) {
467 nrerror(
"gaussj: Singular Matrix");
469 double pivinv = 1.0 / a[icol][icol];
471 for(
int l = 0; l < n; l++) {
472 a[icol][l] *= pivinv;
474 for(
int l = 0; l < m; l++) {
475 b[icol][l] *= pivinv;
477 for(
int ll = 0; ll < n; ll++) {
479 double dum = a[ll][icol];
481 for(
int l = 0; l < n; l++) {
482 a[ll][l] -= a[icol][l] * dum;
484 for(
int l = 0; l < m; l++) {
485 b[ll][l] -= b[icol][l] * dum;
490 for(
int l = n - 1; l >= 0; l--) {
491 if(indxr[l] != indxc[l]) {
492 for(
int k = 0; k < n; k++) {
493 SWAP(a[k][indxr[l]], a[k][indxc[l]]);
int integrator(Vec_I_double &x, Vec_I_double &y, Vec_double &sig, Vec_I_double &W, Vec_IO_double &a, Vec_double &dyda, int chisqnumber, const double &bin_width, Vec_double &yfit, const int &bin)
void mrqcof(Vec_I_double &x, Vec_I_double &y, Vec_double &sig, Vec_IO_double &a, Vec_I_BOOL &ia, Mat_O_double &alpha, Vec_O_double &beta, double &chisq, Vec_I_double &W, double &chisqexp)
void mrqmin(Vec_I_double &x, Vec_I_double &y, Vec_double &sig, Vec_IO_double &a, Vec_I_BOOL &ia, Mat_O_double &covar, Mat_O_double &alpha, double &chisq, Vec_I_double &W, double &alamda)
*******************************************************************/