69 const int PEAK_WINDOW = 1024;
71 int i=0, j=0, numberIterations = (
int)(7 *
sigma + 0.5);
73 int k=0, lindex=0, posit=0, imin=0, imax=0, jmin=0, jmax=0, lh_gold=0, priz=0;
74 double lda=0, ldb=0, ldc=0, area=0,
maximum=0, maximum_decon=0;
75 int xmin=0, xmax=0,
l=0, peak_index = 0,
w=0;
76 int size_ext =
ssize + 2 * numberIterations, shift = numberIterations, bw = 2;
78 double nom=0, nip=0, nim=0, sp=0, sm=0, plocha = 0;
79 double m0low=0,m1low=0,m2low=0,l0low=0,l1low=0,detlow=0,av=0,men=0;
81 log->error(
"SearchHighRes: invalid sigma {}, must be greater than or equal to 1",
sigma);
85 if(threshold<=0 || threshold>=100){
86 log->error(
"SearchHighRes: invalid threshold {}, must be positive and less than 100",
threshold);
91 if (j >= PEAK_WINDOW / 2) {
92 log->error(
"SearchHighRes: too large sigma: j={}",j);
98 log->error(
"SearchHighRes: averaging window must be positive, got {}",
averWindow);
104 if(
ssize < 2 * numberIterations + 1){
105 log->error(
"SearchHighRes: too large clipping window: {}",
ssize);
112 for(i = 0;i <
k;i++){
114 m0low += 1,m1low +=
a,m2low += a *
a,l0low +=
b,l1low += a *
b;
116 detlow = m0low * m2low - m1low * m1low;
118 l1low = (-l0low * m1low + l1low * m0low) / detlow;
132 double *working_space =
new double [7 * (
ssize + i)];
133 for (j=0;j<7 * (
ssize + i);j++) working_space[j] = 0;
134 for(i = 0; i < size_ext; i++){
137 working_space[i + size_ext] =
source[0] + l1low *
a;
138 if(working_space[i + size_ext] < 0)
139 working_space[i + size_ext]=0;
142 else if(i >=
ssize + shift){
143 a = i - (
ssize - 1 + shift);
145 if(working_space[i + size_ext] < 0)
146 working_space[i + size_ext]=0;
150 working_space[i + size_ext] =
source[i - shift];
154 for(i = 1; i <= numberIterations; i++){
155 for(j = i; j < size_ext - i; j++){
157 a = working_space[size_ext + j];
158 b = (working_space[size_ext + j - i] + working_space[size_ext + j + i]) / 2.0;
166 a = working_space[size_ext + j];
169 for (
w = j - bw;
w <= j + bw;
w++){
170 if (
w >= 0 &&
w < size_ext){
171 av += working_space[size_ext +
w];
178 for (
w = j - i - bw;
w <= j - i + bw;
w++){
179 if (
w >= 0 &&
w < size_ext){
180 b += working_space[size_ext +
w];
187 for (
w = j + i - bw;
w <= j + i + bw;
w++){
188 if (
w >= 0 &&
w < size_ext){
189 c += working_space[size_ext +
w];
200 for(j = i; j < size_ext - i; j++)
201 working_space[size_ext + j] = working_space[j];
203 for(j = 0;j < size_ext; j++){
208 working_space[size_ext + j] =
b - working_space[size_ext + j];
211 else if(j >=
ssize + shift){
212 a = j - (
ssize - 1 + shift);
215 working_space[size_ext + j] = b - working_space[size_ext + j];
219 working_space[size_ext + j] =
source[j - shift] - working_space[size_ext + j];
222 for(j = 0;j < size_ext; j++){
223 if(working_space[size_ext + j] < 0) working_space[size_ext + j] = 0;
227 for(i = 0; i < size_ext; i++){
228 working_space[i + 6*size_ext] = working_space[i + size_ext];
232 for(j = 0; j < size_ext; j++)
233 working_space[2 * size_ext + j] = working_space[size_ext + j];
234 xmin = 0,xmax = size_ext - 1;
235 for(i = 0, maxch = 0; i < size_ext; i++){
236 working_space[i] = 0;
237 if(maxch < working_space[2 * size_ext + i])
238 maxch = working_space[2 * size_ext + i];
239 plocha += working_space[2 * size_ext + i];
242 delete [] working_space;
247 working_space[xmin] = 1;
248 for(i = xmin; i < xmax; i++){
249 nip = working_space[2 * size_ext + i] / maxch;
250 nim = working_space[2 * size_ext + i + 1] / maxch;
254 a = working_space[2 * size_ext + xmax] / maxch;
257 a = working_space[2 * size_ext + i +
l] / maxch;
269 if((i -
l + 1) < xmin)
270 a = working_space[2 * size_ext + xmin] / maxch;
273 a = working_space[2 * size_ext + i -
l + 1] / maxch;
287 a = working_space[i + 1] = working_space[i] *
a;
290 for(i = xmin; i <= xmax; i++){
291 working_space[i] = working_space[i] / nom;
293 for(j = 0; j < size_ext; j++)
294 working_space[size_ext + j] = working_space[j] * plocha;
295 for(j = 0; j < size_ext; j++){
296 working_space[2 * size_ext + j] = working_space[size_ext + j];
299 for(i = 1; i <= numberIterations; i++){
300 for(j = i; j < size_ext - i; j++){
301 a = working_space[size_ext + j];
302 b = (working_space[size_ext + j - i] + working_space[size_ext + j + i]) / 2.0;
305 working_space[j] =
a;
307 for(j = i; j < size_ext - i; j++)
308 working_space[size_ext + j] = working_space[j];
310 for(j = 0; j < size_ext; j++){
311 working_space[size_ext + j] = working_space[2 * size_ext + j] - working_space[size_ext + j];
321 for(i = 0; i < size_ext; i++){
322 lda = (double)i - 3 *
sigma;
324 j = (
int)(1000 * exp(-lda));
329 working_space[i] = lda;
337 for(i = 0; i < size_ext; i++)
338 working_space[2 * size_ext + i] = fabs(working_space[size_ext + i]);
345 for(i = imin; i <= imax; i++){
350 jmax = lh_gold - 1 - i;
351 if(jmax > (lh_gold - 1))
354 for(j = jmin;j <= jmax; j++){
355 ldb = working_space[j];
356 ldc = working_space[i + j];
357 lda = lda + ldb * ldc;
359 working_space[size_ext + i - imin] = lda;
363 imin = -i,imax = size_ext + i - 1;
364 for(i = imin; i <= imax; i++){
366 for(j = 0; j <= (lh_gold - 1); j++){
367 ldb = working_space[j];
369 if(k >= 0 && k < size_ext){
370 ldc = working_space[2 * size_ext +
k];
371 lda = lda + ldb * ldc;
375 working_space[4 * size_ext + i - imin] = lda;
378 for(i = imin; i <= imax; i++)
379 working_space[2 * size_ext + i - imin] = working_space[4 * size_ext + i - imin];
381 for(i = 0; i < size_ext; i++)
382 working_space[i] = 1;
385 for(i = 0; i < size_ext; i++){
386 if(fabs(working_space[2 * size_ext + i]) > 0.00001 && fabs(working_space[i]) > 0.00001){
394 if(jmax > (size_ext - 1 - i))
397 for(j = jmin; j <= jmax; j++){
398 ldb = working_space[j + lh_gold - 1 + size_ext];
399 ldc = working_space[i + j];
400 lda = lda + ldb * ldc;
402 ldb = working_space[2 * size_ext + i];
409 ldb = working_space[i];
411 working_space[3 * size_ext + i] = lda;
414 for(i = 0; i < size_ext; i++){
415 working_space[i] = working_space[3 * size_ext + i];
419 for(i=0;i<size_ext;i++){
420 lda = working_space[i];
423 working_space[size_ext + j] = lda;
426 maximum = 0, maximum_decon = 0;
428 for(i = 0; i < size_ext - j; i++){
429 if(i >= shift && i <
ssize + shift){
430 working_space[i] = area * working_space[size_ext + i + j];
431 if(maximum_decon < working_space[i])
432 maximum_decon = working_space[i];
433 if(
maximum < working_space[6 * size_ext + i])
434 maximum = working_space[6 * size_ext + i];
438 working_space[i] = 0;
446 for(i = 1; i < size_ext - 1; i++){
447 if(working_space[i] > working_space[i - 1] && working_space[i] > working_space[i + 1]){
448 if(i >= shift && i <
ssize + shift){
449 if(working_space[i] > lda*maximum_decon && working_space[6 * size_ext + i] >
threshold *
maximum / 100.0){
450 for(j = i - 1, a = 0, b = 0; j <= i + 1; j++){
451 a += (double)(j - shift) * working_space[j];
452 b += working_space[j];
466 for(j = 0, priz = 0; j < peak_index && priz == 0; j++){
467 if(working_space[6 * size_ext + shift + (
int)
a] > working_space[6 * size_ext + shift + (
int)
fPositionX[j]])
477 for(k = peak_index; k >= j; k--){
493 delete [] working_space;
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a