Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5504)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5505)
@@ -91,5 +91,5 @@
 //
 MExtractTimeAndChargeDigitalFilter::MExtractTimeAndChargeDigitalFilter(const char *name, const char *title) 
-    : fWeightsSet(kFALSE)
+    : fWeightsSet(kFALSE), fRandomIter(0)
 {
     fName  = name  ? name  : "MExtractTimeAndChargeDigitalFilter";
@@ -188,5 +188,4 @@
 Int_t MExtractTimeAndChargeDigitalFilter::PreProcess(MParList *pList)
 {
-
   if (!fWeightsSet)
     if (!ReadWeightsFile(fNameWeightsFile))
@@ -223,6 +222,8 @@
 void MExtractTimeAndChargeDigitalFilter::InitArrays()
 {
-  fHiGainSignal.Set(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
-  fLoGainSignal.Set(fLoGainLast - fLoGainFirst + 1);
+  Int_t range = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
+  fHiGainSignal.Set(range);
+  range = (Int_t)(fLoGainLast - fLoGainFirst + 1);
+  fLoGainSignal.Set(range);
 }
 
@@ -237,4 +238,5 @@
 
   Int_t range = fHiGainLast - fHiGainFirst + 1;
+  
   const Byte_t *end = ptr + range;
   Byte_t *p     = ptr;
@@ -305,4 +307,21 @@
     return;
 
+  //
+  // Slide with a window of size fWindowSizeHiGain over the sample 
+  // and multiply the entries with the corresponding weights
+  //
+  if (IsNoiseCalculation())
+    {
+      if (fRandomIter == 10)
+        fRandomIter = 0;
+      for (Int_t ids=0; ids < fWindowSizeHiGain; ids++)
+        {
+          const Int_t   idx = fBinningResolutionHiGain*ids + fRandomIter;
+          sum              += fAmpWeightsHiGain [idx]*fHiGainSignal[ids]; 
+        }
+      fRandomIter++;
+      return;
+    }
+  
   Float_t time_sum  = 0.;
   Float_t fmax      = 0.;
@@ -330,6 +349,4 @@
       }
 
-      //  if (IsNoiseCalculation()) return;
-
       if (sum>fmax)
       {
@@ -373,8 +390,7 @@
   {
     const Int_t   idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter;
-    const Int_t   ids = IsNoiseCalculation() ? sample : max_p + sample;
+    const Int_t   ids = max_p + sample;
     
-    const Float_t pex = ids < 0 ? 0. : 
-      ( ids > range ? 0. : fHiGainSignal[ids]);
+    const Float_t pex = ids < 0 ? 0. : ( ids > range ? 0. : fHiGainSignal[ids]);
     sum              += fAmpWeightsHiGain [idx]*pex; 
     time_sum         += fTimeWeightsHiGain[idx]*pex;
@@ -436,4 +452,18 @@
     }
   
+  //
+  // Slide with a window of size fWindowSizeHiGain over the sample 
+  // and multiply the entries with the corresponding weights
+  //
+  if (IsNoiseCalculation())
+    {
+      for (Int_t ids=0; ids < fWindowSizeLoGain; ids++)
+        {
+          const Int_t   idx = fBinningResolutionHiGain*ids + fRandomIter;
+          sum              += fAmpWeightsLoGain [idx]*fLoGainSignal[ids]; 
+        }
+      return;
+    }
+
   Float_t time_sum  = 0.;
   Float_t fmax      = 0.;
@@ -503,7 +533,6 @@
   {
     const Int_t   idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter;
-    const Int_t   ids = (IsNoiseCalculation()) ? sample : max_p + sample;;
-    const Float_t pex = ids < 0 ? 0. : 
-      ( ids > range ? 0. : fLoGainSignal[ids]);
+    const Int_t   ids = max_p + sample;;
+    const Float_t pex = ids < 0 ? 0. : ( ids > range ? 0. : fLoGainSignal[ids]);
     sum              += fAmpWeightsLoGain [idx]*pex; 
     time_sum         += fTimeWeightsLoGain[idx]*pex;
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 5504)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 5505)
@@ -50,5 +50,6 @@
   TString fNameWeightsFile;                     // Name of the weights file
   Bool_t  fWeightsSet;                          // Flag if weights have alreayd been set
-  
+  UInt_t  fRandomIter;                          // Counter used to randomize weights for noise calculation
+
   Bool_t ReInit(MParList *pList);
   Int_t PreProcess(MParList *pList);
@@ -87,5 +88,7 @@
 
   void Print(Option_t *o="") const;
-  
+
+  Bool_t IsWeightsSet() const  { return fWeightsSet;  }
+
   void FindTimeAndChargeHiGain(Byte_t *firstused, Byte_t *logain, Float_t &sum, Float_t &dsum,
                                Float_t &time, Float_t &dtime,
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 5504)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSlidingWindow.cc	(revision 5505)
@@ -187,6 +187,8 @@
 void MExtractTimeAndChargeSlidingWindow::InitArrays()
 {
-  fHiGainSignal.Set(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
-  fLoGainSignal.Set(fLoGainLast - fLoGainFirst + 1);
+  Int_t range = (Int_t)(fHiGainLast - fHiGainFirst + 1 + fHiLoLast);
+  fHiGainSignal.Set(range);
+  range = (Int_t)(fLoGainLast - fLoGainFirst + 1);
+  fLoGainSignal.Set(range);
 }
 
