1 | /*
|
---|
2 | * QtGl.cpp
|
---|
3 | *
|
---|
4 | * Created on: Jul 19, 2011
|
---|
5 | * Author: lyard
|
---|
6 | */
|
---|
7 | //FIXME replace with FACT++ Time class
|
---|
8 | #include <boost/date_time/local_time/local_time.hpp>
|
---|
9 |
|
---|
10 |
|
---|
11 | #include "RawEventsViewer.h"
|
---|
12 | #include "viewer.h"
|
---|
13 | #include <math.h>
|
---|
14 | #include <fstream>
|
---|
15 |
|
---|
16 | #include <QFileDialog>
|
---|
17 |
|
---|
18 | #include <qwt_symbol.h>
|
---|
19 |
|
---|
20 | #include "src/Configuration.h"
|
---|
21 | #include "externals/fits.h"
|
---|
22 |
|
---|
23 |
|
---|
24 | using namespace std;
|
---|
25 |
|
---|
26 | #undef ACTUAL_NUM_PIXELS
|
---|
27 | #define ACTUAL_NUM_PIXELS 1440
|
---|
28 |
|
---|
29 | //bounding box for diplaying the impulse curve
|
---|
30 | float bboxMin[2] = {-0.8,-0.9};
|
---|
31 | float bboxMax[2] = {0.8,-0.3};
|
---|
32 | /************************************************************
|
---|
33 | * CALC BLUR COLOR if in blur display mode, calculate the interpolated
|
---|
34 | * colour for a given vertex
|
---|
35 | ************************************************************/
|
---|
36 | void RawDataViewer::calcBlurColor(int pixel, int vertex)
|
---|
37 | {
|
---|
38 | GLfloat color[3];
|
---|
39 | int first, second;
|
---|
40 | first = vertex-1;
|
---|
41 | second = vertex;
|
---|
42 | if (first < 0)
|
---|
43 | first = 5;
|
---|
44 |
|
---|
45 | first = neighbors[pixel][first];
|
---|
46 | second = neighbors[pixel][second];
|
---|
47 | // cout << pixel << " " << vertex << " " << "first: " << first << " second: " << second << endl;
|
---|
48 | for (int i=0;i<3;i++)
|
---|
49 | color[i] = pixelsColor[pixel][i];
|
---|
50 | float divide = 1;
|
---|
51 | if (first != -1)
|
---|
52 | {
|
---|
53 | divide++;
|
---|
54 | for (int i=0;i<3;i++)
|
---|
55 | color[i] += pixelsColor[first][i];
|
---|
56 | }
|
---|
57 | if (second != -1)
|
---|
58 | {
|
---|
59 | divide++;
|
---|
60 | for (int i=0;i<3;i++)
|
---|
61 | color[i] += pixelsColor[second][i];
|
---|
62 | }
|
---|
63 | for (int i=0;i<3;i++)
|
---|
64 | color[i] /= divide;
|
---|
65 |
|
---|
66 | // cout << color[0] << " " << color[1] << " " << color[2] << endl;
|
---|
67 |
|
---|
68 | glColor3fv(color);
|
---|
69 | }
|
---|
70 | void RawDataViewer::calcMidBlurColor(int pixel, int vertex)
|
---|
71 | {
|
---|
72 | GLfloat color[3];
|
---|
73 | int first;
|
---|
74 | first = vertex-1;
|
---|
75 | if (first < 0)
|
---|
76 | first = 5;
|
---|
77 | first = neighbors[pixel][first];
|
---|
78 | for (int i=0;i<3;i++)
|
---|
79 | color[i] = pixelsColor[pixel][i];
|
---|
80 | float divide = 1;
|
---|
81 | if (first != -1)
|
---|
82 | {
|
---|
83 | divide++;
|
---|
84 | for (int i=0;i<3;i++)
|
---|
85 | color[i] += pixelsColor[first][i];
|
---|
86 | }
|
---|
87 | for (int i=0;i<3;i++)
|
---|
88 | color[i] /= divide;
|
---|
89 | glColor3fv(color);
|
---|
90 | }
|
---|
91 | /************************************************************
|
---|
92 | * DRAW BLURRY HEXAGON. draws a solid hexagon, with interpolated colours
|
---|
93 | ************************************************************/
|
---|
94 | void RawDataViewer::drawBlurryHexagon(int index)
|
---|
95 | {
|
---|
96 |
|
---|
97 | //per-pixel mesh
|
---|
98 | GLfloat color[3];
|
---|
99 | for (int i=0;i<3;i++)
|
---|
100 | color[i] = pixelsColor[index][i];
|
---|
101 | glBegin(GL_TRIANGLES);
|
---|
102 | calcBlurColor(index, 0);
|
---|
103 | glVertex2fv(verticesList[verticesIndices[index][0]]);
|
---|
104 | glColor3fv(color);
|
---|
105 | glVertex2fv(pixelsCoords[index]);
|
---|
106 |
|
---|
107 | calcBlurColor(index, 1);
|
---|
108 | glVertex2fv(verticesList[verticesIndices[index][1]]);
|
---|
109 |
|
---|
110 | glVertex2fv(verticesList[verticesIndices[index][1]]);
|
---|
111 | glColor3fv(color);
|
---|
112 | glVertex2fv(pixelsCoords[index]);
|
---|
113 |
|
---|
114 | calcBlurColor(index, 2);
|
---|
115 | glVertex2fv(verticesList[verticesIndices[index][2]]);
|
---|
116 |
|
---|
117 | glVertex2fv(verticesList[verticesIndices[index][2]]);
|
---|
118 | glColor3fv(color);
|
---|
119 | glVertex2fv(pixelsCoords[index]);
|
---|
120 |
|
---|
121 | calcBlurColor(index, 3);
|
---|
122 | glVertex2fv(verticesList[verticesIndices[index][3]]);
|
---|
123 |
|
---|
124 | glVertex2fv(verticesList[verticesIndices[index][3]]);
|
---|
125 | glColor3fv(color);
|
---|
126 | glVertex2fv(pixelsCoords[index]);
|
---|
127 |
|
---|
128 | calcBlurColor(index, 4);
|
---|
129 | glVertex2fv(verticesList[verticesIndices[index][4]]);
|
---|
130 |
|
---|
131 | glVertex2fv(verticesList[verticesIndices[index][4]]);
|
---|
132 | glColor3fv(color);
|
---|
133 | glVertex2fv(pixelsCoords[index]);
|
---|
134 |
|
---|
135 | calcBlurColor(index, 5);
|
---|
136 | glVertex2fv(verticesList[verticesIndices[index][5]]);
|
---|
137 |
|
---|
138 | glVertex2fv(verticesList[verticesIndices[index][5]]);
|
---|
139 | glColor3fv(color);
|
---|
140 | glVertex2fv(pixelsCoords[index]);
|
---|
141 |
|
---|
142 | calcBlurColor(index, 0);
|
---|
143 | glVertex2fv(verticesList[verticesIndices[index][0]]);
|
---|
144 | glEnd();
|
---|
145 |
|
---|
146 | return;
|
---|
147 | }
|
---|
148 |
|
---|
149 | /************************************************************
|
---|
150 | * DRAW CAMERA draws all the camera pixels
|
---|
151 | ************************************************************/
|
---|
152 | void RawDataViewer::drawCamera(bool alsoWire)
|
---|
153 | {
|
---|
154 | glLoadIdentity();
|
---|
155 | if (!drawImpulse)
|
---|
156 | {
|
---|
157 | glTranslatef(0,-0.44,0);
|
---|
158 | glRotatef(cameraRotation, 0,0,-1);
|
---|
159 | if (cameraRotation == 90)
|
---|
160 | {
|
---|
161 | glTranslatef(-0.45,-0.45,0);
|
---|
162 | }
|
---|
163 | if (cameraRotation == -90)
|
---|
164 | {
|
---|
165 | glTranslatef(0.45,-0.45,0);
|
---|
166 | }
|
---|
167 | glScalef(1.5,1.5,1);
|
---|
168 | }
|
---|
169 | else
|
---|
170 | {
|
---|
171 | glRotatef(cameraRotation, 0,0,-1);
|
---|
172 | if (cameraRotation == 90)
|
---|
173 | {
|
---|
174 | glTranslatef(-0.45/1.5,-0.45/1.5,0);
|
---|
175 | }
|
---|
176 | if (cameraRotation == -90)
|
---|
177 | {
|
---|
178 | glTranslatef(0.45/1.5,-0.45/1.5,0);
|
---|
179 | }
|
---|
180 | }
|
---|
181 | glColor3f(0.5,0.5,0.5);
|
---|
182 | glLineWidth(1.0);
|
---|
183 | float color;
|
---|
184 |
|
---|
185 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
186 | {
|
---|
187 | if (!nRoi)
|
---|
188 | color = (float)(i)/(float)(ACTUAL_NUM_PIXELS);
|
---|
189 | else
|
---|
190 |
|
---|
191 | color = float(eventData[nRoi*hardwareMapping[i] + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
|
---|
192 | if (logScale)
|
---|
193 | {
|
---|
194 | color *= 9;
|
---|
195 | color += 1;
|
---|
196 | color = log10(color);
|
---|
197 | }
|
---|
198 |
|
---|
199 | if (color < ss[0])
|
---|
200 | {
|
---|
201 | pixelsColor[i][0] = tooLowValueCoulour[0];
|
---|
202 | pixelsColor[i][1] = tooLowValueCoulour[1];
|
---|
203 | pixelsColor[i][2] = tooLowValueCoulour[2];
|
---|
204 | continue;
|
---|
205 | }
|
---|
206 | if (color > ss[4])
|
---|
207 | {
|
---|
208 | pixelsColor[i][0] = tooHighValueCoulour[0];
|
---|
209 | pixelsColor[i][1] = tooHighValueCoulour[1];
|
---|
210 | pixelsColor[i][2] = tooHighValueCoulour[2];
|
---|
211 | continue;
|
---|
212 | }
|
---|
213 | int index = 0;
|
---|
214 | while (ss[index] < color && index < 4)
|
---|
215 | index++;
|
---|
216 | index--;
|
---|
217 | if (index < 0) index = 0;
|
---|
218 | float weight0 = (color-ss[index]) / (ss[index+1]-ss[index]);
|
---|
219 | if (weight0 > 1.0f) weight0 = 1.0f;
|
---|
220 | if (weight0 < 0.0f) weight0 = 0.0f;
|
---|
221 | float weight1 = 1.0f-weight0;
|
---|
222 | pixelsColor[i][0] = weight1*rr[index] + weight0*rr[index+1];
|
---|
223 | pixelsColor[i][1] = weight1*gg[index] + weight0*gg[index+1];
|
---|
224 | pixelsColor[i][2] = weight1*bb[index] + weight0*bb[index+1];
|
---|
225 | }
|
---|
226 |
|
---|
227 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
228 | {
|
---|
229 |
|
---|
230 | glColor3fv(pixelsColor[i]);
|
---|
231 | glLoadName(i);
|
---|
232 | if (drawBlur)
|
---|
233 | drawBlurryHexagon(i);
|
---|
234 | else
|
---|
235 | drawHexagon(i,true);
|
---|
236 |
|
---|
237 | }
|
---|
238 | if (!alsoWire)
|
---|
239 | return;
|
---|
240 | glTranslatef(0,0,0.1f);
|
---|
241 | glColor3f(0.0f,0.0f,0.0f);
|
---|
242 | for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
|
---|
243 | {
|
---|
244 |
|
---|
245 | drawHexagon(i, false);
|
---|
246 | }
|
---|
247 |
|
---|
248 | }
|
---|
249 |
|
---|
250 | /************************************************************
|
---|
251 | * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel
|
---|
252 | ************************************************************/
|
---|
253 | void RawDataViewer::drawPixelCurve()
|
---|
254 | {
|
---|
255 | float xZoom, yZoom;
|
---|
256 | xZoom = yZoom = 1.0f;
|
---|
257 | float xRange = bboxMax[0] - bboxMin[0];
|
---|
258 | float yRange = bboxMax[1] - bboxMin[1];
|
---|
259 |
|
---|
260 | glBegin(GL_LINES);
|
---|
261 | glLineWidth(1.0f);
|
---|
262 | glColor3f(0.0,0.0,0.0);
|
---|
263 | glVertex2f(bboxMin[0], bboxMin[1]);
|
---|
264 | glVertex2f(bboxMax[0], bboxMin[1]);
|
---|
265 | glVertex2f(bboxMin[0], bboxMin[1]);
|
---|
266 | glVertex2f(bboxMin[0], bboxMax[1]);
|
---|
267 | glVertex2f(bboxMin[0], (bboxMin[1]+bboxMax[1])/2.0f);
|
---|
268 | glVertex2f(bboxMax[0], (bboxMin[1]+bboxMax[1])/2.0f);
|
---|
269 | glVertex2f(bboxMin[0] + xRange*nRoi/(float)(nRoi+nRoiTM),
|
---|
270 | bboxMin[1]);
|
---|
271 | glVertex2f(bboxMin[0] + xRange*nRoi/(float)(nRoi+nRoiTM),
|
---|
272 | bboxMax[1]);
|
---|
273 | glEnd();
|
---|
274 | glTranslatef(0,0,0.1f);
|
---|
275 | if (!nRoi)
|
---|
276 | return;
|
---|
277 | glBegin(GL_LINES);
|
---|
278 | glColor3f(1.0f,1.0f,0.0f);
|
---|
279 | float divideMe = (float)(VALUES_SPAN-1);
|
---|
280 | float plusMe = (float)(VALUES_SPAN)/2;
|
---|
281 | if (divideMe <= 0)
|
---|
282 | divideMe = 1;
|
---|
283 |
|
---|
284 | /*
|
---|
285 | if (drawCalibrationLoaded)
|
---|
286 | plusMe += 0;//VALUES_SPAN/2;
|
---|
287 | if (drawCalibrationLoaded && calibrationLoaded)
|
---|
288 | {
|
---|
289 | divideMe /=2;
|
---|
290 | plusMe = 0 ;///=2;
|
---|
291 | }*/
|
---|
292 |
|
---|
293 | const int hw = hardwareMapping[selectedPixel];
|
---|
294 | const PixelMapEntry& mapEntry = fPixelMap.index(selectedPixel);
|
---|
295 | const int pixelIdInPatch = mapEntry.pixel();
|
---|
296 | const int patchId = mapEntry.patch();
|
---|
297 | const int boardId = mapEntry.board();
|
---|
298 | const int crateId = mapEntry.crate();
|
---|
299 |
|
---|
300 | if (selectedPixel != -1)
|
---|
301 | {
|
---|
302 | for (int i=0;i<nRoi-1;i++)
|
---|
303 | {
|
---|
304 | float d1 = eventData[nRoi*hw + i]+plusMe;
|
---|
305 | float d2 = eventData[nRoi*hw + i+1]+plusMe;
|
---|
306 | if (!finite(d1)) d1 = 20000;
|
---|
307 | if (!finite(d2)) d2 = 20000;
|
---|
308 | glVertex2f(bboxMin[0] + xRange*i/(float)(nRoi+nRoiTM),
|
---|
309 | bboxMin[1] + yRange*(d1) /divideMe);
|
---|
310 | glVertex2f(bboxMin[0] + xRange*(i+1)/(float)(nRoi+nRoiTM),
|
---|
311 | bboxMin[1] + yRange*(d2) /divideMe);
|
---|
312 | }
|
---|
313 | glEnd();
|
---|
314 |
|
---|
315 | glColor3f(0.0f, 1.0f, 1.0f);
|
---|
316 | glBegin(GL_LINES);
|
---|
317 | if (pixelIdInPatch == 8)//this channel has a time marker
|
---|
318 | {
|
---|
319 |
|
---|
320 | for (int i=0;i<nRoiTM-1;i++)
|
---|
321 | {
|
---|
322 | float d1 = eventData[nRoi*1440 + nRoiTM*(40*crateId + 4*boardId + patchId) + i] + plusMe;
|
---|
323 | float d2 = eventData[nRoi*1440 + nRoiTM*(40*crateId + 4*boardId + patchId) + i+1] + plusMe;
|
---|
324 | if (!finite(d1)) d1 = 20000;
|
---|
325 | if (!finite(d2)) d2 = 20000;
|
---|
326 | glVertex2f(bboxMin[0] + xRange*(i+nRoi)/(float)(nRoi+nRoiTM),
|
---|
327 | bboxMin[1] + yRange*(d1)/divideMe);
|
---|
328 | glVertex2f(bboxMin[0] + xRange*(i+1+nRoi)/(float)(nRoi+nRoiTM),
|
---|
329 | bboxMin[1] + yRange*(d2) / divideMe);
|
---|
330 | }
|
---|
331 | }
|
---|
332 |
|
---|
333 | }
|
---|
334 | glEnd();
|
---|
335 | glTranslatef(0,0,0.1f);
|
---|
336 | glBegin(GL_LINES);
|
---|
337 | glColor3f(1.0,0.0,0.0);
|
---|
338 | glVertex2f(bboxMin[0] + xRange*whichSlice/(float)(nRoi+nRoiTM),
|
---|
339 | bboxMin[1]);
|
---|
340 | glVertex2f(bboxMin[0] + xRange*whichSlice/(float)(nRoi+nRoiTM),
|
---|
341 | bboxMax[1]);
|
---|
342 |
|
---|
343 | glEnd();
|
---|
344 |
|
---|
345 | }
|
---|
346 | /************************************************************
|
---|
347 | * CONSTRUCTOR.
|
---|
348 | ************************************************************/
|
---|
349 | RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent), RMSvalues(1440), Meanvalues(1440), Maxvalues(1440), PosOfMaxvalues(1440), VALUES_SPAN(4096)
|
---|
350 |
|
---|
351 | {
|
---|
352 |
|
---|
353 | whichSlice = 0;
|
---|
354 |
|
---|
355 | nRoi = 0;
|
---|
356 | nRoiTM = 0;
|
---|
357 | offSetRoi = 0;
|
---|
358 | eventNum = 0;
|
---|
359 | rowNum = -1;
|
---|
360 | eventStep = 1;
|
---|
361 | selectedPixel = 393;
|
---|
362 | inputFile = NULL;
|
---|
363 | eventData = NULL;
|
---|
364 | drawPatch = false;
|
---|
365 | drawImpulse = true;
|
---|
366 | drawBlur = false;
|
---|
367 | loopCurrentEvent = false;
|
---|
368 | fIsDrsCalibration = false;
|
---|
369 | SetAutoRefresh(true);
|
---|
370 |
|
---|
371 | PixelMap mypMap;
|
---|
372 | if (!mypMap.Read("/swdev_nfs/FACT++/FACTmap111030.txt"))
|
---|
373 | {
|
---|
374 | cerr << "ERROR - Problems reading FACTmap111030.txt" << endl;
|
---|
375 | exit(-1);
|
---|
376 | }
|
---|
377 |
|
---|
378 | assignPixelMap(mypMap);
|
---|
379 |
|
---|
380 | for (int i=0;i<160;i++)
|
---|
381 | {
|
---|
382 | const float color[3] = { 0.5, 0.5, 0.3 };
|
---|
383 |
|
---|
384 | for (int j=0;j<3;j++)
|
---|
385 | patchesColor[i][j] = color[j];
|
---|
386 | }
|
---|
387 |
|
---|
388 | }
|
---|
389 | /************************************************************
|
---|
390 | * DESTRUCTOR
|
---|
391 | ************************************************************/
|
---|
392 | RawDataViewer::~RawDataViewer()
|
---|
393 | {
|
---|
394 | if (inputFile != NULL)
|
---|
395 | {
|
---|
396 | inputFile->close();
|
---|
397 | delete inputFile;
|
---|
398 | }
|
---|
399 | if (eventData != NULL) {
|
---|
400 | delete[] eventData;
|
---|
401 | delete[] rawEventData;
|
---|
402 | delete[] waveLetArray;
|
---|
403 | }
|
---|
404 | }
|
---|
405 |
|
---|
406 | /************************************************************
|
---|
407 | * PAINT GL. main drawing function.
|
---|
408 | ************************************************************/
|
---|
409 | void RawDataViewer::paintGL()
|
---|
410 | {
|
---|
411 | //Should not be required, but apparently it helps when piping it through X forwarding
|
---|
412 | glFinish();
|
---|
413 | glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
---|
414 | glLoadIdentity();
|
---|
415 |
|
---|
416 | glTranslatef(0,0,-0.5);
|
---|
417 |
|
---|
418 | if (drawBlur)
|
---|
419 | {
|
---|
420 | glShadeModel(GL_SMOOTH);
|
---|
421 | drawCamera(false);
|
---|
422 | }
|
---|
423 | else
|
---|
424 | {
|
---|
425 | glShadeModel(GL_FLAT);
|
---|
426 | drawCamera(true);
|
---|
427 | }
|
---|
428 | glTranslatef(0,0,0.1f);
|
---|
429 | if (drawPatch)
|
---|
430 | drawPatches();
|
---|
431 | glTranslatef(0,0,0.1f);
|
---|
432 | if (!drawBlur && (selectedPixel != -1))
|
---|
433 | {
|
---|
434 | glLineWidth(1.0f);
|
---|
435 | glColor3f(1.0,1.0,1.0);
|
---|
436 | drawHexagon(selectedPixel, false);
|
---|
437 | }
|
---|
438 | glTranslatef(0,0,0.1f);
|
---|
439 | if (drawImpulse)
|
---|
440 | {
|
---|
441 | // glRotatef(cameraRotation, 0,0,1);
|
---|
442 | glLoadIdentity();
|
---|
443 | glLineWidth(2.0);
|
---|
444 | drawPixelCurve();
|
---|
445 | }
|
---|
446 | glTranslatef(0,0,0.1f);
|
---|
447 | DrawScale();
|
---|
448 | }
|
---|
449 |
|
---|
450 | /************************************************************
|
---|
451 | * MOUSE PRESS EVENT. mouse click handler.
|
---|
452 | ************************************************************/
|
---|
453 | void RawDataViewer::mousePressEvent(QMouseEvent *cEvent)
|
---|
454 | {
|
---|
455 | if (cEvent->pos().x() > width()-(width()/50.f))
|
---|
456 | {
|
---|
457 | toggleInterfaceDisplay();
|
---|
458 | return;
|
---|
459 | }
|
---|
460 | lastPos = cEvent->pos();
|
---|
461 | if (setCorrectSlice(cEvent))
|
---|
462 | return;
|
---|
463 | int face = PixelAtPosition(cEvent->pos());
|
---|
464 |
|
---|
465 | selectedPixel = face;
|
---|
466 | emit signalCurrentPixel(face);
|
---|
467 |
|
---|
468 | updateGL();
|
---|
469 | }
|
---|
470 |
|
---|
471 | /************************************************************
|
---|
472 | * SET CORRECT SLICE. if displayed, figures out if the graph was
|
---|
473 | * clicked, and if so, which slice should be displayed
|
---|
474 | ************************************************************/
|
---|
475 | bool RawDataViewer::setCorrectSlice(QMouseEvent* cEvent)
|
---|
476 | {
|
---|
477 | if (!drawImpulse)
|
---|
478 | return false;
|
---|
479 | float cx = (float)cEvent->x() * pixelSize - shownSizex/2;
|
---|
480 | float cy = ((float)height()-(float)cEvent->y())*pixelSize - shownSizey/2;
|
---|
481 | if (cx < bboxMin[0] ||
|
---|
482 | cx > bboxMax[0] ||
|
---|
483 | cy < bboxMin[1] ||
|
---|
484 | cy > bboxMax[1])
|
---|
485 | return false;
|
---|
486 | whichSlice = (cx - bboxMin[0])*(nRoi+nRoiTM)/(bboxMax[0] - bboxMin[0]);
|
---|
487 | if (whichSlice >= nRoi)
|
---|
488 | whichSlice = nRoi-1;
|
---|
489 | emit signalCurrentSlice(whichSlice);
|
---|
490 | return true;
|
---|
491 | }
|
---|
492 |
|
---|
493 | /************************************************************
|
---|
494 | * MOUSE MOVE EVENT. used to track the dragging of slices display
|
---|
495 | ************************************************************/
|
---|
496 | void RawDataViewer::mouseMoveEvent(QMouseEvent *cEvent)
|
---|
497 | {
|
---|
498 | if (cEvent->buttons() & Qt::LeftButton) {
|
---|
499 | setCorrectSlice(cEvent);
|
---|
500 | updateGL();
|
---|
501 | } else if (cEvent->buttons() & Qt::RightButton) {
|
---|
502 | updateGL();
|
---|
503 | }
|
---|
504 | lastPos = cEvent->pos();
|
---|
505 | }
|
---|
506 |
|
---|
507 | /************************************************************
|
---|
508 | * MOUSE DOUBLE CLICK EVENT. used to select pixels
|
---|
509 | ************************************************************/
|
---|
510 | void RawDataViewer::mouseDoubleClickEvent(QMouseEvent *cEvent)
|
---|
511 | {
|
---|
512 | int face = PixelAtPosition(cEvent->pos());
|
---|
513 | if (face != -1) {
|
---|
514 | selectedPixel = face;
|
---|
515 | emit signalCurrentPixel(face);
|
---|
516 | updateGL();
|
---|
517 | }
|
---|
518 | }
|
---|
519 |
|
---|
520 | /************************************************************
|
---|
521 | * OPEN FILE. opens a new fits file
|
---|
522 | ************************************************************/
|
---|
523 | void RawDataViewer::openFile(string& file)
|
---|
524 | {
|
---|
525 | if (inputFile)
|
---|
526 | {
|
---|
527 | inputFile->close();
|
---|
528 | delete inputFile;
|
---|
529 | }
|
---|
530 | try {
|
---|
531 | inputFile = new fits(file);
|
---|
532 | }
|
---|
533 | catch (std::runtime_error e)
|
---|
534 | {
|
---|
535 | cout << "Something went wrong while loading fits. Aborting: " << e.what() << endl;
|
---|
536 | return;
|
---|
537 | }
|
---|
538 | if (!*inputFile)
|
---|
539 | {
|
---|
540 | delete inputFile;
|
---|
541 | inputFile = NULL;
|
---|
542 | return;
|
---|
543 | }
|
---|
544 | vector<string> entriesToCheck;
|
---|
545 | entriesToCheck.push_back("NAXIS2");
|
---|
546 | entriesToCheck.push_back("NROI");
|
---|
547 | entriesToCheck.push_back("REVISION");
|
---|
548 | entriesToCheck.push_back("RUNID");
|
---|
549 | entriesToCheck.push_back("NBOARD");
|
---|
550 | entriesToCheck.push_back("NPIX");
|
---|
551 | entriesToCheck.push_back("NROITM");
|
---|
552 | entriesToCheck.push_back("TIMESYS");
|
---|
553 | entriesToCheck.push_back("DATE");
|
---|
554 | entriesToCheck.push_back("NIGHT");
|
---|
555 | entriesToCheck.push_back("CAMERA");
|
---|
556 | entriesToCheck.push_back("DAQ");
|
---|
557 | entriesToCheck.push_back("TSTART");
|
---|
558 | entriesToCheck.push_back("TSTOP");
|
---|
559 |
|
---|
560 |
|
---|
561 | for (vector<string>::const_iterator it=entriesToCheck.begin(); it != entriesToCheck.end(); it++)
|
---|
562 | {
|
---|
563 | try {
|
---|
564 | if (!inputFile->HasKey(*it)){
|
---|
565 | cout << "Warning: header keyword " << *it << " missing." << endl;
|
---|
566 | }
|
---|
567 | }
|
---|
568 | catch (std::runtime_error e)
|
---|
569 | {
|
---|
570 | cout << e.what() << endl;
|
---|
571 | return;
|
---|
572 | }
|
---|
573 | }
|
---|
574 | nRows = inputFile->HasKey("NAXIS2") ? inputFile->GetInt("NAXIS2") : 0;
|
---|
575 | nRoi = inputFile->HasKey("NROI") ? inputFile->GetInt("NROI") : 0;
|
---|
576 | runNumber = inputFile->HasKey("RUNID") ? inputFile->GetInt("RUNID") : -1;
|
---|
577 | nTM = inputFile->HasKey("NTMARK") ? inputFile->GetInt("NTMARK") : 0;
|
---|
578 | runType = inputFile->HasKey("RUNTYPE") ? inputFile->GetInt("RUNTYPE") : -1;
|
---|
579 | firstDataTime = inputFile->HasKey("TSTART") ? inputFile->GetInt("TSTART") : -1;
|
---|
580 | lastDataTime = inputFile->HasKey("TSTOP") ? inputFile->GetInt("TSTOP"): -1;
|
---|
581 | nRoiTM = inputFile->HasKey("NROITM") ? inputFile->GetInt("NROITM") : 0;
|
---|
582 | revision = inputFile->HasKey("REVISION") ? inputFile->GetInt("REVISION") : -1;
|
---|
583 | builderVersion = inputFile->HasKey("BLDVER") ? inputFile->GetInt("BLDVER") : -1;
|
---|
584 | nBoards = inputFile->HasKey("NBOARD") ? inputFile->GetInt("NBOARD") : 0;
|
---|
585 | nPixels = inputFile->HasKey("NPIX") ? inputFile->GetInt("NPIX") : 0;
|
---|
586 | timeSystem = inputFile->HasKey("TIMESYS") ? inputFile->GetStr("TIMESYS") : 0;
|
---|
587 | creationDate = inputFile->HasKey("DATE") ? inputFile->GetStr("DATE") : 0;
|
---|
588 | nightInt = inputFile->HasKey("NIGHT") ? inputFile->GetInt("NIGHT") : 0;
|
---|
589 | camera = inputFile->HasKey("CAMERA") ? inputFile->GetStr("CAMERA") : 0;
|
---|
590 | daq = inputFile->HasKey("DAQ") ? inputFile->GetStr("DAQ") : 0;
|
---|
591 | adcCount = inputFile->HasKey("ADCRANGE") ? inputFile->GetFloat("ADCRANGE") : 2000;
|
---|
592 |
|
---|
593 | if (inputFile->HasKey("OFFSET"))
|
---|
594 | offSetRoi = inputFile->GetInt("OFFSET");
|
---|
595 |
|
---|
596 | nbOk = 0;//inputFile->GetInt("NBEVTOK");
|
---|
597 | nbRej = 0;//inputFile->GetInt("NBEVTREJ");
|
---|
598 | nbBad = 0;//inputFile->GetInt("NBEVTBAD");
|
---|
599 |
|
---|
600 | eventNum = 0;
|
---|
601 |
|
---|
602 | if (eventData != NULL) {
|
---|
603 | delete[] eventData;
|
---|
604 | delete[] rawEventData;
|
---|
605 | delete[] waveLetArray;
|
---|
606 | }
|
---|
607 | eventData = new float[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
|
---|
608 |
|
---|
609 | rawEventData = new int16_t[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
|
---|
610 | waveLetArray = new int16_t[1024*1440];
|
---|
611 | try
|
---|
612 | {
|
---|
613 | inputFile->SetPtrAddress("Data", rawEventData);
|
---|
614 | inputFile->SetPtrAddress("EventNum", &eventNum);
|
---|
615 | inputFile->SetPtrAddress("TriggerType", &triggerType);
|
---|
616 | inputFile->SetPtrAddress("SoftTrig", &softTrig);
|
---|
617 | inputFile->SetPtrAddress("BoardTime", boardTime);
|
---|
618 | inputFile->SetPtrAddress("StartCellData", startPix);
|
---|
619 | inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
|
---|
620 | inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
|
---|
621 | }
|
---|
622 | catch (const runtime_error &e)
|
---|
623 | {
|
---|
624 | cout << e.what() << endl;
|
---|
625 | cout << "Loading aborted." << endl;
|
---|
626 |
|
---|
627 | nRoi = nRows = 0;
|
---|
628 |
|
---|
629 | return;
|
---|
630 | }
|
---|
631 |
|
---|
632 | try
|
---|
633 | {
|
---|
634 | pcTime[0] = pcTime[1] = 0;
|
---|
635 | inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
|
---|
636 | }
|
---|
637 | catch (const runtime_error&)
|
---|
638 | {
|
---|
639 | try
|
---|
640 | {
|
---|
641 | inputFile->SetPtrAddress("PCTime", pcTime);
|
---|
642 | }
|
---|
643 | catch (const runtime_error&)
|
---|
644 | {
|
---|
645 |
|
---|
646 | }
|
---|
647 | }
|
---|
648 |
|
---|
649 |
|
---|
650 | int backupStep = eventStep;
|
---|
651 | rowNum = -1;
|
---|
652 | eventStep = 1;
|
---|
653 |
|
---|
654 | plusEvent();
|
---|
655 | eventStep = backupStep;
|
---|
656 | emit newFileLoaded();
|
---|
657 | emit signalCurrentPixel(selectedPixel);
|
---|
658 | }
|
---|
659 |
|
---|
660 | void RawDataViewer::openCalibFile(string& file)
|
---|
661 | {
|
---|
662 | //calibrationLoaded = false;
|
---|
663 | string msg;
|
---|
664 | try
|
---|
665 | {
|
---|
666 | msg = fDrsCalib.ReadFitsImp(file);
|
---|
667 | if (msg.empty())
|
---|
668 | {
|
---|
669 | emit newFileLoaded();
|
---|
670 | updateGL();
|
---|
671 | return;
|
---|
672 | }
|
---|
673 | }
|
---|
674 | catch (const runtime_error &e)
|
---|
675 | {
|
---|
676 | msg = e.what();
|
---|
677 | }
|
---|
678 |
|
---|
679 | cerr << msg << endl;
|
---|
680 | fDrsCalib.Clear();
|
---|
681 | }
|
---|
682 |
|
---|
683 | template <typename T>
|
---|
684 | void RawDataViewer::getCalibrationDataForDisplay(const CalibDataTypes/* calibTypes*/,
|
---|
685 | const vector<T>& inputData,
|
---|
686 | const int roi,
|
---|
687 | const int roiTM)
|
---|
688 | {
|
---|
689 |
|
---|
690 | eventData = new float[1440*roi + 160*roiTM];//(1440+160)*nRoi];
|
---|
691 | nRoi=roi;
|
---|
692 | nRoiTM=roiTM;
|
---|
693 |
|
---|
694 | long long min, max, mean;
|
---|
695 | min = max = inputData[0];
|
---|
696 | mean=0;
|
---|
697 | for (int i=0;i<1440*roi + 160*roiTM;i++) {
|
---|
698 | eventData[i] = (float)inputData[i];
|
---|
699 | mean += inputData[i];
|
---|
700 | if (inputData[i] > max)
|
---|
701 | max = inputData[i];
|
---|
702 | if (inputData[i] < min)
|
---|
703 | min = inputData[i];
|
---|
704 | }
|
---|
705 | mean /= 1440*roi + 160*roiTM;
|
---|
706 | for (int i=0;i<1440*roi + 160*roiTM;i++)
|
---|
707 | eventData[i] -= (float)mean;
|
---|
708 | VALUES_SPAN = max - min;
|
---|
709 | // cout << VALUES_SPAN << " " << min << " " << max << " " << mean << endl;
|
---|
710 | // cout << 1440*roi + 160*roiTM << " " << roi << " " << roiTM << " " << inputData.size() << endl;
|
---|
711 | }
|
---|
712 | /************************************************************
|
---|
713 | * PLUS EVENT
|
---|
714 | ************************************************************/
|
---|
715 | void RawDataViewer::plusEvent()
|
---|
716 | {
|
---|
717 | eventStepping(true);
|
---|
718 | }
|
---|
719 | /************************************************************
|
---|
720 | * MINUS EVENT
|
---|
721 | ************************************************************/
|
---|
722 | void RawDataViewer::minusEvent()
|
---|
723 | {
|
---|
724 | eventStepping(false);
|
---|
725 | }
|
---|
726 | /************************************************************
|
---|
727 | * SET EVENT STEP
|
---|
728 | ************************************************************/
|
---|
729 | void RawDataViewer::setEventStep(int step)
|
---|
730 | {
|
---|
731 | eventStep = step;
|
---|
732 | }
|
---|
733 | /************************************************************
|
---|
734 | * EVENT STEPPING
|
---|
735 | ************************************************************/
|
---|
736 |
|
---|
737 | void RawDataViewer::ApplyCalibration()
|
---|
738 | {
|
---|
739 | for (int i=0;i<1440*nRoi + 160*nRoiTM;i++)//(1440+160)*nRoi;i++)
|
---|
740 | eventData[i] = (float)rawEventData[i];
|
---|
741 |
|
---|
742 | if (fIsDrsCalibration)
|
---|
743 | {
|
---|
744 | fDrsCalib.Apply(eventData, rawEventData, startPix, nRoi);
|
---|
745 | DrsCalibrate::RemoveSpikes(eventData, nRoi);
|
---|
746 | //TODO apply calibration to the Time markers
|
---|
747 | }
|
---|
748 |
|
---|
749 | //hide the time markers
|
---|
750 | int nSlicesToRemove = 60;
|
---|
751 | float* backupData = 0;
|
---|
752 | if (nRoiTM == 0) //they are written into the regular channel
|
---|
753 | {
|
---|
754 | backupData = new float[nSlicesToRemove*160];
|
---|
755 | for (int i=0;i<1440;i++)
|
---|
756 | {
|
---|
757 | const PixelMapEntry& mapEntry = fPixelMap.index(i);
|
---|
758 | const int pixelIdInPatch = mapEntry.pixel();
|
---|
759 | const int patchId = mapEntry.patch();
|
---|
760 | const int boardId = mapEntry.board();
|
---|
761 | const int crateId = mapEntry.crate();
|
---|
762 |
|
---|
763 | const int hw = mapEntry.hw();
|
---|
764 | if (pixelIdInPatch == 8)
|
---|
765 | {
|
---|
766 | for (int j=0;j<nSlicesToRemove;j++)
|
---|
767 | {
|
---|
768 | backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j] = eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j];
|
---|
769 | eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j] = eventData[hw*nRoi + (nRoi-nSlicesToRemove) - 1];
|
---|
770 | }
|
---|
771 | }
|
---|
772 | }
|
---|
773 | }
|
---|
774 |
|
---|
775 | vector<float> pixelStatsData(1440*4);
|
---|
776 | DrsCalibrate::GetPixelStats(pixelStatsData.data(), eventData, nRoi);
|
---|
777 |
|
---|
778 | for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
|
---|
779 | {
|
---|
780 | Meanvalues[it->index] = pixelStatsData[0*1440+it->hw()];
|
---|
781 | RMSvalues[it->index] = pixelStatsData[1*1440+it->hw()];
|
---|
782 | Maxvalues[it->index] = pixelStatsData[2*1440+it->hw()];
|
---|
783 | PosOfMaxvalues[it->index] = pixelStatsData[3*1440+it->hw()];
|
---|
784 | }
|
---|
785 | if (nRoiTM == 0)//move back the data back in place
|
---|
786 | {
|
---|
787 | for (int i=0;i<1440;i++)
|
---|
788 | {
|
---|
789 | const PixelMapEntry& mapEntry = fPixelMap.index(i);
|
---|
790 | const int pixelIdInPatch = mapEntry.pixel();
|
---|
791 | const int patchId = mapEntry.patch();
|
---|
792 | const int boardId = mapEntry.board();
|
---|
793 | const int crateId = mapEntry.crate();
|
---|
794 | if (patchId > 160)
|
---|
795 | cout << "Voila mon probleme: " << patchId << endl;
|
---|
796 | const int hw = mapEntry.hw();
|
---|
797 | if (pixelIdInPatch == 8)
|
---|
798 | {
|
---|
799 | // cout << "|" << crateId << " " << boardId << " " << patchId << " " << hw << "| ";
|
---|
800 | for (int j=0;j<nSlicesToRemove;j++)
|
---|
801 | {
|
---|
802 | eventData[(hw*nRoi) + (nRoi - nSlicesToRemove) + j] = backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j];
|
---|
803 | }
|
---|
804 | }
|
---|
805 | }
|
---|
806 | delete[] backupData;
|
---|
807 | }
|
---|
808 | if (isVisible())
|
---|
809 | updateGL();
|
---|
810 | }
|
---|
811 |
|
---|
812 | void RawDataViewer::eventStepping(bool plus)
|
---|
813 | {
|
---|
814 | if (plus)
|
---|
815 | rowNum += eventStep;
|
---|
816 | else
|
---|
817 | rowNum -= eventStep;
|
---|
818 | if (rowNum >= nRows)
|
---|
819 | rowNum -= nRows;
|
---|
820 | if (rowNum < 0)
|
---|
821 | rowNum += nRows;
|
---|
822 |
|
---|
823 | if (inputFile == NULL)
|
---|
824 | return;
|
---|
825 | inputFile->GetRow(rowNum);
|
---|
826 | // cout << "Getting row " << rowNum << endl;
|
---|
827 |
|
---|
828 |
|
---|
829 | ApplyCalibration();
|
---|
830 |
|
---|
831 | emit signalCurrentEvent(eventNum);
|
---|
832 | emit signalCurrentPixel(selectedPixel);
|
---|
833 | }
|
---|
834 |
|
---|
835 | /************************************************************
|
---|
836 | * NEXT SLICE. deprec ?
|
---|
837 | ************************************************************/
|
---|
838 | void RawDataViewer::nextSlice()
|
---|
839 | {
|
---|
840 | whichSlice++;
|
---|
841 | if (whichSlice >= nRoi)
|
---|
842 | {
|
---|
843 | whichSlice = 0;
|
---|
844 | if (!loopCurrentEvent)
|
---|
845 | {
|
---|
846 | int backupStep = eventStep;
|
---|
847 | eventStep = 1;
|
---|
848 | eventStepping(true);
|
---|
849 | eventStep = backupStep;
|
---|
850 | }
|
---|
851 | }
|
---|
852 | emit signalCurrentSlice(whichSlice);
|
---|
853 | updateGL();
|
---|
854 | }
|
---|
855 | void RawDataViewer::previousSlice()
|
---|
856 | {
|
---|
857 | whichSlice--;
|
---|
858 | if (whichSlice < 0)
|
---|
859 | {
|
---|
860 | whichSlice = nRoi-1;
|
---|
861 | if (!loopCurrentEvent)
|
---|
862 | {
|
---|
863 | int backupStep = eventStep;
|
---|
864 | eventStep = 1;
|
---|
865 | eventStepping(false);
|
---|
866 | eventStep = backupStep;
|
---|
867 | }
|
---|
868 | }
|
---|
869 | emit signalCurrentSlice(whichSlice);
|
---|
870 | updateGL();
|
---|
871 | }
|
---|
872 | void RawDataViewer::setCurrentPixel(int pix)
|
---|
873 | {
|
---|
874 | // if (pix == -1)
|
---|
875 | // return;
|
---|
876 | selectedPixel = pix;
|
---|
877 | if (isVisible())
|
---|
878 | updateGL();
|
---|
879 | emit signalCurrentPixel(pix);
|
---|
880 | }
|
---|
881 | void RawDataViewer::computePulsesStatistics()
|
---|
882 | {
|
---|
883 | if (!inputFile)
|
---|
884 | {
|
---|
885 | cout << "A FITS file must be open in order to complete this operation" << endl;
|
---|
886 | return;
|
---|
887 | }
|
---|
888 |
|
---|
889 |
|
---|
890 | // for (int i=0;i<nRows;i++)//for all events
|
---|
891 | // {
|
---|
892 | // inputFile->GetRow(rowNum);
|
---|
893 | // for (int i=0;i<(1440+160)*nRoi;i++)
|
---|
894 | // eventData[i] = (float)rawEventData[i];
|
---|
895 |
|
---|
896 | // for (int j=0;j<ACTUAL_NUM_PIXELS;j++)
|
---|
897 | /// {
|
---|
898 | int j = selectedPixel;
|
---|
899 | if (j == -1)
|
---|
900 | return;
|
---|
901 | for (int i=0;i<nRoi;i++)
|
---|
902 | {
|
---|
903 | aMeas[i] = eventData[j*nRoi+i];// * adcCount;
|
---|
904 |
|
---|
905 | }
|
---|
906 | for (int i=0;i<nRoi;i++)
|
---|
907 | {
|
---|
908 | if (i==0)
|
---|
909 | n1mean[i] = aMeas[i+1];
|
---|
910 | else
|
---|
911 | {
|
---|
912 | if (i==1023)
|
---|
913 | n1mean[i] = aMeas[i-1];
|
---|
914 | else
|
---|
915 | n1mean[i] = (aMeas[i-1]+aMeas[i+1])/2.f;
|
---|
916 | }
|
---|
917 | }
|
---|
918 | //find spike
|
---|
919 | for (int i=0;i<nRoi-3;i++)
|
---|
920 | {
|
---|
921 | const float fract = 0.8f;
|
---|
922 | float xx, xp, xpp;
|
---|
923 | vCorr[i] = 0;//aMeas[i];
|
---|
924 | xx = aMeas[i] - n1mean[i];
|
---|
925 | if (xx < -8.f)
|
---|
926 | {
|
---|
927 | xp = aMeas[i+1] - n1mean[i+1];
|
---|
928 | xpp = aMeas[i+2] - n1mean[i+2];
|
---|
929 | if ((aMeas[i+2] - (aMeas[i] + aMeas[i+3])/2.f) > 10.f)
|
---|
930 | {
|
---|
931 | vCorr[i+1] = (aMeas[i] + aMeas[i+3])/2.f;
|
---|
932 | vCorr[i+2] = (aMeas[i] + aMeas[i+3])/2.f;
|
---|
933 | i = i+2;
|
---|
934 | }
|
---|
935 | else
|
---|
936 | {
|
---|
937 | if ((xp > -2.*xx*fract) && (xpp < -10.f))
|
---|
938 | {
|
---|
939 | vCorr[i+1] = n1mean[i+1];
|
---|
940 | n1mean[i+2] = aMeas[i+1] - aMeas[i+3]/2.f;
|
---|
941 | i++;
|
---|
942 | }
|
---|
943 | }
|
---|
944 | }
|
---|
945 | }
|
---|
946 | for (int i=0;i<nRoi;i++)
|
---|
947 | n1mean[i] = aMeas[i]-n1mean[i];
|
---|
948 | // }
|
---|
949 | // }
|
---|
950 | }
|
---|
951 | /************************************************************
|
---|
952 | * UICONNECTOR CONSTRUCTOR
|
---|
953 | ************************************************************/
|
---|
954 | UIConnector::UIConnector(QWidget *p)
|
---|
955 | {
|
---|
956 | setupUi(this);
|
---|
957 | initHistograms();
|
---|
958 |
|
---|
959 | currentFile = "none";
|
---|
960 | currentCalibFile = "none";
|
---|
961 |
|
---|
962 | updateSpinnerDisplay = true;
|
---|
963 | updating = false;
|
---|
964 |
|
---|
965 | timer.setInterval(10.0);
|
---|
966 | QObject::connect(&timer, SIGNAL(timeout()),
|
---|
967 | this, SLOT(nextSlicePlease()));
|
---|
968 |
|
---|
969 | QButtonGroup &scaleGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
|
---|
970 | QButtonGroup &animateGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
|
---|
971 |
|
---|
972 | scaleGroup.addButton(currentPixelScale);
|
---|
973 | scaleGroup.addButton(entireCameraScale);
|
---|
974 |
|
---|
975 | animateGroup.addButton(playEventsRadio);
|
---|
976 | animateGroup.addButton(playSlicesRadio);
|
---|
977 | animateGroup.addButton(playPixelsRadio);
|
---|
978 |
|
---|
979 | entireCameraScale->setChecked(true);
|
---|
980 |
|
---|
981 | RMS_window->enableText(false);
|
---|
982 | Mean_window->enableText(false);
|
---|
983 | PosOfMax_window->enableText(false);
|
---|
984 | Max_window->enableText(false);
|
---|
985 |
|
---|
986 | // RMS_window->ShowPatchCursor(true);
|
---|
987 |
|
---|
988 | QObject::connect(GLWindow, SIGNAL(colorPaletteHasChanged()),
|
---|
989 | this, SLOT(on_autoScaleColor_clicked()));
|
---|
990 | QObject::connect(GLWindow, SIGNAL(signalCurrentSlice(int)),
|
---|
991 | this, SLOT(currentSliceHasChanged(int)));
|
---|
992 | QObject::connect(GLWindow, SIGNAL(signalCurrentEvent(int)),
|
---|
993 | this, SLOT(currentEventHasChanged(int)));
|
---|
994 | QObject::connect(GLWindow, SIGNAL(signalCurrentPixel(int)),
|
---|
995 | this, SLOT(pixelChanged(int)));
|
---|
996 | QObject::connect(GLWindow, SIGNAL(newFileLoaded()),
|
---|
997 | this, SLOT(newFileLoaded()));
|
---|
998 |
|
---|
999 | QObject::connect(RMS_window, SIGNAL(signalCurrentPixel(int)),
|
---|
1000 | GLWindow, SLOT(setCurrentPixel(int)));
|
---|
1001 | QObject::connect(Max_window, SIGNAL(signalCurrentPixel(int)),
|
---|
1002 | GLWindow, SLOT(setCurrentPixel(int)));
|
---|
1003 | QObject::connect(PosOfMax_window, SIGNAL(signalCurrentPixel(int)),
|
---|
1004 | GLWindow, SLOT(setCurrentPixel(int)));
|
---|
1005 | QObject::connect(Mean_window, SIGNAL(signalCurrentPixel(int)),
|
---|
1006 | GLWindow, SLOT(setCurrentPixel(int)));
|
---|
1007 |
|
---|
1008 |
|
---|
1009 |
|
---|
1010 | show();
|
---|
1011 | }
|
---|
1012 | UIConnector::~UIConnector()
|
---|
1013 | {
|
---|
1014 | grid1->detach();
|
---|
1015 | grid2->detach();
|
---|
1016 | grid3->detach();
|
---|
1017 | grid4->detach();
|
---|
1018 | grid5->detach();
|
---|
1019 | grid6->detach();
|
---|
1020 | boardsTimeHistoItem.detach();
|
---|
1021 | startCellHistoItem.detach();
|
---|
1022 | startTimeMarkHistoItem.detach();
|
---|
1023 | pixelValueCurveItem.detach();
|
---|
1024 | pixelAverageCurveItem.detach();
|
---|
1025 | aMeanCurveItem.detach();
|
---|
1026 | vCorrCurveItem.detach();
|
---|
1027 | meanCurveItem.detach();
|
---|
1028 | }
|
---|
1029 | void UIConnector::slicesPlusPlus()
|
---|
1030 | {
|
---|
1031 | GLWindow->nextSlice();
|
---|
1032 | }
|
---|
1033 | void UIConnector::slicesMinusMinus()
|
---|
1034 | {
|
---|
1035 | GLWindow->previousSlice();
|
---|
1036 | }
|
---|
1037 | void UIConnector::on_calibratedCheckBox_stateChanged(int state)
|
---|
1038 | {
|
---|
1039 | GLWindow->fIsDrsCalibration = state;
|
---|
1040 | GLWindow->ApplyCalibration();
|
---|
1041 | threeD_Window->setData(GLWindow->eventData);
|
---|
1042 |
|
---|
1043 | on_autoScaleColor_clicked();
|
---|
1044 | pixelChanged(GLWindow->selectedPixel);
|
---|
1045 |
|
---|
1046 | }
|
---|
1047 | /************************************************************
|
---|
1048 | * DRAW PATCHES CHECK CHANGE. checkbox handler
|
---|
1049 | ************************************************************/
|
---|
1050 | void UIConnector::on_drawPatchCheckBox_stateChanged(int state)
|
---|
1051 | {
|
---|
1052 | GLWindow->drawPatch = state;
|
---|
1053 | GLWindow->updateGL();
|
---|
1054 | }
|
---|
1055 | /************************************************************
|
---|
1056 | * DRAW IMPULSE CHECK CHANGE. checkbox handler
|
---|
1057 | ************************************************************/
|
---|
1058 | void UIConnector::on_drawImpulseCheckBox_stateChanged(int state)
|
---|
1059 | {
|
---|
1060 | GLWindow->drawImpulse = state;
|
---|
1061 | TriggerOffset_window->drawImpulse = state;
|
---|
1062 | Gain_window->drawImpulse = state;
|
---|
1063 | Baseline_window->drawImpulse = state;
|
---|
1064 | GLWindow->updateGL();
|
---|
1065 | TriggerOffset_window->updateGL();
|
---|
1066 | Gain_window->updateGL();
|
---|
1067 | Baseline_window->updateGL();
|
---|
1068 | }
|
---|
1069 | /************************************************************
|
---|
1070 | * DRAW BLUR CHECK CHANGE. checkbox handler
|
---|
1071 | ************************************************************/
|
---|
1072 | void UIConnector::on_drawBlurCheckBox_stateChanged(int state)
|
---|
1073 | {
|
---|
1074 | GLWindow->drawBlur = state;
|
---|
1075 | GLWindow->updateGL();
|
---|
1076 | }
|
---|
1077 | void UIConnector::on_loopOverCurrentEventBox_stateChanged(int state)
|
---|
1078 | {
|
---|
1079 | GLWindow->loopCurrentEvent = state;
|
---|
1080 | }
|
---|
1081 |
|
---|
1082 | /************************************************************
|
---|
1083 | * NEXT SLICE PLEASE
|
---|
1084 | ************************************************************/
|
---|
1085 | void UIConnector::nextSlicePlease()
|
---|
1086 | {
|
---|
1087 | if (playEventsRadio->isChecked ())
|
---|
1088 | GLWindow->eventStepping(true);
|
---|
1089 | else
|
---|
1090 | if (playPixelsRadio->isChecked())
|
---|
1091 | GLWindow->setCurrentPixel((GLWindow->getCurrentPixel()+1)%1440);
|
---|
1092 | else
|
---|
1093 | GLWindow->nextSlice();
|
---|
1094 | }
|
---|
1095 |
|
---|
1096 | /************************************************************
|
---|
1097 | * SET VIEWER.
|
---|
1098 | ************************************************************/
|
---|
1099 | //void UIConnector::setViewer(RawDataViewer* v)
|
---|
1100 | //{
|
---|
1101 | // viewer = v;
|
---|
1102 | //}
|
---|
1103 | /************************************************************
|
---|
1104 | * SLICES PER SECOND CHANGED. timing ui handler
|
---|
1105 | ************************************************************/
|
---|
1106 | void UIConnector::slicesPerSecondChanged(double value)
|
---|
1107 | {
|
---|
1108 | timer.setInterval(1000.0/value);
|
---|
1109 | }
|
---|
1110 |
|
---|
1111 | void UIConnector::on_colorRange0_valueChanged(double value) { GLWindow->ss[0] = (float)value; GLWindow->updateGL(); }
|
---|
1112 | void UIConnector::on_colorRange1_valueChanged(double value) { GLWindow->ss[1] = (float)value; GLWindow->updateGL(); }
|
---|
1113 | void UIConnector::on_colorRange2_valueChanged(double value) { GLWindow->ss[2] = (float)value; GLWindow->updateGL(); }
|
---|
1114 | void UIConnector::on_colorRange3_valueChanged(double value) { GLWindow->ss[3] = (float)value; GLWindow->updateGL(); }
|
---|
1115 | void UIConnector::on_colorRange4_valueChanged(double value) { GLWindow->ss[4] = (float)value; GLWindow->updateGL(); }
|
---|
1116 |
|
---|
1117 | void UIConnector::on_redValue0_valueChanged(double value) { GLWindow->rr[0] = (float)value; GLWindow->updateGL(); }
|
---|
1118 | void UIConnector::on_redValue1_valueChanged(double value) { GLWindow->rr[1] = (float)value; GLWindow->updateGL(); }
|
---|
1119 | void UIConnector::on_redValue2_valueChanged(double value) { GLWindow->rr[2] = (float)value; GLWindow->updateGL(); }
|
---|
1120 | void UIConnector::on_redValue3_valueChanged(double value) { GLWindow->rr[3] = (float)value; GLWindow->updateGL(); }
|
---|
1121 | void UIConnector::on_redValue4_valueChanged(double value) { GLWindow->rr[4] = (float)value; GLWindow->updateGL(); }
|
---|
1122 |
|
---|
1123 | void UIConnector::on_greenValue0_valueChanged(double value) { GLWindow->gg[0] = (float)value; GLWindow->updateGL(); }
|
---|
1124 | void UIConnector::on_greenValue1_valueChanged(double value) { GLWindow->gg[1] = (float)value; GLWindow->updateGL(); }
|
---|
1125 | void UIConnector::on_greenValue2_valueChanged(double value) { GLWindow->gg[2] = (float)value; GLWindow->updateGL(); }
|
---|
1126 | void UIConnector::on_greenValue3_valueChanged(double value) { GLWindow->gg[3] = (float)value; GLWindow->updateGL(); }
|
---|
1127 | void UIConnector::on_greenValue4_valueChanged(double value) { GLWindow->gg[4] = (float)value; GLWindow->updateGL(); }
|
---|
1128 |
|
---|
1129 | void UIConnector::on_blueValue0_valueChanged(double value) { GLWindow->bb[0] = (float)value; GLWindow->updateGL(); }
|
---|
1130 | void UIConnector::on_blueValue1_valueChanged(double value) { GLWindow->bb[1] = (float)value; GLWindow->updateGL(); }
|
---|
1131 | void UIConnector::on_blueValue2_valueChanged(double value) { GLWindow->bb[2] = (float)value; GLWindow->updateGL(); }
|
---|
1132 | void UIConnector::on_blueValue3_valueChanged(double value) { GLWindow->bb[3] = (float)value; GLWindow->updateGL(); }
|
---|
1133 | void UIConnector::on_blueValue4_valueChanged(double value) { GLWindow->bb[4] = (float)value; GLWindow->updateGL(); }
|
---|
1134 |
|
---|
1135 | /************************************************************
|
---|
1136 | * LOAD NEW FILE CLICKED. button handler
|
---|
1137 | ************************************************************/
|
---|
1138 | void UIConnector::on_loadNewFileButton_clicked()
|
---|
1139 | {
|
---|
1140 | QFileDialog dialog;
|
---|
1141 | dialog.setFileMode(QFileDialog::ExistingFile);
|
---|
1142 | dialog.open(this, SLOT(fileSelected(QString)));
|
---|
1143 | dialog.setVisible(true);
|
---|
1144 | dialog.exec();
|
---|
1145 | }
|
---|
1146 | void UIConnector::on_loadDRSCalibButton_clicked()
|
---|
1147 | {
|
---|
1148 | QFileDialog dialog;
|
---|
1149 | dialog.setFileMode(QFileDialog::ExistingFile);
|
---|
1150 | dialog.open(this, SLOT(calibFileSelected(QString)));
|
---|
1151 | dialog.setVisible(true);
|
---|
1152 | dialog.exec();
|
---|
1153 | }
|
---|
1154 | /************************************************************
|
---|
1155 | * FILE SELECTED. return of the file open dialog handler
|
---|
1156 | ************************************************************/
|
---|
1157 | void UIConnector::fileSelected(QString file)
|
---|
1158 | {
|
---|
1159 | currentFile = file.toStdString();
|
---|
1160 | if (currentFile != "")
|
---|
1161 | GLWindow->openFile(currentFile);
|
---|
1162 | }
|
---|
1163 | void UIConnector::calibFileSelected(QString file)
|
---|
1164 | {
|
---|
1165 | currentCalibFile = file.toStdString();
|
---|
1166 | if (currentCalibFile != "")
|
---|
1167 | GLWindow->openCalibFile(currentCalibFile);
|
---|
1168 | if (GLWindow->fDrsCalib.fRoi != 0)
|
---|
1169 | {//spread the calibration data to the displayers
|
---|
1170 | Baseline_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_BASELINE,
|
---|
1171 | GLWindow->fDrsCalib.fOffset,
|
---|
1172 | GLWindow->fDrsCalib.fRoi,
|
---|
1173 | GLWindow->fDrsCalib.fNumTm);
|
---|
1174 |
|
---|
1175 | Gain_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_GAIN,
|
---|
1176 | GLWindow->fDrsCalib.fGain,
|
---|
1177 | GLWindow->fDrsCalib.fRoi,
|
---|
1178 | GLWindow->fDrsCalib.fNumTm);
|
---|
1179 |
|
---|
1180 | TriggerOffset_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_TRIG_OFFSET,
|
---|
1181 | GLWindow->fDrsCalib.fTrgOff,
|
---|
1182 | GLWindow->fDrsCalib.fRoi,
|
---|
1183 | GLWindow->fDrsCalib.fNumTm);
|
---|
1184 |
|
---|
1185 | }
|
---|
1186 | }
|
---|
1187 | /************************************************************
|
---|
1188 | * NEW FILE LOADED. update of the UI after a new file has been loaded
|
---|
1189 | ************************************************************/
|
---|
1190 | void UIConnector::newFileLoaded()
|
---|
1191 | {
|
---|
1192 | ostringstream str;
|
---|
1193 |
|
---|
1194 | //extract the file name only (no path) from the full name
|
---|
1195 | str << "File: ";
|
---|
1196 | if (currentFile.size() > 2)
|
---|
1197 | str << currentFile.substr(currentFile.find_last_of("//")+1, currentFile.size()) << "\n";
|
---|
1198 | else
|
---|
1199 | str << "--\n";
|
---|
1200 | str << "Calibration: ";
|
---|
1201 | if (currentCalibFile.size() > 2)
|
---|
1202 | str << currentCalibFile.substr(currentCalibFile.find_last_of("//")+1, currentCalibFile.size()) << "\n";
|
---|
1203 | else
|
---|
1204 | str << "--\n";
|
---|
1205 | // fileLoadedLabel->setText(QString(str.str().c_str()));
|
---|
1206 | // str.str("");
|
---|
1207 | str << "Run number: " << GLWindow->runNumber << "\n";
|
---|
1208 | // runNumberLabel->setText(QString(str.str().c_str()));
|
---|
1209 | // str.str("");
|
---|
1210 | str << "Number of Events: " << GLWindow->nRows << "\n";
|
---|
1211 |
|
---|
1212 | displayingEventBox->setMaximum(GLWindow->nRows-1);
|
---|
1213 |
|
---|
1214 | str << "Number of Slices: " << GLWindow->nRoi << "\n";// << "/1024";
|
---|
1215 | // numberOfSlicesLabel->setText(QString(str.str().c_str()));
|
---|
1216 | // str.str("");
|
---|
1217 | str << "Number of Time Marks: " << GLWindow->nTM << "\n";
|
---|
1218 | // numberOfTimeMarksLabel->setText(QString(str.str().c_str()));
|
---|
1219 |
|
---|
1220 | // str.str("");
|
---|
1221 | str << "Run Type: " << GLWindow->runType << "\n";
|
---|
1222 | // runTypeLabel->setText(QString(str.str().c_str()));
|
---|
1223 | // str.str("");
|
---|
1224 | str << "Time of 1st data: " << GLWindow->firstDataTime << "\n";
|
---|
1225 | // firstTimeLabel->setText(QString(str.str().c_str()));
|
---|
1226 | // str.str("");
|
---|
1227 | str << "Time of last data: " << GLWindow->lastDataTime << "\n";
|
---|
1228 | // lastTimeLabel->setText(QString(str.str().c_str()));
|
---|
1229 | // str.str("");
|
---|
1230 | str << "SVN revision: " << GLWindow->revision << '\n';
|
---|
1231 | str << "Number of boards: " << GLWindow->nBoards << '\n';
|
---|
1232 | str << "Number of pixels: " << GLWindow->nPixels << '\n';
|
---|
1233 | str << "Number of Slices TM: " << GLWindow->nRoiTM << '\n';
|
---|
1234 | str << "Time system: " << GLWindow->timeSystem << '\n';
|
---|
1235 | str << "Date: " << GLWindow->creationDate << '\n';
|
---|
1236 | str << "Night: " << GLWindow->nightInt << '\n';
|
---|
1237 | str << "Camera: " << GLWindow->camera << '\n';
|
---|
1238 | str << "DAQ: " << GLWindow->daq << '\n';
|
---|
1239 | str << "ADC Count: " << GLWindow->adcCount << '\n';
|
---|
1240 | str << "NB Evts OK:" << GLWindow->nbOk << '\n';
|
---|
1241 | str << "NB Evts Rejected: " << GLWindow->nbRej << '\n';
|
---|
1242 | str << "NB Evts Bad: " << GLWindow->nbBad << '\n';
|
---|
1243 | extraInfoLabel->setText(QString(str.str().c_str()));
|
---|
1244 |
|
---|
1245 | /*
|
---|
1246 | if (GLWindow->calibrationLoaded)
|
---|
1247 | {
|
---|
1248 | drawCalibrationCheckBox->setEnabled(true);
|
---|
1249 | }*/
|
---|
1250 |
|
---|
1251 |
|
---|
1252 | }
|
---|
1253 | /************************************************************
|
---|
1254 | * PLAY PAUSE CLICKED. ui handler
|
---|
1255 | ************************************************************/
|
---|
1256 | void UIConnector::on_playPauseButton_clicked()
|
---|
1257 | {
|
---|
1258 | if (timer.isActive())
|
---|
1259 | timer.stop();
|
---|
1260 | else
|
---|
1261 | timer.start();
|
---|
1262 | }
|
---|
1263 |
|
---|
1264 | void UIConnector::displaySliceValue()
|
---|
1265 | {
|
---|
1266 | if (!GLWindow->nRoi)
|
---|
1267 | return;
|
---|
1268 | if (GLWindow->selectedPixel == -1)
|
---|
1269 | {
|
---|
1270 | ostringstream str;
|
---|
1271 | str << " Current Pixel val.: --";
|
---|
1272 | currentPixelValue->setText(QString(str.str().c_str()));
|
---|
1273 | return;
|
---|
1274 | }
|
---|
1275 | const int idx =
|
---|
1276 | GLWindow->nRoi*GLWindow->hardwareMapping[GLWindow->selectedPixel]
|
---|
1277 | + GLWindow->whichSlice;
|
---|
1278 |
|
---|
1279 | ostringstream str;
|
---|
1280 | str << "Current Pixel val.: " << GLWindow->eventData[idx];
|
---|
1281 | currentPixelValue->setText(QString(str.str().c_str()));
|
---|
1282 | }
|
---|
1283 |
|
---|
1284 | /************************************************************
|
---|
1285 | * CURRENT SLICE HAS CHANGE. ui handler
|
---|
1286 | ************************************************************/
|
---|
1287 | void UIConnector::currentSliceHasChanged(int slice)
|
---|
1288 | {
|
---|
1289 | if (!GLWindow->nRoi)
|
---|
1290 | return;
|
---|
1291 |
|
---|
1292 | if (updateSpinnerDisplay)
|
---|
1293 | displayingSliceBox->setValue(slice);
|
---|
1294 |
|
---|
1295 | displaySliceValue();
|
---|
1296 | }
|
---|
1297 |
|
---|
1298 | /*****
|
---|
1299 | *******************************************************
|
---|
1300 | * CURRENT EVENT HAS CHANGED. ui handler
|
---|
1301 | ************************************************************/
|
---|
1302 |
|
---|
1303 | double xval[50000];
|
---|
1304 | double yval[50000];
|
---|
1305 | void UIConnector::on_displayingEventBox_valueChanged(int cEvent)
|
---|
1306 | {
|
---|
1307 | // cout << "Here " << updateSpinnerDisplay << endl;
|
---|
1308 | if (!updateSpinnerDisplay)
|
---|
1309 | return;
|
---|
1310 | updateSpinnerDisplay = false;
|
---|
1311 | // currentEventHasChanged(cEvent);
|
---|
1312 | GLWindow->rowNum = cEvent - GLWindow->eventStep;
|
---|
1313 | GLWindow->eventStepping(true);
|
---|
1314 | updateSpinnerDisplay = true;
|
---|
1315 |
|
---|
1316 | // GLWindow->updateGL();
|
---|
1317 | }
|
---|
1318 | void UIConnector::on_slicesPerSecValue_valueChanged(double value)
|
---|
1319 | {
|
---|
1320 | timer.setInterval(1000.0/value);
|
---|
1321 | }
|
---|
1322 | void UIConnector::on_displayingSliceBox_valueChanged(int cSlice)
|
---|
1323 | {
|
---|
1324 | updateSpinnerDisplay = false;
|
---|
1325 | currentSliceHasChanged(cSlice);
|
---|
1326 | updateSpinnerDisplay = true;
|
---|
1327 | GLWindow->whichSlice = cSlice;
|
---|
1328 | GLWindow->updateGL();
|
---|
1329 | }
|
---|
1330 | void UIConnector::currentEventHasChanged(int )
|
---|
1331 | {
|
---|
1332 |
|
---|
1333 | RMS_window->SetData(GLWindow->RMSvalues);
|
---|
1334 | Mean_window->SetData(GLWindow->Meanvalues);
|
---|
1335 | PosOfMax_window->SetData(GLWindow->PosOfMaxvalues);
|
---|
1336 | Max_window->SetData(GLWindow->Maxvalues);
|
---|
1337 | threeD_Window->setData(GLWindow->eventData);//rawEventData);
|
---|
1338 |
|
---|
1339 | if (RMS_window->isVisible())
|
---|
1340 | RMS_window->updateGL();
|
---|
1341 | if (Mean_window->isVisible())
|
---|
1342 | Mean_window->updateGL();
|
---|
1343 | if (PosOfMax_window->isVisible())
|
---|
1344 | PosOfMax_window->updateGL();
|
---|
1345 | if (Max_window->isVisible())
|
---|
1346 | Max_window->updateGL();
|
---|
1347 | ostringstream str;
|
---|
1348 | // str << "Displaying Event " << cEvent;
|
---|
1349 | // QString qstr(str.str().c_str());
|
---|
1350 | // emit updateCurrentEventDisplay(qstr);
|
---|
1351 | if (updateSpinnerDisplay)
|
---|
1352 | {
|
---|
1353 | updateSpinnerDisplay = false;
|
---|
1354 | displayingEventBox->setValue(GLWindow->rowNum);
|
---|
1355 | updateSpinnerDisplay = true;
|
---|
1356 | }
|
---|
1357 |
|
---|
1358 | // GLWindow->doWaveLetOnCurrentEventPlease();
|
---|
1359 |
|
---|
1360 | //retrieve the data that we want to display
|
---|
1361 | boost::posix_time::ptime hrTime( boost::gregorian::date(1970, boost::gregorian::Jan, 1),
|
---|
1362 | boost::posix_time::seconds(GLWindow->pcTime[0]) + boost::posix_time::microsec(GLWindow->pcTime[1]));
|
---|
1363 |
|
---|
1364 | str.str("");
|
---|
1365 | str << "PC Time: " << boost::posix_time::to_iso_extended_string(hrTime);
|
---|
1366 | PCTimeLabel->setText(QString(str.str().c_str()));
|
---|
1367 |
|
---|
1368 | str.str("");
|
---|
1369 | str << "Software Trigger: " << GLWindow->softTrig;
|
---|
1370 | softwareTriggerLabel->setText(QString(str.str().c_str()));
|
---|
1371 |
|
---|
1372 | str.str("");
|
---|
1373 | str << "Trigger Type: " << GLWindow->triggerType;
|
---|
1374 | triggerTypeLabel->setText(QString(str.str().c_str()));
|
---|
1375 |
|
---|
1376 | displaySliceValue();
|
---|
1377 |
|
---|
1378 | if (autoScaleColor->isChecked())
|
---|
1379 | emit GLWindow->colorPaletteHasChanged();//autoScalePressed();
|
---|
1380 |
|
---|
1381 | boardsTimeList->clear();
|
---|
1382 | startPixelsList->clear();
|
---|
1383 | startTimeMarksList->clear();
|
---|
1384 | triggerDelayList->clear();
|
---|
1385 | std::map<int, int> boardsHistoMap;
|
---|
1386 | for (int i=0;i <NBOARDS; i++)
|
---|
1387 | {
|
---|
1388 | str.str("");
|
---|
1389 | str << i;
|
---|
1390 | if (i<10) str << " ";
|
---|
1391 | if (i<100) str << " ";
|
---|
1392 | if (i<1000) str << " ";
|
---|
1393 | str << ": " << GLWindow->boardTime[i];
|
---|
1394 | boardsTimeList->addItem(QString(str.str().c_str()));
|
---|
1395 | if (boardsHistoMap.find(GLWindow->boardTime[i]) != boardsHistoMap.end())
|
---|
1396 | boardsHistoMap[GLWindow->boardTime[i]]++;
|
---|
1397 | else
|
---|
1398 | boardsHistoMap[GLWindow->boardTime[i]] = 1;
|
---|
1399 | }
|
---|
1400 | std::map<int, int> pixelHistoMap;
|
---|
1401 | for (int i=0;i <NPIX; i++)
|
---|
1402 | {
|
---|
1403 | str.str("");
|
---|
1404 | str << i;
|
---|
1405 | if (i<10) str << " ";
|
---|
1406 | if (i<100) str << " ";
|
---|
1407 | if (i<1000) str << " ";
|
---|
1408 | str << ": " << GLWindow->startPix[i];
|
---|
1409 | startPixelsList->addItem(QString(str.str().c_str()));
|
---|
1410 | if (pixelHistoMap.find(GLWindow->startPix[i]) != pixelHistoMap.end())
|
---|
1411 | pixelHistoMap[GLWindow->startPix[i]]++;
|
---|
1412 | else
|
---|
1413 | pixelHistoMap[GLWindow->startPix[i]] = 1;
|
---|
1414 | }
|
---|
1415 |
|
---|
1416 | std::map<int, int> timeMarksMap;
|
---|
1417 | for (int i=0;i <NTMARK; i++)
|
---|
1418 | {
|
---|
1419 | str.str("");
|
---|
1420 | str << i;
|
---|
1421 | if (i<10) str << " ";
|
---|
1422 | if (i<100) str << " ";
|
---|
1423 | if (i<1000) str << " ";
|
---|
1424 | str << ": " << GLWindow->startTM[i];
|
---|
1425 | startTimeMarksList->addItem(QString(str.str().c_str()));
|
---|
1426 | if (timeMarksMap.find(GLWindow->startTM[i]) != timeMarksMap.end())
|
---|
1427 | timeMarksMap[GLWindow->startTM[i]]++;
|
---|
1428 | else
|
---|
1429 | timeMarksMap[GLWindow->startTM[i]] = 1;
|
---|
1430 | }
|
---|
1431 | std::map<int,int> delayMap;
|
---|
1432 | triggerDelayList->addItem(QString("Patch | Slice:Delay Slice:Delay..."));
|
---|
1433 | for (int i=0;i<NTMARK; i++)
|
---|
1434 | {
|
---|
1435 | str.str("");
|
---|
1436 | str << i << " | ";
|
---|
1437 | for (int j=0;j<GLWindow->nRoi;j++)
|
---|
1438 | {
|
---|
1439 | int value = GLWindow->eventData[1440*GLWindow->nRoi + i*GLWindow->nRoi + j];
|
---|
1440 | if (delayMap.find(value) != delayMap.end())
|
---|
1441 | delayMap[value]++;
|
---|
1442 | else
|
---|
1443 | delayMap[value] = 1;
|
---|
1444 | str << j << ":" << value << " ";
|
---|
1445 | }
|
---|
1446 | triggerDelayList->addItem(QString(str.str().c_str()));
|
---|
1447 | }
|
---|
1448 |
|
---|
1449 | std::map<int,int>::iterator it = boardsHistoMap.begin();
|
---|
1450 | int nsamples = 0;
|
---|
1451 | int previousValue = it->first-10;
|
---|
1452 | for (unsigned int i=0;i<boardsHistoMap.size();i++)
|
---|
1453 | {
|
---|
1454 | if (previousValue != it->first-1)
|
---|
1455 | {
|
---|
1456 | xval[nsamples] = previousValue+1;
|
---|
1457 | yval[nsamples] = 0;
|
---|
1458 | nsamples++;
|
---|
1459 | xval[nsamples] = it->first-1;
|
---|
1460 | yval[nsamples] = 0;
|
---|
1461 | nsamples++;
|
---|
1462 | }
|
---|
1463 | xval[nsamples] = it->first;
|
---|
1464 | yval[nsamples] = it->second;
|
---|
1465 | previousValue = it->first;
|
---|
1466 | it++;
|
---|
1467 | nsamples++;
|
---|
1468 | xval[nsamples] = previousValue;
|
---|
1469 | yval[nsamples] = 0;
|
---|
1470 | nsamples++;
|
---|
1471 | if (nsamples > 4090)
|
---|
1472 | {
|
---|
1473 | cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
|
---|
1474 | break;
|
---|
1475 | }
|
---|
1476 | }
|
---|
1477 | xval[nsamples] = it==boardsHistoMap.begin() ? 0 : (--it)->first+1;
|
---|
1478 | yval[nsamples] = 0;
|
---|
1479 | nsamples++;
|
---|
1480 | // if (nsamples > 5)
|
---|
1481 | #if QWT_VERSION < 0x060000
|
---|
1482 | boardsTimeHistoItem.setData(xval, yval, nsamples);
|
---|
1483 | #else
|
---|
1484 | boardsTimeHistoItem.setSamples(xval, yval, nsamples);
|
---|
1485 | #endif
|
---|
1486 |
|
---|
1487 | it = pixelHistoMap.begin();
|
---|
1488 | nsamples = 0;
|
---|
1489 | previousValue = it->first-10;
|
---|
1490 | for (unsigned int i=0;i<pixelHistoMap.size();i++)
|
---|
1491 | {
|
---|
1492 | if (previousValue != it->first-1)
|
---|
1493 | {
|
---|
1494 | xval[nsamples] = previousValue+1;
|
---|
1495 | yval[nsamples] = 0;
|
---|
1496 | nsamples++;
|
---|
1497 | xval[nsamples] = it->first-1;
|
---|
1498 | yval[nsamples] = 0;
|
---|
1499 | nsamples++;
|
---|
1500 | }
|
---|
1501 | xval[nsamples] = it->first;
|
---|
1502 | yval[nsamples] = it->second;
|
---|
1503 | previousValue = it->first;
|
---|
1504 | it++;
|
---|
1505 | nsamples++;
|
---|
1506 | xval[nsamples] = previousValue;
|
---|
1507 | yval[nsamples] = 0;
|
---|
1508 | nsamples++;
|
---|
1509 | if (nsamples > 4090)
|
---|
1510 | {
|
---|
1511 | cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
|
---|
1512 | break;
|
---|
1513 | }
|
---|
1514 | }
|
---|
1515 | xval[nsamples] = it==pixelHistoMap.begin() ? 0 : (--it)->first+1;
|
---|
1516 | yval[nsamples] = 0;
|
---|
1517 | nsamples++;
|
---|
1518 | // if (nsamples > 5)
|
---|
1519 | #if QWT_VERSION < 0x060000
|
---|
1520 | startCellHistoItem.setData(xval, yval, nsamples);
|
---|
1521 | #else
|
---|
1522 | startCellHistoItem.setSamples(xval, yval, nsamples);
|
---|
1523 | #endif
|
---|
1524 |
|
---|
1525 | it = timeMarksMap.begin();
|
---|
1526 | nsamples = 0;
|
---|
1527 | previousValue = it->first-10;
|
---|
1528 | for (unsigned int i=0;i<timeMarksMap.size();i++)
|
---|
1529 | {
|
---|
1530 | if (previousValue != it->first-1)
|
---|
1531 | {
|
---|
1532 | xval[nsamples] = previousValue+1;
|
---|
1533 | yval[nsamples] = 0;
|
---|
1534 | nsamples++;
|
---|
1535 | xval[nsamples] = it->first-1;
|
---|
1536 | yval[nsamples] = 0;
|
---|
1537 | nsamples++;
|
---|
1538 | }
|
---|
1539 | xval[nsamples] = it->first;
|
---|
1540 | yval[nsamples] = it->second;
|
---|
1541 | previousValue = it->first;
|
---|
1542 | it++;
|
---|
1543 | nsamples++;
|
---|
1544 | xval[nsamples] = previousValue;
|
---|
1545 | yval[nsamples] = 0;
|
---|
1546 | nsamples++;
|
---|
1547 | if (nsamples > 4090)
|
---|
1548 | {
|
---|
1549 | cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
|
---|
1550 | break;
|
---|
1551 | }
|
---|
1552 | }
|
---|
1553 | xval[nsamples] = it==timeMarksMap.begin() ? 0 : (--it)->first+1;
|
---|
1554 | yval[nsamples] = 0;
|
---|
1555 | nsamples++;
|
---|
1556 | // if (nsamples > 5)
|
---|
1557 | #if QWT_VERSION < 0x060000
|
---|
1558 | startTimeMarkHistoItem.setData(xval, yval, nsamples);
|
---|
1559 | #else
|
---|
1560 | startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
|
---|
1561 | #endif
|
---|
1562 |
|
---|
1563 | it = delayMap.begin();
|
---|
1564 | nsamples = 0;
|
---|
1565 | previousValue = it->first-10;
|
---|
1566 | for (unsigned int i=0;i<delayMap.size();i++)
|
---|
1567 | {
|
---|
1568 | if (previousValue != it->first-1)
|
---|
1569 | {
|
---|
1570 | xval[nsamples] = previousValue+1;
|
---|
1571 | yval[nsamples] = 0;
|
---|
1572 | nsamples++;
|
---|
1573 | xval[nsamples] = it->first-1;
|
---|
1574 | yval[nsamples] = 0;
|
---|
1575 | nsamples++;
|
---|
1576 | }
|
---|
1577 | xval[nsamples] = it->first;
|
---|
1578 | yval[nsamples] = it->second;
|
---|
1579 | previousValue = it->first;
|
---|
1580 | it++;
|
---|
1581 | nsamples++;
|
---|
1582 | xval[nsamples] = previousValue;
|
---|
1583 | yval[nsamples] = 0;
|
---|
1584 | nsamples++;
|
---|
1585 | if (nsamples > 4090)
|
---|
1586 | {
|
---|
1587 | cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
|
---|
1588 | break;
|
---|
1589 | }
|
---|
1590 | }
|
---|
1591 | xval[nsamples] = it==delayMap.begin() ? 0 : (--it)->first+1;
|
---|
1592 | yval[nsamples] = 0;
|
---|
1593 | nsamples++;
|
---|
1594 | // if (nsamples > 5)
|
---|
1595 | #if QWT_VERSION < 0x060000
|
---|
1596 | triggerDelayHistoItem.setData(xval, yval, nsamples);
|
---|
1597 | #else
|
---|
1598 | triggerDelayHistoItem.setSamples(xval, yval, nsamples);
|
---|
1599 | #endif
|
---|
1600 | //WAVELETS HACK
|
---|
1601 | /* std::map<int, int> valuesHistoMap;
|
---|
1602 | std::map<int, int> waveletHistoMap;
|
---|
1603 | for (int i=0;i<1024*1440;i++)
|
---|
1604 | {
|
---|
1605 | if (valuesHistoMap.find(GLWindow->rawEventData[i]) != valuesHistoMap.end())
|
---|
1606 | valuesHistoMap[GLWindow->rawEventData[i]]++;
|
---|
1607 | else
|
---|
1608 | valuesHistoMap[GLWindow->rawEventData[i]] = 1;
|
---|
1609 | if (waveletHistoMap.find(GLWindow->waveLetArray[i]) != waveletHistoMap.end())
|
---|
1610 | waveletHistoMap[GLWindow->waveLetArray[i]]++;
|
---|
1611 | else
|
---|
1612 | waveletHistoMap[GLWindow->waveLetArray[i]] = 1;
|
---|
1613 | }
|
---|
1614 |
|
---|
1615 | it = valuesHistoMap.begin();
|
---|
1616 | nsamples = 0;
|
---|
1617 | previousValue = it->first-10;
|
---|
1618 | cout << "Num values Original: " << valuesHistoMap.size() << endl;
|
---|
1619 | for (unsigned int i=0;i<valuesHistoMap.size();i++)
|
---|
1620 | {
|
---|
1621 | if (previousValue != it->first-1)
|
---|
1622 | {
|
---|
1623 | xval[nsamples] = previousValue+1;
|
---|
1624 | yval[nsamples] = 0;
|
---|
1625 | nsamples++;
|
---|
1626 | xval[nsamples] = it->first-1;
|
---|
1627 | yval[nsamples] = 0;
|
---|
1628 | nsamples++;
|
---|
1629 | }
|
---|
1630 | xval[nsamples] = it->first;
|
---|
1631 | yval[nsamples] = it->second;
|
---|
1632 | previousValue = it->first;
|
---|
1633 | it++;
|
---|
1634 | nsamples++;
|
---|
1635 | xval[nsamples] = previousValue;
|
---|
1636 | yval[nsamples] = 0;
|
---|
1637 | nsamples++;
|
---|
1638 | if (nsamples > 50000)
|
---|
1639 | {
|
---|
1640 | cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
|
---|
1641 | break;
|
---|
1642 | }
|
---|
1643 | }
|
---|
1644 | xval[nsamples] = it==valuesHistoMap.begin() ? 0 : (--it)->first+1;
|
---|
1645 | yval[nsamples] = 0;
|
---|
1646 | nsamples++;
|
---|
1647 | // if (nsamples > 5)
|
---|
1648 | #if QWT_VERSION < 0x060000
|
---|
1649 | triggerDelayHistoItem.setData(xval, yval, nsamples);
|
---|
1650 | #else
|
---|
1651 | triggerDelayHistoItem.setSamples(xval, yval, nsamples);
|
---|
1652 | #endif
|
---|
1653 |
|
---|
1654 | it = waveletHistoMap.begin();
|
---|
1655 | nsamples = 0;
|
---|
1656 | previousValue = it->first-10;
|
---|
1657 | cout << "Num values WaveLets: " << waveletHistoMap.size() << endl;
|
---|
1658 | for (unsigned int i=0;i<waveletHistoMap.size();i++)
|
---|
1659 | {
|
---|
1660 | if (previousValue != it->first-1)
|
---|
1661 | {
|
---|
1662 | xval[nsamples] = previousValue+1;
|
---|
1663 | yval[nsamples] = 0;
|
---|
1664 | nsamples++;
|
---|
1665 | xval[nsamples] = it->first-1;
|
---|
1666 | yval[nsamples] = 0;
|
---|
1667 | nsamples++;
|
---|
1668 | }
|
---|
1669 | xval[nsamples] = it->first;
|
---|
1670 | yval[nsamples] = it->second;
|
---|
1671 | previousValue = it->first;
|
---|
1672 | it++;
|
---|
1673 | nsamples++;
|
---|
1674 | xval[nsamples] = previousValue;
|
---|
1675 | yval[nsamples] = 0;
|
---|
1676 | nsamples++;
|
---|
1677 | if (nsamples > 50000)
|
---|
1678 | {
|
---|
1679 | cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
|
---|
1680 | break;
|
---|
1681 | }
|
---|
1682 | }
|
---|
1683 | xval[nsamples] = it==waveletHistoMap.begin() ? 0 : (--it)->first+1;
|
---|
1684 | yval[nsamples] = 0;
|
---|
1685 | nsamples++;
|
---|
1686 | // if (nsamples > 5)
|
---|
1687 | #if QWT_VERSION < 0x060000
|
---|
1688 | startTimeMarkHistoItem.setData(xval, yval, nsamples);
|
---|
1689 | #else
|
---|
1690 | startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
|
---|
1691 | #endif
|
---|
1692 | */
|
---|
1693 | //END OF WAVELETS HACK
|
---|
1694 | // startCellHistoZoom->setZoomBase(startCellHistoItem.boundingRect());
|
---|
1695 | QStack< QRectF > stack;
|
---|
1696 | // QRectF cRectangle = boardsTimeHistoItem.boundingRect();
|
---|
1697 | stack.push(scaleBoundingRectangle(boardsTimeHistoItem.boundingRect(), 1.05f));//cRectangle);//boardsTimeHistoItem.boundingRect());
|
---|
1698 | boardsTimeHistoZoom->setZoomStack(stack);
|
---|
1699 | stack.pop();
|
---|
1700 | stack.push(scaleBoundingRectangle(startCellHistoItem.boundingRect(), 1.05f));
|
---|
1701 | startCellHistoZoom->setZoomStack(stack);
|
---|
1702 | stack.pop();
|
---|
1703 | stack.push(scaleBoundingRectangle(startTimeMarkHistoItem.boundingRect(), 1.05f));
|
---|
1704 | startTimeMarkHistoZoom->setZoomStack(stack);
|
---|
1705 | stack.pop();
|
---|
1706 | stack.push(scaleBoundingRectangle(triggerDelayHistoItem.boundingRect(), 1.05f));
|
---|
1707 | triggerDelayHistoZoom->setZoomStack(stack);
|
---|
1708 | stack.pop();
|
---|
1709 |
|
---|
1710 | pixelChanged(GLWindow->selectedPixel);
|
---|
1711 | }
|
---|
1712 | //can't use a ref to rectangle, as the type must be converted first
|
---|
1713 | QRectF UIConnector::scaleBoundingRectangle(QRectF rectangle, float scale)
|
---|
1714 | {
|
---|
1715 | QPointF bottomRight = rectangle.bottomRight();
|
---|
1716 | QPointF topLeft = rectangle.topLeft();
|
---|
1717 | QPointF center = rectangle.center();
|
---|
1718 | return QRectF(topLeft + (topLeft-center)*(scale-1.0f), //top left
|
---|
1719 | bottomRight + (bottomRight-center)*(scale-1.0f)); //bottom right
|
---|
1720 | }
|
---|
1721 | void UIConnector::initHistograms()
|
---|
1722 | {
|
---|
1723 | // QwtPlot* boardsTimeHisto;
|
---|
1724 | // QwtPlotHistogram boardsTimeHistoItem;
|
---|
1725 | grid1 = new QwtPlotGrid;
|
---|
1726 | grid1->enableX(false);
|
---|
1727 | grid1->enableY(true);
|
---|
1728 | grid1->enableXMin(false);
|
---|
1729 | grid1->enableYMin(false);
|
---|
1730 | grid1->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
|
---|
1731 | grid1->attach(boardsTimeHisto);
|
---|
1732 |
|
---|
1733 | grid2 = new QwtPlotGrid;
|
---|
1734 | grid2->enableX(false);
|
---|
1735 | grid2->enableY(true);
|
---|
1736 | grid2->enableXMin(false);
|
---|
1737 | grid2->enableYMin(false);
|
---|
1738 | grid2->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
|
---|
1739 | grid2->attach(startCellsHisto);
|
---|
1740 |
|
---|
1741 | grid3 = new QwtPlotGrid;
|
---|
1742 | grid3->enableX(false);
|
---|
1743 | grid3->enableY(true);
|
---|
1744 | grid3->enableXMin(false);
|
---|
1745 | grid3->enableYMin(false);
|
---|
1746 | grid3->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
|
---|
1747 | grid3->attach(startTimeMarkHisto);
|
---|
1748 |
|
---|
1749 | grid4 = new QwtPlotGrid;
|
---|
1750 | grid4->enableX(false);
|
---|
1751 | grid4->enableY(true);
|
---|
1752 | grid4->enableXMin(false);
|
---|
1753 | grid4->enableYMin(false);
|
---|
1754 | grid4->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
|
---|
1755 | grid4->attach(pixelValueCurve);
|
---|
1756 |
|
---|
1757 | grid6 = new QwtPlotGrid;
|
---|
1758 | grid6->enableX(false);
|
---|
1759 | grid6->enableY(true);
|
---|
1760 | grid6->enableXMin(false);
|
---|
1761 | grid6->enableYMin(false);
|
---|
1762 | grid6->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
|
---|
1763 | grid6->attach(pixelAverageCurve);
|
---|
1764 |
|
---|
1765 | grid5 = new QwtPlotGrid;
|
---|
1766 | grid5->enableX(false);
|
---|
1767 | grid5->enableY(true);
|
---|
1768 | grid5->enableXMin(false);
|
---|
1769 | grid5->enableYMin(false);
|
---|
1770 | grid5->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
|
---|
1771 | grid5->attach(triggerDelayHisto);
|
---|
1772 |
|
---|
1773 | boardsTimeHisto->setAutoReplot(true);
|
---|
1774 | startCellsHisto->setAutoReplot(true);
|
---|
1775 | startTimeMarkHisto->setAutoReplot(true);
|
---|
1776 | pixelValueCurve->setAutoReplot(true);
|
---|
1777 | pixelAverageCurve->setAutoReplot(true);
|
---|
1778 | triggerDelayHisto->setAutoReplot(true);
|
---|
1779 | boardsTimeHisto->setTitle("Boards time values");
|
---|
1780 | startCellsHisto->setTitle("Start Cell values");
|
---|
1781 | startTimeMarkHisto->setTitle("Start Time Marks values");
|
---|
1782 | pixelValueCurve->setTitle("Current pixel values");
|
---|
1783 | pixelAverageCurve->setTitle("Average pixels values");
|
---|
1784 | triggerDelayHisto->setTitle("Trigger Delays");
|
---|
1785 |
|
---|
1786 | // boardsTimeHistoItem.setBrush(QBrush(Qt::red));
|
---|
1787 | // startCellHistoItem.setBrush(QBrush(Qt::red));
|
---|
1788 | // startTimeMarkHistoItem.setBrush(QBrush(Qt::red));
|
---|
1789 | // triggerDelayHistoItem.setBrush(QBrush(Qt::red));
|
---|
1790 | // pixelValueCurveItem.setBrush(QBrush(Qt::red));
|
---|
1791 |
|
---|
1792 | boardsTimeHistoItem.setPen(QColor(Qt::darkGreen));
|
---|
1793 | boardsTimeHistoItem.setStyle(QwtPlotCurve::Steps);
|
---|
1794 | startCellHistoItem.setPen(QColor(Qt::darkGreen));
|
---|
1795 | startCellHistoItem.setStyle(QwtPlotCurve::Steps);
|
---|
1796 | startTimeMarkHistoItem.setPen(QColor(Qt::darkGreen));
|
---|
1797 | startTimeMarkHistoItem.setStyle(QwtPlotCurve::Steps);
|
---|
1798 | triggerDelayHistoItem.setPen(QColor(Qt::darkGreen));
|
---|
1799 | triggerDelayHistoItem.setStyle(QwtPlotCurve::Steps);
|
---|
1800 |
|
---|
1801 | boardsTimeHistoItem.attach(boardsTimeHisto);
|
---|
1802 | startCellHistoItem.attach(startCellsHisto);
|
---|
1803 | startTimeMarkHistoItem.attach(startTimeMarkHisto);
|
---|
1804 | triggerDelayHistoItem.attach(triggerDelayHisto);
|
---|
1805 |
|
---|
1806 | //curve
|
---|
1807 | // pixelValueCurveItem.setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::black), QSize(5,5)));
|
---|
1808 | pixelValueCurveItem.setPen(QColor(Qt::black));
|
---|
1809 | pixelAverageCurveItem.setPen(QColor(Qt::black));
|
---|
1810 | aMeanCurveItem.setPen(QColor(Qt::darkGreen));
|
---|
1811 | vCorrCurveItem.setPen(QColor(Qt::red));
|
---|
1812 | meanCurveItem.setPen(QColor(Qt::blue));
|
---|
1813 | pixelValueCurveItem.setStyle(QwtPlotCurve::Lines);
|
---|
1814 | pixelAverageCurveItem.setStyle(QwtPlotCurve::Lines);
|
---|
1815 | aMeanCurveItem.setStyle(QwtPlotCurve::Lines);
|
---|
1816 | vCorrCurveItem.setStyle(QwtPlotCurve::Lines);
|
---|
1817 | meanCurveItem.setStyle(QwtPlotCurve::Lines);
|
---|
1818 |
|
---|
1819 | // pixelValueCurveItem.setCurveAttribute(QwtPlotCurve::Fitted);
|
---|
1820 | pixelValueCurveItem.attach(pixelValueCurve);
|
---|
1821 | pixelAverageCurveItem.attach(pixelAverageCurve);
|
---|
1822 | // aMeanCurveItem.attach(pixelValueCurve);
|
---|
1823 | // vCorrCurveItem.attach(pixelValueCurve);
|
---|
1824 | // meanCurveItem.attach(pixelValueCurve);
|
---|
1825 |
|
---|
1826 | //FIXME delete these pointers with the destructor
|
---|
1827 | curveZoom = new QwtPlotZoomer(pixelValueCurve->canvas());
|
---|
1828 | curveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
|
---|
1829 | curveZoom->setTrackerPen(QPen(Qt::gray));
|
---|
1830 | averageCurveZoom = new QwtPlotZoomer(pixelAverageCurve->canvas());
|
---|
1831 | averageCurveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
|
---|
1832 | averageCurveZoom->setTrackerPen(QPen(Qt::gray));
|
---|
1833 |
|
---|
1834 | boardsTimeHistoZoom = new QwtPlotZoomer(boardsTimeHisto->canvas());
|
---|
1835 | boardsTimeHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
|
---|
1836 | boardsTimeHistoZoom->setTrackerPen(QPen(Qt::gray));
|
---|
1837 |
|
---|
1838 | startCellHistoZoom = new QwtPlotZoomer(startCellsHisto->canvas());
|
---|
1839 | startCellHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
|
---|
1840 | startCellHistoZoom->setTrackerPen(QPen(Qt::gray));
|
---|
1841 |
|
---|
1842 | startTimeMarkHistoZoom = new QwtPlotZoomer(startTimeMarkHisto->canvas());
|
---|
1843 | startTimeMarkHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
|
---|
1844 | startTimeMarkHistoZoom->setTrackerPen(QPen(Qt::gray));
|
---|
1845 |
|
---|
1846 | triggerDelayHistoZoom = new QwtPlotZoomer(triggerDelayHisto->canvas());
|
---|
1847 | triggerDelayHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
|
---|
1848 | triggerDelayHistoZoom->setTrackerPen(QPen(Qt::gray));
|
---|
1849 |
|
---|
1850 |
|
---|
1851 | }
|
---|
1852 |
|
---|
1853 | void UIConnector::pixelChanged(int pixel)
|
---|
1854 | {
|
---|
1855 | RMS_window->fWhite = pixel;
|
---|
1856 | Mean_window->fWhite = pixel;
|
---|
1857 | Max_window->fWhite = pixel;
|
---|
1858 | PosOfMax_window->fWhite = pixel;
|
---|
1859 | if (pixel != -1)
|
---|
1860 | {
|
---|
1861 | RMS_window->fWhitePatch = RMS_window->pixelsPatch[pixel];
|
---|
1862 | Mean_window->fWhitePatch = Mean_window->pixelsPatch[pixel];
|
---|
1863 | Max_window->fWhitePatch = Max_window->pixelsPatch[pixel];
|
---|
1864 | PosOfMax_window->fWhitePatch = PosOfMax_window->pixelsPatch[pixel];
|
---|
1865 | }
|
---|
1866 | else
|
---|
1867 | {
|
---|
1868 | RMS_window->fWhitePatch = -1;
|
---|
1869 | Mean_window->fWhitePatch = -1;
|
---|
1870 | Max_window->fWhitePatch = -1;
|
---|
1871 | PosOfMax_window->fWhitePatch = -1;
|
---|
1872 | }
|
---|
1873 | if (pixel == -1)
|
---|
1874 | return;
|
---|
1875 | int softwarePix = pixel;
|
---|
1876 | pixel = GLWindow->hardwareMapping[pixel];
|
---|
1877 |
|
---|
1878 | HwIDBox->setValue(pixel);
|
---|
1879 |
|
---|
1880 | if (!GLWindow->nRoi)
|
---|
1881 | return;
|
---|
1882 |
|
---|
1883 | int currentPixel = pixel;
|
---|
1884 |
|
---|
1885 | for (int i=0;i<GLWindow->nRoi;i++)
|
---|
1886 | {
|
---|
1887 | xval[i] = i;
|
---|
1888 | yval[i] = GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
|
---|
1889 | }
|
---|
1890 |
|
---|
1891 |
|
---|
1892 | int realNumSamples = GLWindow->nRoi;
|
---|
1893 | if (GLWindow->nRoiTM != 0)
|
---|
1894 | {
|
---|
1895 | const PixelMapEntry& mapEntry = GLWindow->fPixelMap.index(softwarePix);
|
---|
1896 | const int pixelIdInPatch = mapEntry.pixel();
|
---|
1897 | const int patchId = mapEntry.patch();
|
---|
1898 | const int boardId = mapEntry.board();
|
---|
1899 | const int crateId = mapEntry.crate();
|
---|
1900 | if (pixelIdInPatch == 8)
|
---|
1901 | {
|
---|
1902 | int TMIndex = 0;
|
---|
1903 | int xIndex = GLWindow->nRoi;
|
---|
1904 | int arrayIndex = GLWindow->nRoi;
|
---|
1905 | if (GLWindow->offSetRoi < 0)
|
---|
1906 | TMIndex -= GLWindow->offSetRoi;
|
---|
1907 | if (GLWindow->offSetRoi > 0)
|
---|
1908 | xIndex += GLWindow->offSetRoi;
|
---|
1909 | for (int i=TMIndex;i<GLWindow->nRoiTM;i++, xIndex++, arrayIndex++)
|
---|
1910 | {
|
---|
1911 | xval[arrayIndex] = xIndex;
|
---|
1912 | yval[arrayIndex] = GLWindow->eventData[GLWindow->nRoi*1440 + GLWindow->nRoiTM*(40*crateId + 4*boardId + patchId) + i];
|
---|
1913 | }
|
---|
1914 | realNumSamples += GLWindow->nRoiTM - TMIndex;
|
---|
1915 | }
|
---|
1916 | // cout << pixelIdInPatch << " " ;
|
---|
1917 | }
|
---|
1918 |
|
---|
1919 | #if QWT_VERSION < 0x060000
|
---|
1920 | pixelValueCurveItem.setData(xval, yval, realNumSamples);
|
---|
1921 | #else
|
---|
1922 | pixelValueCurveItem.setSamples(xval, yval, realNumSamples);
|
---|
1923 | #endif
|
---|
1924 |
|
---|
1925 | //now compute the average value of all pixels
|
---|
1926 | currentPixel = 0;
|
---|
1927 | for (int i=0;i<GLWindow->nRoi;i++)
|
---|
1928 | yval[i] = 0;
|
---|
1929 | for (int j=0;j<1440;j++) {
|
---|
1930 | currentPixel = j;
|
---|
1931 | for (int i=0;i<GLWindow->nRoi;i++)
|
---|
1932 | {
|
---|
1933 | xval[i] = i;
|
---|
1934 | yval[i] += GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
|
---|
1935 | }
|
---|
1936 | }
|
---|
1937 | for (int i=0;i<GLWindow->nRoi;i++)
|
---|
1938 | yval[i] /= 1440;
|
---|
1939 | #if QWT_VERSION < 0x060000
|
---|
1940 | pixelAverageCurveItem.setData(xval, yval, GLWindow->nRoi);
|
---|
1941 | #else
|
---|
1942 | pixelAverageCurveItem.setSamples(xval, yval, realNumSamples);
|
---|
1943 | #endif
|
---|
1944 |
|
---|
1945 | QStack< QRectF > stack;
|
---|
1946 | stack.push(scaleBoundingRectangle(pixelValueCurveItem.boundingRect(), 1.5f));
|
---|
1947 | curveZoom->setZoomBase(scaleBoundingRectangle(pixelValueCurveItem.boundingRect(), 1.5f));
|
---|
1948 | curveZoom->setZoomStack(stack);
|
---|
1949 | stack.pop();
|
---|
1950 | stack.push(scaleBoundingRectangle(pixelAverageCurveItem.boundingRect(), 1.5f));
|
---|
1951 | averageCurveZoom->setZoomBase(scaleBoundingRectangle(pixelAverageCurveItem.boundingRect(), 1.5f));
|
---|
1952 | averageCurveZoom->setZoomStack(stack);
|
---|
1953 | stack.pop();
|
---|
1954 |
|
---|
1955 | displaySliceValue();
|
---|
1956 | on_autoScaleColor_clicked();
|
---|
1957 | }
|
---|
1958 |
|
---|
1959 | void UIConnector::on_HwIDBox_valueChanged(int)
|
---|
1960 | {
|
---|
1961 | updating = true;
|
---|
1962 |
|
---|
1963 | const int hwID = HwIDBox->value();
|
---|
1964 |
|
---|
1965 | const int crateID = hwID/360;
|
---|
1966 | const int boardID = (hwID%360)/36;
|
---|
1967 | const int patchID = (hwID%36 )/9;
|
---|
1968 | const int pixelID = hwID%9;
|
---|
1969 |
|
---|
1970 | SwIDBox->setValue(GLWindow->softwareMapping[hwID]);
|
---|
1971 |
|
---|
1972 | crateIDBox->setValue(crateID);
|
---|
1973 | boardIDBox->setValue(boardID);
|
---|
1974 | patchIDBox->setValue(patchID);
|
---|
1975 | pixelIDBox->setValue(pixelID);
|
---|
1976 |
|
---|
1977 | updating = false;
|
---|
1978 |
|
---|
1979 | GLWindow->selectedPixel = GLWindow->softwareMapping[hwID];
|
---|
1980 | GLWindow->updateGL();
|
---|
1981 |
|
---|
1982 | pixelChanged(GLWindow->selectedPixel);
|
---|
1983 | }
|
---|
1984 |
|
---|
1985 | void UIConnector::cbpxChanged()
|
---|
1986 | {
|
---|
1987 | if (updating)
|
---|
1988 | return;
|
---|
1989 |
|
---|
1990 | const int hwid = crateIDBox->value()*360 + boardIDBox->value()*36 + patchIDBox->value()*9 + pixelIDBox->value();
|
---|
1991 | HwIDBox->setValue(hwid);
|
---|
1992 | }
|
---|
1993 |
|
---|
1994 | void UIConnector::on_SwIDBox_valueChanged(int swid)
|
---|
1995 | {
|
---|
1996 | if (updating)
|
---|
1997 | return;
|
---|
1998 |
|
---|
1999 | HwIDBox->setValue(GLWindow->hardwareMapping[swid]);
|
---|
2000 | }
|
---|
2001 |
|
---|
2002 | void UIConnector::on_autoScaleColor_clicked()
|
---|
2003 | {
|
---|
2004 | if (!autoScaleColor->isChecked())
|
---|
2005 | {
|
---|
2006 | GLWindow->ss[0] = 0.496;
|
---|
2007 | GLWindow->ss[1] = 0.507;
|
---|
2008 | GLWindow->ss[2] = 0.518;
|
---|
2009 | GLWindow->ss[3] = 0.529;
|
---|
2010 | GLWindow->ss[4] = 0.540;;
|
---|
2011 | colorRange0->setValue(GLWindow->ss[0]);
|
---|
2012 | colorRange1->setValue(GLWindow->ss[1]);
|
---|
2013 | colorRange2->setValue(GLWindow->ss[2]);
|
---|
2014 | colorRange3->setValue(GLWindow->ss[3]);
|
---|
2015 | colorRange4->setValue(GLWindow->ss[4]);
|
---|
2016 | return;
|
---|
2017 | }
|
---|
2018 | if (!GLWindow->nRoi)
|
---|
2019 | return;
|
---|
2020 |
|
---|
2021 | int start = 0;
|
---|
2022 | int end = 1440;
|
---|
2023 |
|
---|
2024 | if (!entireCameraScale->isChecked())
|
---|
2025 | {
|
---|
2026 | start = GLWindow->selectedPixel;
|
---|
2027 | end = GLWindow->selectedPixel+1;
|
---|
2028 | if (end == 0)
|
---|
2029 | {
|
---|
2030 | start = 0;
|
---|
2031 | end = 1440;
|
---|
2032 | }
|
---|
2033 | }
|
---|
2034 |
|
---|
2035 | int min = 100000; //real min = -2048, int_16 = -32768 to 32767
|
---|
2036 | int max = -100000; //real max = 2047
|
---|
2037 |
|
---|
2038 | long average = 0;
|
---|
2039 | long numSamples = 0;
|
---|
2040 | int errorDetected = -1;
|
---|
2041 |
|
---|
2042 | for (int i=start;i<end;i++)
|
---|
2043 | {
|
---|
2044 | if (i==863)//keep crazy pixel out of the autoscale
|
---|
2045 | continue;
|
---|
2046 | for (int j=10;j<GLWindow->nRoi-50;j++)
|
---|
2047 | {
|
---|
2048 | int cValue = GLWindow->eventData[i*GLWindow->nRoi+j];
|
---|
2049 | if (cValue > max && cValue < 32767)
|
---|
2050 | max = cValue;
|
---|
2051 | if (cValue < min && cValue > -32768)
|
---|
2052 | min = cValue;
|
---|
2053 | if (cValue < 32767 && cValue > -32768)
|
---|
2054 | {
|
---|
2055 | average+=cValue;
|
---|
2056 | numSamples++;
|
---|
2057 | }
|
---|
2058 | else
|
---|
2059 | {
|
---|
2060 | errorDetected = i;
|
---|
2061 | }
|
---|
2062 | // numSamples++;
|
---|
2063 | }
|
---|
2064 | }
|
---|
2065 | average /= numSamples;
|
---|
2066 | if (errorDetected != -1)
|
---|
2067 | {
|
---|
2068 | cout << "Overflow detected at pixel " << errorDetected << " (at least)" << endl;
|
---|
2069 | }
|
---|
2070 | // cout << "min: " << min << " max: " << max << " average: " << average << endl;
|
---|
2071 | float minRange = (float)(min+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
|
---|
2072 | float maxRange = (float)(max+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
|
---|
2073 | float midRange = (float)(average+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
|
---|
2074 | if (GLWindow->logScale)
|
---|
2075 | {
|
---|
2076 | minRange *= 9;
|
---|
2077 | maxRange *= 9;
|
---|
2078 | // midRange *= 9;
|
---|
2079 | minRange += 1;
|
---|
2080 | maxRange += 1;
|
---|
2081 | // midRange += 1;
|
---|
2082 | minRange = log10(minRange);
|
---|
2083 | maxRange = log10(maxRange);
|
---|
2084 | // midRange = (minRange + maxRange)/2.f;
|
---|
2085 | midRange = log10(midRange);
|
---|
2086 | }
|
---|
2087 |
|
---|
2088 | GLWindow->ss[0] = minRange;
|
---|
2089 | colorRange0->setValue(GLWindow->ss[0]);
|
---|
2090 | GLWindow->ss[4] = maxRange;
|
---|
2091 | colorRange4->setValue(GLWindow->ss[4]);
|
---|
2092 | // GLWindow->ss[2] = midRange;
|
---|
2093 | // range2->setValue(GLWindow->ss[2]);
|
---|
2094 | // GLWindow->ss[1] = (minRange+midRange)/2;
|
---|
2095 | // range1->setValue(GLWindow->ss[1]);
|
---|
2096 | // GLWindow->ss[3] = (maxRange+midRange)/2;
|
---|
2097 | // range3->setValue(GLWindow->ss[3]);
|
---|
2098 |
|
---|
2099 | GLWindow->ss[2] = (maxRange+minRange)/2;
|
---|
2100 | colorRange2->setValue(GLWindow->ss[2]);
|
---|
2101 |
|
---|
2102 | GLWindow->ss[1] = minRange+(maxRange-minRange)/4;
|
---|
2103 | colorRange1->setValue(GLWindow->ss[1]);
|
---|
2104 |
|
---|
2105 | GLWindow->ss[3] = minRange+3*(maxRange-minRange)/4;
|
---|
2106 | colorRange3->setValue(GLWindow->ss[3]);
|
---|
2107 | }
|
---|
2108 |
|
---|
2109 | void PrintUsage()
|
---|
2110 | {
|
---|
2111 | cout << "\n"
|
---|
2112 | "The FACT++ raw data viewer.\n"
|
---|
2113 | "\n"
|
---|
2114 | "Usage: viewer [OPTIONS] [datafile.fits[.gz] [calibration.drs.fits[.gz]]]\n"
|
---|
2115 | " or: viewer [OPTIONS]\n";
|
---|
2116 | cout << endl;
|
---|
2117 |
|
---|
2118 | }
|
---|
2119 |
|
---|
2120 | void PrintHelp()
|
---|
2121 | {
|
---|
2122 | cout <<
|
---|
2123 | "\n"
|
---|
2124 | << endl;
|
---|
2125 | }
|
---|
2126 |
|
---|
2127 | int UIConnector::SetupConfiguration(Configuration &conf)
|
---|
2128 | {
|
---|
2129 | RawDataViewer *canvas = GLWindow;
|
---|
2130 |
|
---|
2131 | if (conf.Has("color.range"))
|
---|
2132 | {
|
---|
2133 | vector<double> value = conf.Vec<double>("color.range");
|
---|
2134 | if (value.size() != 5)
|
---|
2135 | {
|
---|
2136 | cout << "Error, colorRange option should have exactly 5 double values" << endl;
|
---|
2137 | return -1;
|
---|
2138 | }
|
---|
2139 | for (int i=0;i<5;i++)
|
---|
2140 | canvas->ss[i] = value[i];
|
---|
2141 | }
|
---|
2142 |
|
---|
2143 | if (conf.Has("color.red"))
|
---|
2144 | {
|
---|
2145 | vector<double> value = conf.Vec<double>("color.red");
|
---|
2146 | if (value.size() != 5)
|
---|
2147 | {
|
---|
2148 | cout << "Error, colorRed option should have exactly 5 double values" << endl;
|
---|
2149 | return -1;
|
---|
2150 | }
|
---|
2151 | for (int i=0;i<5;i++)
|
---|
2152 | canvas->rr[i] = value[i];
|
---|
2153 | }
|
---|
2154 |
|
---|
2155 | if (conf.Has("color.green"))
|
---|
2156 | {
|
---|
2157 | vector<double> value = conf.Vec<double>("color.green");
|
---|
2158 | if (value.size() != 5)
|
---|
2159 | {
|
---|
2160 | cout << "Error, colorGreen option should have exactly 5 double values" << endl;
|
---|
2161 | return -1;
|
---|
2162 | }
|
---|
2163 | for (int i=0;i<5;i++)
|
---|
2164 | canvas->gg[i] = value[i];
|
---|
2165 | }
|
---|
2166 |
|
---|
2167 | if (conf.Has("color.blue"))
|
---|
2168 | {
|
---|
2169 | vector<double> value = conf.Vec<double>("color.blue");
|
---|
2170 | if (value.size() != 5)
|
---|
2171 | {
|
---|
2172 | cout << "Error, colorBlue option should have exactly 5 double values" << endl;
|
---|
2173 | return -1;
|
---|
2174 | }
|
---|
2175 | for (int i=0;i<5;i++)
|
---|
2176 | canvas->bb[i] = value[i];
|
---|
2177 | }
|
---|
2178 |
|
---|
2179 | colorRange0->setValue(canvas->ss[0]);
|
---|
2180 | colorRange1->setValue(canvas->ss[1]);
|
---|
2181 | colorRange2->setValue(canvas->ss[2]);
|
---|
2182 | colorRange3->setValue(canvas->ss[3]);
|
---|
2183 | colorRange4->setValue(canvas->ss[4]);
|
---|
2184 | redValue0->setValue(canvas->rr[0]);
|
---|
2185 | redValue1->setValue(canvas->rr[1]);
|
---|
2186 | redValue2->setValue(canvas->rr[2]);
|
---|
2187 | redValue3->setValue(canvas->rr[3]);
|
---|
2188 | redValue4->setValue(canvas->rr[4]);
|
---|
2189 | greenValue0->setValue(canvas->gg[0]);
|
---|
2190 | greenValue1->setValue(canvas->gg[1]);
|
---|
2191 | greenValue2->setValue(canvas->gg[2]);
|
---|
2192 | greenValue3->setValue(canvas->gg[3]);
|
---|
2193 | greenValue4->setValue(canvas->gg[4]);
|
---|
2194 | blueValue0->setValue(canvas->bb[0]);
|
---|
2195 | blueValue1->setValue(canvas->bb[1]);
|
---|
2196 | blueValue2->setValue(canvas->bb[2]);
|
---|
2197 | blueValue3->setValue(canvas->bb[3]);
|
---|
2198 | blueValue4->setValue(canvas->bb[4]);
|
---|
2199 |
|
---|
2200 | if (conf.Has("drs"))
|
---|
2201 | {
|
---|
2202 | const QString qstr(conf.Get<string>("drs").c_str());
|
---|
2203 | calibFileSelected(qstr);
|
---|
2204 | }
|
---|
2205 |
|
---|
2206 | if (conf.Has("file"))
|
---|
2207 | {
|
---|
2208 | const QString qstr(conf.Get<string>("file").c_str());
|
---|
2209 | fileSelected(qstr);
|
---|
2210 | }
|
---|
2211 |
|
---|
2212 |
|
---|
2213 | return 0;
|
---|
2214 | }
|
---|
2215 |
|
---|
2216 | void SetupConfiguration(Configuration& conf)
|
---|
2217 | {
|
---|
2218 | po::options_description configs("Raw Events Viewer Options");
|
---|
2219 | configs.add_options()
|
---|
2220 | ("color.range", vars<double>(), "Range of the display colours")
|
---|
2221 | ("color.red", vars<double>(), "Range of red values")
|
---|
2222 | ("color.green", vars<double>(), "Range of green values")
|
---|
2223 | ("color.blue", vars<double>(), "Range of blue values")
|
---|
2224 | ("file,f", var<string>(), "File to be loaded")
|
---|
2225 | ("drs,d", var<string>(), "DRS calibration file to be loaded")
|
---|
2226 | ;
|
---|
2227 | conf.AddOptions(configs);
|
---|
2228 |
|
---|
2229 | po::positional_options_description p;
|
---|
2230 | p.add("file", 1); // The first positional options
|
---|
2231 | p.add("drs", 2); // The first positional options
|
---|
2232 | conf.SetArgumentPositions(p);
|
---|
2233 |
|
---|
2234 | }
|
---|
2235 |
|
---|
2236 | /************************************************************
|
---|
2237 | * MAIN PROGRAM FUNCTION.
|
---|
2238 | ************************************************************/
|
---|
2239 | int main(int argc, const char *argv[])
|
---|
2240 | {
|
---|
2241 | QApplication app(argc, const_cast<char**>(argv));
|
---|
2242 |
|
---|
2243 | if (!QGLFormat::hasOpenGL()) {
|
---|
2244 | std::cerr << "This system has no OpenGL support" << std::endl;
|
---|
2245 | return 1;
|
---|
2246 | }
|
---|
2247 |
|
---|
2248 | Configuration conf(argv[0]);
|
---|
2249 | conf.SetPrintUsage(PrintUsage);
|
---|
2250 | SetupConfiguration(conf);
|
---|
2251 | if (!conf.DoParse(argc, argv, PrintHelp))
|
---|
2252 | return 2;
|
---|
2253 |
|
---|
2254 | UIConnector myUi;
|
---|
2255 | if (myUi.SetupConfiguration(conf)<0)
|
---|
2256 | return 3;
|
---|
2257 |
|
---|
2258 | return app.exec();
|
---|
2259 | }
|
---|
2260 |
|
---|