source: trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc@ 12375

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