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

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