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

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