- Timestamp:
- 02/04/13 12:18:37 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Mars/mcore/DrsCalib.h
r14619 r14865 278 278 }; 279 279 280 static Step AverageSteps(const std::vector<Step> &list, uint32_t n)280 static Step AverageSteps(const std::vector<Step>::iterator beg, const std::vector<Step>::iterator end) 281 281 { 282 282 Step rc; 283 for (auto it= list.begin(); it!=list.begin()+n; it++)283 for (auto it=beg; it!=end; it++) 284 284 { 285 285 rc.pos += it->pos; … … 288 288 } 289 289 290 rc.cnt = n;290 rc.cnt = end-beg; 291 291 292 292 rc.pos /= rc.cnt; … … 329 329 return Step(); 330 330 331 Step rc = AverageSteps(list ,list.size());;331 Step rc = AverageSteps(list.begin(), list.begin()+list.size());; 332 332 333 333 if (rc.avg==0) 334 334 return Step(); 335 335 336 // std::cout << " A0=" << rc.avg << " rms=" << rc.rms << std::endl; 336 337 if (rc.rms>5) 337 338 { 338 partial_sort(list.begin(), list.begin()+list.size()/2, 339 list.end(), Step::sort); 340 341 rc = AverageSteps(list, list.size()/2); 339 sort(list.begin(), list.end(), Step::sort); 340 341 //for (auto it=list.begin(); it!=list.end(); it++) 342 // std::cout << " " << it->avg << std::endl; 343 344 const Int_t skip = list.size()/10; 345 rc = AverageSteps(list.begin()+skip, list.begin()+list.size()-skip); 346 347 // std::cout << " A1=" << rc.avg << " rms=" << rc.rms << std::endl; 342 348 } 343 349 … … 387 393 std::vector<float> Ameas(p, p+roi); 388 394 389 std::vector<float> N1mean(roi); 390 for (size_t i=2; i<roi-2; i++) 391 { 392 N1mean[i] = (p[i-1] + p[i+1])/2.; 393 } 395 std::vector<float> diff(roi); 396 for (size_t i=1; i<roi-1; i++) 397 diff[i] = (p[i-1] + p[i+1])/2 - p[i]; 398 399 //std::vector<float> N1mean(roi); 400 //for (size_t i=1; i<roi-1; i++) 401 // N1mean[i] = (p[i-1] + p[i+1])/2; 394 402 395 403 const float fract = 0.8; 396 float x, xp, xpp;397 404 398 405 for (size_t i=0; i<roi-3; i++) 399 406 { 400 x = Ameas[i] - N1mean[i]; 401 if ( x > -5.) 407 if (diff[i]<5) 402 408 continue; 403 409 404 xp = Ameas[i+1] - N1mean[i+1]; 405 xpp = Ameas[i+2] - N1mean[i+2]; 406 407 if(Ameas[i+2] - (Ameas[i] + Ameas[i+3])/2. > 10.) 410 if (Ameas[i+2] - (Ameas[i] + Ameas[i+3])/2 > 10) 408 411 { 409 p[i+1]= (Ameas[i] + Ameas[i+3])/2.;410 p[i+2]= (Ameas[i] + Ameas[i+3])/2.;412 p[i+1]= (Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 413 p[i+2]= 2*(Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 411 414 412 415 i += 3; … … 414 417 continue; 415 418 } 416 if ( (xp > -2.*x*fract) && (xpp < -10.) ) 419 420 if ( (diff[i+1]<-diff[i]*fract*2) && (diff[i+2]>10) ) 417 421 { 418 p[i+1] = N1mean[i+1];419 N1mean[i+2] = (Ameas[i+1] - Ameas[i+3] / 2.);422 p[i+1] = (Ameas[i]+Ameas[i+2])/2; 423 diff[i+2] = (p[i+1] + Ameas[i+3])/2 - Ameas[i+2]; 420 424 421 425 i += 2; 422 426 } 423 } 424 } 427 428 // const float x = Ameas[i] - N1mean[i]; 429 // if (x > -5.) 430 // continue; 431 432 // if (Ameas[i+2] - (Ameas[i] + Ameas[i+3])/2. > 10.) 433 // { 434 // p[i+1]= (Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 435 // p[i+2]= 2*(Ameas[i+3] - Ameas[i])/3 + Ameas[i]; 436 // i += 3; 437 // continue; 438 // } 439 440 // const float xp = Ameas[i+1] - N1mean[i+1]; 441 // const float xpp = Ameas[i+2] - N1mean[i+2]; 442 443 // if ( (xp > -2.*x*fract) && (xpp < -10.) ) 444 // { 445 // p[i+1] = N1mean[i+1]; 446 // N1mean[i+2] = Ameas[i+1] - Ameas[i+3]/2; 447 // 448 // i += 2; 449 // } 450 } 451 } 452 } 453 454 static void RemoveSpikes3(float *vec, uint32_t roi)//from Werner 455 { 456 const float SingleCandidateTHR = -10.; 457 const float DoubleCandidateTHR = -5.; 458 459 const std::vector<float> src(vec, vec+roi); 460 461 std::vector<float> diff(roi); 462 for (size_t i=1; i<roi-1; i++) 463 diff[i] = src[i] - (src[i-1] + src[i+1])/2; 464 465 // find the spike and replace it by mean value of neighbors 466 for (unsigned int i=1; i<roi-3; i++) 467 { 468 // Speed up (no leading edge) 469 if (diff[i]>=DoubleCandidateTHR) 470 continue; 471 472 //bool checkDouble = false; 473 474 // a single spike candidate 475 if (diff[i]<SingleCandidateTHR) 476 { 477 // check consistency with a single channel spike 478 if (diff[i+1] > -1.6*diff[i]) 479 { 480 vec[i+1] = (src[i] + src[i+2]) / 2; 481 482 i += 2; 483 484 /*** NEW ***/ 485 continue; 486 /*** NEW ***/ 487 } 488 /* 489 else 490 { 491 // do nothing - not really a single spike, 492 // but check if it is a double 493 checkDouble = true; 494 }*/ 495 } 496 497 // a double spike candidate 498 //if (diff[i]>DoubleCandidateTHR || checkDouble == 1) 499 { 500 // check the consistency with a double spike 501 if ((diff[i+1] > -DoubleCandidateTHR) && 502 (diff[i+2] > -DoubleCandidateTHR)) 503 { 504 vec[i+1] = (src[i+3] - src[i])/3 + src[i]; 505 vec[i+2] = 2*(src[i+3] - src[i])/3 + src[i]; 506 507 //vec[i] = (src[i-1] + src[i+2]) / 2.; 508 //vec[i+1] = (src[i-1] + src[i+2]) / 2.; 509 510 //do not care about the next sample it was the spike 511 i += 3; 512 } 513 } 514 } 425 515 } 426 516
Note:
See TracChangeset
for help on using the changeset viewer.