Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 7023)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 7028)
@@ -179,5 +179,9 @@
 //  
 //  
-//  
+//  ClassVersion 2:
+//   - Float_t fPheErrLimit;
+//   + Float_t fPheErrLowerLimit;                   // Lower limit acceptance nr. phe's w.r.t. area idx mean (in sigmas)
+//   + Float_t fPheErrUpperLimit;                   // Upper limit acceptance nr. phe's w.r.t. area idx mean (in sigmas)
+//
 //////////////////////////////////////////////////////////////////////////////
 #include "MCalibrationChargeCalc.h"
@@ -236,5 +240,6 @@
 const Float_t MCalibrationChargeCalc::fgLambdaErrLimit         = 0.2;
 const Float_t MCalibrationChargeCalc::fgLambdaCheckLimit       = 0.5;
-const Float_t MCalibrationChargeCalc::fgPheErrLimit            = 4.5;
+const Float_t MCalibrationChargeCalc::fgPheErrLowerLimit       = 9.0;
+const Float_t MCalibrationChargeCalc::fgPheErrUpperLimit       = 5.5;
 const Float_t MCalibrationChargeCalc::fgFFactorErrLimit        = 4.5;
 const Float_t MCalibrationChargeCalc::fgArrTimeRmsLimit        = 3.5;
@@ -262,5 +267,6 @@
 // - fLambdaErrLimit    to fgLambdaErrLimit 
 // - fNamePedestalCam   to fgNamePedestalCam
-// - fPheErrLimit       to fgPheErrLimit  
+// - fPheErrLowerLimit  to fgPheErrLowerLimit
+// - fPheErrUpperLimit  to fgPheErrUpperLimit
 // - fPulserColor       to MCalibrationCam::kCT1
 // - fOutputPath        to "."
@@ -289,12 +295,13 @@
   SetChargeErrLimit    ();  
   SetChargeRelErrLimit ();
+  SetDebug       ( kFALSE );
   SetFFactorErrLimit   ();
   SetLambdaCheckLimit  ();
   SetLambdaErrLimit    ();
   SetNamePedestalCam   ();
-  SetPheErrLimit       ();
   SetOutputPath        ();
   SetOutputFile        ();
-  SetDebug       ( kFALSE );
+  SetPheErrLowerLimit  ();
+  SetPheErrUpperLimit  ();
 
   SetCheckArrivalTimes     ();
@@ -867,4 +874,6 @@
   PrintUncalibrated(MBadPixelsPix::kDeadPedestalRms,
                     "Presumably dead from Pedestal Rms:                ");
+  PrintUncalibrated(MBadPixelsPix::kDeviatingNumPhes,
+                    "Deviating number of phes:                         ");
   PrintUncalibrated(MBadPixelsPix::kPreviouslyExcluded,
                     "Previously excluded:                              ");
@@ -883,6 +892,4 @@
   PrintUncalibrated(MBadPixelsPix::kLoGainNotFitted,     
                     "Unsuccesful Gauss fit to the Lo Gain:   ");
-  PrintUncalibrated(MBadPixelsPix::kDeviatingNumPhes,    
-                    "Deviating number of phes:               ");
   PrintUncalibrated(MBadPixelsPix::kDeviatingFFactor,    
                     "Deviating F-Factor:                     ");
@@ -1100,5 +1107,5 @@
         {
           if (bad.IsUncalibrated( MBadPixelsPix::kDeviatingNumPhes ))
-            bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun    );
+            bad.SetUnsuitable(   MBadPixelsPix::kUnsuitableRun    );
         }
       
@@ -1235,6 +1242,7 @@
         }
       
-      lowlim  [i] = areaphes[i] - fPheErrLimit*TMath::Sqrt(areavars[i]);
-      upplim  [i] = areaphes[i] + fPheErrLimit*TMath::Sqrt(areavars[i]);
+      lowlim[i] = areaphes[i] - fPheErrLowerLimit*TMath::Sqrt(areavars[i]);
+      upplim[i] = areaphes[i] + fPheErrUpperLimit*TMath::Sqrt(areavars[i]);
+ 
 
       TH1D *hist = camphes.ProjectionS(TArrayI(),TArrayI(1,&i),"_py",100);
@@ -1247,9 +1255,9 @@
         hist->DrawClone();
 
-      if (ndf < 2)
+      if (ndf < 5)
         {
           *fLog << warn << GetDescriptor() << ": Cannot use a Gauss fit to the number of photo-electrons " 
                 << "in the camera with area index: " << i << endl;
-          *fLog << warn << GetDescriptor() << ": Number of dof.: " << ndf << " is smaller than 2 " << endl;
+          *fLog << warn << GetDescriptor() << ": Number of dof.: " << ndf << " is smaller than 5 " << endl;
           *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;
           delete hist;
@@ -1282,6 +1290,6 @@
             << Form("%7.2f+-%6.2f",mean,sigma) << endl;
 
-      lowlim  [i] = mean  - fPheErrLimit*sigma;
-      upplim  [i] = mean  + fPheErrLimit*sigma;
+      lowlim[i] = mean - fPheErrLowerLimit*sigma;
+      upplim[i] = mean + fPheErrUpperLimit*sigma;
 
       delete hist;
@@ -1326,12 +1334,10 @@
         {
           *fLog << warn << "Number of phes: "
-                << Form("%7.2f out of %3.1f sigma limit: ",nphe,fPheErrLimit)
+                << Form("%7.2f out of +%3.1f-%3.1f sigma limit: ",nphe,fPheErrUpperLimit,fPheErrLowerLimit)
                 << Form("[%7.2f,%7.2f] pixel%4i",lowlim[aidx],upplim[aidx],i) << endl;
           bad.SetUncalibrated( MBadPixelsPix::kDeviatingNumPhes );
+
           if (IsCheckDeviatingBehavior())
-            {
-              bad.SetUnsuitable  ( MBadPixelsPix::kUnreliableRun    );
-              //              pix.SetFFactorMethodValid(kFALSE);
-            }
+                bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
           continue;
         }
@@ -1511,8 +1517,9 @@
       if (2.*(lambdacheck-lambda)/(lambdacheck+lambda) > fLambdaCheckLimit)
         {
-          *fLog << warn << GetDescriptor() 
-                << Form("%s%4.2f%s%4.2f%s%4.2f%s%2i",": Lambda: ",lambda," and Lambda-Check: ",
-                    lambdacheck," differ by more than ",fLambdaCheckLimit," in the Blind Pixel Nr.",i)
-                << endl;
+          *fLog << warn << GetDescriptor() << ": Lambda="
+                << Form("%4.2f", lambda) << " and Lambda-Check="
+                << Form("%4.2f", lambdacheck) << " differ by more than "
+                << Form("%4.2f", fLambdaCheckLimit) << " in the Blind Pixel Nr."
+                << Form("%2i", i) << endl;
           blindpix.SetValid(kFALSE);
           continue;
@@ -1521,7 +1528,8 @@
       if (lambdaerr > fLambdaErrLimit) 
         {
-          *fLog << warn << GetDescriptor() 
-                << Form("%s%4.2f%s%4.2f%s%2i",": Error of Fitted Lambda: ",lambdaerr," is greater than ",
-                        fLambdaErrLimit," in Blind Pixel Nr.",i) << endl;
+            *fLog << warn << GetDescriptor() << ": Error of Fitted Lambda="
+                << Form("%4.2f", lambdaerr) << " is greater than "
+                << Form("%4.2f", fLambdaErrLimit)
+                << " in Blind Pixel Nr." << Form("%2d", i) << endl;
           blindpix.SetValid(kFALSE);
           continue;
@@ -2248,9 +2256,4 @@
       rc = kTRUE;
     }
-  if (IsEnvDefined(env, prefix, "PheErrLimit", print))
-    {
-      SetPheErrLimit(GetEnvValue(env, prefix, "PheErrLimit", fPheErrLimit));
-      rc = kTRUE;
-    }
   if (IsEnvDefined(env, prefix, "CheckDeadPixels", print))
     {
@@ -2283,6 +2286,18 @@
       rc = kTRUE;
     }
+  if (IsEnvDefined(env, prefix, "PheErrLowerLimit", print))
+    {
+      SetPheErrLowerLimit(GetEnvValue(env, prefix, "PheErrLowerLimit", fPheErrLowerLimit));
+      rc = kTRUE;
+    }
+  if (IsEnvDefined(env, prefix, "PheErrUpperLimit", print))
+    {
+      SetPheErrUpperLimit(GetEnvValue(env, prefix, "PheErrUpperLimit", fPheErrUpperLimit));
+      rc = kTRUE;
+    }
 
   return rc;
 }
 
+
+  
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 7023)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 7028)
@@ -54,5 +54,6 @@
   static const Float_t fgLambdaCheckLimit;     //! Default for fLambdaCheckLimit   (now set to: 0.2)
   static const Float_t fgLambdaErrLimit;       //! Default for fLabmdaErrLimit     (now set to: 0.5)
-  static const Float_t fgPheErrLimit;          //! Default for fPheErrLimit        (now set to: 4.5)
+  static const Float_t fgPheErrLowerLimit;     //! Default for fPheErrLowerLimit   (now set to: 9.0)
+  static const Float_t fgPheErrUpperLimit;     //! Default for fPheErrUpperLimit   (now set to: 4.5)
   static const Float_t fgFFactorErrLimit;      //! Default for fFFactorErrLimit    (now set to: 4.5)
   static const Float_t fgArrTimeRmsLimit;      //! Default for fArrTimeRmsLimit    (now set to: 3.5)
@@ -68,6 +69,7 @@
   Float_t fNumHiGainSamples;                   // Number High-Gain FADC slices used by extractor
   Float_t fNumLoGainSamples;                   // Number Low -Gain FADC slices used by extractor
-  Float_t fPheErrLimit;                        // Limit acceptance nr. phe's w.r.t. area idx mean (in sigmas)
-  Float_t fFFactorErrLimit;                    // Limit acceptance F-Factor w.r.t. area idx mean 
+  Float_t fPheErrLowerLimit;                   // Lower limit acceptance nr. phe's w.r.t. area idx mean (in sigmas)
+  Float_t fPheErrUpperLimit;                   // Upper limit acceptance nr. phe's w.r.t. area idx mean (in sigmas)
+  Float_t fFFactorErrLimit;                    // Limit acceptance F-Factor w.r.t. area idx mean
   Float_t fArrTimeRmsLimit;                    // Limit acceptance RMS of absolute arrival times
   Float_t fSqrtHiGainSamples;                  // Square root nr. High-Gain FADC slices used by extractor
@@ -218,8 +220,9 @@
   void SetOutputPath        ( TString path="."                   );
   void SetOutputFile        ( TString file="ChargeCalibStat.txt" );
-  void SetPheErrLimit       ( const Float_t f=fgPheErrLimit            ) { fPheErrLimit       = f;     }  
+  void SetPheErrLowerLimit  ( const Float_t f=fgPheErrLowerLimit       ) { fPheErrLowerLimit  = f;     }
+  void SetPheErrUpperLimit  ( const Float_t f=fgPheErrUpperLimit       ) { fPheErrUpperLimit  = f;     }
   void SetPulserColor       ( const MCalibrationCam::PulserColor_t col ) { fPulserColor       = col;   }
 
-  ClassDef(MCalibrationChargeCalc, 1)   // Task calculating Calibration Containers and Quantum Efficiencies
+  ClassDef(MCalibrationChargeCalc, 2)   // Task calculating Calibration Containers and Quantum Efficiencies
 };
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 7023)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCam.cc	(revision 7028)
@@ -523,32 +523,50 @@
       break;
     case 9:
-      if (!pix.IsFFactorMethodValid())
+      //      if (!pix.IsFFactorMethodValid())
+      //        return kFALSE;
+      if (pix.IsExcluded())
         return kFALSE;
       val = pix.GetPheFFactorMethod();
       break;
     case 10:
-      if (!pix.IsFFactorMethodValid())
+      //      if (!pix.IsFFactorMethodValid())
+      //        return kFALSE;
+      if (pix.IsExcluded())
         return kFALSE;
       val = pix.GetPheFFactorMethodErr();
+      if (val < 0.)
+        val = 0.00001;
       break;
     case 11:
-      if (!pix.IsFFactorMethodValid())
+      //      if (!pix.IsFFactorMethodValid())
+      //        return kFALSE;
+      if (pix.IsExcluded())
         return kFALSE;
       val = pix.GetMeanConvFADC2Phe();
       break;
     case 12:
-      if (!pix.IsFFactorMethodValid())
+      //      if (!pix.IsFFactorMethodValid())
+      //        return kFALSE;
+      if (pix.IsExcluded())
         return kFALSE;
       val = pix.GetMeanConvFADC2PheErr();
+      if (val < 0.)
+        val = 0.00001;
       break;
     case 13:
-      if (!pix.IsFFactorMethodValid())
+      //      if (!pix.IsFFactorMethodValid())
+      //        return kFALSE;
+      if (pix.IsExcluded())
         return kFALSE;
       val = pix.GetMeanFFactorFADC2Phot();
       break;
     case 14:
-      if (!pix.IsFFactorMethodValid())
+      //      if (!pix.IsFFactorMethodValid())
+      //        return kFALSE;
+      if (pix.IsExcluded())
         return kFALSE;
       val = pix.GetMeanFFactorFADC2PhotErr();
+      if (val < 0.)
+        val = 0.00001;
       break;
     case 15:
