38 fNumberIterations = 1;
41 fStatisticType = kFitOptimChiCounts;
42 fAlphaOptim = kFitAlphaHalving;
44 fFitTaylor = kFitTaylorOrderFirst;
103 if (numberPeaks <= 0){
104 Error (
"TSpectrumFit",
"Invalid number of peaks, must be > than 0");
179 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
191 c = c * t * (da1 + t * (da2 + t * da3));
203 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
214 c = (-1.) * dap * c * t * t * (da1 + t * (2. * da2 + t * 3. * da3)) -
233 p = (i - i0) / sigma;
248 r = r *
Erfc(p + 1. / (2. * b));
251 q = q + s *
Erfc(p) / 2.;
270 p = (i - i0) / sigma;
280 c = p + 1. / (2. *
b);
284 r2 = -t *
exp(e) *
Erfc(c) / (d *
b);
289 r4 = -s *
Derfc(p) / d;
290 r1 = amp * (r1 + r2 + r3 + r4);
307 p = (i - i0) / sigma;
314 r1 = r1 * (4 * p * p - 2) / (sigma * sigma);
315 r2 = 0, r3 = 0, r4 = 0;
316 r1 = amp * (r1 + r2 + r3 + r4);
339 for (j = 0; j < num_of_fitted_peaks; j++) {
340 p = (i - parameter[2 * j + 1]) / sigma;
344 r1 = 2. * p * p *
exp(-p * p) /
sigma;
352 c = p + 1. / (2. *
b);
356 r2 = -t * p *
exp(e) *
Erfc(c) / (d *
b);
357 r3 = -t * p *
exp(e) *
Derfc(c) / d;
361 r4 = -s * p *
Derfc(p) / d;
362 r = r + parameter[2 * j] * (r1 + r2 + r3 + r4);
382 for (j = 0; j < num_of_fitted_peaks; j++) {
383 p = (i - parameter[2 * j + 1]) / sigma;
387 r1 =
exp(-p * p) * p * p * (4. * p * p - 6) / (sigma * sigma);
393 r2 = 0, r3 = 0, r4 = 0;
394 r = r + parameter[2 * j] * (r1 + r2 + r3 + r4);
415 for (j = 0; j < num_of_fitted_peaks; j++) {
416 p = (i - parameter[2 * j + 1]) / sigma;
417 c = p + 1. / (2. *
b);
422 r = r + parameter[2 * j] *
r1;
443 for (j = 0; j < num_of_fitted_peaks; j++) {
444 p = (i - parameter[2 * j + 1]) / sigma;
446 r = r + parameter[2 * j] *
r1;
470 for (j = 0; j < num_of_fitted_peaks && t != 0; j++) {
471 p = (i - parameter[2 * j + 1]) / sigma;
472 c = p + 1. / (2. *
b);
475 r1 = r1 +
Derfc(c) / 2.;
483 r = r + parameter[2 * j] *
r1;
485 r = -r * t / (2. * b *
b);
524 for (j = 0; j < num_of_fitted_peaks; j++) {
526 p = (i - parameter[2 * j + 1]) / sigma;
529 if (i == parameter[2 * j + 1])
546 c = p + 1. / (2. *
b);
550 r2 = t *
exp(e) *
Erfc(c) / 2.;
554 r3 = s *
Erfc(p) / 2.;
555 r = r + parameter[2 * j] * (r1 + r2 +
r3);
557 r = r + a0 + a1 * i + a2 * i * i;
576 r = a * sigma * (odm_pi + t * b *
exp(r));
579 r = a * sigma * odm_pi;
598 r = sigma * (odm_pi + t * b *
exp(r));
620 r = a * (odm_pi + t * b *
exp(r));
642 r = a * sigma * b *
exp(r);
661 r = (-1) * 0.25 / (b * b);
663 r = a * sigma * t *
exp(r) * (1 - 2 *
r);
684 if (pw > 10) c *= a2;
685 if (pw > 12) c *= a2;
822 Int_t i, j, k, shift =
823 2 *
fNPeaks + 7, peak_vel, rozmer, iter, pw, regul_cycle,
825 Double_t a,
b,
c, d = 0, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
826 0,
pi, pmin = 0, chi_cel = 0, chi_er;
828 for (i = 0, j = 0; i <
fNPeaks; i++) {
831 working_space[shift + j] =
fAmpInit[i];
846 working_space[2 * i + 1] =
fTInit;
847 if (
fFixT ==
false) {
848 working_space[shift + j] =
fTInit;
851 working_space[2 * i + 2] =
fBInit;
852 if (
fFixB ==
false) {
853 working_space[shift + j] =
fBInit;
856 working_space[2 * i + 3] =
fSInit;
857 if (
fFixS ==
false) {
858 working_space[shift + j] =
fSInit;
861 working_space[2 * i + 4] =
fA0Init;
863 working_space[shift + j] =
fA0Init;
866 working_space[2 * i + 5] =
fA1Init;
868 working_space[shift + j] =
fA1Init;
871 working_space[2 * i + 6] =
fA2Init;
873 working_space[shift + j] =
fA2Init;
878 delete [] working_space;
879 Error (
"FitAwmi",
"All parameters are fixed");
883 delete [] working_space;
884 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
888 for (j = 0; j < rozmer; j++) {
889 working_space[2 * shift + j] = 0, working_space[3 * shift + j] = 0;
894 chi_opt = 0, pw =
fPower - 2;
899 working_space[peak_vel], working_space[peak_vel + 1],
900 working_space[peak_vel + 3],
901 working_space[peak_vel + 2],
902 working_space[peak_vel + 4],
903 working_space[peak_vel + 5],
904 working_space[peak_vel + 6]);
912 chi_opt += (yw -
f) * (yw - f) / ywm;
932 for (j = 0, k = 0; j <
fNPeaks; j++) {
935 working_space[peak_vel],
936 working_space[peak_vel + 1],
937 working_space[peak_vel + 3],
938 working_space[peak_vel + 2]);
942 b = a * (yw * yw - f *
f) / (ywm * ywm);
943 working_space[2 * shift + k] += b *
c;
944 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
945 working_space[3 * shift + k] += b *
c;
949 b = a * (yw -
f) / ywm;
950 working_space[2 * shift + k] += b *
c;
952 working_space[3 * shift + k] += b *
c;
959 working_space[2 * j + 1],
960 working_space[peak_vel],
961 working_space[peak_vel + 1],
962 working_space[peak_vel + 3],
963 working_space[peak_vel + 2]);
966 working_space[2 * j + 1],
967 working_space[peak_vel]);
973 if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
981 b = a * (yw * yw - f *
f) / (ywm * ywm);
982 working_space[2 * shift + k] += b *
c;
983 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
984 working_space[3 * shift + k] += b *
c;
988 b = a * (yw -
f) / ywm;
989 working_space[2 * shift + k] += b *
c;
991 working_space[3 * shift + k] += b *
c;
999 working_space[peak_vel],
1000 working_space[peak_vel + 1],
1001 working_space[peak_vel + 3],
1002 working_space[peak_vel + 2]);
1005 working_space, working_space[peak_vel]);
1011 if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
1019 b = a * (yw * yw - f *
f) / (ywm * ywm);
1020 working_space[2 * shift + k] += b *
c;
1021 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1022 working_space[3 * shift + k] += b *
c;
1026 b = a * (yw -
f) / ywm;
1027 working_space[2 * shift + k] += b *
c;
1029 working_space[3 * shift + k] += b *
c;
1034 if (
fFixT ==
false) {
1036 working_space[peak_vel],
1037 working_space[peak_vel + 2]);
1041 b = a * (yw * yw - f *
f) / (ywm * ywm);
1042 working_space[2 * shift + k] += b *
c;
1043 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1044 working_space[3 * shift + k] += b *
c;
1048 b = a * (yw -
f) / ywm;
1049 working_space[2 * shift + k] += b *
c;
1051 working_space[3 * shift + k] += b *
c;
1056 if (
fFixB ==
false) {
1058 working_space[peak_vel], working_space[peak_vel + 1],
1059 working_space[peak_vel + 2]);
1063 b = a * (yw * yw - f *
f) / (ywm * ywm);
1064 working_space[2 * shift + k] += b *
c;
1065 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1066 working_space[3 * shift + k] += b *
c;
1070 b = a * (yw -
f) / ywm;
1071 working_space[2 * shift + k] += b *
c;
1073 working_space[3 * shift + k] += b *
c;
1078 if (
fFixS ==
false) {
1080 working_space[peak_vel]);
1084 b = a * (yw * yw - f *
f) / (ywm * ywm);
1085 working_space[2 * shift + k] += b *
c;
1086 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1087 working_space[3 * shift + k] += b *
c;
1091 b = a * (yw -
f) / ywm;
1092 working_space[2 * shift + k] += b *
c;
1094 working_space[3 * shift + k] += b *
c;
1104 b = a * (yw * yw - f *
f) / (ywm * ywm);
1105 working_space[2 * shift + k] += b *
c;
1106 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1107 working_space[3 * shift + k] += b *
c;
1111 b = a * (yw -
f) / ywm;
1112 working_space[2 * shift + k] += b *
c;
1114 working_space[3 * shift + k] += b *
c;
1124 b = a * (yw * yw - f *
f) / (ywm * ywm);
1125 working_space[2 * shift + k] += b *
c;
1126 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1127 working_space[3 * shift + k] += b *
c;
1131 b = a * (yw -
f) / ywm;
1132 working_space[2 * shift + k] += b *
c;
1134 working_space[3 * shift + k] += b *
c;
1144 b = a * (yw * yw - f *
f) / (ywm * ywm);
1145 working_space[2 * shift + k] += b *
c;
1146 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1147 working_space[3 * shift + k] += b *
c;
1151 b = a * (yw -
f) / ywm;
1152 working_space[2 * shift + k] += b *
c;
1154 working_space[3 * shift + k] += b *
c;
1160 for (j = 0; j < rozmer; j++) {
1161 if (
TMath::Abs(working_space[3 * shift + j]) > 0.000001)
1162 working_space[2 * shift + j] = working_space[2 * shift + j] /
TMath::Abs(working_space[3 * shift + j]);
1164 working_space[2 * shift + j] = 0;
1173 for (j = 0; j < rozmer; j++) {
1174 working_space[4 * shift + j] = working_space[shift + j];
1180 chi_min = 10000 * chi2;
1183 chi_min = 0.1 * chi2;
1185 for (
pi = 0.1; flag == 0 &&
pi <= 100;
pi += 0.1) {
1186 for (j = 0; j < rozmer; j++) {
1187 working_space[shift + j] = working_space[4 * shift + j] +
pi * alpha * working_space[2 * shift + j];
1189 for (i = 0, j = 0; i <
fNPeaks; i++) {
1191 if (working_space[shift + j] < 0)
1192 working_space[shift + j] = 0;
1193 working_space[2 * i] = working_space[shift + j];
1197 if (working_space[shift + j] <
fXmin)
1198 working_space[shift + j] =
fXmin;
1199 if (working_space[shift + j] >
fXmax)
1200 working_space[shift + j] =
fXmax;
1201 working_space[2 * i + 1] = working_space[shift + j];
1206 if (working_space[shift + j] < 0.001) {
1207 working_space[shift + j] = 0.001;
1209 working_space[peak_vel] = working_space[shift + j];
1212 if (
fFixT ==
false) {
1213 working_space[peak_vel + 1] = working_space[shift + j];
1216 if (
fFixB ==
false) {
1217 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1218 if (working_space[shift + j] < 0)
1219 working_space[shift + j] = -0.001;
1221 working_space[shift + j] = 0.001;
1223 working_space[peak_vel + 2] = working_space[shift + j];
1226 if (
fFixS ==
false) {
1227 working_space[peak_vel + 3] = working_space[shift + j];
1231 working_space[peak_vel + 4] = working_space[shift + j];
1235 working_space[peak_vel + 5] = working_space[shift + j];
1239 working_space[peak_vel + 6] = working_space[shift + j];
1247 working_space[peak_vel],
1248 working_space[peak_vel + 1],
1249 working_space[peak_vel + 3],
1250 working_space[peak_vel + 2],
1251 working_space[peak_vel + 4],
1252 working_space[peak_vel + 5],
1253 working_space[peak_vel + 6]);
1266 chi2 += (yw -
f) * (yw - f) / ywm;
1273 pmin =
pi, chi_min = chi2;
1283 for (j = 0; j < rozmer; j++) {
1284 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
1286 for (i = 0, j = 0; i <
fNPeaks; i++) {
1288 if (working_space[shift + j] < 0)
1289 working_space[shift + j] = 0;
1290 working_space[2 * i] = working_space[shift + j];
1294 if (working_space[shift + j] <
fXmin)
1295 working_space[shift + j] =
fXmin;
1296 if (working_space[shift + j] >
fXmax)
1297 working_space[shift + j] =
fXmax;
1298 working_space[2 * i + 1] = working_space[shift + j];
1303 if (working_space[shift + j] < 0.001) {
1304 working_space[shift + j] = 0.001;
1306 working_space[peak_vel] = working_space[shift + j];
1309 if (
fFixT ==
false) {
1310 working_space[peak_vel + 1] = working_space[shift + j];
1313 if (
fFixB ==
false) {
1314 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1315 if (working_space[shift + j] < 0)
1316 working_space[shift + j] = -0.001;
1318 working_space[shift + j] = 0.001;
1320 working_space[peak_vel + 2] = working_space[shift + j];
1323 if (
fFixS ==
false) {
1324 working_space[peak_vel + 3] = working_space[shift + j];
1328 working_space[peak_vel + 4] = working_space[shift + j];
1332 working_space[peak_vel + 5] = working_space[shift + j];
1336 working_space[peak_vel + 6] = working_space[shift + j];
1344 for (j = 0; j < rozmer; j++) {
1345 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
1347 for (i = 0, j = 0; i <
fNPeaks; i++) {
1349 if (working_space[shift + j] < 0)
1350 working_space[shift + j] = 0;
1351 working_space[2 * i] = working_space[shift + j];
1355 if (working_space[shift + j] <
fXmin)
1356 working_space[shift + j] =
fXmin;
1357 if (working_space[shift + j] >
fXmax)
1358 working_space[shift + j] =
fXmax;
1359 working_space[2 * i + 1] = working_space[shift + j];
1364 if (working_space[shift + j] < 0.001) {
1365 working_space[shift + j] = 0.001;
1367 working_space[peak_vel] = working_space[shift + j];
1370 if (
fFixT ==
false) {
1371 working_space[peak_vel + 1] = working_space[shift + j];
1374 if (
fFixB ==
false) {
1375 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1376 if (working_space[shift + j] < 0)
1377 working_space[shift + j] = -0.001;
1379 working_space[shift + j] = 0.001;
1381 working_space[peak_vel + 2] = working_space[shift + j];
1384 if (
fFixS ==
false) {
1385 working_space[peak_vel + 3] = working_space[shift + j];
1389 working_space[peak_vel + 4] = working_space[shift + j];
1393 working_space[peak_vel + 5] = working_space[shift + j];
1397 working_space[peak_vel + 6] = working_space[shift + j];
1405 working_space[peak_vel],
1406 working_space[peak_vel + 1],
1407 working_space[peak_vel + 3],
1408 working_space[peak_vel + 2],
1409 working_space[peak_vel + 4],
1410 working_space[peak_vel + 5],
1411 working_space[peak_vel + 6]);
1424 chi += (yw -
f) * (yw - f) / ywm;
1431 alpha = alpha * chi_opt / (2 * chi);
1434 alpha = alpha / 10.0;
1437 }
while (((chi > chi_opt
1442 for (j = 0; j < rozmer; j++) {
1443 working_space[4 * shift + j] = 0;
1444 working_space[2 * shift + j] = 0;
1446 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
1451 working_space[peak_vel], working_space[peak_vel + 1],
1452 working_space[peak_vel + 3],
1453 working_space[peak_vel + 2],
1454 working_space[peak_vel + 4],
1455 working_space[peak_vel + 5],
1456 working_space[peak_vel + 6]);
1457 chi_opt = (yw -
f) * (yw - f) / yw;
1458 chi_cel += (yw -
f) * (yw - f) / yw;
1461 for (j = 0, k = 0; j <
fNPeaks; j++) {
1464 working_space[peak_vel],
1465 working_space[peak_vel + 1],
1466 working_space[peak_vel + 3],
1467 working_space[peak_vel + 2]);
1470 working_space[2 * shift + k] += chi_opt *
c;
1472 working_space[4 * shift + k] += b *
c;
1478 working_space[2 * j + 1],
1479 working_space[peak_vel],
1480 working_space[peak_vel + 1],
1481 working_space[peak_vel + 3],
1482 working_space[peak_vel + 2]);
1485 working_space[2 * shift + k] += chi_opt *
c;
1487 working_space[4 * shift + k] += b *
c;
1494 working_space[peak_vel],
1495 working_space[peak_vel + 1],
1496 working_space[peak_vel + 3],
1497 working_space[peak_vel + 2]);
1500 working_space[2 * shift + k] += chi_opt *
c;
1502 working_space[4 * shift + k] += b *
c;
1506 if (
fFixT ==
false) {
1508 working_space[peak_vel],
1509 working_space[peak_vel + 2]);
1512 working_space[2 * shift + k] += chi_opt *
c;
1514 working_space[4 * shift + k] += b *
c;
1518 if (
fFixB ==
false) {
1520 working_space[peak_vel], working_space[peak_vel + 1],
1521 working_space[peak_vel + 2]);
1524 working_space[2 * shift + k] += chi_opt *
c;
1526 working_space[4 * shift + k] += b *
c;
1530 if (
fFixS ==
false) {
1532 working_space[peak_vel]);
1535 working_space[2 * shift + k] += chi_opt *
c;
1537 working_space[4 * shift + k] += b *
c;
1545 working_space[2 * shift + k] += chi_opt *
c;
1547 working_space[4 * shift + k] += b *
c;
1555 working_space[2 * shift + k] += chi_opt *
c;
1557 working_space[4 * shift + k] += b *
c;
1565 working_space[2 * shift + k] += chi_opt *
c;
1567 working_space[4 * shift + k] += b *
c;
1574 chi_er = chi_cel /
b;
1575 for (i = 0, j = 0; i <
fNPeaks; i++) {
1577 Area(working_space[2 * i], working_space[peak_vel],
1578 working_space[peak_vel + 1], working_space[peak_vel + 2]);
1580 fAmpCalc[i] = working_space[shift + j];
1581 if (working_space[3 * shift + j] != 0)
1584 a =
Derpa(working_space[peak_vel],
1585 working_space[peak_vel + 1],
1586 working_space[peak_vel + 2]);
1587 b = working_space[4 * shift + j];
1608 if (working_space[3 * shift + j] != 0)
1620 if (working_space[3 * shift + j] != 0)
1629 if (
fFixT ==
false) {
1630 fTCalc = working_space[shift + j];
1631 if (working_space[3 * shift + j] != 0)
1640 if (
fFixB ==
false) {
1641 fBCalc = working_space[shift + j];
1642 if (working_space[3 * shift + j] != 0)
1651 if (
fFixS ==
false) {
1652 fSCalc = working_space[shift + j];
1653 if (working_space[3 * shift + j] != 0)
1663 fA0Calc = working_space[shift + j];
1664 if (working_space[3 * shift + j] != 0)
1674 fA1Calc = working_space[shift + j];
1675 if (working_space[3 * shift + j] != 0)
1685 fA2Calc = working_space[shift + j];
1686 if (working_space[3 * shift + j] != 0)
1699 working_space[peak_vel], working_space[peak_vel + 1],
1700 working_space[peak_vel + 3], working_space[peak_vel + 2],
1701 working_space[peak_vel + 4], working_space[peak_vel + 5],
1702 working_space[peak_vel + 6]);
1705 delete[]working_space;
1724 Double_t sk = 0,
b, lambdak, normk, normk_old = 0;
1730 for (i = 0; i < size; i++) {
1731 a[i][size + 2] = -a[i][size];
1732 for (j = 0; j < size; j++) {
1733 a[i][size + 2] += a[i][j] * a[j][size + 1];
1735 normk += a[i][size + 2] * a[i][size + 2];
1740 sk = normk / normk_old;
1744 for (i = 0; i < size; i++) {
1745 a[i][size + 3] = -a[i][size + 2] + sk * a[i][size + 3];
1750 for (i = 0; i < size; i++) {
1751 for (j = 0,
b = 0; j < size; j++) {
1752 b += a[i][j] * a[j][size + 3];
1754 lambdak +=
b * a[i][size + 3];
1757 lambdak = normk / lambdak;
1761 for (i = 0; i < size; i++)
1762 a[i][size + 1] += lambdak * a[i][size + 3];
1859 Int_t i, j, k, shift =
1860 2 *
fNPeaks + 7, peak_vel, rozmer, iter, regul_cycle,
1862 Double_t a,
b, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
1863 0,
pi, pmin = 0, chi_cel = 0, chi_er;
1865 for (i = 0, j = 0; i <
fNPeaks; i++) {
1866 working_space[2 * i] =
fAmpInit[i];
1868 working_space[shift + j] =
fAmpInit[i];
1883 working_space[2 * i + 1] =
fTInit;
1884 if (
fFixT ==
false) {
1885 working_space[shift + j] =
fTInit;
1888 working_space[2 * i + 2] =
fBInit;
1889 if (
fFixB ==
false) {
1890 working_space[shift + j] =
fBInit;
1893 working_space[2 * i + 3] =
fSInit;
1894 if (
fFixS ==
false) {
1895 working_space[shift + j] =
fSInit;
1898 working_space[2 * i + 4] =
fA0Init;
1900 working_space[shift + j] =
fA0Init;
1903 working_space[2 * i + 5] =
fA1Init;
1905 working_space[shift + j] =
fA1Init;
1908 working_space[2 * i + 6] =
fA2Init;
1910 working_space[shift + j] =
fA2Init;
1915 Error (
"FitAwmi",
"All parameters are fixed");
1916 delete [] working_space;
1920 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
1921 delete [] working_space;
1925 for (i = 0; i < rozmer; i++)
1926 working_matrix[i] =
new Double_t[rozmer + 4];
1928 for (j = 0; j < rozmer; j++) {
1929 working_space[3 * shift + j] = 0;
1930 for (k = 0; k <= rozmer; k++) {
1931 working_matrix[j][k] = 0;
1941 for (j = 0, k = 0; j <
fNPeaks; j++) {
1943 working_space[2 * shift + k] =
1945 working_space[peak_vel],
1946 working_space[peak_vel + 1],
1947 working_space[peak_vel + 3],
1948 working_space[peak_vel + 2]);
1952 working_space[2 * shift + k] =
1954 working_space[2 * j + 1], working_space[peak_vel],
1955 working_space[peak_vel + 1],
1956 working_space[peak_vel + 3],
1957 working_space[peak_vel + 2]);
1961 working_space[2 * shift + k] =
1963 working_space[peak_vel],
1964 working_space[peak_vel + 1],
1965 working_space[peak_vel + 3],
1966 working_space[peak_vel + 2]);
1969 if (
fFixT ==
false) {
1970 working_space[2 * shift + k] =
1972 working_space[peak_vel], working_space[peak_vel + 2]);
1975 if (
fFixB ==
false) {
1976 working_space[2 * shift + k] =
1978 working_space[peak_vel], working_space[peak_vel + 1],
1979 working_space[peak_vel + 2]);
1982 if (
fFixS ==
false) {
1983 working_space[2 * shift + k] =
1985 working_space[peak_vel]);
1989 working_space[2 * shift + k] = 1.;
2003 working_space[peak_vel], working_space[peak_vel + 1],
2004 working_space[peak_vel + 3],
2005 working_space[peak_vel + 2],
2006 working_space[peak_vel + 4],
2007 working_space[peak_vel + 5],
2008 working_space[peak_vel + 6]);
2016 chi_opt += (yw -
f) * (yw - f) / ywm;
2034 for (j = 0; j < rozmer; j++) {
2035 for (k = 0; k < rozmer; k++) {
2036 b = working_space[2 * shift +
2037 j] * working_space[2 * shift + k] / ywm;
2039 b = b * (4 * yw - 2 *
f) / ywm;
2040 working_matrix[j][k] +=
b;
2042 working_space[3 * shift + j] +=
b;
2046 b = (f * f - yw * yw) / (ywm * ywm);
2050 for (j = 0; j < rozmer; j++) {
2051 working_matrix[j][rozmer] -= b * working_space[2 * shift + j];
2054 for (i = 0; i < rozmer; i++) {
2055 working_matrix[i][rozmer + 1] = 0;
2058 for (i = 0; i < rozmer; i++) {
2059 working_space[2 * shift + i] = working_matrix[i][rozmer + 1];
2068 for (j = 0; j < rozmer; j++) {
2069 working_space[4 * shift + j] = working_space[shift + j];
2075 chi_min = 10000 * chi2;
2078 chi_min = 0.1 * chi2;
2080 for (
pi = 0.1; flag == 0 &&
pi <= 100;
pi += 0.1) {
2081 for (j = 0; j < rozmer; j++) {
2082 working_space[shift + j] = working_space[4 * shift + j] +
pi * alpha * working_space[2 * shift + j];
2084 for (i = 0, j = 0; i <
fNPeaks; i++) {
2086 if (working_space[shift + j] < 0)
2087 working_space[shift + j] = 0;
2088 working_space[2 * i] = working_space[shift + j];
2092 if (working_space[shift + j] <
fXmin)
2093 working_space[shift + j] =
fXmin;
2094 if (working_space[shift + j] >
fXmax)
2095 working_space[shift + j] =
fXmax;
2096 working_space[2 * i + 1] = working_space[shift + j];
2101 if (working_space[shift + j] < 0.001) {
2102 working_space[shift + j] = 0.001;
2104 working_space[peak_vel] = working_space[shift + j];
2107 if (
fFixT ==
false) {
2108 working_space[peak_vel + 1] = working_space[shift + j];
2111 if (
fFixB ==
false) {
2112 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2113 if (working_space[shift + j] < 0)
2114 working_space[shift + j] = -0.001;
2116 working_space[shift + j] = 0.001;
2118 working_space[peak_vel + 2] = working_space[shift + j];
2121 if (
fFixS ==
false) {
2122 working_space[peak_vel + 3] = working_space[shift + j];
2126 working_space[peak_vel + 4] = working_space[shift + j];
2130 working_space[peak_vel + 5] = working_space[shift + j];
2134 working_space[peak_vel + 6] = working_space[shift + j];
2142 working_space[peak_vel],
2143 working_space[peak_vel + 1],
2144 working_space[peak_vel + 3],
2145 working_space[peak_vel + 2],
2146 working_space[peak_vel + 4],
2147 working_space[peak_vel + 5],
2148 working_space[peak_vel + 6]);
2161 chi2 += (yw -
f) * (yw - f) / ywm;
2168 pmin =
pi, chi_min = chi2;
2178 for (j = 0; j < rozmer; j++) {
2179 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
2181 for (i = 0, j = 0; i <
fNPeaks; i++) {
2183 if (working_space[shift + j] < 0)
2184 working_space[shift + j] = 0;
2185 working_space[2 * i] = working_space[shift + j];
2189 if (working_space[shift + j] <
fXmin)
2190 working_space[shift + j] =
fXmin;
2191 if (working_space[shift + j] >
fXmax)
2192 working_space[shift + j] =
fXmax;
2193 working_space[2 * i + 1] = working_space[shift + j];
2198 if (working_space[shift + j] < 0.001) {
2199 working_space[shift + j] = 0.001;
2201 working_space[peak_vel] = working_space[shift + j];
2204 if (
fFixT ==
false) {
2205 working_space[peak_vel + 1] = working_space[shift + j];
2208 if (
fFixB ==
false) {
2209 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2210 if (working_space[shift + j] < 0)
2211 working_space[shift + j] = -0.001;
2213 working_space[shift + j] = 0.001;
2215 working_space[peak_vel + 2] = working_space[shift + j];
2218 if (
fFixS ==
false) {
2219 working_space[peak_vel + 3] = working_space[shift + j];
2223 working_space[peak_vel + 4] = working_space[shift + j];
2227 working_space[peak_vel + 5] = working_space[shift + j];
2231 working_space[peak_vel + 6] = working_space[shift + j];
2239 for (j = 0; j < rozmer; j++) {
2240 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
2242 for (i = 0, j = 0; i <
fNPeaks; i++) {
2244 if (working_space[shift + j] < 0)
2245 working_space[shift + j] = 0;
2246 working_space[2 * i] = working_space[shift + j];
2250 if (working_space[shift + j] <
fXmin)
2251 working_space[shift + j] =
fXmin;
2252 if (working_space[shift + j] >
fXmax)
2253 working_space[shift + j] =
fXmax;
2254 working_space[2 * i + 1] = working_space[shift + j];
2259 if (working_space[shift + j] < 0.001) {
2260 working_space[shift + j] = 0.001;
2262 working_space[peak_vel] = working_space[shift + j];
2265 if (
fFixT ==
false) {
2266 working_space[peak_vel + 1] = working_space[shift + j];
2269 if (
fFixB ==
false) {
2270 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2271 if (working_space[shift + j] < 0)
2272 working_space[shift + j] = -0.001;
2274 working_space[shift + j] = 0.001;
2276 working_space[peak_vel + 2] = working_space[shift + j];
2279 if (
fFixS ==
false) {
2280 working_space[peak_vel + 3] = working_space[shift + j];
2284 working_space[peak_vel + 4] = working_space[shift + j];
2288 working_space[peak_vel + 5] = working_space[shift + j];
2292 working_space[peak_vel + 6] = working_space[shift + j];
2300 working_space[peak_vel],
2301 working_space[peak_vel + 1],
2302 working_space[peak_vel + 3],
2303 working_space[peak_vel + 2],
2304 working_space[peak_vel + 4],
2305 working_space[peak_vel + 5],
2306 working_space[peak_vel + 6]);
2319 chi += (yw -
f) * (yw - f) / ywm;
2326 alpha = alpha * chi_opt / (2 * chi);
2329 alpha = alpha / 10.0;
2332 }
while (((chi > chi_opt
2337 for (j = 0; j < rozmer; j++) {
2338 working_space[4 * shift + j] = 0;
2339 working_space[2 * shift + j] = 0;
2341 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
2346 working_space[peak_vel], working_space[peak_vel + 1],
2347 working_space[peak_vel + 3],
2348 working_space[peak_vel + 2],
2349 working_space[peak_vel + 4],
2350 working_space[peak_vel + 5],
2351 working_space[peak_vel + 6]);
2352 chi_opt = (yw -
f) * (yw - f) / yw;
2353 chi_cel += (yw -
f) * (yw - f) / yw;
2356 for (j = 0, k = 0; j <
fNPeaks; j++) {
2359 working_space[peak_vel],
2360 working_space[peak_vel + 1],
2361 working_space[peak_vel + 3],
2362 working_space[peak_vel + 2]);
2364 working_space[2 * shift + k] += chi_opt;
2366 working_space[4 * shift + k] +=
b;
2372 working_space[2 * j + 1],
2373 working_space[peak_vel],
2374 working_space[peak_vel + 1],
2375 working_space[peak_vel + 3],
2376 working_space[peak_vel + 2]);
2378 working_space[2 * shift + k] += chi_opt;
2380 working_space[4 * shift + k] +=
b;
2387 working_space[peak_vel],
2388 working_space[peak_vel + 1],
2389 working_space[peak_vel + 3],
2390 working_space[peak_vel + 2]);
2392 working_space[2 * shift + k] += chi_opt;
2394 working_space[4 * shift + k] +=
b;
2398 if (
fFixT ==
false) {
2400 working_space[peak_vel],
2401 working_space[peak_vel + 2]);
2403 working_space[2 * shift + k] += chi_opt;
2405 working_space[4 * shift + k] +=
b;
2409 if (
fFixB ==
false) {
2411 working_space[peak_vel], working_space[peak_vel + 1],
2412 working_space[peak_vel + 2]);
2414 working_space[2 * shift + k] += chi_opt;
2416 working_space[4 * shift + k] +=
b;
2420 if (
fFixS ==
false) {
2422 working_space[peak_vel]);
2424 working_space[2 * shift + k] += chi_opt;
2426 working_space[4 * shift + k] +=
b;
2433 working_space[2 * shift + k] += chi_opt;
2435 working_space[4 * shift + k] +=
b;
2442 working_space[2 * shift + k] += chi_opt;
2444 working_space[4 * shift + k] +=
b;
2451 working_space[2 * shift + k] += chi_opt;
2453 working_space[4 * shift + k] +=
b;
2460 chi_er = chi_cel /
b;
2461 for (i = 0, j = 0; i <
fNPeaks; i++) {
2463 Area(working_space[2 * i], working_space[peak_vel],
2464 working_space[peak_vel + 1], working_space[peak_vel + 2]);
2466 fAmpCalc[i] = working_space[shift + j];
2467 if (working_space[3 * shift + j] != 0)
2470 a =
Derpa(working_space[peak_vel],
2471 working_space[peak_vel + 1],
2472 working_space[peak_vel + 2]);
2473 b = working_space[4 * shift + j];
2494 if (working_space[3 * shift + j] != 0)
2506 if (working_space[3 * shift + j] != 0)
2515 if (
fFixT ==
false) {
2516 fTCalc = working_space[shift + j];
2517 if (working_space[3 * shift + j] != 0)
2526 if (
fFixB ==
false) {
2527 fBCalc = working_space[shift + j];
2528 if (working_space[3 * shift + j] != 0)
2537 if (
fFixS ==
false) {
2538 fSCalc = working_space[shift + j];
2539 if (working_space[3 * shift + j] != 0)
2549 fA0Calc = working_space[shift + j];
2550 if (working_space[3 * shift + j] != 0)
2560 fA1Calc = working_space[shift + j];
2561 if (working_space[3 * shift + j] != 0)
2571 fA2Calc = working_space[shift + j];
2572 if (working_space[3 * shift + j] != 0)
2585 working_space[peak_vel], working_space[peak_vel + 1],
2586 working_space[peak_vel + 3], working_space[peak_vel + 2],
2587 working_space[peak_vel + 4], working_space[peak_vel + 5],
2588 working_space[peak_vel + 6]);
2591 for (i = 0; i < rozmer; i++)
2592 delete [] working_matrix[i];
2593 delete [] working_matrix;
2594 delete [] working_space;
2610 if(xmin<0 || xmax <= xmin){
2611 Error(
"SetFitParameters",
"Wrong range");
2614 if (numberIterations <= 0){
2615 Error(
"SetFitParameters",
"Invalid number of iterations, must be positive");
2618 if (alpha <= 0 || alpha > 1){
2619 Error (
"SetFitParameters",
"Invalid step coefficient alpha, must be > than 0 and <=1");
2625 Error(
"SetFitParameters",
"Wrong type of statistic");
2630 Error(
"SetFitParameters",
"Wrong optimization algorithm");
2636 Error(
"SetFitParameters",
"Wrong power");
2641 Error(
"SetFitParameters",
"Wrong order of Taylor development");
2660 Error (
"SetPeakParameters",
"Invalid sigma, must be > than 0");
2665 Error (
"SetPeakParameters",
"Invalid peak position, must be in the range fXmin, fXmax");
2669 Error (
"SetPeakParameters",
"Invalid peak amplitude, must be > than 0");
Double_t Shape(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma, Double_t t, Double_t s, Double_t b, Double_t a0, Double_t a1, Double_t a2)
This function calculates peaks shape function (see manual) Function parameters:
Double_t fAlpha
convergence coefficient, input parameter, it should be positive number and <=1, for details see refer...
Double_t * fAreaErr
[fNPeaks] array of errors of peak areas
virtual ~TSpectrumFit()
Destructor.
Bool_t fFixSigma
logical value of sigma parameter, which allows to fix the parameter (not to fit). ...
Double_t Derpb(Double_t a, Double_t sigma, Double_t t, Double_t b)
This function calculates derivative of the area of peak according to b parameter. ...
void SetPeakParameters(Double_t sigma, Bool_t fixSigma, const Double_t *positionInit, const Bool_t *fixPosition, const Double_t *ampInit, const Bool_t *fixAmp)
This function sets the following fitting parameters of peaks:
Double_t * fAmpInit
[fNPeaks] array of initial values of peaks amplitudes, input parameters
Int_t fXmax
last fitted channel
Double_t * fPositionCalc
[fNPeaks] array of calculated values of fitted positions, output parameters
Double_t Area(Double_t a, Double_t sigma, Double_t t, Double_t b)
This function calculates area of a peak Function parameters:
void StiefelInversion(Double_t **a, Int_t rozmer)
This function calculates solution of the system of linear equations.
Int_t fFitTaylor
order of Taylor expansion, possible values kFitTaylorOrderFirst, kFitTaylorOrderSecond. It applies only for Awmi fitting function.
Int_t fStatisticType
type of statistics, possible values kFitOptimChiCounts (chi square statistics with counts as weightin...
Double_t Dert(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma, Double_t b)
This function calculates derivative of peaks shape function (see manual) according to relative amplit...
Int_t fPower
possible values kFitPower2,4,6,8,10,12, for details see references. It applies only for Awmi fitting ...
Double_t Derpsigma(Double_t a, Double_t t, Double_t b)
This function calculates derivative of the area of peak according to sigma of peaks.
Double_t * fPositionErr
[fNPeaks] array of position errors
Double_t fTErr
error value of t parameter
void GetTailParameters(Double_t &t, Double_t &tErr, Double_t &b, Double_t &bErr, Double_t &s, Double_t &sErr)
This function gets the tail parameters and their errors.
Double_t fA0Init
initial value of background a0 parameter(backgroud is estimated as a0+a1*x+a2*x*x) ...
Bool_t fFixS
logical value of s parameter, which allows to fix the parameter (not to fit).
Int_t fAlphaOptim
optimization of convergence algorithm, possible values kFitAlphaHalving, kFitAlphaOptimal ...
The TNamed class is the base class for all named ROOT classes.
unsigned int r3[N_CITIES]
Double_t fA1Calc
calculated value of background a1 parameter
Double_t fA2Init
initial value of background a2 parameter(backgroud is estimated as a0+a1*x+a2*x*x) ...
void SetBackgroundParameters(Double_t a0Init, Bool_t fixA0, Double_t a1Init, Bool_t fixA1, Double_t a2Init, Bool_t fixA2)
This function sets the following fitting parameters of background:
Double_t * fPositionInit
[fNPeaks] array of initial values of peaks positions, input parameters
Double_t Dera2(Double_t i)
Derivative of background according to a2.
Double_t fSigmaCalc
calculated value of sigma parameter
Int_t fNumberIterations
number of iterations in fitting procedure, input parameter, it should be > 0
Double_t Derfc(Double_t x)
This function calculates derivative of error function of x.
Double_t fSCalc
calculated value of s parameter
Double_t fChi
here the fitting functions return resulting chi square
Double_t fA2Err
error value of background a2 parameter
Bool_t fFixB
logical value of b parameter, which allows to fix the parameter (not to fit).
Double_t fA1Init
initial value of background a1 parameter(backgroud is estimated as a0+a1*x+a2*x*x) ...
Double_t fTInit
initial value of t parameter (relative amplitude of tail), for details see html manual and references...
Double_t fSErr
error value of s parameter
Double_t fBCalc
calculated value of b parameter
Double_t * fAmpErr
[fNPeaks] array of amplitude errors
Double_t Dersigma(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma, Double_t t, Double_t s, Double_t b)
This function calculates derivative of peaks shape function (see manual) according to sigma of peaks...
unsigned int r1[N_CITIES]
Int_t fXmin
first fitted channel
Double_t fBInit
initial value of b parameter (slope), for details see html manual and references
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Double_t Erfc(Double_t x)
Double_t fBErr
error value of b parameter
Double_t Deramp(Double_t i, Double_t i0, Double_t sigma, Double_t t, Double_t s, Double_t b)
This function calculates derivative of peak shape function (see manual) according to amplitude of pea...
Double_t fA1Err
error value of background a1 parameter
void SetFitParameters(Int_t xmin, Int_t xmax, Int_t numberIterations, Double_t alpha, Int_t statisticType, Int_t alphaOptim, Int_t power, Int_t fitTaylor)
This function sets the following fitting parameters:
Double_t Deri0(Double_t i, Double_t amp, Double_t i0, Double_t sigma, Double_t t, Double_t s, Double_t b)
This function calculates derivative of peak shape function (see manual) according to peak position...
Bool_t fFixA0
logical value of a0 parameter, which allows to fix the parameter (not to fit).
Double_t Derpa(Double_t sigma, Double_t t, Double_t b)
This function calculates derivative of the area of peak according to its amplitude.
Double_t Ders(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma)
This function calculates derivative of peaks shape function (see manual) according to relative amplit...
Double_t fA0Err
error value of background a0 parameter
Int_t fNPeaks
number of peaks present in fit, input parameter, it should be > 0
Double_t Dera1(Double_t i)
Derivative of background according to a1.
Double_t Derderi0(Double_t i, Double_t amp, Double_t i0, Double_t sigma)
This function calculates second derivative of peak shape function (see manual) according to peak posi...
you should not use this method at all Int_t Int_t Double_t Double_t Double_t e
Double_t Derdersigma(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma)
This function calculates second derivative of peaks shape function (see manual) according to sigma of...
Double_t Derpt(Double_t a, Double_t sigma, Double_t b)
This function calculates derivative of the area of peak according to t parameter. ...
Bool_t * fFixPosition
[fNPeaks] array of logical values which allow to fix appropriate positions (not fit). However they are present in the estimated functional
Bool_t * fFixAmp
[fNPeaks] array of logical values which allow to fix appropriate amplitudes (not fit). However they are present in the estimated functional
Double_t fSInit
initial value of s parameter (relative amplitude of step), for details see html manual and references...
TSpectrumFit(void)
Default constructor.
void SetTailParameters(Double_t tInit, Bool_t fixT, Double_t bInit, Bool_t fixB, Double_t sInit, Bool_t fixS)
This function sets the following fitting parameters of tails of peaks.
Double_t Ourpowl(Double_t a, Int_t pw)
Power function.
Advanced 1-dimensional spectra fitting functions.
you should not use this method at all Int_t Int_t Double_t Double_t Double_t Int_t Double_t Double_t Double_t Double_t b
Double_t Derb(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma, Double_t t, Double_t b)
This function calculates derivative of peaks shape function (see manual) according to slope b...
void GetBackgroundParameters(Double_t &a0, Double_t &a0Err, Double_t &a1, Double_t &a1Err, Double_t &a2, Double_t &a2Err)
This function gets the background parameters and their errors.
Double_t * fArea
[fNPeaks] array of calculated areas of peaks
Double_t fSigmaInit
initial value of sigma parameter
Double_t fA2Calc
calculated value of background a2 parameter
Double_t Sqrt(Double_t x)
Double_t fA0Calc
calculated value of background a0 parameter
Double_t fTCalc
calculated value of t parameter
void GetSigma(Double_t &sigma, Double_t &sigmaErr)
This function gets the sigma parameter and its error.
void FitAwmi(Double_t *source)
This function fits the source spectrum.
void FitStiefel(Double_t *source)
This function fits the source spectrum.
Double_t * fAmpCalc
[fNPeaks] array of calculated values of fitted amplitudes, output parameters
unsigned int r2[N_CITIES]
Double_t fSigmaErr
error value of sigma parameter
Bool_t fFixT
logical value of t parameter, which allows to fix the parameter (not to fit).
Bool_t fFixA1
logical value of a1 parameter, which allows to fix the parameter (not to fit).
Bool_t fFixA2
logical value of a2 parameter, which allows to fix the parameter (not to fit).