88 mz_array->data.resize(spectrum->getMZArray()->data.size());
89 intensity_array->data.resize(spectrum->getMZArray()->data.size());
92 bool ret_val = filter(
93 spectrum->getMZArray()->data.begin(),
94 spectrum->getMZArray()->data.end(),
95 spectrum->getIntensityArray()->data.begin(),
96 mz_array->data.begin(), intensity_array->data.begin()
99 spectrum->setMZArray(mz_array);
100 spectrum->setIntensityArray(intensity_array);
112 rt_array->data.resize(chromatogram->getTimeArray()->data.size());
113 intensity_array->data.resize(chromatogram->getTimeArray()->data.size());
116 bool ret_val = filter(
117 chromatogram->getTimeArray()->data.begin(),
118 chromatogram->getTimeArray()->data.end(),
119 chromatogram->getIntensityArray()->data.begin(),
120 rt_array->data.begin(), intensity_array->data.begin()
123 chromatogram->setTimeArray(rt_array);
124 chromatogram->setIntensityArray(intensity_array);
133 template <
typename ConstIterT,
typename IterT>
135 ConstIterT mz_in_start,
136 ConstIterT mz_in_end,
137 ConstIterT int_in_start,
141 bool found_signal =
false;
143 ConstIterT mz_it = mz_in_start;
144 ConstIterT int_it = int_in_start;
145 for (; mz_it != mz_in_end; mz_it++, int_it++)
148 if (use_ppm_tolerance_)
150 initialize(
Math::ppmToMass(ppm_tolerance_, *mz_it), spacing_, ppm_tolerance_, use_ppm_tolerance_);
153 double new_int = integrate_(mz_it, int_it, mz_in_start, mz_in_end);
161 if (fabs(new_int) > 0) found_signal =
true;
166 void initialize(
double gaussian_width,
double spacing,
double ppm_tolerance,
bool use_ppm_tolerance);
182 template <
typename InputPeakIterator>
183 double integrate_(InputPeakIterator x , InputPeakIterator y , InputPeakIterator first, InputPeakIterator last)
188 Size middle = coeffs_.size();
190 double start_pos = (( (*x) - (middle * spacing_)) > (*first)) ? ((*x) - (middle * spacing_)) : (*first);
191 double end_pos = (( (*x) + (middle * spacing_)) < (*(last - 1))) ? ((*x) + (middle * spacing_)) : (*(last - 1));
193 InputPeakIterator help_x = x;
194 InputPeakIterator help_y = y;
195 #ifdef DEBUG_FILTERING
197 std::cout <<
"integrate from middle to start_pos " << *help_x <<
" until " << start_pos << std::endl;
201 while ((help_x != first) && (*(help_x - 1) > start_pos))
204 double distance_in_gaussian = fabs(*x - *help_x);
205 Size left_position = (
Size)floor(distance_in_gaussian / spacing_);
208 for (
int j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
210 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
216 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
224 Size right_position = left_position + 1;
225 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
227 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
228 : coeffs_[left_position];
229 #ifdef DEBUG_FILTERING
231 std::cout <<
"distance_in_gaussian " << distance_in_gaussian << std::endl;
232 std::cout <<
" right_position " << right_position << std::endl;
233 std::cout <<
" left_position " << left_position << std::endl;
234 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
235 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
236 std::cout <<
"interpolated value left " << coeffs_right << std::endl;
241 distance_in_gaussian = fabs((*x) - (*(help_x - 1)));
242 left_position = (
Size)floor(distance_in_gaussian / spacing_);
245 for (
UInt j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
247 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
253 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
261 right_position = left_position + 1;
262 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
263 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
264 : coeffs_[left_position];
265 #ifdef DEBUG_FILTERING
267 std::cout <<
" help_x-1 " << *(help_x - 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
268 std::cout <<
" right_position " << right_position << std::endl;
269 std::cout <<
" left_position " << left_position << std::endl;
270 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
271 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
272 std::cout <<
"interpolated value right " << coeffs_left << std::endl;
274 std::cout <<
" intensity " << fabs(*(help_x - 1) - (*help_x)) / 2. <<
" * " << *(help_y - 1) <<
" * " << coeffs_left <<
" + " << *help_y <<
"* " << coeffs_right
279 norm += fabs((*(help_x - 1)) - (*help_x)) / 2. * (coeffs_left + coeffs_right);
281 v += fabs((*(help_x - 1)) - (*help_x)) / 2. * (*(help_y - 1) * coeffs_left + (*help_y) * coeffs_right);
290 #ifdef DEBUG_FILTERING
292 std::cout <<
"integrate from middle to endpos " << *help_x <<
" until " << end_pos << std::endl;
295 while ((help_x != (last - 1)) && (*(help_x + 1) < end_pos))
298 double distance_in_gaussian = fabs((*x) - (*help_x));
299 int left_position = (
UInt)floor(distance_in_gaussian / spacing_);
302 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
304 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
310 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
317 Size right_position = left_position + 1;
318 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
319 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
320 : coeffs_[left_position];
322 #ifdef DEBUG_FILTERING
324 std::cout <<
" help " << *help_x <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
325 std::cout <<
" left_position " << left_position << std::endl;
326 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
327 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
328 std::cout <<
"interpolated value left " << coeffs_left << std::endl;
332 distance_in_gaussian = fabs((*x) - (*(help_x + 1)));
333 left_position = (
UInt)floor(distance_in_gaussian / spacing_);
336 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
338 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
344 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
352 right_position = left_position + 1;
353 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
354 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
355 : coeffs_[left_position];
356 #ifdef DEBUG_FILTERING
358 std::cout <<
" (help + 1) " << *(help_x + 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
359 std::cout <<
" left_position " << left_position << std::endl;
360 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
361 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
362 std::cout <<
"interpolated value right " << coeffs_right << std::endl;
364 std::cout <<
" intensity " << fabs(*help_x - *(help_x + 1)) / 2.
365 <<
" * " << *help_y <<
" * " << coeffs_left <<
" + " << *(help_y + 1)
366 <<
"* " << coeffs_right
369 norm += fabs((*help_x) - (*(help_x + 1)) ) / 2. * (coeffs_left + coeffs_right);
371 v += fabs((*help_x) - (*(help_x + 1)) ) / 2. * ((*help_y) * coeffs_left + (*(help_y + 1)) * coeffs_right);
This class represents a Gaussian lowpass-filter which works on uniform as well as on non-uniform prof...
Definition: GaussFilterAlgorithm.h:72
std::vector< double > coeffs_
Coefficients.
Definition: GaussFilterAlgorithm.h:171
GaussFilterAlgorithm()
Constructor.
void initialize(double gaussian_width, double spacing, double ppm_tolerance, bool use_ppm_tolerance)
double sigma_
The standard derivation .
Definition: GaussFilterAlgorithm.h:173
bool filter(ConstIterT mz_in_start, ConstIterT mz_in_end, ConstIterT int_in_start, IterT mz_out, IterT int_out)
Smoothes two data arrays.
Definition: GaussFilterAlgorithm.h:134
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:183
double spacing_
The spacing of the pre-tabulated kernel coefficients.
Definition: GaussFilterAlgorithm.h:175
double ppm_tolerance_
Definition: GaussFilterAlgorithm.h:179
virtual ~GaussFilterAlgorithm()
Destructor.
bool use_ppm_tolerance_
Definition: GaussFilterAlgorithm.h:178
bool filter(OpenMS::Interfaces::SpectrumPtr spectrum)
Smoothes an Spectrum containing profile data.
Definition: GaussFilterAlgorithm.h:83
bool filter(OpenMS::Interfaces::ChromatogramPtr chromatogram)
Smoothes an Chromatogram containing profile data.
Definition: GaussFilterAlgorithm.h:107
unsigned int UInt
Unsigned integer type.
Definition: Types.h:94
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:127
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:156
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:80
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:236
The datastructures used by the OpenSwath interfaces.
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:73
T ppmToMass(T ppm, T mz_ref)
Compute the mass diff in [Th], given a ppm value and a reference point.
Definition: MathFunctions.h:335
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:48
double norm(T beg, T end)
compute the Euclidean norm of the vector
Definition: StatsHelpers.h:57