Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 5511)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 5544)
@@ -177,5 +177,5 @@
 //
 MExtractTimeAndChargeSpline::MExtractTimeAndChargeSpline(const char *name, const char *title) 
-    : fAbMax(0.), fAbMaxPos(0.), fHalfMax(0.)
+    : fAbMax(0.), fAbMaxPos(0.), fHalfMax(0.), fRandomIter(0)
 {
 
@@ -251,14 +251,31 @@
 // --------------------------------------------------------------------------
 //
-// ReInit
-//
-// Calls:
-// - MExtractTimeAndCharge::ReInit(pList);
-// - Deletes all arrays, if not NULL
-// - Creates new arrays according to the extraction range
-//
-Bool_t MExtractTimeAndChargeSpline::ReInit(MParList *pList)
+// InitArrays
+//
+// Gets called in the ReInit() and initialized the arrays
+//
+Bool_t MExtractTimeAndChargeSpline::InitArrays()
 {
 
+  Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
+
+  fHiGainSignal     .Set(range);
+  fHiGainFirstDeriv .Set(range);
+  fHiGainSecondDeriv.Set(range);
+
+  range = fLoGainLast - fLoGainFirst + 1;
+
+  fLoGainSignal     .Set(range);
+  fLoGainFirstDeriv .Set(range);
+  fLoGainSecondDeriv.Set(range);
+
+  fHiGainSignal     .Reset();
+  fHiGainFirstDeriv .Reset();
+  fHiGainSecondDeriv.Reset();
+
+  fLoGainSignal     .Reset();
+  fLoGainFirstDeriv .Reset();
+  fLoGainSecondDeriv.Reset();
+  
   if (IsExtractionType(kAmplitude))
     {
@@ -280,39 +297,4 @@
       fWindowSizeLoGain  = (Int_t)(fRiseTime + fFallTime+1);
     }
-
-  if (!MExtractTimeAndCharge::ReInit(pList))
-    return kFALSE;
-
-  return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// InitArrays
-//
-// Gets called in the ReInit() and initialized the arrays
-//
-Bool_t MExtractTimeAndChargeSpline::InitArrays()
-{
-
-  Int_t range = fHiGainLast - fHiGainFirst + 1 + fHiLoLast;
-
-  fHiGainSignal     .Set(range);
-  fHiGainFirstDeriv .Set(range);
-  fHiGainSecondDeriv.Set(range);
-
-  range = fLoGainLast - fLoGainFirst + 1;
-
-  fLoGainSignal     .Set(range);
-  fLoGainFirstDeriv .Set(range);
-  fLoGainSecondDeriv.Set(range);
-
-  fHiGainSignal     .Reset();
-  fHiGainFirstDeriv .Reset();
-  fHiGainSecondDeriv.Reset();
-
-  fLoGainSignal     .Reset();
-  fLoGainFirstDeriv .Reset();
-  fLoGainSecondDeriv.Reset();
 
   return kTRUE;
@@ -415,11 +397,16 @@
   if (IsNoiseCalculation() && IsExtractionType(kAmplitude))
     {
-      //
-      // Take the spline value at the middle of the third slice (to avoid egde effects)
-      // 
-      sum = 0.5*fHiGainSignal[2]
-          + 0.5*fHiGainSignal[3]
-          + (-0.375)*fHiGainSecondDeriv[2] 
-          + (-0.375)*fHiGainSecondDeriv[3];
+      if (fRandomIter == (TMath::Floor(1./fResolution)))
+        fRandomIter = 0;
+
+      const Float_t b = fRandomIter * fResolution;
+      const Float_t a = 1. - b;
+
+      fRandomIter++;
+
+      sum = a*fHiGainSignal[1]
+          + b*fHiGainSignal[2]
+          + (a*a*a-a)*fHiGainSecondDeriv[1] 
+          + (b*b*b-b)*fHiGainSecondDeriv[2];
       return;
     }
@@ -531,6 +518,6 @@
   // Try a better precision. 
   //
-  const Float_t up = fAbMaxPos+step-0.035;
-  const Float_t lo = fAbMaxPos-step+0.035;
+  const Float_t up = fAbMaxPos+step - 1.5*fResolution;
+  const Float_t lo = fAbMaxPos-step + 1.5*fResolution;
   const Float_t maxpossave = fAbMaxPos;
   
@@ -539,5 +526,5 @@
   b     = x - lower;
  
-  step  = 0.025; // step size of 83 ps 
+  step  = fResolution; // step size of 83 ps 
  
   while (x<up)
@@ -562,5 +549,5 @@
 
   //
-  // Second, try from time down to time-0.2 in steps of 0.025.
+  // Second, try from time down to time-0.2 in steps of fResolution.
   //
   x     = maxpossave;
@@ -571,5 +558,5 @@
   // which requires new setting of klocont and khicont
   //
-  if (x < klo + 0.02)
+  if (x < klo + fResolution/2.)
     {
       klo--;
@@ -605,5 +592,5 @@
     {
       time = (Float_t)fHiGainFirst + fAbMaxPos;
-      dtime = 0.025;
+      dtime = fResolution;
     }
   else
@@ -892,6 +879,6 @@
   // Try a better precision. 
   //
-  const Float_t up = fAbMaxPos+step-0.035;
-  const Float_t lo = fAbMaxPos-step+0.035;
+  const Float_t up = fAbMaxPos+step - 1.5*fResolution;
+  const Float_t lo = fAbMaxPos-step + 1.5*fResolution;
   const Float_t maxpossave = fAbMaxPos;
   
@@ -900,5 +887,5 @@
   b     = x - lower;
  
-  step  = 0.025; // step size of 83 ps 
+  step  = fResolution; // step size of fResolution (33 ps )
  
   while (x<up)
@@ -932,5 +919,5 @@
   // which requires new setting of klocont and khicont
   //
-  if (x < klo + 0.02)
+  if (x < klo + fResolution/2.)
     {
       klo--;
@@ -966,5 +953,5 @@
     {
       time = (Float_t)fLoGainFirst + fAbMaxPos;
-      dtime = 0.02;
+      dtime = fResolution;
     }
   else
