Index: trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 842)
+++ trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 845)
@@ -17,4 +17,5 @@
 !
 !   Author(s): Josep Flix 04/2001 (jflix@ifae.es)
+!              Thomas Bretz 05/2001 (tbretz@uni-sw.gwdg.de)
 !
 !   Copyright: MAGIC Software Development, 2000-2001
@@ -61,8 +62,7 @@
     fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
     if (!fPedestals)
-    {
-        *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
         return kFALSE;
-    }
+
+    fNumHiGainSamples = fRawEvt->GetNumHiGainSamples();
 
     return kTRUE;
@@ -72,68 +72,62 @@
 Bool_t MPedCalcPedRun::Process()
 {
-
     MRawEvtPixelIter pixel(fRawEvt);
-    const Byte_t HiGainSamples = fRawEvt->GetNumHiGainSamples();
 
     while (pixel.Next())
     {
+              Byte_t *ptr = pixel.GetHiGainFadcSamples();
+        const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
+
+        const Float_t higainped = CalcHiGainMean(ptr, end);
+        const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
+
+        const Float_t higainpederr = CalcHiGainMeanErr(higainrms);
+        const Float_t higainrmserr = CalcHiGainRmsErr(higainrms);
+
         const UInt_t pixid = pixel.GetPixelId();
+        MPedestalPix &pix = (*fPedestals)[pixid];
 
-        Byte_t *ptr = pixel.GetHiGainFadcSamples();
-        const Byte_t *end = ptr + HiGainSamples;
-
-        Float_t HiGainPed = PedMeanCalcHiGain(ptr,end,HiGainSamples);
-        Float_t HiGainRms = PedRmsCalcHiGain(ptr,end,HiGainPed,HiGainSamples);
-
-        Float_t HiGainPedErr = PedMeanErrCalcHiGain(HiGainRms,HiGainSamples);
-        Float_t HiGainRmsErr = PedRmsErrCalcHiGain(HiGainRms,HiGainSamples);
-
-        (*fPedestals)[pixid].SetPedestal(HiGainPed,HiGainRms);
-        (*fPedestals)[pixid].SetPedestalRms(HiGainPedErr,HiGainRmsErr);
-
+        pix.SetPedestal(higainped, higainrms);
+        pix.SetPedestalRms(higainpederr, higainrmserr);
     }
 
+    fPedestals->SetHasChanged();
+
     return kTRUE;
+}
 
+Float_t MPedCalcPedRun::CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const
+{
+    Int_t sum=0;
+
+    do sum += *ptr;
+    while (++ptr != end);
+
+    return (Float_t)sum/fNumHiGainSamples;
 }
 
 
+Float_t MPedCalcPedRun::CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const
+{
+    Float_t rms = 0;
 
-Float_t MPedCalcPedRun::PedMeanCalcHiGain(Byte_t *ptr, const Byte_t *end, const Byte_t HiGainSamples)
-{
-    Float_t sum=0;
+    do
+    {
+        const Float_t diff = (Float_t)(*ptr)-higainped;
 
-    do sum += *ptr++;
-    while (ptr != end);
+        rms += diff*diff;
+    } while (++ptr != end);
 
-    sum = sum/(Int_t)HiGainSamples;
-
-    return sum;
+    return sqrt(rms/(fNumHiGainSamples-1));
 }
 
-
-Float_t MPedCalcPedRun::PedRmsCalcHiGain(Byte_t *ptr, const Byte_t *end, Float_t HiGainPed, const Byte_t HiGainSamples)
+Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
 {
-
-  Float_t rms = 0;
-
-  do{
-    rms = rms + (*ptr - HiGainPed)*(*ptr - HiGainPed);
-    *ptr++;
-    }while (ptr != end);
-
-    rms = sqrt((Float_t)rms/((Int_t)HiGainSamples-1));
-
-  return rms;
+    return higainrms/sqrt(fNumHiGainSamples);
 }
 
-
-Float_t MPedCalcPedRun::PedMeanErrCalcHiGain(Float_t HiGainRms, const Byte_t HiGainSamples){
-  return HiGainRms/sqrt((Int_t)HiGainSamples);
+Float_t MPedCalcPedRun::CalcHiGainRmsErr(Float_t higainrms) const
+{
+    return higainrms/sqrt(2.*fNumHiGainSamples);
 }
 
-
-Float_t MPedCalcPedRun::PedRmsErrCalcHiGain(Float_t HiGainRms, const Byte_t HiGainSamples){
-  return HiGainRms/sqrt(2*(Int_t)HiGainSamples);
-}
-
Index: trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h	(revision 842)
+++ trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h	(revision 845)
@@ -19,7 +19,13 @@
 class MPedCalcPedRun : public MTask
 {
+    Byte_t fNumHiGainSamples;
 
     MRawEvtData  *fRawEvt;     // raw event data (time slices)
     MPedestalCam *fPedestals;  // Pedestals of all pixels in the camera
+
+    Float_t CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const;
+    Float_t CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const;
+    Float_t CalcHiGainMeanErr(Float_t higainrms) const;
+    Float_t CalcHiGainRmsErr(Float_t higainrms) const;
 
 public:
@@ -30,9 +36,4 @@
     Bool_t Process();
 
-    Float_t PedMeanCalcHiGain(Byte_t *ptr, const Byte_t *end, const Byte_t HiGainSamples);
-    Float_t PedRmsCalcHiGain(Byte_t *ptr, const Byte_t *end, Float_t HiGainPed, const Byte_t HiGainSamples);
-    Float_t PedMeanErrCalcHiGain(Float_t HiGainRms, const Byte_t HiGainSamples);
-    Float_t PedRmsErrCalcHiGain(Float_t HiGainRms, const Byte_t HiGainSamples);
-
     ClassDef(MPedCalcPedRun, 0)   // Task to calculate pedestals from pedestal runs raw data
 };
