Index: trunk/MagicSoft/Mars/mjobs/MJCalibration.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4604)
+++ trunk/MagicSoft/Mars/mjobs/MJCalibration.cc	(revision 4605)
@@ -109,4 +109,6 @@
 #include "MCalibrationChargePINDiode.h"
 #include "MCalibrationChargeBlindPix.h"
+#include "MCalibrationChargeBlindCam.h"
+#include "MCalibrationChargeBlindPix.h"
 #include "MCalibrationChargeCalc.h"
 
@@ -114,5 +116,6 @@
 #include "MHCalibrationCam.h"
 #include "MHCalibrationChargeCam.h"
-#include "MHCalibrationChargeBlindPix.h"
+#include "MHCalibrationChargeBlindCam.h"
+#include "MHCalibrationChargePINDiode.h"
 #include "MHCalibrationRelTimeCam.h"
 #include "MCalibrationRelTimeCam.h"
@@ -142,5 +145,7 @@
 using namespace std;
 
-const Int_t MJCalibration::gkIFAEBoxInaugurationRun = 20113;
+const Int_t MJCalibration::gkIFAEBoxInaugurationRun       = 20113;
+const Int_t MJCalibration::gkSecondBlindPixelInstallation = 31693;
+const Int_t MJCalibration::gkThirdBlindPixelInstallation  = 99999;
 // --------------------------------------------------------------------------
 //
@@ -210,4 +215,5 @@
 void MJCalibration::DisplayResult(MParList &plist)
 {
+
     if (!fDisplay)
         return;
@@ -417,9 +423,10 @@
     if (fDisplayType == kDataCheckDisplay)
       {
+
         TCanvas &c1 = fDisplay->AddTab("Fit.Charge");
         c1.Divide(3, 3);
         
-        disp1.CamDraw(c1, 1, 3, 5);
-        disp4.CamDraw(c1, 2, 3, 5);
+        disp1.CamDraw( c1, 1, 3, 5);
+        disp4.CamDraw( c1, 2, 3, 5);
         disp28.CamDraw(c1, 3, 3, 5);
 
@@ -456,5 +463,4 @@
             disp31.CamDraw(c5, 2, 2, 2);
           }
-
 
         return;
@@ -684,6 +690,20 @@
       //
       // Here starts the list of runs where the shifters did not put 
-      // a colour, but which have been found out by other means
+      // a colour, but which have been found out by other means. 
+      // FIXME: This list has is only preliminary and has to move into the 
+      //        database!!
       //
+      if (filenames.Contains("_30090_"))
+        if (fColor == MCalibrationCam::kNONE)
+          {
+            *fLog << "Found colour: kGREEN  in " << filenames << endl;
+            fColor = MCalibrationCam::kGREEN;
+          }
+        else if (fColor != MCalibrationCam::kNONE)
+          {
+            *fLog << err << "Different colour found in " << filenames << "... abort" << endl;
+            return kFALSE;
+          }
+
       if (filenames.Contains("_27474_"))
         if (fColor == MCalibrationCam::kNONE)
@@ -801,5 +821,5 @@
       //
       // Here start the runs where the shifter put 
-      // the colour
+      // the colour. 
       //
       if (filenames.Contains("green"))
@@ -933,5 +953,5 @@
 //   8)  MContinue(MFCosmics)
 //   9)  MFillH("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode")
-//   10) MFillH("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel")
+//   10) MFillH("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel")
 //   11) MFillH("MHCalibrationChargeCam",      "MExtractedSignalCam")
 //   12) MFillH("MHCalibrationChargeCam",      "MExtractedSignalCam")
@@ -987,19 +1007,50 @@
   }
 
-  MHCalibrationChargeCam   chargecam;
+  MHCalibrationChargeCam      chargecam;
+  MHCalibrationChargeBlindCam blindcam;
 
   plist.AddToList(&pedcam);
-  plist.AddToList(&chargecam);
+  plist.AddToList(&chargecam);  
+  plist.AddToList(&blindcam);  
   plist.AddToList(&fBadPixels);
   plist.AddToList(&fQECam);
   plist.AddToList(&fCalibrationCam);
-  plist.AddToList(&fCalibrationBlindPix);
+  plist.AddToList(&fCalibrationBlindCam);
   plist.AddToList(&fCalibrationPINDiode);
   plist.AddToList(&fRelTimeCam);
 
   MGeomApply               apply;
-  //    MBadPixelsMerge          merge(&fBadPixels);
   MExtractPINDiode         pinext;
   MExtractBlindPixel       blindext;
+  
+  //
+  // Initialize the blind pixel. Unfortunately, there is a hardware difference 
+  // in the first blind pixel until run "gkSecondBlindPixelInstallation" and the 
+  // later setup. The first needs to use a filter because of the length of 
+  // spurious NSB photon signals. The latter get better along extracting the amplitude
+  // from a small window.
+  //
+  TArrayI arr = fRuns->GetRuns();
+  if (arr[fRuns->GetNumRuns()-1] < gkSecondBlindPixelInstallation)
+    {
+      blindext.SetModified(kFALSE);
+      blindext.SetExtractionType(MExtractBlindPixel::kIntegral);
+      blindext.SetExtractionType(MExtractBlindPixel::kFilter);
+      blindext.SetRange(10,19,0,2);
+      blindcam.SetFitFunc( MHCalibrationChargeBlindPix::kEPoisson5 );
+    }
+  else
+    {
+      blindext.SetModified(kTRUE);
+      blindext.SetExtractionType(MExtractBlindPixel::kAmplitude);
+      blindext.SetExtractionType(MExtractBlindPixel::kFilter);
+      blindext.SetRange(5,8,0,2);
+      blindext.SetNSBFilterLimit(38);
+      if (arr[fRuns->GetNumRuns()-1] < gkThirdBlindPixelInstallation)
+        blindext.SetNumBlindPixels(2);
+      else
+        blindext.SetNumBlindPixels(3);
+    }
+  
   MExtractSlidingWindow    extract2;
   MExtractTimeFastSpline   timespline;
@@ -1024,5 +1075,5 @@
   
   MFillH fillpin("MHCalibrationChargePINDiode", "MExtractedSignalPINDiode");
-  MFillH fillbnd("MHCalibrationChargeBlindPix", "MExtractedSignalBlindPixel");
+  MFillH fillbnd("MHCalibrationChargeBlindCam", "MExtractedSignalBlindPixel");
   MFillH fillcam("MHCalibrationChargeCam",      "MExtractedSignalCam");
   MFillH filltme("MHCalibrationRelTimeCam",     "MArrivalTimeCam");
@@ -1032,19 +1083,15 @@
   filltme.SetNameTab("RelTimes");
 
+  TString drawoption;
+
   if (fDisplayType == kDataCheckDisplay)
-    {
-      fillcam.SetDrawOption("datacheck");
-      fillbnd.SetDrawOption("datacheck");
-      fillpin.SetDrawOption("datacheck");
-      filltme.SetDrawOption("datacheck");
-    }
-
+    drawoption += "datacheck";
   if (fDisplayType == kFullDisplay)
-    {
-      fillcam.SetDrawOption("all");
-      filltme.SetDrawOption("all");
-    }
-  
-  
+    drawoption += " all";
+  
+  fillcam.SetDrawOption(drawoption.Data());
+  fillbnd.SetDrawOption(drawoption.Data());
+  fillpin.SetDrawOption(drawoption.Data());
+  filltme.SetDrawOption(drawoption.Data());
   // 
   // Apply a filter against cosmics
@@ -1067,5 +1114,4 @@
     }
   
-
   tlist.AddToList(&pinext);  
   tlist.AddToList(&blindext);
@@ -1088,17 +1134,16 @@
   tlist.AddToList(&fillcam);
 
+  if (fRelTimes)
+    {
+      tlist.AddToList(&filltme);
+      tlist.AddToList(&timecalc);
+    }
+  
+  if (IsUseBlindPixel())
+    tlist.AddToList(&fillbnd);
   if (IsUsePINDiode())
     tlist.AddToList(&fillpin);
-  if (IsUseBlindPixel())
-    tlist.AddToList(&fillbnd);
 
   tlist.AddToList(&calcalc);
-
-  if (fRelTimes)
-    {
-      tlist.AddToList(&filltme);
-      tlist.AddToList(&timecalc);
-    }
-  
 
   // Create and setup the eventloop
@@ -1117,4 +1162,37 @@
   tlist.PrintStatistics();
 
+  //
+  // The next lines are necessary in order to avoid that 
+  // the last entry drawn by MFillH gets deleted again from 
+  // the display. No idea where this comes from...
+  //
+  if (fDisplay)
+    {
+      if (IsUsePINDiode())
+        {
+          MHCalibrationChargePINDiode *pin = 
+            (MHCalibrationChargePINDiode*)plist.FindObject("MHCalibrationChargePINDiode");
+          pin->DrawClone(Form("nonew %s",drawoption.Data()));
+        }
+      else if (IsUseBlindPixel())
+        {
+          MHCalibrationChargeBlindCam *cam = 
+            (MHCalibrationChargeBlindCam*)plist.FindObject("MHCalibrationChargeBlindCam");
+          cam->DrawClone(Form("nonew %s",drawoption.Data()));
+        }
+      else if (fRelTimes)
+        {
+          MHCalibrationRelTimeCam *cam = 
+            (MHCalibrationRelTimeCam*)plist.FindObject("MHCalibrationRelTimeCam");
+          cam->DrawClone(Form("nonew %s",drawoption.Data()));
+        }
+      else
+        {
+          MHCalibrationChargeCam *cam = 
+            (MHCalibrationChargeCam*)plist.FindObject("MHCalibrationChargeCam");
+          cam->DrawClone(Form("nonew %s",drawoption.Data()));
+        }
+    }
+  
   DisplayResult(plist);
 
@@ -1249,7 +1327,7 @@
     }
 
-    if (fCalibrationBlindPix.Write()<=0)
-    {
-        *fLog << err << "Unable to write MCalibrationChargeBlindPix to " << oname << endl;
+    if (fCalibrationBlindCam.Write()<=0)
+    {
+        *fLog << err << "Unable to write MCalibrationChargeBlindCam to " << oname << endl;
         return kFALSE;
     }
