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

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