OpenMS
TOFCalibration.h
Go to the documentation of this file.
1// Copyright (c) 2002-2023, The OpenMS Team -- EKU Tuebingen, ETH Zurich, and FU Berlin
2// SPDX-License-Identifier: BSD-3-Clause
3//
4// --------------------------------------------------------------------------
5// $Maintainer: Timo Sachsenberg $
6// $Authors: $
7// --------------------------------------------------------------------------
8
9#pragma once
10
16
19
20#include <vector>
21#include <map>
22
23//#define DEBUG_CALIBRATION
24namespace OpenMS
25{
40 class OPENMS_DLLAPI TOFCalibration :
42 public ProgressLogger
43 {
44public:
45
48
50 ~TOFCalibration() override;
51
52
53 /*
54 @ brief Apply the external calibration using raw calibrant spectra.
55
56 @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
57
58 */
59 void pickAndCalibrate(PeakMap & calib_spectra, PeakMap & exp, std::vector<double> & exp_masses);
60
61 /*
62 @ brief Apply the external calibration using picked calibrant spectra.
63
64 @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
65
66 */
67 void calibrate(PeakMap & calib_spectra, PeakMap & exp, std::vector<double> & exp_masses);
68
70 inline const std::vector<double> & getML1s() const {return ml1s_; }
72 inline void setML1s(const std::vector<double> & ml1s)
73 {
74 ml1s_ = ml1s;
75 }
76
78 inline const std::vector<double> & getML2s() const {return ml2s_; }
80 inline void setML2s(const std::vector<double> & ml2s)
81 {
82 ml2s_ = ml2s;
83 }
84
86 inline const std::vector<double> & getML3s() const {return ml3s_; }
88 inline void setML3s(const std::vector<double> & ml3s)
89 {
90 ml3s_ = ml3s;
91 }
92
93private:
96
97
99 std::vector<double> exp_masses_;
100
102 std::map<double, std::vector<double> > errors_;
103
105 std::vector<double> error_medians_;
106
108 std::vector<double> calib_masses_;
109
111 std::vector<double> ml1s_;
112 std::vector<double> ml2s_;
113 std::vector<double> ml3s_;
114
116 std::vector<double> coeff_quad_fit_;
117
119 double a_, b_, c_;
120
121
123 void calculateCalibCoeffs_(PeakMap & calib_peaks_ft);
124
125
127 void getMonoisotopicPeaks_(PeakMap & calib_peaks, std::vector<std::vector<unsigned int> > & monoiso_peaks);
128
139 void applyTOFConversion_(PeakMap & calib_spectra);
140
142 void matchMasses_(PeakMap & calib_peaks,
143 std::vector<std::vector<unsigned int> > & monoiso_peaks,
144 std::vector<unsigned int> & obs_masses,
145 std::vector<double> & exp_masses,
146 unsigned int idx);
147
149 inline double mQ_(double ft, unsigned int spec)
150 {
151 return coeff_quad_fit_[3 * spec] + ft * coeff_quad_fit_[3 * spec + 1] + ft * ft * coeff_quad_fit_[3 * spec + 2];
152 }
153
155 inline double mQAv_(double ft) const
156 {
157 return a_ + ft * b_ + ft * ft * c_;
158 }
159
162
165 };
166
167} // namespace OpenMS
168
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:66
In-Memory representation of a mass spectrometry run.
Definition: MSExperiment.h:46
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:27
This class implements an external calibration for TOF data using external calibrant spectra.
Definition: TOFCalibration.h:43
std::vector< double > ml1s_
calibration constants from the instrument needed for the conversion of the calibrant spectra
Definition: TOFCalibration.h:111
void setML1s(const std::vector< double > &ml1s)
mutable access to the first calibration constant
Definition: TOFCalibration.h:72
std::map< double, std::vector< double > > errors_
error in ppm after quadratic fit
Definition: TOFCalibration.h:102
double mQ_(double ft, unsigned int spec)
Calculate the mass value for a given flight time using the coefficients of the quadratic fit in a spe...
Definition: TOFCalibration.h:149
~TOFCalibration() override
Destructor.
std::vector< double > ml3s_
Definition: TOFCalibration.h:113
std::vector< double > error_medians_
median errors
Definition: TOFCalibration.h:105
void pickAndCalibrate(PeakMap &calib_spectra, PeakMap &exp, std::vector< double > &exp_masses)
PeakMap calib_peaks_ft_
the calibrant spectra still using flight times instead of m/z-values
Definition: TOFCalibration.h:95
void averageCoefficients_()
Average the coefficients of the quadratic fit.
void getMonoisotopicPeaks_(PeakMap &calib_peaks, std::vector< std::vector< unsigned int > > &monoiso_peaks)
determines the monoisotopic peaks
void matchMasses_(PeakMap &calib_peaks, std::vector< std::vector< unsigned int > > &monoiso_peaks, std::vector< unsigned int > &obs_masses, std::vector< double > &exp_masses, unsigned int idx)
determine the monoisotopic masses that have matching expected masses
double mQAv_(double ft) const
Calculate the mass value for a given flight time using the averaged coefficients of the quadratic fit...
Definition: TOFCalibration.h:155
TOFCalibration()
Default constructor.
void calibrate(PeakMap &calib_spectra, PeakMap &exp, std::vector< double > &exp_masses)
std::vector< double > exp_masses_
the expected calibrant masses
Definition: TOFCalibration.h:99
std::vector< double > coeff_quad_fit_
all coefficients of the quadratic fit
Definition: TOFCalibration.h:116
void averageErrors_()
Calculate the average errors of the reference masses over all scans.
void setML3s(const std::vector< double > &ml3s)
mutable access to the third calibration constant
Definition: TOFCalibration.h:88
void applyTOFConversion_(PeakMap &calib_spectra)
Applies the conversion from TOF to m/z-values to all peaks.
const std::vector< double > & getML2s() const
Non-mutable access to the second calibration constant.
Definition: TOFCalibration.h:78
const std::vector< double > & getML3s() const
Non-mutable access to the third calibration constant.
Definition: TOFCalibration.h:86
void calculateCalibCoeffs_(PeakMap &calib_peaks_ft)
Calculates the coefficients of the quadratic fit used for external calibration.
std::vector< double > calib_masses_
Definition: TOFCalibration.h:108
void setML2s(const std::vector< double > &ml2s)
mutable access to the second calibration constant
Definition: TOFCalibration.h:80
std::vector< double > ml2s_
Definition: TOFCalibration.h:112
double a_
mean coefficients
Definition: TOFCalibration.h:119
const std::vector< double > & getML1s() const
Non-mutable access to the first calibration constant.
Definition: TOFCalibration.h:70
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:22