60 #define PEAK_WINDOW 1024
86 :
TNamed(
"Spectrum",
"Miroslav Morhac peak finder")
198 if (h == 0)
return 0;
201 Error(
"Search",
"Only implemented for 1-d histograms");
228 Int_t size = last-first+1;
231 for (i = 0; i < size; i++) source[i] = h->
GetBinContent(i + first);
234 Background(source,size,numberIterations, direction, filterOrder,smoothing,
235 smoothWindow,compton);
240 char *
hbname =
new char[nch+20];
241 snprintf(hbname,nch+20,
"%s_background",h->
GetName());
244 hb->GetListOfFunctions()->
Delete();
246 for (i=0; i< size; i++) hb->SetBinContent(i+first,source[i]);
247 hb->SetEntries(size);
251 if (
gPad)
delete gPad->GetPrimitive(hbname);
320 if (hin == 0)
return 0;
323 Error(
"Search",
"Only implemented for 1-d and 2-d histograms");
326 if (threshold <=0 || threshold >= 1) {
327 Warning(
"Search",
"threshold must 0<threshold<1, threshol=0.05 assumed");
347 if (dimension == 1) {
350 Int_t size = last-first+1;
351 Int_t i, bin, npeaks;
354 for (i = 0; i < size; i++) source[i] = hin->
GetBinContent(i + first);
357 if (sigma < 1) sigma = 1;
358 if (sigma > 8) sigma = 8;
360 npeaks =
SearchHighRes(source, dest, size, sigma, 100*threshold,
363 for (i = 0; i < npeaks; i++) {
373 if (!npeaks)
return 0;
417 int numberIterations,
418 int direction,
int filterOrder,
419 bool smoothing,
int smoothWindow,
880 int i, j, w, bw, b1, b2, priz;
881 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;
883 return "Wrong Parameters";
884 if (numberIterations < 1)
885 return "Width of Clipping Window Must Be Positive";
886 if (ssize < 2 * numberIterations + 1)
887 return "Too Large Clipping Window";
889 return "Incorrect width of smoothing window";
891 for (i = 0; i < ssize; i++){
892 working_space[i] = spectrum[i];
893 working_space[i + ssize] = spectrum[i];
895 bw=(smoothWindow-1)/2;
899 i = numberIterations;
902 for (j = i; j < ssize - i; j++) {
904 a = working_space[ssize + j];
905 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
908 working_space[j] =
a;
911 else if (smoothing ==
kTRUE){
912 a = working_space[ssize + j];
915 for (w = j - bw; w <= j + bw; w++){
916 if ( w >= 0 && w < ssize){
917 av += working_space[ssize + w];
924 for (w = j - i - bw; w <= j - i + bw; w++){
925 if ( w >= 0 && w < ssize){
926 b += working_space[ssize + w];
933 for (w = j + i - bw; w <= j + i + bw; w++){
934 if ( w >= 0 && w < ssize){
935 c += working_space[ssize + w];
946 for (j = i; j < ssize - i; j++)
947 working_space[ssize + j] = working_space[j];
957 for (j = i; j < ssize - i; j++) {
959 a = working_space[ssize + j];
960 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
963 c -= working_space[ssize + j - (
Int_t) (2 * ai)] / 6;
964 c += 4 * working_space[ssize + j - (
Int_t) ai] / 6;
965 c += 4 * working_space[ssize + j + (
Int_t) ai] / 6;
966 c -= working_space[ssize + j + (
Int_t) (2 * ai)] / 6;
971 working_space[j] =
a;
974 else if (smoothing ==
kTRUE){
975 a = working_space[ssize + j];
978 for (w = j - bw; w <= j + bw; w++){
979 if ( w >= 0 && w < ssize){
980 av += working_space[ssize + w];
987 for (w = j - i - bw; w <= j - i + bw; w++){
988 if ( w >= 0 && w < ssize){
989 b += working_space[ssize + w];
996 for (w = j + i - bw; w <= j + i + bw; w++){
997 if ( w >= 0 && w < ssize){
998 c += working_space[ssize + w];
1006 for (w = j - (
Int_t)(2 * ai) - bw; w <= j - (
Int_t)(2 * ai) + bw; w++){
1007 if (w >= 0 && w < ssize){
1008 b4 += working_space[ssize + w];
1014 for (w = j - (
Int_t)ai - bw; w <= j - (
Int_t)ai + bw; w++){
1015 if (w >= 0 && w < ssize){
1016 c4 += working_space[ssize + w];
1022 for (w = j + (
Int_t)ai - bw; w <= j + (
Int_t)ai + bw; w++){
1023 if (w >= 0 && w < ssize){
1024 d4 += working_space[ssize + w];
1030 for (w = j + (
Int_t)(2 * ai) - bw; w <= j + (
Int_t)(2 * ai) + bw; w++){
1031 if (w >= 0 && w < ssize){
1032 e4 += working_space[ssize + w];
1037 b4 = (-b4 + 4 * c4 + 4 * d4 - e4) / 6;
1042 working_space[j]=av;
1045 for (j = i; j < ssize - i; j++)
1046 working_space[ssize + j] = working_space[j];
1056 for (j = i; j < ssize - i; j++) {
1057 if (smoothing ==
kFALSE){
1058 a = working_space[ssize + j];
1059 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
1062 c -= working_space[ssize + j - (
Int_t) (2 * ai)] / 6;
1063 c += 4 * working_space[ssize + j - (
Int_t) ai] / 6;
1064 c += 4 * working_space[ssize + j + (
Int_t) ai] / 6;
1065 c -= working_space[ssize + j + (
Int_t) (2 * ai)] / 6;
1068 d += working_space[ssize + j - (
Int_t) (3 * ai)] / 20;
1069 d -= 6 * working_space[ssize + j - (
Int_t) (2 * ai)] / 20;
1070 d += 15 * working_space[ssize + j - (
Int_t) ai] / 20;
1071 d += 15 * working_space[ssize + j + (
Int_t) ai] / 20;
1072 d -= 6 * working_space[ssize + j + (
Int_t) (2 * ai)] / 20;
1073 d += working_space[ssize + j + (
Int_t) (3 * ai)] / 20;
1080 working_space[j] =
a;
1083 else if (smoothing ==
kTRUE){
1084 a = working_space[ssize + j];
1087 for (w = j - bw; w <= j + bw; w++){
1088 if ( w >= 0 && w < ssize){
1089 av += working_space[ssize + w];
1096 for (w = j - i - bw; w <= j - i + bw; w++){
1097 if ( w >= 0 && w < ssize){
1098 b += working_space[ssize + w];
1105 for (w = j + i - bw; w <= j + i + bw; w++){
1106 if ( w >= 0 && w < ssize){
1107 c += working_space[ssize + w];
1115 for (w = j - (
Int_t)(2 * ai) - bw; w <= j - (
Int_t)(2 * ai) + bw; w++){
1116 if (w >= 0 && w < ssize){
1117 b4 += working_space[ssize + w];
1123 for (w = j - (
Int_t)ai - bw; w <= j - (
Int_t)ai + bw; w++){
1124 if (w >= 0 && w < ssize){
1125 c4 += working_space[ssize + w];
1131 for (w = j + (
Int_t)ai - bw; w <= j + (
Int_t)ai + bw; w++){
1132 if (w >= 0 && w < ssize){
1133 d4 += working_space[ssize + w];
1139 for (w = j + (
Int_t)(2 * ai) - bw; w <= j + (
Int_t)(2 * ai) + bw; w++){
1140 if (w >= 0 && w < ssize){
1141 e4 += working_space[ssize + w];
1146 b4 = (-b4 + 4 * c4 + 4 * d4 - e4) / 6;
1149 for (w = j - (
Int_t)(3 * ai) - bw; w <= j - (
Int_t)(3 * ai) + bw; w++){
1150 if (w >= 0 && w < ssize){
1151 b6 += working_space[ssize + w];
1157 for (w = j - (
Int_t)(2 * ai) - bw; w <= j - (
Int_t)(2 * ai) + bw; w++){
1158 if (w >= 0 && w < ssize){
1159 c6 += working_space[ssize + w];
1165 for (w = j - (
Int_t)ai - bw; w <= j - (
Int_t)ai + bw; w++){
1166 if (w >= 0 && w < ssize){
1167 d6 += working_space[ssize + w];
1173 for (w = j + (
Int_t)ai - bw; w <= j + (
Int_t)ai + bw; w++){
1174 if (w >= 0 && w < ssize){
1175 e6 += working_space[ssize + w];
1181 for (w = j + (
Int_t)(2 * ai) - bw; w <= j + (
Int_t)(2 * ai) + bw; w++){
1182 if (w >= 0 && w < ssize){
1183 f6 += working_space[ssize + w];
1189 for (w = j + (
Int_t)(3 * ai) - bw; w <= j + (
Int_t)(3 * ai) + bw; w++){
1190 if (w >= 0 && w < ssize){
1191 g6 += working_space[ssize + w];
1196 b6 = (b6 - 6 * c6 + 15 * d6 + 15 * e6 - 6 * f6 + g6) / 20;
1203 working_space[j]=av;
1206 for (j = i; j < ssize - i; j++)
1207 working_space[ssize + j] = working_space[j];
1217 for (j = i; j < ssize - i; j++) {
1218 if (smoothing ==
kFALSE){
1219 a = working_space[ssize + j];
1220 b = (working_space[ssize + j - i] + working_space[ssize + j + i]) / 2.0;
1223 c -= working_space[ssize + j - (
Int_t) (2 * ai)] / 6;
1224 c += 4 * working_space[ssize + j - (
Int_t) ai] / 6;
1225 c += 4 * working_space[ssize + j + (
Int_t) ai] / 6;
1226 c -= working_space[ssize + j + (
Int_t) (2 * ai)] / 6;
1229 d += working_space[ssize + j - (
Int_t) (3 * ai)] / 20;
1230 d -= 6 * working_space[ssize + j - (
Int_t) (2 * ai)] / 20;
1231 d += 15 * working_space[ssize + j - (
Int_t) ai] / 20;
1232 d += 15 * working_space[ssize + j + (
Int_t) ai] / 20;
1233 d -= 6 * working_space[ssize + j + (
Int_t) (2 * ai)] / 20;
1234 d += working_space[ssize + j + (
Int_t) (3 * ai)] / 20;
1237 e -= working_space[ssize + j - (
Int_t) (4 * ai)] / 70;
1238 e += 8 * working_space[ssize + j - (
Int_t) (3 * ai)] / 70;
1239 e -= 28 * working_space[ssize + j - (
Int_t) (2 * ai)] / 70;
1240 e += 56 * working_space[ssize + j - (
Int_t) ai] / 70;
1241 e += 56 * working_space[ssize + j + (
Int_t) ai] / 70;
1242 e -= 28 * working_space[ssize + j + (
Int_t) (2 * ai)] / 70;
1243 e += 8 * working_space[ssize + j + (
Int_t) (3 * ai)] / 70;
1244 e -= working_space[ssize + j + (
Int_t) (4 * ai)] / 70;
1253 working_space[j] =
a;
1256 else if (smoothing ==
kTRUE){
1257 a = working_space[ssize + j];
1260 for (w = j - bw; w <= j + bw; w++){
1261 if ( w >= 0 && w < ssize){
1262 av += working_space[ssize + w];
1269 for (w = j - i - bw; w <= j - i + bw; w++){
1270 if ( w >= 0 && w < ssize){
1271 b += working_space[ssize + w];
1278 for (w = j + i - bw; w <= j + i + bw; w++){
1279 if ( w >= 0 && w < ssize){
1280 c += working_space[ssize + w];
1288 for (w = j - (
Int_t)(2 * ai) - bw; w <= j - (
Int_t)(2 * ai) + bw; w++){
1289 if (w >= 0 && w < ssize){
1290 b4 += working_space[ssize + w];
1296 for (w = j - (
Int_t)ai - bw; w <= j - (
Int_t)ai + bw; w++){
1297 if (w >= 0 && w < ssize){
1298 c4 += working_space[ssize + w];
1304 for (w = j + (
Int_t)ai - bw; w <= j + (
Int_t)ai + bw; w++){
1305 if (w >= 0 && w < ssize){
1306 d4 += working_space[ssize + w];
1312 for (w = j + (
Int_t)(2 * ai) - bw; w <= j + (
Int_t)(2 * ai) + bw; w++){
1313 if (w >= 0 && w < ssize){
1314 e4 += working_space[ssize + w];
1319 b4 = (-b4 + 4 * c4 + 4 * d4 - e4) / 6;
1322 for (w = j - (
Int_t)(3 * ai) - bw; w <= j - (
Int_t)(3 * ai) + bw; w++){
1323 if (w >= 0 && w < ssize){
1324 b6 += working_space[ssize + w];
1330 for (w = j - (
Int_t)(2 * ai) - bw; w <= j - (
Int_t)(2 * ai) + bw; w++){
1331 if (w >= 0 && w < ssize){
1332 c6 += working_space[ssize + w];
1338 for (w = j - (
Int_t)ai - bw; w <= j - (
Int_t)ai + bw; w++){
1339 if (w >= 0 && w < ssize){
1340 d6 += working_space[ssize + w];
1346 for (w = j + (
Int_t)ai - bw; w <= j + (
Int_t)ai + bw; w++){
1347 if (w >= 0 && w < ssize){
1348 e6 += working_space[ssize + w];
1354 for (w = j + (
Int_t)(2 * ai) - bw; w <= j + (
Int_t)(2 * ai) + bw; w++){
1355 if (w >= 0 && w < ssize){
1356 f6 += working_space[ssize + w];
1362 for (w = j + (
Int_t)(3 * ai) - bw; w <= j + (
Int_t)(3 * ai) + bw; w++){
1363 if (w >= 0 && w < ssize){
1364 g6 += working_space[ssize + w];
1369 b6 = (b6 - 6 * c6 + 15 * d6 + 15 * e6 - 6 * f6 + g6) / 20;
1372 for (w = j - (
Int_t)(4 * ai) - bw; w <= j - (
Int_t)(4 * ai) + bw; w++){
1373 if (w >= 0 && w < ssize){
1374 b8 += working_space[ssize + w];
1380 for (w = j - (
Int_t)(3 * ai) - bw; w <= j - (
Int_t)(3 * ai) + bw; w++){
1381 if (w >= 0 && w < ssize){
1382 c8 += working_space[ssize + w];
1388 for (w = j - (
Int_t)(2 * ai) - bw; w <= j - (
Int_t)(2 * ai) + bw; w++){
1389 if (w >= 0 && w < ssize){
1390 d8 += working_space[ssize + w];
1396 for (w = j - (
Int_t)ai - bw; w <= j - (
Int_t)ai + bw; w++){
1397 if (w >= 0 && w < ssize){
1398 e8 += working_space[ssize + w];
1404 for (w = j + (
Int_t)ai - bw; w <= j + (
Int_t)ai + bw; w++){
1405 if (w >= 0 && w < ssize){
1406 f8 += working_space[ssize + w];
1412 for (w = j + (
Int_t)(2 * ai) - bw; w <= j + (
Int_t)(2 * ai) + bw; w++){
1413 if (w >= 0 && w < ssize){
1414 g8 += working_space[ssize + w];
1420 for (w = j + (
Int_t)(3 * ai) - bw; w <= j + (
Int_t)(3 * ai) + bw; w++){
1421 if (w >= 0 && w < ssize){
1422 h8 += working_space[ssize + w];
1428 for (w = j + (
Int_t)(4 * ai) - bw; w <= j + (
Int_t)(4 * ai) + bw; w++){
1429 if (w >= 0 && w < ssize){
1430 i8 += working_space[ssize + w];
1435 b8 = ( -b8 + 8 * c8 - 28 * d8 + 56 * e8 - 56 * f8 - 28 * g8 + 8 * h8 - i8)/70;
1444 working_space[j]=av;
1447 for (j = i; j < ssize - i; j++)
1448 working_space[ssize + j] = working_space[j];
1456 if (compton ==
kTRUE) {
1457 for (i = 0, b2 = 0; i < ssize; i++){
1459 a = working_space[i], b = spectrum[i];
1465 yb1 = working_space[b1];
1466 for (b2 = b1 + 1, c = 0, priz = 0; priz == 0 && b2 < ssize; b2++){
1467 a = working_space[b2], b = spectrum[b2];
1476 yb2 = working_space[b2];
1478 for (j = b1, c = 0; j <= b2; j++){
1483 c = (yb2 - yb1) / c;
1484 for (j = b1, d = 0; j <= b2 && j < ssize; j++){
1488 working_space[ssize + j] =
a;
1494 for (j = b2, c = 0; j >= b1; j--){
1499 c = (yb1 - yb2) / c;
1500 for (j = b2, d = 0;j >= b1 && j >= 0; j--){
1504 working_space[ssize + j] =
a;
1513 for (j = 0; j < ssize; j++)
1514 spectrum[j] = working_space[ssize + j];
1515 delete[]working_space;
1598 Double_t nom, nip, nim, sp, sm, area = 0;
1600 return "Averaging Window must be positive";
1602 xmin = 0,xmax = ssize - 1;
1603 for(i = 0, maxch = 0; i < ssize; i++){
1605 if(maxch < source[i])
1611 delete [] working_space;
1616 working_space[
xmin] = 1;
1617 for(i = xmin; i <
xmax; i++){
1618 nip = source[i] / maxch;
1619 nim = source[i + 1] / maxch;
1621 for(l = 1; l <= averWindow; l++){
1623 a = source[
xmax] / maxch;
1626 a = source[i +
l] / maxch;
1636 if((i - l + 1) < xmin)
1637 a = source[
xmin] / maxch;
1640 a = source[i - l + 1] / maxch;
1651 a = working_space[i + 1] = working_space[i] *
a;
1654 for(i = xmin; i <=
xmax; i++){
1655 working_space[i] = working_space[i] / nom;
1657 for(i = 0; i < ssize; i++)
1658 source[i] = working_space[i] * area;
1659 delete[]working_space;
1667 int ssize,
int numberIterations,
1984 return "Wrong Parameters";
1986 if (numberRepetitions <= 0)
1987 return "Wrong Parameters";
1992 int i, j, k, lindex, posit, lh_gold,
l, repet;
1993 Double_t lda, ldb, ldc, area, maximum;
2000 for (i = 0; i < ssize; i++) {
2004 working_space[i] = lda;
2006 if (lda > maximum) {
2011 if (lh_gold == -1) {
2012 delete [] working_space;
2013 return "ZERO RESPONSE VECTOR";
2017 for (i = 0; i < ssize; i++)
2018 working_space[2 * ssize + i] = source[i];
2021 for (i = 0; i < ssize; i++){
2023 for (j = 0; j < ssize; j++){
2024 ldb = working_space[j];
2027 ldc = working_space[k];
2028 lda = lda + ldb * ldc;
2031 working_space[ssize + i] = lda;
2033 for (k = 0; k < ssize; k++){
2036 ldb = working_space[
l];
2037 ldc = working_space[2 * ssize + k];
2038 lda = lda + ldb * ldc;
2041 working_space[3 * ssize + i]=lda;
2045 for (i = 0; i < ssize; i++){
2046 working_space[2 * ssize + i] = working_space[3 * ssize + i];
2050 for (i = 0; i < ssize; i++)
2051 working_space[i] = 1;
2054 for (repet = 0; repet < numberRepetitions; repet++) {
2056 for (i = 0; i < ssize; i++)
2057 working_space[i] =
TMath::Power(working_space[i], boost);
2059 for (lindex = 0; lindex < numberIterations; lindex++) {
2060 for (i = 0; i < ssize; i++) {
2061 if (working_space[2 * ssize + i] > 0.000001
2062 && working_space[i] > 0.000001) {
2064 for (j = 0; j < lh_gold; j++) {
2065 ldb = working_space[j + ssize];
2070 ldc = working_space[k];
2073 ldc += working_space[k];
2077 ldc = working_space[i];
2078 lda = lda + ldb * ldc;
2080 ldb = working_space[2 * ssize + i];
2086 ldb = working_space[i];
2088 working_space[3 * ssize + i] = lda;
2091 for (i = 0; i < ssize; i++)
2092 working_space[i] = working_space[3 * ssize + i];
2097 for (i = 0; i < ssize; i++) {
2098 lda = working_space[i];
2101 working_space[ssize + j] = lda;
2105 for (i = 0; i < ssize; i++)
2106 source[i] = area * working_space[ssize + i];
2107 delete[]working_space;
2115 int ssize,
int numberIterations,
2274 return "Wrong Parameters";
2276 if (numberRepetitions <= 0)
2277 return "Wrong Parameters";
2282 int i, j, k, lindex, posit, lh_gold, repet, kmin, kmax;
2289 for (i = 0; i < ssize; i++) {
2293 working_space[ssize + i] = lda;
2294 if (lda > maximum) {
2299 if (lh_gold == -1) {
2300 delete [] working_space;
2301 return "ZERO RESPONSE VECTOR";
2305 for (i = 0; i < ssize; i++)
2306 working_space[2 * ssize + i] = source[i];
2309 for (i = 0; i < ssize; i++){
2310 if (i <= ssize - lh_gold)
2311 working_space[i] = 1;
2314 working_space[i] = 0;
2318 for (repet = 0; repet < numberRepetitions; repet++) {
2320 for (i = 0; i < ssize; i++)
2321 working_space[i] =
TMath::Power(working_space[i], boost);
2323 for (lindex = 0; lindex < numberIterations; lindex++) {
2324 for (i = 0; i <= ssize - lh_gold; i++){
2326 if (working_space[i] > 0){
2327 for (j = i; j < i + lh_gold; j++){
2328 ldb = working_space[2 * ssize + j];
2332 if (kmax > lh_gold - 1)
2334 kmin = j + lh_gold - ssize;
2338 for (k = kmax; k >= kmin; k--){
2339 ldc += working_space[ssize + k] * working_space[j - k];
2347 ldb = ldb * working_space[ssize + j - i];
2351 lda = lda * working_space[i];
2353 working_space[3 * ssize + i] = lda;
2355 for (i = 0; i < ssize; i++)
2356 working_space[i] = working_space[3 * ssize + i];
2361 for (i = 0; i < ssize; i++) {
2362 lda = working_space[i];
2365 working_space[ssize + j] = lda;
2369 for (i = 0; i < ssize; i++)
2370 source[i] = working_space[ssize + i];
2371 delete[]working_space;
2380 int ssizex,
int ssizey,
2381 int numberIterations,
2493 int i, j, k, lindex, lhx = 0, repet;
2495 if (ssizex <= 0 || ssizey <= 0)
2496 return "Wrong Parameters";
2497 if (ssizex < ssizey)
2498 return "Sizex must be greater than sizey)";
2499 if (numberIterations <= 0)
2500 return "Number of iterations must be positive";
2502 new Double_t[ssizex * ssizey + 2 * ssizey * ssizey + 4 * ssizex];
2505 for (j = 0; j < ssizey && lhx != -1; j++) {
2508 for (i = 0; i < ssizex; i++) {
2509 lda = respMatrix[j][i];
2513 working_space[j * ssizex + i] = lda;
2517 for (i = 0; i < ssizex; i++)
2518 working_space[j * ssizex + i] /= area;
2522 delete [] working_space;
2523 return (
"ZERO COLUMN IN RESPONSE MATRIX");
2527 for (i = 0; i < ssizex; i++)
2528 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i] =
2532 for (i = 0; i < ssizey; i++) {
2533 for (j = 0; j < ssizey; j++) {
2535 for (k = 0; k < ssizex; k++) {
2536 ldb = working_space[ssizex * i + k];
2537 ldc = working_space[ssizex * j + k];
2538 lda = lda + ldb * ldc;
2540 working_space[ssizex * ssizey + ssizey * i + j] = lda;
2543 for (k = 0; k < ssizex; k++) {
2544 ldb = working_space[ssizex * i + k];
2546 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex +
2548 lda = lda + ldb * ldc;
2550 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i] =
2555 for (i = 0; i < ssizey; i++)
2556 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i] =
2557 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i];
2560 for (i = 0; i < ssizey; i++) {
2561 for (j = 0; j < ssizey; j++) {
2563 for (k = 0; k < ssizey; k++) {
2564 ldb = working_space[ssizex * ssizey + ssizey * i + k];
2565 ldc = working_space[ssizex * ssizey + ssizey * j + k];
2566 lda = lda + ldb * ldc;
2568 working_space[ssizex * ssizey + ssizey * ssizey + ssizey * i + j] =
2572 for (k = 0; k < ssizey; k++) {
2573 ldb = working_space[ssizex * ssizey + ssizey * i + k];
2575 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex +
2577 lda = lda + ldb * ldc;
2579 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i] =
2584 for (i = 0; i < ssizey; i++)
2585 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i] =
2586 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i];
2589 for (i = 0; i < ssizey; i++)
2590 working_space[ssizex * ssizey + 2 * ssizey * ssizey + i] = 1;
2593 for (repet = 0; repet < numberRepetitions; repet++) {
2595 for (i = 0; i < ssizey; i++)
2596 working_space[ssizex * ssizey + 2 * ssizey * ssizey + i] =
TMath::Power(working_space[ssizex * ssizey + 2 * ssizey * ssizey + i], boost);
2598 for (lindex = 0; lindex < numberIterations; lindex++) {
2599 for (i = 0; i < ssizey; i++) {
2601 for (j = 0; j < ssizey; j++) {
2603 working_space[ssizex * ssizey + ssizey * ssizey + ssizey * i + j];
2604 ldc = working_space[ssizex * ssizey + 2 * ssizey * ssizey + j];
2605 lda = lda + ldb * ldc;
2608 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 2 * ssizex + i];
2615 ldb = working_space[ssizex * ssizey + 2 * ssizey * ssizey + i];
2617 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i] = lda;
2619 for (i = 0; i < ssizey; i++)
2620 working_space[ssizex * ssizey + 2 * ssizey * ssizey + i] =
2621 working_space[ssizex * ssizey + 2 * ssizey * ssizey + 3 * ssizex + i];
2626 for (i = 0; i < ssizex; i++) {
2628 source[i] = working_space[ssizex * ssizey + 2 * ssizey * ssizey + i];
2633 delete[]working_space;
2642 bool backgroundRemove,
int deconIterations,
2643 bool markov,
int averWindow)
2887 int i, j, numberIterations = (
Int_t)(7 * sigma + 0.5);
2889 int k, lindex, posit, imin, imax, jmin, jmax, lh_gold, priz;
2890 Double_t lda, ldb, ldc, area, maximum, maximum_decon;
2891 int xmin,
xmax,
l, peak_index = 0, size_ext = ssize + 2 * numberIterations, shift = numberIterations, bw = 2, w;
2893 Double_t nom, nip, nim, sp, sm, plocha = 0;
2894 Double_t m0low=0,m1low=0,m2low=0,l0low=0,l1low=0,detlow,av,men;
2896 Error(
"SearchHighRes",
"Invalid sigma, must be greater than or equal to 1");
2900 if(threshold<=0 || threshold>=100){
2901 Error(
"SearchHighRes",
"Invalid threshold, must be positive and less than 100");
2905 j = (
Int_t) (5.0 * sigma + 0.5);
2907 Error(
"SearchHighRes",
"Too large sigma");
2911 if (markov ==
true) {
2912 if (averWindow <= 0) {
2913 Error(
"SearchHighRes",
"Averanging window must be positive");
2918 if(backgroundRemove ==
true){
2919 if(ssize < 2 * numberIterations + 1){
2920 Error(
"SearchHighRes",
"Too large clipping window");
2925 k = int(2 * sigma+0.5);
2927 for(i = 0;i < k;i++){
2928 a = i,b = source[i];
2929 m0low += 1,m1low +=
a,m2low += a *
a,l0low += b,l1low += a * b;
2931 detlow = m0low * m2low - m1low * m1low;
2933 l1low = (-l0low * m1low + l1low * m0low) / detlow;
2945 i = (
Int_t)(7 * sigma + 0.5);
2948 for (j=0;j<7 * (ssize + i);j++) working_space[j] = 0;
2949 for(i = 0; i < size_ext; i++){
2952 working_space[i + size_ext] = source[0] + l1low *
a;
2953 if(working_space[i + size_ext] < 0)
2954 working_space[i + size_ext]=0;
2957 else if(i >= ssize + shift){
2958 a = i - (ssize - 1 + shift);
2959 working_space[i + size_ext] = source[ssize - 1];
2960 if(working_space[i + size_ext] < 0)
2961 working_space[i + size_ext]=0;
2965 working_space[i + size_ext] = source[i - shift];
2968 if(backgroundRemove ==
true){
2969 for(i = 1; i <= numberIterations; i++){
2970 for(j = i; j < size_ext - i; j++){
2971 if(markov ==
false){
2972 a = working_space[size_ext + j];
2973 b = (working_space[size_ext + j - i] + working_space[size_ext + j + i]) / 2.0;
2981 a = working_space[size_ext + j];
2984 for (w = j - bw; w <= j + bw; w++){
2985 if ( w >= 0 && w < size_ext){
2986 av += working_space[size_ext + w];
2993 for (w = j - i - bw; w <= j - i + bw; w++){
2994 if ( w >= 0 && w < size_ext){
2995 b += working_space[size_ext + w];
3002 for (w = j + i - bw; w <= j + i + bw; w++){
3003 if ( w >= 0 && w < size_ext){
3004 c += working_space[size_ext + w];
3012 working_space[j]=av;
3015 for(j = i; j < size_ext - i; j++)
3016 working_space[size_ext + j] = working_space[j];
3018 for(j = 0;j < size_ext; j++){
3021 b = source[0] + l1low *
a;
3023 working_space[size_ext + j] = b - working_space[size_ext + j];
3026 else if(j >= ssize + shift){
3027 a = j - (ssize - 1 + shift);
3028 b = source[ssize - 1];
3030 working_space[size_ext + j] = b - working_space[size_ext + j];
3034 working_space[size_ext + j] = source[j - shift] - working_space[size_ext + j];
3037 for(j = 0;j < size_ext; j++){
3038 if(working_space[size_ext + j] < 0) working_space[size_ext + j] = 0;
3042 for(i = 0; i < size_ext; i++){
3043 working_space[i + 6*size_ext] = working_space[i + size_ext];
3047 for(j = 0; j < size_ext; j++)
3048 working_space[2 * size_ext + j] = working_space[size_ext + j];
3049 xmin = 0,xmax = size_ext - 1;
3050 for(i = 0, maxch = 0; i < size_ext; i++){
3051 working_space[i] = 0;
3052 if(maxch < working_space[2 * size_ext + i])
3053 maxch = working_space[2 * size_ext + i];
3054 plocha += working_space[2 * size_ext + i];
3057 delete [] working_space;
3062 working_space[
xmin] = 1;
3063 for(i = xmin; i <
xmax; i++){
3064 nip = working_space[2 * size_ext + i] / maxch;
3065 nim = working_space[2 * size_ext + i + 1] / maxch;
3067 for(l = 1; l <= averWindow; l++){
3069 a = working_space[2 * size_ext + xmax] / maxch;
3072 a = working_space[2 * size_ext + i +
l] / maxch;
3084 if((i - l + 1) < xmin)
3085 a = working_space[2 * size_ext +
xmin] / maxch;
3088 a = working_space[2 * size_ext + i - l + 1] / maxch;
3102 a = working_space[i + 1] = working_space[i] *
a;
3105 for(i = xmin; i <=
xmax; i++){
3106 working_space[i] = working_space[i] / nom;
3108 for(j = 0; j < size_ext; j++)
3109 working_space[size_ext + j] = working_space[j] * plocha;
3110 for(j = 0; j < size_ext; j++){
3111 working_space[2 * size_ext + j] = working_space[size_ext + j];
3113 if(backgroundRemove ==
true){
3114 for(i = 1; i <= numberIterations; i++){
3115 for(j = i; j < size_ext - i; j++){
3116 a = working_space[size_ext + j];
3117 b = (working_space[size_ext + j - i] + working_space[size_ext + j + i]) / 2.0;
3120 working_space[j] =
a;
3122 for(j = i; j < size_ext - i; j++)
3123 working_space[size_ext + j] = working_space[j];
3125 for(j = 0; j < size_ext; j++){
3126 working_space[size_ext + j] = working_space[2 * size_ext + j] - working_space[size_ext + j];
3136 for(i = 0; i < size_ext; i++){
3138 lda = lda * lda / (2 * sigma * sigma);
3144 working_space[i] = lda;
3152 for(i = 0; i < size_ext; i++)
3153 working_space[2 * size_ext + i] =
TMath::Abs(working_space[size_ext + i]);
3160 for(i = imin; i <= imax; i++){
3165 jmax = lh_gold - 1 - i;
3166 if(jmax > (lh_gold - 1))
3169 for(j = jmin;j <= jmax; j++){
3170 ldb = working_space[j];
3171 ldc = working_space[i + j];
3172 lda = lda + ldb * ldc;
3174 working_space[size_ext + i - imin] = lda;
3178 imin = -i,imax = size_ext + i - 1;
3179 for(i = imin; i <= imax; i++){
3181 for(j = 0; j <= (lh_gold - 1); j++){
3182 ldb = working_space[j];
3184 if(k >= 0 && k < size_ext){
3185 ldc = working_space[2 * size_ext + k];
3186 lda = lda + ldb * ldc;
3190 working_space[4 * size_ext + i - imin] = lda;
3193 for(i = imin; i <= imax; i++)
3194 working_space[2 * size_ext + i - imin] = working_space[4 * size_ext + i - imin];
3196 for(i = 0; i < size_ext; i++)
3197 working_space[i] = 1;
3199 for(lindex = 0; lindex < deconIterations; lindex++){
3200 for(i = 0; i < size_ext; i++){
3201 if(
TMath::Abs(working_space[2 * size_ext + i]) > 0.00001 &&
TMath::Abs(working_space[i]) > 0.00001){
3209 if(jmax > (size_ext - 1 - i))
3212 for(j = jmin; j <= jmax; j++){
3213 ldb = working_space[j + lh_gold - 1 + size_ext];
3214 ldc = working_space[i + j];
3215 lda = lda + ldb * ldc;
3217 ldb = working_space[2 * size_ext + i];
3224 ldb = working_space[i];
3226 working_space[3 * size_ext + i] = lda;
3229 for(i = 0; i < size_ext; i++){
3230 working_space[i] = working_space[3 * size_ext + i];
3234 for(i=0;i<size_ext;i++){
3235 lda = working_space[i];
3238 working_space[size_ext + j] = lda;
3241 maximum = 0, maximum_decon = 0;
3243 for(i = 0; i < size_ext - j; i++){
3244 if(i >= shift && i < ssize + shift){
3245 working_space[i] = area * working_space[size_ext + i + j];
3246 if(maximum_decon < working_space[i])
3247 maximum_decon = working_space[i];
3248 if(maximum < working_space[6 * size_ext + i])
3249 maximum = working_space[6 * size_ext + i];
3253 working_space[i] = 0;
3261 for(i = 1; i < size_ext - 1; i++){
3262 if(working_space[i] > working_space[i - 1] && working_space[i] > working_space[i + 1]){
3263 if(i >= shift && i < ssize + shift){
3264 if(working_space[i] > lda*maximum_decon && working_space[6 * size_ext + i] > threshold * maximum / 100.0){
3265 for(j = i - 1, a = 0, b = 0; j <= i + 1; j++){
3266 a += (
Double_t)(j - shift) * working_space[j];
3267 b += working_space[j];
3275 if(peak_index == 0){
3281 for(j = 0, priz = 0; j < peak_index && priz == 0; j++){
3282 if(working_space[6 * size_ext + shift + (
Int_t)
a] > working_space[6 * size_ext + shift + (
Int_t)
fPositionX[j]])
3292 for(k = peak_index; k >= j; k--){
3307 for(i = 0; i < ssize; i++) destVector[i] = working_space[i + shift];
3308 delete [] working_space;
3311 Warning(
"SearchHighRes",
"Peak buffer full");
3320 bool backgroundRemove,
int deconIterations,
3321 bool markov,
int averWindow)
3328 return SearchHighRes(source,destVector,ssize,sigma,threshold,backgroundRemove,
3329 deconIterations,markov,averWindow);
3342 return s.
Search(hist,sigma,option,threshold);
Int_t GetFirst() const
Return first bin on the axis i.e.
TList * GetListOfFunctions() const
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)
virtual Double_t GetBinContent(Int_t bin) const
Return content of bin number bin.
TString & ReplaceAll(const TString &s1, const TString &s2)
virtual Int_t GetDimension() const
static TH1 * StaticBackground(const TH1 *hist, Int_t niter=20, Option_t *option="")
const char * DeconvolutionRL(Double_t *source, const Double_t *response, Int_t ssize, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
Double_t background(Double_t *x, Double_t *par)
ClassImp(TSpectrum) TSpectrum
void ToLower()
Change string to lower-case.
virtual TObject * FindObject(const char *name) const
Find an object in this list using its name.
LongDouble_t Power(LongDouble_t x, LongDouble_t y)
TObject * Clone(const char *newname=0) const
Make a complete copy of the underlying object.
const char * Data() const
The TNamed class is the base class for all named ROOT classes.
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)
virtual void SetMarkerColor(Color_t mcolor=1)
virtual void Error(const char *method, const char *msgfmt,...) const
Issue error message.
virtual void Delete(Option_t *option="")
Delete this object.
virtual Double_t GetBinCenter(Int_t bin) const
return bin center for 1D historam Better to use h1.GetXaxis().GetBinCenter(bin)
virtual Int_t Search(const TH1 *hist, Double_t sigma=2, Option_t *option="", Double_t threshold=0.05)
virtual TObject * Remove(TObject *obj)
Remove object from the list.
LVector boost(const LVector &v, const BoostVector &b)
Boost a generic Lorentz Vector class using a generic 3D Vector class describing the boost The only re...
const char * Deconvolution(Double_t *source, const Double_t *response, Int_t ssize, Int_t numberIterations, Int_t numberRepetitions, Double_t boost)
static void SetAverageWindow(Int_t w=3)
static Int_t fgAverageWindow
virtual const char * GetName() const
Returns name of object.
virtual void SetMarkerStyle(Style_t mstyle=1)
static void SetDeconIterations(Int_t n=3)
virtual void SetMarkerSize(Size_t msize=1)
A PolyMarker is defined by an array on N points in a 2-D space.
virtual TH1 * Background(const TH1 *hist, Int_t niter=20, Option_t *option="")
static Int_t fgIterations
ClassImp(TMCParticle) void TMCParticle printf(": p=(%7.3f,%7.3f,%9.3f) ;", fPx, fPy, fPz)
void SetResolution(Double_t resolution=1)
Advanced Spectra Processing.
Int_t GetLast() const
Return last bin on the axis i.e.
virtual void Print(Option_t *option="") const
Print TNamed name and title.
virtual void Add(TObject *obj)
#define dest(otri, vertexptr)
Bool_t Contains(const char *pat, ECaseCompare cmp=kExact) const
static Int_t StaticSearch(const TH1 *hist, Double_t sigma=2, Option_t *option="goff", Double_t threshold=0.05)
Double_t Sqrt(Double_t x)
const char * SmoothMarkov(Double_t *source, Int_t ssize, Int_t averWindow)
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)
virtual void Warning(const char *method, const char *msgfmt,...) const
Issue warning message.