Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 7287)
+++ trunk/MagicSoft/Mars/Changelog	(revision 7288)
@@ -18,4 +18,26 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2005/08/17 Thomas Bretz
+
+   * mcalib/MCalibCalcFromPast.[h,cc]:
+     - reset the number of events fNumEvents in ReInit, because
+       the corresponding histograms get also reset. This prevents
+       the calibration from analysing partly filled histograms
+     - the number of cases in which the fChargeCalc->Finalize fails
+       are counted and written to the console
+     - In PostProcess all histograms and fChargeCalc are reset to 
+       prevent the finalization of the histograms to fit partly filled
+       histograms and fail.
+
+   * mcalib/MCalibrationChargeCalc.h:
+     - added a member function ResetNumProcessed so that MCalibCalcFromPast
+       can 'switch off' the finalization in PostProcess
+
+   * mhcalib/MHCalibrationCam.cc, mhcalib/MHCalibrationChargeCam.cc,
+     mhcalib/MHCalibrationPulseTimeCam.cc:
+     - shortened some console output
+
+
+
  2005/08/16 Thomas Bretz
 
Index: trunk/MagicSoft/Mars/NEWS
===================================================================
--- trunk/MagicSoft/Mars/NEWS	(revision 7287)
+++ trunk/MagicSoft/Mars/NEWS	(revision 7288)
@@ -3,4 +3,15 @@
  *** Version <cvs>
 
+   - callisto: fixed some problems with the calibration in case of
+     inteleaved events. Therefor the final and some intermediate
+     fits are skipped which would take place on partly filled #
+     histograms and gave wrong results or failed completely.
+
+   - callisto: If the intermediate finalization of the histograms
+     calculating the mean charge of the calibration signal fails
+     it is counted now and printed in PostProcess of MCalibCalcFromPast.
+
+   - ganymed: Fixed some bugs which caused problems in On-only mode.
+     Still the false source plot doesn't give reasonable results.
 
 
@@ -22,5 +33,5 @@
    - general: MHillas - the case of CorrXY==0 is now handled properly
 
-   - general: implemnetd the possibility to change the line and
+   - general: implemented the possibility to change the line and
      marker style of a sky-grid drawn by MAstroCatalog
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc	(revision 7287)
+++ trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.cc	(revision 7288)
@@ -93,5 +93,6 @@
       fIntensBad(NULL),
       fChargeCalc(NULL), fRelTimeCalc(NULL), fCalibrate(NULL),
-      fNumCam(0), fNumEvents(0), fUpdateWithFFactorMethod(kTRUE), fUpdateNumPhes(kTRUE)
+    fNumCam(0), fNumEvents(0), fUpdateWithFFactorMethod(kTRUE), fUpdateNumPhes(kTRUE),
+    fNumFails(0)
 {
 
@@ -252,5 +253,26 @@
     }
 
+  fNumFails = 0;
+
   return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Set fNumEvents=0
+//
+// This is necessary because the calibration histograms do reset themself
+// if ReInit is called, so they are empty. MCalibCalcFromPast errornously
+// ignores how many events are in the histograms but count the number
+// itself.
+//
+Bool_t MCalibCalcFromPast::ReInit(MParList *pList)
+{
+    if (fNumEvents>0)
+        *fLog << inf << fNumEvents << " calibration events at the end of the last file have been skipped." << endl;
+
+    fNumEvents = 0;
+
+    return kTRUE;
 }
 
@@ -288,8 +310,11 @@
   if (fChargeCalc)
     {
-      if (!fChargeCalc->Finalize())
-          return kERROR;
-
-      if (fUpdateNumPhes)
+        if (!fChargeCalc->Finalize())
+        {
+            fNumFails++;
+            *fLog << warn << "WARNING - Finalization of charges failed the " << fNumFails << " time..." << endl;
+        }
+
+        if (fUpdateNumPhes)
         {
           MCalibrationChargePix &avpix =(MCalibrationChargePix&)fIntensCharge->GetCam()->GetAverageArea(0);
@@ -336,17 +361,15 @@
 // - MHCalibrationCam::ResetHists()
 //
-Bool_t MCalibCalcFromPast::Finalize(const char* name)
-{
-
-  MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name);
-  if (hist)
-    {
-      hist->Finalize();
-      hist->ResetHists();
-      return kTRUE;
-    }
-
-  return kFALSE;
-  
+Bool_t MCalibCalcFromPast::Finalize(const char* name, Bool_t finalize)
+{
+    MHCalibrationCam *hist = (MHCalibrationCam*)fParList->FindObject(name, "MHCalibrationCam");
+    if (!hist)
+        return kFALSE;
+
+    if (finalize)
+        hist->Finalize();
+
+    hist->ResetHists();
+    return kTRUE;
 }
 
@@ -398,7 +421,26 @@
 Int_t MCalibCalcFromPast::PostProcess()
 {
-  *fLog << inf << "Number of Calibration Cams: " << fNumCam << endl;
-  return kTRUE;
-  
+    if (GetNumExecutions()==0)
+        return kTRUE;
+
+    // Now we reset all histograms to make sure that the PostProcess
+    // of the following tasks doesn't try to finalize a partly empty
+    // histogram!
+    Finalize("MHCalibrationChargeCam",      kFALSE);
+    Finalize("MHCalibrationChargeBlindCam", kFALSE);
+    Finalize("MHCalibrationRelTimeCam",     kFALSE);
+
+    if (fChargeCalc)
+        fChargeCalc->ResetNumProcessed();
+
+    if (fNumCam==0)
+        return kTRUE;
+
+    *fLog << inf << endl;
+    *fLog << GetDescriptor() << " execution statistics:" << endl;
+    *fLog << " " << setw(7) << fNumFails << " (" << Form("%5.1f", 100.*fNumFails/fNumCam) << "%) updates failed." << endl;
+    *fLog << endl;
+
+    return kTRUE;
 }
 
@@ -468,6 +510,4 @@
     }
 
-
-
     return rc;
 }
Index: trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.h	(revision 7287)
+++ trunk/MagicSoft/Mars/mcalib/MCalibCalcFromPast.h	(revision 7288)
@@ -59,12 +59,15 @@
   TArrayF fPhesVar;
 
+  Int_t fNumFails;          //! How often got the update skipped?
+
   // MTask
   Int_t  PreProcess(MParList *pList);
   Int_t  Process();
-  Int_t  PostProcess();  
+  Int_t  PostProcess();
+  Bool_t ReInit(MParList *pList);
 
   // MCalibCalcFromPast
   Bool_t ReInitialize();
-  Bool_t Finalize(const char* name);
+  Bool_t Finalize(const char* name, Bool_t finalize=kTRUE);
 
   Bool_t UpdateMeanPhes();
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 7287)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 7288)
@@ -183,4 +183,6 @@
   void Clear(const Option_t *o="");
 
+  void ResetNumProcessed() { fNumProcessed=0; }
+
   Int_t Finalize();
 
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.cc	(revision 7287)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationCam.cc	(revision 7288)
@@ -1261,5 +1261,5 @@
     {
       *fLog << warn << GetDescriptor()
-	    << ": Only overflow or underflow in hi-gain pixel: " << pix.GetPixId() << endl;
+	    << ": Only over- or underflow in hi-gain pixel: " << pix.GetPixId() << endl;
       return;
     }  
@@ -1353,5 +1353,5 @@
     {
       *fLog << warn << GetDescriptor()
-	    << ": Only overflow or underflow in lo-gain pixel: " << pix.GetPixId() << endl;
+	    << ": Only over- or underflow in lo-gain pixel: " << pix.GetPixId() << endl;
       return;
     }  
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc	(revision 7287)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationChargeCam.cc	(revision 7288)
@@ -1119,28 +1119,29 @@
                                               Byte_t first, Byte_t last)
 {
-  
-  const Float_t mean = hist.GetAbsTimeMean();
-  const Float_t rms  = hist.GetAbsTimeRms();
-
-  pix.SetAbsTimeMean ( mean );
-  pix.SetAbsTimeRms  ( rms  );
-  
-  const Float_t lowerlimit = (Float_t)first + fTimeLowerLimit;
-  const Float_t upperlimit = (Float_t)last  - fTimeUpperLimit;  
-
-  if ( mean < lowerlimit)
-    {
-      *fLog << warn
-            << Form("Mean ArrivalTime: %3.1f < %2.1f slices from lower edge: %2i in pixel %s",
-                    mean,fTimeLowerLimit,(Int_t)first,hist.GetName()) << endl;
-      bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInFirstBin );
-    }
-  
-  if ( mean  > upperlimit )
-    {
-      *fLog << warn
-            << Form("Mean ArrivalTime: %3.1f > %2.1f slices from upper edge: %2i in pixel %s",
-                    mean,fTimeUpperLimit,(Int_t)last,hist.GetName()) << endl;
-      bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInLast2Bins );
+    const Float_t mean = hist.GetAbsTimeMean();
+    const Float_t rms  = hist.GetAbsTimeRms();
+
+    pix.SetAbsTimeMean(mean);
+    pix.SetAbsTimeRms(rms);
+
+    const Float_t lowerlimit = (Float_t)first + fTimeLowerLimit;
+    const Float_t upperlimit = (Float_t)last  - fTimeUpperLimit;
+
+    if (mean<lowerlimit)
+    {
+        *fLog << warn << "Mean Arr.Time: "
+            << Form("%4.1f < %4.1f, %3.1f", mean, TMath::Floor(first)+fTimeLowerLimit, fTimeLowerLimit)
+            << " slices below " << Form("%2i", (Int_t)first) << " in "
+            << hist.GetName() << endl;
+        bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInFirstBin );
+    }
+
+    if (mean>upperlimit)
+    {
+        *fLog << warn << "Mean Arr.Time: "
+            << Form("%4.1f > %4.1f, %3.1f", mean, TMath::Floor(last)-fTimeUpperLimit, fTimeUpperLimit)
+            << " slices above " << Form("%2i", (Int_t)last) << " in "
+            << hist.GetName() << endl;
+        bad.SetUncalibrated( MBadPixelsPix::kMeanTimeInLast2Bins );
     }
 }
Index: trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 7287)
+++ trunk/MagicSoft/Mars/mhcalib/MHCalibrationPulseTimeCam.cc	(revision 7288)
@@ -555,6 +555,5 @@
   if (hist.IsEmpty() || hist.IsOnlyOverflow() || hist.IsOnlyUnderflow())
     {
-      *fLog << warn << GetDescriptor()
-	    << ": Only overflow or underflow in hi-gain pixel: " << hist.GetName() << endl;
+      *fLog << warn << GetDescriptor() << ": Only over- or underflow in " << hist.GetName() << endl;
       return;
     }  
