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

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