Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 5782)
+++ trunk/MagicSoft/Mars/Changelog	(revision 5790)
@@ -47,4 +47,6 @@
        lead to an unsuitable pixel.
 
+   * msignal/MExtractTimeAndChargeDigitalFilter.[h,cc]
+     - implemented changes suggested by T.B. to speed up calculations
 
 
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5782)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.cc	(revision 5790)
@@ -212,4 +212,26 @@
 }
 
+void MExtractTimeAndChargeDigitalFilter::CalcBinningResArrays()
+{
+
+  fArrBinningResHiGain.Set(fWindowSizeHiGain);
+  fArrBinningResHalfHiGain.Set(fWindowSizeHiGain);
+
+  for (int i=0; i<fWindowSizeHiGain; i++)
+    {
+      fArrBinningResHiGain[i] = fBinningResolutionHiGain*i;
+      fArrBinningResHalfHiGain[i] = fArrBinningResHiGain[i] + fBinningResolutionHalfHiGain;
+    }
+
+  fArrBinningResLoGain.Set(fWindowSizeLoGain);
+  fArrBinningResHalfLoGain.Set(fWindowSizeLoGain);
+  
+  for (int i=0; i<fWindowSizeLoGain; i++)
+    {
+      fArrBinningResLoGain[i] = fBinningResolutionLoGain*i;
+      fArrBinningResHalfLoGain[i] = fArrBinningResLoGain[i] + fBinningResolutionHalfLoGain;
+    }
+}
+
 // --------------------------------------------------------------------------
 //
@@ -253,5 +275,5 @@
       if (*p++ >= fSaturationLimit)
         if (!sat)
-          sat = ids-3;
+          sat = ids-4;
     }
 
@@ -274,5 +296,5 @@
           if (*logain++ >= fSaturationLimit)
             if (!sat)
-              sat = ids-3;
+              sat = ids-4;
 
           range++;
@@ -296,5 +318,5 @@
       for (Int_t ids=0; ids < fWindowSizeHiGain; ids++)
         {
-          const Int_t   idx = fBinningResolutionHiGain*ids + fRandomIter;
+          const Int_t   idx = fArrBinningResHiGain[ids] + fRandomIter;
           sum              += fAmpWeightsHiGain [idx]*fHiGainSignal[ids]; 
         }
@@ -322,5 +344,5 @@
       for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
       {
-        const Int_t   idx = fBinningResolutionHiGain*sample+fBinningResolutionHalfHiGain;
+        const Int_t   idx = fArrBinningResHalfHiGain[sample];
         const Float_t pex = fHiGainSignal[sample+i];
 	sum              += fAmpWeightsHiGain [idx]*pex; 
@@ -368,5 +390,5 @@
   for (Int_t sample=0; sample < fWindowSizeHiGain; sample++)
   {
-    const Int_t   idx = fBinningResolutionHiGain*sample + fBinningResolutionHalfHiGain + t_iter;
+    const Int_t   idx = fArrBinningResHalfHiGain[sample] + t_iter;
     const Int_t   ids = max_p + sample;
     const Float_t pex = ids < 0 ? 0. : ( ids >= range ? 0. : fHiGainSignal[ids]);
@@ -435,5 +457,5 @@
       for (Int_t ids=0; ids < fWindowSizeLoGain; ids++)
         {
-          const Int_t   idx = fBinningResolutionLoGain*ids + fRandomIter;
+          const Int_t   idx = fArrBinningResLoGain[ids] + fRandomIter;
           sum              += fAmpWeightsLoGain [idx]*fLoGainSignal[ids]; 
         }
@@ -460,5 +482,5 @@
       for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
       {
-        const Int_t   idx = fBinningResolutionLoGain*sample+fBinningResolutionHalfLoGain;
+        const Int_t   idx = fArrBinningResHalfLoGain[sample];
         const Float_t pex = fLoGainSignal[sample+i];
 	sum              += fAmpWeightsLoGain [idx]*pex; 
@@ -507,5 +529,5 @@
   for (Int_t sample=0; sample < fWindowSizeLoGain; sample++)
   {
-    const Int_t   idx = fBinningResolutionLoGain*sample + fBinningResolutionHalfLoGain + t_iter;
+    const Int_t   idx = fArrBinningResHalfLoGain[sample] + t_iter;
     const Int_t   ids = max_p + sample;
     const Float_t pex = ids < 0 ? 0. : ( ids >= range ? 0. : fLoGainSignal[ids]);
@@ -674,5 +696,5 @@
             }
 
-            len = fBinningResolutionLoGain*fWindowSizeHiGain;
+            len = fBinningResolutionLoGain*fWindowSizeLoGain;
             fAmpWeightsLoGain .Set(len);
             fTimeWeightsLoGain.Set(len);
@@ -724,4 +746,6 @@
     *fLog << inf << " File contains " << fWindowSizeLoGain << " lo-gain slices ";
     *fLog << "with a resolution of " << fBinningResolutionLoGain << endl;
+
+    CalcBinningResArrays();
 
     fWeightsSet = kTRUE;
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 5782)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeDigitalFilter.h	(revision 5790)
@@ -8,4 +8,8 @@
 #ifndef MARS_MArrayF
 #include "MArrayF.h"
+#endif
+
+#ifndef MARS_MArrayI
+#include "MArrayI.h"
 #endif
 
@@ -32,4 +36,9 @@
   MArrayF fLoGainSignal;                        //! Store them in separate arrays
 
+  MArrayI fArrBinningResHiGain;                 //! helping arrays to hold binningres * i 
+  MArrayI fArrBinningResLoGain;                 //! helping arrays to hold binningres * i 
+  MArrayI fArrBinningResHalfHiGain;             //! helping arrays to hold binningres * i + binningreshalf
+  MArrayI fArrBinningResHalfLoGain;             //! helping arrays to hold binningres * i + binningreshalf
+  
   Float_t fTimeShiftHiGain;                     //  Time shift from when on to apply the filter
   Float_t fTimeShiftLoGain;                     //  Time shift from when on to apply the filter
@@ -54,4 +63,6 @@
   Bool_t  InitArrays();
 
+  void CalcBinningResArrays();
+  
   Int_t   ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
