Index: trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
===================================================================
--- trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 12900)
+++ trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 12917)
@@ -14,11 +14,4 @@
 #include <fstream>
 
-#ifdef LOAD_RAW
-int16_t eventsData[NUM_STORED_EVENTS][ACTUAL_NUM_PIXELS][1024];
-#include </home/lyard/Code/display.C>
-#endif
-
-#define VALUES_SPAN 4096
-
 #include <QFileDialog>
 
@@ -49,8 +42,8 @@
     if (first < 0)
         first = 5;
- //   if (second > 5)
- //       second = 0;
+
     first = neighbors[pixel][first];
     second = neighbors[pixel][second];
+//    cout << pixel << " " << vertex << " " << "first: " << first << " second: " << second << endl;
     for (int i=0;i<3;i++)
         color[i] = pixelsColor[pixel][i];
@@ -70,4 +63,7 @@
     for (int i=0;i<3;i++)
         color[i] /= divide;
+
+//    cout << color[0] << " " << color[1] << " " << color[2] << endl;
+
     glColor3fv(color);
 }
@@ -98,33 +94,5 @@
 void RawDataViewer::drawBlurryHexagon(int index)
 {
-//alternative mesh
-/*    GLfloat color1[3];
-    GLfloat color2[3];
-    GLfloat color3[3];
-    for (int i=0;i<3;i++)
-        color1[i] = pixelsColor[index][i];
-    glBegin(GL_TRIANGLES);
-    for (int i=0;i<6;i++)
-    {
-        int first = i;
-        int second = i+1;
-        if (second == 6) second = 0;
-        first = neighbors[index][first];
-        second = neighbors[index][second];
-        if (first == -1 || second == -1) continue;
-        for (int j=0;j<3;j++)
-        {
-            color2[j] = pixelsColor[first][j];
-            color3[j] = pixelsColor[second][j];
-        }
-        glColor3fv(color2);
-        glVertex2fv(pixelsCoords[first]);
-        glColor3fv(color1);
-        glVertex2fv(pixelsCoords[index]);
-        glColor3fv(color3);
-        glVertex2fv(pixelsCoords[second]);
-    }
-    glEnd();
-    return;*/
+
 //per-pixel mesh
     GLfloat color[3];
@@ -136,13 +104,5 @@
     glColor3fv(color);
     glVertex2fv(pixelsCoords[index]);
-/*
-    calcMidBlurColor(index, 1);
-    glVertex2f((verticesList[verticesIndices[index][0]][0] + verticesList[verticesIndices[index][1]][0])/2.f,
-                   (verticesList[verticesIndices[index][0]][1] + verticesList[verticesIndices[index][1]][1])/2.f);
-    glVertex2f((verticesList[verticesIndices[index][0]][0] + verticesList[verticesIndices[index][1]][0])/2.f,
-                   (verticesList[verticesIndices[index][0]][1] + verticesList[verticesIndices[index][1]][1])/2.f);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-*/
+
     calcBlurColor(index, 1);
     glVertex2fv(verticesList[verticesIndices[index][1]]);
@@ -151,13 +111,5 @@
     glColor3fv(color);
     glVertex2fv(pixelsCoords[index]);
-/*
-    calcMidBlurColor(index, 2);
-    glVertex2f((verticesList[verticesIndices[index][1]][0] + verticesList[verticesIndices[index][2]][0])/2.f,
-                   (verticesList[verticesIndices[index][1]][1] + verticesList[verticesIndices[index][2]][1])/2.f);
-    glVertex2f((verticesList[verticesIndices[index][1]][0] + verticesList[verticesIndices[index][2]][0])/2.f,
-                   (verticesList[verticesIndices[index][1]][1] + verticesList[verticesIndices[index][2]][1])/2.f);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-*/
+
     calcBlurColor(index, 2);
     glVertex2fv(verticesList[verticesIndices[index][2]]);
@@ -166,13 +118,5 @@
     glColor3fv(color);
     glVertex2fv(pixelsCoords[index]);
-/*
-    calcMidBlurColor(index, 3);
-    glVertex2f((verticesList[verticesIndices[index][2]][0] + verticesList[verticesIndices[index][3]][0])/2.f,
-                   (verticesList[verticesIndices[index][2]][1] + verticesList[verticesIndices[index][3]][1])/2.f);
-    glVertex2f((verticesList[verticesIndices[index][2]][0] + verticesList[verticesIndices[index][3]][0])/2.f,
-                   (verticesList[verticesIndices[index][2]][1] + verticesList[verticesIndices[index][3]][1])/2.f);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-*/
+
     calcBlurColor(index, 3);
     glVertex2fv(verticesList[verticesIndices[index][3]]);
@@ -181,13 +125,5 @@
     glColor3fv(color);
     glVertex2fv(pixelsCoords[index]);
-/*
-    calcMidBlurColor(index, 4);
-    glVertex2f((verticesList[verticesIndices[index][3]][0] + verticesList[verticesIndices[index][4]][0])/2.f,
-                   (verticesList[verticesIndices[index][3]][1] + verticesList[verticesIndices[index][4]][1])/2.f);
-    glVertex2f((verticesList[verticesIndices[index][3]][0] + verticesList[verticesIndices[index][4]][0])/2.f,
-                   (verticesList[verticesIndices[index][3]][1] + verticesList[verticesIndices[index][4]][1])/2.f);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-*/
+
     calcBlurColor(index, 4);
     glVertex2fv(verticesList[verticesIndices[index][4]]);
@@ -196,13 +132,5 @@
     glColor3fv(color);
     glVertex2fv(pixelsCoords[index]);
-/*
-    calcMidBlurColor(index, 5);
-    glVertex2f((verticesList[verticesIndices[index][4]][0] + verticesList[verticesIndices[index][5]][0])/2.f,
-                   (verticesList[verticesIndices[index][4]][1] + verticesList[verticesIndices[index][5]][1])/2.f);
-    glVertex2f((verticesList[verticesIndices[index][4]][0] + verticesList[verticesIndices[index][5]][0])/2.f,
-                   (verticesList[verticesIndices[index][4]][1] + verticesList[verticesIndices[index][5]][1])/2.f);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-*/
+
     calcBlurColor(index, 5);
     glVertex2fv(verticesList[verticesIndices[index][5]]);
@@ -211,13 +139,5 @@
     glColor3fv(color);
     glVertex2fv(pixelsCoords[index]);
-/*
-    calcMidBlurColor(index, 0);
-    glVertex2f((verticesList[verticesIndices[index][5]][0] + verticesList[verticesIndices[index][0]][0])/2.f,
-                   (verticesList[verticesIndices[index][5]][1] + verticesList[verticesIndices[index][0]][1])/2.f);
-    glVertex2f((verticesList[verticesIndices[index][5]][0] + verticesList[verticesIndices[index][0]][0])/2.f,
-                   (verticesList[verticesIndices[index][5]][1] + verticesList[verticesIndices[index][0]][1])/2.f);
-    glColor3fv(color);
-    glVertex2fv(pixelsCoords[index]);
-*/
+
     calcBlurColor(index, 0);
     glVertex2fv(verticesList[verticesIndices[index][0]]);
@@ -240,5 +160,4 @@
         {
             glTranslatef(-0.45,-0.45,0);
- //           cout << "correction" << endl;
         }
         if (cameraRotation == -90)
@@ -254,5 +173,4 @@
         {
             glTranslatef(-0.45/1.5,-0.45/1.5,0);
- //           cout << "correction" << endl;
         }
         if (cameraRotation == -90)
@@ -264,5 +182,5 @@
     glLineWidth(1.0);
     float color;
-//cout << "Actual num pixels: " << ACTUAL_NUM_PIXELS << endl;
+
     for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
     {
@@ -270,7 +188,5 @@
           color = (float)(i)/(float)(ACTUAL_NUM_PIXELS);
         else
-#ifdef LOAD_RAW
-        color = float(eventsData[eventNum][i][whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
-#else
+
         color = float(eventData[nRoi*hardwareMapping[i] + whichSlice]+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
         if (logScale)
@@ -280,5 +196,5 @@
             color = log10(color);
         }
-#endif
+
         if (color < ss[0])
         {
@@ -311,7 +227,5 @@
     for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
     {
-//        if (i == 690 ||
-//            i == 70)
-//            continue;
+
         glColor3fv(pixelsColor[i]);
         glLoadName(i);
@@ -328,7 +242,5 @@
     for (int i=0;i<ACTUAL_NUM_PIXELS;i++)
     {
-//        if (i == 690 ||
-//            i == 70)
-//            continue;
+
         drawHexagon(i, false);
     }
@@ -336,19 +248,4 @@
 }
 
-/************************************************************
- * TRIM. FIXME this should not be here but taken from an existing class (somewhere)
- ***********************************************************
-string Trim(const string &str)
-{
-    // Trim Both leading and trailing spaces
-    const size_t start = str.find_first_not_of(' '); // Find the first character position after excluding leading blank spaces
-    const size_t end   = str.find_last_not_of(' ');  // Find the first character position from reverse af
-
-    // if all spaces or empty return an empty string
-    if (string::npos==start || string::npos==end)
-        return string();
-
-    return str.substr(start, end-start+1);
-}*/
 /************************************************************
  * DRAW PIXEL CURVE. draws the raw impulse curve of the currently selected pixel
@@ -381,5 +278,7 @@
     glColor3f(1.0f,1.0f,0.0f);
     float divideMe = (float)(VALUES_SPAN-1);
-    float plusMe = VALUES_SPAN/2;
+    float plusMe = (float)(VALUES_SPAN)/2;
+    if (divideMe <= 0)
+        divideMe = 1;
 
     /*
@@ -418,11 +317,5 @@
     if (pixelIdInPatch == 8)//this channel has a time marker
     {
-//link between pixel slices and TM slices. should I draw it ?
-//        float d1 = eventData[nRoi*hw + nRoi-1]+plusMe;
-//        float d2 = eventData[nRoi*1440 + nRoiTM*(40*crateId + 4*boardId + patchId)] + plusMe;
-//        glVertex2f(bboxMin[0] + xRange*(nRoi-1)/(float)(nRoi+nRoiTM),
-//                   bboxMin[1] + yRange*(d1) /divideMe);
-//        glVertex2f(bboxMin[0] + xRange*(nRoi)/(float)(nRoi+nRoiTM),
-//                   bboxMin[1] + yRange*(d2)/divideMe);
+
         for (int i=0;i<nRoiTM-1;i++)
         {
@@ -448,54 +341,17 @@
                bboxMax[1]);
 
-/*    glColor3f(0.f,0.5f,0.f);
-    for (int i=0;i<nRoi-1;i++)
-    {
-        glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
-                   bboxMin[1] + yRange*(n1mean[ i]+plusMe) /divideMe);
-        glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
-                   bboxMin[1] + yRange*(n1mean[i+1]+plusMe) /divideMe);
-    }
-*/
     glEnd();
- //   glEnable(GL_MULTISAMPLE);
- /*   setFont(QFont("Times", 12));
-    qglColor(QColor(255,223,127));
-    float xShift = 0.10f;
-    float yShift = 0.01f;
-    renderText(bboxMin[0]-xShift/2.0f, bboxMax[1]+3*yShift, 0, QString("Volts"));
-    if (drawCalibrationLoaded)
-    {
-        renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+2.10"));
-        renderText(bboxMin[0]-xShift,  ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+1.05"));//((bboxMin[1]+bboxMax[1])/2.0f)
-        renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("0.00"));
-    }
-    else
-    {
-        renderText(bboxMin[0]-xShift, bboxMax[1]-yShift,0,QString("+1.05"));
-        renderText(bboxMin[0]-xShift,  ((bboxMin[1]+bboxMax[1])/2.0f) - yShift, 0, QString("+0.00"));//((bboxMin[1]+bboxMax[1])/2.0f)
-        renderText(bboxMin[0]-xShift, bboxMin[1]-yShift, 0, QString("-1.05"));
-    }
-    renderText(bboxMax[0]+xShift/2.0f, bboxMin[1]-4*yShift, 0, QString("Slices"));
-    renderText(bboxMin[0]-yShift/2.0f, bboxMin[1]-4*yShift, 0, QString("0"));
-    ostringstream str;
-    str << nRoi/2;
-    renderText(((bboxMin[0]+bboxMax[0])/2.0f)-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
-    str.str("");
-    str << nRoi;
-    renderText(bboxMax[0]-xShift/2.0f, bboxMin[1]-4*yShift, 0, QString(str.str().c_str()));
-*/
+
 }
 /************************************************************
  * CONSTRUCTOR.
  ************************************************************/
-RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent), RMSvalues(1440), Meanvalues(1440), Maxvalues(1440), PosOfMaxvalues(1440)
-{
- //   setFormat(QGLFormat(QGL::DoubleBuffer));// | QGL::DepthBuffer));
+RawDataViewer::RawDataViewer(QWidget *cParent) : BasicGlCamera(cParent), RMSvalues(1440), Meanvalues(1440), Maxvalues(1440), PosOfMaxvalues(1440), VALUES_SPAN(4096)
+
+{
+
     whichSlice = 0;
-#ifdef LOAD_RAW
-    nRoi = 1024;
-#else
+
     nRoi = 0;
-#endif
     nRoiTM = 0;
     offSetRoi = 0;
@@ -512,7 +368,5 @@
     fIsDrsCalibration = false;
     SetAutoRefresh(true);
-#ifdef LOAD_RAW
-    loadEvents("/scratch/00000043.001_T.bin");
-#endif
+
     PixelMap mypMap;
     if (!mypMap.Read("FACTmap111030.txt"))
@@ -531,7 +385,4 @@
             patchesColor[i][j] = color[j];
     }
-
-    //calibrationLoaded = false;
-    //drawCalibrationLoaded = false;
 
 }
@@ -612,8 +463,8 @@
         return;
     int face = PixelAtPosition(cEvent->pos());
- //   if (face != -1) {
+
         selectedPixel = face;
         emit signalCurrentPixel(face);
- //       }
+
     updateGL();
 }
@@ -683,5 +534,5 @@
     catch (std::runtime_error e)
     {
-        cout << "Something went wrong while loading fits. aborting: " << e.what() << endl;
+        cout << "Something went wrong while loading fits. Aborting: " << e.what() << endl;
         return;
     }
@@ -707,8 +558,5 @@
     entriesToCheck.push_back("TSTART");
     entriesToCheck.push_back("TSTOP");
-    //entriesToCheck.push_back("ADCRANGE");
-    //entriesToCheck.push_back("NBEVTOK");
-    //entriesToCheck.push_back("NBEVTREJ");
-    //entriesToCheck.push_back("NBEVTBAD");
+
 
     for (vector<string>::const_iterator it=entriesToCheck.begin(); it != entriesToCheck.end(); it++)
@@ -753,8 +601,4 @@
     eventNum = 0;
 
-#ifdef LOAD_RAW
-    nRows = NUM_STORED_EVENTS;
-#endif
-
     if (eventData != NULL) {
         delete[] eventData;
@@ -809,7 +653,4 @@
     eventStep = 1;
 
-    doMyWaveletTestPlease();
-
-
     plusEvent();
     eventStep = backupStep;
@@ -817,289 +658,8 @@
     emit signalCurrentPixel(selectedPixel);
 }
-/*
-bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
-{
-    float* interArray = new float[givenSpan];
-    float* resultArray = new float[givenSpan];
-    float* orig = new float[givenSpan];
-    float* wavelets = new float[givenSpan];
-    for (int i=0;i<givenSpan;i++)
-    {
-        if (fabs((float)(orig_in[i])) > 32767.f)
-            cout << "Input overflow: " << orig_in[i] << endl;
-        orig[i] = (float)orig_in[i];
-    }
-    for (int k=0;k<givenSpan;k++)
-        interArray[k] = orig[k];
-    int span = givenSpan/2;
-    while (span > 0)
-    {
-        for (int k=0;k<span;k++)
-        {
-            wavelets[k]        = (interArray[2*k] + interArray[2*k + 1])/2.f;
-            wavelets[k + span] = (interArray[2*k + 1] - interArray[2*k])/2.f;
-        }
-        for (int k=0;k<givenSpan;k++)
-            interArray[k] = wavelets[k];
-        span /= 2;
-    }
-    //move float results to int16_t array
-    float intScaling = 15.9f;
-    int max = 0;
-    for (int i=0;i<givenSpan;i++)
-    {
-        float cValue = intScaling*wavelets[i];//
-        if (cValue > 0)
-            cValue += 0.5f;
-        else
-            cValue -= 0.5f;
-        wavelets_in[i] = (int16_t)(cValue);
-        if (fabs(cValue) >  32767.f)
-        {
-            cout << "Overflow ! " << cValue << endl;
-        }
-        if (fabs(cValue) > fabs(max))
-            max = cValue;
-    }
-//    cout << "Max wave value: " << max << endl;
-    //result reconstruction and checking
-    if (!verifyResult)
-        return true;
-
-   for (int k=0;k<givenSpan;k++)
-   {
-       resultArray[k] = wavelets_in[k]/intScaling;
-   }
-
-   span = 1;
-   while (span < givenSpan)
-   {
-       for (int k=0;k<givenSpan;k++)
-           interArray[k] = resultArray[k];
-      for (int k=0;k<span;k++)
-       {
-          resultArray[2*k]     = (float)(((interArray[k] - interArray[k + span])*(1.f/1.f)) + 0.0f);
-          resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
-       }
-       span *= 2;
-   }
-
-   for (int k=0;k<givenSpan;k++)
-   {
-       float plus = 0.5f;
-       if (resultArray[k] < 0)
-           plus *= -1.f;
-       if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
-       {
-           cout << "Nop, sorry: k: "  << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
-           return false;
-       }
-   }
-   return true;
-}
-*/
-bool RawDataViewer::doWaveLetsPlease(int givenSpan, int16_t* orig_in, int16_t* wavelets_in, bool verifyResult)
-{
-    float* interArray = new float[givenSpan];
-    float* resultArray = new float[givenSpan];
-    float* orig = new float[givenSpan];
-    float* wavelets = new float[givenSpan];
-    for (int i=0;i<givenSpan;i++)
-    {
-        if (fabs((float)(orig_in[i])) > 32767.f)
-            cout << "Input overflow: " << orig_in[i] << endl;
-        orig[i] = (float)orig_in[i];
-    }
-    for (int k=0;k<givenSpan;k++)
-        interArray[k] = orig[k];
-    int span = givenSpan/2;
-    while (span > 0)
-    {
-        for (int k=0;k<span;k++)
-        {
-            wavelets[k]        = interArray[2*k];// + interArray[2*k + 1])/2.f;
-            wavelets[k + span] = interArray[2*k + 1] - interArray[2*k];//)/2.f;
-        }
-        for (int k=0;k<givenSpan;k++)
-            interArray[k] = wavelets[k];
-        span /= 2;
-    }
-    //move float results to int16_t array
-    float intScaling = 1.f;
-    int max = 0;
-    for (int i=0;i<givenSpan;i++)
-    {
-        float cValue = intScaling*wavelets[i];//
-        if (cValue > 0)
-            cValue += 0.5f;
-        else
-            cValue -= 0.5f;
-        wavelets_in[i] = (int16_t)(cValue);
-        if (fabs(cValue) >  32767.f)
-        {
-            cout << "Overflow ! " << cValue << endl;
-        }
-        if (fabs(cValue) > fabs(max))
-            max = cValue;
-    }
-//    cout << "Max wave value: " << max << endl;
-    //result reconstruction and checking
-    if (!verifyResult)
-        return true;
-
-   for (int k=0;k<givenSpan;k++)
-   {
-       resultArray[k] = wavelets_in[k]/intScaling;
-   }
-
-   span = 1;
-   while (span < givenSpan)
-   {
-       for (int k=0;k<givenSpan;k++)
-           interArray[k] = resultArray[k];
-      for (int k=0;k<span;k++)
-       {
-          resultArray[2*k]     = (float)(((interArray[k])*(1.f/1.f)) + 0.0f);
-          resultArray[2*k + 1] = (float)(((interArray[k] + interArray[k + span])*(1.f/1.f)) + 0.0f);
-       }
-       span *= 2;
-   }
-
-   for (int k=0;k<givenSpan;k++)
-   {
-       float plus = 0.5f;
-       if (resultArray[k] < 0)
-           plus *= -1.f;
-       if ((int)(resultArray[k]+plus) != (int)(orig_in[k]))
-       {
-           cout << "Nop, sorry: k: "  << k << " " << resultArray[k] << " " << (int)(resultArray[k]+plus) << " " << plus << " " << orig[k] << endl;
-           return false;
-       }
-   }
-   delete[] interArray;
-   delete[] resultArray;
-   delete[] orig;
-   delete[] wavelets;
-   return true;
-}
-
-void RawDataViewer::doWaveLetOnCurrentEventPlease()
-{
-     int16_t* origTheWayIWant = new int16_t[1024*1440];
-
-//     int numPixels = 1024;
-//         int leftOver = 1440-numPixels;
-         for (int k=0;k<1024;k++)
-             for (int j=0;j<1440;j++)
-             {
-                 origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
-             }
-
-         int waveSpan = 1024;
-         int waveToPixelsRatio = 32;
-         waveSpan = waveSpan*waveToPixelsRatio;
-         int totalNumSamples = 1024*1440;
-         int j=0;
-         for (;j<totalNumSamples;j+= waveSpan)
-         {
-             if (j + waveSpan < totalNumSamples)
-             if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray[j], true))
-                 return;
-         }
-
-         while (j%1440 != 0)
-         {
-             int lastRun = 1;
-             while (lastRun < 1440 - j%1440)
-                 lastRun *= 2;
-             lastRun /= 2;
-             if (lastRun > 2)
-             {
-                 doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray[j], true);
-             }
-             else
-             {
-                 for (int l=0;l<lastRun;l++)
-                     waveLetArray[j+l] = origTheWayIWant[j+l];
-             }
-             if (!lastRun)
-                 break;
-             j += lastRun;
-         }
-
-     delete[] origTheWayIWant;
-
-}
-void RawDataViewer::doMyWaveletTestPlease()
-{
-//    cout << "Size of float: " << sizeof(float) << endl;
-    return;
-    ofstream outBin("/scratch/bin/outputBin.bin", ios_base::out | ios_base::binary);
-    ofstream outWave("/scratch/bin/outputWave.bin", ios_base::out | ios_base::binary);
-    int16_t* waveLetArray_ = new int16_t[1024*1440];
-    int16_t* origTheWayIWant = new int16_t[1024*1440];
-
-    for (int i=0;i<nRows;i++)
-    {
-        cout << '\r' <<  "Doing row " << i << " of " << nRows;
-        cout.flush();
-        inputFile->GetRow(i);
-        outBin.write((const char*)(rawEventData), 1440*1024*2);
-
-//       int numPixels = 1024;
-//        int leftOver = 1440-numPixels;
-        for (int k=0;k<1024;k++)
-            for (int j=0;j<1440;j++)
-            {
-                origTheWayIWant[k*1440 + j] = rawEventData[j + k*1440];
-            }
-
-        int waveSpan = 1024;
-        int waveToPixelsRatio = 32;
-        waveSpan = waveSpan*waveToPixelsRatio;
-        int totalNumSamples = 1024*1440;
-        int j=0;
-        for (;j<totalNumSamples;j+= waveSpan)//1440/waveToPixelsRatio;j++)
-        {
-            if (j + waveSpan < totalNumSamples)
-            if (!doWaveLetsPlease(waveSpan, &origTheWayIWant[j], &waveLetArray_[j], true))
-                return;
-        }
-
-        while (j%1440 != 0)// < totalNumSamples)
-        {
-            cout << "Copying the remaining of the data" << endl;
-            int lastRun = 1;
-            while (lastRun < 1440 - j%1440)//totalNumSamples-j)
-                lastRun *= 2;
-            lastRun /= 2;
-            if (lastRun > 2)
-            {
-//                   cout << "   Doint one last run of " << lastRun << " samples" << endl;
-                doWaveLetsPlease(lastRun, &origTheWayIWant[j], &waveLetArray_[j], true);
-            }
-            else
-            {
-//                    cout << " Filling in " << lastRun << " samples" << endl;
-                for (int l=0;l<lastRun;l++)
-                    waveLetArray_[j+l] = origTheWayIWant[j+l];
-            }
-            if (!lastRun)
-                break;
-            j += lastRun;
-        }
-       outWave.write((const char*)(waveLetArray_), 1440*1024*2);
-    }
-    outWave.close();
-    outBin.close();
-    inputFile->GetRow(0);
-
-    delete[] waveLetArray_;
-    delete[] origTheWayIWant;
-}
+
 void RawDataViewer::openCalibFile(string& file)
 {
     //calibrationLoaded = false;
-
     string msg;
     try
@@ -1122,4 +682,33 @@
 }
 
+template <typename T>
+void RawDataViewer::getCalibrationDataForDisplay(const CalibDataTypes calibTypes,
+                                                 const vector<T>& inputData,
+                                                 const int roi,
+                                                 const int roiTM)
+{
+
+    eventData = new float[1440*roi + 160*roiTM];//(1440+160)*nRoi];
+    nRoi=roi;
+    nRoiTM=roiTM;
+
+    long long min, max, mean;
+    min = max = inputData[0];
+    mean=0;
+    for (int i=0;i<1440*roi + 160*roiTM;i++) {
+        eventData[i] = (float)inputData[i];
+        mean += inputData[i];
+        if (inputData[i] > max)
+            max = inputData[i];
+        if (inputData[i] < min)
+            min = inputData[i];
+    }
+    mean /= 1440*roi + 160*roiTM;
+    for (int i=0;i<1440*roi + 160*roiTM;i++)
+        eventData[i] -= (float)mean;
+    VALUES_SPAN = max - min;
+//    cout << VALUES_SPAN << " " << min << " " << max << " " << mean << endl;
+//    cout << 1440*roi + 160*roiTM << " " << roi << " " << roiTM << " " << inputData.size() << endl;
+}
 /************************************************************
  * PLUS EVENT
@@ -1156,6 +745,4 @@
         fDrsCalib.Apply(eventData, rawEventData, startPix, nRoi);
         DrsCalibrate::RemoveSpikes(eventData, nRoi);
-//        for (int i=0;i<1024;i++)
-//            eventData[i] = eventData[i+1024];
         //TODO apply calibration to the Time markers
     }
@@ -1178,5 +765,4 @@
             if (pixelIdInPatch == 8)
             {
- //               cout << patchId << " ";
                 for (int j=0;j<nSlicesToRemove;j++)
                 {
@@ -1197,5 +783,4 @@
         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
@@ -1236,12 +821,10 @@
     if (rowNum < 0)
         rowNum += nRows;
-#ifdef LOAD_RAW
-    eventNum+=eventStep;
-#else
+
     if (inputFile == NULL)
         return;
     inputFile->GetRow(rowNum);
 //    cout << "Getting row " << rowNum << endl;
-#endif
+
 
     ApplyCalibration();
@@ -1475,5 +1058,11 @@
 {
     GLWindow->drawImpulse = state;
+    TriggerOffset_window->drawImpulse = state;
+    Gain_window->drawImpulse = state;
+    Baseline_window->drawImpulse = state;
     GLWindow->updateGL();
+    TriggerOffset_window->updateGL();
+    Gain_window->updateGL();
+    Baseline_window->updateGL();
 }
 /************************************************************
@@ -1573,4 +1162,22 @@
     if (currentCalibFile != "")
         GLWindow->openCalibFile(currentCalibFile);
+    if (GLWindow->fDrsCalib.fRoi != 0)
+    {//spread the calibration data to the displayers
+        Baseline_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_BASELINE,
+                                                      GLWindow->fDrsCalib.fOffset,
+                                                      GLWindow->fDrsCalib.fRoi,
+                                                      GLWindow->fDrsCalib.fNumTm);
+
+        Gain_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_GAIN,
+                                                  GLWindow->fDrsCalib.fGain,
+                                                  GLWindow->fDrsCalib.fRoi,
+                                                  GLWindow->fDrsCalib.fNumTm);
+
+        TriggerOffset_window->getCalibrationDataForDisplay(RawDataViewer::CALIB_TRIG_OFFSET,
+                                                           GLWindow->fDrsCalib.fTrgOff,
+                                                           GLWindow->fDrsCalib.fRoi,
+                                                           GLWindow->fDrsCalib.fNumTm);
+
+    }
 }
 /************************************************************
@@ -2455,7 +2062,7 @@
     }
 //    cout << "min: " << min << " max: " << max << " average: " << average << endl;
-    float minRange = (float)(min+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
-    float maxRange = (float)(max+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
-    float midRange = (float)(average+(VALUES_SPAN/2))/(float)(VALUES_SPAN-1);
+    float minRange = (float)(min+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
+    float maxRange = (float)(max+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
+    float midRange = (float)(average+(GLWindow->VALUES_SPAN/2))/(float)(GLWindow->VALUES_SPAN-1);
     if (GLWindow->logScale)
     {
Index: trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h
===================================================================
--- trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 12900)
+++ trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 12917)
@@ -62,5 +62,9 @@
     friend class UIConnector;
 
-
+    enum CalibDataTypes {
+        CALIB_BASELINE,
+        CALIB_GAIN,
+        CALIB_TRIG_OFFSET
+    };
 
 public:
@@ -74,5 +78,9 @@
     void openCalibFile(std::string& file);
 
-
+    template <typename T>
+    void getCalibrationDataForDisplay(const CalibDataTypes calibTypes,
+                                                     const vector<T>& inputData,
+                                                     const int roi,
+                                                     const int roiTM);
 
 public Q_SLOTS:
@@ -165,4 +173,7 @@
     int eventStep;
 
+
+
+
 //    int hardwareMapping[1440];
 //    int softwareMapping[1440];
@@ -179,8 +190,4 @@
 
     QPoint lastPos;
-
-    void doMyWaveletTestPlease();
-    void doWaveLetOnCurrentEventPlease();
-    bool doWaveLetsPlease(int givenSpan, int16_t* orig, int16_t* wavelets, bool verifyResult);
 public:
     void computePulsesStatistics();
@@ -189,4 +196,5 @@
     double n2mean[1024];
     double vCorr[1024];
+    int64_t VALUES_SPAN;
 
     void ApplyCalibration();
Index: trunk/FACT++/gui/RawEventsViewer/viewer.ui
===================================================================
--- trunk/FACT++/gui/RawEventsViewer/viewer.ui	(revision 12900)
+++ trunk/FACT++/gui/RawEventsViewer/viewer.ui	(revision 12917)
@@ -39,5 +39,5 @@
            </property>
            <attribute name="title">
-            <string>Camera View</string>
+            <string>Camera</string>
            </attribute>
            <layout class="QGridLayout" name="gridLayout_3">
@@ -65,5 +65,5 @@
            </property>
            <attribute name="title">
-            <string>Data View</string>
+            <string>Data</string>
            </attribute>
            <layout class="QVBoxLayout" name="verticalLayout_2">
@@ -205,104 +205,192 @@
            </layout>
           </widget>
-          <widget class="QWidget" name="tab_2">
+          <widget class="QWidget" name="tab_15">
            <attribute name="title">
-            <string>RMS</string>
+            <string>Statistics</string>
            </attribute>
-           <layout class="QGridLayout" name="gridLayout_6">
+           <layout class="QGridLayout" name="gridLayout_11">
             <item row="0" column="0">
-             <widget class="QCameraWidget" name="RMS_window" native="true">
-              <property name="enabled">
-               <bool>true</bool>
-              </property>
-              <property name="sizePolicy">
-               <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>10000</width>
-                <height>10000</height>
-               </size>
-              </property>
+             <widget class="QTabWidget" name="tabWidget_4">
+              <property name="currentIndex">
+               <number>0</number>
+              </property>
+              <widget class="QWidget" name="tab_16">
+               <attribute name="title">
+                <string>RMS</string>
+               </attribute>
+               <layout class="QGridLayout" name="gridLayout_12">
+                <item row="0" column="0">
+                 <widget class="QCameraWidget" name="RMS_window" native="true">
+                  <property name="enabled">
+                   <bool>true</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>10000</width>
+                    <height>10000</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </widget>
+              <widget class="QWidget" name="tab_17">
+               <attribute name="title">
+                <string>Mean</string>
+               </attribute>
+               <layout class="QGridLayout" name="gridLayout_13">
+                <item row="0" column="0">
+                 <widget class="QCameraWidget" name="Mean_window" native="true">
+                  <property name="enabled">
+                   <bool>true</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>10000</width>
+                    <height>10000</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </widget>
+              <widget class="QWidget" name="tab_18">
+               <attribute name="title">
+                <string>Max</string>
+               </attribute>
+               <layout class="QGridLayout" name="gridLayout_14">
+                <item row="0" column="0">
+                 <widget class="QCameraWidget" name="Max_window" native="true">
+                  <property name="enabled">
+                   <bool>true</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>10000</width>
+                    <height>10000</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </widget>
+              <widget class="QWidget" name="tab_19">
+               <attribute name="title">
+                <string>Pos. of Max.</string>
+               </attribute>
+               <layout class="QGridLayout" name="gridLayout_15">
+                <item row="0" column="0">
+                 <widget class="QCameraWidget" name="PosOfMax_window" native="true">
+                  <property name="enabled">
+                   <bool>true</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="maximumSize">
+                   <size>
+                    <width>10000</width>
+                    <height>10000</height>
+                   </size>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </widget>
              </widget>
             </item>
            </layout>
           </widget>
-          <widget class="QWidget" name="tab_8">
+          <widget class="QWidget" name="tab_11">
            <attribute name="title">
-            <string>Mean</string>
+            <string>Calibration</string>
            </attribute>
-           <layout class="QGridLayout" name="gridLayout_61">
+           <layout class="QGridLayout" name="gridLayout_7">
             <item row="0" column="0">
-             <widget class="QCameraWidget" name="Mean_window" native="true">
-              <property name="enabled">
-               <bool>true</bool>
-              </property>
-              <property name="sizePolicy">
-               <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>10000</width>
-                <height>10000</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </widget>
-          <widget class="QWidget" name="tab_9">
-           <attribute name="title">
-            <string>Max</string>
-           </attribute>
-           <layout class="QGridLayout" name="gridLayout_62">
-            <item row="0" column="0">
-             <widget class="QCameraWidget" name="Max_window" native="true">
-              <property name="enabled">
-               <bool>true</bool>
-              </property>
-              <property name="sizePolicy">
-               <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>10000</width>
-                <height>10000</height>
-               </size>
-              </property>
-             </widget>
-            </item>
-           </layout>
-          </widget>
-          <widget class="QWidget" name="tab_10">
-           <attribute name="title">
-            <string>Pos. of Max.</string>
-           </attribute>
-           <layout class="QGridLayout" name="gridLayout_63">
-            <item row="0" column="0">
-             <widget class="QCameraWidget" name="PosOfMax_window" native="true">
-              <property name="enabled">
-               <bool>true</bool>
-              </property>
-              <property name="sizePolicy">
-               <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
-                <horstretch>0</horstretch>
-                <verstretch>0</verstretch>
-               </sizepolicy>
-              </property>
-              <property name="maximumSize">
-               <size>
-                <width>10000</width>
-                <height>10000</height>
-               </size>
-              </property>
+             <widget class="QTabWidget" name="tabWidget">
+              <property name="currentIndex">
+               <number>0</number>
+              </property>
+              <widget class="QWidget" name="tab_12">
+               <attribute name="title">
+                <string>Baseline</string>
+               </attribute>
+               <layout class="QGridLayout" name="gridLayout_8">
+                <item row="0" column="0">
+                 <widget class="RawDataViewer" name="Baseline_window" native="true">
+                  <property name="enabled">
+                   <bool>true</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>1</horstretch>
+                    <verstretch>1</verstretch>
+                   </sizepolicy>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </widget>
+              <widget class="QWidget" name="tab_13">
+               <attribute name="title">
+                <string>Gain</string>
+               </attribute>
+               <layout class="QGridLayout" name="gridLayout_9">
+                <item row="0" column="0">
+                 <widget class="RawDataViewer" name="Gain_window" native="true">
+                  <property name="enabled">
+                   <bool>true</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>1</horstretch>
+                    <verstretch>1</verstretch>
+                   </sizepolicy>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </widget>
+              <widget class="QWidget" name="tab_14">
+               <attribute name="title">
+                <string>Trigger Offset</string>
+               </attribute>
+               <layout class="QGridLayout" name="gridLayout_10">
+                <item row="0" column="0">
+                 <widget class="RawDataViewer" name="TriggerOffset_window" native="true">
+                  <property name="enabled">
+                   <bool>true</bool>
+                  </property>
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>1</horstretch>
+                    <verstretch>1</verstretch>
+                   </sizepolicy>
+                  </property>
+                 </widget>
+                </item>
+               </layout>
+              </widget>
              </widget>
             </item>
@@ -321,5 +409,5 @@
          <widget class="QLabel" name="label">
           <property name="text">
-           <string>FACT - Raw events viewer - v0.5</string>
+           <string>FACT - Raw events viewer - v0.6</string>
           </property>
          </widget>
