Index: /trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc
===================================================================
--- /trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc	(revision 5355)
+++ /trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc	(revision 5356)
@@ -107,5 +107,5 @@
 //
 //  Call: 
-//  SetCheckRange(fCheckWinFirst,fCheckWinLast);
+//  SetCheckRange(fCheckWinFirst,fCheckWinLast); 
 //  to set the Window in which a signal is searched
 //
@@ -179,4 +179,5 @@
     : fGeom(NULL), fPedContainerName("MPedestalCam")
 {
+
   fName  = name  ? name  : "MPedCalcFromLoGain";
   fTitle = title ? title : "Task to calculate pedestals from pedestal runs raw data";
@@ -191,4 +192,5 @@
   SetPedestalUpdate(kTRUE);
   Clear();
+
 }
 
@@ -196,11 +198,19 @@
 //
 // Sets:
-// - fNumSamplesTot to 0
 // - fRawEvt to NULL
 // - fRunHeader to NULL
 // - fPedestals to NULL
 //
+// Resets:
+// - fSumx
+// - fSumx2
+// - fSumAB0
+// - fSumAB1
+// - fNumEventsUsed
+// - fTotalCounter
+//
 void MPedCalcFromLoGain::Clear(const Option_t *o)
 {
+
   fRawEvt    = NULL;
   fRunHeader = NULL;
@@ -223,66 +233,57 @@
 //
 // SetCheckRange: 
-//
-// Calls:
-// - MExtractor::SetCheckRange(hifirst,hilast,lofirst,lolast);
-// - SetExtractWindow(fWindowSizeHiGain,fExtractWinSize);
+// 
+// Exits, if the first argument is smaller than 0
+// Exits, if the the last argument is smaller than the first
 //
 void MPedCalcFromLoGain::SetCheckRange(Int_t chfirst, Int_t chlast)
 {
 
-
-  if(chfirst<0){
-    *fLog << warn << GetDescriptor() 
-           << Form(": First slice in window to check for Signal <0, adjust:")<< endl;
-    exit(-1);
-    }
-
-  if(chlast<=chfirst){
-    *fLog << warn << GetDescriptor() 
-    	  << Form(": Last slice in Check window smaller than first slice in window, adjust:")<< endl;
-    exit(-1);
-    }
-
+  if(chfirst<0)
+    {
+      *fLog << warn << GetDescriptor() 
+            << ": First slice in window to check for Signal <0, adjust:" << endl;
+      exit(-1);
+    }
+
+  if(chlast<=chfirst)
+    {
+      *fLog << warn << GetDescriptor() 
+            << ": Last slice in Check window smaller than first slice in window, adjust:" << endl;
+      exit(-1);
+    }
+  
   fCheckWinFirst = chfirst;
   fCheckWinLast = chlast;
 
+}
+
+// --------------------------------------------------------------------------
+//
+// Exits:
+// - if a window is odd
+//
+void MPedCalcFromLoGain::SetExtractWindow(Int_t windowf, Int_t windows)
+{
  
-}
-
-// --------------------------------------------------------------------------
-//
-void MPedCalcFromLoGain::SetMaxSignalVar(Int_t maxvar)
-{
-  fMaxSignalVar = maxvar;
-}
-
-// --------------------------------------------------------------------------
-//
-// Checks:
-// - if a window is odd
-// 
-void MPedCalcFromLoGain::SetExtractWindow(Int_t windowf, Int_t windows)
-{
- 
-  if(windowf<0){
-    *fLog << warn << GetDescriptor() 
-           << Form(": First slice in Extract window has to be >0, adjust:")<< endl;
-    exit(-1);
+  if(windowf<0)
+    {
+      *fLog << warn << GetDescriptor() 
+            << Form(": First slice in Extract window has to be >0, adjust:")<< endl;
+      exit(-1);
     }
  
   Int_t odd  = windows & 0x1;
  
-  if (odd||(windows==0)){
-    *fLog << warn << GetDescriptor() << ": Extract window size has to be even and larger 0, adjust!"<< endl;
-    exit(-1);
-  }
-
-  fExtractWinSize = windows;
+  if (odd||(windows==0))
+    {
+      *fLog << warn << GetDescriptor() << ": Extract window size has to be even and larger 0, adjust!"<< endl;
+      exit(-1);
+    }
+  
+  fExtractWinSize  = windows;
   fExtractWinFirst = windowf;
-  fExtractWinLast = fExtractWinFirst+fExtractWinSize-1;
-
-//
-//  NO RANGE CHECK IMPLEMENTED, YET
-//
+  fExtractWinLast  = fExtractWinFirst+fExtractWinSize-1;
+  
 /*
     const Byte_t availhirange = (fHiGainLast-fHiGainFirst+1) & ~1;
@@ -322,8 +323,9 @@
 // they were not found:
 //
-//  - MPedestalCam
+//  - MPedestalCam with the name fPedContainerName
 //
 Int_t MPedCalcFromLoGain::PreProcess(MParList *pList)
 {
+
     Clear();
 
@@ -362,19 +364,29 @@
 }
 
-// --------------------------------------------------------------------------
-//
-// The ReInit searches for:
-// -  MRawRunHeader::GetNumSamplesHiGain()
-// -  MRawRunHeader::GetNumSamplesLoGain()
-//
-
+// ---------------------------------------------------------------------------------
+//
+// Checks:
+// - if the number of available slices 
+//   (fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1)
+//   is smaller than the number of used slices
+//   (fExtractWinSize+ fExtractWinFirst-1) or 
+//    fCheckWinLast
+//
+// Sets the size (from MPedestalCam::GetSize() ) and resets the following arrays:
+//  - fSumx
+//  - fSumx2
+//  - fSumAB0
+//  - fSumAB1
+//  - fNumEventsUsed
+//  - fTotalCounter
+//
 Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
 {
 
-  Int_t lastavailableslice = (Int_t)fRunHeader->GetNumSamplesHiGain()+(Int_t)fRunHeader->GetNumSamplesLoGain()-1;
-
-  Int_t lastextractslice =  fExtractWinSize+ fExtractWinFirst - 1;
-
-   if ( lastextractslice  > lastavailableslice)//changed to override check
+  Int_t lastavailableslice = (Int_t)fRunHeader->GetNumSamplesHiGain()
+                            +(Int_t)fRunHeader->GetNumSamplesLoGain()-1;
+  Int_t lastextractslice   =  fExtractWinSize+ fExtractWinFirst - 1;
+
+   if ( lastextractslice  > lastavailableslice ) //changed to override check
     {
       *fLog << endl; 
@@ -382,8 +394,8 @@
             << Form(": Selected Extract Window ranges out of the available limits adjust. Last available slice is %2i",
 		    lastavailableslice) << endl;
-      exit(-1);
-    }
-
-  if (  fCheckWinLast  > lastavailableslice)//changed to override check
+      return kFALSE;
+    }
+
+  if ( fCheckWinLast  > lastavailableslice ) //changed to override check
     {
       *fLog << endl; 
@@ -391,5 +403,5 @@
             << Form(": Last Check Window slice is out of the available limits adjust. Last available slice is %2i",
 		    lastavailableslice) << endl;
-      exit(-1);
+      return kFALSE;
     }
 
@@ -420,29 +432,44 @@
 }
 
+// ---------------------------------------------------------------------------------
+//
+// Calculates for pixel "idx":
+//
+// Ped per slice      = sum / n / fExtractWinSize;
+// RMS per slice      = sqrt { (sum2 -  sum*sum/n) / (n-1) / fExtractWinSize }
+// ABOffset per slice = (fSumAB0[idx] - fSumAB1[idx]) / n / fExtractWinSize;
+//
+// Sets fTotalCounter up by 1.
+//
 void MPedCalcFromLoGain::Calc(ULong_t n, UInt_t idx)
 {
-    const ULong_t nsamplestot = n*fExtractWinSize;
-
-    const Float_t sum  = fSumx.At(idx);
-    const Float_t sum2 = fSumx2.At(idx);
-    const Float_t ped  = sum/nsamplestot;
-
-    // 1. Calculate the Variance of the sums:
-    Float_t var = (sum2-sum*sum/n)/(n-1.);
-
-    // 2. Scale the variance to the number of slices:
-    var /= (Float_t)(fExtractWinSize);
-
-    // 3. Calculate the RMS from the Variance:
-    const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
-
-    // 4. Calculate the amplitude of the 150MHz "AB" noise
-    const Float_t abOffs = (fSumAB0[idx] - fSumAB1[idx]) / nsamplestot;
-
-    (*fPedestals)[idx].Set(ped, rms, abOffs, n);
-
-    fTotalCounter[idx]++;
-}
-
+
+  const ULong_t nsamplestot = n*fExtractWinSize;
+  
+  const Float_t sum  = fSumx.At(idx);
+  const Float_t sum2 = fSumx2.At(idx);
+  const Float_t ped  = sum/nsamplestot;
+  
+  // 1. Calculate the Variance of the sums:
+  Float_t var = (sum2-sum*sum/n)/(n-1.);
+
+  // 2. Scale the variance to the number of slices:
+  var /= (Float_t)(fExtractWinSize);
+  
+  // 3. Calculate the RMS from the Variance:
+  const Float_t rms = var<0 ? 0 : TMath::Sqrt(var);
+  
+  // 4. Calculate the amplitude of the 150MHz "AB" noise
+  const Float_t abOffs = (fSumAB0[idx] - fSumAB1[idx]) / nsamplestot;
+  
+  (*fPedestals)[idx].Set(ped, rms, abOffs, n);
+  
+  fTotalCounter[idx]++;
+}
+
+// ---------------------------------------------------------------------------------
+//
+// Returns the pointer to slice "slice".
+//
 UInt_t MPedCalcFromLoGain::GetSlice(MRawEvtPixelIter *pixel, UInt_t slice)
 {
@@ -459,6 +486,6 @@
  else
    {
-    ptr = pixel->GetHiGainSamples();
-    ptr += slice;
+     ptr = pixel->GetHiGainSamples();
+     ptr += slice;
    }
 
@@ -535,5 +562,5 @@
 
         if (!fPedestalUpdate || fNumEventsUsed[idx]<fNumEventsDump)
-            continue;
+          continue;
 
         Calc(fNumEventsDump, idx);
@@ -547,5 +574,5 @@
 
     if (fPedestalUpdate)
-        fPedestals->SetReadyToSave();
+      fPedestals->SetReadyToSave();
 
     return kTRUE;
@@ -560,5 +587,5 @@
     // Compute pedestals and rms from the whole run
     if (fPedestalUpdate)
-        return kTRUE;
+      return kTRUE;
 
     *fLog << flush << inf << "Calculating Pedestals..." << flush;
@@ -566,13 +593,14 @@
     const Int_t npix = fGeom->GetNumPixels();
     for (Int_t idx=0; idx<npix; idx++)
-    {
+      {
         const ULong_t n = fNumEventsUsed[idx];
         if (n>1)
-            Calc(n, idx);
-    }
+          Calc(n, idx);
+      }
 
     fPedestals->SetReadyToSave();
     return kTRUE;
 }
+
 
 Int_t MPedCalcFromLoGain::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
Index: /trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h
===================================================================
--- /trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h	(revision 5355)
+++ /trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h	(revision 5356)
@@ -69,6 +69,6 @@
     void SetCheckRange(Int_t checkfirst=0, Int_t checklast=29);
     void SetExtractWindow(Int_t extractfirst=15, Int_t windowsize=6);
-    void SetMaxSignalVar(Int_t maxvar=0);
-    void SetNumEventsDump(UInt_t dumpevents = 0) {fNumEventsDump = dumpevents;}
+    void SetMaxSignalVar(Int_t maxvar=0)         { fMaxSignalVar = maxvar;    }
+    void SetNumEventsDump(UInt_t dumpevents = 0) { fNumEventsDump = dumpevents;}
     void SetPedestalUpdate(Bool_t pedupdate)  {fPedestalUpdate = pedupdate;}
 
