QXRD  0.11.16
qxrdpolarnormalization.cpp
Go to the documentation of this file.
2 #include "qxrdexperiment.h"
3 #include "qcepdatasetmodel-ptr.h"
4 #include "qcepdatasetmodel.h"
5 #include "qtconcurrentrun.h"
7 #include "qxrddataprocessor.h"
8 #include <qmath.h>
9 
11  QcepObject("polarNormalization", NULL),
12  m_Source(saver, this, "source", "Polar/image", "Source for normalization operation"),
13  m_Destination(saver, this, "destination", "Polar/normed", "Destination for normalization operation"),
14  m_Integrated(saver, this, "integrated", "Polar/integrated", "Integrated result"),
15  m_ColumnScan(saver, this, "columnScan", "Polar/columnScan", "Data Column Scan result"),
16  m_SelfNormalize(saver, this, "selfNormalize", false, "Self-Normalize integrated curves"),
17  m_SelfNormalizeMin(saver, this, "selfNormalizeMin", 0, "Self-Normalize Range Minimum"),
18  m_SelfNormalizeMax(saver, this, "selfNormalizeMax", 0, "Self-Normalize Range Maximum"),
19  m_Saver(saver),
20  m_Experiment(exp)
21 {
22 }
23 
25 {
27 
28  if (expt) {
29  QcepDatasetModelPtr ds = expt->dataset();
30 
31  QcepDoubleImageDataPtr img = ds->image(get_Source());
32 
33 
35 
36  if (get_Destination().length()>0) {
37  dst = ds->image(get_Destination());
38 
39  if (dst == NULL) {
40  dst = ds->newImage(get_Destination());
41  }
42  }
43 
45 
46  if (get_Integrated().length()>0) {
47  integ = ds->integratedData(get_Integrated());
48 
49  if (integ == NULL) {
50  integ = ds->newIntegratedData(get_Integrated(), 0);
51  }
52  }
53 
55 
56  if (get_ColumnScan().length()>0) {
57  cols = ds->columnScan(get_ColumnScan());
58 
59  if (cols == NULL) {
60  cols = ds->newColumnScan(get_ColumnScan());
61  }
62  }
63 
64  if (img && dst && integ && cols) {
65  int nCols = img->get_Width();
66  int nRows = img->get_Height();
67 
68  dst->resize(nCols, nRows);
69 
70  cols->clear();
71  cols->appendColumn(img->get_HLabel());
72  cols->appendColumn("avg");
73  cols->appendColumn("amp");
74  cols->appendColumn("amp/avg");
75  cols->resizeRows(nCols);
76 
77  integ->resize(nCols);
78 
79  dst->set_HStart(img->get_HStart());
80  dst->set_HStep(img->get_HStep());
81  dst->set_HUnits(img->get_HUnits());
82  dst->set_HLabel(img->get_HLabel());
83 
84  dst->set_VStart(img->get_VStart());
85  dst->set_VStep(img->get_VStep());
86  dst->set_VUnits(img->get_VUnits());
87  dst->set_VLabel(img->get_VLabel());
88 
89  dst->set_Title(img->get_Title());
90  cols->set_Title(img->get_Title());
91  integ->set_Title(img->get_Title());
92 
93  QVector< QFuture<void> > res;
94 
95  for (int i=0; i<nCols; i++) {
96  res.append(QtConcurrent::run(this, &QxrdPolarNormalization::executeCol, cols, dst, img, i));
97  }
98 
99  for (int i=0; i<nCols; i++) {
100  res[i].waitForFinished();
101  }
102 
103  for (int i=0; i<nCols; i++) {
104  integ->setValue(i, cols->value(0,i), cols->value(1,i));
105  }
106 
107  if (get_SelfNormalize()) {
108  integ->selfNormalize(get_SelfNormalizeMin(), get_SelfNormalizeMax());
109  }
110 
111  QxrdDataProcessorPtr proc(expt->dataProcessor());
112 
113  if (proc) {
114  proc->displayIntegratedData(integ);
115  }
116  }
117  }
118 }
119 
122  QcepDoubleImageDataPtr img, int col)
123 {
124  QxrdPolarIntensityFitter fitter(img, col);
125 
126  if (fitter.fit()) {
127  double amp = fitter.fittedAmplitude();
128  double avg = fitter.fittedAverage();
129 
130  int nRows = dst->get_Height();
131  double vStart = dst->get_VStart();
132  double vStep = dst->get_VStep();
133 
134  for (int i=0; i<nRows; i++) {
135  double x = vStart + i*vStep;
136  dst->setValue(col, i, avg+amp*cos(2.0*x*M_PI/180.0));
137  }
138 // dst->setValue(col, 0, avg);
139 // dst->setValue(col, 1, amp);
140 // dst->setValue(col, 2, amp/avg);
141 
142  integ->setValue(0, col, img->hValue(col));
143  integ->setValue(1, col, avg);
144  integ->setValue(2, col, amp);
145  integ->setValue(3, col, amp/avg);
146  }
147 }
QSharedPointer< QxrdExperiment > QxrdExperimentPtr
QxrdPolarNormalization(QcepSettingsSaverWPtr saver, QxrdExperimentWPtr exp)
QSharedPointer< QcepDataColumnScan > QcepDataColumnScanPtr
QSharedPointer< QxrdDataProcessor > QxrdDataProcessorPtr
QWeakPointer< QxrdExperiment > QxrdExperimentWPtr
QSharedPointer< QcepIntegratedData > QcepIntegratedDataPtr
QcepSettingsSaverWPtr m_Saver
QxrdExperimentWPtr m_Experiment
void executeCol(QcepDataColumnScanPtr integ, QcepDoubleImageDataPtr dst, QcepDoubleImageDataPtr img, int col)
QSharedPointer< QcepDatasetModel > QcepDatasetModelPtr
QWeakPointer< QcepSettingsSaver > QcepSettingsSaverWPtr
QSharedPointer< QcepDoubleImageData > QcepDoubleImageDataPtr