Index: /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 11752)
+++ /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 11753)
@@ -514,16 +514,24 @@
     float yRange = bboxMax[1] - bboxMin[1];
     glColor3f(1.0,1.0,1.0);
+    float divideMe = (float)(VALUES_SPAN-1);
+    float plusMe = VALUES_SPAN/2;
+    if (drawCalibrationLoaded && calibrationLoaded)
+    {
+        divideMe /=2;
+        plusMe /=2;
+    }
     for (int i=0;i<nRoi-1;i++)
     {
 #ifdef LOAD_RAW
         glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
-                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
+                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i]+plusMe) /divideMe);
         glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
-                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i+1]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
+                   bboxMin[1] + yRange*(eventsData[eventNum][selectedPixel][i+1]+plusMe) /divideMe);
 #else
+
         glVertex2f(bboxMin[0] + xRange*i/(float)nRoi,
-                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
+                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i]+plusMe) /divideMe);
         glVertex2f(bboxMin[0] + xRange*(i+1)/(float)nRoi,
-                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i+1]+(VALUES_SPAN/2)) /(float)(VALUES_SPAN-1));
+                   bboxMin[1] + yRange*(eventData[nRoi*selectedPixel + i+1]+plusMe) /divideMe);
 #endif
     }
@@ -659,4 +667,8 @@
     for (int i=0;i<1440;i++)
         updateNeighbors(i);
+
+    calibrationLoaded = false;
+    drawCalibrationLoaded = false;
+
 }
 /************************************************************
@@ -936,26 +948,26 @@
     if (!inputFile->SetPtrAddress("Data", eventData)){
         cout << "Missing column " << "Data" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     if (!inputFile->SetPtrAddress("EventNum", &eventNum)){
         cout << "Missing column " << "EventNum" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     if (!inputFile->SetPtrAddress("TriggerType", &triggerType)){
         cout << "Missing column " << "TriggerType" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     if (!inputFile->SetPtrAddress("SoftTrig", &softTrig)){
         cout << "Missing column " << "SoftTrig" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     if (!inputFile->SetPtrAddress("PCTime", &pcTime)){
         cout << "Missing column " << "PCTime" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     if (!inputFile->SetPtrAddress("BoardTime", boardTime)){
         cout << "Missing column " << "BoardTime" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     if (!inputFile->SetPtrAddress("StartCellData", startPix)){
         cout << "Missing column " << "StartCellData" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     if (!inputFile->SetPtrAddress("StartCellTimeMarker", startTM)){
         cout << "Missing column " << "StartCellTimeMarker" << " Aborting load..." << endl;
-        nRoi = nRows = 0;}
+        nRoi = nRows = 0;return;}
     int backupStep = eventStep;
     rowNum = -1;
@@ -966,5 +978,34 @@
     emit signalCurrentPixel(selectedPixel);
 }
-
+void RawDataViewer::openCalibFile(string& file)
+{
+    calibrationLoaded = false;
+    calibInputFile = new fits(file);
+    if (!*calibInputFile)
+    {
+        delete calibInputFile;
+        calibInputFile = NULL;
+        return;
+    }
+
+    if (!calibInputFile->SetPtrAddress("BaselineMean", baseLineMean)){
+        cout << "Missing column " << "BaseLineMean" << " Aborting load..." << endl;
+        return;}
+    if (!calibInputFile->SetPtrAddress("GainMean", gainMean)){
+        cout << "Missing column " << "GainMean" << " Aborting load..." << endl;
+        return;}
+    if (!calibInputFile->SetPtrAddress("TriggerOffsetMean", triggerOffsetMean)){
+        cout << "Missing column " << "TriggerOffsetMean" << " Aborting load..." << endl;
+        return;}
+
+    calibInputFile->GetNextRow();
+
+    delete calibInputFile;
+
+    calibrationLoaded = true;
+    emit newFileLoaded();
+    if (drawCalibrationLoaded)
+        updateGL();
+}
 /************************************************************
  * PLUS EVENT
@@ -1009,8 +1050,17 @@
 #endif
 
+    if (drawCalibrationLoaded)
+    {
+        for (int i=0;i<1440;i++)
+            for (int j=0;j<nRoi;j++)
+            {
+                eventData[i*1024+j] /= 2;
+                eventData[i*1024+j] -= (baseLineMean[i*1024+j]+triggerOffsetMean[i*1024+j]);
+                eventData[i*1024+j] /= gainMean[i*1024+j];
+            }
+    }
     updateGL();
     emit signalCurrentEvent(eventNum);
     emit signalCurrentPixel(selectedPixel);
-
 }
 /************************************************************
@@ -1065,4 +1115,6 @@
     patchID = 1;
     rescaleWholeCamera = true;
+    currentFile = "none";
+    currentCalibFile = "none";
 }
 void UIConnector::slicesPlusPlus()
@@ -1073,4 +1125,43 @@
 {
     viewer->previousSlice();
+}
+void UIConnector::drawCalibratedDataChanged(int state)
+{
+     if (state)
+    {
+        if (viewer->calibrationLoaded)
+        {
+            viewer->drawCalibrationLoaded = true;
+            for (int i=0;i<1440;i++)
+                for (int j=0;j<viewer->nRoi;j++)
+                {
+                    viewer->eventData[i*1024+j] /= 2;
+                    viewer->eventData[i*1024+j] -= (viewer->baseLineMean[i*1024+j]+viewer->triggerOffsetMean[i*1024+j]);
+                    viewer->eventData[i*1024+j] /= viewer->gainMean[i*1024+j];
+                }
+            viewer->updateGL();
+        }
+        else
+        {
+            drawCalibrationCheckBox->setChecked(false);
+        }
+    }
+    else
+    {
+        viewer->drawCalibrationLoaded = false;
+        if (viewer->calibrationLoaded)
+        {
+            for (int i=0;i<1440;i++)
+                for (int j=0;j<viewer->nRoi;j++)
+                {
+                    viewer->eventData[i*1024+j] *= viewer->gainMean[i*1024+j];
+                    viewer->eventData[i*1024+j] += (viewer->baseLineMean[i*1024+j]+viewer->triggerOffsetMean[i*1024+j]);
+                    viewer->eventData[i*1024+j] *= 2;
+               }
+            viewer->updateGL();
+        }
+
+    }
+
 }
 /************************************************************
@@ -1306,4 +1397,12 @@
     dialog.exec();
 }
+void UIConnector::loadNewCalibFileClicked()
+{
+    QFileDialog dialog;
+    dialog.setFileMode(QFileDialog::ExistingFile);
+    dialog.open(this, SLOT(calibFileSelected(QString)));
+    dialog.setVisible(true);
+    dialog.exec();
+}
 /************************************************************
  * FILE SELECTED. return of the file open dialog handler
@@ -1315,4 +1414,10 @@
         viewer->openFile(currentFile);
 }
+void UIConnector::calibFileSelected(QString file)
+{
+    currentCalibFile = file.toStdString();
+    if (currentCalibFile != "")
+        viewer->openCalibFile(currentCalibFile);
+}
 /************************************************************
  * NEW FILE LOADED. update of the UI after a new file has been loaded
@@ -1322,4 +1427,5 @@
     ostringstream str;
     str << "File loaded: " << currentFile << "\n";
+    str << "Calibration file loaded: " << currentCalibFile << "\n";
 //    fileLoadedLabel->setText(QString(str.str().c_str()));
 //    str.str("");
@@ -2123,4 +2229,5 @@
     connector.range3 = myUi.colorRange3;
     connector.range4 = myUi.colorRange4;
+    connector.drawCalibrationCheckBox = myUi.calibratedCheckBox;
 
     connector.initHistograms();
@@ -2162,6 +2269,10 @@
                      &connector, SLOT(newFileLoaded()));
 
+    QObject::connect(myUi.calibratedCheckBox, SIGNAL(stateChanged(int)),
+                     &connector, SLOT(drawCalibratedDataChanged(int)));
     QObject::connect(myUi.loadNewFileButton, SIGNAL(clicked()),
                      &connector, SLOT(loadNewFileClicked()));
+    QObject::connect(myUi.loadDRSCalibButton, SIGNAL(clicked()),
+                     &connector, SLOT(loadNewCalibFileClicked()));
 
     QObject::connect(myUi.colorRange0, SIGNAL(valueChanged(double)),
Index: /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 11752)
+++ /trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 11753)
@@ -27,4 +27,5 @@
 #include <QtGui/QDoubleSpinBox>
 #include <QtGui/QRadioButton>
+#include <QtGui/QCheckBox>
 #include <iostream>
 #include <GL/gl.h>
@@ -79,5 +80,6 @@
     RawDataViewer(QWidget *parent = 0);
     ~RawDataViewer();
-    void openFile(string& filename);
+    void openFile(string& file);
+    void openCalibFile(string& file);
 
 public Q_SLOTS:
@@ -169,4 +171,10 @@
     vector<edge> patchesIndices[160];
     fits* inputFile;
+    fits* calibInputFile;
+    float baseLineMean[1440*1024];
+    float gainMean[1440*1024];
+    float triggerOffsetMean[1440*1024];
+    bool calibrationLoaded;
+    bool drawCalibrationLoaded;
 
     QPoint lastPos;
@@ -191,5 +199,7 @@
 public Q_SLOTS:
     void loadNewFileClicked();
+    void loadNewCalibFileClicked();
     void fileSelected(QString file);
+    void calibFileSelected(QString file);
     void drawPatchesCheckChange(int state);
     void drawImpulseCheckChange(int state);
@@ -233,4 +243,5 @@
     void slicesPlusPlus();
     void slicesMinusMinus();
+    void drawCalibratedDataChanged(int state);
 
 Q_SIGNALS:
@@ -247,4 +258,5 @@
     QTimer timer;
     string currentFile;
+    string currentCalibFile;
     int crateID;
     int boardID;
@@ -301,4 +313,6 @@
     QDoubleSpinBox* range4;
 
+    QCheckBox*  drawCalibrationCheckBox;
+
     void initHistograms();
 
Index: /trunk/FACT++/gui/RawEventsViewer/viewer.ui
===================================================================
--- /trunk/FACT++/gui/RawEventsViewer/viewer.ui	(revision 11752)
+++ /trunk/FACT++/gui/RawEventsViewer/viewer.ui	(revision 11753)
@@ -221,4 +221,5 @@
           <property name="text">
            <string>File loaded: none
+Calibration file loaded: none
 Run number:
 Number of Events:
@@ -243,4 +244,7 @@
 </string>
           </property>
+          <property name="wordWrap">
+           <bool>true</bool>
+          </property>
          </widget>
         </item>
@@ -476,14 +480,4 @@
        </widget>
       </item>
-      <item row="0" column="8">
-       <widget class="QPushButton" name="loadNewFileButton">
-        <property name="toolTip">
-         <string>Load a new fits file</string>
-        </property>
-        <property name="text">
-         <string>Load New File</string>
-        </property>
-       </widget>
-      </item>
       <item row="1" column="5">
        <widget class="QDoubleSpinBox" name="redValue2">
@@ -847,4 +841,35 @@
         </item>
        </layout>
+      </item>
+      <item row="0" column="8">
+       <layout class="QHBoxLayout" name="horizontalLayout_8">
+        <item>
+         <widget class="QPushButton" name="loadNewFileButton">
+          <property name="toolTip">
+           <string>Load a new fits file</string>
+          </property>
+          <property name="text">
+           <string>Load Data</string>
+          </property>
+         </widget>
+        </item>
+        <item>
+         <widget class="QPushButton" name="loadDRSCalibButton">
+          <property name="text">
+           <string>Load DRS calib.</string>
+          </property>
+         </widget>
+        </item>
+       </layout>
+      </item>
+      <item row="0" column="1">
+       <widget class="QCheckBox" name="calibratedCheckBox">
+        <property name="layoutDirection">
+         <enum>Qt::RightToLeft</enum>
+        </property>
+        <property name="text">
+         <string>Calibrated data</string>
+        </property>
+       </widget>
       </item>
      </layout>
