Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 3600)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 3601)
@@ -29,4 +29,7 @@
    * mbadpixels/MBadPixelsPix.cc
      - put some documentation in the header
+
+   * mcalib/MHCalibrationChargeCam.cc
+     - adopt to new style in MBadPixelsPix.h
 
 
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 3600)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCam.cc	(revision 3601)
@@ -342,67 +342,49 @@
       break;
     case 7:
-      val = !(*this)[idx].IsCalibrationFitOK(); 
+      val = !(*this)[idx].IsCalibrationResultOK(); 
       return val;
       break;
     case 8:
-      val = (*this)[idx].IsCalibrationOscillating();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainNotFitted);
       return val;
       break;
     case 9:
-      val = !(*this)[idx].IsCalibrationResultOK();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainNotFitted);
       return val;
       break;
     case 10:
-      val = (*this)[idx].IsHiGainSaturation();
+     val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kHiGainOscillating);
       return val;
       break;
     case 11:
-      val = (*this)[idx].IsLoGainSaturation();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kLoGainSaturation );
       return val;
       break;
     case 12:
-      val = (*this)[idx].IsNotCalibrated();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeIsPedestal );
       return val;
       break;
     case 13:
-      val = (*this)[idx].IsMeanTimeInLastBin();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeErrNotValid);
       return val;
       break;
     case 14:
-      val = (*this)[idx].IsMeanTimeInFirstBin();      
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeRelErrNotValid);
       return val;
       break;
     case 15:
-      val = (*this)[idx].IsLoGainOscillating();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kChargeSigmaNotValid );
       return val;
       break;
     case 16:
-      val = (*this)[idx].IsHiGainOscillating();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInFirstBin  );
       return val;
       break;
     case 17:
-      val = (*this)[idx].IsConvHiLoNotValid();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kMeanTimeInLast2Bins );
       return val;
       break;
     case 18:
-      val = (*this)[idx].IsChargeSigmaNotValid();
-      return val;
-      break;
-    case 19:
-      val = (*this)[idx].IsChargeRelErrNotValid();
-      return val;
-      break;
-    case 20:
-      val = (*this)[idx].IsChargeErrNotValid();
-      return val;
-    case 21:
-      val = (*this)[idx].IsChargeIsPedestal();
-      return val;
-    case 22:
-      val = (*this)[idx].IsLoGainNotFitted();
-      return val;
-      break;
-    case 23:
-      val = (*this)[idx].IsHiGainNotFitted();
+      val = (*this)[idx].IsUncalibrated(MBadPixelsPix::kDeviatingNumPhes    );
       return val;
       break;
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.cc	(revision 3600)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.cc	(revision 3601)
@@ -23,8 +23,46 @@
 !
 \* ======================================================================== */
-
 /////////////////////////////////////////////////////////////////////////////
 //
 // MBadPixelsPix
+//
+// The bits of an integer array fInfo are used to declare and inform about 
+// possible defects in a pixel. Default and absence of defects create an array
+// of zeros. 
+//
+// The first index (fInfo[0]) holds general information which is coded as follows:
+// * BIT(1): Unsuitable Run: The pixel is not suited for analysis for the entire run
+// * BIT(2): Unsuitable Evt: The pixel is not suited for analysis for the current event
+// * BIT(3): Unreliable Run: The pixel can in principle be used for analysis, although 
+//                           previous analysis steps have yielded certain inconsistencies
+//
+// These bits can be called with the enum MBadPixelsPix::UnsuitableTupe_t in combination 
+// with the function IsUnsuitable(MBadPixelsPix::UnsuitableTupe_t), e.g. 
+// MBadPixelsPix::IsUnsuitalbe(MBadPixelsPix::kUnsuitableRun) asks if the first bit is set. 
+//
+// The second index (fInfo[1]) hold information acquired during the calibration. The bits 
+// are coded in the following form:
+// BIT(1 ): kHiGainNotCalibrated :  Any High Gain signal is not calibrated and cannot be used
+// BIT(2 ): kLoGainNotCalibrated :  Any Low  Gain signal is not calibrated and cannot be used
+// BIT(3 ): kHiGainNotFitted     :  Any High Gain signal is calibrated without a Gauss Fit to the signal distribution
+// BIT(4 ): kLoGainNotFitted     :  Any Low  Gain signal is calibrated without a Gauss Fit to the signal distribution
+// BIT(5 ): kHiGainOscillating   :  The High Gain signals fourier transform showed abnormal behavior  
+// BIT(6 ): kLoGainOscillating   :  The Low  Gain signals fourier transform showed abnormal behavior  
+// BIT(7 ): kLoGainSaturation    :  The Low  Gain signals were saturated during calibration
+// BIT(8 ): kChargeIsPedestal    :  The calibration signal contained only pedestals - presumably dead pixel
+// BIT(10): kChargeRelErrNotValid:  The relative error of the derived charge was too large or too small
+// BIT(11): kChargeSigmaNotValid :  The sigma of the pedestal distribution smaller than the pedestal RMS - presumably a pixel with a star in its FOV only during the pedestal taking 
+// BIT(12): kMeanTimeInFirstBin  :  The signal has its mean maximum in the first used FADC slice - signal extractor bad
+// BIT(13): kMeanTimeInLast2Bins :  The signal has its mean maximum in the last two used FADC slice - signal extractor bad
+// BIT(14): kDeviatingNumPhes    :  The calculated number of photo-electrons deviates too much from the mean - inconsitency
+//
+// These bits can be called with the enum MBadPixelsPix::UncalibratedType_t in combination 
+// with the function IsUncalibrated(MBadPixelsPix::UncalibratedTupe_t), e.g. 
+// MBadPixelsPix::IsUncalibrated(MBadPixelsPix::kHiGainNotCalibrated) asks if the Hi Gain signal
+// could be calibrated.
+//
+// Two additional functions yield specific calibration information:
+// * IsCalibrationSignalOK() asks if the extracted calibration signal showed any inconsistency
+// * IsCalibrationResultOK() asks if the applied calibration can be used at all.
 //
 /////////////////////////////////////////////////////////////////////////////
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h	(revision 3600)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsPix.h	(revision 3601)
@@ -27,20 +27,19 @@
 
     // All types are initialized to normal behaviour
-    enum CalibrationType_t {
-      kHiGainSaturation         = BIT(1),
-      kLoGainSaturation         = BIT(2),
+    enum UncalibratedType_t {
+      kHiGainNotCalibrated      = BIT(1),
+      kLoGainNotCalibrated      = BIT(2), 
       kHiGainNotFitted          = BIT(3),
       kLoGainNotFitted          = BIT(4), 
-      kChargeIsPedestal         = BIT(5),
-      kChargeErrNotValid        = BIT(6),
-      kChargeRelErrNotValid     = BIT(7),
-      kChargeSigmaNotValid      = BIT(8),
-      kConvHiLoNotValid         = BIT(9),      
-      kHiGainOscillating        = BIT(10),
-      kLoGainOscillating        = BIT(11),
+      kHiGainOscillating        = BIT(5),
+      kLoGainOscillating        = BIT(6),
+      kLoGainSaturation         = BIT(7),
+      kChargeIsPedestal         = BIT(8),
+      kChargeErrNotValid        = BIT(9),
+      kChargeRelErrNotValid     = BIT(10),
+      kChargeSigmaNotValid      = BIT(11),
       kMeanTimeInFirstBin       = BIT(12),
-      kMeanTimeInLastBin        = BIT(13), 
-      kDeviatingNumPhes         = BIT(14),
-      kNotCalibrated            = BIT(15)   
+      kMeanTimeInLast2Bins      = BIT(13), 
+      kDeviatingNumPhes         = BIT(14)
     };
     
@@ -53,64 +52,33 @@
 
     // Setter
-    void SetUnsuitable(UnsuitableType_t typ) { fInfo[0] |= typ; }
-
-    // Calibration
-    void SetHiGainSaturation         () { fInfo[1] |= kHiGainSaturation; }
-    void SetLoGainSaturation         () { fInfo[1] |= kLoGainSaturation; }
-    void SetNotCalibrated           () { fInfo[1] |= kNotCalibrated; }
-    void SetMeanTimeInLastBin        () { fInfo[1] |= kMeanTimeInLastBin; }
-    void SetMeanTimeInFirstBin       () { fInfo[1] |= kMeanTimeInFirstBin; }
-    void SetLoGainOscillating        () { fInfo[1] |= kLoGainOscillating; }
-    void SetHiGainOscillating        () { fInfo[1] |= kHiGainOscillating; }
-    void SetConvHiLoNotValid         () { fInfo[1] |= kConvHiLoNotValid; }
-    void SetChargeSigmaNotValid      () { fInfo[1] |= kChargeSigmaNotValid; }
-    void SetChargeRelErrNotValid     () { fInfo[1] |= kChargeRelErrNotValid; }
-    void SetChargeErrNotValid        () { fInfo[1] |= kChargeErrNotValid; }
-    void SetChargeIsPedestal         () { fInfo[1] |= kChargeIsPedestal; }
-    void SetLoGainNotFitted          () { fInfo[1] |= kLoGainNotFitted; }
-    void SetHiGainNotFitted          () { fInfo[1] |= kHiGainNotFitted; }
-    void SetDeviatingNumPhes         () { fInfo[1] |= kDeviatingNumPhes; }
+    void SetUnsuitable  ( UnsuitableType_t   typ ) { fInfo[0] |= typ; }
+    void SetUncalibrated( UncalibratedType_t typ ) { fInfo[1] |= typ; }
 
     // Getter
-    Bool_t IsUnsuitable(UnsuitableType_t typ) const { return fInfo[0]&typ; }
+    Bool_t IsUnsuitable  ( UnsuitableType_t   typ ) const { return fInfo[0]&typ; }
+    Bool_t IsUncalibrated( UncalibratedType_t typ ) const { return fInfo[1]&typ; }
 
     Bool_t IsOK() const  { return fInfo[0]==0; }
     Bool_t IsBad() const { return fInfo[0]!=0; }
 
-    Bool_t IsHiGainSaturation         () const      { return fInfo[1] & kHiGainSaturation ;        }
-    Bool_t IsLoGainSaturation         () const      { return fInfo[1] & kLoGainSaturation ;        }
-    Bool_t IsNotCalibrated            () const      { return fInfo[1] & kNotCalibrated;            }
-    Bool_t IsMeanTimeInLastBin        () const      { return fInfo[1] & kMeanTimeInLastBin;        }
-    Bool_t IsMeanTimeInFirstBin       () const      { return fInfo[1] & kMeanTimeInFirstBin;       }
-    Bool_t IsLoGainOscillating        () const      { return fInfo[1] & kLoGainOscillating;        }
-    Bool_t IsHiGainOscillating        () const      { return fInfo[1] & kHiGainOscillating;        }
-    Bool_t IsConvHiLoNotValid         () const      { return fInfo[1] & kConvHiLoNotValid;         }
-    Bool_t IsChargeSigmaNotValid      () const      { return fInfo[1] & kChargeSigmaNotValid;      }
-    Bool_t IsChargeRelErrNotValid     () const      { return fInfo[1] & kChargeRelErrNotValid;     }
-    Bool_t IsChargeErrNotValid        () const      { return fInfo[1] & kChargeErrNotValid;        }
-    Bool_t IsChargeIsPedestal         () const      { return fInfo[1] & kChargeIsPedestal;         }
-    Bool_t IsLoGainNotFitted          () const      { return fInfo[1] & kLoGainNotFitted;          }
-    Bool_t IsHiGainNotFitted          () const      { return fInfo[1] & kHiGainNotFitted;          }
-    Bool_t IsDeviatingNumPhes         () const      { return fInfo[1] & kDeviatingNumPhes;         }    
+    Bool_t IsLoGainBad() const { return IsUnsuitable  (kUnsuitableRun      )
+				     || IsUncalibrated(kLoGainSaturation   ) 
+				     || IsUncalibrated(kLoGainNotCalibrated) 
+				     || IsUncalibrated(kLoGainOscillating  ) ; }
+    Bool_t IsHiGainBad() const { return IsUnsuitable  (kUnsuitableRun      )
+				     || IsUncalibrated(kHiGainNotCalibrated) 
+  				     || IsUncalibrated(kHiGainOscillating  ) ; }
 
-    
-    Bool_t IsLoGainBad() const { return IsLoGainSaturation() || IsConvHiLoNotValid() || IsLoGainOscillating() ;}
-    Bool_t IsHiGainBad() const { return (IsHiGainSaturation() && IsConvHiLoNotValid()) || IsHiGainOscillating(); }
+    Bool_t IsCalibrationSignalOK() const  { return !( IsUncalibrated(kChargeIsPedestal    )
+					           || IsUncalibrated(kChargeErrNotValid   )
+					           || IsUncalibrated(kChargeRelErrNotValid)
+					           || IsUncalibrated(kChargeSigmaNotValid )
+					           || IsUncalibrated(kMeanTimeInFirstBin  )
+ 					           || IsUncalibrated(kMeanTimeInLast2Bins )  );  }
 
-    Bool_t IsCalibrationSignalOK() const  { return !( IsChargeIsPedestal()
-                                                      || IsChargeErrNotValid()
-                                                      || IsChargeRelErrNotValid()
-                                                      || IsChargeSigmaNotValid()
-                                                      || IsMeanTimeInFirstBin()
-                                                      || IsMeanTimeInLastBin() );  }
-    Bool_t IsCalibrationFitOK()       const    { return !( (!IsHiGainSaturation() && IsHiGainNotFitted())
-                                                      || ( IsHiGainSaturation() && IsLoGainNotFitted()) ); }
-    Bool_t IsCalibrationOscillating() const  { return ( !IsHiGainSaturation() && IsHiGainOscillating()) 
-                                                  || ( IsHiGainSaturation() && IsLoGainOscillating()) ; }
-    Bool_t IsCalibrationResultOK()    const  {  return !IsUnsuitable(kUnsuitableRun) &&
-                                                        IsCalibrationSignalOK()
-                                                    && !IsCalibrationOscillating()
-                                                   && (   (!IsHiGainSaturation() && !IsHiGainBad())
-                                                       || (IsHiGainSaturation() && !IsLoGainBad()) ) ;}
+    Bool_t IsCalibrationResultOK() const  {  return  !IsUnsuitable(kUnsuitableRun) 
+					          &&  IsCalibrationSignalOK()
+                                                  && !IsHiGainBad()
+					          && !IsLoGainBad() ; }
 
     void Merge(const MBadPixelsPix &pix);
Index: /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc	(revision 3600)
+++ /trunk/MagicSoft/Mars/mcalib/MHCalibrationChargeCam.cc	(revision 3601)
@@ -113,15 +113,13 @@
     fLoGainArray->SetOwner();
 
-    fAverageHiGainInnerPix = new MHCalibrationChargeHiGainPix("AverageHiGainInnerPix","Average HiGain FADC sums of inner pixels");
-    fAverageLoGainInnerPix = new MHCalibrationChargeLoGainPix("AverageLoGainInnerPix","Average LoGain FADC sums of inner pixels");
-    fAverageHiGainOuterPix = new MHCalibrationChargeHiGainPix("AverageHiGainOuterPix","Average HiGain FADC sums of outer pixels");
-    fAverageLoGainOuterPix = new MHCalibrationChargeLoGainPix("AverageLoGainOuterPix","Average LoGain FADC sums of outer pixels");
-
-/*
-    fAverageHiGainInnerPix->GetHGausHist()->SetName("HCalibrationChargeAverageInnerHiGainPix");
-    fAverageHiGainOuterPix->GetHGausHist()->SetName("HCalibrationChargeAverageOuterHiGainPix");
-    fAverageLoGainInnerPix->GetHGausHist()->SetName("HCalibrationChargeAverageInnerLoGainPix");
-    fAverageLoGainOuterPix->GetHGausHist()->SetName("HCalibrationChargeAverageOuterLoGainPix");
-*/
+    fAverageHiGainInnerPix = new MHCalibrationChargeHiGainPix("AverageHiGainInnerPix",
+							      "Average HiGain FADC sums of inner pixels");
+    fAverageLoGainInnerPix = new MHCalibrationChargeLoGainPix("AverageLoGainInnerPix",
+							      "Average LoGain FADC sums of inner pixels");
+    fAverageHiGainOuterPix = new MHCalibrationChargeHiGainPix("AverageHiGainOuterPix",
+							      "Average HiGain FADC sums of outer pixels");
+    fAverageLoGainOuterPix = new MHCalibrationChargeLoGainPix("AverageLoGainOuterPix",
+							      "Average LoGain FADC sums of outer pixels");
+
     fAverageHiGainInnerPix->GetHGausHist()->SetTitle("Summed FADC slices average Inner pixels HiGain");
     fAverageLoGainInnerPix->GetHGausHist()->SetTitle("Summed FADC slices average Inner pixels LoGain");
@@ -348,6 +346,7 @@
           if ((*fBadPixels)[i].IsBad())
 	  {
-	      fNumExcluded++;
-	      (*this)[i].SetExcluded();
+	    *fLog << warn << "Excluded pixel: " << i << " from calibration " << endl;
+	    fNumExcluded++;
+	    (*this)[i].SetExcluded();
 	  }
 	  (*this)[i].Init();
@@ -576,4 +575,5 @@
     if (hist.IsEmpty())
       {
+	*fLog << warn << "Empty Hi Gain histogram in pixel: " << pix.GetPixId() << endl;
         bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);        
 	return;
@@ -583,5 +583,4 @@
     {
 	pix.SetHiGainSaturation();
-        bad.SetHiGainSaturation();
 	return;
     }
@@ -597,6 +596,7 @@
         {
           hist.BypassFit();
-          bad.SetHiGainNotFitted();
-          bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
+	  *fLog << warn << "Hi Gain could not be fitted in pixel: " << pix.GetPixId() << endl;
+          bad.SetUncalibrated( MBadPixelsPix::kHiGainNotFitted );
+          bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun   );
         }
 
@@ -627,6 +627,7 @@
     if (!hist.IsFourierSpectrumOK())
       {
-        bad.SetHiGainOscillating();
-        bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
+	*fLog << warn << "Oscillating Hi Gain in pixel: " << pix.GetPixId() << endl;
+	bad.SetUncalibrated( MBadPixelsPix::kHiGainOscillating );
+        bad.SetUnsuitable(   MBadPixelsPix::kUnreliableRun     );
       }
 }
@@ -648,6 +649,6 @@
     {
 	pix.SetLoGainSaturation();
-        bad.SetLoGainSaturation();
-        bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
+	bad.SetUncalibrated( MBadPixelsPix::kLoGainSaturation ); 
+        bad.SetUnsuitable(    MBadPixelsPix::kUnsuitableRun    );
 	return;
     }
@@ -663,5 +664,5 @@
         {
           hist.BypassFit();
-          bad.SetLoGainNotFitted();
+	  bad.SetUncalibrated( MBadPixelsPix::kLoGainNotFitted );
           if (pix.IsHiGainSaturation())
             bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
@@ -697,5 +698,5 @@
     if (!hist.IsFourierSpectrumOK())
       {
-        bad.SetLoGainOscillating();
+        bad.SetUncalibrated( MBadPixelsPix::kLoGainOscillating );
         if (pix.IsHiGainSaturation())
           bad.SetUnsuitable(MBadPixelsPix::kUnreliableRun);
