Index: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 1290)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 1291)
@@ -44,4 +44,6 @@
 #include "MLog.h"
 #include "MLogManip.h"
+
+#include "MMcRunHeader.hxx"
 
 #include "MRawRunHeader.h"
@@ -113,4 +115,35 @@
 // --------------------------------------------------------------------------
 //
+// Check for the run type and camera version.
+// If the file is a MC file and the used camera version is <= 40
+// we enable a fix for truncated pedestal means in this version.
+//
+Bool_t MCerPhotCalc::ReInit(MParList *pList)
+{
+    const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!runheader)
+    {
+        *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
+        return kTRUE;
+    }
+
+    if (runheader->GetRunType() != kRTMonteCarlo)
+        return kTRUE;
+
+    MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
+    if (!mcrunheader)
+    {
+        *fLog << warn << dbginf << "Warning - cannot check for camera version, MC run header not found." << endl;
+        return kTRUE;
+    }
+
+    if (mcrunheader->GetCamVersion() <= 40)
+        fEnableFix = kTRUE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
 // Calculate the integral of the FADC time slices and store them as a new
 // pixel in the MCerPhotEvt container.
@@ -144,6 +177,7 @@
         // 0 signal in all the slices.
         //
+        const Double_t mean = fEnableFix ? ped.GetMean()-0.5 : ped.GetMean();
         if (nphot!=0)
-            nphot -= fRunHeader->GetNumSamplesHiGain()*ped.GetMean();
+            nphot -= fRunHeader->GetNumSamplesHiGain()*mean;
 
         fCerPhotEvt->AddPixel(pixid, nphot, sqrt(fRunHeader->GetNumSamplesHiGain())*ped.GetSigma());
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.h	(revision 1290)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.h	(revision 1291)
@@ -26,5 +26,7 @@
     MCerPhotEvt   *fCerPhotEvt; // Cerenkov Photon Event used for calculation
     MRawRunHeader *fRunHeader;  //  RunHeader information
- 
+
+    Bool_t         fEnableFix;  // fix for a bug in files from older camera versions (<=40)
+
 public:
     MCerPhotCalc(const char *name=NULL, const char *title=NULL);
@@ -33,4 +35,6 @@
     Bool_t Process();
 
+    Bool_t ReInit(MParList *pList);
+
     ClassDef(MCerPhotCalc, 0)   // Task to calculate cerenkov photons from raw data
 };
Index: trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.hxx
===================================================================
--- trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.hxx	(revision 1290)
+++ trunk/MagicSoft/include-Classes/MMcFormat/MMcRunHeader.hxx	(revision 1291)
@@ -135,5 +135,7 @@
   void GetStarFieldRa(Int_t *hour, Int_t *minute, Int_t *second) const;
   void GetStarFieldDec(Int_t *degree, Int_t *minute, Int_t *second) const;
-  
+
+  UShort_t GetCamVersion() const { return fCamVersion; }
+
   ClassDef(MMcRunHeader, 2)	// storage container for general info
 };
