Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 6839)
+++ trunk/MagicSoft/Mars/Changelog	(revision 6840)
@@ -43,4 +43,28 @@
      mhcalib/MHCalibrationCam.cc:
      - undocummented change
+
+
+
+ 2005/03/16 Markus Gaug
+
+   * msignal/MExtractTimeAndChargeSlidingWindow.cc
+     - fixed a bug in the reading of the resource file (reading of the 
+       MExtractTimeAndCharge resources was skipped).
+
+   * mcalib/MCalibrateData.cc
+     - for the case that the high-gain saturates, but the low-gain signal
+       could not be extracted successfully, take the high-gain signal,
+       multiplied by 1.5 (before, 0 was taken erroneously).
+
+   * msignal/MExtractTimeAndCharge.cc
+     - catch one potential case for memory leaks in the low-gain 
+       calculation. Extract low-gain only if the remaining extraction 
+       window is not smaller than the number of slices needed by the 
+       signal extractor. 
+     - set the default fgLoGainStartShift to -3.5
+
+   * msignal/MExtractTimeAndChargeSpline.[h,cc]
+   * msignal/MExtractTimeAndChargeDigitalFilter.[h,cc]
+     - adjust fLoGainStartShift by one slice, after findings from MC.
 
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 6839)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndCharge.cc	(revision 6840)
@@ -85,5 +85,5 @@
 using namespace std;
 
-const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -4.0; 
+const Float_t MExtractTimeAndCharge::fgLoGainStartShift = -3.5; 
 const Byte_t  MExtractTimeAndCharge::fgLoGainSwitch = 120; 
 // --------------------------------------------------------------------------
@@ -217,5 +217,5 @@
           fLoGainFirstSave = fLoGainFirst;
           const Byte_t logainstart = sathi 
-            ? (sathi > (Int_t)(-fLoGainStartShift) ? sathi + (Int_t)fLoGainStartShift : fLoGainFirst)
+            ? (sathi > (Int_t)(-1*fLoGainStartShift) ? sathi + (Int_t)fLoGainStartShift : fLoGainFirst)
             : (timehi+fLoGainStartShift > 0. ? (Byte_t)(timehi + fLoGainStartShift) : fLoGainFirst);
           fLoGainFirst = logainstart > fLoGainFirstSave ? logainstart : fLoGainFirstSave;
@@ -223,5 +223,5 @@
           // *fLog << err << (Int_t)fLoGainFirst << endl;
 
-          if ( fLoGainFirst < fLoGainLast )
+          if ( fLoGainFirst <= fLoGainLast-fWindowSizeLoGain)
             {
               const Bool_t logainabflag = (higainabflag + pixel.GetNumHiGainSamples()) & 0x1;
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 6839)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 6840)
@@ -70,5 +70,5 @@
 const Byte_t MExtractTimeAndChargeDigitalFilter::fgHiGainFirst             =  0;
 const Byte_t MExtractTimeAndChargeDigitalFilter::fgHiGainLast              = 15;
-const Byte_t MExtractTimeAndChargeDigitalFilter::fgLoGainFirst             =  3;
+const Byte_t MExtractTimeAndChargeDigitalFilter::fgLoGainFirst             =  1;
 const Byte_t MExtractTimeAndChargeDigitalFilter::fgLoGainLast              = 14;
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgWindowSizeHiGain        =  6;
@@ -79,5 +79,6 @@
 const Int_t  MExtractTimeAndChargeDigitalFilter::fgSignalStartBinLoGain    =  4;
 const TString MExtractTimeAndChargeDigitalFilter::fgNameWeightsFile        = "msignal/cosmics_weights.dat";
-const Float_t MExtractTimeAndChargeDigitalFilter::fgOffsetLoGain           = 1.8;   // 5 ns
+const Float_t MExtractTimeAndChargeDigitalFilter::fgOffsetLoGain           =  1.7; // 5 ns
+const Float_t MExtractTimeAndChargeDigitalFilter::fgLoGainStartShift       = -1.8;  
 // --------------------------------------------------------------------------
 //
@@ -104,4 +105,5 @@
     SetNameWeightsFile();
     SetOffsetLoGain(fgOffsetLoGain);
+    SetLoGainStartShift(fgLoGainStartShift);
 }
 
@@ -279,5 +281,5 @@
       if (*p++ >= fSaturationLimit)
         if (!sat)
-          sat = ids-4;
+          sat = ids-3;
     }
 
@@ -311,5 +313,5 @@
           if (*logain++ >= fSaturationLimit)
             if (!sat)
-              sat = ids-4;
+              sat = ids-3;
         }
     }
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 6839)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 6840)
@@ -32,5 +32,6 @@
   static const Int_t  fgSignalStartBinLoGain;    //! Default for fSignalStartBinLoGain (now set to: 4)
   static const TString fgNameWeightsFile;        //! "cosmics_weights.dat"
-  static const Float_t fgOffsetLoGain;           //! Default for fOffsetLoGain (now set to 1.8)
+  static const Float_t fgOffsetLoGain;           //! Default for fOffsetLoGain (now set to 1.7)
+  static const Float_t fgLoGainStartShift;       //! Default for fLoGainStartShift (now set to -1.8)
   
   MArrayF fHiGainSignal;                        //! Need fast access to the signals in a float way
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 6839)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 6840)
@@ -441,6 +441,6 @@
     SetWindowSize(hw, lw);
   
-  return MExtractTime::ReadEnv(env, prefix, print) ? kTRUE : rc;
-
-}
-
+  return MExtractTimeAndCharge::ReadEnv(env, prefix, print) ? kTRUE : rc;
+
+}
+
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 6839)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 6840)
@@ -150,13 +150,14 @@
 using namespace std;
 
-const Byte_t  MExtractTimeAndChargeSpline::fgHiGainFirst    = 2;
-const Byte_t  MExtractTimeAndChargeSpline::fgHiGainLast     = 14;
-const Byte_t  MExtractTimeAndChargeSpline::fgLoGainFirst    = 2;
-const Byte_t  MExtractTimeAndChargeSpline::fgLoGainLast     = 14;
-const Float_t MExtractTimeAndChargeSpline::fgResolution     = 0.05;
-const Float_t MExtractTimeAndChargeSpline::fgRiseTimeHiGain = 0.5;
-const Float_t MExtractTimeAndChargeSpline::fgFallTimeHiGain = 1.5;
-const Float_t MExtractTimeAndChargeSpline::fgLoGainStretch  = 1.5;
-const Float_t MExtractTimeAndChargeSpline::fgOffsetLoGain   = 1.7;   // 5 ns
+const Byte_t  MExtractTimeAndChargeSpline::fgHiGainFirst      = 2;
+const Byte_t  MExtractTimeAndChargeSpline::fgHiGainLast       = 14;
+const Byte_t  MExtractTimeAndChargeSpline::fgLoGainFirst      = 1;
+const Byte_t  MExtractTimeAndChargeSpline::fgLoGainLast       = 14;
+const Float_t MExtractTimeAndChargeSpline::fgResolution       = 0.05;
+const Float_t MExtractTimeAndChargeSpline::fgRiseTimeHiGain   = 0.5;
+const Float_t MExtractTimeAndChargeSpline::fgFallTimeHiGain   = 1.5;
+const Float_t MExtractTimeAndChargeSpline::fgLoGainStretch    = 1.5;
+const Float_t MExtractTimeAndChargeSpline::fgOffsetLoGain     = 1.7;  // 5 ns
+const Float_t MExtractTimeAndChargeSpline::fgLoGainStartShift = -1.8;  
 // --------------------------------------------------------------------------
 //
@@ -184,4 +185,5 @@
   SetLoGainStretch();
   SetOffsetLoGain(fgOffsetLoGain);
+  SetLoGainStartShift(fgLoGainStartShift);
 
   SetRiseTimeHiGain();
@@ -352,5 +354,5 @@
       if (*p++ >= fSaturationLimit)
         if (!sat)
-          sat = ids-2;
+          sat = ids-3;
       
     }
@@ -374,5 +376,5 @@
           if (*logain++ >= fSaturationLimit)
             if (!sat)
-              sat = ids-2;
+              sat = ids-3;
 
           range++;
@@ -718,5 +720,5 @@
   fAbMaxPos     = 0.;
   Int_t  maxpos = 0;
-  Int_t  max    = 0;
+  Int_t  max    = -9999;
 
   //
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h	(revision 6839)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h	(revision 6840)
@@ -16,13 +16,14 @@
 private:
   
-  static const Byte_t  fgHiGainFirst;    //! Default for fHiGainFirst  (now set to: 2)
-  static const Byte_t  fgHiGainLast;     //! Default for fHiGainLast   (now set to: 14)
-  static const Byte_t  fgLoGainFirst;    //! Default for fLoGainFirst  (now set to: 2)
-  static const Byte_t  fgLoGainLast;     //! Default for fLoGainLast   (now set to: 14)
-  static const Float_t fgResolution;     //! Default for fResolution   (now set to: 0.003)
-  static const Float_t fgRiseTimeHiGain; //! Default for fRiseTime     (now set to: 1.5)
-  static const Float_t fgFallTimeHiGain; //! Default for fFallTime     (now set to: 4.5)
-  static const Float_t fgLoGainStretch;  //! Default for fLoGainStretch (now set to: 1.5)
-  static const Float_t fgOffsetLoGain;   //! Default for fOffsetLoGain (now set to 1.7)
+  static const Byte_t  fgHiGainFirst;      //! Default for fHiGainFirst  (now set to: 2)
+  static const Byte_t  fgHiGainLast;       //! Default for fHiGainLast   (now set to: 14)
+  static const Byte_t  fgLoGainFirst;      //! Default for fLoGainFirst  (now set to: 2)
+  static const Byte_t  fgLoGainLast;       //! Default for fLoGainLast   (now set to: 14)
+  static const Float_t fgResolution;       //! Default for fResolution   (now set to: 0.003)
+  static const Float_t fgRiseTimeHiGain;   //! Default for fRiseTime     (now set to: 1.5)
+  static const Float_t fgFallTimeHiGain;   //! Default for fFallTime     (now set to: 4.5)
+  static const Float_t fgLoGainStretch;    //! Default for fLoGainStretch    (now set to: 1.5)
+  static const Float_t fgOffsetLoGain;     //! Default for fOffsetLoGain     (now set to 1.7)
+  static const Float_t fgLoGainStartShift; //! Default for fLoGainStartShift (now set to -1.6)
   
   MArrayF fHiGainSignal;                //! Need fast access to the signals in a float way
