63 fNumberIterations = 1;
66 fStatisticType = kFitOptimChiCounts;
67 fAlphaOptim = kFitAlphaHalving;
69 fFitTaylor = kFitTaylorOrderFirst;
167 if (numberPeaks <= 0){
168 Error (
"TSpectrumFit",
"Invalid number of peaks, must be > than 0");
250 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
262 c = c * t * (da1 + t * (da2 + t * da3));
279 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
290 c = (-1.) * dap * c * t * t * (da1 + t * (2. * da2 + t * 3. * da3)) -
314 p = (i - i0) / sigma;
329 r = r *
Erfc(p + 1. / (2. * b));
332 q = q + s *
Erfc(p) / 2.;
356 p = (i - i0) / sigma;
359 r1 = 2. * p *
exp(-p * p) / sigma;
366 c = p + 1. / (2. * b);
370 r2 = -t *
exp(e) *
Erfc(c) / (d * b);
375 r4 = -s *
Derfc(p) / d;
376 r1 = amp * (r1 + r2 + r3 + r4);
398 p = (i - i0) / sigma;
405 r1 = r1 * (4 * p * p - 2) / (sigma * sigma);
406 r2 = 0, r3 = 0, r4 = 0;
407 r1 = amp * (r1 + r2 + r3 + r4);
435 for (j = 0; j < num_of_fitted_peaks; j++) {
436 p = (i - parameter[2 * j + 1]) / sigma;
440 r1 = 2. * p * p *
exp(-p * p) / sigma;
448 c = p + 1. / (2. * b);
452 r2 = -t * p *
exp(e) *
Erfc(c) / (d * b);
453 r3 = -t * p *
exp(e) *
Derfc(c) / d;
457 r4 = -s * p *
Derfc(p) / d;
458 r = r + parameter[2 * j] * (r1 + r2 + r3 + r4);
483 for (j = 0; j < num_of_fitted_peaks; j++) {
484 p = (i - parameter[2 * j + 1]) / sigma;
488 r1 =
exp(-p * p) * p * p * (4. * p * p - 6) / (sigma * sigma);
494 r2 = 0, r3 = 0, r4 = 0;
495 r = r + parameter[2 * j] * (r1 + r2 + r3 + r4);
521 for (j = 0; j < num_of_fitted_peaks; j++) {
522 p = (i - parameter[2 * j + 1]) / sigma;
523 c = p + 1. / (2. * b);
528 r = r + parameter[2 * j] *
r1;
554 for (j = 0; j < num_of_fitted_peaks; j++) {
555 p = (i - parameter[2 * j + 1]) / sigma;
557 r = r + parameter[2 * j] *
r1;
586 for (j = 0; j < num_of_fitted_peaks && t != 0; j++) {
587 p = (i - parameter[2 * j + 1]) / sigma;
588 c = p + 1. / (2. * b);
591 r1 = r1 +
Derfc(c) / 2.;
599 r = r + parameter[2 * j] *
r1;
601 r = -r * t / (2. * b * b);
645 for (j = 0; j < num_of_fitted_peaks; j++) {
647 p = (i - parameter[2 * j + 1]) / sigma;
650 if (i == parameter[2 * j + 1])
667 c = p + 1. / (2. * b);
671 r2 = t *
exp(e) *
Erfc(c) / 2.;
675 r3 = s *
Erfc(p) / 2.;
676 r = r + parameter[2 * j] * (r1 + r2 +
r3);
678 r = r + a0 + a1 * i + a2 * i * i;
702 r = a * sigma * (odm_pi + t * b *
exp(r));
705 r = a * sigma * odm_pi;
729 r = sigma * (odm_pi + t * b *
exp(r));
753 r = a * (odm_pi + t * b *
exp(r));
780 r = a * sigma * b *
exp(r);
804 r = (-1) * 0.25 / (b * b);
806 r = a * sigma * t *
exp(r) * (1 - 2 *
r);
827 if (pw > 10) c *= a2;
828 if (pw > 12) c *= a2;
1348 Int_t i, j, k, shift =
1349 2 *
fNPeaks + 7, peak_vel, rozmer,
iter, pw, regul_cycle,
1351 Double_t a, b,
c, d = 0, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
1352 0,
pi, pmin = 0, chi_cel = 0, chi_er;
1354 for (i = 0, j = 0; i <
fNPeaks; i++) {
1355 working_space[2 * i] =
fAmpInit[i];
1357 working_space[shift + j] =
fAmpInit[i];
1372 working_space[2 * i + 1] =
fTInit;
1373 if (
fFixT ==
false) {
1374 working_space[shift + j] =
fTInit;
1377 working_space[2 * i + 2] =
fBInit;
1378 if (
fFixB ==
false) {
1379 working_space[shift + j] =
fBInit;
1382 working_space[2 * i + 3] =
fSInit;
1383 if (
fFixS ==
false) {
1384 working_space[shift + j] =
fSInit;
1387 working_space[2 * i + 4] =
fA0Init;
1389 working_space[shift + j] =
fA0Init;
1392 working_space[2 * i + 5] =
fA1Init;
1394 working_space[shift + j] =
fA1Init;
1397 working_space[2 * i + 6] =
fA2Init;
1399 working_space[shift + j] =
fA2Init;
1404 delete [] working_space;
1405 Error (
"FitAwmi",
"All parameters are fixed");
1409 delete [] working_space;
1410 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
1414 for (j = 0; j < rozmer; j++) {
1415 working_space[2 * shift + j] = 0, working_space[3 * shift + j] = 0;
1420 chi_opt = 0, pw =
fPower - 2;
1425 working_space[peak_vel], working_space[peak_vel + 1],
1426 working_space[peak_vel + 3],
1427 working_space[peak_vel + 2],
1428 working_space[peak_vel + 4],
1429 working_space[peak_vel + 5],
1430 working_space[peak_vel + 6]);
1438 chi_opt += (yw -
f) * (yw - f) / ywm;
1458 for (j = 0, k = 0; j <
fNPeaks; j++) {
1461 working_space[peak_vel],
1462 working_space[peak_vel + 1],
1463 working_space[peak_vel + 3],
1464 working_space[peak_vel + 2]);
1468 b = a * (yw * yw - f *
f) / (ywm * ywm);
1469 working_space[2 * shift + k] += b *
c;
1470 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1471 working_space[3 * shift + k] += b *
c;
1475 b = a * (yw -
f) / ywm;
1476 working_space[2 * shift + k] += b *
c;
1478 working_space[3 * shift + k] += b *
c;
1485 working_space[2 * j + 1],
1486 working_space[peak_vel],
1487 working_space[peak_vel + 1],
1488 working_space[peak_vel + 3],
1489 working_space[peak_vel + 2]);
1492 working_space[2 * j + 1],
1493 working_space[peak_vel]);
1499 if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
1507 b = a * (yw * yw - f *
f) / (ywm * ywm);
1508 working_space[2 * shift + k] += b *
c;
1509 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1510 working_space[3 * shift + k] += b *
c;
1514 b = a * (yw -
f) / ywm;
1515 working_space[2 * shift + k] += b *
c;
1517 working_space[3 * shift + k] += b *
c;
1525 working_space[peak_vel],
1526 working_space[peak_vel + 1],
1527 working_space[peak_vel + 3],
1528 working_space[peak_vel + 2]);
1531 working_space, working_space[peak_vel]);
1537 if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
1545 b = a * (yw * yw - f *
f) / (ywm * ywm);
1546 working_space[2 * shift + k] += b *
c;
1547 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1548 working_space[3 * shift + k] += b *
c;
1552 b = a * (yw -
f) / ywm;
1553 working_space[2 * shift + k] += b *
c;
1555 working_space[3 * shift + k] += b *
c;
1560 if (
fFixT ==
false) {
1562 working_space[peak_vel],
1563 working_space[peak_vel + 2]);
1567 b = a * (yw * yw - f *
f) / (ywm * ywm);
1568 working_space[2 * shift + k] += b *
c;
1569 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1570 working_space[3 * shift + k] += b *
c;
1574 b = a * (yw -
f) / ywm;
1575 working_space[2 * shift + k] += b *
c;
1577 working_space[3 * shift + k] += b *
c;
1582 if (
fFixB ==
false) {
1584 working_space[peak_vel], working_space[peak_vel + 1],
1585 working_space[peak_vel + 2]);
1589 b = a * (yw * yw - f *
f) / (ywm * ywm);
1590 working_space[2 * shift + k] += b *
c;
1591 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1592 working_space[3 * shift + k] += b *
c;
1596 b = a * (yw -
f) / ywm;
1597 working_space[2 * shift + k] += b *
c;
1599 working_space[3 * shift + k] += b *
c;
1604 if (
fFixS ==
false) {
1606 working_space[peak_vel]);
1610 b = a * (yw * yw - f *
f) / (ywm * ywm);
1611 working_space[2 * shift + k] += b *
c;
1612 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1613 working_space[3 * shift + k] += b *
c;
1617 b = a * (yw -
f) / ywm;
1618 working_space[2 * shift + k] += b *
c;
1620 working_space[3 * shift + k] += b *
c;
1630 b = a * (yw * yw - f *
f) / (ywm * ywm);
1631 working_space[2 * shift + k] += b *
c;
1632 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1633 working_space[3 * shift + k] += b *
c;
1637 b = a * (yw -
f) / ywm;
1638 working_space[2 * shift + k] += b *
c;
1640 working_space[3 * shift + k] += b *
c;
1650 b = a * (yw * yw - f *
f) / (ywm * ywm);
1651 working_space[2 * shift + k] += b *
c;
1652 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1653 working_space[3 * shift + k] += b *
c;
1657 b = a * (yw -
f) / ywm;
1658 working_space[2 * shift + k] += b *
c;
1660 working_space[3 * shift + k] += b *
c;
1670 b = a * (yw * yw - f *
f) / (ywm * ywm);
1671 working_space[2 * shift + k] += b *
c;
1672 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1673 working_space[3 * shift + k] += b *
c;
1677 b = a * (yw -
f) / ywm;
1678 working_space[2 * shift + k] += b *
c;
1680 working_space[3 * shift + k] += b *
c;
1686 for (j = 0; j < rozmer; j++) {
1687 if (
TMath::Abs(working_space[3 * shift + j]) > 0.000001)
1688 working_space[2 * shift + j] = working_space[2 * shift + j] /
TMath::Abs(working_space[3 * shift + j]);
1690 working_space[2 * shift + j] = 0;
1699 for (j = 0; j < rozmer; j++) {
1700 working_space[4 * shift + j] = working_space[shift + j];
1706 chi_min = 10000 * chi2;
1709 chi_min = 0.1 * chi2;
1711 for (
pi = 0.1; flag == 0 &&
pi <= 100;
pi += 0.1) {
1712 for (j = 0; j < rozmer; j++) {
1713 working_space[shift + j] = working_space[4 * shift + j] +
pi * alpha * working_space[2 * shift + j];
1715 for (i = 0, j = 0; i <
fNPeaks; i++) {
1717 if (working_space[shift + j] < 0)
1718 working_space[shift + j] = 0;
1719 working_space[2 * i] = working_space[shift + j];
1723 if (working_space[shift + j] <
fXmin)
1724 working_space[shift + j] =
fXmin;
1725 if (working_space[shift + j] >
fXmax)
1726 working_space[shift + j] =
fXmax;
1727 working_space[2 * i + 1] = working_space[shift + j];
1732 if (working_space[shift + j] < 0.001) {
1733 working_space[shift + j] = 0.001;
1735 working_space[peak_vel] = working_space[shift + j];
1738 if (
fFixT ==
false) {
1739 working_space[peak_vel + 1] = working_space[shift + j];
1742 if (
fFixB ==
false) {
1743 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1744 if (working_space[shift + j] < 0)
1745 working_space[shift + j] = -0.001;
1747 working_space[shift + j] = 0.001;
1749 working_space[peak_vel + 2] = working_space[shift + j];
1752 if (
fFixS ==
false) {
1753 working_space[peak_vel + 3] = working_space[shift + j];
1757 working_space[peak_vel + 4] = working_space[shift + j];
1761 working_space[peak_vel + 5] = working_space[shift + j];
1765 working_space[peak_vel + 6] = working_space[shift + j];
1773 working_space[peak_vel],
1774 working_space[peak_vel + 1],
1775 working_space[peak_vel + 3],
1776 working_space[peak_vel + 2],
1777 working_space[peak_vel + 4],
1778 working_space[peak_vel + 5],
1779 working_space[peak_vel + 6]);
1792 chi2 += (yw -
f) * (yw - f) / ywm;
1799 pmin =
pi, chi_min = chi2;
1809 for (j = 0; j < rozmer; j++) {
1810 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
1812 for (i = 0, j = 0; i <
fNPeaks; i++) {
1814 if (working_space[shift + j] < 0)
1815 working_space[shift + j] = 0;
1816 working_space[2 * i] = working_space[shift + j];
1820 if (working_space[shift + j] <
fXmin)
1821 working_space[shift + j] =
fXmin;
1822 if (working_space[shift + j] >
fXmax)
1823 working_space[shift + j] =
fXmax;
1824 working_space[2 * i + 1] = working_space[shift + j];
1829 if (working_space[shift + j] < 0.001) {
1830 working_space[shift + j] = 0.001;
1832 working_space[peak_vel] = working_space[shift + j];
1835 if (
fFixT ==
false) {
1836 working_space[peak_vel + 1] = working_space[shift + j];
1839 if (
fFixB ==
false) {
1840 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1841 if (working_space[shift + j] < 0)
1842 working_space[shift + j] = -0.001;
1844 working_space[shift + j] = 0.001;
1846 working_space[peak_vel + 2] = working_space[shift + j];
1849 if (
fFixS ==
false) {
1850 working_space[peak_vel + 3] = working_space[shift + j];
1854 working_space[peak_vel + 4] = working_space[shift + j];
1858 working_space[peak_vel + 5] = working_space[shift + j];
1862 working_space[peak_vel + 6] = working_space[shift + j];
1870 for (j = 0; j < rozmer; j++) {
1871 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
1873 for (i = 0, j = 0; i <
fNPeaks; i++) {
1875 if (working_space[shift + j] < 0)
1876 working_space[shift + j] = 0;
1877 working_space[2 * i] = working_space[shift + j];
1881 if (working_space[shift + j] <
fXmin)
1882 working_space[shift + j] =
fXmin;
1883 if (working_space[shift + j] >
fXmax)
1884 working_space[shift + j] =
fXmax;
1885 working_space[2 * i + 1] = working_space[shift + j];
1890 if (working_space[shift + j] < 0.001) {
1891 working_space[shift + j] = 0.001;
1893 working_space[peak_vel] = working_space[shift + j];
1896 if (
fFixT ==
false) {
1897 working_space[peak_vel + 1] = working_space[shift + j];
1900 if (
fFixB ==
false) {
1901 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1902 if (working_space[shift + j] < 0)
1903 working_space[shift + j] = -0.001;
1905 working_space[shift + j] = 0.001;
1907 working_space[peak_vel + 2] = working_space[shift + j];
1910 if (
fFixS ==
false) {
1911 working_space[peak_vel + 3] = working_space[shift + j];
1915 working_space[peak_vel + 4] = working_space[shift + j];
1919 working_space[peak_vel + 5] = working_space[shift + j];
1923 working_space[peak_vel + 6] = working_space[shift + j];
1931 working_space[peak_vel],
1932 working_space[peak_vel + 1],
1933 working_space[peak_vel + 3],
1934 working_space[peak_vel + 2],
1935 working_space[peak_vel + 4],
1936 working_space[peak_vel + 5],
1937 working_space[peak_vel + 6]);
1950 chi += (yw -
f) * (yw - f) / ywm;
1957 alpha = alpha * chi_opt / (2 * chi);
1960 alpha = alpha / 10.0;
1963 }
while (((chi > chi_opt
1968 for (j = 0; j < rozmer; j++) {
1969 working_space[4 * shift + j] = 0;
1970 working_space[2 * shift + j] = 0;
1972 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
1977 working_space[peak_vel], working_space[peak_vel + 1],
1978 working_space[peak_vel + 3],
1979 working_space[peak_vel + 2],
1980 working_space[peak_vel + 4],
1981 working_space[peak_vel + 5],
1982 working_space[peak_vel + 6]);
1983 chi_opt = (yw -
f) * (yw - f) / yw;
1984 chi_cel += (yw -
f) * (yw - f) / yw;
1987 for (j = 0, k = 0; j <
fNPeaks; j++) {
1990 working_space[peak_vel],
1991 working_space[peak_vel + 1],
1992 working_space[peak_vel + 3],
1993 working_space[peak_vel + 2]);
1996 working_space[2 * shift + k] += chi_opt *
c;
1998 working_space[4 * shift + k] += b *
c;
2004 working_space[2 * j + 1],
2005 working_space[peak_vel],
2006 working_space[peak_vel + 1],
2007 working_space[peak_vel + 3],
2008 working_space[peak_vel + 2]);
2011 working_space[2 * shift + k] += chi_opt *
c;
2013 working_space[4 * shift + k] += b *
c;
2020 working_space[peak_vel],
2021 working_space[peak_vel + 1],
2022 working_space[peak_vel + 3],
2023 working_space[peak_vel + 2]);
2026 working_space[2 * shift + k] += chi_opt *
c;
2028 working_space[4 * shift + k] += b *
c;
2032 if (
fFixT ==
false) {
2034 working_space[peak_vel],
2035 working_space[peak_vel + 2]);
2038 working_space[2 * shift + k] += chi_opt *
c;
2040 working_space[4 * shift + k] += b *
c;
2044 if (
fFixB ==
false) {
2046 working_space[peak_vel], working_space[peak_vel + 1],
2047 working_space[peak_vel + 2]);
2050 working_space[2 * shift + k] += chi_opt *
c;
2052 working_space[4 * shift + k] += b *
c;
2056 if (
fFixS ==
false) {
2058 working_space[peak_vel]);
2061 working_space[2 * shift + k] += chi_opt *
c;
2063 working_space[4 * shift + k] += b *
c;
2071 working_space[2 * shift + k] += chi_opt *
c;
2073 working_space[4 * shift + k] += b *
c;
2081 working_space[2 * shift + k] += chi_opt *
c;
2083 working_space[4 * shift + k] += b *
c;
2091 working_space[2 * shift + k] += chi_opt *
c;
2093 working_space[4 * shift + k] += b *
c;
2100 chi_er = chi_cel / b;
2101 for (i = 0, j = 0; i <
fNPeaks; i++) {
2103 Area(working_space[2 * i], working_space[peak_vel],
2104 working_space[peak_vel + 1], working_space[peak_vel + 2]);
2106 fAmpCalc[i] = working_space[shift + j];
2107 if (working_space[3 * shift + j] != 0)
2110 a =
Derpa(working_space[peak_vel],
2111 working_space[peak_vel + 1],
2112 working_space[peak_vel + 2]);
2113 b = working_space[4 * shift + j];
2134 if (working_space[3 * shift + j] != 0)
2146 if (working_space[3 * shift + j] != 0)
2155 if (
fFixT ==
false) {
2156 fTCalc = working_space[shift + j];
2157 if (working_space[3 * shift + j] != 0)
2166 if (
fFixB ==
false) {
2167 fBCalc = working_space[shift + j];
2168 if (working_space[3 * shift + j] != 0)
2177 if (
fFixS ==
false) {
2178 fSCalc = working_space[shift + j];
2179 if (working_space[3 * shift + j] != 0)
2189 fA0Calc = working_space[shift + j];
2190 if (working_space[3 * shift + j] != 0)
2200 fA1Calc = working_space[shift + j];
2201 if (working_space[3 * shift + j] != 0)
2211 fA2Calc = working_space[shift + j];
2212 if (working_space[3 * shift + j] != 0)
2225 working_space[peak_vel], working_space[peak_vel + 1],
2226 working_space[peak_vel + 3], working_space[peak_vel + 2],
2227 working_space[peak_vel + 4], working_space[peak_vel + 5],
2228 working_space[peak_vel + 6]);
2231 delete[]working_space;
2256 Double_t sk = 0, b, lambdak, normk, normk_old = 0;
2262 for (i = 0; i < size; i++) {
2263 a[i][size + 2] = -a[i][size];
2264 for (j = 0; j < size; j++) {
2265 a[i][size + 2] += a[i][j] * a[j][size + 1];
2267 normk += a[i][size + 2] * a[i][size + 2];
2272 sk = normk / normk_old;
2276 for (i = 0; i < size; i++) {
2277 a[i][size + 3] = -a[i][size + 2] + sk * a[i][size + 3];
2282 for (i = 0; i < size; i++) {
2283 for (j = 0, b = 0; j < size; j++) {
2284 b += a[i][j] * a[j][size + 3];
2286 lambdak += b * a[i][size + 3];
2289 lambdak = normk / lambdak;
2293 for (i = 0; i < size; i++)
2294 a[i][size + 1] += lambdak * a[i][size + 3];
2297 }
while (k < size &&
TMath::Abs(normk) > 1e-50);
2551 Int_t i, j, k, shift =
2552 2 *
fNPeaks + 7, peak_vel, rozmer,
iter, regul_cycle,
2554 Double_t a, b, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
2555 0,
pi, pmin = 0, chi_cel = 0, chi_er;
2557 for (i = 0, j = 0; i <
fNPeaks; i++) {
2558 working_space[2 * i] =
fAmpInit[i];
2560 working_space[shift + j] =
fAmpInit[i];
2575 working_space[2 * i + 1] =
fTInit;
2576 if (
fFixT ==
false) {
2577 working_space[shift + j] =
fTInit;
2580 working_space[2 * i + 2] =
fBInit;
2581 if (
fFixB ==
false) {
2582 working_space[shift + j] =
fBInit;
2585 working_space[2 * i + 3] =
fSInit;
2586 if (
fFixS ==
false) {
2587 working_space[shift + j] =
fSInit;
2590 working_space[2 * i + 4] =
fA0Init;
2592 working_space[shift + j] =
fA0Init;
2595 working_space[2 * i + 5] =
fA1Init;
2597 working_space[shift + j] =
fA1Init;
2600 working_space[2 * i + 6] =
fA2Init;
2602 working_space[shift + j] =
fA2Init;
2607 Error (
"FitAwmi",
"All parameters are fixed");
2608 delete [] working_space;
2612 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
2613 delete [] working_space;
2617 for (i = 0; i < rozmer; i++)
2618 working_matrix[i] =
new Double_t[rozmer + 4];
2620 for (j = 0; j < rozmer; j++) {
2621 working_space[3 * shift + j] = 0;
2622 for (k = 0; k <= rozmer; k++) {
2623 working_matrix[j][k] = 0;
2633 for (j = 0, k = 0; j <
fNPeaks; j++) {
2635 working_space[2 * shift + k] =
2637 working_space[peak_vel],
2638 working_space[peak_vel + 1],
2639 working_space[peak_vel + 3],
2640 working_space[peak_vel + 2]);
2644 working_space[2 * shift + k] =
2646 working_space[2 * j + 1], working_space[peak_vel],
2647 working_space[peak_vel + 1],
2648 working_space[peak_vel + 3],
2649 working_space[peak_vel + 2]);
2653 working_space[2 * shift + k] =
2655 working_space[peak_vel],
2656 working_space[peak_vel + 1],
2657 working_space[peak_vel + 3],
2658 working_space[peak_vel + 2]);
2661 if (
fFixT ==
false) {
2662 working_space[2 * shift + k] =
2664 working_space[peak_vel], working_space[peak_vel + 2]);
2667 if (
fFixB ==
false) {
2668 working_space[2 * shift + k] =
2670 working_space[peak_vel], working_space[peak_vel + 1],
2671 working_space[peak_vel + 2]);
2674 if (
fFixS ==
false) {
2675 working_space[2 * shift + k] =
2677 working_space[peak_vel]);
2681 working_space[2 * shift + k] = 1.;
2695 working_space[peak_vel], working_space[peak_vel + 1],
2696 working_space[peak_vel + 3],
2697 working_space[peak_vel + 2],
2698 working_space[peak_vel + 4],
2699 working_space[peak_vel + 5],
2700 working_space[peak_vel + 6]);
2708 chi_opt += (yw -
f) * (yw - f) / ywm;
2726 for (j = 0; j < rozmer; j++) {
2727 for (k = 0; k < rozmer; k++) {
2728 b = working_space[2 * shift +
2729 j] * working_space[2 * shift + k] / ywm;
2731 b = b * (4 * yw - 2 *
f) / ywm;
2732 working_matrix[j][k] += b;
2734 working_space[3 * shift + j] += b;
2738 b = (f * f - yw * yw) / (ywm * ywm);
2742 for (j = 0; j < rozmer; j++) {
2743 working_matrix[j][rozmer] -= b * working_space[2 * shift + j];
2746 for (i = 0; i < rozmer; i++) {
2747 working_matrix[i][rozmer + 1] = 0;
2750 for (i = 0; i < rozmer; i++) {
2751 working_space[2 * shift + i] = working_matrix[i][rozmer + 1];
2760 for (j = 0; j < rozmer; j++) {
2761 working_space[4 * shift + j] = working_space[shift + j];
2767 chi_min = 10000 * chi2;
2770 chi_min = 0.1 * chi2;
2772 for (
pi = 0.1; flag == 0 &&
pi <= 100;
pi += 0.1) {
2773 for (j = 0; j < rozmer; j++) {
2774 working_space[shift + j] = working_space[4 * shift + j] +
pi * alpha * working_space[2 * shift + j];
2776 for (i = 0, j = 0; i <
fNPeaks; i++) {
2778 if (working_space[shift + j] < 0)
2779 working_space[shift + j] = 0;
2780 working_space[2 * i] = working_space[shift + j];
2784 if (working_space[shift + j] <
fXmin)
2785 working_space[shift + j] =
fXmin;
2786 if (working_space[shift + j] >
fXmax)
2787 working_space[shift + j] =
fXmax;
2788 working_space[2 * i + 1] = working_space[shift + j];
2793 if (working_space[shift + j] < 0.001) {
2794 working_space[shift + j] = 0.001;
2796 working_space[peak_vel] = working_space[shift + j];
2799 if (
fFixT ==
false) {
2800 working_space[peak_vel + 1] = working_space[shift + j];
2803 if (
fFixB ==
false) {
2804 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2805 if (working_space[shift + j] < 0)
2806 working_space[shift + j] = -0.001;
2808 working_space[shift + j] = 0.001;
2810 working_space[peak_vel + 2] = working_space[shift + j];
2813 if (
fFixS ==
false) {
2814 working_space[peak_vel + 3] = working_space[shift + j];
2818 working_space[peak_vel + 4] = working_space[shift + j];
2822 working_space[peak_vel + 5] = working_space[shift + j];
2826 working_space[peak_vel + 6] = working_space[shift + j];
2834 working_space[peak_vel],
2835 working_space[peak_vel + 1],
2836 working_space[peak_vel + 3],
2837 working_space[peak_vel + 2],
2838 working_space[peak_vel + 4],
2839 working_space[peak_vel + 5],
2840 working_space[peak_vel + 6]);
2853 chi2 += (yw -
f) * (yw - f) / ywm;
2860 pmin =
pi, chi_min = chi2;
2870 for (j = 0; j < rozmer; j++) {
2871 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
2873 for (i = 0, j = 0; i <
fNPeaks; i++) {
2875 if (working_space[shift + j] < 0)
2876 working_space[shift + j] = 0;
2877 working_space[2 * i] = working_space[shift + j];
2881 if (working_space[shift + j] <
fXmin)
2882 working_space[shift + j] =
fXmin;
2883 if (working_space[shift + j] >
fXmax)
2884 working_space[shift + j] =
fXmax;
2885 working_space[2 * i + 1] = working_space[shift + j];
2890 if (working_space[shift + j] < 0.001) {
2891 working_space[shift + j] = 0.001;
2893 working_space[peak_vel] = working_space[shift + j];
2896 if (
fFixT ==
false) {
2897 working_space[peak_vel + 1] = working_space[shift + j];
2900 if (
fFixB ==
false) {
2901 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2902 if (working_space[shift + j] < 0)
2903 working_space[shift + j] = -0.001;
2905 working_space[shift + j] = 0.001;
2907 working_space[peak_vel + 2] = working_space[shift + j];
2910 if (
fFixS ==
false) {
2911 working_space[peak_vel + 3] = working_space[shift + j];
2915 working_space[peak_vel + 4] = working_space[shift + j];
2919 working_space[peak_vel + 5] = working_space[shift + j];
2923 working_space[peak_vel + 6] = working_space[shift + j];
2931 for (j = 0; j < rozmer; j++) {
2932 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
2934 for (i = 0, j = 0; i <
fNPeaks; i++) {
2936 if (working_space[shift + j] < 0)
2937 working_space[shift + j] = 0;
2938 working_space[2 * i] = working_space[shift + j];
2942 if (working_space[shift + j] <
fXmin)
2943 working_space[shift + j] =
fXmin;
2944 if (working_space[shift + j] >
fXmax)
2945 working_space[shift + j] =
fXmax;
2946 working_space[2 * i + 1] = working_space[shift + j];
2951 if (working_space[shift + j] < 0.001) {
2952 working_space[shift + j] = 0.001;
2954 working_space[peak_vel] = working_space[shift + j];
2957 if (
fFixT ==
false) {
2958 working_space[peak_vel + 1] = working_space[shift + j];
2961 if (
fFixB ==
false) {
2962 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2963 if (working_space[shift + j] < 0)
2964 working_space[shift + j] = -0.001;
2966 working_space[shift + j] = 0.001;
2968 working_space[peak_vel + 2] = working_space[shift + j];
2971 if (
fFixS ==
false) {
2972 working_space[peak_vel + 3] = working_space[shift + j];
2976 working_space[peak_vel + 4] = working_space[shift + j];
2980 working_space[peak_vel + 5] = working_space[shift + j];
2984 working_space[peak_vel + 6] = working_space[shift + j];
2992 working_space[peak_vel],
2993 working_space[peak_vel + 1],
2994 working_space[peak_vel + 3],
2995 working_space[peak_vel + 2],
2996 working_space[peak_vel + 4],
2997 working_space[peak_vel + 5],
2998 working_space[peak_vel + 6]);
3011 chi += (yw -
f) * (yw - f) / ywm;
3018 alpha = alpha * chi_opt / (2 * chi);
3021 alpha = alpha / 10.0;
3024 }
while (((chi > chi_opt
3029 for (j = 0; j < rozmer; j++) {
3030 working_space[4 * shift + j] = 0;
3031 working_space[2 * shift + j] = 0;
3033 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
3038 working_space[peak_vel], working_space[peak_vel + 1],
3039 working_space[peak_vel + 3],
3040 working_space[peak_vel + 2],
3041 working_space[peak_vel + 4],
3042 working_space[peak_vel + 5],
3043 working_space[peak_vel + 6]);
3044 chi_opt = (yw -
f) * (yw - f) / yw;
3045 chi_cel += (yw -
f) * (yw - f) / yw;
3048 for (j = 0, k = 0; j <
fNPeaks; j++) {
3051 working_space[peak_vel],
3052 working_space[peak_vel + 1],
3053 working_space[peak_vel + 3],
3054 working_space[peak_vel + 2]);
3056 working_space[2 * shift + k] += chi_opt;
3058 working_space[4 * shift + k] += b;
3064 working_space[2 * j + 1],
3065 working_space[peak_vel],
3066 working_space[peak_vel + 1],
3067 working_space[peak_vel + 3],
3068 working_space[peak_vel + 2]);
3070 working_space[2 * shift + k] += chi_opt;
3072 working_space[4 * shift + k] += b;
3079 working_space[peak_vel],
3080 working_space[peak_vel + 1],
3081 working_space[peak_vel + 3],
3082 working_space[peak_vel + 2]);
3084 working_space[2 * shift + k] += chi_opt;
3086 working_space[4 * shift + k] += b;
3090 if (
fFixT ==
false) {
3092 working_space[peak_vel],
3093 working_space[peak_vel + 2]);
3095 working_space[2 * shift + k] += chi_opt;
3097 working_space[4 * shift + k] += b;
3101 if (
fFixB ==
false) {
3103 working_space[peak_vel], working_space[peak_vel + 1],
3104 working_space[peak_vel + 2]);
3106 working_space[2 * shift + k] += chi_opt;
3108 working_space[4 * shift + k] += b;
3112 if (
fFixS ==
false) {
3114 working_space[peak_vel]);
3116 working_space[2 * shift + k] += chi_opt;
3118 working_space[4 * shift + k] += b;
3125 working_space[2 * shift + k] += chi_opt;
3127 working_space[4 * shift + k] += b;
3134 working_space[2 * shift + k] += chi_opt;
3136 working_space[4 * shift + k] += b;
3143 working_space[2 * shift + k] += chi_opt;
3145 working_space[4 * shift + k] += b;
3152 chi_er = chi_cel / b;
3153 for (i = 0, j = 0; i <
fNPeaks; i++) {
3155 Area(working_space[2 * i], working_space[peak_vel],
3156 working_space[peak_vel + 1], working_space[peak_vel + 2]);
3158 fAmpCalc[i] = working_space[shift + j];
3159 if (working_space[3 * shift + j] != 0)
3162 a =
Derpa(working_space[peak_vel],
3163 working_space[peak_vel + 1],
3164 working_space[peak_vel + 2]);
3165 b = working_space[4 * shift + j];
3186 if (working_space[3 * shift + j] != 0)
3198 if (working_space[3 * shift + j] != 0)
3207 if (
fFixT ==
false) {
3208 fTCalc = working_space[shift + j];
3209 if (working_space[3 * shift + j] != 0)
3218 if (
fFixB ==
false) {
3219 fBCalc = working_space[shift + j];
3220 if (working_space[3 * shift + j] != 0)
3229 if (
fFixS ==
false) {
3230 fSCalc = working_space[shift + j];
3231 if (working_space[3 * shift + j] != 0)
3241 fA0Calc = working_space[shift + j];
3242 if (working_space[3 * shift + j] != 0)
3252 fA1Calc = working_space[shift + j];
3253 if (working_space[3 * shift + j] != 0)
3263 fA2Calc = working_space[shift + j];
3264 if (working_space[3 * shift + j] != 0)
3277 working_space[peak_vel], working_space[peak_vel + 1],
3278 working_space[peak_vel + 3], working_space[peak_vel + 2],
3279 working_space[peak_vel + 4], working_space[peak_vel + 5],
3280 working_space[peak_vel + 6]);
3283 for (i = 0; i < rozmer; i++)
3284 delete [] working_matrix[i];
3285 delete [] working_matrix;
3286 delete [] working_space;
3306 if(xmin<0 || xmax <= xmin){
3307 Error(
"SetFitParameters",
"Wrong range");
3310 if (numberIterations <= 0){
3311 Error(
"SetFitParameters",
"Invalid number of iterations, must be positive");
3314 if (alpha <= 0 || alpha > 1){
3315 Error (
"SetFitParameters",
"Invalid step coefficient alpha, must be > than 0 and <=1");
3321 Error(
"SetFitParameters",
"Wrong type of statistic");
3326 Error(
"SetFitParameters",
"Wrong optimization algorithm");
3332 Error(
"SetFitParameters",
"Wrong power");
3337 Error(
"SetFitParameters",
"Wrong order of Taylor development");
3360 Error (
"SetPeakParameters",
"Invalid sigma, must be > than 0");
3365 Error (
"SetPeakParameters",
"Invalid peak position, must be in the range fXmin, fXmax");
3369 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)
AUXILIARY FUNCTION // // This function calculates peaks shape function (see manual) // Function param...
virtual ~TSpectrumFit()
destructor
Double_t Derpb(Double_t a, Double_t sigma, Double_t t, Double_t b)
AUXILIARY FUNCTION // // This function calculates derivative of the area of peak // according to b pa...
void SetPeakParameters(Double_t sigma, Bool_t fixSigma, const Double_t *positionInit, const Bool_t *fixPosition, const Double_t *ampInit, const Bool_t *fixAmp)
SETTER FUNCTION.
Double_t Area(Double_t a, Double_t sigma, Double_t t, Double_t b)
AUXILIARY FUNCTION // // This function calculates area of a peak // Function parameters: // -a-amplit...
void StiefelInversion(Double_t **a, Int_t rozmer)
AUXILIARY FUNCTION // // This function calculates solution of the system of linear equations...
Double_t Dert(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma, Double_t b)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
Double_t Derpsigma(Double_t a, Double_t t, Double_t b)
void GetTailParameters(Double_t &t, Double_t &tErr, Double_t &b, Double_t &bErr, Double_t &s, Double_t &sErr)
GETTER FUNCTION.
The TNamed class is the base class for all named ROOT classes.
unsigned int r3[N_CITIES]
void SetBackgroundParameters(Double_t a0Init, Bool_t fixA0, Double_t a1Init, Bool_t fixA1, Double_t a2Init, Bool_t fixA2)
SETTER FUNCTION.
std::map< std::string, std::string >::const_iterator iter
Double_t Dera2(Double_t i)
derivative of background according to a2
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
Double_t Derfc(Double_t x)
AUXILIARY FUNCTION // // This function calculates derivative of error function of x...
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)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
unsigned int r1[N_CITIES]
Double_t Erfc(Double_t x)
Double_t Deramp(Double_t i, Double_t i0, Double_t sigma, Double_t t, Double_t s, Double_t b)
AUXILIARY FUNCTION // // This function calculates derivative of peak shape function (see manual) // a...
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)
SETTER FUNCTION.
Double_t Deri0(Double_t i, Double_t amp, Double_t i0, Double_t sigma, Double_t t, Double_t s, Double_t b)
AUXILIARY FUNCTION // // This function calculates derivative of peak shape function (see manual) // a...
ClassImp(TSpectrumFit) TSpectrumFit
default constructor
Double_t Derpa(Double_t sigma, Double_t t, Double_t b)
AUXILIARY FUNCTION // // This function calculates derivative of the area of peak // according to its ...
Double_t Ders(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
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)
AUXILIARY FUNCTION // // This function calculates second derivative of peak shape function // (see ma...
Double_t Derdersigma(Int_t num_of_fitted_peaks, Double_t i, const Double_t *parameter, Double_t sigma)
AUXILIARY FUNCTION // // This function calculates second derivative of peaks shape function // (see m...
Double_t Derpt(Double_t a, Double_t sigma, Double_t b)
AUXILIARY FUNCTION // // This function calculates derivative of the area of peak // according to t pa...
void SetTailParameters(Double_t tInit, Bool_t fixT, Double_t bInit, Bool_t fixB, Double_t sInit, Bool_t fixS)
SETTER FUNCTION.
Double_t Ourpowl(Double_t a, Int_t pw)
power function
Advanced 1-dimentional spectra fitting functions.
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)
AUXILIARY FUNCTION // // This function calculates derivative of peaks shape function (see manual) // ...
void GetBackgroundParameters(Double_t &a0, Double_t &a0Err, Double_t &a1, Double_t &a1Err, Double_t &a2, Double_t &a2Err)
GETTER FUNCTION.
Double_t Sqrt(Double_t x)
void GetSigma(Double_t &sigma, Double_t &sigmaErr)
GETTER FUNCTION.
void FitAwmi(Double_t *source)
ONE-DIMENSIONAL FIT FUNCTION ALGORITHM WITHOUT MATRIX INVERSION This function fits the source spectru...
void FitStiefel(Double_t *source)
ONE-DIMENSIONAL FIT FUNCTION ALGORITHM WITH MATRIX INVERSION (STIEFEL-HESTENS METHOD) This function f...
unsigned int r2[N_CITIES]