libpappsomspp
Library for mass spectrometry
pappso::MzCalibrationModel1 Class Reference

#include <mzcalibrationmodel1.h>

Inheritance diagram for pappso::MzCalibrationModel1:
pappso::MzCalibrationInterface pappso::MzCalibrationModel1Cached

Public Member Functions

 MzCalibrationModel1 (double T1_frame, double T2_frame, double digitizerTimebase, double digitizerDelay, double C0, double C1, double C2, double C3, double C4, double T1_ref, double T2_ref, double dC1, double dC2)
 
virtual ~MzCalibrationModel1 ()
 
virtual double getMzFromTofIndex (quint32 tof_index) override
 get m/z from time of flight raw index More...
 
virtual quint32 getTofIndexFromMz (double mz) override
 get raw TOF index of a given m/z More...
 
- Public Member Functions inherited from pappso::MzCalibrationInterface
 MzCalibrationInterface (double digitizerTimebase, double digitizerDelay)
 
virtual ~MzCalibrationInterface ()
 
MzCalibrationInterfaceoperator= (const MzCalibrationInterface &other)
 
bool operator== (const MzCalibrationInterface &other) const
 
double getTofFromTofIndex (quint32 tof_index) const
 get time of flight from raw index More...
 
double getTofFromTofIndex (double tof_index) const
 get time of flight from double index More...
 

Additional Inherited Members

- Protected Attributes inherited from pappso::MzCalibrationInterface
double m_digitizerTimebase = 0
 
double m_digitizerDelay = 0
 
std::vector< double > m_mzCalibrationArr
 MZ calibration parameters. More...
 

Detailed Description

Todo:
write docs

Definition at line 40 of file mzcalibrationmodel1.h.

Constructor & Destructor Documentation

◆ MzCalibrationModel1()

MzCalibrationModel1::MzCalibrationModel1 ( double  T1_frame,
double  T2_frame,
double  digitizerTimebase,
double  digitizerDelay,
double  C0,
double  C1,
double  C2,
double  C3,
double  C4,
double  T1_ref,
double  T2_ref,
double  dC1,
double  dC2 
)

Default constructor

Definition at line 37 of file mzcalibrationmodel1.cpp.

50  : MzCalibrationInterface(digitizerTimebase, digitizerDelay)
51 {
52 
53  double temperature_correction =
54  dC1 * (T1_ref - T1_frame) + dC2 * (T2_ref - T2_frame);
55  temperature_correction = (double)1.0 + (temperature_correction / 1.0e6);
56 
57  // temperature compensation
58  C1 = C1 * temperature_correction;
59  C2 = C2 / temperature_correction;
60 
61 
62  m_mzCalibrationArr.clear();
63 
64  m_digitizerDelay = digitizerDelay;
65  m_digitizerTimebase = digitizerTimebase;
66 
67  m_mzCalibrationArr.push_back(C0);
68  m_mzCalibrationArr.push_back(std::sqrt(std::pow(10, 12) / C1));
69  m_mzCalibrationArr.push_back(C2);
70  m_mzCalibrationArr.push_back(C3);
71  m_mzCalibrationArr.push_back(C4);
72 }
MzCalibrationInterface(double digitizerTimebase, double digitizerDelay)
std::vector< double > m_mzCalibrationArr
MZ calibration parameters.

References pappso::MzCalibrationInterface::m_digitizerDelay, pappso::MzCalibrationInterface::m_digitizerTimebase, and pappso::MzCalibrationInterface::m_mzCalibrationArr.

◆ ~MzCalibrationModel1()

MzCalibrationModel1::~MzCalibrationModel1 ( )
virtual

Destructor

Definition at line 74 of file mzcalibrationmodel1.cpp.

75 {
76 }

Member Function Documentation

◆ getMzFromTofIndex()

double MzCalibrationModel1::getMzFromTofIndex ( quint32  tof_index)
overridevirtual

get m/z from time of flight raw index

Parameters
tof_indextime of flight
Returns
m/z value

Implements pappso::MzCalibrationInterface.

Reimplemented in pappso::MzCalibrationModel1Cached.

Definition at line 79 of file mzcalibrationmodel1.cpp.

80 {
81  double tof = ((double)tof_index * m_digitizerTimebase) + m_digitizerDelay;
82  // http://www.alglib.net/equations/polynomial.php
83  // http://www.alglib.net/translator/man/manual.cpp.html#sub_polynomialsolve
84  // https://math.stackexchange.com/questions/1291208/number-of-roots-of-a-polynomial-of-non-integer-degree
85  // https://www.google.com/url?sa=t&rct=j&q=&esrc=s&source=web&cd=2&ved=2ahUKEwiWhLOFxqrkAhVLxYUKHVqqDFcQFjABegQIAxAB&url=https%3A%2F%2Fkluge.in-chemnitz.de%2Fopensource%2Fspline%2Fexample_alglib.cpp&usg=AOvVaw0guGejJGPmkOVg48_GJYR8
86  // https://stackoverflow.com/questions/26091323/how-to-plot-a-function-curve-in-r
87  /*
88  * beware to put the function on a single line in R:
89 > eq <- function(m){ 1 + (sqrt((10^12)/670) * sqrt(m)) + (207.775676931964 * m)
90 + (59.2526676368822 * (m^1.5)) }
91 > eq <- function(m){ 313.577620892277 + (sqrt((10^12)/157424.07710945) *
92 sqrt(m)) + (0.000338743021989553 * m)
93 + (0 * (m^1.5)) }
94 > plot(eq(1:1000), type='l')
95 
96 
97 
98 > eq2 <- function(m2){ 1 + sqrt((10^12)/670) * m2 + 207.775676931964 * (m2^2)
99 + 59.2526676368822 * (m2^3) }
100 > plot(eq2(1:sqrt(1000)), type='l')
101 */
102  // How to Factor a Trinomial with Fractions as Coefficients
103 
104  // formula
105  // a = c0 = 1
106  // b = sqrt((10^12)/c1), c1 = 670 * m^0.5 (1/2)
107  // c = c2, c2 = 207.775676931964 * m
108  // d = c3, c3 = 59.2526676368822 * m^1.5 (3/2)
109  // double mz = 0;
110 
111 
112  /* transformation formula given by Bruker 29/8/2019 :
113  * x = m + dm
114  *
115  * time = m_mzCalibrationArr[0]
116  * + sqrt ((10^12)/m_mzCalibrationArr[1]) * x^0.5
117  * + m_mzCalibrationArr[2] * x
118  * + m_mzCalibrationArr[3] * x^1.5
119  */
120  std::vector<double> X;
121  X.push_back((m_mzCalibrationArr[0] - (double)tof));
122  X.push_back(m_mzCalibrationArr[1]);
123  if(m_mzCalibrationArr[2] != 0)
124  {
125  X.push_back(m_mzCalibrationArr[2]);
126  }
127  if(m_mzCalibrationArr[3] != 0)
128  {
129  X.push_back(m_mzCalibrationArr[3]);
130  // qDebug() << "m_mzCalibrationArr[3]=" << m_mzCalibrationArr[3];
131  }
132  else
133  {
134  // qDebug() << "m_mzCalibrationArr[3]=" << m_mzCalibrationArr[3];
135  }
136  // qDebug() << "polynom_array :";
137  /*
138  for(double arg : X)
139  {
140  qDebug() << arg;
141  }
142  */
143  alglib::real_1d_array polynom_array;
144  try
145  {
146  polynom_array.setcontent(X.size(), &(X[0]));
147  }
148  catch(alglib::ap_error &error)
149  {
150  // PolynomialSolve: A[N]=0
152  QObject::tr("ERROR in alglib::polynom_array.setcontent :\n%1")
153  .arg(error.msg.c_str()));
154  }
155 
156 
157  /*
158  alglib::polynomialsolve(
159 real_1d_array a,
160 ae_int_t n,
161 complex_1d_array& x,
162 polynomialsolverreport& rep,
163 const xparams _params = alglib::xdefault);
164 */
165  alglib::complex_1d_array m;
166  alglib::polynomialsolverreport rep;
167  // qDebug();
168  try
169  {
170  alglib::polynomialsolve(polynom_array, X.size() - 1, m, rep);
171  }
172  catch(alglib::ap_error &error)
173  {
174  qDebug() << " X.size() - 1 = " << X.size() - 1;
175  qDebug() << m_mzCalibrationArr[0];
176  qDebug() << m_mzCalibrationArr[1];
177  qDebug() << m_mzCalibrationArr[2];
178  qDebug() << m_mzCalibrationArr[3];
179 
180  // PolynomialSolve: A[N]=0
182  QObject::tr("ERROR in MzCalibrationModel1::getMzFromTofIndex, "
183  "alglib::polynomialsolve :\n%1")
184  .arg(error.msg.c_str()));
185  }
186 
187 
188  // qDebug();
189 
190  if(m.length() == 0)
191  {
192  throw pappso::PappsoException(QObject::tr(
193  "ERROR in MzCalibrationModel1::getMzFromTofIndex m.size() == 0"));
194  }
195  // qDebug();
196  if(m[0].y != 0)
197  {
199  QObject::tr("ERROR in MzCalibrationModel1::getMzFromTofIndex m[0].y!= "
200  "0 for tof index=%1")
201  .arg(tof_index));
202  }
203 
204  // qDebug() << "m.length()=" << m.length();
205  // qDebug() << "m1=" << pow(m[0].x, 2);
206  // qDebug() << "m2=" << pow(m[1].x, 2);
207  return (pow(m[0].x, 2) - m_mzCalibrationArr[4]);
208 }

References pappso::MzCalibrationInterface::m_digitizerDelay, pappso::MzCalibrationInterface::m_digitizerTimebase, pappso::MzCalibrationInterface::m_mzCalibrationArr, pappso::x, and pappso::y.

Referenced by pappso::MzCalibrationModel1Cached::getMzFromTofIndex().

◆ getTofIndexFromMz()

quint32 MzCalibrationModel1::getTofIndexFromMz ( double  mz)
overridevirtual

get raw TOF index of a given m/z

Parameters
mzthe mass to transform
Returns
integer x raw value

Implements pappso::MzCalibrationInterface.

Definition at line 211 of file mzcalibrationmodel1.cpp.

212 {
213  // formula
214  // a = c0 = 1
215  // b = sqrt((10^12)/c1), c1 = 670 * m^0.5 (1/2)
216  // c = c2, c2 = 207.775676931964 * m
217  // d = c3, c3 = 59.2526676368822 * m^1.5 (3/2)
218  qDebug() << "mz=" << mz;
219 
220  mz = mz + m_mzCalibrationArr[4]; // mz_corr
221 
222  double tof = m_mzCalibrationArr[0];
223  qDebug() << "tof ( m_mzCalibrationArr[0])=" << tof;
224  // TODO cache value of std::sqrt((std::pow(10, 12) / m_mzCalibrationArr[1]))
225  tof += m_mzCalibrationArr[1] * std::sqrt(mz);
226  qDebug() << "tof=" << tof;
227  tof += m_mzCalibrationArr[2] * mz;
228  qDebug() << "tof=" << tof;
229  tof += m_mzCalibrationArr[3] * std::pow(mz, 1.5);
230  qDebug() << "tof=" << tof;
231  tof -= m_digitizerDelay;
232  qDebug() << "tof=" << tof;
233  tof = tof / m_digitizerTimebase;
234  qDebug() << "index=" << tof;
235  return (quint32)std::round(tof);
236 }

References pappso::MzCalibrationInterface::m_digitizerDelay, pappso::MzCalibrationInterface::m_digitizerTimebase, pappso::MzCalibrationInterface::m_mzCalibrationArr, and pappso::mz.


The documentation for this class was generated from the following files: