OpenMS  2.7.0
TOFCalibration.h
Go to the documentation of this file.
1 // --------------------------------------------------------------------------
2 // OpenMS -- Open-Source Mass Spectrometry
3 // --------------------------------------------------------------------------
4 // Copyright The OpenMS Team -- Eberhard Karls University Tuebingen,
5 // ETH Zurich, and Freie Universitaet Berlin 2002-2021.
6 //
7 // This software is released under a three-clause BSD license:
8 // * Redistributions of source code must retain the above copyright
9 // notice, this list of conditions and the following disclaimer.
10 // * Redistributions in binary form must reproduce the above copyright
11 // notice, this list of conditions and the following disclaimer in the
12 // documentation and/or other materials provided with the distribution.
13 // * Neither the name of any author or any participating institution
14 // may be used to endorse or promote products derived from this software
15 // without specific prior written permission.
16 // For a full list of authors, refer to the file AUTHORS.
17 // --------------------------------------------------------------------------
18 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
19 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 // ARE DISCLAIMED. IN NO EVENT SHALL ANY OF THE AUTHORS OR THE CONTRIBUTING
22 // INSTITUTIONS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
25 // OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
26 // WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
27 // OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
28 // ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 //
30 // --------------------------------------------------------------------------
31 // $Maintainer: Timo Sachsenberg $
32 // $Authors: $
33 // --------------------------------------------------------------------------
34 
35 #pragma once
36 
42 
45 
46 #include <vector>
47 #include <map>
48 
49 //#define DEBUG_CALIBRATION
50 namespace OpenMS
51 {
66  class OPENMS_DLLAPI TOFCalibration :
67  public DefaultParamHandler,
68  public ProgressLogger
69  {
70 public:
71 
74 
76  ~TOFCalibration() override;
77 
78 
79  /*
80  @ brief Apply the external calibration using raw calibrant spectra.
81 
82  @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
83 
84  */
85  void pickAndCalibrate(PeakMap & calib_spectra, PeakMap & exp, std::vector<double> & exp_masses);
86 
87  /*
88  @ brief Apply the external calibration using picked calibrant spectra.
89 
90  @exception Exception::UnableToCalibrate is thrown if not enough reference masses are observed.
91 
92  */
93  void calibrate(PeakMap & calib_spectra, PeakMap & exp, std::vector<double> & exp_masses);
94 
96  inline const std::vector<double> & getML1s() const {return ml1s_; }
98  inline void setML1s(const std::vector<double> & ml1s)
99  {
100  ml1s_ = ml1s;
101  }
102 
104  inline const std::vector<double> & getML2s() const {return ml2s_; }
106  inline void setML2s(const std::vector<double> & ml2s)
107  {
108  ml2s_ = ml2s;
109  }
110 
112  inline const std::vector<double> & getML3s() const {return ml3s_; }
114  inline void setML3s(const std::vector<double> & ml3s)
115  {
116  ml3s_ = ml3s;
117  }
118 
119 private:
122 
123 
125  std::vector<double> exp_masses_;
126 
128  std::map<double, std::vector<double> > errors_;
129 
131  std::vector<double> error_medians_;
132 
134  std::vector<double> calib_masses_;
135 
137  std::vector<double> ml1s_;
138  std::vector<double> ml2s_;
139  std::vector<double> ml3s_;
140 
142  std::vector<double> coeff_quad_fit_;
143 
145  double a_, b_, c_;
146 
147 
149  void calculateCalibCoeffs_(PeakMap & calib_peaks_ft);
150 
151 
153  void getMonoisotopicPeaks_(PeakMap & calib_peaks, std::vector<std::vector<unsigned int> > & monoiso_peaks);
154 
165  void applyTOFConversion_(PeakMap & calib_spectra);
166 
168  void matchMasses_(PeakMap & calib_peaks,
169  std::vector<std::vector<unsigned int> > & monoiso_peaks,
170  std::vector<unsigned int> & obs_masses,
171  std::vector<double> & exp_masses,
172  unsigned int idx);
173 
175  inline double mQ_(double ft, unsigned int spec)
176  {
177  return coeff_quad_fit_[3 * spec] + ft * coeff_quad_fit_[3 * spec + 1] + ft * ft * coeff_quad_fit_[3 * spec + 2];
178  }
179 
181  inline double mQAv_(double ft)
182  {
183  return a_ + ft * b_ + ft * ft * c_;
184  }
185 
188 
191  };
192 
193 } // namespace OpenMS
194 
A base class for all classes handling default parameters.
Definition: DefaultParamHandler.h:93
In-Memory representation of a mass spectrometry experiment.
Definition: MSExperiment.h:80
Base class for all classes that want to report their progress.
Definition: ProgressLogger.h:55
This class implements an external calibration for TOF data using external calibrant spectra.
Definition: TOFCalibration.h:69
std::vector< double > ml1s_
calibration constants from the instrument needed for the conversion of the calibrant spectra
Definition: TOFCalibration.h:137
void setML1s(const std::vector< double > &ml1s)
mutable access to the first calibration constant
Definition: TOFCalibration.h:98
std::map< double, std::vector< double > > errors_
error in ppm after quadratic fit
Definition: TOFCalibration.h:128
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:175
~TOFCalibration() override
Destructor.
const std::vector< double > & getML2s() const
Non-mutable access to the second calibration constant.
Definition: TOFCalibration.h:104
std::vector< double > ml3s_
Definition: TOFCalibration.h:139
std::vector< double > error_medians_
median errors
Definition: TOFCalibration.h:131
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:121
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
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:125
std::vector< double > coeff_quad_fit_
all coefficients of the quadratic fit
Definition: TOFCalibration.h:142
double mQAv_(double ft)
Calculate the mass value for a given flight time using the averaged coefficients of the quadratic fit...
Definition: TOFCalibration.h:181
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:114
void applyTOFConversion_(PeakMap &calib_spectra)
Applies the conversion from TOF to m/z-values to all peaks.
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:134
void setML2s(const std::vector< double > &ml2s)
mutable access to the second calibration constant
Definition: TOFCalibration.h:106
const std::vector< double > & getML1s() const
Non-mutable access to the first calibration constant.
Definition: TOFCalibration.h:96
std::vector< double > ml2s_
Definition: TOFCalibration.h:138
double a_
mean coefficients
Definition: TOFCalibration.h:145
const std::vector< double > & getML3s() const
Non-mutable access to the third calibration constant.
Definition: TOFCalibration.h:112
Main OpenMS namespace.
Definition: FeatureDeconvolution.h:47