Index: trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
===================================================================
--- trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 12671)
+++ trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 12677)
@@ -489,5 +489,5 @@
  * CONSTRUCTOR.
  ************************************************************/
-RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent), RMSvalues(1440)
+RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent), RMSvalues(1440), Meanvalues(1440), Maxvalues(1440), PosOfMaxvalues(1440)
 {
  //   setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
@@ -1192,6 +1192,11 @@
 
     for (vector<PixelMapEntry>::const_iterator it=fPixelMap.begin(); it!=fPixelMap.end(); it++)
-        RMSvalues[it->index] = pixelStatsData[1*1440+it->hw()];
-
+    {
+        Meanvalues[it->index]     = pixelStatsData[0*1440+it->hw()];
+        RMSvalues[it->index]      = pixelStatsData[1*1440+it->hw()];
+        Maxvalues[it->index]      = pixelStatsData[2*1440+it->hw()];
+        PosOfMaxvalues[it->index] = pixelStatsData[3*1440+it->hw()];
+
+    }
     if (nRoiTM == 0)//move back the data back in place
     {
@@ -1391,6 +1396,10 @@
     entireCameraScale->setChecked(true);
 
-    GLWindow_2->enableText(false);
- //   GLWindow_2->ShowPatchCursor(true);
+    RMS_window->enableText(false);
+    Mean_window->enableText(false);
+    PosOfMax_window->enableText(false);
+    Max_window->enableText(false);
+
+ //   RMS_window->ShowPatchCursor(true);
 
     QObject::connect(GLWindow, SIGNAL(colorPaletteHasChanged()),
@@ -1405,6 +1414,13 @@
                      this, SLOT(newFileLoaded()));
 
-    QObject::connect(GLWindow_2, SIGNAL(signalCurrentPixel(int)),
+    QObject::connect(RMS_window, SIGNAL(signalCurrentPixel(int)),
                      GLWindow, SLOT(setCurrentPixel(int)));
+    QObject::connect(Max_window, SIGNAL(signalCurrentPixel(int)),
+                     GLWindow, SLOT(setCurrentPixel(int)));
+    QObject::connect(PosOfMax_window, SIGNAL(signalCurrentPixel(int)),
+                     GLWindow, SLOT(setCurrentPixel(int)));
+    QObject::connect(Mean_window, SIGNAL(signalCurrentPixel(int)),
+                     GLWindow, SLOT(setCurrentPixel(int)));
+
 
 
@@ -1418,8 +1434,10 @@
     grid4->detach();
     grid5->detach();
+    grid6->detach();
     boardsTimeHistoItem.detach();
     startCellHistoItem.detach();
     startTimeMarkHistoItem.detach();
     pixelValueCurveItem.detach();
+    pixelAverageCurveItem.detach();
     aMeanCurveItem.detach();
     vCorrCurveItem.detach();
@@ -1702,7 +1720,17 @@
 {
 
-    GLWindow_2->SetData(GLWindow->RMSvalues);
-    if (GLWindow_2->isVisible())
-        GLWindow_2->updateGL();
+    RMS_window->SetData(GLWindow->RMSvalues);
+    Mean_window->SetData(GLWindow->Meanvalues);
+    PosOfMax_window->SetData(GLWindow->PosOfMaxvalues);
+    Max_window->SetData(GLWindow->Maxvalues);
+
+    if (RMS_window->isVisible())
+        RMS_window->updateGL();
+    if (Mean_window->isVisible())
+        Mean_window->updateGL();
+    if (PosOfMax_window->isVisible())
+        PosOfMax_window->updateGL();
+    if (Max_window->isVisible())
+        Max_window->updateGL();
     ostringstream str;
 //    str << "Displaying Event " << cEvent;
@@ -2115,4 +2143,12 @@
     grid4->attach(pixelValueCurve);
 
+    grid6 = new QwtPlotGrid;
+    grid6->enableX(false);
+    grid6->enableY(true);
+    grid6->enableXMin(false);
+    grid6->enableYMin(false);
+    grid6->setMajPen(QPen(Qt::black, 0, Qt::DotLine));
+    grid6->attach(pixelAverageCurve);
+
     grid5 = new QwtPlotGrid;
     grid5->enableX(false);
@@ -2127,4 +2163,5 @@
     startTimeMarkHisto->setAutoReplot(true);
     pixelValueCurve->setAutoReplot(true);
+    pixelAverageCurve->setAutoReplot(true);
     triggerDelayHisto->setAutoReplot(true);
     boardsTimeHisto->setTitle("Boards time values");
@@ -2132,4 +2169,5 @@
     startTimeMarkHisto->setTitle("Start Time Marks values");
     pixelValueCurve->setTitle("Current pixel values");
+    pixelAverageCurve->setTitle("Average pixels values");
     triggerDelayHisto->setTitle("Trigger Delays");
 
@@ -2157,8 +2195,10 @@
 //    pixelValueCurveItem.setSymbol(new QwtSymbol(QwtSymbol::Cross, Qt::NoBrush, QPen(Qt::black), QSize(5,5)));
     pixelValueCurveItem.setPen(QColor(Qt::black));
+    pixelAverageCurveItem.setPen(QColor(Qt::black));
     aMeanCurveItem.setPen(QColor(Qt::darkGreen));
     vCorrCurveItem.setPen(QColor(Qt::red));
     meanCurveItem.setPen(QColor(Qt::blue));
     pixelValueCurveItem.setStyle(QwtPlotCurve::Lines);
+    pixelAverageCurveItem.setStyle(QwtPlotCurve::Lines);
     aMeanCurveItem.setStyle(QwtPlotCurve::Lines);
     vCorrCurveItem.setStyle(QwtPlotCurve::Lines);
@@ -2167,4 +2207,5 @@
 //    pixelValueCurveItem.setCurveAttribute(QwtPlotCurve::Fitted);
     pixelValueCurveItem.attach(pixelValueCurve);
+    pixelAverageCurveItem.attach(pixelAverageCurve);
 //    aMeanCurveItem.attach(pixelValueCurve);
  //   vCorrCurveItem.attach(pixelValueCurve);
@@ -2175,4 +2216,7 @@
     curveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
     curveZoom->setTrackerPen(QPen(Qt::gray));
+    averageCurveZoom = new QwtPlotZoomer(pixelAverageCurve->canvas());
+    averageCurveZoom->setRubberBandPen(QPen(Qt::gray, 2, Qt::DotLine));
+    averageCurveZoom->setTrackerPen(QPen(Qt::gray));
 
     boardsTimeHistoZoom = new QwtPlotZoomer(boardsTimeHisto->canvas());
@@ -2197,9 +2241,22 @@
 void UIConnector::pixelChanged(int pixel)
 {
-    GLWindow_2->fWhite = pixel;
+    RMS_window->fWhite = pixel;
+    Mean_window->fWhite = pixel;
+    Max_window->fWhite = pixel;
+    PosOfMax_window->fWhite = pixel;
     if (pixel != -1)
-        GLWindow_2->fWhitePatch = GLWindow_2->pixelsPatch[pixel];
+    {
+        RMS_window->fWhitePatch = RMS_window->pixelsPatch[pixel];
+        Mean_window->fWhitePatch = Mean_window->pixelsPatch[pixel];
+        Max_window->fWhitePatch = Max_window->pixelsPatch[pixel];
+        PosOfMax_window->fWhitePatch = PosOfMax_window->pixelsPatch[pixel];
+    }
     else
-        GLWindow_2->fWhitePatch = -1;
+    {
+        RMS_window->fWhitePatch = -1;
+        Mean_window->fWhitePatch = -1;
+        Max_window->fWhitePatch = -1;
+        PosOfMax_window->fWhitePatch = -1;
+    }
     if (pixel == -1)
         return;
@@ -2213,21 +2270,12 @@
 
 int currentPixel = pixel;
-//IN ORDER TO GET THE AVERAGE OF ALL PIXELS DISPLAYED IN THE CURVE OF THE VIEWER
-//UNCOMMENT THE 9 LINES BELOW, i.e. UNTIL THE END OF AVERAGE DISPLAY COMMENT MARK
-//int currentPixel = 0;
-//    for (int i=0;i<GLWindow->nRoi;i++)
-//        yval[i] = 0;
-//    for (int j=0;j<1440;j++) {
-//        currentPixel = j;
+
     for (int i=0;i<GLWindow->nRoi;i++)
     {
         xval[i] = i;
         yval[i] = GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
-//        yval[i] += GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
-    }
-//    }
-//    for (int i=0;i<GLWindow->nRoi;i++)
-//        yval[i] /= 1440;
-//END OF AVERAGE DISPLAY COMMENTS
+    }
+
+
 int realNumSamples = GLWindow->nRoi;
     if (GLWindow->nRoiTM != 0)
@@ -2256,22 +2304,37 @@
       //  cout << pixelIdInPatch << " " ;
     }
-//cout << realNumSamples << endl;
-  //  GLWindow->computePulsesStatistics();
+
 #if QWT_VERSION < 0x060000
     pixelValueCurveItem.setData(xval, yval, realNumSamples);
-////    aMeanCurveItem.setData(xval, GLWindow->aMeas, GLWindow->nRoi);
- //   meanCurveItem.setData(xval, GLWindow->n1mean, GLWindow->nRoi);
- //   vCorrCurveItem.setData(xval, GLWindow->vCorr, GLWindow->nRoi-3);
 #else
        pixelValueCurveItem.setSamples(xval, yval, realNumSamples);
-//       aMeanCurveItem.setSamples(xval, GLWindow->aMeas, GLWindow->nRoi);
- //      meanCurveItem.setSamples(xval, GLWindow->n1mean, GLWindow->nRoi);
- //      vCorrCurveItem.setSamples(xval, GLWindow->vCorr, GLWindow->nRoi-3);
 #endif
 
+//now compute the average value of all pixels
+       currentPixel = 0;
+       for (int i=0;i<GLWindow->nRoi;i++)
+           yval[i] = 0;
+       for (int j=0;j<1440;j++) {
+           currentPixel = j;
+           for (int i=0;i<GLWindow->nRoi;i++)
+           {
+               xval[i] = i;
+               yval[i] += GLWindow->eventData[GLWindow->nRoi*currentPixel + i];
+           }
+       }
+       for (int i=0;i<GLWindow->nRoi;i++)
+           yval[i] /= 1440;
+#if QWT_VERSION < 0x060000
+       pixelAverageCurveItem.setData(xval, yval, GLWindow->nRoi);
+#else
+    pixelAverageCurveItem.setSamples(xval, yval, realNumSamples);
+#endif
 
     QStack< QRectF > stack;
     stack.push(scaleBoundingRectangle(pixelValueCurveItem.boundingRect(), 1.5f));
     curveZoom->setZoomStack(stack);
+    stack.pop();
+    stack.push(scaleBoundingRectangle(pixelAverageCurveItem.boundingRect(), 1.5f));
+    averageCurveZoom->setZoomStack(stack);
     stack.pop();
 
