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

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