47#define PEAK_WINDOW 1024
74 :
TNamed(
"Spectrum",
"Miroslav Morhac peak finder")
158 if (
h ==
nullptr)
return nullptr;
159 Int_t dimension =
h->GetDimension();
161 Error(
"Search",
"Only implemented for 1-d histograms");
186 Int_t first =
h->GetXaxis()->GetFirst();
187 Int_t last =
h->GetXaxis()->GetLast();
191 for (i = 0; i <
size; i++) source[i] =
h->GetBinContent(i + first);
194 Background(source,
size,numberIterations, direction, filterOrder,smoothing,
195 smoothWindow,compton);
199 Int_t nch = strlen(
h->GetName());
200 char *
hbname =
new char[nch+20];
224 printf(
"\nNumber of positions = %d\n",
fNPeaks);
272 if (hin ==
nullptr)
return 0;
275 Error(
"Search",
"Only implemented for 1-d and 2-d histograms");
278 if (threshold <=0 || threshold >= 1) {
279 Warning(
"Search",
"threshold must 0<threshold<1, threshold=0.05 assumed");
299 if (dimension == 1) {
303 Int_t i, bin, npeaks;
315 for (i = 0; i < npeaks; i++) {
325 if (!npeaks)
return 0;
516 Int_t numberIterations,
518 bool smoothing,
Int_t smoothWindow,
521 int i, j,
w, bw, b1, b2, priz;
522 Double_t a,
b,
c,
d,
e, yb1, yb2, ai, av, men, b4, c4, d4, e4, b6, c6, d6, e6, f6, g6, b8, c8, d8, e8, f8, g8, h8, i8;
524 return "Wrong Parameters";
525 if (numberIterations < 1)
526 return "Width of Clipping Window Must Be Positive";
527 if (ssize < 2 * numberIterations + 1)
528 return "Too Large Clipping Window";
530 return "Incorrect width of smoothing window";
532 for (i = 0; i < ssize; i++){
533 working_space[i] = spectrum[i];
534 working_space[i + ssize] = spectrum[i];
536 bw=(smoothWindow-1)/2;
540 i = numberIterations;
543 for (j = i; j < ssize - i; j++) {
545 a = working_space[ssize + j];
546 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
549 working_space[j] =
a;
552 else if (smoothing ==
kTRUE){
553 a = working_space[ssize + j];
556 for (
w = j - bw;
w <= j + bw;
w++){
557 if (
w >= 0 &&
w < ssize){
558 av += working_space[ssize +
w];
565 for (
w = j - i - bw;
w <= j - i + bw;
w++){
566 if (
w >= 0 &&
w < ssize){
567 b += working_space[ssize +
w];
574 for (
w = j + i - bw;
w <= j + i + bw;
w++){
575 if (
w >= 0 &&
w < ssize){
576 c += working_space[ssize +
w];
587 for (j = i; j < ssize - i; j++)
588 working_space[ssize + j] = working_space[j];
598 for (j = i; j < ssize - i; j++) {
600 a = working_space[ssize + j];
601 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
604 c -= working_space[ssize + j - (
Int_t) (2 * ai)] / 6;
605 c += 4 * working_space[ssize + j - (
Int_t) ai] / 6;
606 c += 4 * working_space[ssize + j + (
Int_t) ai] / 6;
607 c -= working_space[ssize + j + (
Int_t) (2 * ai)] / 6;
612 working_space[j] =
a;
615 else if (smoothing ==
kTRUE){
616 a = working_space[ssize + j];
619 for (
w = j - bw;
w <= j + bw;
w++){
620 if (
w >= 0 &&
w < ssize){
621 av += working_space[ssize +
w];
628 for (
w = j - i - bw;
w <= j - i + bw;
w++){
629 if (
w >= 0 &&
w < ssize){
630 b += working_space[ssize +
w];
637 for (
w = j + i - bw;
w <= j + i + bw;
w++){
638 if (
w >= 0 &&
w < ssize){
639 c += working_space[ssize +
w];
647 for (
w = j - (
Int_t)(2 * ai) - bw;
w <= j - (
Int_t)(2 * ai) + bw;
w++){
648 if (
w >= 0 &&
w < ssize){
649 b4 += working_space[ssize +
w];
656 if (
w >= 0 &&
w < ssize){
657 c4 += working_space[ssize +
w];
664 if (
w >= 0 &&
w < ssize){
665 d4 += working_space[ssize +
w];
671 for (
w = j + (
Int_t)(2 * ai) - bw;
w <= j + (
Int_t)(2 * ai) + bw;
w++){
672 if (
w >= 0 &&
w < ssize){
673 e4 += working_space[ssize +
w];
678 b4 = (-b4 + 4 * c4 + 4 * d4 - e4) / 6;
686 for (j = i; j < ssize - i; j++)
687 working_space[ssize + j] = working_space[j];
697 for (j = i; j < ssize - i; j++) {
699 a = working_space[ssize + j];
700 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
703 c -= working_space[ssize + j - (
Int_t) (2 * ai)] / 6;
704 c += 4 * working_space[ssize + j - (
Int_t) ai] / 6;
705 c += 4 * working_space[ssize + j + (
Int_t) ai] / 6;
706 c -= working_space[ssize + j + (
Int_t) (2 * ai)] / 6;
709 d += working_space[ssize + j - (
Int_t) (3 * ai)] / 20;
710 d -= 6 * working_space[ssize + j - (
Int_t) (2 * ai)] / 20;
711 d += 15 * working_space[ssize + j - (
Int_t) ai] / 20;
712 d += 15 * working_space[ssize + j + (
Int_t) ai] / 20;
713 d -= 6 * working_space[ssize + j + (
Int_t) (2 * ai)] / 20;
714 d += working_space[ssize + j + (
Int_t) (3 * ai)] / 20;
721 working_space[j] =
a;
724 else if (smoothing ==
kTRUE){
725 a = working_space[ssize + j];
728 for (
w = j - bw;
w <= j + bw;
w++){
729 if (
w >= 0 &&
w < ssize){
730 av += working_space[ssize +
w];
737 for (
w = j - i - bw;
w <= j - i + bw;
w++){
738 if (
w >= 0 &&
w < ssize){
739 b += working_space[ssize +
w];
746 for (
w = j + i - bw;
w <= j + i + bw;
w++){
747 if (
w >= 0 &&
w < ssize){
748 c += working_space[ssize +
w];
756 for (
w = j - (
Int_t)(2 * ai) - bw;
w <= j - (
Int_t)(2 * ai) + bw;
w++){
757 if (
w >= 0 &&
w < ssize){
758 b4 += working_space[ssize +
w];
765 if (
w >= 0 &&
w < ssize){
766 c4 += working_space[ssize +
w];
773 if (
w >= 0 &&
w < ssize){
774 d4 += working_space[ssize +
w];
780 for (
w = j + (
Int_t)(2 * ai) - bw;
w <= j + (
Int_t)(2 * ai) + bw;
w++){
781 if (
w >= 0 &&
w < ssize){
782 e4 += working_space[ssize +
w];
787 b4 = (-b4 + 4 * c4 + 4 * d4 - e4) / 6;
790 for (
w = j - (
Int_t)(3 * ai) - bw;
w <= j - (
Int_t)(3 * ai) + bw;
w++){
791 if (
w >= 0 &&
w < ssize){
792 b6 += working_space[ssize +
w];
798 for (
w = j - (
Int_t)(2 * ai) - bw;
w <= j - (
Int_t)(2 * ai) + bw;
w++){
799 if (
w >= 0 &&
w < ssize){
800 c6 += working_space[ssize +
w];
807 if (
w >= 0 &&
w < ssize){
808 d6 += working_space[ssize +
w];
815 if (
w >= 0 &&
w < ssize){
816 e6 += working_space[ssize +
w];
822 for (
w = j + (
Int_t)(2 * ai) - bw;
w <= j + (
Int_t)(2 * ai) + bw;
w++){
823 if (
w >= 0 &&
w < ssize){
824 f6 += working_space[ssize +
w];
830 for (
w = j + (
Int_t)(3 * ai) - bw;
w <= j + (
Int_t)(3 * ai) + bw;
w++){
831 if (
w >= 0 &&
w < ssize){
832 g6 += working_space[ssize +
w];
837 b6 = (b6 - 6 * c6 + 15 * d6 + 15 * e6 - 6 * f6 + g6) / 20;
847 for (j = i; j < ssize - i; j++)
848 working_space[ssize + j] = working_space[j];
858 for (j = i; j < ssize - i; j++) {
860 a = working_space[ssize + j];
861 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
864 c -= working_space[ssize + j - (
Int_t) (2 * ai)] / 6;
865 c += 4 * working_space[ssize + j - (
Int_t) ai] / 6;
866 c += 4 * working_space[ssize + j + (
Int_t) ai] / 6;
867 c -= working_space[ssize + j + (
Int_t) (2 * ai)] / 6;
870 d += working_space[ssize + j - (
Int_t) (3 * ai)] / 20;
871 d -= 6 * working_space[ssize + j - (
Int_t) (2 * ai)] / 20;
872 d += 15 * working_space[ssize + j - (
Int_t) ai] / 20;
873 d += 15 * working_space[ssize + j + (
Int_t) ai] / 20;
874 d -= 6 * working_space[ssize + j + (
Int_t) (2 * ai)] / 20;
875 d += working_space[ssize + j + (
Int_t) (3 * ai)] / 20;
878 e -= working_space[ssize + j - (
Int_t) (4 * ai)] / 70;
879 e += 8 * working_space[ssize + j - (
Int_t) (3 * ai)] / 70;
880 e -= 28 * working_space[ssize + j - (
Int_t) (2 * ai)] / 70;
881 e += 56 * working_space[ssize + j - (
Int_t) ai] / 70;
882 e += 56 * working_space[ssize + j + (
Int_t) ai] / 70;
883 e -= 28 * working_space[ssize + j + (
Int_t) (2 * ai)] / 70;
884 e += 8 * working_space[ssize + j + (
Int_t) (3 * ai)] / 70;
885 e -= working_space[ssize + j + (
Int_t) (4 * ai)] / 70;
894 working_space[j] =
a;
897 else if (smoothing ==
kTRUE){
898 a = working_space[ssize + j];
901 for (
w = j - bw;
w <= j + bw;
w++){
902 if (
w >= 0 &&
w < ssize){
903 av += working_space[ssize +
w];
910 for (
w = j - i - bw;
w <= j - i + bw;
w++){
911 if (
w >= 0 &&
w < ssize){
912 b += working_space[ssize +
w];
919 for (
w = j + i - bw;
w <= j + i + bw;
w++){
920 if (
w >= 0 &&
w < ssize){
921 c += working_space[ssize +
w];
929 for (
w = j - (
Int_t)(2 * ai) - bw;
w <= j - (
Int_t)(2 * ai) + bw;
w++){
930 if (
w >= 0 &&
w < ssize){
931 b4 += working_space[ssize +
w];
938 if (
w >= 0 &&
w < ssize){
939 c4 += working_space[ssize +
w];
946 if (
w >= 0 &&
w < ssize){
947 d4 += working_space[ssize +
w];
953 for (
w = j + (
Int_t)(2 * ai) - bw;
w <= j + (
Int_t)(2 * ai) + bw;
w++){
954 if (
w >= 0 &&
w < ssize){
955 e4 += working_space[ssize +
w];
960 b4 = (-b4 + 4 * c4 + 4 * d4 - e4) / 6;
963 for (
w = j - (
Int_t)(3 * ai) - bw;
w <= j - (
Int_t)(3 * ai) + bw;
w++){
964 if (
w >= 0 &&
w < ssize){
965 b6 += working_space[ssize +
w];
971 for (
w = j - (
Int_t)(2 * ai) - bw;
w <= j - (
Int_t)(2 * ai) + bw;
w++){
972 if (
w >= 0 &&
w < ssize){
973 c6 += working_space[ssize +
w];
980 if (
w >= 0 &&
w < ssize){
981 d6 += working_space[ssize +
w];
988 if (
w >= 0 &&
w < ssize){
989 e6 += working_space[ssize +
w];
995 for (
w = j + (
Int_t)(2 * ai) - bw;
w <= j + (
Int_t)(2 * ai) + bw;
w++){
996 if (
w >= 0 &&
w < ssize){
997 f6 += working_space[ssize +
w];
1003 for (
w = j + (
Int_t)(3 * ai) - bw;
w <= j + (
Int_t)(3 * ai) + bw;
w++){
1004 if (
w >= 0 &&
w < ssize){
1005 g6 += working_space[ssize +
w];
1010 b6 = (b6 - 6 * c6 + 15 * d6 + 15 * e6 - 6 * f6 + g6) / 20;
1013 for (
w = j - (
Int_t)(4 * ai) - bw;
w <= j - (
Int_t)(4 * ai) + bw;
w++){
1014 if (
w >= 0 &&
w < ssize){
1015 b8 += working_space[ssize +
w];
1021 for (
w = j - (
Int_t)(3 * ai) - bw;
w <= j - (
Int_t)(3 * ai) + bw;
w++){
1022 if (
w >= 0 &&
w < ssize){
1023 c8 += working_space[ssize +
w];
1029 for (
w = j - (
Int_t)(2 * ai) - bw;
w <= j - (
Int_t)(2 * ai) + bw;
w++){
1030 if (
w >= 0 &&
w < ssize){
1031 d8 += working_space[ssize +
w];
1038 if (
w >= 0 &&
w < ssize){
1039 e8 += working_space[ssize +
w];
1046 if (
w >= 0 &&
w < ssize){
1047 f8 += working_space[ssize +
w];
1053 for (
w = j + (
Int_t)(2 * ai) - bw;
w <= j + (
Int_t)(2 * ai) + bw;
w++){
1054 if (
w >= 0 &&
w < ssize){
1055 g8 += working_space[ssize +
w];
1061 for (
w = j + (
Int_t)(3 * ai) - bw;
w <= j + (
Int_t)(3 * ai) + bw;
w++){
1062 if (
w >= 0 &&
w < ssize){
1063 h8 += working_space[ssize +
w];
1069 for (
w = j + (
Int_t)(4 * ai) - bw;
w <= j + (
Int_t)(4 * ai) + bw;
w++){
1070 if (
w >= 0 &&
w < ssize){
1071 i8 += working_space[ssize +
w];
1076 b8 = ( -b8 + 8 * c8 - 28 * d8 + 56 * e8 - 56 * f8 - 28 * g8 + 8 * h8 - i8)/70;
1085 working_space[j]=av;
1088 for (j = i; j < ssize - i; j++)
1089 working_space[ssize + j] = working_space[j];
1097 if (compton ==
kTRUE) {
1098 for (i = 0, b2 = 0; i < ssize; i++){
1100 a = working_space[i],
b = spectrum[i];
1106 yb1 = working_space[b1];
1107 for (b2 = b1 + 1,
c = 0, priz = 0; priz == 0 && b2 < ssize; b2++){
1108 a = working_space[b2],
b = spectrum[b2];
1117 yb2 = working_space[b2];
1119 for (j = b1,
c = 0; j <= b2; j++){
1124 c = (yb2 - yb1) /
c;
1125 for (j = b1,
d = 0; j <= b2 && j < ssize; j++){
1129 working_space[ssize + j] =
a;
1135 for (j = b2,
c = 0; j >= b1; j--){
1140 c = (yb1 - yb2) /
c;
1141 for (j = b2,
d = 0;j >= b1 && j >= 0; j--){
1145 working_space[ssize + j] =
a;
1154 for (j = 0; j < ssize; j++)
1155 spectrum[j] = working_space[ssize + j];
1156 delete[]working_space;
1202 Double_t nom, nip, nim, sp, sm, area = 0;
1204 return "Averaging Window must be positive";
1207 for(i = 0, maxch = 0; i < ssize; i++){
1209 if(maxch < source[i])
1215 delete [] working_space;
1220 working_space[
xmin] = 1;
1222 nip = source[i] / maxch;
1223 nim = source[i + 1] / maxch;
1225 for(
l = 1;
l <= averWindow;
l++){
1227 a = source[
xmax] / maxch;
1230 a = source[i +
l] / maxch;
1240 if((i -
l + 1) <
xmin)
1241 a = source[
xmin] / maxch;
1244 a = source[i -
l + 1] / maxch;
1255 a = working_space[i + 1] = working_space[i] *
a;
1259 working_space[i] = working_space[i] / nom;
1261 for(i = 0; i < ssize; i++)
1262 source[i] = working_space[i] * area;
1263 delete[]working_space;
1463 int ssize,
int numberIterations,
1464 int numberRepetitions,
Double_t boost )
1467 return "Wrong Parameters";
1469 if (numberRepetitions <= 0)
1470 return "Wrong Parameters";
1475 int i, j, k, lindex, posit, lh_gold,
l, repet;
1476 Double_t lda, ldb, ldc, area, maximum;
1483 for (i = 0; i < ssize; i++) {
1487 working_space[i] = lda;
1489 if (lda > maximum) {
1494 if (lh_gold == -1) {
1495 delete [] working_space;
1496 return "ZERO RESPONSE VECTOR";
1500 for (i = 0; i < ssize; i++)
1501 working_space[2 * ssize + i] = source[i];
1504 for (i = 0; i < ssize; i++){
1506 for (j = 0; j < ssize; j++){
1507 ldb = working_space[j];
1510 ldc = working_space[k];
1511 lda = lda + ldb * ldc;
1514 working_space[ssize + i] = lda;
1516 for (k = 0; k < ssize; k++){
1519 ldb = working_space[
l];
1520 ldc = working_space[2 * ssize + k];
1521 lda = lda + ldb * ldc;
1524 working_space[3 * ssize + i]=lda;
1528 for (i = 0; i < ssize; i++){
1529 working_space[2 * ssize + i] = working_space[3 * ssize + i];
1533 for (i = 0; i < ssize; i++)
1534 working_space[i] = 1;
1537 for (repet = 0; repet < numberRepetitions; repet++) {
1539 for (i = 0; i < ssize; i++)
1540 working_space[i] =
TMath::Power(working_space[i], boost);
1542 for (lindex = 0; lindex < numberIterations; lindex++) {
1543 for (i = 0; i < ssize; i++) {
1544 if (working_space[2 * ssize + i] > 0.000001
1545 && working_space[i] > 0.000001) {
1547 for (j = 0; j < lh_gold; j++) {
1548 ldb = working_space[j + ssize];
1553 ldc = working_space[k];
1556 ldc += working_space[k];
1560 ldc = working_space[i];
1561 lda = lda + ldb * ldc;
1563 ldb = working_space[2 * ssize + i];
1569 ldb = working_space[i];
1571 working_space[3 * ssize + i] = lda;
1574 for (i = 0; i < ssize; i++)
1575 working_space[i] = working_space[3 * ssize + i];
1580 for (i = 0; i < ssize; i++) {
1581 lda = working_space[i];
1584 working_space[ssize + j] = lda;
1588 for (i = 0; i < ssize; i++)
1589 source[i] = area * working_space[ssize + i];
1590 delete[]working_space;
1669 int ssize,
int numberIterations,
1670 int numberRepetitions,
Double_t boost )
1673 return "Wrong Parameters";
1675 if (numberRepetitions <= 0)
1676 return "Wrong Parameters";
1681 int i, j, k, lindex, posit, lh_gold, repet, kmin, kmax;
1688 for (i = 0; i < ssize; i++) {
1692 working_space[ssize + i] = lda;
1693 if (lda > maximum) {
1698 if (lh_gold == -1) {
1699 delete [] working_space;
1700 return "ZERO RESPONSE VECTOR";
1704 for (i = 0; i < ssize; i++)
1705 working_space[2 * ssize + i] = source[i];
1708 for (i = 0; i < ssize; i++){
1709 if (i <= ssize - lh_gold)
1710 working_space[i] = 1;
1713 working_space[i] = 0;
1717 for (repet = 0; repet < numberRepetitions; repet++) {
1719 for (i = 0; i < ssize; i++)
1720 working_space[i] =
TMath::Power(working_space[i], boost);
1722 for (lindex = 0; lindex < numberIterations; lindex++) {
1723 for (i = 0; i <= ssize - lh_gold; i++){
1725 if (working_space[i] > 0){
1726 for (j = i; j < i + lh_gold; j++){
1727 ldb = working_space[2 * ssize + j];
1731 if (kmax > lh_gold - 1)
1733 kmin = j + lh_gold - ssize;
1737 for (k = kmax; k >= kmin; k--){
1738 ldc += working_space[ssize + k] * working_space[j - k];
1746 ldb = ldb * working_space[ssize + j - i];
1750 lda = lda * working_space[i];
1752 working_space[3 * ssize + i] = lda;
1754 for (i = 0; i < ssize; i++)
1755 working_space[i] = working_space[3 * ssize + i];
1760 for (i = 0; i < ssize; i++) {
1761 lda = working_space[i];
1764 working_space[ssize + j] = lda;
1768 for (i = 0; i < ssize; i++)
1769 source[i] = working_space[ssize + i];
1770 delete[]working_space;
1894 int ssizex,
int ssizey,
1895 int numberIterations,
1896 int numberRepetitions,
Double_t boost)
1898 int i, j, k, lindex, lhx = 0, repet;
1900 if (ssizex <= 0 || ssizey <= 0)
1901 return "Wrong Parameters";
1902 if (ssizex < ssizey)
1903 return "Sizex must be greater than sizey)";
1904 if (numberIterations <= 0)
1905 return "Number of iterations must be positive";
1907 new Double_t[ssizex * ssizey + 2 * ssizey * ssizey + 4 * ssizex];
1910 for (j = 0; j < ssizey && lhx != -1; j++) {
1913 for (i = 0; i < ssizex; i++) {
1914 lda = respMatrix[j][i];
1918 working_space[j * ssizex + i] = lda;
1922 for (i = 0; i < ssizex; i++)
1923 working_space[j * ssizex + i] /= area;
1927 delete [] working_space;
1928 return (
"ZERO COLUMN IN RESPONSE MATRIX");
1932 for (i = 0; i < ssizex; i++)
1933 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i] =
1937 for (i = 0; i < ssizey; i++) {
1938 for (j = 0; j < ssizey; j++) {
1940 for (k = 0; k < ssizex; k++) {
1941 ldb = working_space[ssizex * i + k];
1942 ldc = working_space[ssizex * j + k];
1943 lda = lda + ldb * ldc;
1945 working_space[ssizex * ssizey + ssizey * i + j] = lda;
1948 for (k = 0; k < ssizex; k++) {
1949 ldb = working_space[ssizex * i + k];
1951 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex +
1953 lda = lda + ldb * ldc;
1955 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i] =
1960 for (i = 0; i < ssizey; i++)
1961 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i] =
1962 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i];
1965 for (i = 0; i < ssizey; i++) {
1966 for (j = 0; j < ssizey; j++) {
1968 for (k = 0; k < ssizey; k++) {
1969 ldb = working_space[ssizex * ssizey + ssizey * i + k];
1970 ldc = working_space[ssizex * ssizey + ssizey * j + k];
1971 lda = lda + ldb * ldc;
1973 working_space[ssizex * ssizey + ssizey * ssizey + ssizey * i + j] =
1977 for (k = 0; k < ssizey; k++) {
1978 ldb = working_space[ssizex * ssizey + ssizey * i + k];
1980 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex +
1982 lda = lda + ldb * ldc;
1984 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i] =
1989 for (i = 0; i < ssizey; i++)
1990 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i] =
1991 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i];
1994 for (i = 0; i < ssizey; i++)
1995 working_space[ssizex * ssizey + 2 * ssizey * ssizey + i] = 1;
1998 for (repet = 0; repet < numberRepetitions; repet++) {
2000 for (i = 0; i < ssizey; i++)
2001 working_space[ssizex * ssizey + 2 * ssizey * ssizey + i] =
TMath::Power(working_space[ssizex * ssizey + 2 * ssizey * ssizey + i], boost);
2003 for (lindex = 0; lindex < numberIterations; lindex++) {
2004 for (i = 0; i < ssizey; i++) {
2006 for (j = 0; j < ssizey; j++) {
2008 working_space[ssizex * ssizey + ssizey * ssizey + ssizey * i + j];
2009 ldc = working_space[ssizex * ssizey + 2 * ssizey * ssizey + j];
2010 lda = lda + ldb * ldc;
2013 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i];
2020 ldb = working_space[ssizex * ssizey + 2 * ssizey * ssizey + i];
2022 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i] = lda;
2024 for (i = 0; i < ssizey; i++)
2025 working_space[ssizex * ssizey + 2 * ssizey * ssizey + i] =
2026 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i];
2031 for (i = 0; i < ssizex; i++) {
2033 source[i] = working_space[ssizex * ssizey + 2 * ssizey * ssizey + i];
2038 delete[]working_space;
2131 bool backgroundRemove,
int deconIterations,
2132 bool markov,
int averWindow)
2134 int i, j, numberIterations = (
Int_t)(7 *
sigma + 0.5);
2136 int k, lindex, posit, imin, imax, jmin, jmax, lh_gold, priz;
2137 Double_t lda, ldb, ldc, area, maximum, maximum_decon;
2138 int xmin,
xmax,
l, peak_index = 0, size_ext = ssize + 2 * numberIterations, shift = numberIterations, bw = 2,
w;
2140 Double_t nom, nip, nim, sp, sm, plocha = 0;
2141 Double_t m0low=0,m1low=0,m2low=0,l0low=0,l1low=0,detlow,av,men;
2143 Error(
"SearchHighRes",
"Invalid sigma, must be greater than or equal to 1");
2147 if(threshold<=0 || threshold>=100){
2148 Error(
"SearchHighRes",
"Invalid threshold, must be positive and less than 100");
2154 Error(
"SearchHighRes",
"Too large sigma");
2158 if (markov ==
true) {
2159 if (averWindow <= 0) {
2160 Error(
"SearchHighRes",
"Averaging window must be positive");
2165 if(backgroundRemove ==
true){
2166 if(ssize < 2 * numberIterations + 1){
2167 Error(
"SearchHighRes",
"Too large clipping window");
2174 for(i = 0;i < k;i++){
2175 a = i,
b = source[i];
2176 m0low += 1,m1low +=
a,m2low +=
a *
a,l0low +=
b,l1low +=
a *
b;
2178 detlow = m0low * m2low - m1low * m1low;
2180 l1low = (-l0low * m1low + l1low * m0low) / detlow;
2195 for (j=0;j<7 * (ssize + i);j++) working_space[j] = 0;
2196 for(i = 0; i < size_ext; i++){
2199 working_space[i + size_ext] = source[0] + l1low *
a;
2200 if(working_space[i + size_ext] < 0)
2201 working_space[i + size_ext]=0;
2204 else if(i >= ssize + shift){
2205 a = i - (ssize - 1 + shift);
2206 working_space[i + size_ext] = source[ssize - 1];
2207 if(working_space[i + size_ext] < 0)
2208 working_space[i + size_ext]=0;
2212 working_space[i + size_ext] = source[i - shift];
2215 if(backgroundRemove ==
true){
2216 for(i = 1; i <= numberIterations; i++){
2217 for(j = i; j < size_ext - i; j++){
2218 if(markov ==
false){
2219 a = working_space[size_ext + j];
2220 b = (working_space[size_ext + j - i] + working_space[size_ext + j + i]) / 2.0;
2228 a = working_space[size_ext + j];
2231 for (
w = j - bw;
w <= j + bw;
w++){
2232 if (
w >= 0 &&
w < size_ext){
2233 av += working_space[size_ext +
w];
2240 for (
w = j - i - bw;
w <= j - i + bw;
w++){
2241 if (
w >= 0 &&
w < size_ext){
2242 b += working_space[size_ext +
w];
2249 for (
w = j + i - bw;
w <= j + i + bw;
w++){
2250 if (
w >= 0 &&
w < size_ext){
2251 c += working_space[size_ext +
w];
2259 working_space[j]=av;
2262 for(j = i; j < size_ext - i; j++)
2263 working_space[size_ext + j] = working_space[j];
2265 for(j = 0;j < size_ext; j++){
2268 b = source[0] + l1low *
a;
2270 working_space[size_ext + j] =
b - working_space[size_ext + j];
2273 else if(j >= ssize + shift){
2274 a = j - (ssize - 1 + shift);
2275 b = source[ssize - 1];
2277 working_space[size_ext + j] =
b - working_space[size_ext + j];
2281 working_space[size_ext + j] = source[j - shift] - working_space[size_ext + j];
2284 for(j = 0;j < size_ext; j++){
2285 if(working_space[size_ext + j] < 0) working_space[size_ext + j] = 0;
2289 for(i = 0; i < size_ext; i++){
2290 working_space[i + 6*size_ext] = working_space[i + size_ext];
2294 for(j = 0; j < size_ext; j++)
2295 working_space[2 * size_ext + j] = working_space[size_ext + j];
2297 for(i = 0, maxch = 0; i < size_ext; i++){
2298 working_space[i] = 0;
2299 if(maxch < working_space[2 * size_ext + i])
2300 maxch = working_space[2 * size_ext + i];
2301 plocha += working_space[2 * size_ext + i];
2304 delete [] working_space;
2309 working_space[
xmin] = 1;
2311 nip = working_space[2 * size_ext + i] / maxch;
2312 nim = working_space[2 * size_ext + i + 1] / maxch;
2314 for(
l = 1;
l <= averWindow;
l++){
2316 a = working_space[2 * size_ext +
xmax] / maxch;
2319 a = working_space[2 * size_ext + i +
l] / maxch;
2331 if((i -
l + 1) <
xmin)
2332 a = working_space[2 * size_ext +
xmin] / maxch;
2335 a = working_space[2 * size_ext + i -
l + 1] / maxch;
2349 a = working_space[i + 1] = working_space[i] *
a;
2353 working_space[i] = working_space[i] / nom;
2355 for(j = 0; j < size_ext; j++)
2356 working_space[size_ext + j] = working_space[j] * plocha;
2357 for(j = 0; j < size_ext; j++){
2358 working_space[2 * size_ext + j] = working_space[size_ext + j];
2360 if(backgroundRemove ==
true){
2361 for(i = 1; i <= numberIterations; i++){
2362 for(j = i; j < size_ext - i; j++){
2363 a = working_space[size_ext + j];
2364 b = (working_space[size_ext + j - i] + working_space[size_ext + j + i]) / 2.0;
2367 working_space[j] =
a;
2369 for(j = i; j < size_ext - i; j++)
2370 working_space[size_ext + j] = working_space[j];
2372 for(j = 0; j < size_ext; j++){
2373 working_space[size_ext + j] = working_space[2 * size_ext + j] - working_space[size_ext + j];
2383 for(i = 0; i < size_ext; i++){
2391 working_space[i] = lda;
2399 for(i = 0; i < size_ext; i++)
2400 working_space[2 * size_ext + i] =
TMath::Abs(working_space[size_ext + i]);
2407 for(i = imin; i <= imax; i++){
2412 jmax = lh_gold - 1 - i;
2413 if(jmax > (lh_gold - 1))
2416 for(j = jmin;j <= jmax; j++){
2417 ldb = working_space[j];
2418 ldc = working_space[i + j];
2419 lda = lda + ldb * ldc;
2421 working_space[size_ext + i - imin] = lda;
2425 imin = -i,imax = size_ext + i - 1;
2426 for(i = imin; i <= imax; i++){
2428 for(j = 0; j <= (lh_gold - 1); j++){
2429 ldb = working_space[j];
2431 if(k >= 0 && k < size_ext){
2432 ldc = working_space[2 * size_ext + k];
2433 lda = lda + ldb * ldc;
2437 working_space[4 * size_ext + i - imin] = lda;
2440 for(i = imin; i <= imax; i++)
2441 working_space[2 * size_ext + i - imin] = working_space[4 * size_ext + i - imin];
2443 for(i = 0; i < size_ext; i++)
2444 working_space[i] = 1;
2446 for(lindex = 0; lindex < deconIterations; lindex++){
2447 for(i = 0; i < size_ext; i++){
2448 if(
TMath::Abs(working_space[2 * size_ext + i]) > 0.00001 &&
TMath::Abs(working_space[i]) > 0.00001){
2456 if(jmax > (size_ext - 1 - i))
2459 for(j = jmin; j <= jmax; j++){
2460 ldb = working_space[j + lh_gold - 1 + size_ext];
2461 ldc = working_space[i + j];
2462 lda = lda + ldb * ldc;
2464 ldb = working_space[2 * size_ext + i];
2471 ldb = working_space[i];
2473 working_space[3 * size_ext + i] = lda;
2476 for(i = 0; i < size_ext; i++){
2477 working_space[i] = working_space[3 * size_ext + i];
2481 for(i=0;i<size_ext;i++){
2482 lda = working_space[i];
2485 working_space[size_ext + j] = lda;
2488 maximum = 0, maximum_decon = 0;
2490 for(i = 0; i < size_ext - j; i++){
2491 if(i >= shift && i < ssize + shift){
2492 working_space[i] = area * working_space[size_ext + i + j];
2493 if(maximum_decon < working_space[i])
2494 maximum_decon = working_space[i];
2495 if(maximum < working_space[6 * size_ext + i])
2496 maximum = working_space[6 * size_ext + i];
2500 working_space[i] = 0;
2508 for(i = 1; i < size_ext - 1; i++){
2509 if(working_space[i] > working_space[i - 1] && working_space[i] > working_space[i + 1]){
2510 if(i >= shift && i < ssize + shift){
2511 if(working_space[i] > lda*maximum_decon && working_space[6 * size_ext + i] > threshold * maximum / 100.0){
2512 for(j = i - 1,
a = 0,
b = 0; j <= i + 1; j++){
2513 a += (
Double_t)(j - shift) * working_space[j];
2514 b += working_space[j];
2522 if(peak_index == 0){
2528 for(j = 0, priz = 0; j < peak_index && priz == 0; j++){
2529 if(working_space[6 * size_ext + shift + (
Int_t)
a] > working_space[6 * size_ext + shift + (
Int_t)
fPositionX[j]])
2539 for(k = peak_index; k >= j; k--){
2554 for(i = 0; i < ssize; i++) destVector[i] = working_space[i + shift];
2555 delete [] working_space;
2558 Warning(
"SearchHighRes",
"Peak buffer full");
2568 bool backgroundRemove,
int deconIterations,
2569 bool markov,
int averWindow)
2574 deconIterations,markov,averWindow);
size_t size(const MatrixT &matrix)
retrieve the size of a square matrix
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t dest
virtual void SetLineColor(Color_t lcolor)
Set the line color.
virtual void SetMarkerColor(Color_t mcolor=1)
Set the marker color.
virtual void SetMarkerStyle(Style_t mstyle=1)
Set the marker style.
virtual void SetMarkerSize(Size_t msize=1)
Set the marker size.
Int_t GetLast() const
Return last bin on the axis i.e.
Int_t GetFirst() const
Return first bin on the axis i.e.
TH1 is the base class of all histogram classes in ROOT.
virtual Double_t GetBinCenter(Int_t bin) const
Return bin center for 1D histogram.
virtual Int_t GetDimension() const
virtual void Reset(Option_t *option="")
Reset this histogram: contents, errors, etc.
void Draw(Option_t *option="") override
Draw this histogram with options.
virtual void SetBinContent(Int_t bin, Double_t content)
Set bin content see convention for numbering bins in TH1::GetBin In case the bin number is greater th...
TList * GetListOfFunctions() const
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TObject * Clone(const char *newname="") const override
Make a complete copy of the underlying object.
virtual void SetEntries(Double_t n)
TObject * FindObject(const char *name) const override
Find an object in this list using its name.
void Add(TObject *obj) override
TObject * Remove(TObject *obj) override
Remove object from the list.
void Delete(Option_t *option="") override
Remove all objects from the list AND delete all heap based objects.
The TNamed class is the base class for all named ROOT classes.
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
A PolyMarker is defined by an array on N points in a 2-D space.
Advanced Spectra Processing.
Double_t fResolution
NOT USED resolution of the neighboring peaks
static TH1 * StaticBackground(const TH1 *hist, Int_t niter=20, Option_t *option="")
Static function, interface to TSpectrum::Background.
Int_t fMaxPeaks
Maximum number of peaks to be found.
Double_t * fPositionX
[fNPeaks] X position of peaks
const char * SmoothMarkov(Double_t *source, Int_t ssize, Int_t averWindow)
One-dimensional markov spectrum smoothing function.
const char * Unfolding(Double_t *source, const Double_t **respMatrix, Int_t ssizex, Int_t ssizey, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
One-dimensional unfolding function.
void SetResolution(Double_t resolution=1)
NOT USED resolution: determines resolution of the neighbouring peaks default value is 1 correspond to...
virtual TH1 * Background(const TH1 *hist, Int_t niter=20, Option_t *option="")
One-dimensional background estimation function.
Int_t SearchHighRes(Double_t *source, Double_t *destVector, Int_t ssize, Double_t sigma, Double_t threshold, bool backgroundRemove, Int_t deconIterations, bool markov, Int_t averWindow)
One-dimensional high-resolution peak search function.
virtual Int_t Search(const TH1 *hist, Double_t sigma=2, Option_t *option="", Double_t threshold=0.05)
One-dimensional peak search function.
Int_t fNPeaks
number of peaks found
Int_t Search1HighRes(Double_t *source, Double_t *destVector, Int_t ssize, Double_t sigma, Double_t threshold, bool backgroundRemove, Int_t deconIterations, bool markov, Int_t averWindow)
Old name of SearcHighRes introduced for back compatibility.
const char * Deconvolution(Double_t *source, const Double_t *response, Int_t ssize, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
One-dimensional deconvolution function.
static Int_t fgAverageWindow
Average window of searched peaks.
static void SetDeconIterations(Int_t n=3)
Static function: Set max number of decon iterations in deconvolution operation (see TSpectrum::Search...
Double_t * fPosition
[fNPeaks] array of current peak positions
void Print(Option_t *option="") const override
Print the array of positions.
static void SetAverageWindow(Int_t w=3)
Static function: Set average window of searched peaks (see TSpectrum::SearchHighRes).
const char * DeconvolutionRL(Double_t *source, const Double_t *response, Int_t ssize, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
One-dimensional deconvolution function.
static Int_t fgIterations
Maximum number of decon iterations (default=3)
TH1 * fHistogram
resulting histogram
~TSpectrum() override
Destructor.
static Int_t StaticSearch(const TH1 *hist, Double_t sigma=2, Option_t *option="goff", Double_t threshold=0.05)
Static function, interface to TSpectrum::Search.
Double_t * fPositionY
[fNPeaks] Y position of peaks
void ToLower()
Change string to lower-case.
const char * Data() const
TString & ReplaceAll(const TString &s1, const TString &s2)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
Double_t Exp(Double_t x)
Returns the base-e exponential function of x, which is e raised to the power x.
Double_t Sqrt(Double_t x)
Returns the square root of x.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
Returns x raised to the power y.
Short_t Abs(Short_t d)
Returns the absolute value of parameter Short_t d.