Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 5218)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 5219)
@@ -19,4 +19,11 @@
 
                                                  -*-*- END OF LINE -*-*-
+
+ 2004/10/11: Markus Gaug
+
+   * mpedestal/MPedCalcPedRun.[h,cc]
+     - calculate addtionally to the usual pedestal the ABOffset, like 
+       in MPedCalcFromLoGain. 
+
 
  2004/10/08: Markus Meyer and Keiichi Mase
Index: /trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc
===================================================================
--- /trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 5218)
+++ /trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.cc	(revision 5219)
@@ -190,4 +190,26 @@
     fRunHeader = NULL;
     fPedestals = NULL;
+
+    // If the size is yet set, set the size
+    if (fSumx.GetSize()>0)
+    {
+        // Reset contents of arrays.
+        fSumx.Reset();
+        fSumx2.Reset();
+        fSumAB0.Reset();
+        fSumAB1.Reset();
+
+        fAreaSumx. Reset();
+        fAreaSumx2.Reset();
+        fAreaSumAB0.Reset();
+        fAreaSumAB1.Reset();
+        fAreaValid.Reset();
+        
+        fSectorSumx. Reset();
+        fSectorSumx2.Reset();
+        fSectorSumAB0.Reset();
+        fSectorSumAB1.Reset();
+        fSectorValid.Reset();
+    }
 }
 
@@ -241,5 +263,5 @@
     {
         *fLog << warn;
-        *fLog << GetDescriptor() << ": HiGain window currently set to 0, will set it to 2 samples ";
+        *fLog << GetDescriptor() << ": HiGain window currently set to 0, will set it to 2 samples " << endl;
         fWindowSizeHiGain = 2;
     }
@@ -248,5 +270,5 @@
     {
         *fLog << warn;
-        *fLog << GetDescriptor() << ": LoGain window currently set to 0, will set it to 2 samples ";
+        *fLog << GetDescriptor() << ": LoGain window currently set to 0, will set it to 2 samples " << endl;
         fWindowSizeLoGain = 2;
     }
@@ -346,4 +368,5 @@
 Bool_t MPedCalcPedRun::ReInit(MParList *pList)
 {
+
   Int_t lastdesired   = (Int_t)fLoGainLast;
   Int_t lastavailable = (Int_t)fRunHeader->GetNumSamplesLoGain()-1;
@@ -414,16 +437,22 @@
   if (fSumx.GetSize()==0)
     {
-      fSumx. Set(npixels);
-      fSumx2.Set(npixels);
-      
-      fAreaSumx. Set(areas);
-      fAreaSumx2.Set(areas);
-      fAreaValid.Set(areas);
-      
-      fSectorSumx. Set(sectors);
-      fSectorSumx2.Set(sectors);
-      fSectorValid.Set(sectors);
-      
-      fSumx.Reset();
+      fSumx.  Set(npixels);
+      fSumx2. Set(npixels);
+      fSumAB0.Set(npixels);
+      fSumAB1.Set(npixels);
+      
+      fAreaSumx.  Set(areas);
+      fAreaSumx2. Set(areas);
+      fAreaSumAB0.Set(areas);
+      fAreaSumAB1.Set(areas);
+      fAreaValid. Set(areas);
+      
+      fSectorSumx.  Set(sectors);
+      fSectorSumx2. Set(sectors);
+      fSectorSumAB0.Set(sectors);
+      fSectorSumAB1.Set(sectors);
+      fSectorValid. Set(sectors);
+      
+      fSumx. Reset();
       fSumx2.Reset();
     }
@@ -454,4 +483,5 @@
 Int_t MPedCalcPedRun::Process()
 {
+
   MRawEvtPixelIter pixel(fRawEvt);
   
@@ -467,4 +497,7 @@
       UInt_t sum = 0;
       UInt_t sqr = 0;
+      UInt_t ab0 = 0;
+      UInt_t ab1 = 0;
+      Int_t  cnt = 0;
 
       if (fWindowSizeHiGain != 0)
@@ -474,7 +507,20 @@
               sum += *ptr;
               sqr += *ptr * *ptr;
+
+              if (pixel.IsABFlagValid())
+                {
+                  const Int_t abFlag = (fHiGainFirst + pixel.HasABFlag() + cnt) & 0x1;
+                  if (abFlag)
+                    ab1 += *ptr;
+                  else
+                    ab0 += *ptr;
+
+                  cnt++;
+                }
             }
           while (++ptr != end);
         }
+
+      cnt = 0;
       
       if (fWindowSizeLoGain != 0)
@@ -488,4 +534,17 @@
               sum += *ptr;
               sqr += *ptr * *ptr;
+
+              if (pixel.IsABFlagValid())
+                {
+                  const Int_t abFlag = (fLoGainFirst + pixel.GetNumHiGainSamples() + pixel.HasABFlag() + cnt) 
+                                      & 0x1;
+                  if (abFlag)
+                    ab1 += *ptr;
+                  else
+                    ab0 += *ptr;
+
+                  cnt++;
+                }
+
             }
           while (++ptr != end);
@@ -506,4 +565,5 @@
       fAreaSumx[aidx]     += msum;
       fSectorSumx[sector] += msum;      
+
       //
       // The old version:
@@ -518,4 +578,16 @@
       fAreaSumx2[aidx]     += sqrsum;
       fSectorSumx2[sector] += sqrsum;      
+
+      //
+      // Now, the sums separated for AB0 and AB1
+      //
+      fSumAB0[idx]        += ab0;
+      fSumAB1[idx]        += ab1;
+
+      fAreaSumAB0[aidx]   += ab0;
+      fAreaSumAB1[aidx]   += ab1;      
+      
+      fSectorSumAB0[aidx] += ab0;
+      fSectorSumAB1[aidx] += ab1;      
     }
   
@@ -532,4 +604,5 @@
 Int_t MPedCalcPedRun::PostProcess()
 {
+
   // Compute pedestals and rms from the whole run
   const ULong_t n     = fNumSamplesTot;
@@ -563,5 +636,11 @@
       higainVar /= (Float_t)(fWindowSizeHiGain+fWindowSizeLoGain);
       // 3. Calculate the RMS from the Variance:
-      (*fPedestals)[pixid].Set(higainped, higainVar < 0 ? 0. : TMath::Sqrt(higainVar));
+      const Float_t rms = higainVar<0 ? 0. : TMath::Sqrt(higainVar);
+      // 4. Calculate the amplitude of the 150MHz "AB" noise
+      const Float_t abOffs = (fSumAB0.At(pixid) - fSumAB1.At(pixid)) / n;
+      
+      *fLog << "THIS is the aboffs: " << abOffs << endl;
+
+      (*fPedestals)[pixid].Set(higainped,rms,abOffs);
 
     }
@@ -594,6 +673,8 @@
       //    in order to be comparable to the mean of pedRMS of that area
       higainrms *= TMath::Sqrt((Float_t)napix);
-
-      fPedestals->GetAverageArea(aidx).Set(higainped, higainrms);
+      // 5. Calculate the amplitude of the 150MHz "AB" noise
+      const Float_t abOffs = (fAreaSumAB0.At(aidx) - fAreaSumAB1.At(aidx)) / an;
+
+      fPedestals->GetAverageArea(aidx).Set(higainped, higainrms,abOffs);
     }
   
@@ -625,6 +706,8 @@
       //    in order to be comparable to the mean of pedRMS of that sector
       higainrms *= TMath::Sqrt((Float_t)nspix);
-
-      fPedestals->GetAverageSector(sector).Set(higainped, higainrms);
+      // 5. Calculate the amplitude of the 150MHz "AB" noise
+      const Float_t abOffs = (fSectorSumAB0.At(sector) - fSectorSumAB1.At(sector)) / sn;
+
+      fPedestals->GetAverageSector(sector).Set(higainped, higainrms, abOffs);
     }
   
Index: /trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h
===================================================================
--- /trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h	(revision 5218)
+++ /trunk/MagicSoft/Mars/mpedestal/MPedCalcPedRun.h	(revision 5219)
@@ -15,43 +15,52 @@
 
 class MGeomCam;
-
 class MPedCalcPedRun : public MExtractor
 {
-    static const Byte_t fgHiGainFirst;      // First FADC slice Hi-Gain (currently set to: 3)
-    static const Byte_t fgHiGainLast;       // Last FADC slice Hi-Gain (currently set to: 14)
-    static const Byte_t fgLoGainFirst;      // First FADC slice Lo-Gain (currently set to: 3)
-    static const Byte_t fgLoGainLast;       // Last FADC slice Lo-Gain (currently set to: 14)
-    static const Byte_t fgHiGainWindowSize; // The extraction window Hi-Gain
-    static const Byte_t fgLoGainWindowSize; // The extraction window Lo-Gain
 
-    UInt_t  fNumSamplesTot;
-    Byte_t  fWindowSizeHiGain; // Number of Hi Gain slices in window
-    Byte_t  fWindowSizeLoGain; // Number of Lo Gain slices in window
+  static const Byte_t fgHiGainFirst;      // First FADC slice Hi-Gain (currently set to: 3)
+  static const Byte_t fgHiGainLast;       // Last FADC slice Hi-Gain (currently set to: 14)
+  static const Byte_t fgLoGainFirst;      // First FADC slice Lo-Gain (currently set to: 3)
+  static const Byte_t fgLoGainLast;       // Last FADC slice Lo-Gain (currently set to: 14)
+  static const Byte_t fgHiGainWindowSize; // The extraction window Hi-Gain
+  static const Byte_t fgLoGainWindowSize; // The extraction window Lo-Gain
+  
+  UInt_t  fNumSamplesTot;
+  Byte_t  fWindowSizeHiGain; // Number of Hi Gain slices in window
+  Byte_t  fWindowSizeLoGain; // Number of Lo Gain slices in window
+  
+  MGeomCam *fGeom;           // Camera geometry
+  
+  TArrayD fSumx;             // sum of values
+  TArrayD fSumx2;            // sum of squared values
+  TArrayD fSumAB0;           // sum of ABFlag=0 slices
+  TArrayD fSumAB1;           // sum of ABFlag=1 slices
+  TArrayD fAreaSumx;         // averaged sum of values per area idx
+  TArrayD fAreaSumx2;        // averaged sum of squared values per area idx
+  TArrayD fAreaSumAB0;       // averaged sum of ABFlag=0 slices per area idx
+  TArrayD fAreaSumAB1;       // averaged sum of ABFlag=1 slices per area idx
+  TArrayI fAreaValid;        // number of valid pixel with area idx
+  TArrayD fSectorSumx;       // averaged sum of values per sector
+  TArrayD fSectorSumx2;      // averaged sum of squared values per sector
+  TArrayD fSectorSumAB0;     // averaged sum of ABFlag=0 slices per sector
+  TArrayD fSectorSumAB1;     // averaged sum of ABFlag=1 slices per sector 
+  TArrayI fSectorValid;      // number of valid pixel with sector idx
+  
+  Int_t  PreProcess (MParList *pList);
+  Bool_t ReInit     (MParList *pList);
+  Int_t  Process    ();
+  Int_t  PostProcess();
+  Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
+  
+public:
 
-    MGeomCam *fGeom;           // Camera geometry
-
-    TArrayD fSumx;             // sum of values
-    TArrayD fSumx2;            // sum of squared values
-    TArrayD fAreaSumx;         // averaged sum of values per area idx
-    TArrayD fAreaSumx2;        // averaged sum of squared values per area idx
-    TArrayI fAreaValid;        // number of valid pixel with area idx
-    TArrayD fSectorSumx;       // averaged sum of values per sector
-    TArrayD fSectorSumx2;      // averaged sum of squared values per sector
-    TArrayI fSectorValid;      // number of valid pixel with sector idx
-
-    Int_t  PreProcess (MParList *pList);
-    Bool_t ReInit     (MParList *pList);
-    Int_t  Process    ();
-    Int_t  PostProcess();
-    Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
-
-public:
-    MPedCalcPedRun(const char *name=NULL, const char *title=NULL);
-
-    void Clear(const Option_t *o="");
-    void SetRange(Byte_t hifirst=0, Byte_t hilast=0, Byte_t lofirst=0, Byte_t lolast=0);
-    void SetWindowSize(Byte_t windowh=0, Byte_t windowl=0);
-
-    ClassDef(MPedCalcPedRun, 0)   // Task to calculate pedestals from pedestal runs raw data
+  MPedCalcPedRun(const char *name=NULL, const char *title=NULL);
+  
+  void Clear(const Option_t *o="");
+  
+  void SetRange        ( const Byte_t hifirst=0, const Byte_t hilast=0, 
+	                 const Byte_t lofirst=0, const Byte_t lolast=0  );
+  void SetWindowSize   ( const Byte_t windowh=0, const Byte_t windowl=0 );
+  
+  ClassDef(MPedCalcPedRun, 0)   // Task to calculate pedestals from pedestal runs raw data
 };
 
