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

Last change on this file since 13710 was 12967, checked in by tbretz, 13 years ago
Fixed some trivial compiler warnings.
File size: 70.9 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("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 makeCurrent();
414 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
415 glLoadIdentity();
416
417 glTranslatef(0,0,-0.5);
418
419 if (drawBlur)
420 {
421 glShadeModel(GL_SMOOTH);
422 drawCamera(false);
423 }
424 else
425 {
426 glShadeModel(GL_FLAT);
427 drawCamera(true);
428 }
429 glTranslatef(0,0,0.1f);
430 if (drawPatch)
431 drawPatches();
432 glTranslatef(0,0,0.1f);
433 if (!drawBlur && (selectedPixel != -1))
434 {
435 glLineWidth(1.0f);
436 glColor3f(1.0,1.0,1.0);
437 drawHexagon(selectedPixel, false);
438 }
439 glTranslatef(0,0,0.1f);
440 if (drawImpulse)
441 {
442 // glRotatef(cameraRotation, 0,0,1);
443 glLoadIdentity();
444 glLineWidth(2.0);
445 drawPixelCurve();
446 }
447 glTranslatef(0,0,0.1f);
448 DrawScale();
449}
450
451/************************************************************
452 * MOUSE PRESS EVENT. mouse click handler.
453 ************************************************************/
454void RawDataViewer::mousePressEvent(QMouseEvent *cEvent)
455{
456 if (cEvent->pos().x() > width()-(width()/50.f))
457 {
458 toggleInterfaceDisplay();
459 return;
460 }
461 lastPos = cEvent->pos();
462 if (setCorrectSlice(cEvent))
463 return;
464 int face = PixelAtPosition(cEvent->pos());
465
466 selectedPixel = face;
467 emit signalCurrentPixel(face);
468
469 updateGL();
470}
471
472/************************************************************
473 * SET CORRECT SLICE. if displayed, figures out if the graph was
474 * clicked, and if so, which slice should be displayed
475 ************************************************************/
476bool RawDataViewer::setCorrectSlice(QMouseEvent* cEvent)
477{
478 if (!drawImpulse)
479 return false;
480 float cx = (float)cEvent->x() * pixelSize - shownSizex/2;
481 float cy = ((float)height()-(float)cEvent->y())*pixelSize - shownSizey/2;
482 if (cx < bboxMin[0] ||
483 cx > bboxMax[0] ||
484 cy < bboxMin[1] ||
485 cy > bboxMax[1])
486 return false;
487 whichSlice = (cx - bboxMin[0])*(nRoi+nRoiTM)/(bboxMax[0] - bboxMin[0]);
488 if (whichSlice >= nRoi)
489 whichSlice = nRoi-1;
490 emit signalCurrentSlice(whichSlice);
491 return true;
492}
493
494/************************************************************
495 * MOUSE MOVE EVENT. used to track the dragging of slices display
496 ************************************************************/
497void RawDataViewer::mouseMoveEvent(QMouseEvent *cEvent)
498{
499 if (cEvent->buttons() & Qt::LeftButton) {
500 setCorrectSlice(cEvent);
501 updateGL();
502 } else if (cEvent->buttons() & Qt::RightButton) {
503 updateGL();
504 }
505 lastPos = cEvent->pos();
506}
507
508/************************************************************
509 * MOUSE DOUBLE CLICK EVENT. used to select pixels
510 ************************************************************/
511void RawDataViewer::mouseDoubleClickEvent(QMouseEvent *cEvent)
512{
513 int face = PixelAtPosition(cEvent->pos());
514 if (face != -1) {
515 selectedPixel = face;
516 emit signalCurrentPixel(face);
517 updateGL();
518 }
519}
520
521/************************************************************
522 * OPEN FILE. opens a new fits file
523 ************************************************************/
524void RawDataViewer::openFile(string& file)
525{
526 if (inputFile)
527 {
528 inputFile->close();
529 delete inputFile;
530 }
531 try {
532 inputFile = new fits(file);
533 }
534 catch (std::runtime_error e)
535 {
536 cout << "Something went wrong while loading fits. Aborting: " << e.what() << endl;
537 return;
538 }
539 if (!*inputFile)
540 {
541 delete inputFile;
542 inputFile = NULL;
543 return;
544 }
545 vector<string> entriesToCheck;
546 entriesToCheck.push_back("NAXIS2");
547 entriesToCheck.push_back("NROI");
548 entriesToCheck.push_back("REVISION");
549 entriesToCheck.push_back("RUNID");
550 entriesToCheck.push_back("NBOARD");
551 entriesToCheck.push_back("NPIX");
552 entriesToCheck.push_back("NROITM");
553 entriesToCheck.push_back("TIMESYS");
554 entriesToCheck.push_back("DATE");
555 entriesToCheck.push_back("NIGHT");
556 entriesToCheck.push_back("CAMERA");
557 entriesToCheck.push_back("DAQ");
558 entriesToCheck.push_back("TSTART");
559 entriesToCheck.push_back("TSTOP");
560
561
562 for (vector<string>::const_iterator it=entriesToCheck.begin(); it != entriesToCheck.end(); it++)
563 {
564 try {
565 if (!inputFile->HasKey(*it)){
566 cout << "Warning: header keyword " << *it << " missing." << endl;
567 }
568 }
569 catch (std::runtime_error e)
570 {
571 cout << e.what() << endl;
572 return;
573 }
574 }
575 nRows = inputFile->HasKey("NAXIS2") ? inputFile->GetInt("NAXIS2") : 0;
576 nRoi = inputFile->HasKey("NROI") ? inputFile->GetInt("NROI") : 0;
577 runNumber = inputFile->HasKey("RUNID") ? inputFile->GetInt("RUNID") : -1;
578 nTM = inputFile->HasKey("NTMARK") ? inputFile->GetInt("NTMARK") : 0;
579 runType = inputFile->HasKey("RUNTYPE") ? inputFile->GetInt("RUNTYPE") : -1;
580 firstDataTime = inputFile->HasKey("TSTART") ? inputFile->GetInt("TSTART") : -1;
581 lastDataTime = inputFile->HasKey("TSTOP") ? inputFile->GetInt("TSTOP"): -1;
582 nRoiTM = inputFile->HasKey("NROITM") ? inputFile->GetInt("NROITM") : 0;
583 revision = inputFile->HasKey("REVISION") ? inputFile->GetInt("REVISION") : -1;
584 builderVersion = inputFile->HasKey("BLDVER") ? inputFile->GetInt("BLDVER") : -1;
585 nBoards = inputFile->HasKey("NBOARD") ? inputFile->GetInt("NBOARD") : 0;
586 nPixels = inputFile->HasKey("NPIX") ? inputFile->GetInt("NPIX") : 0;
587 timeSystem = inputFile->HasKey("TIMESYS") ? inputFile->GetStr("TIMESYS") : 0;
588 creationDate = inputFile->HasKey("DATE") ? inputFile->GetStr("DATE") : 0;
589 nightInt = inputFile->HasKey("NIGHT") ? inputFile->GetInt("NIGHT") : 0;
590 camera = inputFile->HasKey("CAMERA") ? inputFile->GetStr("CAMERA") : 0;
591 daq = inputFile->HasKey("DAQ") ? inputFile->GetStr("DAQ") : 0;
592 adcCount = inputFile->HasKey("ADCRANGE") ? inputFile->GetFloat("ADCRANGE") : 2000;
593
594 if (inputFile->HasKey("OFFSET"))
595 offSetRoi = inputFile->GetInt("OFFSET");
596
597 nbOk = 0;//inputFile->GetInt("NBEVTOK");
598 nbRej = 0;//inputFile->GetInt("NBEVTREJ");
599 nbBad = 0;//inputFile->GetInt("NBEVTBAD");
600
601 eventNum = 0;
602
603 if (eventData != NULL) {
604 delete[] eventData;
605 delete[] rawEventData;
606 delete[] waveLetArray;
607 }
608 eventData = new float[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
609
610 rawEventData = new int16_t[1440*nRoi + 160*nRoiTM];//(1440+160)*nRoi];
611 waveLetArray = new int16_t[1024*1440];
612 try
613 {
614 inputFile->SetPtrAddress("Data", rawEventData);
615 inputFile->SetPtrAddress("EventNum", &eventNum);
616 inputFile->SetPtrAddress("TriggerType", &triggerType);
617 inputFile->SetPtrAddress("SoftTrig", &softTrig);
618 inputFile->SetPtrAddress("BoardTime", boardTime);
619 inputFile->SetPtrAddress("StartCellData", startPix);
620 inputFile->SetPtrAddress("StartCellTimeMarker", startTM);
621 inputFile->SetPtrAddress("TimeMarker", &rawEventData[1440*nRoi]);
622 }
623 catch (const runtime_error &e)
624 {
625 cout << e.what() << endl;
626 cout << "Loading aborted." << endl;
627
628 nRoi = nRows = 0;
629
630 return;
631 }
632
633 try
634 {
635 pcTime[0] = pcTime[1] = 0;
636 inputFile->SetPtrAddress("UnixTimeUTC", pcTime);
637 }
638 catch (const runtime_error&)
639 {
640 try
641 {
642 inputFile->SetPtrAddress("PCTime", pcTime);
643 }
644 catch (const runtime_error&)
645 {
646
647 }
648 }
649
650
651 int backupStep = eventStep;
652 rowNum = -1;
653 eventStep = 1;
654
655 plusEvent();
656 eventStep = backupStep;
657 emit newFileLoaded();
658 emit signalCurrentPixel(selectedPixel);
659}
660
661void RawDataViewer::openCalibFile(string& file)
662{
663 //calibrationLoaded = false;
664 string msg;
665 try
666 {
667 msg = fDrsCalib.ReadFitsImp(file);
668 if (msg.empty())
669 {
670 emit newFileLoaded();
671 updateGL();
672 return;
673 }
674 }
675 catch (const runtime_error &e)
676 {
677 msg = e.what();
678 }
679
680 cerr << msg << endl;
681 fDrsCalib.Clear();
682}
683
684template <typename T>
685void RawDataViewer::getCalibrationDataForDisplay(const CalibDataTypes/* calibTypes*/,
686 const vector<T>& inputData,
687 const int roi,
688 const int roiTM)
689{
690
691 eventData = new float[1440*roi + 160*roiTM];//(1440+160)*nRoi];
692 nRoi=roi;
693 nRoiTM=roiTM;
694
695 long long min, max, mean;
696 min = max = inputData[0];
697 mean=0;
698 for (int i=0;i<1440*roi + 160*roiTM;i++) {
699 eventData[i] = (float)inputData[i];
700 mean += inputData[i];
701 if (inputData[i] > max)
702 max = inputData[i];
703 if (inputData[i] < min)
704 min = inputData[i];
705 }
706 mean /= 1440*roi + 160*roiTM;
707 for (int i=0;i<1440*roi + 160*roiTM;i++)
708 eventData[i] -= (float)mean;
709 VALUES_SPAN = max - min;
710// cout << VALUES_SPAN << " " << min << " " << max << " " << mean << endl;
711// cout << 1440*roi + 160*roiTM << " " << roi << " " << roiTM << " " << inputData.size() << endl;
712}
713/************************************************************
714 * PLUS EVENT
715 ************************************************************/
716void RawDataViewer::plusEvent()
717{
718 eventStepping(true);
719}
720/************************************************************
721 * MINUS EVENT
722 ************************************************************/
723void RawDataViewer::minusEvent()
724{
725 eventStepping(false);
726}
727/************************************************************
728 * SET EVENT STEP
729 ************************************************************/
730void RawDataViewer::setEventStep(int step)
731{
732 eventStep = step;
733}
734/************************************************************
735 * EVENT STEPPING
736 ************************************************************/
737
738void RawDataViewer::ApplyCalibration()
739{
740 for (int i=0;i<1440*nRoi + 160*nRoiTM;i++)//(1440+160)*nRoi;i++)
741 eventData[i] = (float)rawEventData[i];
742
743 if (fIsDrsCalibration)
744 {
745 fDrsCalib.Apply(eventData, rawEventData, startPix, nRoi);
746 DrsCalibrate::RemoveSpikes(eventData, nRoi);
747 //TODO apply calibration to the Time markers
748 }
749
750 //hide the time markers
751 int nSlicesToRemove = 60;
752 float* backupData = 0;
753 if (nRoiTM == 0) //they are written into the regular channel
754 {
755 backupData = new float[nSlicesToRemove*160];
756 for (int i=0;i<1440;i++)
757 {
758 const PixelMapEntry& mapEntry = fPixelMap.index(i);
759 const int pixelIdInPatch = mapEntry.pixel();
760 const int patchId = mapEntry.patch();
761 const int boardId = mapEntry.board();
762 const int crateId = mapEntry.crate();
763
764 const int hw = mapEntry.hw();
765 if (pixelIdInPatch == 8)
766 {
767 for (int j=0;j<nSlicesToRemove;j++)
768 {
769 backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j] = eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j];
770 eventData[(hw*nRoi) + (nRoi-nSlicesToRemove) + j] = eventData[hw*nRoi + (nRoi-nSlicesToRemove) - 1];
771 }
772 }
773 }
774 }
775
776 vector<float> pixelStatsData(1440*4);
777 DrsCalibrate::GetPixelStats(pixelStatsData.data(), eventData, nRoi);
778
779 for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
780 {
781 Meanvalues[it->index] = pixelStatsData[0*1440+it->hw()];
782 RMSvalues[it->index] = pixelStatsData[1*1440+it->hw()];
783 Maxvalues[it->index] = pixelStatsData[2*1440+it->hw()];
784 PosOfMaxvalues[it->index] = pixelStatsData[3*1440+it->hw()];
785 }
786 if (nRoiTM == 0)//move back the data back in place
787 {
788 for (int i=0;i<1440;i++)
789 {
790 const PixelMapEntry& mapEntry = fPixelMap.index(i);
791 const int pixelIdInPatch = mapEntry.pixel();
792 const int patchId = mapEntry.patch();
793 const int boardId = mapEntry.board();
794 const int crateId = mapEntry.crate();
795 if (patchId > 160)
796 cout << "Voila mon probleme: " << patchId << endl;
797 const int hw = mapEntry.hw();
798 if (pixelIdInPatch == 8)
799 {
800 // cout << "|" << crateId << " " << boardId << " " << patchId << " " << hw << "| ";
801 for (int j=0;j<nSlicesToRemove;j++)
802 {
803 eventData[(hw*nRoi) + (nRoi - nSlicesToRemove) + j] = backupData[(40*crateId + 4*boardId + patchId)*nSlicesToRemove+j];
804 }
805 }
806 }
807 delete[] backupData;
808 }
809 if (isVisible())
810 updateGL();
811}
812
813void RawDataViewer::eventStepping(bool plus)
814{
815 if (plus)
816 rowNum += eventStep;
817 else
818 rowNum -= eventStep;
819 if (rowNum >= nRows)
820 rowNum -= nRows;
821 if (rowNum < 0)
822 rowNum += nRows;
823
824 if (inputFile == NULL)
825 return;
826 inputFile->GetRow(rowNum);
827// cout << "Getting row " << rowNum << endl;
828
829
830 ApplyCalibration();
831
832 emit signalCurrentEvent(eventNum);
833 emit signalCurrentPixel(selectedPixel);
834}
835
836/************************************************************
837 * NEXT SLICE. deprec ?
838 ************************************************************/
839void RawDataViewer::nextSlice()
840{
841 whichSlice++;
842 if (whichSlice >= nRoi)
843 {
844 whichSlice = 0;
845 if (!loopCurrentEvent)
846 {
847 int backupStep = eventStep;
848 eventStep = 1;
849 eventStepping(true);
850 eventStep = backupStep;
851 }
852 }
853 emit signalCurrentSlice(whichSlice);
854 updateGL();
855}
856void RawDataViewer::previousSlice()
857{
858 whichSlice--;
859 if (whichSlice < 0)
860 {
861 whichSlice = nRoi-1;
862 if (!loopCurrentEvent)
863 {
864 int backupStep = eventStep;
865 eventStep = 1;
866 eventStepping(false);
867 eventStep = backupStep;
868 }
869 }
870 emit signalCurrentSlice(whichSlice);
871 updateGL();
872}
873void RawDataViewer::setCurrentPixel(int pix)
874{
875 // if (pix == -1)
876 // return;
877 selectedPixel = pix;
878 if (isVisible())
879 updateGL();
880 emit signalCurrentPixel(pix);
881}
882void RawDataViewer::computePulsesStatistics()
883{
884 if (!inputFile)
885 {
886 cout << "A FITS file must be open in order to complete this operation" << endl;
887 return;
888 }
889
890
891// for (int i=0;i<nRows;i++)//for all events
892// {
893// inputFile->GetRow(rowNum);
894// for (int i=0;i<(1440+160)*nRoi;i++)
895// eventData[i] = (float)rawEventData[i];
896
897// for (int j=0;j<ACTUAL_NUM_PIXELS;j++)
898/// {
899 int j = selectedPixel;
900 if (j == -1)
901 return;
902 for (int i=0;i<nRoi;i++)
903 {
904 aMeas[i] = eventData[j*nRoi+i];// * adcCount;
905
906 }
907 for (int i=0;i<nRoi;i++)
908 {
909 if (i==0)
910 n1mean[i] = aMeas[i+1];
911 else
912 {
913 if (i==1023)
914 n1mean[i] = aMeas[i-1];
915 else
916 n1mean[i] = (aMeas[i-1]+aMeas[i+1])/2.f;
917 }
918 }
919 //find spike
920 for (int i=0;i<nRoi-3;i++)
921 {
922 const float fract = 0.8f;
923 float xx, xp, xpp;
924 vCorr[i] = 0;//aMeas[i];
925 xx = aMeas[i] - n1mean[i];
926 if (xx < -8.f)
927 {
928 xp = aMeas[i+1] - n1mean[i+1];
929 xpp = aMeas[i+2] - n1mean[i+2];
930 if ((aMeas[i+2] - (aMeas[i] + aMeas[i+3])/2.f) > 10.f)
931 {
932 vCorr[i+1] = (aMeas[i] + aMeas[i+3])/2.f;
933 vCorr[i+2] = (aMeas[i] + aMeas[i+3])/2.f;
934 i = i+2;
935 }
936 else
937 {
938 if ((xp > -2.*xx*fract) && (xpp < -10.f))
939 {
940 vCorr[i+1] = n1mean[i+1];
941 n1mean[i+2] = aMeas[i+1] - aMeas[i+3]/2.f;
942 i++;
943 }
944 }
945 }
946 }
947 for (int i=0;i<nRoi;i++)
948 n1mean[i] = aMeas[i]-n1mean[i];
949 // }
950 // }
951}
952/************************************************************
953 * UICONNECTOR CONSTRUCTOR
954 ************************************************************/
955UIConnector::UIConnector(QWidget *p)
956{
957 setupUi(this);
958 initHistograms();
959
960 currentFile = "none";
961 currentCalibFile = "none";
962
963 updateSpinnerDisplay = true;
964 updating = false;
965
966 timer.setInterval(10.0);
967 QObject::connect(&timer, SIGNAL(timeout()),
968 this, SLOT(nextSlicePlease()));
969
970 QButtonGroup &scaleGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
971 QButtonGroup &animateGroup = *new QButtonGroup(p);// = new QButtonGroup(canvas);
972
973 scaleGroup.addButton(currentPixelScale);
974 scaleGroup.addButton(entireCameraScale);
975
976 animateGroup.addButton(playEventsRadio);
977 animateGroup.addButton(playSlicesRadio);
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 GLWindow->nextSlice();
1090}
1091
1092/************************************************************
1093 * SET VIEWER.
1094 ************************************************************/
1095//void UIConnector::setViewer(RawDataViewer* v)
1096//{
1097// viewer = v;
1098//}
1099/************************************************************
1100 * SLICES PER SECOND CHANGED. timing ui handler
1101 ************************************************************/
1102void UIConnector::slicesPerSecondChanged(double value)
1103{
1104 timer.setInterval(1000.0/value);
1105}
1106
1107void UIConnector::on_colorRange0_valueChanged(double value) { GLWindow->ss[0] = (float)value; GLWindow->updateGL(); }
1108void UIConnector::on_colorRange1_valueChanged(double value) { GLWindow->ss[1] = (float)value; GLWindow->updateGL(); }
1109void UIConnector::on_colorRange2_valueChanged(double value) { GLWindow->ss[2] = (float)value; GLWindow->updateGL(); }
1110void UIConnector::on_colorRange3_valueChanged(double value) { GLWindow->ss[3] = (float)value; GLWindow->updateGL(); }
1111void UIConnector::on_colorRange4_valueChanged(double value) { GLWindow->ss[4] = (float)value; GLWindow->updateGL(); }
1112
1113void UIConnector::on_redValue0_valueChanged(double value) { GLWindow->rr[0] = (float)value; GLWindow->updateGL(); }
1114void UIConnector::on_redValue1_valueChanged(double value) { GLWindow->rr[1] = (float)value; GLWindow->updateGL(); }
1115void UIConnector::on_redValue2_valueChanged(double value) { GLWindow->rr[2] = (float)value; GLWindow->updateGL(); }
1116void UIConnector::on_redValue3_valueChanged(double value) { GLWindow->rr[3] = (float)value; GLWindow->updateGL(); }
1117void UIConnector::on_redValue4_valueChanged(double value) { GLWindow->rr[4] = (float)value; GLWindow->updateGL(); }
1118
1119void UIConnector::on_greenValue0_valueChanged(double value) { GLWindow->gg[0] = (float)value; GLWindow->updateGL(); }
1120void UIConnector::on_greenValue1_valueChanged(double value) { GLWindow->gg[1] = (float)value; GLWindow->updateGL(); }
1121void UIConnector::on_greenValue2_valueChanged(double value) { GLWindow->gg[2] = (float)value; GLWindow->updateGL(); }
1122void UIConnector::on_greenValue3_valueChanged(double value) { GLWindow->gg[3] = (float)value; GLWindow->updateGL(); }
1123void UIConnector::on_greenValue4_valueChanged(double value) { GLWindow->gg[4] = (float)value; GLWindow->updateGL(); }
1124
1125void UIConnector::on_blueValue0_valueChanged(double value) { GLWindow->bb[0] = (float)value; GLWindow->updateGL(); }
1126void UIConnector::on_blueValue1_valueChanged(double value) { GLWindow->bb[1] = (float)value; GLWindow->updateGL(); }
1127void UIConnector::on_blueValue2_valueChanged(double value) { GLWindow->bb[2] = (float)value; GLWindow->updateGL(); }
1128void UIConnector::on_blueValue3_valueChanged(double value) { GLWindow->bb[3] = (float)value; GLWindow->updateGL(); }
1129void UIConnector::on_blueValue4_valueChanged(double value) { GLWindow->bb[4] = (float)value; GLWindow->updateGL(); }
1130
1131/************************************************************
1132 * LOAD NEW FILE CLICKED. button handler
1133 ************************************************************/
1134void UIConnector::on_loadNewFileButton_clicked()
1135{
1136 QFileDialog dialog;
1137 dialog.setFileMode(QFileDialog::ExistingFile);
1138 dialog.open(this, SLOT(fileSelected(QString)));
1139 dialog.setVisible(true);
1140 dialog.exec();
1141}
1142void UIConnector::on_loadDRSCalibButton_clicked()
1143{
1144 QFileDialog dialog;
1145 dialog.setFileMode(QFileDialog::ExistingFile);
1146 dialog.open(this, SLOT(calibFileSelected(QString)));
1147 dialog.setVisible(true);
1148 dialog.exec();
1149}
1150/************************************************************
1151 * FILE SELECTED. return of the file open dialog handler
1152 ************************************************************/
1153void UIConnector::fileSelected(QString file)
1154{
1155 currentFile = file.toStdString();
1156 if (currentFile != "")
1157 GLWindow->openFile(currentFile);
1158}
1159void UIConnector::calibFileSelected(QString file)
1160{
1161 currentCalibFile = file.toStdString();
1162 if (currentCalibFile != "")
1163 GLWindow->openCalibFile(currentCalibFile);
1164 if (GLWindow->fDrsCalib.fRoi != 0)
1165 {//spread the calibration data to the displayers
1166 Baseline_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_BASELINE,
1167 GLWindow->fDrsCalib.fOffset,
1168 GLWindow->fDrsCalib.fRoi,
1169 GLWindow->fDrsCalib.fNumTm);
1170
1171 Gain_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_GAIN,
1172 GLWindow->fDrsCalib.fGain,
1173 GLWindow->fDrsCalib.fRoi,
1174 GLWindow->fDrsCalib.fNumTm);
1175
1176 TriggerOffset_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_TRIG_OFFSET,
1177 GLWindow->fDrsCalib.fTrgOff,
1178 GLWindow->fDrsCalib.fRoi,
1179 GLWindow->fDrsCalib.fNumTm);
1180
1181 }
1182}
1183/************************************************************
1184 * NEW FILE LOADED. update of the UI after a new file has been loaded
1185 ************************************************************/
1186void UIConnector::newFileLoaded()
1187{
1188 ostringstream str;
1189
1190 //extract the file name only (no path) from the full name
1191 str << "File: ";
1192 if (currentFile.size() > 2)
1193 str << currentFile.substr(currentFile.find_last_of("//")+1, currentFile.size()) << "\n";
1194 else
1195 str << "--\n";
1196 str << "Calibration: ";
1197 if (currentCalibFile.size() > 2)
1198 str << currentCalibFile.substr(currentCalibFile.find_last_of("//")+1, currentCalibFile.size()) << "\n";
1199 else
1200 str << "--\n";
1201// fileLoadedLabel->setText(QString(str.str().c_str()));
1202// str.str("");
1203 str << "Run number: " << GLWindow->runNumber << "\n";
1204// runNumberLabel->setText(QString(str.str().c_str()));
1205// str.str("");
1206 str << "Number of Events: " << GLWindow->nRows << "\n";
1207
1208 displayingEventBox->setMaximum(GLWindow->nRows-1);
1209
1210 str << "Number of Slices: " << GLWindow->nRoi << "\n";// << "/1024";
1211// numberOfSlicesLabel->setText(QString(str.str().c_str()));
1212// str.str("");
1213 str << "Number of Time Marks: " << GLWindow->nTM << "\n";
1214// numberOfTimeMarksLabel->setText(QString(str.str().c_str()));
1215
1216// str.str("");
1217 str << "Run Type: " << GLWindow->runType << "\n";
1218// runTypeLabel->setText(QString(str.str().c_str()));
1219// str.str("");
1220 str << "Time of 1st data: " << GLWindow->firstDataTime << "\n";
1221// firstTimeLabel->setText(QString(str.str().c_str()));
1222// str.str("");
1223 str << "Time of last data: " << GLWindow->lastDataTime << "\n";
1224// lastTimeLabel->setText(QString(str.str().c_str()));
1225// str.str("");
1226 str << "SVN revision: " << GLWindow->revision << '\n';
1227 str << "Number of boards: " << GLWindow->nBoards << '\n';
1228 str << "Number of pixels: " << GLWindow->nPixels << '\n';
1229 str << "Number of Slices TM: " << GLWindow->nRoiTM << '\n';
1230 str << "Time system: " << GLWindow->timeSystem << '\n';
1231 str << "Date: " << GLWindow->creationDate << '\n';
1232 str << "Night: " << GLWindow->nightInt << '\n';
1233 str << "Camera: " << GLWindow->camera << '\n';
1234 str << "DAQ: " << GLWindow->daq << '\n';
1235 str << "ADC Count: " << GLWindow->adcCount << '\n';
1236 str << "NB Evts OK:" << GLWindow->nbOk << '\n';
1237 str << "NB Evts Rejected: " << GLWindow->nbRej << '\n';
1238 str << "NB Evts Bad: " << GLWindow->nbBad << '\n';
1239 extraInfoLabel->setText(QString(str.str().c_str()));
1240
1241 /*
1242 if (GLWindow->calibrationLoaded)
1243 {
1244 drawCalibrationCheckBox->setEnabled(true);
1245 }*/
1246
1247
1248}
1249/************************************************************
1250 * PLAY PAUSE CLICKED. ui handler
1251 ************************************************************/
1252void UIConnector::on_playPauseButton_clicked()
1253{
1254 if (timer.isActive())
1255 timer.stop();
1256 else
1257 timer.start();
1258}
1259
1260void UIConnector::displaySliceValue()
1261{
1262 if (!GLWindow->nRoi)
1263 return;
1264 if (GLWindow->selectedPixel == -1)
1265 {
1266 ostringstream str;
1267 str << " Current Pixel val.: --";
1268 currentPixelValue->setText(QString(str.str().c_str()));
1269 return;
1270 }
1271 const int idx =
1272 GLWindow->nRoi*GLWindow->hardwareMapping[GLWindow->selectedPixel]
1273 + GLWindow->whichSlice;
1274
1275 ostringstream str;
1276 str << "Current Pixel val.: " << GLWindow->eventData[idx];
1277 currentPixelValue->setText(QString(str.str().c_str()));
1278}
1279
1280/************************************************************
1281 * CURRENT SLICE HAS CHANGE. ui handler
1282 ************************************************************/
1283void UIConnector::currentSliceHasChanged(int slice)
1284{
1285 if (!GLWindow->nRoi)
1286 return;
1287
1288 if (updateSpinnerDisplay)
1289 displayingSliceBox->setValue(slice);
1290
1291 displaySliceValue();
1292}
1293
1294/*****
1295 *******************************************************
1296 * CURRENT EVENT HAS CHANGED. ui handler
1297 ************************************************************/
1298
1299double xval[50000];
1300double yval[50000];
1301void UIConnector::on_displayingEventBox_valueChanged(int cEvent)
1302{
1303// cout << "Here " << updateSpinnerDisplay << endl;
1304 if (!updateSpinnerDisplay)
1305 return;
1306 updateSpinnerDisplay = false;
1307// currentEventHasChanged(cEvent);
1308 GLWindow->rowNum = cEvent - GLWindow->eventStep;
1309 GLWindow->eventStepping(true);
1310 updateSpinnerDisplay = true;
1311
1312// GLWindow->updateGL();
1313}
1314void UIConnector::on_slicesPerSecValue_valueChanged(double value)
1315{
1316 timer.setInterval(1000.0/value);
1317}
1318void UIConnector::on_displayingSliceBox_valueChanged(int cSlice)
1319{
1320 updateSpinnerDisplay = false;
1321 currentSliceHasChanged(cSlice);
1322 updateSpinnerDisplay = true;
1323 GLWindow->whichSlice = cSlice;
1324 GLWindow->updateGL();
1325}
1326void UIConnector::currentEventHasChanged(int )
1327{
1328
1329 RMS_window->SetData(GLWindow->RMSvalues);
1330 Mean_window->SetData(GLWindow->Meanvalues);
1331 PosOfMax_window->SetData(GLWindow->PosOfMaxvalues);
1332 Max_window->SetData(GLWindow->Maxvalues);
1333
1334 if (RMS_window->isVisible())
1335 RMS_window->updateGL();
1336 if (Mean_window->isVisible())
1337 Mean_window->updateGL();
1338 if (PosOfMax_window->isVisible())
1339 PosOfMax_window->updateGL();
1340 if (Max_window->isVisible())
1341 Max_window->updateGL();
1342 ostringstream str;
1343// str << "Displaying Event " << cEvent;
1344// QString qstr(str.str().c_str());
1345// emit updateCurrentEventDisplay(qstr);
1346 if (updateSpinnerDisplay)
1347 {
1348 updateSpinnerDisplay = false;
1349 displayingEventBox->setValue(GLWindow->rowNum);
1350 updateSpinnerDisplay = true;
1351 }
1352
1353 // GLWindow->doWaveLetOnCurrentEventPlease();
1354
1355 //retrieve the data that we want to display
1356 boost::posix_time::ptime hrTime( boost::gregorian::date(1970, boost::gregorian::Jan, 1),
1357 boost::posix_time::seconds(GLWindow->pcTime[0]) + boost::posix_time::microsec(GLWindow->pcTime[1]));
1358
1359 str.str("");
1360 str << "PC Time: " << boost::posix_time::to_iso_extended_string(hrTime);
1361 PCTimeLabel->setText(QString(str.str().c_str()));
1362
1363 str.str("");
1364 str << "Software Trigger: " << GLWindow->softTrig;
1365 softwareTriggerLabel->setText(QString(str.str().c_str()));
1366
1367 str.str("");
1368 str << "Trigger Type: " << GLWindow->triggerType;
1369 triggerTypeLabel->setText(QString(str.str().c_str()));
1370
1371 displaySliceValue();
1372
1373 if (autoScaleColor->isChecked())
1374 emit GLWindow->colorPaletteHasChanged();//autoScalePressed();
1375
1376 boardsTimeList->clear();
1377 startPixelsList->clear();
1378 startTimeMarksList->clear();
1379 triggerDelayList->clear();
1380 std::map<int, int> boardsHistoMap;
1381 for (int i=0;i <NBOARDS; i++)
1382 {
1383 str.str("");
1384 str << i;
1385 if (i<10) str << " ";
1386 if (i<100) str << " ";
1387 if (i<1000) str << " ";
1388 str << ": " << GLWindow->boardTime[i];
1389 boardsTimeList->addItem(QString(str.str().c_str()));
1390 if (boardsHistoMap.find(GLWindow->boardTime[i]) != boardsHistoMap.end())
1391 boardsHistoMap[GLWindow->boardTime[i]]++;
1392 else
1393 boardsHistoMap[GLWindow->boardTime[i]] = 1;
1394 }
1395 std::map<int, int> pixelHistoMap;
1396 for (int i=0;i <NPIX; i++)
1397 {
1398 str.str("");
1399 str << i;
1400 if (i<10) str << " ";
1401 if (i<100) str << " ";
1402 if (i<1000) str << " ";
1403 str << ": " << GLWindow->startPix[i];
1404 startPixelsList->addItem(QString(str.str().c_str()));
1405 if (pixelHistoMap.find(GLWindow->startPix[i]) != pixelHistoMap.end())
1406 pixelHistoMap[GLWindow->startPix[i]]++;
1407 else
1408 pixelHistoMap[GLWindow->startPix[i]] = 1;
1409 }
1410
1411 std::map<int, int> timeMarksMap;
1412 for (int i=0;i <NTMARK; i++)
1413 {
1414 str.str("");
1415 str << i;
1416 if (i<10) str << " ";
1417 if (i<100) str << " ";
1418 if (i<1000) str << " ";
1419 str << ": " << GLWindow->startTM[i];
1420 startTimeMarksList->addItem(QString(str.str().c_str()));
1421 if (timeMarksMap.find(GLWindow->startTM[i]) != timeMarksMap.end())
1422 timeMarksMap[GLWindow->startTM[i]]++;
1423 else
1424 timeMarksMap[GLWindow->startTM[i]] = 1;
1425 }
1426 std::map<int,int> delayMap;
1427 triggerDelayList->addItem(QString("Patch | Slice:Delay Slice:Delay..."));
1428 for (int i=0;i<NTMARK; i++)
1429 {
1430 str.str("");
1431 str << i << " | ";
1432 for (int j=0;j<GLWindow->nRoi;j++)
1433 {
1434 int value = GLWindow->eventData[1440*GLWindow->nRoi + i*GLWindow->nRoi + j];
1435 if (delayMap.find(value) != delayMap.end())
1436 delayMap[value]++;
1437 else
1438 delayMap[value] = 1;
1439 str << j << ":" << value << " ";
1440 }
1441 triggerDelayList->addItem(QString(str.str().c_str()));
1442 }
1443
1444 std::map<int,int>::iterator it = boardsHistoMap.begin();
1445 int nsamples = 0;
1446 int previousValue = it->first-10;
1447 for (unsigned int i=0;i<boardsHistoMap.size();i++)
1448 {
1449 if (previousValue != it->first-1)
1450 {
1451 xval[nsamples] = previousValue+1;
1452 yval[nsamples] = 0;
1453 nsamples++;
1454 xval[nsamples] = it->first-1;
1455 yval[nsamples] = 0;
1456 nsamples++;
1457 }
1458 xval[nsamples] = it->first;
1459 yval[nsamples] = it->second;
1460 previousValue = it->first;
1461 it++;
1462 nsamples++;
1463 xval[nsamples] = previousValue;
1464 yval[nsamples] = 0;
1465 nsamples++;
1466 if (nsamples > 4090)
1467 {
1468 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1469 break;
1470 }
1471 }
1472 xval[nsamples] = it==boardsHistoMap.begin() ? 0 : (--it)->first+1;
1473 yval[nsamples] = 0;
1474 nsamples++;
1475 // if (nsamples > 5)
1476#if QWT_VERSION < 0x060000
1477 boardsTimeHistoItem.setData(xval, yval, nsamples);
1478#else
1479 boardsTimeHistoItem.setSamples(xval, yval, nsamples);
1480#endif
1481
1482 it = pixelHistoMap.begin();
1483 nsamples = 0;
1484 previousValue = it->first-10;
1485 for (unsigned int i=0;i<pixelHistoMap.size();i++)
1486 {
1487 if (previousValue != it->first-1)
1488 {
1489 xval[nsamples] = previousValue+1;
1490 yval[nsamples] = 0;
1491 nsamples++;
1492 xval[nsamples] = it->first-1;
1493 yval[nsamples] = 0;
1494 nsamples++;
1495 }
1496 xval[nsamples] = it->first;
1497 yval[nsamples] = it->second;
1498 previousValue = it->first;
1499 it++;
1500 nsamples++;
1501 xval[nsamples] = previousValue;
1502 yval[nsamples] = 0;
1503 nsamples++;
1504 if (nsamples > 4090)
1505 {
1506 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1507 break;
1508 }
1509 }
1510 xval[nsamples] = it==pixelHistoMap.begin() ? 0 : (--it)->first+1;
1511 yval[nsamples] = 0;
1512 nsamples++;
1513// if (nsamples > 5)
1514#if QWT_VERSION < 0x060000
1515 startCellHistoItem.setData(xval, yval, nsamples);
1516#else
1517 startCellHistoItem.setSamples(xval, yval, nsamples);
1518#endif
1519
1520 it = timeMarksMap.begin();
1521 nsamples = 0;
1522 previousValue = it->first-10;
1523 for (unsigned int i=0;i<timeMarksMap.size();i++)
1524 {
1525 if (previousValue != it->first-1)
1526 {
1527 xval[nsamples] = previousValue+1;
1528 yval[nsamples] = 0;
1529 nsamples++;
1530 xval[nsamples] = it->first-1;
1531 yval[nsamples] = 0;
1532 nsamples++;
1533 }
1534 xval[nsamples] = it->first;
1535 yval[nsamples] = it->second;
1536 previousValue = it->first;
1537 it++;
1538 nsamples++;
1539 xval[nsamples] = previousValue;
1540 yval[nsamples] = 0;
1541 nsamples++;
1542 if (nsamples > 4090)
1543 {
1544 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1545 break;
1546 }
1547 }
1548 xval[nsamples] = it==timeMarksMap.begin() ? 0 : (--it)->first+1;
1549 yval[nsamples] = 0;
1550 nsamples++;
1551 // if (nsamples > 5)
1552#if QWT_VERSION < 0x060000
1553 startTimeMarkHistoItem.setData(xval, yval, nsamples);
1554#else
1555 startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
1556#endif
1557
1558 it = delayMap.begin();
1559 nsamples = 0;
1560 previousValue = it->first-10;
1561 for (unsigned int i=0;i<delayMap.size();i++)
1562 {
1563 if (previousValue != it->first-1)
1564 {
1565 xval[nsamples] = previousValue+1;
1566 yval[nsamples] = 0;
1567 nsamples++;
1568 xval[nsamples] = it->first-1;
1569 yval[nsamples] = 0;
1570 nsamples++;
1571 }
1572 xval[nsamples] = it->first;
1573 yval[nsamples] = it->second;
1574 previousValue = it->first;
1575 it++;
1576 nsamples++;
1577 xval[nsamples] = previousValue;
1578 yval[nsamples] = 0;
1579 nsamples++;
1580 if (nsamples > 4090)
1581 {
1582 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1583 break;
1584 }
1585 }
1586 xval[nsamples] = it==delayMap.begin() ? 0 : (--it)->first+1;
1587 yval[nsamples] = 0;
1588 nsamples++;
1589 // if (nsamples > 5)
1590#if QWT_VERSION < 0x060000
1591 triggerDelayHistoItem.setData(xval, yval, nsamples);
1592#else
1593 triggerDelayHistoItem.setSamples(xval, yval, nsamples);
1594#endif
1595 //WAVELETS HACK
1596/* std::map<int, int> valuesHistoMap;
1597 std::map<int, int> waveletHistoMap;
1598 for (int i=0;i<1024*1440;i++)
1599 {
1600 if (valuesHistoMap.find(GLWindow->rawEventData[i]) != valuesHistoMap.end())
1601 valuesHistoMap[GLWindow->rawEventData[i]]++;
1602 else
1603 valuesHistoMap[GLWindow->rawEventData[i]] = 1;
1604 if (waveletHistoMap.find(GLWindow->waveLetArray[i]) != waveletHistoMap.end())
1605 waveletHistoMap[GLWindow->waveLetArray[i]]++;
1606 else
1607 waveletHistoMap[GLWindow->waveLetArray[i]] = 1;
1608 }
1609
1610 it = valuesHistoMap.begin();
1611 nsamples = 0;
1612 previousValue = it->first-10;
1613 cout << "Num values Original: " << valuesHistoMap.size() << endl;
1614 for (unsigned int i=0;i<valuesHistoMap.size();i++)
1615 {
1616 if (previousValue != it->first-1)
1617 {
1618 xval[nsamples] = previousValue+1;
1619 yval[nsamples] = 0;
1620 nsamples++;
1621 xval[nsamples] = it->first-1;
1622 yval[nsamples] = 0;
1623 nsamples++;
1624 }
1625 xval[nsamples] = it->first;
1626 yval[nsamples] = it->second;
1627 previousValue = it->first;
1628 it++;
1629 nsamples++;
1630 xval[nsamples] = previousValue;
1631 yval[nsamples] = 0;
1632 nsamples++;
1633 if (nsamples > 50000)
1634 {
1635 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1636 break;
1637 }
1638 }
1639 xval[nsamples] = it==valuesHistoMap.begin() ? 0 : (--it)->first+1;
1640 yval[nsamples] = 0;
1641 nsamples++;
1642 // if (nsamples > 5)
1643 #if QWT_VERSION < 0x060000
1644 triggerDelayHistoItem.setData(xval, yval, nsamples);
1645 #else
1646 triggerDelayHistoItem.setSamples(xval, yval, nsamples);
1647 #endif
1648
1649 it = waveletHistoMap.begin();
1650 nsamples = 0;
1651 previousValue = it->first-10;
1652 cout << "Num values WaveLets: " << waveletHistoMap.size() << endl;
1653 for (unsigned int i=0;i<waveletHistoMap.size();i++)
1654 {
1655 if (previousValue != it->first-1)
1656 {
1657 xval[nsamples] = previousValue+1;
1658 yval[nsamples] = 0;
1659 nsamples++;
1660 xval[nsamples] = it->first-1;
1661 yval[nsamples] = 0;
1662 nsamples++;
1663 }
1664 xval[nsamples] = it->first;
1665 yval[nsamples] = it->second;
1666 previousValue = it->first;
1667 it++;
1668 nsamples++;
1669 xval[nsamples] = previousValue;
1670 yval[nsamples] = 0;
1671 nsamples++;
1672 if (nsamples > 50000)
1673 {
1674 cout << "Error: Maximum number of samples reached for histograms. skipping what's remaining" << endl;
1675 break;
1676 }
1677 }
1678 xval[nsamples] = it==waveletHistoMap.begin() ? 0 : (--it)->first+1;
1679 yval[nsamples] = 0;
1680 nsamples++;
1681 // if (nsamples > 5)
1682 #if QWT_VERSION < 0x060000
1683 startTimeMarkHistoItem.setData(xval, yval, nsamples);
1684 #else
1685 startTimeMarkHistoItem.setSamples(xval, yval, nsamples);
1686 #endif
1687*/
1688//END OF WAVELETS HACK
1689 // startCellHistoZoom->setZoomBase(startCellHistoItem.boundingRect());
1690 QStack< QRectF > stack;
1691// QRectF cRectangle = boardsTimeHistoItem.boundingRect();
1692 stack.push(scaleBoundingRectangle(boardsTimeHistoItem.boundingRect(), 1.05f));//cRectangle);//boardsTimeHistoItem.boundingRect());
1693 boardsTimeHistoZoom->setZoomStack(stack);
1694 stack.pop();
1695 stack.push(scaleBoundingRectangle(startCellHistoItem.boundingRect(), 1.05f));
1696 startCellHistoZoom->setZoomStack(stack);
1697 stack.pop();
1698 stack.push(scaleBoundingRectangle(startTimeMarkHistoItem.boundingRect(), 1.05f));
1699 startTimeMarkHistoZoom->setZoomStack(stack);
1700 stack.pop();
1701 stack.push(scaleBoundingRectangle(triggerDelayHistoItem.boundingRect(), 1.05f));
1702 triggerDelayHistoZoom->setZoomStack(stack);
1703 stack.pop();
1704
1705 pixelChanged(GLWindow->selectedPixel);
1706}
1707//can't use a ref to rectangle, as the type must be converted first
1708QRectF UIConnector::scaleBoundingRectangle(QRectF rectangle, float scale)
1709{
1710 QPointF bottomRight = rectangle.bottomRight();
1711 QPointF topLeft = rectangle.topLeft();
1712 QPointF center = rectangle.center();
1713 return QRectF(topLeft + (topLeft-center)*(scale-1.0f), //top left
1714 bottomRight + (bottomRight-center)*(scale-1.0f)); //bottom right
1715}
1716void UIConnector::initHistograms()
1717{
1718// QwtPlot* boardsTimeHisto;
1719// QwtPlotHistogram boardsTimeHistoItem;
1720 grid1 = new QwtPlotGrid;
1721 grid1->enableX(false);
1722 grid1->enableY(true);
1723 grid1->enableXMin(false);
1724 grid1->enableYMin(false);
1725 grid1->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1726 grid1->attach(boardsTimeHisto);
1727
1728 grid2 = new QwtPlotGrid;
1729 grid2->enableX(false);
1730 grid2->enableY(true);
1731 grid2->enableXMin(false);
1732 grid2->enableYMin(false);
1733 grid2->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1734 grid2->attach(startCellsHisto);
1735
1736 grid3 = new QwtPlotGrid;
1737 grid3->enableX(false);
1738 grid3->enableY(true);
1739 grid3->enableXMin(false);
1740 grid3->enableYMin(false);
1741 grid3->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1742 grid3->attach(startTimeMarkHisto);
1743
1744 grid4 = new QwtPlotGrid;
1745 grid4->enableX(false);
1746 grid4->enableY(true);
1747 grid4->enableXMin(false);
1748 grid4->enableYMin(false);
1749 grid4->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1750 grid4->attach(pixelValueCurve);
1751
1752 grid6 = new QwtPlotGrid;
1753 grid6->enableX(false);
1754 grid6->enableY(true);
1755 grid6->enableXMin(false);
1756 grid6->enableYMin(false);
1757 grid6->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1758 grid6->attach(pixelAverageCurve);
1759
1760 grid5 = new QwtPlotGrid;
1761 grid5->enableX(false);
1762 grid5->enableY(true);
1763 grid5->enableXMin(false);
1764 grid5->enableYMin(false);
1765 grid5->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
1766 grid5->attach(triggerDelayHisto);
1767
1768 boardsTimeHisto->setAutoReplot(true);
1769 startCellsHisto->setAutoReplot(true);
1770 startTimeMarkHisto->setAutoReplot(true);
1771 pixelValueCurve->setAutoReplot(true);
1772 pixelAverageCurve->setAutoReplot(true);
1773 triggerDelayHisto->setAutoReplot(true);
1774 boardsTimeHisto->setTitle("Boards time values");
1775 startCellsHisto->setTitle("Start Cell values");
1776 startTimeMarkHisto->setTitle("Start Time Marks values");
1777 pixelValueCurve->setTitle("Current pixel values");
1778 pixelAverageCurve->setTitle("Average pixels values");
1779 triggerDelayHisto->setTitle("Trigger Delays");
1780
1781 // boardsTimeHistoItem.setBrush(QBrush(Qt::red));
1782// startCellHistoItem.setBrush(QBrush(Qt::red));
1783// startTimeMarkHistoItem.setBrush(QBrush(Qt::red));
1784// triggerDelayHistoItem.setBrush(QBrush(Qt::red));
1785// pixelValueCurveItem.setBrush(QBrush(Qt::red));
1786
1787 boardsTimeHistoItem.setPen(QColor(Qt::darkGreen));
1788 boardsTimeHistoItem.setStyle(QwtPlotCurve::Steps);
1789 startCellHistoItem.setPen(QColor(Qt::darkGreen));
1790 startCellHistoItem.setStyle(QwtPlotCurve::Steps);
1791 startTimeMarkHistoItem.setPen(QColor(Qt::darkGreen));
1792 startTimeMarkHistoItem.setStyle(QwtPlotCurve::Steps);
1793 triggerDelayHistoItem.setPen(QColor(Qt::darkGreen));
1794 triggerDelayHistoItem.setStyle(QwtPlotCurve::Steps);
1795
1796 boardsTimeHistoItem.attach(boardsTimeHisto);
1797 startCellHistoItem.attach(startCellsHisto);
1798 startTimeMarkHistoItem.attach(startTimeMarkHisto);
1799 triggerDelayHistoItem.attach(triggerDelayHisto);
1800
1801 //curve
1802// pixelValueCurveItem.setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::black), QSize(5,5)));
1803 pixelValueCurveItem.setPen(QColor(Qt::black));
1804 pixelAverageCurveItem.setPen(QColor(Qt::black));
1805 aMeanCurveItem.setPen(QColor(Qt::darkGreen));
1806 vCorrCurveItem.setPen(QColor(Qt::red));
1807 meanCurveItem.setPen(QColor(Qt::blue));
1808 pixelValueCurveItem.setStyle(QwtPlotCurve::Lines);
1809 pixelAverageCurveItem.setStyle(QwtPlotCurve::Lines);
1810 aMeanCurveItem.setStyle(QwtPlotCurve::Lines);
1811 vCorrCurveItem.setStyle(QwtPlotCurve::Lines);
1812 meanCurveItem.setStyle(QwtPlotCurve::Lines);
1813
1814// pixelValueCurveItem.setCurveAttribute(QwtPlotCurve::Fitted);
1815 pixelValueCurveItem.attach(pixelValueCurve);
1816 pixelAverageCurveItem.attach(pixelAverageCurve);
1817// aMeanCurveItem.attach(pixelValueCurve);
1818 // vCorrCurveItem.attach(pixelValueCurve);
1819// meanCurveItem.attach(pixelValueCurve);
1820
1821 //FIXME delete these pointers with the destructor
1822 curveZoom = new QwtPlotZoomer(pixelValueCurve->canvas());
1823 curveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1824 curveZoom->setTrackerPen(QPen(Qt::gray));
1825 averageCurveZoom = new QwtPlotZoomer(pixelAverageCurve->canvas());
1826 averageCurveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1827 averageCurveZoom->setTrackerPen(QPen(Qt::gray));
1828
1829 boardsTimeHistoZoom = new QwtPlotZoomer(boardsTimeHisto->canvas());
1830 boardsTimeHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1831 boardsTimeHistoZoom->setTrackerPen(QPen(Qt::gray));
1832
1833 startCellHistoZoom = new QwtPlotZoomer(startCellsHisto->canvas());
1834 startCellHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1835 startCellHistoZoom->setTrackerPen(QPen(Qt::gray));
1836
1837 startTimeMarkHistoZoom = new QwtPlotZoomer(startTimeMarkHisto->canvas());
1838 startTimeMarkHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1839 startTimeMarkHistoZoom->setTrackerPen(QPen(Qt::gray));
1840
1841 triggerDelayHistoZoom = new QwtPlotZoomer(triggerDelayHisto->canvas());
1842 triggerDelayHistoZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
1843 triggerDelayHistoZoom->setTrackerPen(QPen(Qt::gray));
1844
1845
1846}
1847
1848void UIConnector::pixelChanged(int pixel)
1849{
1850 RMS_window->fWhite = pixel;
1851 Mean_window->fWhite = pixel;
1852 Max_window->fWhite = pixel;
1853 PosOfMax_window->fWhite = pixel;
1854 if (pixel != -1)
1855 {
1856 RMS_window->fWhitePatch = RMS_window->pixelsPatch[pixel];
1857 Mean_window->fWhitePatch = Mean_window->pixelsPatch[pixel];
1858 Max_window->fWhitePatch = Max_window->pixelsPatch[pixel];
1859 PosOfMax_window->fWhitePatch = PosOfMax_window->pixelsPatch[pixel];
1860 }
1861 else
1862 {
1863 RMS_window->fWhitePatch = -1;
1864 Mean_window->fWhitePatch = -1;
1865 Max_window->fWhitePatch = -1;
1866 PosOfMax_window->fWhitePatch = -1;
1867 }
1868 if (pixel == -1)
1869 return;
1870 int softwarePix = pixel;
1871 pixel = GLWindow->hardwareMapping[pixel];
1872
1873 HwIDBox->setValue(pixel);
1874
1875 if (!GLWindow->nRoi)
1876 return;
1877
1878int currentPixel = pixel;
1879
1880 for (int i=0;i<GLWindow->nRoi;i++)
1881 {
1882 xval[i] = i;
1883 yval[i] = GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
1884 }
1885
1886
1887int realNumSamples = GLWindow->nRoi;
1888 if (GLWindow->nRoiTM != 0)
1889 {
1890 const PixelMapEntry& mapEntry = GLWindow->fPixelMap.index(softwarePix);
1891 const int pixelIdInPatch = mapEntry.pixel();
1892 const int patchId = mapEntry.patch();
1893 const int boardId = mapEntry.board();
1894 const int crateId = mapEntry.crate();
1895 if (pixelIdInPatch == 8)
1896 {
1897 int TMIndex = 0;
1898 int xIndex = GLWindow->nRoi;
1899 int arrayIndex = GLWindow->nRoi;
1900 if (GLWindow->offSetRoi < 0)
1901 TMIndex -= GLWindow->offSetRoi;
1902 if (GLWindow->offSetRoi > 0)
1903 xIndex += GLWindow->offSetRoi;
1904 for (int i=TMIndex;i<GLWindow->nRoiTM;i++, xIndex++, arrayIndex++)
1905 {
1906 xval[arrayIndex] = xIndex;
1907 yval[arrayIndex] = GLWindow->eventData[GLWindow->nRoi*1440 + GLWindow->nRoiTM*(40*crateId + 4*boardId + patchId) + i];
1908 }
1909 realNumSamples += GLWindow->nRoiTM - TMIndex;
1910 }
1911 // cout << pixelIdInPatch << " " ;
1912 }
1913
1914#if QWT_VERSION < 0x060000
1915 pixelValueCurveItem.setData(xval, yval, realNumSamples);
1916#else
1917 pixelValueCurveItem.setSamples(xval, yval, realNumSamples);
1918#endif
1919
1920//now compute the average value of all pixels
1921 currentPixel = 0;
1922 for (int i=0;i<GLWindow->nRoi;i++)
1923 yval[i] = 0;
1924 for (int j=0;j<1440;j++) {
1925 currentPixel = j;
1926 for (int i=0;i<GLWindow->nRoi;i++)
1927 {
1928 xval[i] = i;
1929 yval[i] += GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
1930 }
1931 }
1932 for (int i=0;i<GLWindow->nRoi;i++)
1933 yval[i] /= 1440;
1934#if QWT_VERSION < 0x060000
1935 pixelAverageCurveItem.setData(xval, yval, GLWindow->nRoi);
1936#else
1937 pixelAverageCurveItem.setSamples(xval, yval, realNumSamples);
1938#endif
1939
1940 QStack< QRectF > stack;
1941 stack.push(scaleBoundingRectangle(pixelValueCurveItem.boundingRect(), 1.5f));
1942 curveZoom->setZoomStack(stack);
1943 stack.pop();
1944 stack.push(scaleBoundingRectangle(pixelAverageCurveItem.boundingRect(), 1.5f));
1945 averageCurveZoom->setZoomStack(stack);
1946 stack.pop();
1947
1948 displaySliceValue();
1949 on_autoScaleColor_clicked();
1950}
1951
1952void UIConnector::on_HwIDBox_valueChanged(int)
1953{
1954 updating = true;
1955
1956 const int hwID = HwIDBox->value();
1957
1958 const int crateID = hwID/360;
1959 const int boardID = (hwID%360)/36;
1960 const int patchID = (hwID%36 )/9;
1961 const int pixelID = hwID%9;
1962
1963 SwIDBox->setValue(GLWindow->softwareMapping[hwID]);
1964
1965 crateIDBox->setValue(crateID);
1966 boardIDBox->setValue(boardID);
1967 patchIDBox->setValue(patchID);
1968 pixelIDBox->setValue(pixelID);
1969
1970 updating = false;
1971
1972 GLWindow->selectedPixel = GLWindow->softwareMapping[hwID];
1973 GLWindow->updateGL();
1974
1975 pixelChanged(GLWindow->selectedPixel);
1976}
1977
1978void UIConnector::cbpxChanged()
1979{
1980 if (updating)
1981 return;
1982
1983 const int hwid = crateIDBox->value()*360 + boardIDBox->value()*36 + patchIDBox->value()*9 + pixelIDBox->value();
1984 HwIDBox->setValue(hwid);
1985}
1986
1987void UIConnector::on_SwIDBox_valueChanged(int swid)
1988{
1989 if (updating)
1990 return;
1991
1992 HwIDBox->setValue(GLWindow->hardwareMapping[swid]);
1993}
1994
1995void UIConnector::on_autoScaleColor_clicked()
1996{
1997 if (!autoScaleColor->isChecked())
1998 {
1999 GLWindow->ss[0] = 0.496;
2000 GLWindow->ss[1] = 0.507;
2001 GLWindow->ss[2] = 0.518;
2002 GLWindow->ss[3] = 0.529;
2003 GLWindow->ss[4] = 0.540;;
2004 colorRange0->setValue(GLWindow->ss[0]);
2005 colorRange1->setValue(GLWindow->ss[1]);
2006 colorRange2->setValue(GLWindow->ss[2]);
2007 colorRange3->setValue(GLWindow->ss[3]);
2008 colorRange4->setValue(GLWindow->ss[4]);
2009 return;
2010 }
2011 if (!GLWindow->nRoi)
2012 return;
2013
2014 int start = 0;
2015 int end = 1440;
2016
2017 if (!entireCameraScale->isChecked())
2018 {
2019 start = GLWindow->selectedPixel;
2020 end = GLWindow->selectedPixel+1;
2021 if (end == 0)
2022 {
2023 start = 0;
2024 end = 1440;
2025 }
2026 }
2027
2028 int min = 100000; //real min = -2048, int_16 = -32768 to 32767
2029 int max = -100000; //real max = 2047
2030
2031 long average = 0;
2032 long numSamples = 0;
2033 int errorDetected = -1;
2034
2035 for (int i=start;i<end;i++)
2036 {
2037 if (i==863)//keep crazy pixel out of the autoscale
2038 continue;
2039 for (int j=10;j<GLWindow->nRoi-50;j++)
2040 {
2041 int cValue = GLWindow->eventData[i*GLWindow->nRoi+j];
2042 if (cValue > max && cValue < 32767)
2043 max = cValue;
2044 if (cValue < min && cValue > -32768)
2045 min = cValue;
2046 if (cValue < 32767 && cValue > -32768)
2047 {
2048 average+=cValue;
2049 numSamples++;
2050 }
2051 else
2052 {
2053 errorDetected = i;
2054 }
2055// numSamples++;
2056 }
2057 }
2058 average /= numSamples;
2059 if (errorDetected != -1)
2060 {
2061 cout << "Overflow detected at pixel " << errorDetected << " (at least)" << endl;
2062 }
2063// cout << "min: " << min << " max: " << max << " average: " << average << endl;
2064 float minRange = (float)(min+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
2065 float maxRange = (float)(max+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
2066 float midRange = (float)(average+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
2067 if (GLWindow->logScale)
2068 {
2069 minRange *= 9;
2070 maxRange *= 9;
2071// midRange *= 9;
2072 minRange += 1;
2073 maxRange += 1;
2074// midRange += 1;
2075 minRange = log10(minRange);
2076 maxRange = log10(maxRange);
2077// midRange = (minRange + maxRange)/2.f;
2078 midRange = log10(midRange);
2079 }
2080
2081 GLWindow->ss[0] = minRange;
2082 colorRange0->setValue(GLWindow->ss[0]);
2083 GLWindow->ss[4] = maxRange;
2084 colorRange4->setValue(GLWindow->ss[4]);
2085// GLWindow->ss[2] = midRange;
2086// range2->setValue(GLWindow->ss[2]);
2087// GLWindow->ss[1] = (minRange+midRange)/2;
2088// range1->setValue(GLWindow->ss[1]);
2089// GLWindow->ss[3] = (maxRange+midRange)/2;
2090// range3->setValue(GLWindow->ss[3]);
2091
2092 GLWindow->ss[2] = (maxRange+minRange)/2;
2093 colorRange2->setValue(GLWindow->ss[2]);
2094
2095 GLWindow->ss[1] = minRange+(maxRange-minRange)/4;
2096 colorRange1->setValue(GLWindow->ss[1]);
2097
2098 GLWindow->ss[3] = minRange+3*(maxRange-minRange)/4;
2099 colorRange3->setValue(GLWindow->ss[3]);
2100}
2101
2102void PrintUsage()
2103{
2104 cout << "\n"
2105 "The FACT++ raw data viewer.\n"
2106 "\n"
2107 "Usage: viewer [OPTIONS] [datafile.fits[.gz] [calibration.drs.fits[.gz]]]\n"
2108 " or: viewer [OPTIONS]\n";
2109 cout << endl;
2110
2111}
2112
2113void PrintHelp()
2114{
2115 cout <<
2116 "\n"
2117 << endl;
2118}
2119
2120int UIConnector::SetupConfiguration(Configuration &conf)
2121{
2122 RawDataViewer *canvas = GLWindow;
2123
2124 if (conf.Has("color.range"))
2125 {
2126 vector<double> value = conf.Vec<double>("color.range");
2127 if (value.size() != 5)
2128 {
2129 cout << "Error, colorRange option should have exactly 5 double values" << endl;
2130 return -1;
2131 }
2132 for (int i=0;i<5;i++)
2133 canvas->ss[i] = value[i];
2134 }
2135
2136 if (conf.Has("color.red"))
2137 {
2138 vector<double> value = conf.Vec<double>("color.red");
2139 if (value.size() != 5)
2140 {
2141 cout << "Error, colorRed option should have exactly 5 double values" << endl;
2142 return -1;
2143 }
2144 for (int i=0;i<5;i++)
2145 canvas->rr[i] = value[i];
2146 }
2147
2148 if (conf.Has("color.green"))
2149 {
2150 vector<double> value = conf.Vec<double>("color.green");
2151 if (value.size() != 5)
2152 {
2153 cout << "Error, colorGreen option should have exactly 5 double values" << endl;
2154 return -1;
2155 }
2156 for (int i=0;i<5;i++)
2157 canvas->gg[i] = value[i];
2158 }
2159
2160 if (conf.Has("color.blue"))
2161 {
2162 vector<double> value = conf.Vec<double>("color.blue");
2163 if (value.size() != 5)
2164 {
2165 cout << "Error, colorBlue option should have exactly 5 double values" << endl;
2166 return -1;
2167 }
2168 for (int i=0;i<5;i++)
2169 canvas->bb[i] = value[i];
2170 }
2171
2172 colorRange0->setValue(canvas->ss[0]);
2173 colorRange1->setValue(canvas->ss[1]);
2174 colorRange2->setValue(canvas->ss[2]);
2175 colorRange3->setValue(canvas->ss[3]);
2176 colorRange4->setValue(canvas->ss[4]);
2177 redValue0->setValue(canvas->rr[0]);
2178 redValue1->setValue(canvas->rr[1]);
2179 redValue2->setValue(canvas->rr[2]);
2180 redValue3->setValue(canvas->rr[3]);
2181 redValue4->setValue(canvas->rr[4]);
2182 greenValue0->setValue(canvas->gg[0]);
2183 greenValue1->setValue(canvas->gg[1]);
2184 greenValue2->setValue(canvas->gg[2]);
2185 greenValue3->setValue(canvas->gg[3]);
2186 greenValue4->setValue(canvas->gg[4]);
2187 blueValue0->setValue(canvas->bb[0]);
2188 blueValue1->setValue(canvas->bb[1]);
2189 blueValue2->setValue(canvas->bb[2]);
2190 blueValue3->setValue(canvas->bb[3]);
2191 blueValue4->setValue(canvas->bb[4]);
2192
2193 if (conf.Has("drs"))
2194 {
2195 const QString qstr(conf.Get<string>("drs").c_str());
2196 calibFileSelected(qstr);
2197 }
2198
2199 if (conf.Has("file"))
2200 {
2201 const QString qstr(conf.Get<string>("file").c_str());
2202 fileSelected(qstr);
2203 }
2204
2205
2206 return 0;
2207}
2208
2209void SetupConfiguration(Configuration& conf)
2210{
2211 po::options_description configs("Raw Events Viewer Options");
2212 configs.add_options()
2213 ("color.range", vars<double>(), "Range of the display colours")
2214 ("color.red", vars<double>(), "Range of red values")
2215 ("color.green", vars<double>(), "Range of green values")
2216 ("color.blue", vars<double>(), "Range of blue values")
2217 ("file,f", var<string>(), "File to be loaded")
2218 ("drs,d", var<string>(), "DRS calibration file to be loaded")
2219 ;
2220 conf.AddOptions(configs);
2221
2222 po::positional_options_description p;
2223 p.add("file", 1); // The first positional options
2224 p.add("drs", 2); // The first positional options
2225 conf.SetArgumentPositions(p);
2226
2227}
2228
2229/************************************************************
2230 * MAIN PROGRAM FUNCTION.
2231 ************************************************************/
2232int main(int argc, const char *argv[])
2233{
2234 QApplication app(argc, const_cast<char**>(argv));
2235
2236 if (!QGLFormat::hasOpenGL()) {
2237 std::cerr << "This system has no OpenGL support" << std::endl;
2238 return 1;
2239 }
2240
2241 Configuration conf(argv[0]);
2242 conf.SetPrintUsage(PrintUsage);
2243 SetupConfiguration(conf);
2244 if (!conf.DoParse(argc, argv, PrintHelp))
2245 return 2;
2246
2247 UIConnector myUi;
2248 if (myUi.SetupConfiguration(conf)<0)
2249 return 3;
2250
2251 return app.exec();
2252}
2253
Note: See TracBrowser for help on using the repository browser.