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

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