Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 5542)
+++ trunk/MagicSoft/Mars/Changelog	(revision 5544)
@@ -22,4 +22,9 @@
 
  2004/12/01: Markus Gaug
+
+   * MExtractTimeAndChargeSpline.[h,cc]:
+     - introduced a random iterator for the "pedestal" calculation of 
+       the amplitude spline.
+
 
    * MExtractTimeAndChargeDigitalFilter.cc:
Index: trunk/MagicSoft/Mars/mhcalib/MHGausEvents.cc
===================================================================
--- trunk/MagicSoft/Mars/mhcalib/MHGausEvents.cc	(revision 5542)
+++ trunk/MagicSoft/Mars/mhcalib/MHGausEvents.cc	(revision 5544)
@@ -487,12 +487,26 @@
   
   Int_t win = 1;
+  Int_t nofit = 0;
 
   if (option.Contains("events"))
-    win += 1;
+    {
+      option.ReplaceAll("events","");      
+      win += 1;
+    }
   if (option.Contains("fourier"))
-    win += 2;
+    {
+      option.ReplaceAll("fourier","");      
+      win += 2;
+    }
+  
   if (IsEmpty())
     win--;
 
+  if (option.Contains("nofit"))
+    {
+      option.ReplaceAll("nofit","");
+      nofit++;
+    }
+  
   pad->SetBorderMode(0);
   pad->Divide(1,win);
@@ -510,10 +524,11 @@
 
       fHGausHist.Draw(option);
-      
-      if (fFGausFit)
-        {
-          fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
-          fFGausFit->Draw("same");
-        }
+
+      if (!nofit)
+        if (fFGausFit)
+          {
+            fFGausFit->SetLineColor(IsGausFitOK() ? kGreen : kRed);
+            fFGausFit->Draw("same");
+          }
     }
   
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.cc	(revision 5542)
+++ 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
Index: trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h
===================================================================
--- trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h	(revision 5542)
+++ trunk/MagicSoft/Mars/msignal/MExtractTimeAndChargeSpline.h	(revision 5544)
@@ -39,7 +39,7 @@
   Float_t fFallTime;                     // The usual fall time of the pulse
 
+  UInt_t  fRandomIter;                   // Counter used to randomize weights for noise calculation
+  
   Byte_t  fFlags;                        // Bit-field to hold the time extraction types
-  
-  Bool_t ReInit( MParList *pList );
   
   Int_t  ReadEnv(const TEnv &env, TString prefix, Bool_t print);
