Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2714)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2715)
@@ -4,4 +4,14 @@
 
                                                  -*-*- END OF LINE -*-*-
+ 2003/12/18: Markus Gaug
+
+   * manalysis/MExtractSignal.[h,cc]
+     - introduced a third argument in the constructor: Byte_t logainshift
+
+   * manalysis/MCalibrationCam.cc
+   * manalysis/MCalibrationPix.cc
+     - introduced error calculation for the F-Factor method
+
+
  2003/12/18: Abelardo Moralejo
 
Index: /trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2714)
+++ /trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2715)
@@ -173,41 +173,60 @@
 MCalibrationPix &MCalibrationCam::operator[](Int_t i) const
 {
-    return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
-}
-
-// --------------------------------------------------------------------------
-//
-// Return a pointer to the pixel with the requested idx. 
-// NULL if it doesn't exist. 
-//
-MCalibrationPix *MCalibrationCam::GetCalibrationPix(Int_t idx) const
-{
-   if (idx<0)
-     return NULL;
-
+
+  if (!CheckBounds(i))
+    return *static_cast<MCalibrationPix*>(NULL);
+
+  return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
+}
+
+
+// --------------------------------------------------------------------------
+//
+// Return true if pixel is inside bounds of the TClonesArray fPixels
+//
+Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const 
+{
   if (!CheckBounds(idx))
-    return NULL;
-  
-  return (MCalibrationPix*)fPixels->At(idx);
-}
-
-
-
-
-Bool_t MCalibrationCam::IsPixelUsed(Int_t idx) const 
-{
+    return kFALSE;
+
+  return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return true if pixel has already been fitted once (independent of the result)
+//
+Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const 
+{
+
   if (!CheckBounds(idx))
     return kFALSE;
 
-  return kTRUE;
-}
-
-Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const 
-{
-  return ((*this)[idx].GetCharge() > 0. && (*this)[idx].GetErrCharge() > 0.);
-}
-
-
-
+  return (*this)[idx].IsFitted();
+}
+
+// --------------------------------------------------------------------------
+//
+// Return TRUE if:
+//
+// 1) Pixel is inside the range of the TClonesArray
+// 2) Pixel has a fitted charge greater than 3*PedRMS
+// 3) Pixel has a charge sigma bigger than its Pedestal RMS
+// 4) Pixel has a fit error greater than 0.
+// 5) Pixel has a fit Probability greater than 0.0001
+// 6) If FitTimes is used, 
+//    the mean arrival time is at least 1.5 slices from the edge
+// 
+Bool_t MCalibrationCam::IsPixelFitValid(Int_t idx) const 
+{
+
+  if (!CheckBounds(idx))
+    return kFALSE;
+
+  return (*this)[idx].IsFitValid();
+}
+
+// --------------------------------------
+//
 void MCalibrationCam::Clear(Option_t *o)
 {
@@ -215,8 +234,15 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Sets the user ranges of all histograms such that 
+// empty bins at the edges are not used. Additionally, it rebins the 
+// histograms such that in total, 50 bins are used.
+//
 void MCalibrationCam::CutEdges()
 {
 
   fBlindPixel->GetHist()->CutAllEdges();
+  fPINDiode->GetHist()->CutAllEdges();
 
   TIter Next(fPixels);
@@ -230,19 +256,25 @@
 }
   
+// --------------------------------------------------------------------------
+//
+// 
+// 
+// 
+//
 void MCalibrationCam::Print(Option_t *o) const
 {
 
-    *fLog << all << GetDescriptor() << ":" << endl;
-    int id = 0;
-
-    *fLog << "Succesfully calibrated pixels:" << endl;
-    *fLog << endl;
-
-    TIter Next(fPixels);
-    MCalibrationPix *pix;
-    while ((pix=(MCalibrationPix*)Next()))
-    {
-
-      if (pix->GetCharge() >= 0.) 
+  *fLog << all << GetDescriptor() << ":" << endl;
+  int id = 0;
+  
+  *fLog << "Succesfully calibrated pixels:" << endl;
+  *fLog << endl;
+
+  TIter Next(fPixels);
+  MCalibrationPix *pix;
+  while ((pix=(MCalibrationPix*)Next()))
+    {
+      
+      if (pix->IsFitValid()) 
 	{
 	  *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
@@ -252,26 +284,26 @@
 	}
     }
-
-    *fLog << id << " succesful pixels :-))" << endl;
-    id = 0;
-
-    *fLog << endl;
-    *fLog << "Pixels with errors:" << endl;
-    *fLog << endl;
-
-    TIter Next2(fPixels);
+  
+  *fLog << id << " succesful pixels :-))" << endl;
+  id = 0;
+  
+  *fLog << endl;
+  *fLog << "Pixels with errors:" << endl;
+  *fLog << endl;
+  
+  TIter Next2(fPixels);
     while ((pix=(MCalibrationPix*)Next2()))
-    {
-
-      if (pix->GetCharge() == -1.)
-	{
-	  *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
-		<< " Reduced Charge: " << pix->GetCharge() << " +- " 
+      {
+        
+        if (!pix->IsFitValid())
+          {
+            *fLog << pix->GetPixId() << " Pedestals: " << pix->GetPed() << " +- " << pix->GetPedRms() 
+                  << " Reduced Charge: " << pix->GetCharge() << " +- " 
 		<< pix->GetSigmaCharge() << " Reduced Sigma: " << TMath::Sqrt(pix->GetRSigmaSquare()) << endl;
-	  id++;
-	}
-    }
+            id++;
+          }
+      }
     *fLog << id << " pixels with errors :-((" << endl;
-
+    
 }
 
@@ -321,5 +353,29 @@
 	val = -1.;
       break;
+    case 11:
+      val = (*this)[idx].GetPheFFactorMethod();
+      break;
+    case 12:
+      val = (*this)[idx].GetPheFFactorMethodError();
+      break;
+    case 13:
+      val = (*this)[idx].GetMeanConversionFFactorMethod();
+      break;
+    case 14:
+      val = (*this)[idx].GetErrorConversionFFactorMethod();
+      break;
     case 15:
+      if (idx < 397)
+	val = (double)fMeanPhotInsidePlexiglass;
+      else
+	val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
+      break;
+    case 16:
+      if (idx < 397)
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod();
+      else 
+        val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
+      break;
+    case 17:
       if ((*this)[idx].GetCharge() != 0.)
         val = ((*this)[idx].GetSigmaCharge()/(*this)[idx].GetCharge())*
@@ -327,22 +383,4 @@
       else
         val = -1.;
-      break;
-    case 11:
-      val = (*this)[idx].GetPheFFactorMethod();
-      break;
-    case 12:
-      val = (*this)[idx].GetMeanConversionFFactorMethod();
-      break;
-    case 13:
-      if (idx < 397)
-	val = (double)fMeanPhotInsidePlexiglass;
-      else
-	val = (double)fMeanPhotInsidePlexiglass*gkCalibrationOutervsInnerPixelArea;
-      break;
-    case 14:
-      if (idx < 397)
-        val = (*this)[idx].GetMeanConversionBlindPixelMethod();
-      else 
-        val = (*this)[idx].GetMeanConversionBlindPixelMethod()*gkCalibrationOutervsInnerPixelArea;
       break;
     default:
Index: /trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc	(revision 2714)
+++ /trunk/MagicSoft/Mars/manalysis/MExtractSignal.cc	(revision 2715)
@@ -56,5 +56,6 @@
 // Default constructor. 
 //
-MExtractSignal::MExtractSignal(const Byte_t first, const Byte_t last, const char *name, const char *title)
+MExtractSignal::MExtractSignal(const Byte_t first, const Byte_t last, const Byte_t logainshift, 
+                    const char *name, const char *title)
   : fNumHiGainSamples(last-first+1), fNumLoGainSamples(last-first+1),
     fSaturationLimit(254), fConversionHiLo(10.)
@@ -66,5 +67,6 @@
     AddToBranchList("MRawEvtData.*");
 
-    fFirst = first;
+    fFirst       = first;
+    fLoGainFirst = first+logainshift;
 
     fSqrtHiGainSamples = TMath::Sqrt((Float_t)fNumHiGainSamples); 
@@ -186,6 +188,6 @@
 
 	ptr   = pixel.GetLoGainSamples();
-        first = ptr + fFirst + 1;
-        last  = ptr + fFirst + fNumLoGainSamples +1;
+        first = ptr + fLoGainFirst + 1;
+        last  = ptr + fLoGainFirst + fNumLoGainSamples +1;
 	Byte_t maxlo  = 0;
 	Byte_t midlo  = 0;
@@ -222,5 +224,5 @@
 	  pix.SetArrivalTimes((Float_t)(midlo+fFirst),0.,0.);
 	else
-	  pix.SetArrivalTimes((Float_t)(midhi+fFirst),0.,0.);
+	  pix.SetArrivalTimes((Float_t)(midhi+fLoGainFirst),0.,0.);
 
       } /* while (pixel.Next()) */
Index: /trunk/MagicSoft/Mars/manalysis/MExtractSignal.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MExtractSignal.h	(revision 2714)
+++ /trunk/MagicSoft/Mars/manalysis/MExtractSignal.h	(revision 2715)
@@ -32,4 +32,5 @@
 
   Byte_t fFirst;
+  Byte_t fLoGainFirst;
 
   Byte_t fNumHiGainSamples; 
@@ -49,5 +50,5 @@
 public:
 
-  MExtractSignal(const Byte_t first=4, const Byte_t last=9, const char *name=NULL, const char *title=NULL);
+  MExtractSignal(const Byte_t first=4, const Byte_t last=9, const Byte_t logainshift=1, const char *name=NULL, const char *title=NULL);
   
   void SetSaturationLimit(Byte_t lim)      { fSaturationLimit = lim; }
