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

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