Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 1091)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 1092)
@@ -45,4 +45,5 @@
 #include "MLogManip.h"
 
+#include "MRawRunHeader.h"
 #include "MRawEvtData.h"       // MRawEvtData::GetNumPixels
 #include "MCerPhotEvt.h"
@@ -66,4 +67,5 @@
     AddToBranchList("fHiGainFadcSamples");
     AddToBranchList("fLoGainFadcSamples");
+
 }
 
@@ -71,4 +73,5 @@
 //
 // The PreProcess searches for the following input containers:
+//  - MRawRunHeader
 //  - MRawEvtData
 //  - MPedestalCam
@@ -80,4 +83,13 @@
 Bool_t MCerPhotCalc::PreProcess(MParList *pList)
 {
+    MRawRunHeader *RunHeader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!RunHeader)
+    {
+        *fLog << dbginf << "MRawRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+    fNumLoGainFadcSlices= RunHeader->GetNumSamplesLoGain();
+    fNumHiGainFadcSlices= RunHeader->GetNumSamplesHiGain();
+
     fRawEvt = (MRawEvtData*)pList->FindObject("MRawEvtData");
     if (!fRawEvt)
@@ -103,5 +115,5 @@
 // --------------------------------------------------------------------------
 //
-// Calculate the integral of the FADC time slaices and store them as a new
+// Calculate the integral of the FADC time slices and store them as a new
 // pixel in the MCerPhotEvt container.
 //
@@ -111,13 +123,17 @@
 
     MRawEvtPixelIter pixel(fRawEvt);
+
     while (pixel.Next())
     {
+
         const UInt_t pixid = pixel.GetPixelId();
 
         const MPedestalPix &ped = (*fPedestals)[pixid];
 
-        const Float_t nphot = (Float_t)pixel.GetSumHiGainSamples() - ped.GetMean();
+        Float_t nphot = (Float_t)pixel.GetSumHiGainSamples();
 
-        fCerPhotEvt->AddPixel(pixid, nphot, ped.GetMeanRms());
+	if(nphot>0) nphot -= fNumHiGainFadcSlices*ped.GetMean();
+
+        fCerPhotEvt->AddPixel(pixid, nphot, sqrt(fNumHiGainFadcSlices)*ped.GetMeanRms());
 
         // FIXME! Handling of Lo Gains is missing!
@@ -128,3 +144,2 @@
     return kTRUE;
 }
-
