Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 5678)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 5679)
@@ -27,4 +27,9 @@
       - added some new Getter-functions for the calibration conf. 
         pattern
+    * mcalib/MCalibrationChargeCalc.[h,cc]
+    * mcalib/MCalibrationRelTimeCalc.[h,cc]
+    * mcalib/MCalibrationColorSteer.cc
+      - use the new functions
+
 
  2004/12/22 Eva Domingo
Index: /trunk/MagicSoft/Mars/mcalib/MCalibColorSteer.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibColorSteer.cc	(revision 5678)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibColorSteer.cc	(revision 5679)
@@ -51,4 +51,6 @@
 
 #include "MHCalibrationCam.h"
+#include "MCalibrationCam.h"
+#include "MCalibrationBlindCam.h"
 
 #include "MCalibrationIntensityChargeCam.h"
@@ -78,6 +80,5 @@
     : fHeader(NULL), fGeom(NULL), fParList(NULL), 
       fIntensCharge(NULL), fIntensRelTime(NULL), fIntensBad(NULL),
-      fChargeCalc(NULL), fRelTimeCalc(NULL),
-      fPattern(0)
+      fBad(NULL), fChargeCalc(NULL), fRelTimeCalc(NULL), fPattern(0)
 {
 
@@ -135,6 +136,21 @@
   //
   fIntensBad = (MBadPixelsIntensityCam*)pList->FindCreateObj("MBadPixelsIntensityCam");
-
-  *fLog << inf << "Found MBadPixelsIntensityCam ... " << flush;
+  if (fIntensBad)
+    *fLog << inf << "Found MBadPixelsIntensityCam ... " << flush;
+  else
+    return kFALSE;
+  
+  // 
+  // Look for the MBadPixels Intensity Cam
+  //
+  fBad = (MBadPixelsCam*)pList->FindObject("MBadPixelsCam");
+  if (fBad)
+    {
+      *fLog << inf << "Found also MBadPixelsCam ... " << flush;
+      fIntensBad->GetCam()->Merge(*fBad);
+    }
+  else
+    return kFALSE;
+  
   // 
   // Look for the MCalibrationIntensityBlindCam
@@ -142,6 +158,9 @@
   fIntensBlind = (MCalibrationIntensityBlindCam*)pList->FindCreateObj("MCalibrationIntensityBlindCam");
 
-  *fLog << inf << "Found MCalibrationIntensityBlindCam ... " << flush;
-
+  if (fIntensBlind)
+    *fLog << inf << "Found MCalibrationIntensityBlindCam ... " << flush;
+  else
+    return kFALSE;
+  
   // 
   // Look for the MFillH name "FillChargeCam". In case yes, initialize the 
@@ -208,5 +227,5 @@
 //
 // Reads the pattern from MRawEvtHeader and initializes new containers in the 
-// Intensity Cams, if the pattern has changed. Executes CallPostProcess of the 
+// Intensity Cams, if the pattern has changed. Executes Finalize of the 
 // MCalibration*Calc classes in that case.
 //
@@ -214,8 +233,5 @@
 {
 
-  const UInt_t pattern = fHeader->GetCalibrationPattern();
-
-  if (pattern == fPattern)
-    return kTRUE;
+  const UInt_t pattern = fHeader->GetPulserSlotPattern();
 
   if (fPattern == 0)
@@ -225,6 +241,13 @@
     }
 
+  if (pattern == 0 || pattern == fPattern)
+    return kTRUE;
+
+  *fLog << inf << GetDescriptor() << " : old pattern: " << fPattern << flush;
+
   fPattern = pattern;
   
+  *fLog << " : new pattern: " << pattern << flush;
+
   //
   // Finalize Possible calibration histogram classes...
@@ -243,7 +266,7 @@
   *fLog << inf << GetDescriptor() << " : Finalize calibration calculations..." << flush;
   if (fChargeCalc)
-    fChargeCalc->CallPostProcess();
+    fChargeCalc->Finalize();
   if (fRelTimeCalc)
-    fRelTimeCalc->CallPostProcess();
+    fRelTimeCalc->Finalize();
 
   ReInitialize();
@@ -267,4 +290,5 @@
       hist->Finalize();
       hist->ResetHists();
+      hist->SetColor( fHeader->GetPulserColor());
       return kTRUE;
     }
@@ -284,24 +308,41 @@
 
   *fLog << endl;
-  
+
+  TString namep = GetNamePattern();
+
   if (fIntensBad)
     {
-      fIntensBad->AddToList(Form("MBadPixelsCam%s",GetNamePattern()),*fGeom);
-      *fLog << inf << "New MBadPixelsCam with " << GetNamePattern() << endl;
+      fIntensBad->AddToList(Form("MBadPixelsCam%s",namep.Data()),*fGeom);
+      *fLog << inf << "New MBadPixelsCam with " << namep << endl;
+      fIntensBad->GetCam()->Merge(*fBad);
+      *fLog << inf << "Merged new MBadPixelsCam with first of list" << endl;
     }
   if (fIntensCharge)
     {
-      fIntensCharge->AddToList(Form("MCalibrationChargeCam%s",GetNamePattern()),*fGeom);
-      *fLog << inf << "New MCalibrationChargeCam with " << GetNamePattern() << endl;
+      fIntensCharge->AddToList(Form("MCalibrationChargeCam%s",namep.Data()),*fGeom);
+      MCalibrationCam *cam = fIntensCharge->GetCam();
+      cam->SetPulserColor(fHeader->GetPulserColor());
+      *fLog << inf << "New MCalibrationChargeCam with name: " << cam->GetName() << endl;
     }
   if (fIntensQE)
     {
-      fIntensQE->AddToList(Form("MCalibrationQECam%s",GetNamePattern()),*fGeom);
-      *fLog << inf << "New MCalibrationQECam with " << GetNamePattern() << endl;
-    }
+      fIntensQE->AddToList(Form("MCalibrationQECam%s",namep.Data()),*fGeom);
+      *fLog << inf << "New MCalibrationQECam with: " << namep << endl;
+    }
+
   if (fIntensBlind)
     {
-      fIntensBlind->AddToList(Form("MCalibrationBlindCam%s",GetNamePattern()),*fGeom);
-      *fLog << inf << "New MCalibrationBlindCam with " << GetNamePattern() << endl;
+      fIntensBlind->AddToList(Form("MCalibrationBlindCam%s",namep.Data()),*fGeom);
+      MCalibrationCam *cam = fIntensBlind->GetCam();
+      cam->SetPulserColor(fHeader->GetPulserColor());
+      *fLog << inf << "New MCalibrationBlindCam with name: " << cam->GetName() << endl;
+    }
+
+  if (fIntensRelTime)
+    {
+      fIntensRelTime->AddToList(Form("MCalibrationRelTimeCam%s",namep.Data()),*fGeom);
+      MCalibrationCam *cam = fIntensRelTime->GetCam();
+      cam->SetPulserColor(fHeader->GetPulserColor());
+      *fLog << inf << "New MCalibrationRelTimeCam with name: " << cam->GetName() << endl;
     }
 
@@ -310,87 +351,29 @@
 }
 
-const char* MCalibColorSteer::GetNamePattern()
-{
-
-  Float_t number[MCalibrationCam::gkNumPulserColors];
-  memset(number,0,MCalibrationCam::gkNumPulserColors*sizeof(Float_t));
-
-  enum ColorCode_t 
-    {
-      k5LedGreen   = BIT(0 ),
-      k2LedGreen   = BIT(1 ),
-      k5LedBlue2   = BIT(2 ),      
-      k1LedUV      = BIT(3 ),
-      k2LedUV      = BIT(4 ),
-      k5LedBlue3   = BIT(5 ),
-      k5LedBlue4   = BIT(6 ),
-      k2LedBlue    = BIT(7 ),
-      k01LedBlue   = BIT(8 ),
-      k1LedBlue    = BIT(10),
-      k5LedUV1     = BIT(11),
-      k5LedUV2     = BIT(12),
-      k5LedBlue1   = BIT(13),
-      k1LedGreen   = BIT(14),
-      k01LedGreen  = BIT(15),
-      kCT1Pulser   = BIT(16)
-    };
-
-  if (fPattern & k5LedGreen)
-    number[MCalibrationCam::kGREEN] += 5;
-  if (fPattern & k2LedGreen)
-    number[MCalibrationCam::kGREEN] += 2;
-  if (fPattern & k5LedBlue2)
-    number[MCalibrationCam::kBLUE]  += 2;
-  if (fPattern & k1LedUV)           
-    number[MCalibrationCam::kUV]    += 1;
-  if (fPattern & k2LedUV)           
-    number[MCalibrationCam::kUV]    += 2;
-  if (fPattern & k5LedBlue3)        
-    number[MCalibrationCam::kBLUE]  += 5;
-  if (fPattern & k5LedBlue4)        
-    number[MCalibrationCam::kBLUE]  += 5;
-  if (fPattern & k2LedBlue)         
-    number[MCalibrationCam::kBLUE]  += 2;
-  if (fPattern & k01LedBlue)        
-    number[MCalibrationCam::kBLUE]  += 0.5;
-  if (fPattern & k1LedBlue)         
-    number[MCalibrationCam::kBLUE]  += 1;
-  if (fPattern & k5LedUV1)          
-    number[MCalibrationCam::kUV]    += 5;
-  if (fPattern & k5LedUV2)        
-    number[MCalibrationCam::kUV]    += 5;
-  if (fPattern & k5LedBlue1)        
-    number[MCalibrationCam::kBLUE]  += 5;
-  if (fPattern & k1LedGreen)
-    number[MCalibrationCam::kGREEN] += 1;
-  if (fPattern & k01LedGreen)
-    number[MCalibrationCam::kGREEN] += 0.5;
-  if (fPattern & kCT1Pulser)
-    number[MCalibrationCam::kCT1]   += 1;
-
-  TString result;
-  
-  for (Int_t i=0; i<MCalibrationCam::gkNumPulserColors; i++)
-    {
-      switch (i)
-        {
-        case MCalibrationCam::kGREEN:
-          if (number[i] > 0.1)
-            result = Form("%2.1f%s",number[i],"GREEN");
-          break;
-        case MCalibrationCam::kBLUE:
-          if (number[i] > 0.1)
-            result = Form("%2.1f%s",number[i],"BLUE");
-          break;
-        case MCalibrationCam::kUV:
-          if (number[i] > 0.1)
-            result = Form("%2.1f%s",number[i],"UV");
-          break;
-        case MCalibrationCam::kCT1:
-          if (number[i] > 0.1)
-            result = Form("%2.1f%s",number[i],"CT1");
-          break;
-        }
-    }
-  return result.Data();
-}
+TString MCalibColorSteer::GetNamePattern()
+{
+
+  const Float_t strength = fHeader->GetPulserStrength();
+  const MCalibrationCam::PulserColor_t col = fHeader->GetPulserColor();
+
+  TString result = Form("%2.1f",strength);
+  
+  switch (col)
+    {
+    case MCalibrationCam::kCT1:
+      result += "CT1";
+      break;
+    case MCalibrationCam::kGREEN:
+      result += "GREEN";
+      break;
+    case MCalibrationCam::kBLUE:
+      result += "BLUE";
+      break;
+    case MCalibrationCam::kUV:
+      result += "UV";
+      break;
+    default:
+      break;
+    }
+  return result;
+}
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 5678)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 5679)
@@ -239,5 +239,4 @@
 const Float_t MCalibrationChargeCalc::fgFFactorErrLimit        = 4.5;
 const TString MCalibrationChargeCalc::fgNamePedestalCam = "MPedestalCam";
-
 // --------------------------------------------------------------------------
 //
@@ -324,4 +323,6 @@
     fNumInnerFFactorMethodUsed = 0;
 
+    fNumProcessed              = 0;
+
     fIntensBad   = NULL;
     fBadPixels   = NULL;
@@ -337,5 +338,4 @@
     fPedestals   = NULL;
 
-    fPulserPattern = 0;
     SetPulserColor ( MCalibrationCam::kNONE );
     
@@ -355,29 +355,33 @@
 Int_t MCalibrationChargeCalc::PreProcess(MParList *pList)
 {
-    fHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
-    if (!fHeader)
-    {
-        *fLog << err << "MRawEvtHeader not found... abort." << endl;
-        return kFALSE;
-    }
-
-    fSignal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
-    if (!fSignal)
-    {
-        *fLog << err << "MExtractedSignalCam not found... aborting" << endl;
-        return kFALSE;
-    }
-
-    if (fPedestals)
-        return kTRUE;
-
-    fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
-    if (!fPedestals)
-    {
-        *fLog << err << fNamePedestalCam << " not found... aborting" << endl;
-        return kFALSE;
-    }
-
+  
+  fHeader = (MRawEvtHeader*)pList->FindObject("MRawEvtHeader");
+  if (!fHeader)
+    {
+      *fLog << err << "MRawEvtHeader not found... abort." << endl;
+      return kFALSE;
+    }
+
+  // 
+  // Containers that have to be there.
+  //
+  fSignal = (MExtractedSignalCam*)pList->FindObject("MExtractedSignalCam");
+  if (!fSignal)
+    {
+      *fLog << err << "MExtractedSignalCam not found... aborting" << endl;
+      return kFALSE;
+    }
+
+  if (fPedestals)
     return kTRUE;
+
+  fPedestals = (MPedestalCam*)pList->FindObject(AddSerialNumber(fNamePedestalCam), "MPedestalCam");
+  if (!fPedestals)
+    {
+      *fLog << err << GetDescriptor() << fNamePedestalCam << " not found... aborting" << endl;
+      return kFALSE;
+    }
+
+  return kTRUE;
 }
 
@@ -509,11 +513,4 @@
     }
   
-  fNumHiGainSamples  =  fSignal->GetNumUsedHiGainFADCSlices();
-  fNumLoGainSamples  =  fSignal->GetNumUsedLoGainFADCSlices();
-
-  fSqrtHiGainSamples =  TMath::Sqrt(fNumHiGainSamples);
-  fSqrtLoGainSamples =  TMath::Sqrt(fNumLoGainSamples);
-  
-
   MCalibrationQECam     *qecam     = fIntensQE      
     ? (MCalibrationQECam*)    fIntensQE->GetCam()   : fQECam;
@@ -532,7 +529,4 @@
       MBadPixelsPix         &bad = (*badcam)   [i];
       
-      pix.SetPixId(i);
-      pqe.SetPixId(i);
-      
       if (bad.IsBad())
         {
@@ -556,98 +550,52 @@
 {
 
-  const UInt_t pattern = fHeader->GetCalibrationPattern();
-
-  if (pattern == fPulserPattern)
+  const MCalibrationCam::PulserColor_t col = fHeader->GetPulserColor();
+
+  if (col == fPulserColor)
+    {
+      fNumProcessed++;
+      return kTRUE;
+    }
+  
+  if (col == MCalibrationCam::kNONE)
     return kTRUE;
-
-  enum ColorCode_t 
-    {
-      kSlot1Green     = BIT(0),
-      kSlot2Green     = BIT(1),
-      kSlot3Blue      = BIT(2),
-      kSlot4UV        = BIT(3),
-      kSlot5UV        = BIT(4),
-      kSlot6Blue      = BIT(5),
-      kSlot7Blue      = BIT(6),
-      kSlot8Blue      = BIT(7),
-      kSlot9AttBlue   = BIT(8),
-      kSlot10Blue     = BIT(9),
-      kSlot11Blue     = BIT(10),
-      kSlot12UV       = BIT(11),
-      kSlot13UV       = BIT(12),
-      kSlot14Blue     = BIT(13),
-      kSlot15Green    = BIT(14),
-      kSlot16AttGreen = BIT(15),
-      kCT1Pulser      = BIT(16),
-      kAnyGreen       = kSlot1Green  | kSlot2Green | kSlot15Green | kSlot16AttGreen,
-      kAnyUV          = kSlot4UV     | kSlot5UV    | kSlot12UV    | kSlot13UV,
-      kAnyBlue        = kSlot3Blue   | kSlot6Blue  | kSlot7Blue   | kSlot8Blue 
-                      | kSlot9AttBlue| kSlot10Blue | kSlot11Blue  | kSlot14Blue 
-    };
-
-  //
-  // The pattern has changed, we have to initialize everything new!!!
-  //
-  *fLog << inf << GetDescriptor() << "- New pulser pattern: " ;
-  for (Int_t i=16; i>= 0; i--)
-    *fLog << (pattern >> i & 1);
-  *fLog  << endl;
+  
   //
   // Now retrieve the colour and check if not various colours have been used
   //
-  if ((pattern & kAnyBlue   ||
-       pattern & kAnyUV    ||
-       pattern & kAnyGreen ||
-       pattern & kCT1Pulser) && fPulserColor != MCalibrationCam::kNONE)
-  {
-      *fLog << err << "Multiple colours used simultaneously in calibration file. Will reset histograms " 
-            << " and merge the MCalibrationQECam!" << endl;
-      fHCam->Finalize();
-      fHBlindCam->Finalize();
-      fHCam->ResetHists();
-      fHBlindCam->ResetHists();
-      CallPostProcess();
-  }
-
-  fPulserColor   = MCalibrationCam::kNONE;
-  fPulserPattern = pattern;
-  
-  if (fPulserPattern & kAnyGreen)
-    fPulserColor = MCalibrationCam::kGREEN;
-  if (fPulserPattern & kAnyBlue)
-    fPulserColor = MCalibrationCam::kBLUE;
-  if (fPulserPattern & kAnyUV)
-    fPulserColor = MCalibrationCam::kUV;
-  if (fPulserPattern & kCT1Pulser)
-          fPulserColor = MCalibrationCam::kCT1;
+  if (!fIntensCam)
+    {
+      if (fPulserColor != MCalibrationCam::kNONE)
+        {
+          *fLog << err << "Multiple colours used simultaneously in calibration file. Will reset histograms " 
+                << " and merge the MCalibrationQECam!" << endl;
+          fHCam->Finalize();
+          fHBlindCam->Finalize();
+          fHCam->ResetHists();
+          fHBlindCam->ResetHists();
+          Finalize();
+        }
+    }
+  
+  fPulserColor = col;
 
   *fLog << inf << "Found new colour ... " << flush;
   
-  switch (fPulserColor)
-    {
-    case MCalibrationCam::kGREEN: *fLog << "Green.";  break;
-    case MCalibrationCam::kBLUE:  *fLog << "Blue.";   break;
-    case MCalibrationCam::kUV:    *fLog << "UV.";     break;
-    case MCalibrationCam::kCT1:   *fLog << "CT1.";    break;
+  switch (col)
+    {
+    case MCalibrationCam::kGREEN: *fLog << "Green";  break;
+    case MCalibrationCam::kBLUE:  *fLog << "Blue";   break;
+    case MCalibrationCam::kUV:    *fLog << "UV";     break;
+    case MCalibrationCam::kCT1:   *fLog << "CT1";    break;
     default: break;
     }
-  *fLog << endl;
-  
-  MCalibrationBlindCam     *blindcam  = fIntensBlind      
-    ? (MCalibrationBlindCam*) fIntensBlind->GetCam()   : fBlindCam;
-  MCalibrationChargeCam *chargecam = fIntensCam 
-    ? (MCalibrationChargeCam*)fIntensCam->GetCam()  : fCam;
-
-  //
-  // Initialize the pulser colours
-  //
-  chargecam ->SetPulserColor( fPulserColor );
-  blindcam  ->SetPulserColor( fPulserColor );
-  fHCam     ->SetColor      ( fPulserColor );
-  fHBlindCam->SetColor      ( fPulserColor );
-
+
+  *fLog << inf << " with strength: " << fHeader->GetPulserStrength() << endl;
+  
   if (fPINDiode)
     fPINDiode->SetColor( fPulserColor );
-
+  
+  fNumProcessed = 0;
+  
   return kTRUE;
 }
@@ -655,26 +603,28 @@
 // -----------------------------------------------------------------------
 //
-// Analogue to the MTask::CallPostProcess, but without the manipulation 
-// of the bit fIsPreProcessed. Needed in order to call PostProcess multiple 
-// times in the intensity calibration.
-//
-Int_t MCalibrationChargeCalc::CallPostProcess()
+// Return if number of executions is null.
+//
+Int_t MCalibrationChargeCalc::PostProcess()
 {
 
-  //  if (!fIsPreprocessed)
-  //    return kTRUE;
-
-  *fLog << all << fName << "... " << flush;
-  if (fDisplay)
-    fDisplay->SetStatusLine2(*this);
-  
-  return PostProcess();
+  if (GetNumExecutions()==0)
+    return kFALSE;
+
+  if (fPulserColor == MCalibrationCam::kNONE)
+    return kTRUE;
+  
+  if (fNumProcessed == 0)
+    return kTRUE;
+
+  *fLog << endl;
+
+  return Finalize();
 }
 
 // -----------------------------------------------------------------------
 //
-// Return if number of executions is null.
-//
-// First loop over pixels, average areas and sectors, call: 
+// Return kTRUE if fPulserColor is kNONE
+//
+// First loop over pixels, average areas and sectors, call:
 //  - FinalizePedestals() 
 //  - FinalizeCharges()
@@ -700,13 +650,18 @@
 // Print out some statistics
 //
-Int_t MCalibrationChargeCalc::PostProcess()
+Int_t MCalibrationChargeCalc::Finalize()
 {
-  if (GetNumExecutions()==0)
-    return kFALSE;
-
+  
+  fNumHiGainSamples  =  fSignal->GetNumUsedHiGainFADCSlices();
+  fNumLoGainSamples  =  fSignal->GetNumUsedLoGainFADCSlices();
+
+  fSqrtHiGainSamples =  TMath::Sqrt(fNumHiGainSamples);
+  fSqrtLoGainSamples =  TMath::Sqrt(fNumLoGainSamples);
+  
   if (fPINDiode)
     if (!fPINDiode->IsValid())
       {
-        *fLog << warn << "MCalibrationChargePINDiode is declared not valid... no PIN Diode method! " << endl;
+        *fLog << warn << GetDescriptor() 
+              << ": MCalibrationChargePINDiode is declared not valid... no PIN Diode method! " << endl;
         fPINDiode = NULL;
       }
@@ -753,8 +708,8 @@
   if (nvalid == 0)
   {
-      *fLog << err << "All pixels have non-valid calibration. "
+      *fLog << err << GetDescriptor() << ": All pixels have non-valid calibration. " 
 	    << "Did you forget to fill the histograms "
             << "(filling MHCalibrationChargeCam from MExtractedSignalCam using MFillH) ? " << endl;
-      *fLog << err << "Or, maybe, you have used a pedestal run "
+      *fLog << err << GetDescriptor() << ": Or, maybe, you have used a pedestal run " 
             << "instead of a calibration run " << endl;
       return kFALSE;
@@ -770,5 +725,5 @@
       FinalizeCharges(pix, 
                       fIntensCam ? fIntensCam->GetAverageBadArea(aidx) : fCam->GetAverageBadArea(aidx),
-                      "area idx");
+                      "area id");
     }
   
@@ -922,5 +877,5 @@
                       prms    * fSqrtLoGainSamples,
                       prmserr * fSqrtLoGainSamples);
-      cal.CalcLoGainPedestal((Float_t)fNumLoGainSamples);
+      cal.CalcLoGainPedestal(fNumLoGainSamples);
     }
   else
@@ -1006,4 +961,12 @@
     }
 
+  if (cal.GetPheFFactorMethod() < 0.)
+    {
+      bad.SetUncalibrated(MBadPixelsPix::kDeviatingNumPhes);
+      bad.SetUnsuitable(MBadPixelsPix::kUnsuitableRun);
+      cal.SetFFactorMethodValid(kFALSE);
+      return kFALSE;
+    }
+
   if (!cal.CalcConvFFactor())
     {
@@ -1246,4 +1209,13 @@
         }
       
+      if (mean < 0.)
+        {
+          *fLog << inf << GetDescriptor() << ": Fitted mean number of photo-electrons " 
+                << "with area idx " << i << ": " << mean << " is smaller than 0. " << endl;
+          *fLog << warn << GetDescriptor() << ": Will use the simple mean and rms " << endl;          
+          delete hist;
+          continue;
+        }
+      
       *fLog << inf << GetDescriptor() << ": Mean number of photo-electrons " 
             << "with area idx " << i << ": " 
@@ -1350,5 +1322,5 @@
       *fLog << inf << GetDescriptor() 
             << ": Average total number phes in area idx " << aidx << ": " 
-            << Form("%7.2f%s%6.2f",areaphes[aidx]," +- ",TMath::Sqrt(areaweights[aidx])) << endl;
+            << Form("%7.2f +- 6.2f",areaphes[aidx],TMath::Sqrt(areaweights[aidx])) << endl;
                     
       apix.SetPheFFactorMethod   ( areaphes[aidx] );
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 5678)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 5679)
@@ -74,5 +74,4 @@
 
   MCalibrationCam::PulserColor_t fPulserColor; // Calibration LEDs colour 
-  UInt_t  fPulserPattern;                      // Calibration LEDs Pulser Pattern
 
   Int_t   fNumInnerFFactorMethodUsed;          // Number of inner pixels used for F-Factor Method calibration
@@ -86,4 +85,6 @@
   TString fOutputFile;                         // Name of the output file  
   TString fNamePedestalCam;                    // Name of the 'MPedestalCam' container
+
+  Int_t   fNumProcessed;                       // Number of processed events (for Intensity calibration)
   
   // Pointers
@@ -169,7 +170,7 @@
   MCalibrationChargeCalc(const char *name=NULL, const char *title=NULL);
 
-  Int_t CallPostProcess();
-
   void Clear(const Option_t *o="");
+
+  Int_t Finalize();
 
   Bool_t IsDebug() const   {  return TESTBIT(fFlags,kDebug); }
@@ -195,6 +196,7 @@
     b ? SETBIT(fCheckFlags,kCheckOscillations)
       : CLRBIT(fCheckFlags,kCheckOscillations); }
-
-  void SetDebug             ( const Bool_t  b=kTRUE                    ) { b ? SETBIT(fFlags, kDebug) : CLRBIT(fFlags, kDebug); }
+  void SetDebug            ( const Bool_t b=kTRUE ) { 
+    b ? SETBIT(fFlags, kDebug) 
+      : CLRBIT(fFlags, kDebug); }
 
   void SetPedestals(MPedestalCam *cam) { fPedestals=cam; }
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 5678)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.cc	(revision 5679)
@@ -187,6 +187,4 @@
       MBadPixelsPix          &bad =                          (*badcam)[i];
       
-      pix.SetPixId(i);
-      
       if (bad.IsBad())
         {
@@ -204,25 +202,16 @@
 // -----------------------------------------------------------------------
 //
-// Analogue to the MTask::CallPostProcess, but without the manipulation 
-// of the bit fIsPreProcessed. Needed in order to call PostProcess multiple 
-// times in the intensity calibration.
-//
-Int_t MCalibrationRelTimeCalc::CallPostProcess()
-{
-
-  //  if (!fIsPreprocessed)
-  //    return kTRUE;
-
-  *fLog << all << fName << "... " << flush;
-  if (fDisplay)
-    fDisplay->SetStatusLine2(*this);
-  
-  return PostProcess();
-}
-
+// Return if number of executions is null.
+//
+Int_t MCalibrationRelTimeCalc::PostProcess()
+{
+
+  if (GetNumExecutions()==0)
+    return kFALSE;
+
+  return Finalize();
+}
 
 // -----------------------------------------------------------------------
-//
-// Return if number of executions is null.
 //
 // First loop over pixels, average areas and sectors, call: 
@@ -237,10 +226,7 @@
 // Print out some statistics
 //
-Int_t MCalibrationRelTimeCalc::PostProcess()
-{
-
-  if (GetNumExecutions()==0)
-    return kFALSE;
-
+Int_t MCalibrationRelTimeCalc::Finalize()
+{
+  
   //
   // First loop over pixels, call FinalizePedestals and FinalizeRelTimes
Index: /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 5678)
+++ /trunk/MagicSoft/Mars/mcalib/MCalibrationRelTimeCalc.h	(revision 5679)
@@ -64,7 +64,7 @@
   MCalibrationRelTimeCalc(const char *name=NULL, const char *title=NULL);
 
-  Int_t CallPostProcess();
+  void Clear(const Option_t *o="");
   
-  void Clear(const Option_t *o="");
+  Int_t Finalize();
   
   Bool_t IsDebug() const  {  return TESTBIT(fFlags,kDebug); }
