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

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