cctw  0.2.1
cctwpeingresscommand.cpp
Go to the documentation of this file.
1 #include "cctwpeingresscommand.h"
2 #include "cctwapplication.h"
3 #include "cctwlinearfitter.h"
4 
5 #ifndef NO_GUI
6 #include "qwt_plot.h"
7 #include "qwt_plot_curve.h"
8 #endif
9 
10 #include <QFile>
11 #include <math.h>
12 
13 CctwPEIngressCommand::CctwPEIngressCommand(CctwApplication *app, QString name, QObject *parent) :
14  CctwObject(name, parent),
15  m_Application(app)
16 {
17 }
18 
20 {
21 }
22 
24 {
25 }
26 
28 {
29  m_Application->set_Halting(false);
30 
31  printMessage(tr("Analyzing PE MetaData from %1").arg(path));
32 
33  QFile file(path);
34 
35  QVector<double> xData, y1Data, y2Data, y3Data, y4Data;
36 
37  if (file.open(QIODevice::ReadOnly | QIODevice::Text)) {
38  QSharedPointer<CctwLinearFitter> fit1(new CctwLinearFitter("fit1"));
39  QSharedPointer<CctwLinearFitter> fit2(new CctwLinearFitter("fit2"));
40  QSharedPointer<CctwLinearFitter> fit3(new CctwLinearFitter("fit3"));
41  QSharedPointer<CctwLinearFitter> fit4(new CctwLinearFitter("fit4"));
42 
43  int ncols = 0;
44  int line1 = true;
45  int scanNumber = -1;
46  int rowNum = -1;
47  QString scanCmd;
48  int isRotScan = false;
49 
50  QRegExp scanRE("^#S\\s*(\\d+)\\s+(\\w+)");
51  QRegExp ncolsRE("^#N\\s*(\\d+)");
52 
53  while(!file.atEnd() && !m_Application->get_Halting()) {
54  QString line = file.readLine();
55 
56  if (line.startsWith("#S")) {
57  if (line.contains(scanRE)) {
58  if (isRotScan && (rowNum >= 1200)) {
59  fit1->performFit(10, 80);
60  fit2->performFit(10, 80);
61  fit3->performFit(10, 80);
62  fit4->performFit(10, 80);
63  printLine(tr("%1 %2 %3 %4 %5, %6 %7 %8")
64  .arg(rowNum)
65  .arg(scanNumber, 6)
66  .arg(fit1->slope(), 20, 'f', 14)
67  .arg(fit1->intercept(), 20, 'f', 14)
68  .arg(fit1->rSquared(), 20, 'f', 14)
69  .arg(fit2->slope(), 20, 'f', 14)
70  .arg(fit2->intercept(), 20, 'f', 14)
71  .arg(fit2->rSquared(), 20, 'f', 14) +
72  tr(", %1 %2 %3")
73  .arg(fit3->slope(), 20, 'f', 14)
74  .arg(fit3->intercept(), 20, 'f', 14)
75  .arg(fit3->rSquared(), 20, 'f', 14) +
76  tr(", %1 %2 %3")
77  .arg(fit4->slope(), 20, 'f', 14)
78  .arg(fit4->intercept(), 20, 'f', 14)
79  .arg(fit4->rSquared(), 20, 'f', 14));
80  // printLine(tr("Scan %1, cmd %2").arg(scanRE.cap(1)).arg(scanRE.cap(2)));
81  // fit2->performFit(10, 10);
82  // fit3->performFit(10, 10);
83  // fit4->performFit(10, 10);
84 
85  xData.append(scanNumber);
86  y1Data.append(normalizedValue(fit1->slope()));
87  y2Data.append(normalizedValue(fit2->slope()));
88  y3Data.append(normalizedValue(fit3->slope()));
89  y4Data.append(normalizedValue(fit4->slope()));
90  }
91 
92  scanNumber = scanRE.cap(1).toInt();
93  scanCmd = scanRE.cap(2);
94  isRotScan = (scanCmd == "rotscan") && line.contains("auxth");
95  rowNum = 0;
96  }
97  line1 = true;
98  // scan start
99  } else if (line.startsWith("#D")) {
100  // scan date
101  } else if (line.startsWith("#L")) {
102  // scan headings
103  } else if (line.startsWith("#N")) {
104  if (line.contains(ncolsRE)) {
105  QString f = ncolsRE.cap(1);
106 
107  // printLine(tr("Ncols = %1").arg(f));
108 
109  ncols = f.toInt();
110  }
111  // number of columns
112  } else if (line.startsWith("#")) {
113  // other comment
114  } else if (isRotScan) {
115  // data line
116  rowNum++;
117 
118  QStringList fields = line.split(QRegExp("\\s+"));
119 
120  if (fields.count() >= ncols) {
121  double x1 = fields[1].toDouble();
122  double y1 = fields[0].toDouble();
123 
124  double x2 = fields[1].toDouble() + fields[2].toDouble();
125  double y2 = fields[0].toDouble();
126 
127  double x3 = fields[1].toDouble()/* + fields[2].toDouble()*/;
128  double y3 = fields[3].toDouble();
129 
130  double x4 = fields[3].toDouble();
131  double y4 = fields[0].toDouble();
132 
133  if (line1) {
134  line1 = false;
135  fit1->startNewFit();
136  fit2->startNewFit();
137  fit3->startNewFit();
138  fit4->startNewFit();
139  }
140 
141  fit1->appendPoint(x1, y1);
142  fit2->appendPoint(x2, y2);
143  fit3->appendPoint(x3, y3);
144  fit4->appendPoint(x4, y4);
145  }
146  }
147  }
148  }
149 
150 #ifndef NO_GUI
151  QwtPlotCurve *pc1 = new QwtPlotCurve("auxth vs spec epoch");
152 
153  pc1->setSamples(xData, y1Data);
154 
155  QwtPlotCurve *pc2 = new QwtPlotCurve("auxth vs det epoch");
156 
157  pc2->setSamples(xData, y2Data);
158  // pc1->attach(graph);
159 
160  QwtPlotCurve *pc3 = new QwtPlotCurve("index vs spec epoch");
161 
162  pc3->setSamples(xData, y3Data);
163 
164  QwtPlotCurve *pc4 = new QwtPlotCurve("auxth vs index");
165 
166  pc4->setSamples(xData, y4Data);
167 
168  m_Application->plotCurves(pc1, pc2, pc3, pc4);
169 #endif
170 }
171 
173 {
174  double r = fabs(v);
175 
176  if (r > 7) {
177  r = r / 10.0;
178  } else if (r > 4) {
179  r = r / 5.0;
180  } else if (r > 0.8) {
181 
182  } else if (r > 0.4) {
183  r = r * 2;
184  } else {
185  r = r * 10;
186  }
187 
188  return r;
189 }
CctwApplication * m_Application
void analyzeSpecDataFile(QString path)
virtual void printMessage(QString msg, QDateTime dt=QDateTime::currentDateTime())
Definition: cctwobject.cpp:25
virtual void printLine(QString line)
Definition: cctwobject.cpp:14
double normalizedValue(double v)
CctwPEIngressCommand(CctwApplication *app, QString name, QObject *parent)
void plotCurves(QwtPlotCurve *c1, QwtPlotCurve *c2, QwtPlotCurve *c3, QwtPlotCurve *c4)
void analyzePEMetaData(QString path)