nmrspectrum.cpp
1 /***************************************************************************
2  Copyright (C) 2002-2015 Kentaro Kitagawa
3  kitagawa@phys.s.u-tokyo.ac.jp
4 
5  This program is free software; you can redistribute it and/or
6  modify it under the terms of the GNU Library General Public
7  License as published by the Free Software Foundation; either
8  version 2 of the License, or (at your option) any later version.
9 
10  You should have received a copy of the GNU Library General
11  Public License and a list of authors along with this program;
12  see the files COPYING and AUTHORS.
13 ***************************************************************************/
14 //---------------------------------------------------------------------------
15 #include "ui_nmrspectrumform.h"
16 #include "nmrspectrum.h"
17 #include "dmm.h"
18 #include "magnetps.h"
19 #include "qdppms.h"
20 
21 #include "nmrspectrumbase_impl.h"
22 
23 REGISTER_TYPE(XDriverList, NMRSpectrum, "NMR field-swept spectrum measurement");
24 
25 //---------------------------------------------------------------------------
26 XNMRSpectrum::XNMRSpectrum(const char *name, bool runtime,
27  Transaction &tr_meas, const shared_ptr<XMeasure> &meas) :
28  XNMRSpectrumBase<FrmNMRSpectrum>(name, runtime, ref(tr_meas), meas),
29  m_magnet(create<XItemNode<XDriverList, XMagnetPS, XDMM, XQDPPMS> >(
30  "MagnetPS", false, ref(tr_meas), meas->drivers(), true)),
31  m_centerFreq(create<XDoubleNode>("CenterFreq", false)),
32  m_resolution(create<XDoubleNode>("Resolution", false)),
33  m_minValue(create<XDoubleNode>("FieldMin", false)),
34  m_maxValue(create<XDoubleNode>("FieldMax", false)),
35  m_fieldFactor(create<XDoubleNode>("FieldFactor", false)),
36  m_residualField(create<XDoubleNode>("ResidualField", false)) {
37  connect(magnet());
38 
39  m_form->setWindowTitle(i18n("NMR Spectrum - ") + getLabel() );
40  iterate_commit([=](Transaction &tr){
41  tr[ *m_spectrum].setLabel(0, "Field [T]");
42  tr[ *tr[ *m_spectrum].axisx()->label()] = i18n("Field [T]");
43 
44  tr[ *centerFreq()] = 20;
45  tr[ *resolution()] = 0.001;
46  tr[ *fieldFactor()] = 1;
47  tr[ *maxValue()] = 5.0;
48  tr[ *minValue()] = 3.0;
49  });
50 
51  m_conUIs = {
52  xqcon_create<XQLineEditConnector>(m_centerFreq, m_form->m_edFreq),
53  xqcon_create<XQLineEditConnector>(m_resolution, m_form->m_edResolution),
54  xqcon_create<XQLineEditConnector>(m_minValue, m_form->m_edMin),
55  xqcon_create<XQLineEditConnector>(m_maxValue, m_form->m_edMax),
56  xqcon_create<XQLineEditConnector>(m_fieldFactor, m_form->m_edFieldFactor),
57  xqcon_create<XQLineEditConnector>(m_residualField, m_form->m_edResidual),
58  xqcon_create<XQComboBoxConnector>(m_magnet, m_form->m_cmbFieldEntry, ref(tr_meas)),
59  };
60 
61  iterate_commit([=](Transaction &tr){
62  tr[ *centerFreq()].onValueChanged().connect(m_lsnOnCondChanged);
63  tr[ *resolution()].onValueChanged().connect(m_lsnOnCondChanged);
64  tr[ *minValue()].onValueChanged().connect(m_lsnOnCondChanged);
65  tr[ *maxValue()].onValueChanged().connect(m_lsnOnCondChanged);
66  tr[ *fieldFactor()].onValueChanged().connect(m_lsnOnCondChanged);
67  tr[ *residualField()].onValueChanged().connect(m_lsnOnCondChanged);
68  });
69 }
70 bool
72  return (node == m_residualField.get()) || (node == m_fieldFactor.get()) || (node == m_resolution.get());
73 }
74 bool
75 XNMRSpectrum::checkDependencyImpl(const Snapshot &shot_this,
76  const Snapshot &shot_emitter, const Snapshot &shot_others,
77  XDriver *emitter) const {
78  shared_ptr<XMagnetPS> magnet__ = shot_this[ *magnet()];
79  shared_ptr<XDMM> dmm__ = shot_this[ *magnet()];
80  shared_ptr<XQDPPMS> ppms__ = shot_this[ *magnet()];
81  if( !(magnet__ || dmm__ || ppms__)) return false;
82  if(emitter == magnet__.get()) return false;
83  if(emitter == dmm__.get()) return false;
84  if(emitter == ppms__.get()) return false;
85  return true;
86 }
87 double
88 XNMRSpectrum::getFreqResHint(const Snapshot &shot_this) const {
89  double res = fabs(shot_this[ *resolution()] / shot_this[ *maxValue()] * shot_this[ *centerFreq()]);
90  res = std::min(res, fabs(shot_this[ *resolution()] / shot_this[ *minValue()] * shot_this[ *centerFreq()]));
91  return res * 1e6;
92 }
93 double
94 XNMRSpectrum::getMinFreq(const Snapshot &shot_this) const {
95  double freq = -log(shot_this[ *maxValue()]) * shot_this[ *centerFreq()];
96  freq = std::min(freq, -log(shot_this[ *minValue()]) * shot_this[ *centerFreq()]);
97  return freq * 1e6;
98 }
99 double
100 XNMRSpectrum::getMaxFreq(const Snapshot &shot_this) const {
101  double freq = -log(shot_this[ *maxValue()]) * shot_this[ *centerFreq()];
102  freq = std::max(freq, -log(shot_this[ *minValue()]) * shot_this[ *centerFreq()]);
103  return freq * 1e6;
104 }
105 double
106 XNMRSpectrum::getCurrentCenterFreq(const Snapshot &shot_this, const Snapshot &shot_others) const {
107  shared_ptr<XMagnetPS> magnet__ = shot_this[ *magnet()];
108  shared_ptr<XDMM> dmm__ = shot_this[ *magnet()];
109  shared_ptr<XQDPPMS> ppms__ = shot_this[ *magnet()];
110  shared_ptr<XNMRPulseAnalyzer> pulse__ = shot_this[ *pulse()];
111 
112  assert( magnet__ || dmm__ || ppms__);
113  double field;
114  if(magnet__) {
115  field = shot_others[ *magnet__].magnetField();
116  }
117  else if(dmm__ ) {
118  field = shot_others[ *dmm__].value();
119  }
120  else {
121  field = shot_others[ *ppms__].magnetField();
122  }
123 
124  field *= shot_this[ *fieldFactor()];
125  field += shot_this[ *residualField()];
126 
127  return -log(field) * shot_this[ *centerFreq()] * 1e6;
128 }
129 void
130 XNMRSpectrum::getValues(const Snapshot &shot_this, std::vector<double> &values) const {
131  int wave_size = shot_this[ *this].wave().size();
132  double min__ = shot_this[ *this].min();
133  double res = shot_this[ *this].res();
134  double cfreq = shot_this[ *centerFreq()];
135  values.resize(wave_size);
136  for(unsigned int i = 0; i < wave_size; i++) {
137  double freq = min__ + i * res;
138  values[i] = exp( -freq * 1e-6 / cfreq);
139  }
140 }

Generated for KAME4 by  doxygen 1.8.3