105 if (numberPeaks <= 0){
106 Error (
"TSpectrumFit",
"Invalid number of peaks, must be > than 0");
181 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
193 c =
c * t * (da1 + t * (da2 + t * da3));
205 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
216 c = (-1.) * dap *
c * t * t * (da1 + t * (2. * da2 + t * 3. * da3)) -
235 p = (i - i0) /
sigma;
250 r =
r *
Erfc(p + 1. / (2. *
b));
272 p = (i - i0) /
sigma;
275 r1 = 2. * p * exp(-p * p) /
sigma;
282 c = p + 1. / (2. *
b);
286 r2 = -t * exp(
e) *
Erfc(
c) / (
d *
b);
292 r1 = amp * (r1 + r2 + r3 + r4);
309 p = (i - i0) /
sigma;
317 r2 = 0, r3 = 0, r4 = 0;
318 r1 = amp * (r1 + r2 + r3 + r4);
341 for (j = 0; j < num_of_fitted_peaks; j++) {
342 p = (i - parameter[2 * j + 1]) /
sigma;
346 r1 = 2. * p * p * exp(-p * p) /
sigma;
354 c = p + 1. / (2. *
b);
358 r2 = -t * p * exp(
e) *
Erfc(
c) / (
d *
b);
359 r3 = -t * p * exp(
e) *
Derfc(
c) /
d;
363 r4 = -s * p *
Derfc(p) /
d;
364 r =
r + parameter[2 * j] * (r1 + r2 + r3 + r4);
384 for (j = 0; j < num_of_fitted_peaks; j++) {
385 p = (i - parameter[2 * j + 1]) /
sigma;
389 r1 = exp(-p * p) * p * p * (4. * p * p - 6) / (
sigma *
sigma);
395 r2 = 0, r3 = 0, r4 = 0;
396 r =
r + parameter[2 * j] * (r1 + r2 + r3 + r4);
417 for (j = 0; j < num_of_fitted_peaks; j++) {
418 p = (i - parameter[2 * j + 1]) /
sigma;
419 c = p + 1. / (2. *
b);
424 r =
r + parameter[2 * j] * r1;
445 for (j = 0; j < num_of_fitted_peaks; j++) {
446 p = (i - parameter[2 * j + 1]) /
sigma;
448 r =
r + parameter[2 * j] * r1;
472 for (j = 0; j < num_of_fitted_peaks && t != 0; j++) {
473 p = (i - parameter[2 * j + 1]) /
sigma;
474 c = p + 1. / (2. *
b);
485 r =
r + parameter[2 * j] * r1;
487 r = -
r * t / (2. *
b *
b);
526 for (j = 0; j < num_of_fitted_peaks; j++) {
528 p = (i - parameter[2 * j + 1]) /
sigma;
531 if (i == parameter[2 * j + 1])
548 c = p + 1. / (2. *
b);
552 r2 = t * exp(
e) *
Erfc(
c) / 2.;
556 r3 = s *
Erfc(p) / 2.;
557 r =
r + parameter[2 * j] * (r1 + r2 + r3);
559 r =
r + a0 + a1 * i + a2 * i * i;
578 r =
a *
sigma * (odm_pi + t *
b * exp(
r));
600 r =
sigma * (odm_pi + t *
b * exp(
r));
622 r =
a * (odm_pi + t *
b * exp(
r));
663 r = (-1) * 0.25 / (
b *
b);
665 r =
a *
sigma * t * exp(
r) * (1 - 2 *
r);
686 if (pw > 10)
c *= a2;
687 if (pw > 12)
c *= a2;
824 Int_t i, j, k, shift =
825 2 *
fNPeaks + 7, peak_vel, rozmer, iter, pw, regul_cycle,
827 Double_t a,
b,
c,
d = 0, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
828 0, pi, pmin = 0, chi_cel = 0, chi_er;
830 for (i = 0, j = 0; i <
fNPeaks; i++) {
833 working_space[shift + j] =
fAmpInit[i];
848 working_space[2 * i + 1] =
fTInit;
849 if (
fFixT ==
false) {
850 working_space[shift + j] =
fTInit;
853 working_space[2 * i + 2] =
fBInit;
854 if (
fFixB ==
false) {
855 working_space[shift + j] =
fBInit;
858 working_space[2 * i + 3] =
fSInit;
859 if (
fFixS ==
false) {
860 working_space[shift + j] =
fSInit;
863 working_space[2 * i + 4] =
fA0Init;
865 working_space[shift + j] =
fA0Init;
868 working_space[2 * i + 5] =
fA1Init;
870 working_space[shift + j] =
fA1Init;
873 working_space[2 * i + 6] =
fA2Init;
875 working_space[shift + j] =
fA2Init;
880 delete [] working_space;
881 Error (
"FitAwmi",
"All parameters are fixed");
885 delete [] working_space;
886 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
890 for (j = 0; j < rozmer; j++) {
891 working_space[2 * shift + j] = 0, working_space[3 * shift + j] = 0;
896 chi_opt = 0, pw =
fPower - 2;
901 working_space[peak_vel], working_space[peak_vel + 1],
902 working_space[peak_vel + 3],
903 working_space[peak_vel + 2],
904 working_space[peak_vel + 4],
905 working_space[peak_vel + 5],
906 working_space[peak_vel + 6]);
914 chi_opt += (yw -
f) * (yw -
f) / ywm;
934 for (j = 0, k = 0; j <
fNPeaks; j++) {
937 working_space[peak_vel],
938 working_space[peak_vel + 1],
939 working_space[peak_vel + 3],
940 working_space[peak_vel + 2]);
944 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
945 working_space[2 * shift + k] +=
b *
c;
946 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
947 working_space[3 * shift + k] +=
b *
c;
951 b =
a * (yw -
f) / ywm;
952 working_space[2 * shift + k] +=
b *
c;
954 working_space[3 * shift + k] +=
b *
c;
961 working_space[2 * j + 1],
962 working_space[peak_vel],
963 working_space[peak_vel + 1],
964 working_space[peak_vel + 3],
965 working_space[peak_vel + 2]);
968 working_space[2 * j + 1],
969 working_space[peak_vel]);
975 if (((
a +
d) <= 0 &&
a >= 0) || ((
a +
d) >= 0 &&
a <= 0))
983 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
984 working_space[2 * shift + k] +=
b *
c;
985 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
986 working_space[3 * shift + k] +=
b *
c;
990 b =
a * (yw -
f) / ywm;
991 working_space[2 * shift + k] +=
b *
c;
993 working_space[3 * shift + k] +=
b *
c;
1001 working_space[peak_vel],
1002 working_space[peak_vel + 1],
1003 working_space[peak_vel + 3],
1004 working_space[peak_vel + 2]);
1007 working_space, working_space[peak_vel]);
1013 if (((
a +
d) <= 0 &&
a >= 0) || ((
a +
d) >= 0 &&
a <= 0))
1021 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
1022 working_space[2 * shift + k] +=
b *
c;
1023 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
1024 working_space[3 * shift + k] +=
b *
c;
1028 b =
a * (yw -
f) / ywm;
1029 working_space[2 * shift + k] +=
b *
c;
1031 working_space[3 * shift + k] +=
b *
c;
1036 if (
fFixT ==
false) {
1038 working_space[peak_vel],
1039 working_space[peak_vel + 2]);
1043 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
1044 working_space[2 * shift + k] +=
b *
c;
1045 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
1046 working_space[3 * shift + k] +=
b *
c;
1050 b =
a * (yw -
f) / ywm;
1051 working_space[2 * shift + k] +=
b *
c;
1053 working_space[3 * shift + k] +=
b *
c;
1058 if (
fFixB ==
false) {
1060 working_space[peak_vel], working_space[peak_vel + 1],
1061 working_space[peak_vel + 2]);
1065 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
1066 working_space[2 * shift + k] +=
b *
c;
1067 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
1068 working_space[3 * shift + k] +=
b *
c;
1072 b =
a * (yw -
f) / ywm;
1073 working_space[2 * shift + k] +=
b *
c;
1075 working_space[3 * shift + k] +=
b *
c;
1080 if (
fFixS ==
false) {
1082 working_space[peak_vel]);
1086 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
1087 working_space[2 * shift + k] +=
b *
c;
1088 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
1089 working_space[3 * shift + k] +=
b *
c;
1093 b =
a * (yw -
f) / ywm;
1094 working_space[2 * shift + k] +=
b *
c;
1096 working_space[3 * shift + k] +=
b *
c;
1106 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
1107 working_space[2 * shift + k] +=
b *
c;
1108 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
1109 working_space[3 * shift + k] +=
b *
c;
1113 b =
a * (yw -
f) / ywm;
1114 working_space[2 * shift + k] +=
b *
c;
1116 working_space[3 * shift + k] +=
b *
c;
1126 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
1127 working_space[2 * shift + k] +=
b *
c;
1128 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
1129 working_space[3 * shift + k] +=
b *
c;
1133 b =
a * (yw -
f) / ywm;
1134 working_space[2 * shift + k] +=
b *
c;
1136 working_space[3 * shift + k] +=
b *
c;
1146 b =
a * (yw * yw -
f *
f) / (ywm * ywm);
1147 working_space[2 * shift + k] +=
b *
c;
1148 b =
a *
a * (4 * yw - 2 *
f) / (ywm * ywm);
1149 working_space[3 * shift + k] +=
b *
c;
1153 b =
a * (yw -
f) / ywm;
1154 working_space[2 * shift + k] +=
b *
c;
1156 working_space[3 * shift + k] +=
b *
c;
1162 for (j = 0; j < rozmer; j++) {
1163 if (
TMath::Abs(working_space[3 * shift + j]) > 0.000001)
1164 working_space[2 * shift + j] = working_space[2 * shift + j] /
TMath::Abs(working_space[3 * shift + j]);
1166 working_space[2 * shift + j] = 0;
1175 for (j = 0; j < rozmer; j++) {
1176 working_space[4 * shift + j] = working_space[shift + j];
1182 chi_min = 10000 * chi2;
1185 chi_min = 0.1 * chi2;
1187 for (pi = 0.1; flag == 0 && pi <= 100; pi += 0.1) {
1188 for (j = 0; j < rozmer; j++) {
1189 working_space[shift + j] = working_space[4 * shift + j] + pi * alpha * working_space[2 * shift + j];
1191 for (i = 0, j = 0; i <
fNPeaks; i++) {
1193 if (working_space[shift + j] < 0)
1194 working_space[shift + j] = 0;
1195 working_space[2 * i] = working_space[shift + j];
1199 if (working_space[shift + j] <
fXmin)
1200 working_space[shift + j] =
fXmin;
1201 if (working_space[shift + j] >
fXmax)
1202 working_space[shift + j] =
fXmax;
1203 working_space[2 * i + 1] = working_space[shift + j];
1208 if (working_space[shift + j] < 0.001) {
1209 working_space[shift + j] = 0.001;
1211 working_space[peak_vel] = working_space[shift + j];
1214 if (
fFixT ==
false) {
1215 working_space[peak_vel + 1] = working_space[shift + j];
1218 if (
fFixB ==
false) {
1219 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1220 if (working_space[shift + j] < 0)
1221 working_space[shift + j] = -0.001;
1223 working_space[shift + j] = 0.001;
1225 working_space[peak_vel + 2] = working_space[shift + j];
1228 if (
fFixS ==
false) {
1229 working_space[peak_vel + 3] = working_space[shift + j];
1233 working_space[peak_vel + 4] = working_space[shift + j];
1237 working_space[peak_vel + 5] = working_space[shift + j];
1241 working_space[peak_vel + 6] = working_space[shift + j];
1249 working_space[peak_vel],
1250 working_space[peak_vel + 1],
1251 working_space[peak_vel + 3],
1252 working_space[peak_vel + 2],
1253 working_space[peak_vel + 4],
1254 working_space[peak_vel + 5],
1255 working_space[peak_vel + 6]);
1268 chi2 += (yw -
f) * (yw -
f) / ywm;
1275 pmin = pi, chi_min = chi2;
1285 for (j = 0; j < rozmer; j++) {
1286 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
1288 for (i = 0, j = 0; i <
fNPeaks; i++) {
1290 if (working_space[shift + j] < 0)
1291 working_space[shift + j] = 0;
1292 working_space[2 * i] = working_space[shift + j];
1296 if (working_space[shift + j] <
fXmin)
1297 working_space[shift + j] =
fXmin;
1298 if (working_space[shift + j] >
fXmax)
1299 working_space[shift + j] =
fXmax;
1300 working_space[2 * i + 1] = working_space[shift + j];
1305 if (working_space[shift + j] < 0.001) {
1306 working_space[shift + j] = 0.001;
1308 working_space[peak_vel] = working_space[shift + j];
1311 if (
fFixT ==
false) {
1312 working_space[peak_vel + 1] = working_space[shift + j];
1315 if (
fFixB ==
false) {
1316 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1317 if (working_space[shift + j] < 0)
1318 working_space[shift + j] = -0.001;
1320 working_space[shift + j] = 0.001;
1322 working_space[peak_vel + 2] = working_space[shift + j];
1325 if (
fFixS ==
false) {
1326 working_space[peak_vel + 3] = working_space[shift + j];
1330 working_space[peak_vel + 4] = working_space[shift + j];
1334 working_space[peak_vel + 5] = working_space[shift + j];
1338 working_space[peak_vel + 6] = working_space[shift + j];
1346 for (j = 0; j < rozmer; j++) {
1347 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
1349 for (i = 0, j = 0; i <
fNPeaks; i++) {
1351 if (working_space[shift + j] < 0)
1352 working_space[shift + j] = 0;
1353 working_space[2 * i] = working_space[shift + j];
1357 if (working_space[shift + j] <
fXmin)
1358 working_space[shift + j] =
fXmin;
1359 if (working_space[shift + j] >
fXmax)
1360 working_space[shift + j] =
fXmax;
1361 working_space[2 * i + 1] = working_space[shift + j];
1366 if (working_space[shift + j] < 0.001) {
1367 working_space[shift + j] = 0.001;
1369 working_space[peak_vel] = working_space[shift + j];
1372 if (
fFixT ==
false) {
1373 working_space[peak_vel + 1] = working_space[shift + j];
1376 if (
fFixB ==
false) {
1377 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1378 if (working_space[shift + j] < 0)
1379 working_space[shift + j] = -0.001;
1381 working_space[shift + j] = 0.001;
1383 working_space[peak_vel + 2] = working_space[shift + j];
1386 if (
fFixS ==
false) {
1387 working_space[peak_vel + 3] = working_space[shift + j];
1391 working_space[peak_vel + 4] = working_space[shift + j];
1395 working_space[peak_vel + 5] = working_space[shift + j];
1399 working_space[peak_vel + 6] = working_space[shift + j];
1407 working_space[peak_vel],
1408 working_space[peak_vel + 1],
1409 working_space[peak_vel + 3],
1410 working_space[peak_vel + 2],
1411 working_space[peak_vel + 4],
1412 working_space[peak_vel + 5],
1413 working_space[peak_vel + 6]);
1426 chi += (yw -
f) * (yw -
f) / ywm;
1433 alpha = alpha * chi_opt / (2 * chi);
1436 alpha = alpha / 10.0;
1439 }
while (((chi > chi_opt
1444 for (j = 0; j < rozmer; j++) {
1445 working_space[4 * shift + j] = 0;
1446 working_space[2 * shift + j] = 0;
1448 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
1453 working_space[peak_vel], working_space[peak_vel + 1],
1454 working_space[peak_vel + 3],
1455 working_space[peak_vel + 2],
1456 working_space[peak_vel + 4],
1457 working_space[peak_vel + 5],
1458 working_space[peak_vel + 6]);
1459 chi_opt = (yw -
f) * (yw -
f) / yw;
1460 chi_cel += (yw -
f) * (yw -
f) / yw;
1463 for (j = 0, k = 0; j <
fNPeaks; j++) {
1466 working_space[peak_vel],
1467 working_space[peak_vel + 1],
1468 working_space[peak_vel + 3],
1469 working_space[peak_vel + 2]);
1472 working_space[2 * shift + k] += chi_opt *
c;
1474 working_space[4 * shift + k] +=
b *
c;
1480 working_space[2 * j + 1],
1481 working_space[peak_vel],
1482 working_space[peak_vel + 1],
1483 working_space[peak_vel + 3],
1484 working_space[peak_vel + 2]);
1487 working_space[2 * shift + k] += chi_opt *
c;
1489 working_space[4 * shift + k] +=
b *
c;
1496 working_space[peak_vel],
1497 working_space[peak_vel + 1],
1498 working_space[peak_vel + 3],
1499 working_space[peak_vel + 2]);
1502 working_space[2 * shift + k] += chi_opt *
c;
1504 working_space[4 * shift + k] +=
b *
c;
1508 if (
fFixT ==
false) {
1510 working_space[peak_vel],
1511 working_space[peak_vel + 2]);
1514 working_space[2 * shift + k] += chi_opt *
c;
1516 working_space[4 * shift + k] +=
b *
c;
1520 if (
fFixB ==
false) {
1522 working_space[peak_vel], working_space[peak_vel + 1],
1523 working_space[peak_vel + 2]);
1526 working_space[2 * shift + k] += chi_opt *
c;
1528 working_space[4 * shift + k] +=
b *
c;
1532 if (
fFixS ==
false) {
1534 working_space[peak_vel]);
1537 working_space[2 * shift + k] += chi_opt *
c;
1539 working_space[4 * shift + k] +=
b *
c;
1547 working_space[2 * shift + k] += chi_opt *
c;
1549 working_space[4 * shift + k] +=
b *
c;
1557 working_space[2 * shift + k] += chi_opt *
c;
1559 working_space[4 * shift + k] +=
b *
c;
1567 working_space[2 * shift + k] += chi_opt *
c;
1569 working_space[4 * shift + k] +=
b *
c;
1576 chi_er = chi_cel /
b;
1577 for (i = 0, j = 0; i <
fNPeaks; i++) {
1579 Area(working_space[2 * i], working_space[peak_vel],
1580 working_space[peak_vel + 1], working_space[peak_vel + 2]);
1582 fAmpCalc[i] = working_space[shift + j];
1583 if (working_space[3 * shift + j] != 0)
1586 a =
Derpa(working_space[peak_vel],
1587 working_space[peak_vel + 1],
1588 working_space[peak_vel + 2]);
1589 b = working_space[4 * shift + j];
1610 if (working_space[3 * shift + j] != 0)
1622 if (working_space[3 * shift + j] != 0)
1631 if (
fFixT ==
false) {
1632 fTCalc = working_space[shift + j];
1633 if (working_space[3 * shift + j] != 0)
1642 if (
fFixB ==
false) {
1643 fBCalc = working_space[shift + j];
1644 if (working_space[3 * shift + j] != 0)
1653 if (
fFixS ==
false) {
1654 fSCalc = working_space[shift + j];
1655 if (working_space[3 * shift + j] != 0)
1665 fA0Calc = working_space[shift + j];
1666 if (working_space[3 * shift + j] != 0)
1676 fA1Calc = working_space[shift + j];
1677 if (working_space[3 * shift + j] != 0)
1687 fA2Calc = working_space[shift + j];
1688 if (working_space[3 * shift + j] != 0)
1701 working_space[peak_vel], working_space[peak_vel + 1],
1702 working_space[peak_vel + 3], working_space[peak_vel + 2],
1703 working_space[peak_vel + 4], working_space[peak_vel + 5],
1704 working_space[peak_vel + 6]);
1707 delete[]working_space;
1726 Double_t sk = 0,
b, lambdak, normk, normk_old = 0;
1732 for (i = 0; i <
size; i++) {
1734 for (j = 0; j <
size; j++) {
1742 sk = normk / normk_old;
1746 for (i = 0; i <
size; i++) {
1752 for (i = 0; i <
size; i++) {
1753 for (j = 0,
b = 0; j <
size; j++) {
1754 b +=
a[i][j] *
a[j][
size + 3];
1756 lambdak +=
b *
a[i][
size + 3];
1759 lambdak = normk / lambdak;
1763 for (i = 0; i <
size; i++)
1861 Int_t i, j, k, shift =
1862 2 *
fNPeaks + 7, peak_vel, rozmer, iter, regul_cycle,
1864 Double_t a,
b, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
1865 0, pi, pmin = 0, chi_cel = 0, chi_er;
1867 for (i = 0, j = 0; i <
fNPeaks; i++) {
1868 working_space[2 * i] =
fAmpInit[i];
1870 working_space[shift + j] =
fAmpInit[i];
1885 working_space[2 * i + 1] =
fTInit;
1886 if (
fFixT ==
false) {
1887 working_space[shift + j] =
fTInit;
1890 working_space[2 * i + 2] =
fBInit;
1891 if (
fFixB ==
false) {
1892 working_space[shift + j] =
fBInit;
1895 working_space[2 * i + 3] =
fSInit;
1896 if (
fFixS ==
false) {
1897 working_space[shift + j] =
fSInit;
1900 working_space[2 * i + 4] =
fA0Init;
1902 working_space[shift + j] =
fA0Init;
1905 working_space[2 * i + 5] =
fA1Init;
1907 working_space[shift + j] =
fA1Init;
1910 working_space[2 * i + 6] =
fA2Init;
1912 working_space[shift + j] =
fA2Init;
1917 Error (
"FitAwmi",
"All parameters are fixed");
1918 delete [] working_space;
1922 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
1923 delete [] working_space;
1927 for (i = 0; i < rozmer; i++)
1928 working_matrix[i] =
new Double_t[rozmer + 4];
1930 for (j = 0; j < rozmer; j++) {
1931 working_space[3 * shift + j] = 0;
1932 for (k = 0; k < (rozmer + 4); k++) {
1933 working_matrix[j][k] = 0;
1943 for (j = 0, k = 0; j <
fNPeaks; j++) {
1945 working_space[2 * shift + k] =
1947 working_space[peak_vel],
1948 working_space[peak_vel + 1],
1949 working_space[peak_vel + 3],
1950 working_space[peak_vel + 2]);
1954 working_space[2 * shift + k] =
1956 working_space[2 * j + 1], working_space[peak_vel],
1957 working_space[peak_vel + 1],
1958 working_space[peak_vel + 3],
1959 working_space[peak_vel + 2]);
1963 working_space[2 * shift + k] =
1965 working_space[peak_vel],
1966 working_space[peak_vel + 1],
1967 working_space[peak_vel + 3],
1968 working_space[peak_vel + 2]);
1971 if (
fFixT ==
false) {
1972 working_space[2 * shift + k] =
1974 working_space[peak_vel], working_space[peak_vel + 2]);
1977 if (
fFixB ==
false) {
1978 working_space[2 * shift + k] =
1980 working_space[peak_vel], working_space[peak_vel + 1],
1981 working_space[peak_vel + 2]);
1984 if (
fFixS ==
false) {
1985 working_space[2 * shift + k] =
1987 working_space[peak_vel]);
1991 working_space[2 * shift + k] = 1.;
2005 working_space[peak_vel], working_space[peak_vel + 1],
2006 working_space[peak_vel + 3],
2007 working_space[peak_vel + 2],
2008 working_space[peak_vel + 4],
2009 working_space[peak_vel + 5],
2010 working_space[peak_vel + 6]);
2018 chi_opt += (yw -
f) * (yw -
f) / ywm;
2036 for (j = 0; j < rozmer; j++) {
2037 for (k = 0; k < rozmer; k++) {
2038 b = working_space[2 * shift +
2039 j] * working_space[2 * shift + k] / ywm;
2041 b =
b * (4 * yw - 2 *
f) / ywm;
2042 working_matrix[j][k] +=
b;
2044 working_space[3 * shift + j] +=
b;
2048 b = (
f *
f - yw * yw) / (ywm * ywm);
2052 for (j = 0; j < rozmer; j++) {
2053 working_matrix[j][rozmer] -=
b * working_space[2 * shift + j];
2056 for (i = 0; i < rozmer; i++) {
2057 working_matrix[i][rozmer + 1] = 0;
2060 for (i = 0; i < rozmer; i++) {
2061 working_space[2 * shift + i] = working_matrix[i][rozmer + 1];
2070 for (j = 0; j < rozmer; j++) {
2071 working_space[4 * shift + j] = working_space[shift + j];
2077 chi_min = 10000 * chi2;
2080 chi_min = 0.1 * chi2;
2082 for (pi = 0.1; flag == 0 && pi <= 100; pi += 0.1) {
2083 for (j = 0; j < rozmer; j++) {
2084 working_space[shift + j] = working_space[4 * shift + j] + pi * alpha * working_space[2 * shift + j];
2086 for (i = 0, j = 0; i <
fNPeaks; i++) {
2088 if (working_space[shift + j] < 0)
2089 working_space[shift + j] = 0;
2090 working_space[2 * i] = working_space[shift + j];
2094 if (working_space[shift + j] <
fXmin)
2095 working_space[shift + j] =
fXmin;
2096 if (working_space[shift + j] >
fXmax)
2097 working_space[shift + j] =
fXmax;
2098 working_space[2 * i + 1] = working_space[shift + j];
2103 if (working_space[shift + j] < 0.001) {
2104 working_space[shift + j] = 0.001;
2106 working_space[peak_vel] = working_space[shift + j];
2109 if (
fFixT ==
false) {
2110 working_space[peak_vel + 1] = working_space[shift + j];
2113 if (
fFixB ==
false) {
2114 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2115 if (working_space[shift + j] < 0)
2116 working_space[shift + j] = -0.001;
2118 working_space[shift + j] = 0.001;
2120 working_space[peak_vel + 2] = working_space[shift + j];
2123 if (
fFixS ==
false) {
2124 working_space[peak_vel + 3] = working_space[shift + j];
2128 working_space[peak_vel + 4] = working_space[shift + j];
2132 working_space[peak_vel + 5] = working_space[shift + j];
2136 working_space[peak_vel + 6] = working_space[shift + j];
2144 working_space[peak_vel],
2145 working_space[peak_vel + 1],
2146 working_space[peak_vel + 3],
2147 working_space[peak_vel + 2],
2148 working_space[peak_vel + 4],
2149 working_space[peak_vel + 5],
2150 working_space[peak_vel + 6]);
2163 chi2 += (yw -
f) * (yw -
f) / ywm;
2170 pmin = pi, chi_min = chi2;
2180 for (j = 0; j < rozmer; j++) {
2181 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
2183 for (i = 0, j = 0; i <
fNPeaks; i++) {
2185 if (working_space[shift + j] < 0)
2186 working_space[shift + j] = 0;
2187 working_space[2 * i] = working_space[shift + j];
2191 if (working_space[shift + j] <
fXmin)
2192 working_space[shift + j] =
fXmin;
2193 if (working_space[shift + j] >
fXmax)
2194 working_space[shift + j] =
fXmax;
2195 working_space[2 * i + 1] = working_space[shift + j];
2200 if (working_space[shift + j] < 0.001) {
2201 working_space[shift + j] = 0.001;
2203 working_space[peak_vel] = working_space[shift + j];
2206 if (
fFixT ==
false) {
2207 working_space[peak_vel + 1] = working_space[shift + j];
2210 if (
fFixB ==
false) {
2211 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2212 if (working_space[shift + j] < 0)
2213 working_space[shift + j] = -0.001;
2215 working_space[shift + j] = 0.001;
2217 working_space[peak_vel + 2] = working_space[shift + j];
2220 if (
fFixS ==
false) {
2221 working_space[peak_vel + 3] = working_space[shift + j];
2225 working_space[peak_vel + 4] = working_space[shift + j];
2229 working_space[peak_vel + 5] = working_space[shift + j];
2233 working_space[peak_vel + 6] = working_space[shift + j];
2241 for (j = 0; j < rozmer; j++) {
2242 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
2244 for (i = 0, j = 0; i <
fNPeaks; i++) {
2246 if (working_space[shift + j] < 0)
2247 working_space[shift + j] = 0;
2248 working_space[2 * i] = working_space[shift + j];
2252 if (working_space[shift + j] <
fXmin)
2253 working_space[shift + j] =
fXmin;
2254 if (working_space[shift + j] >
fXmax)
2255 working_space[shift + j] =
fXmax;
2256 working_space[2 * i + 1] = working_space[shift + j];
2261 if (working_space[shift + j] < 0.001) {
2262 working_space[shift + j] = 0.001;
2264 working_space[peak_vel] = working_space[shift + j];
2267 if (
fFixT ==
false) {
2268 working_space[peak_vel + 1] = working_space[shift + j];
2271 if (
fFixB ==
false) {
2272 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2273 if (working_space[shift + j] < 0)
2274 working_space[shift + j] = -0.001;
2276 working_space[shift + j] = 0.001;
2278 working_space[peak_vel + 2] = working_space[shift + j];
2281 if (
fFixS ==
false) {
2282 working_space[peak_vel + 3] = working_space[shift + j];
2286 working_space[peak_vel + 4] = working_space[shift + j];
2290 working_space[peak_vel + 5] = working_space[shift + j];
2294 working_space[peak_vel + 6] = working_space[shift + j];
2302 working_space[peak_vel],
2303 working_space[peak_vel + 1],
2304 working_space[peak_vel + 3],
2305 working_space[peak_vel + 2],
2306 working_space[peak_vel + 4],
2307 working_space[peak_vel + 5],
2308 working_space[peak_vel + 6]);
2321 chi += (yw -
f) * (yw -
f) / ywm;
2328 alpha = alpha * chi_opt / (2 * chi);
2331 alpha = alpha / 10.0;
2334 }
while (((chi > chi_opt
2339 for (j = 0; j < rozmer; j++) {
2340 working_space[4 * shift + j] = 0;
2341 working_space[2 * shift + j] = 0;
2343 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
2348 working_space[peak_vel], working_space[peak_vel + 1],
2349 working_space[peak_vel + 3],
2350 working_space[peak_vel + 2],
2351 working_space[peak_vel + 4],
2352 working_space[peak_vel + 5],
2353 working_space[peak_vel + 6]);
2354 chi_opt = (yw -
f) * (yw -
f) / yw;
2355 chi_cel += (yw -
f) * (yw -
f) / yw;
2358 for (j = 0, k = 0; j <
fNPeaks; j++) {
2361 working_space[peak_vel],
2362 working_space[peak_vel + 1],
2363 working_space[peak_vel + 3],
2364 working_space[peak_vel + 2]);
2366 working_space[2 * shift + k] += chi_opt;
2368 working_space[4 * shift + k] +=
b;
2374 working_space[2 * j + 1],
2375 working_space[peak_vel],
2376 working_space[peak_vel + 1],
2377 working_space[peak_vel + 3],
2378 working_space[peak_vel + 2]);
2380 working_space[2 * shift + k] += chi_opt;
2382 working_space[4 * shift + k] +=
b;
2389 working_space[peak_vel],
2390 working_space[peak_vel + 1],
2391 working_space[peak_vel + 3],
2392 working_space[peak_vel + 2]);
2394 working_space[2 * shift + k] += chi_opt;
2396 working_space[4 * shift + k] +=
b;
2400 if (
fFixT ==
false) {
2402 working_space[peak_vel],
2403 working_space[peak_vel + 2]);
2405 working_space[2 * shift + k] += chi_opt;
2407 working_space[4 * shift + k] +=
b;
2411 if (
fFixB ==
false) {
2413 working_space[peak_vel], working_space[peak_vel + 1],
2414 working_space[peak_vel + 2]);
2416 working_space[2 * shift + k] += chi_opt;
2418 working_space[4 * shift + k] +=
b;
2422 if (
fFixS ==
false) {
2424 working_space[peak_vel]);
2426 working_space[2 * shift + k] += chi_opt;
2428 working_space[4 * shift + k] +=
b;
2435 working_space[2 * shift + k] += chi_opt;
2437 working_space[4 * shift + k] +=
b;
2444 working_space[2 * shift + k] += chi_opt;
2446 working_space[4 * shift + k] +=
b;
2453 working_space[2 * shift + k] += chi_opt;
2455 working_space[4 * shift + k] +=
b;
2462 chi_er = chi_cel /
b;
2463 for (i = 0, j = 0; i <
fNPeaks; i++) {
2465 Area(working_space[2 * i], working_space[peak_vel],
2466 working_space[peak_vel + 1], working_space[peak_vel + 2]);
2468 fAmpCalc[i] = working_space[shift + j];
2469 if (working_space[3 * shift + j] != 0)
2472 a =
Derpa(working_space[peak_vel],
2473 working_space[peak_vel + 1],
2474 working_space[peak_vel + 2]);
2475 b = working_space[4 * shift + j];
2496 if (working_space[3 * shift + j] != 0)
2508 if (working_space[3 * shift + j] != 0)
2517 if (
fFixT ==
false) {
2518 fTCalc = working_space[shift + j];
2519 if (working_space[3 * shift + j] != 0)
2528 if (
fFixB ==
false) {
2529 fBCalc = working_space[shift + j];
2530 if (working_space[3 * shift + j] != 0)
2539 if (
fFixS ==
false) {
2540 fSCalc = working_space[shift + j];
2541 if (working_space[3 * shift + j] != 0)
2551 fA0Calc = working_space[shift + j];
2552 if (working_space[3 * shift + j] != 0)
2562 fA1Calc = working_space[shift + j];
2563 if (working_space[3 * shift + j] != 0)
2573 fA2Calc = working_space[shift + j];
2574 if (working_space[3 * shift + j] != 0)
2587 working_space[peak_vel], working_space[peak_vel + 1],
2588 working_space[peak_vel + 3], working_space[peak_vel + 2],
2589 working_space[peak_vel + 4], working_space[peak_vel + 5],
2590 working_space[peak_vel + 6]);
2593 for (i = 0; i < rozmer; i++)
2594 delete [] working_matrix[i];
2595 delete [] working_matrix;
2596 delete [] working_space;
2613 Error(
"SetFitParameters",
"Wrong range");
2616 if (numberIterations <= 0){
2617 Error(
"SetFitParameters",
"Invalid number of iterations, must be positive");
2620 if (alpha <= 0 || alpha > 1){
2621 Error (
"SetFitParameters",
"Invalid step coefficient alpha, must be > than 0 and <=1");
2627 Error(
"SetFitParameters",
"Wrong type of statistic");
2632 Error(
"SetFitParameters",
"Wrong optimization algorithm");
2638 Error(
"SetFitParameters",
"Wrong power");
2643 Error(
"SetFitParameters",
"Wrong order of Taylor development");
2662 Error (
"SetPeakParameters",
"Invalid sigma, must be > than 0");
2667 Error (
"SetPeakParameters",
"Invalid peak position, must be in the range fXmin, fXmax");
2671 Error (
"SetPeakParameters",
"Invalid peak amplitude, must be > than 0");
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
The TNamed class is the base class for all named ROOT classes.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Advanced 1-dimensional spectra fitting functions.
Bool_t fFixSigma
logical value of sigma parameter, which allows to fix the parameter (not to fit).
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 Area(Double_t a, Double_t sigma, Double_t t, Double_t b)
This function calculates area of a peak Function parameters:
Double_t * fAmpErr
[fNPeaks] array of amplitude errors
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:
virtual ~TSpectrumFit()
Destructor.
Double_t fAlpha
convergence coefficient, input parameter, it should be positive number and <=1, for details see refer...
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.
Double_t Ourpowl(Double_t a, Int_t pw)
Power function.
Int_t fAlphaOptim
optimization of convergence algorithm, possible values kFitAlphaHalving, kFitAlphaOptimal
Double_t fA1Init
initial value of background a1 parameter(backgroud is estimated as a0+a1*x+a2*x*x)
void FitStiefel(Double_t *source)
This function fits the source spectrum.
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 * fPositionCalc
[fNPeaks] array of calculated values of fitted positions, output parameters
Double_t fSInit
initial value of s parameter (relative amplitude of step), for details see html manual and references
Double_t fA1Calc
calculated value of background a1 parameter
Double_t fSigmaErr
error value of sigma parameter
Bool_t * fFixAmp
[fNPeaks] array of logical values which allow to fix appropriate amplitudes (not fit)....
Double_t * fAmpCalc
[fNPeaks] array of calculated values of fitted amplitudes, output parameters
Bool_t fFixB
logical value of b parameter, which allows to fix the parameter (not to fit).
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.
Double_t fBErr
error value of b parameter
void FitAwmi(Double_t *source)
This function fits the source spectrum.
Int_t fNumberIterations
number of iterations in fitting procedure, input parameter, it should be > 0
Double_t * fAmpInit
[fNPeaks] array of initial values of peaks amplitudes, input parameters
Double_t fA1Err
error value of background a1 parameter
Double_t fA2Err
error value of background a2 parameter
Bool_t * fFixPosition
[fNPeaks] array of logical values which allow to fix appropriate positions (not fit)....
Double_t fA0Calc
calculated value of background a0 parameter
Int_t fNPeaks
number of peaks present in fit, input parameter, it should be > 0
Double_t fBCalc
calculated value of b parameter
Bool_t fFixA2
logical value of a2 parameter, which allows to fix the parameter (not to fit).
Double_t Erfc(Double_t x)
TSpectrumFit(void)
Default constructor.
Double_t fA2Init
initial value of background a2 parameter(backgroud is estimated as a0+a1*x+a2*x*x)
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 fFixA1
logical value of a1 parameter, which allows to fix the parameter (not to fit).
Double_t fA2Calc
calculated value of background a2 parameter
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.
Double_t * fPositionErr
[fNPeaks] array of position errors
Double_t fTInit
initial value of t parameter (relative amplitude of tail), for details see html manual and references
Bool_t fFixT
logical value of t parameter, which allows to fix the parameter (not to fit).
void GetSigma(Double_t &sigma, Double_t &sigmaErr)
This function gets the sigma parameter and its error.
Int_t fFitTaylor
order of Taylor expansion, possible values kFitTaylorOrderFirst, kFitTaylorOrderSecond....
Double_t Dera1(Double_t i)
Derivative of background according to a1.
Double_t fSigmaCalc
calculated value of sigma parameter
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 fSErr
error value of s parameter
Bool_t fFixA0
logical value of a0 parameter, which allows to fix the parameter (not to fit).
Int_t fPower
possible values kFitPower2,4,6,8,10,12, for details see references. It applies only for Awmi fitting ...
Double_t fChi
here the fitting functions return resulting chi square
Double_t * fArea
[fNPeaks] array of calculated areas of peaks
Double_t Dera2(Double_t i)
Derivative of background according to a2.
Double_t fBInit
initial value of b parameter (slope), for details see html manual and references
Double_t * fPositionInit
[fNPeaks] array of initial values of peaks positions, input parameters
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.
Bool_t fFixS
logical value of s parameter, which allows to fix the parameter (not to fit).
Double_t fA0Init
initial value of background a0 parameter(backgroud is estimated as a0+a1*x+a2*x*x)
Int_t fXmin
first fitted channel
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 fSCalc
calculated value of s parameter
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.
Int_t fXmax
last fitted channel
Int_t fStatisticType
type of statistics, possible values kFitOptimChiCounts (chi square statistics with counts as weightin...
Double_t fTErr
error value of t parameter
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...
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.
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 fSigmaInit
initial value of sigma 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 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...
Double_t fA0Err
error value of background a0 parameter
Double_t fTCalc
calculated value of t parameter
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 * fAreaErr
[fNPeaks] array of errors of peak areas
void StiefelInversion(Double_t **a, Int_t rozmer)
This function calculates solution of the system of linear equations.
Double_t Derfc(Double_t x)
This function calculates derivative of error function of 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:
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 Sqrt(Double_t x)