Index: trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h	(revision 2590)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationBlindPix.h	(revision 2599)
@@ -51,7 +51,7 @@
   Float_t GetErrT()      const    { return fErrT;      }
   
-  Bool_t FillQ(Int_t q)            { return fHist->FillBPQ(q); }
-  Bool_t FillT(Int_t t)            { return fHist->FillBPT(t); }  
-  Bool_t FillRQvsT(Float_t rq, Int_t t) { return fHist->FillBPQvsN(rq,t); }    
+  Bool_t FillQ(Int_t q)            { return fHist->FillBlindPixelQ(q); }
+  Bool_t FillT(Int_t t)            { return fHist->FillBlindPixelT(t); }  
+  Bool_t FillRQvsT(Float_t rq, Int_t t) { return fHist->FillBlindPixelQvsN(rq,t); }    
   
   Bool_t IsValid()                 { return fLambda > 0. || fErrLambda > 0.; }
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2590)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCalc.cc	(revision 2599)
@@ -163,8 +163,4 @@
       }
 
-    //
-    // fRawEvt->GetNumPixels() does not work !!!!!!!!!!
-    //
-    fCalibrations->InitSize(577);
 
     switch (fColor)
@@ -189,15 +185,4 @@
       }
     
-
-    // MTime does not work!!!!
-
-    //    fEvtTime = (MTime*)pList->FindObject("MRawEvtTime");
-    //    if (!fEvtTime)
-    //      {
-    //        *fLog << dbginf << "MTime could not be created ... ¡!¡!¡!¡!" << endl;        
-    //      }
-    
-    // fEvtTime->SetTime(0.);
-
     
     return kTRUE;
@@ -222,5 +207,19 @@
     fNumHiGainSamples =  fRunHeader->GetNumSamplesHiGain();
     fNumLoGainSamples =  fRunHeader->GetNumSamplesLoGain();
- 
+
+    //
+    // FIXME: The next statement simply does not work: 
+    //        fRawEvt->GetNumPixels() returns always 0
+    // fCalibrations->InitSize(fRawEvt->GetNumPixels());
+    //
+
+    fCalibrations->InitSize(577);    
+
+    for (Int_t i=0;i<577;i++)
+      {
+        MCalibrationPix &pix = (*fCalibrations)[i];
+        pix.ChangePixId(i);
+      }
+    
     return kTRUE;
  
@@ -238,5 +237,5 @@
     fEvents++;
 
-    Bool_t cosmic = kFALSE;
+    Int_t cosmicpix = 0;
 
     MCalibrationBlindPix &blindpixel = *(fCalibrations->GetBlindPixel());
@@ -251,8 +250,4 @@
         const Int_t pixid = pixel.GetPixelId();
 
-        if (!fCalibrations->IsPixelUsed(pixid))
-          if (!fCalibrations->AddPixel(pixid)) 
-            *fLog << err << dbginf << "MCalibrationPix(" << pixid << ") could not be created !!" << endl;
-        
         Byte_t *ptr = pixel.GetHiGainSamples();
         Byte_t mid  = pixel.GetIdxMaxHiGainSample();
@@ -270,10 +265,12 @@
             mid = pixel.GetIdxMaxLoGainSample();
 
-            sum = (max == gkSaturationLimit              // overflow of LoGain ??? -> GimmeABreak!!!
-                   ? fHistOverFlow++, gkLoGainOverFlow   // OUCH (Florian was maybe right)
-                   : sum*gkConversionHiLo    );          // OUFF (Florian was wrong) !! 
-
-            //            *fLog << warn << "Warning: Saturation of HiGain reached in slice " << (int)mid << " !!! " << endl;
-            //            *fLog << warn << "Max = " << max << endl;
+            // 
+            //  FIXME: It seems the conversion HiGain LoGain is already
+            //         performed in the data?!?
+            //
+            sum = (max > gkSaturationLimit              // overflow of LoGain ??? -> GimmeABreak!!!
+                   ? fHistOverFlow++, gkLoGainOverFlow  // OUCH (Florian was maybe right)
+                   : sum  );                            // OUFF (Florian was wrong) !! 
+            //                   : sum*gkConversionHiLo    );          // OUFF (Florian was wrong) !! 
 
             if (fHistOverFlow) 
@@ -282,5 +279,4 @@
 
           }
-	
 
         MPedestalPix    &ped = (*fPedestals)[pixid];
@@ -298,5 +294,5 @@
 
 	// 
-	// This is a very primitive check for the number of cosmics
+	// This is a very primitive check for the number of cosmicpixs
 	// The cut will be applied in the fit, but for the blind pixel,
 	// we need to remove this event
@@ -305,6 +301,6 @@
 	//
 
-	if ((float)sum < pedes+5.*pedrms)
-           cosmic = kTRUE;
+	if ((float)sum < pedes+4.*pedrms)
+           cosmicpix++;
 
         Float_t rsum      = (float)sum - pedes;
@@ -314,21 +310,24 @@
             
           case gkCalibrationBlindPixelId:
+
 	    // 
 	    // FIXME: This works only when the blind pixel ID is much larger than 
 	    //        the rest of the pixels (which is the case right now)
 	    //
-//	    if (!cosmic)
-	       if (!blindpixel.FillQ(sum)) 
+            if (cosmicpix < 100.)
+              {
+                if (!blindpixel.FillQ(sum)) 
                   *fLog << warn << 
-                  "Overflow or Underflow occurred filling Blind Pixel sum = " << sum << endl;
-
-            if (!blindpixel.FillT((int)mid)) 
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling Blind Pixel time = " << (int)mid << endl;
-
-            if (!blindpixel.FillRQvsT(rsum,fEvents))
-              *fLog << warn << 
-                "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
-
+                    "Overflow or Underflow occurred filling Blind Pixel sum = " << sum << endl;
+
+                if (!blindpixel.FillT((int)mid)) 
+                  *fLog << warn << 
+                    "Overflow or Underflow occurred filling Blind Pixel time = " << (int)mid << endl;
+
+                if (!blindpixel.FillRQvsT(rsum,fEvents))
+                  *fLog << warn << 
+                    "Overflow or Underflow occurred filling Blind Pixel eventnr = " << fEvents << endl;
+              }
+            
           case gkCalibrationPINDiodeId:
             if (!pindiode.FillQ(sum)) 
@@ -364,9 +363,7 @@
       } /* while (pixel.Next()) */
 
-    if (cosmic)
+    if (cosmicpix > 300.)
 	fCosmics++;
 
-    fCalibrations->SetReadyToSave();
-    
     return kTRUE;
 }
@@ -405,4 +402,5 @@
 
   *fLog << GetDescriptor() << " Fitting the Normal Pixels" << endl;
+
   //
   // loop over the pedestal events and check if we have calibration
@@ -411,21 +409,15 @@
     {
 
-      if (fCalibrations->IsPixelUsed(pixid))
-        {
-
-          MCalibrationPix &pix = (*fCalibrations)[pixid];
-
-          const Float_t ped    = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
-          const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms() * fNumHiGainSamples;
-
-          pix.SetPedestal(ped,prms);
-
-          if (TESTBIT(fFlags,kUseTFits))
-            pix.FitT();
-
-          if (!pix.FitQ())
-             continue;
-
-        }
+      MCalibrationPix &pix = (*fCalibrations)[pixid];
+
+      const Float_t ped    = (*fPedestals)[pixid].GetPedestal() * fNumHiGainSamples;
+      const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms() * fNumHiGainSamples;
+
+      pix.SetPedestal(ped,prms);
+
+      if (TESTBIT(fFlags,kUseTFits))
+        pix.FitT();
+      
+      pix.FitQ();
     }
 
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2590)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCam.cc	(revision 2599)
@@ -61,5 +61,5 @@
     fTitle = title ? title : "Storage container for the Calibration Information in the camera";
 
-    fPixels     = new TClonesArray("MCalibrationPix",0);
+    fPixels     = new TClonesArray("MCalibrationPix",1);
     fBlindPixel = new MCalibrationBlindPix();
     fPINDiode   = new MCalibrationPINDiode();
@@ -92,7 +92,5 @@
 
   //
-  // Here it is important to use GetEntriesFast, 
-  // We get the array index of the last "filled" fPixel entry
-  // (Not the number of "filled" fPixels!!)
+  // Here we get the number of "filled" fPixels!!
   //
   return fPixels->GetEntriesFast();
@@ -116,22 +114,4 @@
     return *static_cast<MCalibrationPix*>(fPixels->UncheckedAt(i));
 }
-
-Bool_t MCalibrationCam::AddPixel(Int_t idx) 
-{
-
-  //
-  // Check bounds first
-  //
-  if (!CheckBounds(idx))
-    InitSize(idx);
-
-  //
-  // in case, new cannot allocate memory, 
-  // return FALSE
-  //
-  return (new ((*fPixels)[idx]) MCalibrationPix(idx));
-
-}
-
 
 // --------------------------------------------------------------------------
@@ -173,7 +153,4 @@
 Bool_t MCalibrationCam::IsPixelFitted(Int_t idx) const 
 {
-  if (!IsPixelUsed(idx))
-    return kFALSE;
-
   return ((*this)[idx].GetRQ() > 0. && (*this)[idx].GetErrRQ() > 0.);
 }
@@ -208,12 +185,8 @@
     {
 
-      Int_t id = 0;
-      
       TIter Next(fPixels);
       MCalibrationPix *pix;
       while ((pix=(MCalibrationPix*)Next()))
         {
-          if (!IsPixelUsed(id++))
-            continue;
           if (pix->FitQ())
             nsuccess++;
@@ -222,6 +195,4 @@
   else                  // fit only the pixel with index i
     {
-      if (!IsPixelUsed(i))
-        return 0;
       if((*this)[i].FitQ())
         nsuccess++;
@@ -247,12 +218,8 @@
   UShort_t nsuccess = 0;
 
-  Int_t id = 0;
-
   TIter Next(fPixels);
   MCalibrationPix *pix;
   while ((pix=(MCalibrationPix*)Next()))
     {
-      if (!IsPixelUsed(id++))
-        continue;
       if (pix->FitQ())
         nsuccess++;
@@ -293,13 +260,9 @@
     {
 
-      Int_t id = 0;
-      
       TIter Next(fPixels);
       MCalibrationPix *pix;
       while ((pix=(MCalibrationPix*)Next()))
         {
-          if (!IsPixelUsed(id++))
-            continue;
-          if (pix->FitT())
+         if (pix->FitT())
             nsuccess++;
         }
@@ -331,12 +294,8 @@
   UShort_t nsuccess = 0;
 
-  Int_t id = 0;
-
   TIter Next(fPixels);
   MCalibrationPix *pix;
   while ((pix=(MCalibrationPix*)Next()))
     {
-      if (!IsPixelUsed(id++))
-        continue;
       if (pix->FitT())
         nsuccess++;
@@ -391,15 +350,6 @@
   // we want to keep all pixel not used with a NULL pointer.
   //
-  fPixels->Expand(size);
-  //
-  // Set all entries to the null pointer.  
-  // Later we fill the array per pixId with the contruction: new (fPixels[i]) MCalibrationPix(pixid)
-  // To check, if pixels is already filled, we test the NULL pointer (see IsPixelUsed)
-  //
-  for (Int_t i=0; i< size; i++)
-    {
-      MCalibrationPix *pix = &(*this)[i];
-      pix = NULL;
-    }
+  fPixels->ExpandCreate(size);
+
 }
   
@@ -413,8 +363,6 @@
     while ((pix=(MCalibrationPix*)Next()))
     {
-        if (!IsPixelUsed(id))
-          continue;
-
-        *fLog << id << ": ";
+
+        *fLog << id << ": " << pix->GetPed() << " " << pix->GetPedRms() << " Charges: " ;
         *fLog << pix->GetQ() << " " << pix->GetRQ() << endl;
 
@@ -426,7 +374,4 @@
 Bool_t MCalibrationCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
 {
-
-  if (!IsPixelFitted(idx))
-    return kFALSE;
 
   switch (type)
@@ -468,4 +413,10 @@
       val = (*this)[idx].GetErrRQ();
       break;
+    case 12:
+      val = (*this)[idx].GetPheFFactorMethod();
+      break;
+    case 13:
+      val = (*this)[idx].GetConversionFFactorMethod();
+      break;
     default:
       return kFALSE;
@@ -474,7 +425,9 @@
 }
 
-void MCalibrationCam::DrawPixelContent(Int_t num) const
-{
-    *fLog << warn << "MCalibrationCam::DrawPixelContent - not available." << endl;
+void MCalibrationCam::DrawPixelContent(Int_t idx) const
+{
+
+  (*this)[idx].Draw();
+
 }
 
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h	(revision 2590)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationCam.h	(revision 2599)
@@ -77,6 +77,4 @@
   Bool_t CheckBounds(Int_t i) const;
 
-  Bool_t AddPixel(Int_t idx);
-
   void Print(Option_t *o="") const;
   
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2590)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.cc	(revision 2599)
@@ -40,11 +40,25 @@
 using namespace std;
 
-static const TString gsDefHTitle = "Calibration Histograms Pixel ";
 // --------------------------------------------------------------------------
 //
 // Default Constructor. 
 //
-MCalibrationPix::MCalibrationPix(Int_t pix, const char *name, const char *title)
-    : fPixId(pix)
+MCalibrationPix::MCalibrationPix(const char *name, const char *title)
+    : fPixId(-1),
+      fQ(-1.),
+      fErrQ(-1.),
+      fSigmaQ(-1.),
+      fErrSigmaQ(-1.),
+      fQProb(-1.),
+      fPed(-1.),
+      fPedRms(-1.),
+      fT(-1.),
+      fSigmaT(-1.),
+      fTProb(-1.),
+      fRQ(-1.),
+      fErrRQ(-1.),
+      fFactor(1.3),
+      fPheFFactorMethod(-1.),
+      fConversionFFactorMethod(-1.)
 {
 
@@ -52,13 +66,5 @@
   fTitle = title ? title : "Container of the MHCalibrationPixels and the fit results";
 
-  fHist = new MHCalibrationPixel(fPixId,"MHCalibrationPixel",gsDefHTitle.Data()+fPixId);
-
-  fQ   = fErrQ     = 0.;
-  fPed = fPedRms   = 0.;
-  fT   = fSigmaT  = 0.;
-  fRQ  = fErrRQ = 0.;
-  fSigmaQ = fErrSigmaQ = 0.;
-  fQProb  = 0.;
-
+  fHist = new MHCalibrationPixel("MHCalibrationPixel","Calibration Histograms Pixel");
 }
 
@@ -67,4 +73,14 @@
   delete fHist;
 }
+
+
+void MCalibrationPix::ChangePixId(Int_t i)
+{
+  
+  fPixId = i;
+  fHist->ChangeHistId(i);
+  
+}
+
 
 // ------------------------------------------------------------------------
@@ -84,5 +100,5 @@
 
   if (fPed && fPedRms)
-    fHist->SetLowerFitRange(fPed + 3.5*fPedRms);
+    fHist->SetLowerFitRange(fPed + 2.0*fPedRms);
   else
     *fLog << warn << "Cannot set lower fit range to suppress cosmics: Pedestals not available" << endl;
@@ -101,9 +117,18 @@
   fQProb     = fHist->GetQProb();
 
-  if (fPed)
+  if ((fPed > 0.)  && (fPedRms > 0.))
+    {
+      
     fRQ      = fQ - fPed;
-  if (fPedRms)
     fErrRQ   = TMath::Sqrt(fErrQ*fErrQ + fPedRms*fPedRms);
-  
+
+    fPheFFactorMethod = 
+      fFactor 
+      * fRQ * fRQ 
+      / (fSigmaQ * fSigmaQ - fPedRms*fPedRms) ;
+
+    fConversionFFactorMethod = fPheFFactorMethod / fRQ ;
+    
+    }
 
   return kTRUE;
@@ -142,6 +167,2 @@
 }
 
-void MCalibrationPix::Test()
-{
-  *fLog << "TEST: pixid: " << fPixId << endl;  
-}
Index: trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2590)
+++ trunk/MagicSoft/Mars/manalysis/MCalibrationPix.h	(revision 2599)
@@ -12,7 +12,4 @@
 private:
 
-  //
-  // FIXME: Derive class from MCerphotPix ??
-  //
   Int_t   fPixId;           // the pixel Id
   
@@ -32,10 +29,14 @@
   Float_t fRQ;               // The reduced mean charge after the fit
   Float_t fErrRQ;            // The error of the reduced mean charge after the fit  
-  
+
+  Float_t fFactor;            // The F-factor
+  Float_t fPheFFactorMethod;  // The number of Phe's calculated after the F-factor method
+  Float_t fConversionFFactorMethod; // The conversion factor to Phe's calculated after the F-factor method
+    
   MHCalibrationPixel *fHist; // Pointer to the histograms performing the fits, etc.  
   
 public:
 
-  MCalibrationPix(Int_t pix=-1, const char *name=NULL, const char *title=NULL);
+  MCalibrationPix(const char *name=NULL, const char *title=NULL);
   ~MCalibrationPix();
   
@@ -66,5 +67,6 @@
   Bool_t IsValid()      const           { return fRQ >=0 || fErrRQ >= 0; }
   Int_t  GetPixId()     const           { return fPixId;   }
-
+  void ChangePixId(Int_t i);
+  
   Bool_t FitQ();
   Bool_t FitT();
@@ -73,6 +75,7 @@
   virtual void Draw(Option_t *opt="")     { fHist->Draw(opt); }
   
-  void Test();
-    
+  Float_t GetPheFFactorMethod() const        { return fPheFFactorMethod;  }  
+  Float_t GetConversionFFactorMethod() const { return fConversionFFactorMethod;  }
+  
   ClassDef(MCalibrationPix, 1)	// Storage Container for Calibration information of one pixel
 };
Index: trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 2590)
+++ trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 2599)
@@ -60,7 +60,5 @@
 
     AddToBranchList("fHiGainPixId");
-    //AddToBranchList("fLoGainPixId");
     AddToBranchList("fHiGainFadcSamples");
-    //AddToBranchList("fLoGainFadcSamples");
 }
 
@@ -98,4 +96,6 @@
     fNumHiGainSamples =  fRunheader->GetNumSamplesHiGain();
 
+    fPedestals->InitSize(fRunheader->GetNumPixel());
+
     return kTRUE;
 
@@ -105,9 +105,10 @@
 Int_t MPedCalcPedRun::Process()
 {
+
     MRawEvtPixelIter pixel(fRawEvt);
 
     while (pixel.Next())
     {
-              Byte_t *ptr = pixel.GetHiGainSamples();
+             Byte_t *ptr = pixel.GetHiGainSamples();
         const Byte_t *end = ptr + fRawEvt->GetNumHiGainSamples();
 
@@ -115,12 +116,9 @@
         const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
 
-        //const Float_t higainpederr = CalcHiGainMeanErr(higainrms);
-        //const Float_t higainrmserr = CalcHiGainRmsErr(higainrms);
-
         const UInt_t pixid = pixel.GetPixelId();
         MPedestalPix &pix = (*fPedestals)[pixid];
 
         pix.Set(higainped, higainrms);
-       //pix.SetPedestalRms(higainpederr, higainrmserr);
+
     }
 
