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

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