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

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