87 mz_array->data.resize(spectrum->getMZArray()->data.size());
88 intensity_array->data.resize(spectrum->getMZArray()->data.size());
91 bool ret_val = filter(
92 spectrum->getMZArray()->data.begin(),
93 spectrum->getMZArray()->data.end(),
94 spectrum->getIntensityArray()->data.begin(),
95 mz_array->data.begin(), intensity_array->data.begin()
98 spectrum->setMZArray(mz_array);
99 spectrum->setIntensityArray(intensity_array);
111 rt_array->data.resize(chromatogram->getTimeArray()->data.size());
112 intensity_array->data.resize(chromatogram->getTimeArray()->data.size());
115 bool ret_val = filter(
116 chromatogram->getTimeArray()->data.begin(),
117 chromatogram->getTimeArray()->data.end(),
118 chromatogram->getIntensityArray()->data.begin(),
119 rt_array->data.begin(), intensity_array->data.begin()
122 chromatogram->setTimeArray(rt_array);
123 chromatogram->setIntensityArray(intensity_array);
132 template <
typename ConstIterT,
typename IterT>
134 ConstIterT mz_in_start,
135 ConstIterT mz_in_end,
136 ConstIterT int_in_start,
140 bool found_signal =
false;
142 ConstIterT mz_it = mz_in_start;
143 ConstIterT int_it = int_in_start;
144 for (; mz_it != mz_in_end; mz_it++, int_it++)
147 if (use_ppm_tolerance_)
149 initialize((*mz_it) * ppm_tolerance_ * 10e-6, spacing_, ppm_tolerance_, use_ppm_tolerance_ );
152 double new_int = integrate_(mz_it, int_it, mz_in_start, mz_in_end);
160 if (fabs(new_int) > 0) found_signal =
true;
165 void initialize(
double gaussian_width,
double spacing,
double ppm_tolerance,
bool use_ppm_tolerance);
181 template <
typename InputPeakIterator>
182 double integrate_(InputPeakIterator x , InputPeakIterator y , InputPeakIterator first, InputPeakIterator last)
187 Size middle = coeffs_.size();
189 double start_pos = (( (*x) - (middle * spacing_)) > (*first)) ? ((*x) - (middle * spacing_)) : (*first);
190 double end_pos = (( (*x) + (middle * spacing_)) < (*(last - 1))) ? ((*x) + (middle * spacing_)) : (*(last - 1));
192 InputPeakIterator help_x = x;
193 InputPeakIterator help_y = y;
194 #ifdef DEBUG_FILTERING 196 std::cout <<
"integrate from middle to start_pos " << *help_x <<
" until " << start_pos << std::endl;
200 while ((help_x != first) && (*(help_x - 1) > start_pos))
203 double distance_in_gaussian = fabs(*x - *help_x);
204 Size left_position = (
Size)floor(distance_in_gaussian / spacing_);
207 for (
int j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
209 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
215 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
223 Size right_position = left_position + 1;
224 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
226 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
227 : coeffs_[left_position];
228 #ifdef DEBUG_FILTERING 230 std::cout <<
"distance_in_gaussian " << distance_in_gaussian << std::endl;
231 std::cout <<
" right_position " << right_position << std::endl;
232 std::cout <<
" left_position " << left_position << std::endl;
233 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
234 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
235 std::cout <<
"interpolated value left " << coeffs_right << std::endl;
240 distance_in_gaussian = fabs((*x) - (*(help_x - 1)));
241 left_position = (
Size)floor(distance_in_gaussian / spacing_);
244 for (
UInt j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
246 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
252 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
260 right_position = left_position + 1;
261 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
262 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
263 : coeffs_[left_position];
264 #ifdef DEBUG_FILTERING 266 std::cout <<
" help_x-1 " << *(help_x - 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
267 std::cout <<
" right_position " << right_position << std::endl;
268 std::cout <<
" left_position " << left_position << std::endl;
269 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
270 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
271 std::cout <<
"interpolated value right " << coeffs_left << std::endl;
273 std::cout <<
" intensity " << fabs(*(help_x - 1) - (*help_x)) / 2. <<
" * " << *(help_y - 1) <<
" * " << coeffs_left <<
" + " << *help_y <<
"* " << coeffs_right
278 norm += fabs((*(help_x - 1)) - (*help_x)) / 2. * (coeffs_left + coeffs_right);
280 v += fabs((*(help_x - 1)) - (*help_x)) / 2. * (*(help_y - 1) * coeffs_left + (*help_y) * coeffs_right);
289 #ifdef DEBUG_FILTERING 291 std::cout <<
"integrate from middle to endpos " << *help_x <<
" until " << end_pos << std::endl;
294 while ((help_x != (last - 1)) && (*(help_x + 1) < end_pos))
297 double distance_in_gaussian = fabs((*x) - (*help_x));
298 int left_position = (
UInt)floor(distance_in_gaussian / spacing_);
301 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
303 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
309 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
316 Size right_position = left_position + 1;
317 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
318 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
319 : coeffs_[left_position];
321 #ifdef DEBUG_FILTERING 323 std::cout <<
" help " << *help_x <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
324 std::cout <<
" left_position " << left_position << std::endl;
325 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
326 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
327 std::cout <<
"interpolated value left " << coeffs_left << std::endl;
331 distance_in_gaussian = fabs((*x) - (*(help_x + 1)));
332 left_position = (
UInt)floor(distance_in_gaussian / spacing_);
335 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
337 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
343 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
351 right_position = left_position + 1;
352 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
353 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
354 : coeffs_[left_position];
355 #ifdef DEBUG_FILTERING 357 std::cout <<
" (help + 1) " << *(help_x + 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
358 std::cout <<
" left_position " << left_position << std::endl;
359 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
360 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
361 std::cout <<
"interpolated value right " << coeffs_right << std::endl;
363 std::cout <<
" intensity " << fabs(*help_x - *(help_x + 1)) / 2.
364 <<
" * " << *help_y <<
" * " << coeffs_left <<
" + " << *(help_y + 1)
365 <<
"* " << coeffs_right
368 norm += fabs((*help_x) - (*(help_x + 1)) ) / 2. * (coeffs_left + coeffs_right);
370 v += fabs((*help_x) - (*(help_x + 1)) ) / 2. * ((*help_y) * coeffs_left + (*(help_y + 1)) * coeffs_right);
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:236
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:156
bool use_ppm_tolerance_
Definition: GaussFilterAlgorithm.h:177
std::vector< double > coeffs_
Coefficients.
Definition: GaussFilterAlgorithm.h:170
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:80
The datastructures used by the OpenSwath interfaces.
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:72
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:46
double integrate_(InputPeakIterator x, InputPeakIterator y, InputPeakIterator first, InputPeakIterator last)
Computes the convolution of the raw data at position x and the gaussian kernel.
Definition: GaussFilterAlgorithm.h:182
double spacing_
The spacing of the pre-tabulated kernel coefficients.
Definition: GaussFilterAlgorithm.h:174
bool filter(OpenMS::Interfaces::SpectrumPtr spectrum)
Smoothes an Spectrum containing profile data.
Definition: GaussFilterAlgorithm.h:82
This class represents a Gaussian lowpass-filter which works on uniform as well as on non-uniform prof...
Definition: GaussFilterAlgorithm.h:70
double sigma_
The standard derivation .
Definition: GaussFilterAlgorithm.h:172
bool filter(ConstIterT mz_in_start, ConstIterT mz_in_end, ConstIterT int_in_start, IterT mz_out, IterT int_out)
Smoothes an two data arrays containing data.
Definition: GaussFilterAlgorithm.h:133
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
double norm(T beg, T end)
compute the norm of the vector
Definition: StatsHelpers.h:57
bool filter(OpenMS::Interfaces::ChromatogramPtr chromatogram)
Smoothes an Chromatogram containing profile data.
Definition: GaussFilterAlgorithm.h:106
double ppm_tolerance_
Definition: GaussFilterAlgorithm.h:178