63 fNumberIterations = 1;
66 fStatisticType = kFitOptimChiCounts;
67 fAlphaOptim = kFitAlphaHalving;
69 fFitTaylor = kFitTaylorOrderFirst;
165 if (numberPeaks <= 0){
166 Error (
"TSpectrumFit",
"Invalid number of peaks, must be > than 0");
248 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
260 c = c * t * (da1 + t * (da2 + t * da3));
277 Double_t da1 = 0.1740121, da2 = -0.0479399, da3 = 0.3739278, dap = 0.47047;
288 c = (-1.) * dap * c * t * t * (da1 + t * (2. * da2 + t * 3. * da3)) -
312 p = (i - i0) / sigma;
327 r = r *
Erfc(p + 1. / (2. * b));
330 q = q + s *
Erfc(p) / 2.;
354 p = (i - i0) / sigma;
357 r1 = 2. * p *
exp(-p * p) / sigma;
364 c = p + 1. / (2. * b);
368 r2 = -t *
exp(e) *
Erfc(c) / (d * b);
373 r4 = -s *
Derfc(p) / d;
374 r1 = amp * (r1 + r2 + r3 + r4);
396 p = (i - i0) / sigma;
403 r1 = r1 * (4 * p * p - 2) / (sigma * sigma);
404 r2 = 0, r3 = 0, r4 = 0;
405 r1 = amp * (r1 + r2 + r3 + r4);
433 for (j = 0; j < num_of_fitted_peaks; j++) {
434 p = (i - parameter[2 * j + 1]) / sigma;
438 r1 = 2. * p * p *
exp(-p * p) / sigma;
446 c = p + 1. / (2. * b);
450 r2 = -t * p *
exp(e) *
Erfc(c) / (d * b);
451 r3 = -t * p *
exp(e) *
Derfc(c) / d;
455 r4 = -s * p *
Derfc(p) / d;
456 r = r + parameter[2 * j] * (r1 + r2 + r3 + r4);
481 for (j = 0; j < num_of_fitted_peaks; j++) {
482 p = (i - parameter[2 * j + 1]) / sigma;
486 r1 =
exp(-p * p) * p * p * (4. * p * p - 6) / (sigma * sigma);
492 r2 = 0, r3 = 0, r4 = 0;
493 r = r + parameter[2 * j] * (r1 + r2 + r3 + r4);
519 for (j = 0; j < num_of_fitted_peaks; j++) {
520 p = (i - parameter[2 * j + 1]) / sigma;
521 c = p + 1. / (2. * b);
526 r = r + parameter[2 * j] *
r1;
552 for (j = 0; j < num_of_fitted_peaks; j++) {
553 p = (i - parameter[2 * j + 1]) / sigma;
555 r = r + parameter[2 * j] *
r1;
584 for (j = 0; j < num_of_fitted_peaks && t != 0; j++) {
585 p = (i - parameter[2 * j + 1]) / sigma;
586 c = p + 1. / (2. * b);
589 r1 = r1 +
Derfc(c) / 2.;
597 r = r + parameter[2 * j] *
r1;
599 r = -r * t / (2. * b * b);
643 for (j = 0; j < num_of_fitted_peaks; j++) {
645 p = (i - parameter[2 * j + 1]) / sigma;
648 if (i == parameter[2 * j + 1])
665 c = p + 1. / (2. * b);
669 r2 = t *
exp(e) *
Erfc(c) / 2.;
673 r3 = s *
Erfc(p) / 2.;
674 r = r + parameter[2 * j] * (r1 + r2 +
r3);
676 r = r + a0 + a1 * i + a2 * i * i;
700 r = a * sigma * (odm_pi + t * b *
exp(r));
703 r = a * sigma * odm_pi;
727 r = sigma * (odm_pi + t * b *
exp(r));
751 r = a * (odm_pi + t * b *
exp(r));
778 r = a * sigma * b *
exp(r);
802 r = (-1) * 0.25 / (b * b);
804 r = a * sigma * t *
exp(r) * (1 - 2 *
r);
825 if (pw > 10) c *= a2;
826 if (pw > 12) c *= a2;
1344 Int_t i, j, k, shift =
1345 2 *
fNPeaks + 7, peak_vel, rozmer, iter, pw, regul_cycle,
1347 Double_t a, b,
c, d = 0, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
1348 0,
pi, pmin = 0, chi_cel = 0, chi_er;
1350 for (i = 0, j = 0; i <
fNPeaks; i++) {
1351 working_space[2 * i] =
fAmpInit[i];
1353 working_space[shift + j] =
fAmpInit[i];
1368 working_space[2 * i + 1] =
fTInit;
1369 if (
fFixT ==
false) {
1370 working_space[shift + j] =
fTInit;
1373 working_space[2 * i + 2] =
fBInit;
1374 if (
fFixB ==
false) {
1375 working_space[shift + j] =
fBInit;
1378 working_space[2 * i + 3] =
fSInit;
1379 if (
fFixS ==
false) {
1380 working_space[shift + j] =
fSInit;
1383 working_space[2 * i + 4] =
fA0Init;
1385 working_space[shift + j] =
fA0Init;
1388 working_space[2 * i + 5] =
fA1Init;
1390 working_space[shift + j] =
fA1Init;
1393 working_space[2 * i + 6] =
fA2Init;
1395 working_space[shift + j] =
fA2Init;
1400 delete [] working_space;
1401 Error (
"FitAwmi",
"All parameters are fixed");
1405 delete [] working_space;
1406 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
1410 for (j = 0; j < rozmer; j++) {
1411 working_space[2 * shift + j] = 0, working_space[3 * shift + j] = 0;
1416 chi_opt = 0, pw =
fPower - 2;
1421 working_space[peak_vel], working_space[peak_vel + 1],
1422 working_space[peak_vel + 3],
1423 working_space[peak_vel + 2],
1424 working_space[peak_vel + 4],
1425 working_space[peak_vel + 5],
1426 working_space[peak_vel + 6]);
1434 chi_opt += (yw -
f) * (yw - f) / ywm;
1454 for (j = 0, k = 0; j <
fNPeaks; j++) {
1457 working_space[peak_vel],
1458 working_space[peak_vel + 1],
1459 working_space[peak_vel + 3],
1460 working_space[peak_vel + 2]);
1464 b = a * (yw * yw - f *
f) / (ywm * ywm);
1465 working_space[2 * shift + k] += b *
c;
1466 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1467 working_space[3 * shift + k] += b *
c;
1471 b = a * (yw -
f) / ywm;
1472 working_space[2 * shift + k] += b *
c;
1474 working_space[3 * shift + k] += b *
c;
1481 working_space[2 * j + 1],
1482 working_space[peak_vel],
1483 working_space[peak_vel + 1],
1484 working_space[peak_vel + 3],
1485 working_space[peak_vel + 2]);
1488 working_space[2 * j + 1],
1489 working_space[peak_vel]);
1495 if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
1503 b = a * (yw * yw - f *
f) / (ywm * ywm);
1504 working_space[2 * shift + k] += b *
c;
1505 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1506 working_space[3 * shift + k] += b *
c;
1510 b = a * (yw -
f) / ywm;
1511 working_space[2 * shift + k] += b *
c;
1513 working_space[3 * shift + k] += b *
c;
1521 working_space[peak_vel],
1522 working_space[peak_vel + 1],
1523 working_space[peak_vel + 3],
1524 working_space[peak_vel + 2]);
1527 working_space, working_space[peak_vel]);
1533 if (((a + d) <= 0 && a >= 0) || ((a + d) >= 0 && a <= 0))
1541 b = a * (yw * yw - f *
f) / (ywm * ywm);
1542 working_space[2 * shift + k] += b *
c;
1543 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1544 working_space[3 * shift + k] += b *
c;
1548 b = a * (yw -
f) / ywm;
1549 working_space[2 * shift + k] += b *
c;
1551 working_space[3 * shift + k] += b *
c;
1556 if (
fFixT ==
false) {
1558 working_space[peak_vel],
1559 working_space[peak_vel + 2]);
1563 b = a * (yw * yw - f *
f) / (ywm * ywm);
1564 working_space[2 * shift + k] += b *
c;
1565 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1566 working_space[3 * shift + k] += b *
c;
1570 b = a * (yw -
f) / ywm;
1571 working_space[2 * shift + k] += b *
c;
1573 working_space[3 * shift + k] += b *
c;
1578 if (
fFixB ==
false) {
1580 working_space[peak_vel], working_space[peak_vel + 1],
1581 working_space[peak_vel + 2]);
1585 b = a * (yw * yw - f *
f) / (ywm * ywm);
1586 working_space[2 * shift + k] += b *
c;
1587 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1588 working_space[3 * shift + k] += b *
c;
1592 b = a * (yw -
f) / ywm;
1593 working_space[2 * shift + k] += b *
c;
1595 working_space[3 * shift + k] += b *
c;
1600 if (
fFixS ==
false) {
1602 working_space[peak_vel]);
1606 b = a * (yw * yw - f *
f) / (ywm * ywm);
1607 working_space[2 * shift + k] += b *
c;
1608 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1609 working_space[3 * shift + k] += b *
c;
1613 b = a * (yw -
f) / ywm;
1614 working_space[2 * shift + k] += b *
c;
1616 working_space[3 * shift + k] += b *
c;
1626 b = a * (yw * yw - f *
f) / (ywm * ywm);
1627 working_space[2 * shift + k] += b *
c;
1628 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1629 working_space[3 * shift + k] += b *
c;
1633 b = a * (yw -
f) / ywm;
1634 working_space[2 * shift + k] += b *
c;
1636 working_space[3 * shift + k] += b *
c;
1646 b = a * (yw * yw - f *
f) / (ywm * ywm);
1647 working_space[2 * shift + k] += b *
c;
1648 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1649 working_space[3 * shift + k] += b *
c;
1653 b = a * (yw -
f) / ywm;
1654 working_space[2 * shift + k] += b *
c;
1656 working_space[3 * shift + k] += b *
c;
1666 b = a * (yw * yw - f *
f) / (ywm * ywm);
1667 working_space[2 * shift + k] += b *
c;
1668 b = a * a * (4 * yw - 2 *
f) / (ywm * ywm);
1669 working_space[3 * shift + k] += b *
c;
1673 b = a * (yw -
f) / ywm;
1674 working_space[2 * shift + k] += b *
c;
1676 working_space[3 * shift + k] += b *
c;
1682 for (j = 0; j < rozmer; j++) {
1683 if (
TMath::Abs(working_space[3 * shift + j]) > 0.000001)
1684 working_space[2 * shift + j] = working_space[2 * shift + j] /
TMath::Abs(working_space[3 * shift + j]);
1686 working_space[2 * shift + j] = 0;
1695 for (j = 0; j < rozmer; j++) {
1696 working_space[4 * shift + j] = working_space[shift + j];
1702 chi_min = 10000 * chi2;
1705 chi_min = 0.1 * chi2;
1707 for (
pi = 0.1; flag == 0 &&
pi <= 100;
pi += 0.1) {
1708 for (j = 0; j < rozmer; j++) {
1709 working_space[shift + j] = working_space[4 * shift + j] +
pi * alpha * working_space[2 * shift + j];
1711 for (i = 0, j = 0; i <
fNPeaks; i++) {
1713 if (working_space[shift + j] < 0)
1714 working_space[shift + j] = 0;
1715 working_space[2 * i] = working_space[shift + j];
1719 if (working_space[shift + j] <
fXmin)
1720 working_space[shift + j] =
fXmin;
1721 if (working_space[shift + j] >
fXmax)
1722 working_space[shift + j] =
fXmax;
1723 working_space[2 * i + 1] = working_space[shift + j];
1728 if (working_space[shift + j] < 0.001) {
1729 working_space[shift + j] = 0.001;
1731 working_space[peak_vel] = working_space[shift + j];
1734 if (
fFixT ==
false) {
1735 working_space[peak_vel + 1] = working_space[shift + j];
1738 if (
fFixB ==
false) {
1739 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1740 if (working_space[shift + j] < 0)
1741 working_space[shift + j] = -0.001;
1743 working_space[shift + j] = 0.001;
1745 working_space[peak_vel + 2] = working_space[shift + j];
1748 if (
fFixS ==
false) {
1749 working_space[peak_vel + 3] = working_space[shift + j];
1753 working_space[peak_vel + 4] = working_space[shift + j];
1757 working_space[peak_vel + 5] = working_space[shift + j];
1761 working_space[peak_vel + 6] = working_space[shift + j];
1769 working_space[peak_vel],
1770 working_space[peak_vel + 1],
1771 working_space[peak_vel + 3],
1772 working_space[peak_vel + 2],
1773 working_space[peak_vel + 4],
1774 working_space[peak_vel + 5],
1775 working_space[peak_vel + 6]);
1788 chi2 += (yw -
f) * (yw - f) / ywm;
1795 pmin =
pi, chi_min = chi2;
1805 for (j = 0; j < rozmer; j++) {
1806 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
1808 for (i = 0, j = 0; i <
fNPeaks; i++) {
1810 if (working_space[shift + j] < 0)
1811 working_space[shift + j] = 0;
1812 working_space[2 * i] = working_space[shift + j];
1816 if (working_space[shift + j] <
fXmin)
1817 working_space[shift + j] =
fXmin;
1818 if (working_space[shift + j] >
fXmax)
1819 working_space[shift + j] =
fXmax;
1820 working_space[2 * i + 1] = working_space[shift + j];
1825 if (working_space[shift + j] < 0.001) {
1826 working_space[shift + j] = 0.001;
1828 working_space[peak_vel] = working_space[shift + j];
1831 if (
fFixT ==
false) {
1832 working_space[peak_vel + 1] = working_space[shift + j];
1835 if (
fFixB ==
false) {
1836 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1837 if (working_space[shift + j] < 0)
1838 working_space[shift + j] = -0.001;
1840 working_space[shift + j] = 0.001;
1842 working_space[peak_vel + 2] = working_space[shift + j];
1845 if (
fFixS ==
false) {
1846 working_space[peak_vel + 3] = working_space[shift + j];
1850 working_space[peak_vel + 4] = working_space[shift + j];
1854 working_space[peak_vel + 5] = working_space[shift + j];
1858 working_space[peak_vel + 6] = working_space[shift + j];
1866 for (j = 0; j < rozmer; j++) {
1867 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
1869 for (i = 0, j = 0; i <
fNPeaks; i++) {
1871 if (working_space[shift + j] < 0)
1872 working_space[shift + j] = 0;
1873 working_space[2 * i] = working_space[shift + j];
1877 if (working_space[shift + j] <
fXmin)
1878 working_space[shift + j] =
fXmin;
1879 if (working_space[shift + j] >
fXmax)
1880 working_space[shift + j] =
fXmax;
1881 working_space[2 * i + 1] = working_space[shift + j];
1886 if (working_space[shift + j] < 0.001) {
1887 working_space[shift + j] = 0.001;
1889 working_space[peak_vel] = working_space[shift + j];
1892 if (
fFixT ==
false) {
1893 working_space[peak_vel + 1] = working_space[shift + j];
1896 if (
fFixB ==
false) {
1897 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
1898 if (working_space[shift + j] < 0)
1899 working_space[shift + j] = -0.001;
1901 working_space[shift + j] = 0.001;
1903 working_space[peak_vel + 2] = working_space[shift + j];
1906 if (
fFixS ==
false) {
1907 working_space[peak_vel + 3] = working_space[shift + j];
1911 working_space[peak_vel + 4] = working_space[shift + j];
1915 working_space[peak_vel + 5] = working_space[shift + j];
1919 working_space[peak_vel + 6] = working_space[shift + j];
1927 working_space[peak_vel],
1928 working_space[peak_vel + 1],
1929 working_space[peak_vel + 3],
1930 working_space[peak_vel + 2],
1931 working_space[peak_vel + 4],
1932 working_space[peak_vel + 5],
1933 working_space[peak_vel + 6]);
1946 chi += (yw -
f) * (yw - f) / ywm;
1953 alpha = alpha * chi_opt / (2 * chi);
1956 alpha = alpha / 10.0;
1959 }
while (((chi > chi_opt
1964 for (j = 0; j < rozmer; j++) {
1965 working_space[4 * shift + j] = 0;
1966 working_space[2 * shift + j] = 0;
1968 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
1973 working_space[peak_vel], working_space[peak_vel + 1],
1974 working_space[peak_vel + 3],
1975 working_space[peak_vel + 2],
1976 working_space[peak_vel + 4],
1977 working_space[peak_vel + 5],
1978 working_space[peak_vel + 6]);
1979 chi_opt = (yw -
f) * (yw - f) / yw;
1980 chi_cel += (yw -
f) * (yw - f) / yw;
1983 for (j = 0, k = 0; j <
fNPeaks; j++) {
1986 working_space[peak_vel],
1987 working_space[peak_vel + 1],
1988 working_space[peak_vel + 3],
1989 working_space[peak_vel + 2]);
1992 working_space[2 * shift + k] += chi_opt *
c;
1994 working_space[4 * shift + k] += b *
c;
2000 working_space[2 * j + 1],
2001 working_space[peak_vel],
2002 working_space[peak_vel + 1],
2003 working_space[peak_vel + 3],
2004 working_space[peak_vel + 2]);
2007 working_space[2 * shift + k] += chi_opt *
c;
2009 working_space[4 * shift + k] += b *
c;
2016 working_space[peak_vel],
2017 working_space[peak_vel + 1],
2018 working_space[peak_vel + 3],
2019 working_space[peak_vel + 2]);
2022 working_space[2 * shift + k] += chi_opt *
c;
2024 working_space[4 * shift + k] += b *
c;
2028 if (
fFixT ==
false) {
2030 working_space[peak_vel],
2031 working_space[peak_vel + 2]);
2034 working_space[2 * shift + k] += chi_opt *
c;
2036 working_space[4 * shift + k] += b *
c;
2040 if (
fFixB ==
false) {
2042 working_space[peak_vel], working_space[peak_vel + 1],
2043 working_space[peak_vel + 2]);
2046 working_space[2 * shift + k] += chi_opt *
c;
2048 working_space[4 * shift + k] += b *
c;
2052 if (
fFixS ==
false) {
2054 working_space[peak_vel]);
2057 working_space[2 * shift + k] += chi_opt *
c;
2059 working_space[4 * shift + k] += b *
c;
2067 working_space[2 * shift + k] += chi_opt *
c;
2069 working_space[4 * shift + k] += b *
c;
2077 working_space[2 * shift + k] += chi_opt *
c;
2079 working_space[4 * shift + k] += b *
c;
2087 working_space[2 * shift + k] += chi_opt *
c;
2089 working_space[4 * shift + k] += b *
c;
2096 chi_er = chi_cel / b;
2097 for (i = 0, j = 0; i <
fNPeaks; i++) {
2099 Area(working_space[2 * i], working_space[peak_vel],
2100 working_space[peak_vel + 1], working_space[peak_vel + 2]);
2102 fAmpCalc[i] = working_space[shift + j];
2103 if (working_space[3 * shift + j] != 0)
2106 a =
Derpa(working_space[peak_vel],
2107 working_space[peak_vel + 1],
2108 working_space[peak_vel + 2]);
2109 b = working_space[4 * shift + j];
2130 if (working_space[3 * shift + j] != 0)
2142 if (working_space[3 * shift + j] != 0)
2151 if (
fFixT ==
false) {
2152 fTCalc = working_space[shift + j];
2153 if (working_space[3 * shift + j] != 0)
2162 if (
fFixB ==
false) {
2163 fBCalc = working_space[shift + j];
2164 if (working_space[3 * shift + j] != 0)
2173 if (
fFixS ==
false) {
2174 fSCalc = working_space[shift + j];
2175 if (working_space[3 * shift + j] != 0)
2185 fA0Calc = working_space[shift + j];
2186 if (working_space[3 * shift + j] != 0)
2196 fA1Calc = working_space[shift + j];
2197 if (working_space[3 * shift + j] != 0)
2207 fA2Calc = working_space[shift + j];
2208 if (working_space[3 * shift + j] != 0)
2221 working_space[peak_vel], working_space[peak_vel + 1],
2222 working_space[peak_vel + 3], working_space[peak_vel + 2],
2223 working_space[peak_vel + 4], working_space[peak_vel + 5],
2224 working_space[peak_vel + 6]);
2227 delete[]working_space;
2252 Double_t sk = 0, b, lambdak, normk, normk_old = 0;
2258 for (i = 0; i < size; i++) {
2259 a[i][size + 2] = -a[i][size];
2260 for (j = 0; j < size; j++) {
2261 a[i][size + 2] += a[i][j] * a[j][size + 1];
2263 normk += a[i][size + 2] * a[i][size + 2];
2268 sk = normk / normk_old;
2272 for (i = 0; i < size; i++) {
2273 a[i][size + 3] = -a[i][size + 2] + sk * a[i][size + 3];
2278 for (i = 0; i < size; i++) {
2279 for (j = 0, b = 0; j < size; j++) {
2280 b += a[i][j] * a[j][size + 3];
2282 lambdak += b * a[i][size + 3];
2285 lambdak = normk / lambdak;
2289 for (i = 0; i < size; i++)
2290 a[i][size + 1] += lambdak * a[i][size + 3];
2293 }
while (k < size &&
TMath::Abs(normk) > 1e-50);
2545 Int_t i, j, k, shift =
2546 2 *
fNPeaks + 7, peak_vel, rozmer, iter, regul_cycle,
2548 Double_t a, b, alpha, chi_opt, yw, ywm,
f, chi2, chi_min, chi =
2549 0,
pi, pmin = 0, chi_cel = 0, chi_er;
2551 for (i = 0, j = 0; i <
fNPeaks; i++) {
2552 working_space[2 * i] =
fAmpInit[i];
2554 working_space[shift + j] =
fAmpInit[i];
2569 working_space[2 * i + 1] =
fTInit;
2570 if (
fFixT ==
false) {
2571 working_space[shift + j] =
fTInit;
2574 working_space[2 * i + 2] =
fBInit;
2575 if (
fFixB ==
false) {
2576 working_space[shift + j] =
fBInit;
2579 working_space[2 * i + 3] =
fSInit;
2580 if (
fFixS ==
false) {
2581 working_space[shift + j] =
fSInit;
2584 working_space[2 * i + 4] =
fA0Init;
2586 working_space[shift + j] =
fA0Init;
2589 working_space[2 * i + 5] =
fA1Init;
2591 working_space[shift + j] =
fA1Init;
2594 working_space[2 * i + 6] =
fA2Init;
2596 working_space[shift + j] =
fA2Init;
2601 Error (
"FitAwmi",
"All parameters are fixed");
2602 delete [] working_space;
2606 Error (
"FitAwmi",
"Number of fitted parameters is larger than # of fitted points");
2607 delete [] working_space;
2611 for (i = 0; i < rozmer; i++)
2612 working_matrix[i] =
new Double_t[rozmer + 4];
2614 for (j = 0; j < rozmer; j++) {
2615 working_space[3 * shift + j] = 0;
2616 for (k = 0; k <= rozmer; k++) {
2617 working_matrix[j][k] = 0;
2627 for (j = 0, k = 0; j <
fNPeaks; j++) {
2629 working_space[2 * shift + k] =
2631 working_space[peak_vel],
2632 working_space[peak_vel + 1],
2633 working_space[peak_vel + 3],
2634 working_space[peak_vel + 2]);
2638 working_space[2 * shift + k] =
2640 working_space[2 * j + 1], working_space[peak_vel],
2641 working_space[peak_vel + 1],
2642 working_space[peak_vel + 3],
2643 working_space[peak_vel + 2]);
2647 working_space[2 * shift + k] =
2649 working_space[peak_vel],
2650 working_space[peak_vel + 1],
2651 working_space[peak_vel + 3],
2652 working_space[peak_vel + 2]);
2655 if (
fFixT ==
false) {
2656 working_space[2 * shift + k] =
2658 working_space[peak_vel], working_space[peak_vel + 2]);
2661 if (
fFixB ==
false) {
2662 working_space[2 * shift + k] =
2664 working_space[peak_vel], working_space[peak_vel + 1],
2665 working_space[peak_vel + 2]);
2668 if (
fFixS ==
false) {
2669 working_space[2 * shift + k] =
2671 working_space[peak_vel]);
2675 working_space[2 * shift + k] = 1.;
2689 working_space[peak_vel], working_space[peak_vel + 1],
2690 working_space[peak_vel + 3],
2691 working_space[peak_vel + 2],
2692 working_space[peak_vel + 4],
2693 working_space[peak_vel + 5],
2694 working_space[peak_vel + 6]);
2702 chi_opt += (yw -
f) * (yw - f) / ywm;
2720 for (j = 0; j < rozmer; j++) {
2721 for (k = 0; k < rozmer; k++) {
2722 b = working_space[2 * shift +
2723 j] * working_space[2 * shift + k] / ywm;
2725 b = b * (4 * yw - 2 *
f) / ywm;
2726 working_matrix[j][k] += b;
2728 working_space[3 * shift + j] += b;
2732 b = (f * f - yw * yw) / (ywm * ywm);
2736 for (j = 0; j < rozmer; j++) {
2737 working_matrix[j][rozmer] -= b * working_space[2 * shift + j];
2740 for (i = 0; i < rozmer; i++) {
2741 working_matrix[i][rozmer + 1] = 0;
2744 for (i = 0; i < rozmer; i++) {
2745 working_space[2 * shift + i] = working_matrix[i][rozmer + 1];
2754 for (j = 0; j < rozmer; j++) {
2755 working_space[4 * shift + j] = working_space[shift + j];
2761 chi_min = 10000 * chi2;
2764 chi_min = 0.1 * chi2;
2766 for (
pi = 0.1; flag == 0 &&
pi <= 100;
pi += 0.1) {
2767 for (j = 0; j < rozmer; j++) {
2768 working_space[shift + j] = working_space[4 * shift + j] +
pi * alpha * working_space[2 * shift + j];
2770 for (i = 0, j = 0; i <
fNPeaks; i++) {
2772 if (working_space[shift + j] < 0)
2773 working_space[shift + j] = 0;
2774 working_space[2 * i] = working_space[shift + j];
2778 if (working_space[shift + j] <
fXmin)
2779 working_space[shift + j] =
fXmin;
2780 if (working_space[shift + j] >
fXmax)
2781 working_space[shift + j] =
fXmax;
2782 working_space[2 * i + 1] = working_space[shift + j];
2787 if (working_space[shift + j] < 0.001) {
2788 working_space[shift + j] = 0.001;
2790 working_space[peak_vel] = working_space[shift + j];
2793 if (
fFixT ==
false) {
2794 working_space[peak_vel + 1] = working_space[shift + j];
2797 if (
fFixB ==
false) {
2798 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2799 if (working_space[shift + j] < 0)
2800 working_space[shift + j] = -0.001;
2802 working_space[shift + j] = 0.001;
2804 working_space[peak_vel + 2] = working_space[shift + j];
2807 if (
fFixS ==
false) {
2808 working_space[peak_vel + 3] = working_space[shift + j];
2812 working_space[peak_vel + 4] = working_space[shift + j];
2816 working_space[peak_vel + 5] = working_space[shift + j];
2820 working_space[peak_vel + 6] = working_space[shift + j];
2828 working_space[peak_vel],
2829 working_space[peak_vel + 1],
2830 working_space[peak_vel + 3],
2831 working_space[peak_vel + 2],
2832 working_space[peak_vel + 4],
2833 working_space[peak_vel + 5],
2834 working_space[peak_vel + 6]);
2847 chi2 += (yw -
f) * (yw - f) / ywm;
2854 pmin =
pi, chi_min = chi2;
2864 for (j = 0; j < rozmer; j++) {
2865 working_space[shift + j] = working_space[4 * shift + j] + pmin * alpha * working_space[2 * shift + j];
2867 for (i = 0, j = 0; i <
fNPeaks; i++) {
2869 if (working_space[shift + j] < 0)
2870 working_space[shift + j] = 0;
2871 working_space[2 * i] = working_space[shift + j];
2875 if (working_space[shift + j] <
fXmin)
2876 working_space[shift + j] =
fXmin;
2877 if (working_space[shift + j] >
fXmax)
2878 working_space[shift + j] =
fXmax;
2879 working_space[2 * i + 1] = working_space[shift + j];
2884 if (working_space[shift + j] < 0.001) {
2885 working_space[shift + j] = 0.001;
2887 working_space[peak_vel] = working_space[shift + j];
2890 if (
fFixT ==
false) {
2891 working_space[peak_vel + 1] = working_space[shift + j];
2894 if (
fFixB ==
false) {
2895 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2896 if (working_space[shift + j] < 0)
2897 working_space[shift + j] = -0.001;
2899 working_space[shift + j] = 0.001;
2901 working_space[peak_vel + 2] = working_space[shift + j];
2904 if (
fFixS ==
false) {
2905 working_space[peak_vel + 3] = working_space[shift + j];
2909 working_space[peak_vel + 4] = working_space[shift + j];
2913 working_space[peak_vel + 5] = working_space[shift + j];
2917 working_space[peak_vel + 6] = working_space[shift + j];
2925 for (j = 0; j < rozmer; j++) {
2926 working_space[shift + j] = working_space[4 * shift + j] + alpha * working_space[2 * shift + j];
2928 for (i = 0, j = 0; i <
fNPeaks; i++) {
2930 if (working_space[shift + j] < 0)
2931 working_space[shift + j] = 0;
2932 working_space[2 * i] = working_space[shift + j];
2936 if (working_space[shift + j] <
fXmin)
2937 working_space[shift + j] =
fXmin;
2938 if (working_space[shift + j] >
fXmax)
2939 working_space[shift + j] =
fXmax;
2940 working_space[2 * i + 1] = working_space[shift + j];
2945 if (working_space[shift + j] < 0.001) {
2946 working_space[shift + j] = 0.001;
2948 working_space[peak_vel] = working_space[shift + j];
2951 if (
fFixT ==
false) {
2952 working_space[peak_vel + 1] = working_space[shift + j];
2955 if (
fFixB ==
false) {
2956 if (
TMath::Abs(working_space[shift + j]) < 0.001) {
2957 if (working_space[shift + j] < 0)
2958 working_space[shift + j] = -0.001;
2960 working_space[shift + j] = 0.001;
2962 working_space[peak_vel + 2] = working_space[shift + j];
2965 if (
fFixS ==
false) {
2966 working_space[peak_vel + 3] = working_space[shift + j];
2970 working_space[peak_vel + 4] = working_space[shift + j];
2974 working_space[peak_vel + 5] = working_space[shift + j];
2978 working_space[peak_vel + 6] = working_space[shift + j];
2986 working_space[peak_vel],
2987 working_space[peak_vel + 1],
2988 working_space[peak_vel + 3],
2989 working_space[peak_vel + 2],
2990 working_space[peak_vel + 4],
2991 working_space[peak_vel + 5],
2992 working_space[peak_vel + 6]);
3005 chi += (yw -
f) * (yw - f) / ywm;
3012 alpha = alpha * chi_opt / (2 * chi);
3015 alpha = alpha / 10.0;
3018 }
while (((chi > chi_opt
3023 for (j = 0; j < rozmer; j++) {
3024 working_space[4 * shift + j] = 0;
3025 working_space[2 * shift + j] = 0;
3027 for (i =
fXmin, chi_cel = 0; i <=
fXmax; i++) {
3032 working_space[peak_vel], working_space[peak_vel + 1],
3033 working_space[peak_vel + 3],
3034 working_space[peak_vel + 2],
3035 working_space[peak_vel + 4],
3036 working_space[peak_vel + 5],
3037 working_space[peak_vel + 6]);
3038 chi_opt = (yw -
f) * (yw - f) / yw;
3039 chi_cel += (yw -
f) * (yw - f) / yw;
3042 for (j = 0, k = 0; j <
fNPeaks; j++) {
3045 working_space[peak_vel],
3046 working_space[peak_vel + 1],
3047 working_space[peak_vel + 3],
3048 working_space[peak_vel + 2]);
3050 working_space[2 * shift + k] += chi_opt;
3052 working_space[4 * shift + k] += b;
3058 working_space[2 * j + 1],
3059 working_space[peak_vel],
3060 working_space[peak_vel + 1],
3061 working_space[peak_vel + 3],
3062 working_space[peak_vel + 2]);
3064 working_space[2 * shift + k] += chi_opt;
3066 working_space[4 * shift + k] += b;
3073 working_space[peak_vel],
3074 working_space[peak_vel + 1],
3075 working_space[peak_vel + 3],
3076 working_space[peak_vel + 2]);
3078 working_space[2 * shift + k] += chi_opt;
3080 working_space[4 * shift + k] += b;
3084 if (
fFixT ==
false) {
3086 working_space[peak_vel],
3087 working_space[peak_vel + 2]);
3089 working_space[2 * shift + k] += chi_opt;
3091 working_space[4 * shift + k] += b;
3095 if (
fFixB ==
false) {
3097 working_space[peak_vel], working_space[peak_vel + 1],
3098 working_space[peak_vel + 2]);
3100 working_space[2 * shift + k] += chi_opt;
3102 working_space[4 * shift + k] += b;
3106 if (
fFixS ==
false) {
3108 working_space[peak_vel]);
3110 working_space[2 * shift + k] += chi_opt;
3112 working_space[4 * shift + k] += b;
3119 working_space[2 * shift + k] += chi_opt;
3121 working_space[4 * shift + k] += b;
3128 working_space[2 * shift + k] += chi_opt;
3130 working_space[4 * shift + k] += b;
3137 working_space[2 * shift + k] += chi_opt;
3139 working_space[4 * shift + k] += b;
3146 chi_er = chi_cel / b;
3147 for (i = 0, j = 0; i <
fNPeaks; i++) {
3149 Area(working_space[2 * i], working_space[peak_vel],
3150 working_space[peak_vel + 1], working_space[peak_vel + 2]);
3152 fAmpCalc[i] = working_space[shift + j];
3153 if (working_space[3 * shift + j] != 0)
3156 a =
Derpa(working_space[peak_vel],
3157 working_space[peak_vel + 1],
3158 working_space[peak_vel + 2]);
3159 b = working_space[4 * shift + j];
3180 if (working_space[3 * shift + j] != 0)
3192 if (working_space[3 * shift + j] != 0)
3201 if (
fFixT ==
false) {
3202 fTCalc = working_space[shift + j];
3203 if (working_space[3 * shift + j] != 0)
3212 if (
fFixB ==
false) {
3213 fBCalc = working_space[shift + j];
3214 if (working_space[3 * shift + j] != 0)
3223 if (
fFixS ==
false) {
3224 fSCalc = working_space[shift + j];
3225 if (working_space[3 * shift + j] != 0)
3235 fA0Calc = working_space[shift + j];
3236 if (working_space[3 * shift + j] != 0)
3246 fA1Calc = working_space[shift + j];
3247 if (working_space[3 * shift + j] != 0)
3257 fA2Calc = working_space[shift + j];
3258 if (working_space[3 * shift + j] != 0)
3271 working_space[peak_vel], working_space[peak_vel + 1],
3272 working_space[peak_vel + 3], working_space[peak_vel + 2],
3273 working_space[peak_vel + 4], working_space[peak_vel + 5],
3274 working_space[peak_vel + 6]);
3277 for (i = 0; i < rozmer; i++)
3278 delete [] working_matrix[i];
3279 delete [] working_matrix;
3280 delete [] working_space;
3300 if(xmin<0 || xmax <= xmin){
3301 Error(
"SetFitParameters",
"Wrong range");
3304 if (numberIterations <= 0){
3305 Error(
"SetFitParameters",
"Invalid number of iterations, must be positive");
3308 if (alpha <= 0 || alpha > 1){
3309 Error (
"SetFitParameters",
"Invalid step coefficient alpha, must be > than 0 and <=1");
3315 Error(
"SetFitParameters",
"Wrong type of statistic");
3320 Error(
"SetFitParameters",
"Wrong optimization algorithm");
3326 Error(
"SetFitParameters",
"Wrong power");
3331 Error(
"SetFitParameters",
"Wrong order of Taylor development");
3354 Error (
"SetPeakParameters",
"Invalid sigma, must be > than 0");
3359 Error (
"SetPeakParameters",
"Invalid peak position, must be in the range fXmin, fXmax");
3363 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.
Double_t Dera2(Double_t i)
derivative of background according to a2
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]
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
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...
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...
TSpectrumFit(void)
default constructor
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]