Index: trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc
===================================================================
--- trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 12167)
+++ trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.cc	(revision 12173)
@@ -1,2 +1,3 @@
+/*
 /*
  * QtGl.cpp
@@ -270,4 +271,8 @@
     float divideMe = (float)(VALUES_SPAN-1);
     float plusMe = VALUES_SPAN/2;
+
+    cout << "---> value span..." << endl;
+
+    /*
     if (drawCalibrationLoaded)
         plusMe += 0;//VALUES_SPAN/2;
@@ -276,5 +281,6 @@
         divideMe /=2;
         plusMe = 0 ;///=2;
-    }
+        }*/
+
     for (int i=0;i<nRoi-1;i++)
     {
@@ -460,6 +466,6 @@
         updateNeighbors(i);
 
-    calibrationLoaded = false;
-    drawCalibrationLoaded = false;
+    //calibrationLoaded = false;
+    //drawCalibrationLoaded = false;
 
 }
@@ -1039,5 +1045,14 @@
 void RawDataViewer::openCalibFile(string& file)
 {
-    calibrationLoaded = false;
+    //calibrationLoaded = false;
+
+    MessageImp msg;
+    if (!DataCalib::ReadFits(file, msg))
+    {
+        DataCalib::Restart();
+        return;
+    }
+    /*
+
     calibInputFile = new fits(file);
     if (!*calibInputFile)
@@ -1073,9 +1088,10 @@
 
     delete calibInputFile;
-
-    calibrationLoaded = true;
+*/
+    //calibrationLoaded = true;
 
     emit newFileLoaded();
-    if (drawCalibrationLoaded)
+
+    //if (calibratedCheckBox->isChecked())
         updateGL();
 }
@@ -1125,10 +1141,14 @@
 #endif
 
-    if (drawCalibrationLoaded && calibrationLoaded)
-    {
+//    if (drawCalibrationLoaded && calibrationLoaded)
+//    {
+
+//    if (calibratedCheckBox->isChecked())
+        DataCalib::Apply(eventData, rawEventData, startPix, nRoi);
+/*
         for (int i=0;i<1440;i++)
             for (int j=0;j<nRoi;j++)
             {
-                int realj = (j+startPix[j])%1024;
+                int realj = (j+startPix[i])%1024;
                 eventData[i*1024+j] *= 2000.f/4096.f;
                 eventData[i*1024+j] -= (baseLineMean[i*1024+realj]+triggerOffsetMean[i*1024+j]);
@@ -1137,5 +1157,6 @@
             }
     }
-    updateGL();
+    */
+        updateGL();
     emit signalCurrentEvent(eventNum);
     emit signalCurrentPixel(selectedPixel);
@@ -1277,45 +1298,19 @@
 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++)
-                {
-                    int realj = (j+viewer->startPix[j])%1024;
-                    viewer->eventData[i*1024+j] *= 2000.f/4096.f;
-                    viewer->eventData[i*1024+j] -= (viewer->baseLineMean[i*1024+realj]+viewer->triggerOffsetMean[i*1024+j]);
-                    viewer->eventData[i*1024+j] /= viewer->gainMean[i*1024+realj];
-                    viewer->eventData[i*1024+j] *= (50000.f/65536.f) * 2500.f;
-                }
-            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++)
-                {
-                    int realj = (j+viewer->startPix[j])%1024;
-                    viewer->eventData[i*1024+j] /= (50000.f/65536.f) * 2500.f;
-                    viewer->eventData[i*1024+j] *= viewer->gainMean[i*1024+realj];
-                    viewer->eventData[i*1024+j] += (viewer->baseLineMean[i*1024+realj]+viewer->triggerOffsetMean[i*1024+j]);
-                    viewer->eventData[i*1024+j] /= 2000.f/4096.f;
-               }
-            viewer->updateGL();
-        }
-
-    }
-     autoScalePressed();
-     pixelChanged(viewer->selectedPixel);
+    cout << "=== drawCalibratedDataChanged " << state << endl;
+
+    for (int i=0;i<(1440+160)*viewer->nRoi;i++)
+        viewer->eventData[i] = (float)viewer->rawEventData[i];
+
+//    if (viewer->calibratedCheckBox->isChecked())
+    if (state)
+        DataCalib::Apply(viewer->eventData, viewer->rawEventData, viewer->startPix, viewer->nRoi);
+
+    viewer->updateGL();
+
+    //drawCalibrationCheckBox->setChecked(false);
+
+    autoScalePressed();
+    pixelChanged(viewer->selectedPixel);
 
 }
@@ -1325,8 +1320,5 @@
 void UIConnector::drawPatchesCheckChange(int state)
 {
-    if (state)
-        viewer->drawPatch = true;
-    else
-        viewer->drawPatch = false;
+    viewer->drawPatch = state;
     viewer->updateGL();
 }
@@ -1336,8 +1328,5 @@
 void UIConnector::drawImpulseCheckChange(int state)
 {
-    if (state)
-        viewer->drawImpulse = true;
-    else
-        viewer->drawImpulse = false;
+    viewer->drawImpulse = state;
     viewer->updateGL();
 }
@@ -1347,16 +1336,10 @@
 void UIConnector::drawBlurCheckChange(int state)
 {
-    if (state)
-        viewer->drawBlur = true;
-    else
-        viewer->drawBlur = false;
+    viewer->drawBlur = state;
     viewer->updateGL();
 }
 void UIConnector::loopEventCheckChange(int state)
 {
-    if (state)
-        viewer->loopCurrentEvent = true;
-    else
-        viewer->loopCurrentEvent = false;
+    viewer->loopCurrentEvent = state;
 }
 /************************************************************
@@ -1628,8 +1611,9 @@
     extraInfoLabel->setText(QString(str.str().c_str()));
 
+    /*
     if (viewer->calibrationLoaded)
     {
         drawCalibrationCheckBox->setEnabled(true);
-    }
+    }*/
 
 
@@ -2409,9 +2393,18 @@
     viewer->ss[4] = maxRange;
     range4->setValue(viewer->ss[4]);
-    viewer->ss[2] = midRange;
+//    viewer->ss[2] = midRange;
+//    range2->setValue(viewer->ss[2]);
+//    viewer->ss[1] = (minRange+midRange)/2;
+//    range1->setValue(viewer->ss[1]);
+//    viewer->ss[3] = (maxRange+midRange)/2;
+//    range3->setValue(viewer->ss[3]);
+
+    viewer->ss[2] = (maxRange+minRange)/2;
     range2->setValue(viewer->ss[2]);
-    viewer->ss[1] = (minRange+midRange)/2;
+
+    viewer->ss[1] = minRange+(maxRange-minRange)/4;
     range1->setValue(viewer->ss[1]);
-    viewer->ss[3] = (maxRange+midRange)/2;
+
+    viewer->ss[3] = minRange+3*(maxRange-minRange)/4;
     range3->setValue(viewer->ss[3]);
 
@@ -2461,8 +2454,9 @@
     configs.add_options()
         ("color.range", vars<double>(), "Range of the display colours")
-        ("color.red", vars<double>(), "Range of red values")
+        ("color.red",   vars<double>(), "Range of red values")
         ("color.green", vars<double>(), "Range of green values")
-        ("color.blue", vars<double>(), "Range of blue values")
-        ("file,f", var<string>(), "File to be loaded at startup")
+        ("color.blue",  vars<double>(), "Range of blue values")
+        ("file,f",      var<string>(),  "File to be loaded")
+        ("drs,d",       var<string>(),  "DRS calibration file to be loaded")
         ;
     conf.AddOptions(configs);
@@ -2470,4 +2464,5 @@
     po::positional_options_description p;
     p.add("file", 1); // The first positional options
+    p.add("drs",  2); // The first positional options
     conf.SetArgumentPositions(p);
 
@@ -2619,5 +2614,5 @@
     connector.range4 = myUi.colorRange4;
     connector.drawCalibrationCheckBox = myUi.calibratedCheckBox;
-    connector.drawCalibrationCheckBox->setEnabled(false);
+//    connector.drawCalibrationCheckBox->setEnabled(false);
 
     connector.initHistograms();
@@ -2771,9 +2766,14 @@
     if (conf.Has("file"))
     {
-        string str = conf.Get<string>("file");
-        QString qstr(str.c_str());
+        const QString qstr(conf.Get<string>("file").c_str());
         connector.fileSelected(qstr);
     }
 
+    if (conf.Has("drs"))
+    {
+        const QString qstr(conf.Get<string>("drs").c_str());
+        connector.calibFileSelected(qstr);
+    }
+
     mainWindow.show();
 
Index: trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h
===================================================================
--- trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 12167)
+++ trunk/FACT++/gui/RawEventsViewer/RawEventsViewer.h	(revision 12173)
@@ -44,4 +44,7 @@
 
 #include <string>
+
+#include "../../src/DataCalib.h"
+
 
 namespace std
@@ -153,9 +156,9 @@
 //    vector<edge> patchesIndices[160];
     std::fits* inputFile;
-    std::fits* calibInputFile;
-    float baseLineMean[1440*1024];
-    float gainMean[1440*1024];
-    float triggerOffsetMean[1440*1024];
-    bool calibrationLoaded;
+//    std::fits* calibInputFile;
+//    float baseLineMean[1440*1024];
+//    float gainMean[1440*1024];
+//    float triggerOffsetMean[1440*1024];
+//    bool calibrationLoaded;
     bool drawCalibrationLoaded;
 
