Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 3554)
+++ trunk/MagicSoft/Mars/Changelog	(revision 3555)
@@ -46,4 +46,9 @@
    * mcalib/MCalibrationChargeCalc.[h,cc]
      - added MCalibrationQECam
+
+   * mcalib/MCalibrationChargePix.[h,cc]
+     - took out fNumLoGainSampels whihc is not needed any more because 
+       conversion is only done in the getters
+     - Canceled function ApplyLoGainConversion (for same reason)
 
 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3554)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.cc	(revision 3555)
@@ -389,13 +389,58 @@
 
 
-// --------------------------------------------------------------------------
-//
-// Calculate the integral of the FADC time slices and store them as a new
-// pixel in the MCerPhotEvt container.
-//
 Int_t MCalibrationChargeCalc::Process()
 {
   return kTRUE;
 }
+
+// --------------------------------------------------------------------------
+//  
+// Finalize pedestals: 
+// 
+// * Retrieve pedestal and pedestal RMS from MPedestalPix
+// * Retrieve total entries from MPedestalCam
+// * sum up pedestal and pedestalRMS for the average pixel
+// * set pedestal*number of used samples in MCalibrationChargePix
+// * set pedestal RMS * sqrt of number of used samples in MCalibrationChargePix
+// 
+//
+void MCalibrationChargeCalc::FinalizePedestals(MPedestalPix &ped, MCalibrationChargePix &cal,
+                                               Float_t &avped, Float_t &avrms, Float_t &avnum)
+{
+  
+  //
+  // get the pedestals
+  //
+  const Float_t pedes  = ped.GetPedestal();
+  const Float_t prms   = ped.GetPedestalRms();
+  const Float_t num    = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
+
+  //
+  // Calculate the average pedestal
+  //
+  avped += pedes;
+  avrms += prms;
+  avnum++;
+  
+  //
+  // set them in the calibration camera
+  //
+  if (cal.IsHiGainSaturation())
+    {
+      cal.SetPedestal(pedes* fNumLoGainSamples,
+                      prms * fSqrtLoGainSamples,
+                      prms * fNumLoGainSamples / num);
+      cal.CalcLoGainPedestal((Float_t)fNumLoGainSamples);
+    }
+  else
+    {
+      cal.SetPedestal(pedes* fNumHiGainSamples,
+                      prms * fSqrtHiGainSamples,
+                      prms * fNumHiGainSamples / num);
+    }
+  
+}
+
+
 
 Int_t MCalibrationChargeCalc::PostProcess()
@@ -417,6 +462,4 @@
 
       MCalibrationChargePix &pix = (*fCam)[pixid];
-      MBadPixelsPix         &bad = (*fBadPixels)[pixid];
-
       //
       // Check if the pixel has been excluded from the fits
@@ -425,40 +468,14 @@
         continue;
 
-      //
-      // get the pedestals
-      //
-      const Float_t ped    = (*fPedestals)[pixid].GetPedestal();
-      const Float_t prms   = (*fPedestals)[pixid].GetPedestalRms();
-      const Float_t num    = TMath::Sqrt((Float_t)fPedestals->GetTotalEntries());
+      MPedestalPix &ped = (*fPedestals)[pixid];
+
 
       if (fGeom->GetPixRatio(pixid) == 1.)
-      {
-	  avinnerped  += ped;
-	  avinnerprms += prms;
-	  avinnernum++;
-      }
+        FinalizePedestals(ped,pix,avinnerped,avinnerprms,avinnernum);
       else
-      {
-	  avouterped  += ped;
-	  avouterprms += prms;
-	  avouternum++;
-      }
-      //
-      // set them in the calibration camera
-      //
-      if (pix.IsHiGainSaturation())
-      {
-	  pix.SetPedestal(ped  * fNumLoGainSamples,
-			  prms * fSqrtLoGainSamples,
-			  prms * fNumLoGainSamples / num);
-	  pix.SetNumLoGainSamples(fNumLoGainSamples);
-          pix.ApplyLoGainConversion();
-      }
-      else
-      {
-	  pix.SetPedestal(ped  * fNumHiGainSamples,
-			  prms * fSqrtHiGainSamples,
-			  prms * fNumHiGainSamples / num);
-      }
+        FinalizePedestals(ped,pix,avouterped,avouterprms,avouternum);
+
+
+      MBadPixelsPix         &bad = (*fBadPixels)[pixid];
 
       pix.CheckChargeValidity (&bad);
@@ -509,6 +526,5 @@
 			      avinnerprms/avinnernum * fSqrtLoGainSamples,
 			      avinnerprms/avinnernum * fSqrtLoGainSamples/avinnernum);
-      avinnerpix->SetNumLoGainSamples(fNumLoGainSamples);
-      avinnerpix->ApplyLoGainConversion();
+      avinnerpix->CalcLoGainPedestal((Float_t)fNumLoGainSamples);
   }
   else
@@ -524,6 +540,5 @@
 			      avouterprms/avouternum * fSqrtLoGainSamples,
 			      avouterprms/avouternum * fSqrtLoGainSamples/avouternum);
-      avouterpix->SetNumLoGainSamples(fNumLoGainSamples);
-      avouterpix->ApplyLoGainConversion();
+      avouterpix->CalcLoGainPedestal((Float_t)fNumLoGainSamples);
   }
   else
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 3554)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargeCalc.h	(revision 3555)
@@ -18,6 +18,8 @@
 class MRawRunHeader;
 class MPedestalCam;
+class MPedestalPix;
 class MCalibrationChargePINDiode;
 class MCalibrationChargeBlindPix;
+class MCalibrationChargePix;
 class MCalibrationChargeCam;
 class MCalibrationQECam;
@@ -59,4 +61,8 @@
   Int_t  Process();
   Int_t  PostProcess();
+
+  void FinalizePedestals(MPedestalPix &ped, MCalibrationChargePix &cal,
+                         Float_t &avped, Float_t &avrms, Float_t &avnum);
+  
   
 public:
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 3554)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.cc	(revision 3555)
@@ -177,6 +177,4 @@
   fLoGainNumPickup                  =  -1;
 
-  fNumLoGainSamples                 =  -1.;
-
   fPed                              =  -1.;
   fPedRms                           =  -1.;
@@ -708,42 +706,4 @@
 }
 
-void MCalibrationChargePix::CalcLoGainPed()
-{
-
-    Float_t pedRmsSquare      = fPedRms * fPedRms;
-    Float_t pedRmsSquareVar   = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
-    
-    //
-    // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it 
-    // from the HI GAIN (all calculation per slice up to now):  
-    //
-    // We extract the pure NSB contribution:
-    //
-    const Float_t elecRmsSquare    =    fElectronicPedRms    * fElectronicPedRms;
-    const Float_t elecRmsSquareVar = 4.*fElectronicPedRmsVar * elecRmsSquare;
-    
-    Float_t nsbSquare             =  pedRmsSquare    - elecRmsSquare;
-    Float_t nsbSquareRelVar       = (pedRmsSquareVar + elecRmsSquareVar)
-                                	/ (nsbSquare * nsbSquare) ;
-    
-    if (nsbSquare < 0.)
-      nsbSquare = 0.;
-    
-    //
-    // Now, we divide the NSB by the conversion factor and 
-    // add it quadratically to the electronic noise
-    //
-    const Float_t conversionSquare        =    fConversionHiLo    * fConversionHiLo;
-    const Float_t convertedNsbSquare      =    nsbSquare       / conversionSquare;
-    const Float_t convertedNsbSquareVar   =    nsbSquareRelVar
-                                    	    * convertedNsbSquare * convertedNsbSquare;
-    
-    pedRmsSquare     = convertedNsbSquare    + elecRmsSquare;
-    pedRmsSquareVar  = convertedNsbSquareVar + elecRmsSquareVar;
-    
-    fLoGainPedRms    = TMath::Sqrt(pedRmsSquare);
-    fLoGainPedRmsVar = 0.25 * pedRmsSquareVar /  pedRmsSquare;
-
-}
 
 //
@@ -844,12 +804,46 @@
 
 
-void MCalibrationChargePix::ApplyLoGainConversion()
-{
-  
-  fElectronicPedRms       = gkElectronicPedRms    * TMath::Sqrt(fNumLoGainSamples);
-  fElectronicPedRmsVar    = gkElectronicPedRmsErr * gkElectronicPedRmsErr * fNumLoGainSamples;
-  
-  CalcLoGainPed();
-}
-
-
+void MCalibrationChargePix::CalcLoGainPedestal(Float_t logainsamples)
+{
+
+  fElectronicPedRms       = gkElectronicPedRms    * TMath::Sqrt(logainsamples);
+  fElectronicPedRmsVar    = gkElectronicPedRmsErr * gkElectronicPedRmsErr * logainsamples;
+  
+  Float_t pedRmsSquare      = fPedRms * fPedRms;
+  Float_t pedRmsSquareVar   = fPedVar * pedRmsSquare; // fPedRmsErr = fPedErr/2.
+  
+  //
+  // We do not know the Lo Gain Pedestal RMS, so we have to retrieve it 
+  // from the HI GAIN (all calculation per slice up to now):  
+  //
+  // We extract the pure NSB contribution:
+  //
+  const Float_t elecRmsSquare    =    fElectronicPedRms    * fElectronicPedRms;
+  const Float_t elecRmsSquareVar = 4.*fElectronicPedRmsVar * elecRmsSquare;
+  
+  Float_t nsbSquare             =  pedRmsSquare    - elecRmsSquare;
+  Float_t nsbSquareRelVar       = (pedRmsSquareVar + elecRmsSquareVar)
+                                 / (nsbSquare * nsbSquare) ;
+  
+  if (nsbSquare < 0.)
+    nsbSquare = 0.;
+  
+  //
+  // Now, we divide the NSB by the conversion factor and 
+  // add it quadratically to the electronic noise
+  //
+  const Float_t conversionSquare        =    fConversionHiLo    * fConversionHiLo;
+  const Float_t convertedNsbSquare      =    nsbSquare       / conversionSquare;
+  const Float_t convertedNsbSquareVar   =    nsbSquareRelVar
+                                	    * convertedNsbSquare * convertedNsbSquare;
+    
+  pedRmsSquare     = convertedNsbSquare    + elecRmsSquare;
+  pedRmsSquareVar  = convertedNsbSquareVar + elecRmsSquareVar;
+  
+  fLoGainPedRms    = TMath::Sqrt(pedRmsSquare);
+  fLoGainPedRmsVar = 0.25 * pedRmsSquareVar /  pedRmsSquare;
+  
+}
+ 
+ 
+ 
Index: trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.h
===================================================================
--- trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.h	(revision 3554)
+++ trunk/MagicSoft/Mars/mcalib/MCalibrationChargePix.h	(revision 3555)
@@ -109,8 +109,6 @@
   Float_t fConversionHiLoVar;               // The error of the conversion factor between Hi Gain and Lo Gain  
 
-  Float_t fNumLoGainSamples;
-
-  Float_t   fHiGainNumPickup;
-  Float_t   fLoGainNumPickup;
+  Float_t fHiGainNumPickup;
+  Float_t fLoGainNumPickup;
 
   enum  { kHiGainSaturation, kLoGainSaturation,
@@ -121,6 +119,4 @@
 	  kPINDiodeMethodValid, kCombinedMethodValid };
 
-  void CalcLoGainPed();
-  
 public:
 
@@ -170,6 +166,4 @@
   void SetAbsTimeMean           ( const Float_t f ) { fAbsTimeMean           = f; }
   void SetAbsTimeRms            ( const Float_t f ) { fAbsTimeRms            = f; }
-
-  void SetNumLoGainSamples      ( const Float_t f ) { fNumLoGainSamples      = f; }
 
   // Conversion Factors
@@ -283,8 +277,8 @@
 
   // Miscellaneous
-  void  ApplyLoGainConversion();
-
   void CheckChargeValidity ( MBadPixelsPix *bad );
   void CheckTimeValidity   ( MBadPixelsPix *bad );
+
+  void  CalcLoGainPedestal(const Float_t logainsamples);
   Bool_t CalcReducedSigma();
   Bool_t CalcFFactorMethod();
