Skip to content

Commit ad3290e

Browse files
committed
Improve batch peak fitting when doing batch activity - a little.
Slightly improve initial peak area, and now refit the peaks 3 times...
1 parent 104112f commit ad3290e

File tree

1 file changed

+24
-12
lines changed

1 file changed

+24
-12
lines changed

src/BatchPeak.cpp

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1023,20 +1023,29 @@ BatchPeak::BatchPeakFitResult fit_peaks_in_file( const std::string &exemplar_fil
10231023
// and continuum coefficients are reasonable starting values
10241024
if( peak.gausPeak() )
10251025
{
1026+
std::shared_ptr<PeakContinuum> continuum = peak.continuum();
1027+
assert( continuum );
1028+
if( continuum && continuum->isPolynomial() )
1029+
{
1030+
const PeakContinuum::OffsetType origType = continuum->type();
1031+
continuum->calc_linear_continuum_eqn( spec, peak.mean(), peak.lowerX(), peak.upperX(), 2, 2 );
1032+
continuum->setType( origType );
1033+
}//if( continuum )
1034+
10261035
const double mean = peak.mean(), fwhm = peak.fwhm();
10271036
const double data_area = spec->gamma_integral( mean - fwhm, mean + fwhm );
1037+
10281038
if( (data_area > 1) && (peak.amplitude() > data_area) )
10291039
{
1030-
peak.setAmplitude( 0.5*data_area );
1031-
1032-
std::shared_ptr<PeakContinuum> continuum = peak.continuum();
1033-
assert( continuum );
1034-
if( continuum )
1040+
double cont_area = continuum->offset_integral( mean - fwhm, mean + fwhm, spec );
1041+
if( (cont_area > 0.0) && (cont_area < data_area) )
1042+
{
1043+
peak.setAmplitude( data_area - cont_area );
1044+
}else
10351045
{
1036-
const PeakContinuum::OffsetType origType = continuum->type();
1037-
continuum->calc_linear_continuum_eqn( spec, peak.mean(), peak.lowerX(), peak.upperX(), 2, 2 );
1038-
continuum->setType( origType );
1039-
}//if( continuum )
1046+
peak.setAmplitude( 0.25*data_area );
1047+
}
1048+
10401049
}//if( exemplar peak is clearly much larger than data )
10411050
}//if( peak.gausPeak() )
10421051

@@ -1085,9 +1094,12 @@ BatchPeak::BatchPeakFitResult fit_peaks_in_file( const std::string &exemplar_fil
10851094
candidate_peaks, spec, {}, isRefit );
10861095

10871096
// Could re-fit the peaks again...
1088-
fit_peaks = fitPeaksInRange( lower_energy, uppper_energy, ncausalitysigma,
1089-
stat_threshold, hypothesis_threshold,
1090-
fit_peaks, spec, {}, true );
1097+
for( size_t i = 0; i < 3; ++i )
1098+
{
1099+
fit_peaks = fitPeaksInRange( lower_energy, uppper_energy, ncausalitysigma,
1100+
stat_threshold, hypothesis_threshold,
1101+
fit_peaks, spec, {}, true );
1102+
}
10911103

10921104
//cout << "Fit for the following " << fit_peaks.size() << " peaks (the exemplar file had "
10931105
//<< starting_peaks.size() << ") from the raw spectrum:"

0 commit comments

Comments
 (0)