62 mz_array->data.resize(spectrum->getMZArray()->data.size());
63 intensity_array->data.resize(spectrum->getMZArray()->data.size());
66 bool ret_val = filter(
67 spectrum->getMZArray()->data.begin(),
68 spectrum->getMZArray()->data.end(),
69 spectrum->getIntensityArray()->data.begin(),
70 mz_array->data.begin(), intensity_array->data.begin()
73 spectrum->setMZArray(mz_array);
74 spectrum->setIntensityArray(intensity_array);
86 rt_array->data.resize(chromatogram->getTimeArray()->data.size());
87 intensity_array->data.resize(chromatogram->getTimeArray()->data.size());
90 bool ret_val = filter(
91 chromatogram->getTimeArray()->data.begin(),
92 chromatogram->getTimeArray()->data.end(),
93 chromatogram->getIntensityArray()->data.begin(),
94 rt_array->data.begin(), intensity_array->data.begin()
97 chromatogram->setTimeArray(rt_array);
98 chromatogram->setIntensityArray(intensity_array);
107 template <
typename ConstIterT,
typename IterT>
109 ConstIterT mz_in_start,
110 ConstIterT mz_in_end,
111 ConstIterT int_in_start,
115 bool found_signal =
false;
117 ConstIterT mz_it = mz_in_start;
118 ConstIterT int_it = int_in_start;
119 for (; mz_it != mz_in_end; mz_it++, int_it++)
122 if (use_ppm_tolerance_)
124 initialize(
Math::ppmToMass(ppm_tolerance_, *mz_it), spacing_, ppm_tolerance_, use_ppm_tolerance_);
127 double new_int = integrate_(mz_it, int_it, mz_in_start, mz_in_end);
135 if (fabs(new_int) > 0) found_signal =
true;
140 void initialize(
double gaussian_width,
double spacing,
double ppm_tolerance,
bool use_ppm_tolerance);
156 template <
typename InputPeakIterator>
157 double integrate_(InputPeakIterator x , InputPeakIterator y , InputPeakIterator first, InputPeakIterator last)
162 Size middle = coeffs_.size();
164 double start_pos = (( (*x) - (middle * spacing_)) > (*first)) ? ((*x) - (middle * spacing_)) : (*first);
165 double end_pos = (( (*x) + (middle * spacing_)) < (*(last - 1))) ? ((*x) + (middle * spacing_)) : (*(last - 1));
167 InputPeakIterator help_x = x;
168 InputPeakIterator help_y = y;
169 #ifdef DEBUG_FILTERING
171 std::cout <<
"integrate from middle to start_pos " << *help_x <<
" until " << start_pos << std::endl;
175 while ((help_x != first) && (*(help_x - 1) > start_pos))
178 double distance_in_gaussian = fabs(*x - *help_x);
179 Size left_position = (
Size)floor(distance_in_gaussian / spacing_);
182 for (
int j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
184 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
190 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
198 Size right_position = left_position + 1;
199 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
201 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
202 : coeffs_[left_position];
203 #ifdef DEBUG_FILTERING
205 std::cout <<
"distance_in_gaussian " << distance_in_gaussian << std::endl;
206 std::cout <<
" right_position " << right_position << std::endl;
207 std::cout <<
" left_position " << left_position << std::endl;
208 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
209 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
210 std::cout <<
"interpolated value left " << coeffs_right << std::endl;
215 distance_in_gaussian = fabs((*x) - (*(help_x - 1)));
216 left_position = (
Size)floor(distance_in_gaussian / spacing_);
219 for (
UInt j = 0; ((j < 3) && (distance(first, help_x - j) >= 0)); ++j)
221 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
227 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
235 right_position = left_position + 1;
236 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
237 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
238 : coeffs_[left_position];
239 #ifdef DEBUG_FILTERING
241 std::cout <<
" help_x-1 " << *(help_x - 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
242 std::cout <<
" right_position " << right_position << std::endl;
243 std::cout <<
" left_position " << left_position << std::endl;
244 std::cout <<
"coeffs_ at left_position " << coeffs_[left_position] << std::endl;
245 std::cout <<
"coeffs_ at right_position " << coeffs_[right_position] << std::endl;
246 std::cout <<
"interpolated value right " << coeffs_left << std::endl;
248 std::cout <<
" intensity " << fabs(*(help_x - 1) - (*help_x)) / 2. <<
" * " << *(help_y - 1) <<
" * " << coeffs_left <<
" + " << *help_y <<
"* " << coeffs_right
253 norm += fabs((*(help_x - 1)) - (*help_x)) / 2. * (coeffs_left + coeffs_right);
255 v += fabs((*(help_x - 1)) - (*help_x)) / 2. * (*(help_y - 1) * coeffs_left + (*help_y) * coeffs_right);
264 #ifdef DEBUG_FILTERING
266 std::cout <<
"integrate from middle to endpos " << *help_x <<
" until " << end_pos << std::endl;
269 while ((help_x != (last - 1)) && (*(help_x + 1) < end_pos))
272 double distance_in_gaussian = fabs((*x) - (*help_x));
273 int left_position = (
UInt)floor(distance_in_gaussian / spacing_);
276 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
278 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
284 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
291 Size right_position = left_position + 1;
292 double d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
293 double coeffs_left = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
294 : coeffs_[left_position];
296 #ifdef DEBUG_FILTERING
298 std::cout <<
" help " << *help_x <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
299 std::cout <<
" left_position " << left_position << std::endl;
300 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
301 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
302 std::cout <<
"interpolated value left " << coeffs_left << std::endl;
306 distance_in_gaussian = fabs((*x) - (*(help_x + 1)));
307 left_position = (
UInt)floor(distance_in_gaussian / spacing_);
310 for (
int j = 0; ((j < 3) && (distance(help_x + j, last - 1) >= 0)); ++j)
312 if (((left_position - j) * spacing_ <= distance_in_gaussian) && ((left_position - j + 1) * spacing_ >= distance_in_gaussian))
318 if (((left_position + j) * spacing_ < distance_in_gaussian) && ((left_position + j + 1) * spacing_ < distance_in_gaussian))
326 right_position = left_position + 1;
327 d = fabs((left_position * spacing_) - distance_in_gaussian) / spacing_;
328 double coeffs_right = (right_position < middle) ? (1 - d) * coeffs_[left_position] + d * coeffs_[right_position]
329 : coeffs_[left_position];
330 #ifdef DEBUG_FILTERING
332 std::cout <<
" (help + 1) " << *(help_x + 1) <<
" distance_in_gaussian " << distance_in_gaussian << std::endl;
333 std::cout <<
" left_position " << left_position << std::endl;
334 std::cout <<
"coeffs_ at right_position " << coeffs_[left_position] << std::endl;
335 std::cout <<
"coeffs_ at left_position " << coeffs_[right_position] << std::endl;
336 std::cout <<
"interpolated value right " << coeffs_right << std::endl;
338 std::cout <<
" intensity " << fabs(*help_x - *(help_x + 1)) / 2.
339 <<
" * " << *help_y <<
" * " << coeffs_left <<
" + " << *(help_y + 1)
340 <<
"* " << coeffs_right
343 norm += fabs((*help_x) - (*(help_x + 1)) ) / 2. * (coeffs_left + coeffs_right);
345 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:46
std::vector< double > coeffs_
Coefficients.
Definition: GaussFilterAlgorithm.h:145
GaussFilterAlgorithm()
Constructor.
void initialize(double gaussian_width, double spacing, double ppm_tolerance, bool use_ppm_tolerance)
double sigma_
The standard derivation .
Definition: GaussFilterAlgorithm.h:147
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:108
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:157
double spacing_
The spacing of the pre-tabulated kernel coefficients.
Definition: GaussFilterAlgorithm.h:149
double ppm_tolerance_
Definition: GaussFilterAlgorithm.h:153
virtual ~GaussFilterAlgorithm()
Destructor.
bool use_ppm_tolerance_
Definition: GaussFilterAlgorithm.h:152
bool filter(OpenMS::Interfaces::SpectrumPtr spectrum)
Smoothes an Spectrum containing profile data.
Definition: GaussFilterAlgorithm.h:57
bool filter(OpenMS::Interfaces::ChromatogramPtr chromatogram)
Smoothes an Chromatogram containing profile data.
Definition: GaussFilterAlgorithm.h:81
unsigned int UInt
Unsigned integer type.
Definition: Types.h:64
size_t Size
Size type e.g. used as variable which can hold result of size()
Definition: Types.h:97
boost::shared_ptr< Chromatogram > ChromatogramPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:130
boost::shared_ptr< BinaryDataArray > BinaryDataArrayPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:54
boost::shared_ptr< Spectrum > SpectrumPtr
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:210
The datastructures used by the OpenSwath interfaces.
Definition: openms/include/OpenMS/INTERFACES/DataStructures.h:47
T ppmToMass(T ppm, T mz_ref)
Compute the mass diff in [Th], given a ppm value and a reference point.
Definition: MathFunctions.h:338
Main OpenMS namespace.
Definition: openswathalgo/include/OpenMS/OPENSWATHALGO/DATAACCESS/ISpectrumAccess.h:19
double norm(T beg, T end)
compute the Euclidean norm of the vector
Definition: StatsHelpers.h:31