Index: trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.cc	(revision 8490)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.28 2007-03-05 15:54:55 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MExtractPedestal.cc,v 1.29 2007-05-11 10:25:45 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -21,5 +21,5 @@
 !   Author(s): Thomas Bretz 01/2004 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2006
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -238,5 +238,5 @@
     fSectorFilled.Reset();
     fSectorValid.Reset();
-
+    fNumEventsUsed.Reset();
 }
 
@@ -523,4 +523,6 @@
         fSumAB1.Set(npixels);
 
+        fNumEventsUsed.Set(npixels);
+
         if (fUseSpecialPixels)
         {
@@ -613,9 +615,9 @@
 {
     // This is the fast workaround to put hi- and lo-gains together
-    Byte_t *slices = fSignal->GetSamplesRaw(idx);//pixel.GetSamples();
+    Byte_t *slices = fSignal->GetSamplesRaw(idx);
 
     // Start 'real' work
-    UShort_t max = 0;
-    UShort_t min = (UShort_t)-1;
+    UInt_t max = 0;
+    UInt_t min = (UInt_t)-1;
 
     // Find the maximum and minimum signal per slice in the high gain window
@@ -700,95 +702,62 @@
 }
 
-// --------------------------------------------------------------------------
-//
-//  The following resources are available:
-//    ExtractWindowFirst:    15
-//    ExtractWindowSize:      6
-//    PedestalUpdate:       yes
-//    RandomCalculation:    yes
-//
-Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
-{
-    Bool_t rc=kFALSE;
-
-    // find resource for fUseSpecialPixels
-    if (IsEnvDefined(env, prefix, "UseSpecialPixels", print))
-    {
-        SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels));
-        rc = kTRUE;
-    }
-
-    if (IsEnvDefined(env, prefix, "IntermediateStorage", print))
-    {
-        SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage));
-        rc = kTRUE;
-    }
-
-    // find resource for random calculation
-    if (IsEnvDefined(env, prefix, "RandomCalculation", print))
-    {
-        SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation));
-        rc = kTRUE;
-    }
-
-    // Find resources for ExtractWindow
-    Int_t ef = fExtractWinFirst;
-    Int_t es = fExtractWinSize;
-    if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
-    {
-        ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef);
-        rc = kTRUE;
-    }
-    if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
-    {
-        es = GetEnvValue(env, prefix, "ExtractWinSize", es);
-        rc = kTRUE;
-    }
-
-    SetExtractWindow(ef,es);
-
-    // Find resources for CheckWindow
-    Int_t cfs = fCheckWinFirst;
-    Int_t cls = fCheckWinLast;
-    if (IsEnvDefined(env, prefix, "CheckWinFirst", print))
-    {
-        cfs = GetEnvValue(env, prefix, "CheckWinFirst", cfs);
-        rc = kTRUE;
-    }
-    if (IsEnvDefined(env, prefix, "CheckWinLast", print))
-    {
-        cls = GetEnvValue(env, prefix, "CheckWinLast", cls);
-        rc = kTRUE;
-    }
-
-    SetCheckRange(cfs,cls);
-
-    // find resource for maximum signal variation
-    if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
-    {
-        SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar));
-        rc = kTRUE;
-    }
-
-    // find resource for MPedestalCam
-    if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
-    {
-        SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn));
-        rc = kTRUE;
-    }
-
-    if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
-    {
-        SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter));
-        rc = kTRUE;
-    }
-
-    if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
-    {
-        SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut));
-        rc = kTRUE;
-    }
-
-    return rc;
+// ---------------------------------------------------------------------------------
+//
+// Check for the variation of the pixel. Return kFALSE if this pixel
+// should not be used.
+// Calculate the pedestal either with the extractor or by summing slices.
+// And update all arrays.
+//
+Bool_t MExtractPedestal::CalcPixel(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t usespecialpixels)
+{
+    const UInt_t idx = pixel.GetPixelId();
+    if (!CheckVariation(idx))
+        return kFALSE;
+
+    //extract pedestal
+    UInt_t ab[2];
+    const Float_t sum = fExtractor ?
+        CalcExtractor(pixel, offset) :
+        CalcSums(pixel, offset, ab[0], ab[1]);
+
+    fNumEventsUsed[idx]++;
+
+    if (fIntermediateStorage)
+        (*fPedestalsInter)[idx].Set(sum, 0, 0, fNumEventsUsed[idx]);
+
+    const Float_t sqrsum = sum*sum;
+
+    fSumx[idx]  += sum;
+    fSumx2[idx] += sqrsum;
+
+    if (!fExtractor && pixel.IsABFlagValid())
+    {
+        fSumAB0[idx] += ab[0];
+        fSumAB1[idx] += ab[1];
+    }
+
+    if (usespecialpixels)
+        return kTRUE;
+
+    const UInt_t aidx   = (*fGeom)[idx].GetAidx();
+    const UInt_t sector = (*fGeom)[idx].GetSector();
+
+    fAreaFilled[aidx]++;
+    fSectorFilled[sector]++;
+
+    fAreaSumx[aidx]      += sum;
+    fAreaSumx2[aidx]     += sqrsum;
+    fSectorSumx[sector]  += sum;
+    fSectorSumx2[sector] += sqrsum;
+
+    if (!fExtractor && pixel.IsABFlagValid())
+    {
+        fAreaSumAB0[aidx]   += ab[0];
+        fAreaSumAB1[aidx]   += ab[1];
+        fSectorSumAB0[aidx] += ab[0];
+        fSectorSumAB1[aidx] += ab[1];
+    }
+
+    return kTRUE;
 }
 
@@ -803,6 +772,10 @@
 // Stores the results in MPedestalCam[pixid]
 //
-void MExtractPedestal::CalcPixResults(const UInt_t nevts, const UInt_t pixid)
-{
+void MExtractPedestal::CalcPixResults(const UInt_t pixid)
+{
+    const UInt_t  nevts = fNumEventsUsed[pixid];
+    if (nevts<2)
+        return;
+
     const Double_t sum  = fSumx[pixid];
     const Double_t sum2 = fSumx2[pixid];
@@ -843,6 +816,14 @@
 // Stores the results in MPedestalCam::GetAverageArea(aidx)
 //
-void MExtractPedestal::CalcAreaResults(const UInt_t nevts, const UInt_t napix, const UInt_t aidx)
-{
+void MExtractPedestal::CalcAreaResults(const UInt_t aidx)
+{
+    const UInt_t nevts = fAreaFilled[aidx];
+    if (nevts<2)
+        return;
+
+    const UInt_t napix = fAreaValid[aidx];
+    if (napix<1)
+        return;
+
     const Double_t sum  = fAreaSumx[aidx];
     const Double_t sum2 = fAreaSumx2[aidx];
@@ -888,6 +869,14 @@
 // Stores the results in MPedestalCam::GetAverageSector(sector)
 //
-void MExtractPedestal::CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector)
-{
+void MExtractPedestal::CalcSectorResults(const UInt_t sector)
+{
+    const UInt_t nevts = fSectorFilled[sector];
+    if (nevts<2)
+        return;
+
+    const UInt_t nspix = fSectorValid[sector];
+    if (nspix<1)
+        return;
+
     const Double_t sum  = fSectorSumx[sector];
     const Double_t sum2 = fSectorSumx2[sector];
@@ -923,4 +912,34 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Loop over the pixels to get the averaged pedestal
+//
+void MExtractPedestal::CalcPixResult()
+{
+    for (UInt_t idx=0; idx<fNumEventsUsed.GetSize(); idx++)
+        CalcPixResults(idx);
+}
+
+// --------------------------------------------------------------------------
+//
+// Loop over the sector indices to get the averaged pedestal per sector
+//
+void MExtractPedestal::CalcSectorResult()
+{
+    for (UInt_t sector=0; sector<fSectorFilled.GetSize(); sector++)
+        CalcSectorResults(sector);
+}
+
+// --------------------------------------------------------------------------
+//
+// Loop over the (two) area indices to get the averaged pedestal per aidx
+//
+void MExtractPedestal::CalcAreaResult()
+{
+    for (UInt_t aidx=0; aidx<fAreaFilled.GetSize(); aidx++)
+        CalcAreaResults(aidx);
+}
+
 //-----------------------------------------------------------------------
 //
@@ -942,2 +961,96 @@
     *fLog << "Max.allowed signal variation: " << fMaxSignalVar << endl;
 }
+
+// --------------------------------------------------------------------------
+//
+//  The following resources are available:
+//    ExtractWindowFirst:    15
+//    ExtractWindowSize:      6
+//    PedestalUpdate:       yes
+//    RandomCalculation:    yes
+//
+Int_t MExtractPedestal::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc=kFALSE;
+
+    // find resource for fUseSpecialPixels
+    if (IsEnvDefined(env, prefix, "UseSpecialPixels", print))
+    {
+        SetUseSpecialPixels(GetEnvValue(env, prefix, "UseSpecialPixels", fUseSpecialPixels));
+        rc = kTRUE;
+    }
+
+    if (IsEnvDefined(env, prefix, "IntermediateStorage", print))
+    {
+        SetIntermediateStorage(GetEnvValue(env, prefix, "IntermediateStorage", fIntermediateStorage));
+        rc = kTRUE;
+    }
+
+    // find resource for random calculation
+    if (IsEnvDefined(env, prefix, "RandomCalculation", print))
+    {
+        SetRandomCalculation(GetEnvValue(env, prefix, "RandomCalculation", fRandomCalculation));
+        rc = kTRUE;
+    }
+
+    // Find resources for ExtractWindow
+    Int_t ef = fExtractWinFirst;
+    Int_t es = fExtractWinSize;
+    if (IsEnvDefined(env, prefix, "ExtractWinFirst", print))
+    {
+        ef = GetEnvValue(env, prefix, "ExtractWinFirst", ef);
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "ExtractWinSize", print))
+    {
+        es = GetEnvValue(env, prefix, "ExtractWinSize", es);
+        rc = kTRUE;
+    }
+
+    SetExtractWindow(ef,es);
+
+    // Find resources for CheckWindow
+    Int_t cfs = fCheckWinFirst;
+    Int_t cls = fCheckWinLast;
+    if (IsEnvDefined(env, prefix, "CheckWinFirst", print))
+    {
+        cfs = GetEnvValue(env, prefix, "CheckWinFirst", cfs);
+        rc = kTRUE;
+    }
+    if (IsEnvDefined(env, prefix, "CheckWinLast", print))
+    {
+        cls = GetEnvValue(env, prefix, "CheckWinLast", cls);
+        rc = kTRUE;
+    }
+
+    SetCheckRange(cfs,cls);
+
+    // find resource for maximum signal variation
+    if (IsEnvDefined(env, prefix, "MaxSignalVar", print))
+    {
+        SetMaxSignalVar(GetEnvValue(env, prefix, "MaxSignalVar", fMaxSignalVar));
+        rc = kTRUE;
+    }
+
+    // find resource for MPedestalCam
+    if (IsEnvDefined(env, prefix, "NamePedestalCamIn", print))
+    {
+        SetNamePedestalCamIn(GetEnvValue(env, prefix, "NamePedestalCamIn", fNamePedestalCamIn));
+        rc = kTRUE;
+    }
+
+    if (IsEnvDefined(env, prefix, "NamePedestalCamInter", print))
+    {
+        SetNamePedestalCamInter(GetEnvValue(env, prefix, "NamePedestalCamInter", fNamePedestalCamInter));
+        rc = kTRUE;
+    }
+
+    if (IsEnvDefined(env, prefix, "NamePedestalCamOut", print))
+    {
+        SetNamePedestalCamOut(GetEnvValue(env, prefix, "NamePedestalCamOut", fNamePedestalCamOut));
+        rc = kTRUE;
+    }
+
+    return rc;
+}
+
Index: trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MExtractPedestal.h	(revision 8490)
@@ -40,7 +40,11 @@
 
   Bool_t  fRandomCalculation;        // Is pedestalextraction by extractor random?
-  
+
+  // Helper functions
+  void CalcAreaResults(const UInt_t aidx);
+  void CalcSectorResults(const UInt_t sector);
+
 protected:
-  
+
   Bool_t  fIntermediateStorage;      // Is pedestal stored every event?
 
@@ -53,5 +57,5 @@
   MExtractTimeAndCharge *fExtractor; //  Possible Extractor
   MPedestalSubtractedEvt *fSignal;   //!
-  
+
   UShort_t fExtractWinFirst;         // First FADC slice to extract pedestal from
   UShort_t fExtractWinSize;          // Number of slices to calculate the pedestal from
@@ -82,4 +86,6 @@
   MArrayI fSectorValid;              // number of valid pixels within sector idx
 
+  MArrayI fNumEventsUsed;            // Number of events used for pedestal calc for each pixel
+
   // MTask virtual functions
   Int_t  PreProcess(MParList *pList);
@@ -94,8 +100,11 @@
 
   // Helper functions
-  void CalcPixResults   (const UInt_t nevts, const UInt_t pixid);
-  void CalcAreaResults  (const UInt_t nevts, const UInt_t napix, const UInt_t aidx);
-  void CalcSectorResults(const UInt_t nevts, const UInt_t nspix, const UInt_t sector);
+  void CalcPixResults(const UInt_t pixid);
 
+  void CalcPixResult();
+  void CalcSectorResult();
+  void CalcAreaResult();
+
+  Bool_t  CalcPixel(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t usespecialpixels=kFALSE);
   Float_t CalcExtractor(const MRawEvtPixelIter &pixel, Int_t offset) const;
   UInt_t  CalcSums(const MRawEvtPixelIter &pixel, Int_t offset, UInt_t &ab0, UInt_t &ab1) const;
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.cc	(revision 8490)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MPedCalcFromLoGain.cc,v 1.37 2007-03-04 12:00:30 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MPedCalcFromLoGain.cc,v 1.38 2007-05-11 10:25:45 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -26,5 +26,5 @@
 !   Author(s): Nepomuk Otte 10/2004 <mailto:otte@mppmu.mpg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2006
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -145,12 +145,5 @@
 #include "MRawEvtPixelIter.h"
 
-#include "MPedestalPix.h"
 #include "MPedestalCam.h"
-
-#include "MGeomPix.h"
-#include "MGeomCam.h"
-
-#include "MExtractPedestal.h"
-#include "MPedestalSubtractedEvt.h"
 
 ClassImp(MPedCalcFromLoGain);
@@ -177,17 +170,4 @@
     SetPedestalUpdate(kTRUE);
     SetNumDump();
-}
-
-// --------------------------------------------------------------------------
-//
-// Call MExtractPedestl::ResetArrays aand reset fNumAventsUsed and
-// fTotalCounter
-//
-void MPedCalcFromLoGain::ResetArrays()
-{
-    MExtractPedestal::ResetArrays();
-
-    fNumEventsUsed.Reset();
-    fTotalCounter.Reset();
 }
 
@@ -203,12 +183,4 @@
 Bool_t MPedCalcFromLoGain::ReInit(MParList *pList)
 {
-    // If the size is not yet set, set the size
-    if (fSumx.GetSize()==0)
-    {
-        const Int_t npixels = fPedestalsOut->GetSize();
-        fNumEventsUsed.Set(npixels);
-        fTotalCounter.Set(npixels);
-    }
-
     if (!MExtractPedestal::ReInit(pList))
         return kFALSE;
@@ -232,53 +204,18 @@
     const Int_t nlo = fRunHeader->GetNumSamplesLoGain();
 
+    const Int_t offset = nlo>0?nhi:0;
+
     // Real Process
     MRawEvtPixelIter pixel(fRawEvt);
     while (pixel.Next())
     {
+        if (!CalcPixel(pixel, offset))
+            continue;
+
         const UInt_t idx = pixel.GetPixelId();
-
-        if (!CheckVariation(idx))
-            continue;
-
-        //extract pedestal
-        UInt_t ab[2];
-        const Float_t sum = fExtractor ?
-            CalcExtractor(pixel, nlo>0?nhi:0) :
-            CalcSums(pixel, nlo>0?nhi:0, ab[0], ab[1]);
-
-        const UInt_t aidx   = (*fGeom)[idx].GetAidx();
-        const UInt_t sector = (*fGeom)[idx].GetSector();
-
-        const Float_t sqrsum = sum*sum;
-
-        fSumx[idx]           += sum;
-        fSumx2[idx]          += sqrsum;
-        fAreaSumx[aidx]      += sum;
-        fAreaSumx2[aidx]     += sqrsum;
-        fSectorSumx[sector]  += sum;
-        fSectorSumx2[sector] += sqrsum;
-
-        if (fIntermediateStorage)
-            (*fPedestalsInter)[idx].Set(sum, 0, 0, fNumEventsUsed[idx]);
-
-        fNumEventsUsed[idx]   ++;
-        fAreaFilled   [aidx]  ++;
-        fSectorFilled [sector]++;
-
-        if (!fExtractor && pixel.IsABFlagValid())
-        {
-            fSumAB0[idx]        += ab[0];
-            fSumAB1[idx]        += ab[1];
-            fAreaSumAB0[aidx]   += ab[0];
-            fAreaSumAB1[aidx]   += ab[1];
-            fSectorSumAB0[aidx] += ab[0];
-            fSectorSumAB1[aidx] += ab[1];
-        }
-
         if (!fPedestalUpdate || (UInt_t)fNumEventsUsed[idx]<fNumEventsDump)
             continue;
 
-        CalcPixResults(fNumEventsDump, idx);
-        fTotalCounter[idx]++;
+        CalcPixResults(idx);
 
         fNumEventsUsed[idx]=0;
@@ -289,9 +226,15 @@
     }
 
-    if (!(GetNumExecutions() % fNumAreasDump))
+    if (fNumAreasDump>0 && !(GetNumExecutions() % fNumAreasDump))
+    {
         CalcAreaResult();
-
-    if (!(GetNumExecutions() % fNumSectorsDump))
+        fAreaFilled.Reset();
+    }
+
+    if (fNumSectorsDump>0 && !(GetNumExecutions() % fNumSectorsDump))
+    {
         CalcSectorResult();
+        fSectorFilled.Reset();
+    }
 
     if (fPedestalUpdate)
@@ -299,27 +242,4 @@
 
   return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Loop over the sector indices to get the averaged pedestal per sector
-//
-void MPedCalcFromLoGain::CalcSectorResult()
-{
-    for (UInt_t sector=0; sector<fSectorFilled.GetSize(); sector++)
-        if (fSectorValid[sector]>0)
-            CalcSectorResults(fSectorFilled[sector], fSectorValid[sector], sector);
-}
-
-// --------------------------------------------------------------------------
-//
-// Loop over the (two) area indices to get the averaged pedestal per aidx
-//
-void MPedCalcFromLoGain::CalcAreaResult()
-{
-    for (UInt_t aidx=0; aidx<fAreaFilled.GetSize(); aidx++)
-        if (fAreaValid[aidx]>0)
-            CalcAreaResults(fAreaFilled[aidx], fAreaValid[aidx], aidx);
-
 }
 
@@ -336,15 +256,5 @@
     *fLog << flush << inf << "Calculating Pedestals..." << flush;
 
-    const Int_t npix = fGeom->GetNumPixels();
-    for (Int_t idx=0; idx<npix; idx++)
-    {
-        const ULong_t n = fNumEventsUsed[idx];
-        if (n>1)
-        {
-            CalcPixResults(n, idx);
-            fTotalCounter[idx]++;
-        }
-    }
-
+    CalcPixResult();
     CalcAreaResult();
     CalcSectorResult();
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcFromLoGain.h	(revision 8490)
@@ -4,8 +4,4 @@
 #ifndef MARS_MExtractPedestal
 #include "MExtractPedestal.h"
-#endif
-
-#ifndef ROOT_TArrayI
-#include <TArrayI.h>
 #endif
 
@@ -28,7 +24,4 @@
     UInt_t  fNumSectorsDump;           // Number of events after which averaged sectors gets updated
 
-    TArrayI fNumEventsUsed;      //! Number of events used for pedestal calc for each pixel
-    TArrayI fTotalCounter;       //! Counter for dumping values to Pedestal Container
-
     Bool_t  fPedestalUpdate;           // Flag if the pedestal shall be updated after every fNumEventsDump
 
@@ -43,17 +36,8 @@
     Int_t  Calc();
 
-    //Helper function to extract slice values by slice number
-    //void CalcExtractor(const MRawEvtPixelIter &pixel, Float_t &sum, MPedestalPix &ped);
-    void ResetArrays();
-
-    void CalcSectorResult();
-    void CalcAreaResult();
-
 public:
     MPedCalcFromLoGain(const char *name=NULL, const char *title=NULL);
 
     // Getters
-    TArrayI *GetNumEventsUsed() { return &fNumEventsUsed; }
-
     void SetNumEventsDump (UInt_t dumpevents=fgNumDump)  { fNumEventsDump  = dumpevents; }
     void SetNumAreasDump  (UInt_t dumpevents=fgNumDump)  { fNumAreasDump   = dumpevents; }
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 8490)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MPedCalcPedRun.cc,v 1.50 2007-02-03 20:03:35 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MPedCalcPedRun.cc,v 1.51 2007-05-11 10:25:45 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -24,5 +24,5 @@
 !   Author(s): Markus Gaug 01/2004 <mailto:markus@ifae.es>
 !
-!   Copyright: MAGIC Software Development, 2000-2006
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -127,17 +127,8 @@
 #include "MLogManip.h"
 
-#include "MRawRunHeader.h"  
-#include "MRawEvtHeader.h"  
+#include "MRawRunHeader.h"
 #include "MRawEvtPixelIter.h"
-#include "MRawEvtData.h"
-
-#include "MPedestalPix.h"
+
 #include "MPedestalCam.h"
-
-#include "MGeomPix.h"
-#include "MGeomCam.h"
-
-#include "MExtractPedestal.h"
-#include "MPedestalSubtractedEvt.h"
 
 #include "MTriggerPattern.h"
@@ -160,5 +151,5 @@
 //
 MPedCalcPedRun::MPedCalcPedRun(const char *name, const char *title)
-    : fIsFirstPedRun(kFALSE), fUsedEvents(0), fTrigPattern(NULL)
+    : fIsFirstPedRun(kFALSE), fTrigPattern(NULL)
 {
     fName  = name  ? name  : "MPedCalcPedRun";
@@ -170,10 +161,9 @@
 // --------------------------------------------------------------------------
 //
-// Call MExtractPedestal::reset and set fUsedEvents to 0.
+// Call MExtractPedestal::ResetArrays
 //
 void MPedCalcPedRun::Reset()
 {
     MExtractPedestal::ResetArrays();
-    fUsedEvents = 0;
 }
 
@@ -184,5 +174,4 @@
 Int_t MPedCalcPedRun::PreProcess(MParList *pList)
 {
-    fUsedEvents    = 0;
     fIsFirstPedRun = kTRUE;
     fIsNotPedRun   = kFALSE;
@@ -272,47 +261,7 @@
         return kTRUE;
 
-    fUsedEvents++;
-
     MRawEvtPixelIter pixel(fRawEvt);
     while (pixel.Next())
-    {
-        const UInt_t idx = pixel.GetPixelId();
-
-        if (!CheckVariation(idx))
-            continue;
-
-        //extract pedestal
-        UInt_t ab[2];
-        const Float_t sum = fExtractor ?
-            CalcExtractor(pixel, 0) :
-            CalcSums(pixel, 0, ab[0], ab[1]);
-
-        if (fIntermediateStorage)
-            (*fPedestalsInter)[idx].Set(sum, 0, 0, fUsedEvents);
-
-        const Float_t sqrsum = sum*sum;
-
-        fSumx[idx]   += sum;
-        fSumx2[idx]  += sqrsum;
-
-        fSumAB0[idx] += ab[0];
-        fSumAB1[idx] += ab[1];
-
-        if (fUseSpecialPixels)
-            continue;
-
-        const UInt_t aidx   = (*fGeom)[idx].GetAidx();
-        const UInt_t sector = (*fGeom)[idx].GetSector();
-
-        fAreaSumx[aidx]      += sum;
-        fAreaSumx2[aidx]     += sqrsum;
-        fSectorSumx[sector]  += sum;
-        fSectorSumx2[sector] += sqrsum;
-
-        fAreaSumAB0[aidx]    += ab[0];
-        fAreaSumAB1[aidx]    += ab[1];
-        fSectorSumAB0[aidx]  += ab[0];
-        fSectorSumAB1[aidx]  += ab[1];
-    }
+        CalcPixel(pixel, 0, fUseSpecialPixels);
 
     fPedestalsOut->SetReadyToSave();
@@ -327,7 +276,4 @@
 Int_t MPedCalcPedRun::Finalize()
 {
-    if (fUsedEvents == 0)
-        return kTRUE;
-
     //
     // Necessary check for extraction of special pixels
@@ -337,27 +283,13 @@
         return kTRUE;
 
-    MRawEvtPixelIter pixel(fRawEvt);
-    while (pixel.Next())
-        CalcPixResults(fUsedEvents, pixel.GetPixelId());
+    CalcPixResult();
 
     if (!fUseSpecialPixels)
     {
-
-        //
-        // Loop over the (two) area indices to get the averaged pedestal per aidx
-        //
-        for (UInt_t aidx=0; aidx<fAreaValid.GetSize(); aidx++)
-            if (fAreaValid[aidx]>0)
-                CalcAreaResults(fUsedEvents, fAreaValid[aidx], aidx);
-
-        //
-        // Loop over the (six) sector indices to get the averaged pedestal per sector
-        //
-        for (UInt_t sector=0; sector<fSectorValid.GetSize(); sector++)
-            if (fSectorValid[sector]>0)
-                CalcSectorResults(fUsedEvents, fSectorValid[sector], sector);
+        CalcAreaResult();
+        CalcSectorResult();
     }
 
-    fPedestalsOut->SetTotalEntries(fUsedEvents*fExtractWinSize);
+    fPedestalsOut->SetNumSlices(fExtractWinSize);
     fPedestalsOut->SetReadyToSave();
 
@@ -405,4 +337,3 @@
 
     *fLog << "First pedrun out of sequence: " << (fIsFirstPedRun?"yes":"no") << endl;
-    *fLog << "Number of used events so far: " << fUsedEvents << endl;
-}
+}
Index: trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h	(revision 8490)
@@ -18,5 +18,4 @@
     Bool_t  fIsFirstPedRun;    //! Flag to tell if the first run out of many is used
     Bool_t  fIsNotPedRun;      //! Flag to tell if the current run is a pedestal run
-    UInt_t  fUsedEvents;       // Number of used (not skipped) events
 
     MTriggerPattern *fTrigPattern;  //! Trigger pattern decoded
Index: trunk/MagicSoft/Mars/mpedestal/MPedestalCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedestalCam.cc	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MPedestalCam.cc	(revision 8490)
@@ -20,5 +20,5 @@
 !   Author(s): Florian Goebel 06/2004 <mailto:fgoebel@mppmu.mpg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Copyright: MAGIC Software Development, 2000-2007
 !
 !
@@ -26,9 +26,14 @@
 
 /////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MPedestalCam                                                            //
-//                                                                         //
-// Hold the Pedestal information for all pixels in the camera              //
-//                                                                         //
+//
+// MPedestalCam
+//
+// Hold the Pedestal information for all pixels in the camera
+//
+// Class Version 2:
+// ----------------
+//  + fNumSlices
+//  - fTotalEntries
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MPedestalCam.h"
@@ -73,9 +78,9 @@
 //
 MPedestalCam::MPedestalCam(const char *name, const char *title) 
-    : fTotalEntries(0)
+    : fNumSlices(0)
 {
   fName  = name  ? name  : "MPedestalCam";
   fTitle = title ? title : "Storage container for all Pedestal Information in the camera";
-  
+
   fArray            = new TClonesArray("MPedestalPix", 1);
   fAverageAreas     = new TClonesArray("MPedestalPix", 1);
@@ -107,10 +112,10 @@
 
   MPedestalCam &cam = (MPedestalCam&)obj;
-  
+
   Int_t n = GetSize();
-  
+
   if (n==0)
     return;
-  
+
   cam.InitSize(n);
   for (int i=0; i<n; i++)
@@ -272,6 +277,6 @@
     { fAverageAreas->R__FOR_EACH(TObject, Clear)(); }
     { fAverageSectors->R__FOR_EACH(TObject, Clear)(); }
-  
-    fTotalEntries = 0;
+
+    fNumSlices = 0;
 }
 
@@ -512,16 +517,16 @@
       if (bad && (*bad)[i].IsUnsuitable(MBadPixelsPix::kUnsuitableRun))
         continue;
-      
+
       const UInt_t sector = geom[i].GetSector();
-      
+
       if (sec != sector)
         continue;
 
       const MPedestalPix &pix = (*this)[i];
-      
+
       rms  += pix.GetPedestalRms();
       rms2 += pix.GetPedestalRms()*pix.GetPedestalRms();
       nr   ++;
-      
+
     }
 
@@ -530,5 +535,4 @@
   arr[1] = nr>1 ? TMath::Sqrt((rms2 - rms*rms/nr)/(nr-1)) : 0;
   return arr;
-  
 }
 
@@ -542,6 +546,6 @@
         return kFALSE;
 
-    const Float_t ped      = (*this)[idx].GetPedestal();
-    const Float_t rms      = (*this)[idx].GetPedestalRms();
+    const Float_t ped = (*this)[idx].GetPedestal();
+    const Float_t rms = (*this)[idx].GetPedestalRms();
 
     switch (type)
@@ -551,7 +555,7 @@
         break;
     case 1:
-        val = fTotalEntries > 0 ?
-            rms/TMath::Sqrt((Float_t)fTotalEntries)
-          : (*this)[idx].GetPedestalError();
+        val = fNumSlices>0 ?
+            rms/TMath::Sqrt((Float_t)fNumSlices*(*this)[idx].GetNumEvents())
+            : (*this)[idx].GetPedestalError();
         break;
     case 2:
@@ -559,6 +563,6 @@
         break;
     case 3:
-        val = fTotalEntries > 0 ?
-          rms/TMath::Sqrt((Float_t)fTotalEntries*2.)
+        val = fNumSlices>0 ?
+          rms/TMath::Sqrt((Float_t)fNumSlices*(*this)[idx].GetNumEvents()*2.)
           : (*this)[idx].GetPedestalRmsError();
         break;
Index: trunk/MagicSoft/Mars/mpedestal/MPedestalCam.h
===================================================================
--- trunk/MagicSoft/Mars/mpedestal/MPedestalCam.h	(revision 8446)
+++ trunk/MagicSoft/Mars/mpedestal/MPedestalCam.h	(revision 8490)
@@ -23,5 +23,5 @@
   TClonesArray *fAverageSectors;  //-> Array of MPedestalPix, one per camera sector
 
-  UInt_t fTotalEntries;  // Total number of times, the Process was executed (to estimate the error of pedestal)
+  UInt_t fNumSlices;  // Total number of slices
 
   void PrintArr(const TCollection &list) const;
@@ -45,5 +45,5 @@
   Float_t             GetPedestalMax   ( const MGeomCam *cam ) const;
   Int_t               GetSize          ()                      const;
-  ULong_t             GetTotalEntries  ()                      const { return fTotalEntries; }
+  ULong_t             GetNumSlices() const { return fNumSlices; }
 
   TArrayF GetAveragedPedPerArea  ( const MGeomCam &geom, const UInt_t ai=0,  MBadPixelsCam *bad=NULL );
@@ -63,10 +63,10 @@
   
   // Setters
-  void SetTotalEntries(const ULong_t n) { fTotalEntries = n; }
+  void SetNumSlices(const ULong_t n) { fNumSlices = n; }
   
   Bool_t GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type=0) const;
   void DrawPixelContent(Int_t idx) const;
 
-  ClassDef(MPedestalCam, 1)	// Storage Container for all pedestal information of the camera
+  ClassDef(MPedestalCam, 2)	// Storage Container for all pedestal information of the camera
 };
 
