Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 2236)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 2237)
@@ -35,4 +35,50 @@
      - added GetNumMaxLoGainSample
 
+   * manalysis/MCT1PadSchweizer.cc, manalysis/MMcPedestalNSBAdd.cc,
+     manalysis/MSigmabar.cc:
+     - adapted to new function names in MPedestalPix
+     
+   * manalysis/MCerPhotAnal.cc:
+     - adapted to new function names in MPedestalPix
+     - fixed to work with real data and monte carlo data
+     - preliminarily removed error of pedestal and pedestalrms
+     
+   * manalysis/MCerPhotCalc.[h,cc]:
+     - adapted to new function names in MPedestalPix
+     - fixed to work with real data and monte carlo data
+   
+   * manalysis/MMcPedestalCopy.cc, manalysis/MPedCalcPedRun.[h,cc]:
+     - adapted to new function names in MPedestalPix
+     - preliminarily removed error of pedestal and pedestalrms
+ 
+   * manalysis/MPedestalCam.[h,cc]:
+     - adapted to new function names in MPedestalPix
+     - preliminarily removed error of pedestal and pedestalrms
+     - fixed GetPixelContent (do not return Pedestal*PixRatio)
+     
+   * manalysis/MPedestalPix.[h,cc]:
+     - removed old variables
+     - introduced Pedestal for pedestal
+     - introduced pedestalRMS for the rms of the pedestal
+     - error of both values still missing
+     
+   * meventdisp/MGCamDisplay.cc:
+     - fixed display, displays now:
+       + Number Of Photons
+       + Pedestal
+       + PedestalRMS
+       + Number of Photons/PedestalRMS
+       
+   * mimage/MImgCleanStd.[h,cc]:
+     - fixed image cleaning in the sense that erronously the error
+       of the number of photons was used instead of the error of
+       the PMT offset (pedestal)
+     - introduced some debugging option
+     
+   * mmontecarlo/MMcCollectionAreaCalc.cc:
+     - minor change
+     
+
+  
 
 
Index: /trunk/MagicSoft/Mars/manalysis/MCT1PadSchweizer.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCT1PadSchweizer.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MCT1PadSchweizer.cc	(revision 2237)
@@ -293,5 +293,5 @@
       continue;
 
-    fEvt->AddPixel(i, 0.0, (*fPed)[i].GetMeanRms());
+    fEvt->AddPixel(i, 0.0, (*fPed)[i].GetPedestalRms());
   }
 
@@ -543,5 +543,5 @@
 
     MPedestalPix &ppix = (*fPed)[j];
-    Double_t oldsigma = ppix.GetMeanRms();
+    Double_t oldsigma = ppix.GetPedestalRms();
     Double_t oldsigma2 = oldsigma*oldsigma;
 
@@ -691,5 +691,5 @@
     Double_t oldphotons = pix.GetNumPhotons();
     Double_t newphotons = oldphotons + NSB;
-    pix.SetNumPhotons(	newphotons );
+    pix.SetNumPhotons(newphotons);
 
 
@@ -700,12 +700,12 @@
     // error: add sigma of padded noise quadratically
     Double_t olderror = pix.GetErrorPhot();
-    Double_t newerror = sqrt( olderror*olderror + addSig2 );
-    pix.SetErrorPhot( newerror );
-
-
-    Double_t newsigma = sqrt( oldsigma2 + addSig2 ); 
-    ppix.SetMeanRms( newsigma );
-
-    fHSigmaPedestal->Fill( oldsigma, newsigma );
+    Double_t newerror = sqrt(olderror*olderror + addSig2);
+    pix.SetErrorPhot(newerror);
+
+
+    Double_t newsigma = sqrt(oldsigma2 + addSig2);
+    ppix.SetPedestalRms(newsigma);
+
+    fHSigmaPedestal->Fill(oldsigma, newsigma);
   } 
   //----------   end of loop over pixels   ---------------------------------
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotAnal.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotAnal.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotAnal.cc	(revision 2237)
@@ -99,13 +99,20 @@
     }
 
-    fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
-    if (!fPedestals)
-    {
-        *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
-        return kFALSE;
-    }
-
     fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
     if (!fCerPhotEvt)
+        return kFALSE;
+
+    const MRawRunHeader *runheader = (MRawRunHeader*)pList->FindObject("MRawRunHeader");
+    if (!runheader)
+        *fLog << warn << dbginf << "Warning - cannot check file type, MRawRunHeader not found." << endl;
+    else
+        if (runheader->GetRunType() == kRTMonteCarlo)
+        {
+            fPedestals=NULL;
+            return kTRUE;
+        }
+
+    fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
+    if (runheader && !fPedestals)
         return kFALSE;
 
@@ -184,10 +191,8 @@
 	const UInt_t pixid = pixel.GetPixelId();
 
-        MPedestalPix &ped = (*fPedestals)[pixid];
-
 	//
 	// sanity check (old MC files sometimes have pixids>577)
 	//
-        if (!fPedestals->CheckBounds(pixid))
+        if (fPedestals && !fPedestals->CheckBounds(pixid))
         {
 	    *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
@@ -196,8 +201,12 @@
 
         fCerPhotEvt->AddPixel(pixid, nphot, sigmaped/2.236);
-	ped.SetPedestal(pedes, sigmaped);
-	ped.SetPedestalRms(sigmaped/sqrt(fRawEvt->GetNumHiGainSamples()-5.),
-			   sigmaped/sqrt(2.*(fRawEvt->GetNumHiGainSamples()-5)));
-
+
+        if (fPedestals)
+            (*fPedestals)[pixid].Set(pedes, sigmaped);
+
+        /*
+         ped.SetPedestalRms(sigmaped/sqrt(fRawEvt->GetNumHiGainSamples()-5.),
+                            sigmaped/sqrt(2.*(fRawEvt->GetNumHiGainSamples()-5)));
+                            */
         // FIXME! Handling of Lo Gains is missing!
     }
@@ -206,4 +215,7 @@
     fCerPhotEvt->SetReadyToSave();
 
+    if (fPedestals)
+        fPedestals->SetReadyToSave();
+
     return kTRUE;
 }
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 2237)
@@ -107,5 +107,8 @@
     fPedestals = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
     if (!fPedestals)
-        return kFALSE;
+    {
+        *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
+        return kFALSE;
+    }
 
     fCerPhotEvt = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
@@ -148,6 +151,9 @@
     }
 
-    if (runheader->GetRunType() != kRTMonteCarlo)
+    Bool_t fIsMcFile = runheader->GetRunType() == kRTMonteCarlo;
+    if (!fIsMcFile)
         return kTRUE;
+
+    ScalePedestals();
 
     MMcRunHeader *mcrunheader = (MMcRunHeader*)pList->FindObject("MMcRunHeader");
@@ -165,4 +171,19 @@
 }
 
+void MCerPhotCalc::ScalePedestals()
+{
+    Int_t n = 577; //FIXME: fPedestals->GetNumPixel();
+
+    for (int idx=0; idx<n; idx++)
+    {
+        MPedestalPix &ped = (*fPedestals)[idx];
+
+        const Double_t offset = fEnableFix ? ped.GetPedestal()-0.5 : ped.GetPedestal();
+        ped.Set(offset*fSumWeights, ped.GetPedestalRms()*fSumQuadWeights);
+    }
+
+    fPedestals->SetReadyToSave();
+}
+
 // --------------------------------------------------------------------------
 //
@@ -174,24 +195,22 @@
     //fCerPhotEvt->InitSize(fRawEvt->GetNumPixels());
 
+    if (fIsMcFile)
+        ScalePedestals();
+
     MRawEvtPixelIter pixel(fRawEvt);
 
     while (pixel.Next())
     {
-        const UInt_t pixid = pixel.GetPixelId();
-        const MPedestalPix &ped = (*fPedestals)[pixid];
+        const UInt_t idx = pixel.GetPixelId();
+        MPedestalPix &ped = (*fPedestals)[idx];
 
 	//
 	// sanity check (old MC files sometimes have pixids>577)
 	//
-        if (!fPedestals->CheckBounds(pixid))
+        if (!fPedestals->CheckBounds(idx))
         {
-	    *fLog << inf << "Pixel ID larger than camera... skipping event." << endl;
+	    *fLog << inf << "Pixel Index larger than camera... skipping event." << endl;
 	    return kCONTINUE;
 	}
-
-        //
-        // Mean pedestal:
-        //
-        const Double_t mean = fEnableFix ? ped.GetMean()-0.5 : ped.GetMean();
 
         //
@@ -204,9 +223,7 @@
             nphot += ptr[i]*fWeight[i];
 
-        nphot -= mean*fSumWeights;
-
-        const Float_t nphoterr = ped.GetSigma()* fSumQuadWeights;
-
-        fCerPhotEvt->AddPixel(pixid, nphot, nphoterr);
+        nphot -= ped.GetPedestal();
+
+        fCerPhotEvt->AddPixel(idx, nphot, 0);
 
         // FIXME! Handling of Lo Gains is missing!
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.h	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.h	(revision 2237)
@@ -31,4 +31,5 @@
  
     Bool_t          fEnableFix;  // fix for a bug in files from older camera versions (<=40)
+    Bool_t          fIsMcFile;
 
     TArrayF         fWeight;  // Weights for adding up the ADC slices
@@ -42,4 +43,5 @@
 
     Bool_t ReInit(MParList *pList);
+    void ScalePedestals();
 
 public:
Index: /trunk/MagicSoft/Mars/manalysis/MMcPedestalCopy.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMcPedestalCopy.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MMcPedestalCopy.cc	(revision 2237)
@@ -138,11 +138,11 @@
 
         const Float_t pedest = fMcPed->GetPedestal(i);
-        const Float_t pedrms = pedest/sqrt((float)num);
+        //const Float_t pedrms = pedest/sqrt((float)num);
 
         const Float_t sigma  = fMcPed->GetPedestalRms(i);
-        const Float_t sigrms = sigma/sqrt(num*2.);
+        //const Float_t sigrms = sigma/sqrt(num*2.);
 
-	pix.SetPedestal(pedest, sigma);
-        pix.SetPedestalRms(pedrms, sigrms);
+        //pix.SetPedestalRms(pedrms, sigrms);
+        pix.Set(pedest, sigma);
     }
 
Index: /trunk/MagicSoft/Mars/manalysis/MMcPedestalNSBAdd.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMcPedestalNSBAdd.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MMcPedestalNSBAdd.cc	(revision 2237)
@@ -215,9 +215,9 @@
         MPedestalPix &pix    = (*fPedCam)[i];
 
-        const Float_t pedrms = pix.GetSigma();
+        const Float_t pedrms = pix.GetPedestalRms();
         const Float_t ratio  = fGeom->GetPixRatio(i);
         const Float_t ampl   = fFadc->GetAmplitud();
 
-	pix.SetSigma(sqrt(pedrms*pedrms + dnsbpix*ampl*ampl/ratio));
+	pix.SetPedestalRms(sqrt(pedrms*pedrms + dnsbpix*ampl*ampl/ratio));
     }
 
Index: /trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.cc	(revision 2237)
@@ -95,12 +95,12 @@
         const Float_t higainrms = CalcHiGainRms(ptr, end, higainped);
 
-        const Float_t higainpederr = CalcHiGainMeanErr(higainrms);
-        const Float_t higainrmserr = CalcHiGainRmsErr(higainrms);
+        //const Float_t higainpederr = CalcHiGainMeanErr(higainrms);
+        //const Float_t higainrmserr = CalcHiGainRmsErr(higainrms);
 
         const UInt_t pixid = pixel.GetPixelId();
         MPedestalPix &pix = (*fPedestals)[pixid];
 
-        pix.SetPedestal(higainped, higainrms);
-        pix.SetPedestalRms(higainpederr, higainrmserr);
+        pix.Set(higainped, higainrms);
+        //pix.SetPedestalRms(higainpederr, higainrmserr);
     }
 
@@ -132,7 +132,7 @@
     } while (++ptr != end);
 
-    return sqrt(rms/(fNumHiGainSamples-1));
+    return sqrt(rms/fNumHiGainSamples);
 }
-
+/*
 Float_t MPedCalcPedRun::CalcHiGainMeanErr(Float_t higainrms) const
 {
@@ -144,3 +144,3 @@
     return higainrms/sqrt(2.*fNumHiGainSamples);
 }
-
+*/
Index: /trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MPedCalcPedRun.h	(revision 2237)
@@ -26,6 +26,6 @@
     Float_t CalcHiGainMean(Byte_t *ptr, const Byte_t *end) const;
     Float_t CalcHiGainRms(Byte_t *ptr, const Byte_t *end, Float_t higainped) const;
-    Float_t CalcHiGainMeanErr(Float_t higainrms) const;
-    Float_t CalcHiGainRmsErr(Float_t higainrms) const;
+    //Float_t CalcHiGainMeanErr(Float_t higainrms) const;
+    //Float_t CalcHiGainRmsErr(Float_t higainrms) const;
 
     Int_t PreProcess(MParList *pList);
Index: /trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MPedestalCam.cc	(revision 2237)
@@ -133,15 +133,14 @@
 
         *fLog << id-1 << ": ";
-        *fLog << pix->GetMean() << " " << pix->GetSigma() << " ";
-        *fLog << pix->GetMeanRms() << " " << pix->GetSigmaRms() << endl;
+        *fLog << pix->GetPedestal() << " " << pix->GetPedestalRms() << endl;
     }
 }
 
-Float_t MPedestalCam::GetMeanMin(const MGeomCam *geom) const
+Float_t MPedestalCam::GetPedestalMin(const MGeomCam *geom) const
 {
     if (fArray->GetEntries() <= 0)
         return 50.;
 
-    Float_t minval = (*this)[0].GetMean();
+    Float_t minval = (*this)[0].GetPedestalRms();
 
     for (Int_t i=1; i<fArray->GetEntries(); i++)
@@ -149,5 +148,5 @@
         const MPedestalPix &pix = (*this)[i];
 
-        Float_t testval = pix.GetMean();
+        Float_t testval = pix.GetPedestalRms();
 
         if (geom)
@@ -160,10 +159,10 @@
 }
 
-Float_t MPedestalCam::GetMeanMax(const MGeomCam *geom) const
+Float_t MPedestalCam::GetPedestalMax(const MGeomCam *geom) const
 {
     if (fArray->GetEntries() <= 0)
         return 50.;
 
-    Float_t maxval = (*this)[0].GetMean();
+    Float_t maxval = (*this)[0].GetPedestalRms();
 
     for (Int_t i=1; i<fArray->GetEntries(); i++)
@@ -171,5 +170,5 @@
         const MPedestalPix &pix = (*this)[i];
 
-        Float_t testval = pix.GetMean();
+        Float_t testval = pix.GetPedestalRms();
 
         if (geom)
@@ -184,5 +183,13 @@
 Bool_t MPedestalCam::GetPixelContent(Double_t &val, Int_t idx, const MGeomCam &cam, Int_t type) const
 {
-    val = (*this)[idx].GetMean()*cam.GetPixRatio(idx);
+    switch (type)
+    {
+    case 0:
+        val = (*this)[idx].GetPedestal();
+        break;
+    case 1:
+        val = (*this)[idx].GetPedestalRms();
+        break;
+    }
     return kTRUE;
 }
Index: /trunk/MagicSoft/Mars/manalysis/MPedestalCam.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedestalCam.h	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MPedestalCam.h	(revision 2237)
@@ -28,6 +28,6 @@
     MPedestalPix &operator[](Int_t i) const;
 
-    Float_t GetMeanMin(const MGeomCam *cam) const;
-    Float_t GetMeanMax(const MGeomCam *cam) const;
+    Float_t GetPedestalMin(const MGeomCam *cam) const;
+    Float_t GetPedestalMax(const MGeomCam *cam) const;
 
     Bool_t CheckBounds(Int_t i);
Index: /trunk/MagicSoft/Mars/manalysis/MPedestalPix.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedestalPix.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MPedestalPix.cc	(revision 2237)
@@ -48,8 +48,6 @@
 void MPedestalPix::Clear(Option_t *o)
 {
-    fMean = -1;
-    fSigma = -1;
-    fMeanRms = -1;
-    fSigmaRms = -1;
+    fPedestal = -1;
+    fPedestalRms = -1;
 }
 
Index: /trunk/MagicSoft/Mars/manalysis/MPedestalPix.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MPedestalPix.h	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MPedestalPix.h	(revision 2237)
@@ -9,8 +9,6 @@
 {
 private:
-    Float_t fMean;     // mean value of pedestal (PMT offset)
-    Float_t fSigma;    // sigma (standard deviation) of pedestal
-    Float_t fMeanRms;  // root mean square of pedestal
-    Float_t fSigmaRms; // root mean sqare of sigma of the pedestal
+    Float_t fPedestal;     // mean value of pedestal (PMT offset)
+    Float_t fPedestalRms;  // root mean square / sigma  / standard deviation of pedestal
 
 public:
@@ -19,18 +17,18 @@
     void Clear(Option_t *o="");
 
-    Float_t GetMean() const     { return fMean;     }
-    Float_t GetSigma() const    { return fSigma;    }
-    Float_t GetMeanRms() const  { return fMeanRms;  }
-    Float_t GetSigmaRms() const { return fSigmaRms; }
-
+    Float_t GetPedestal() const    { return fPedestal; }
+    Float_t GetPedestalRms() const { return fPedestalRms; }
+/*
     void SetMean(Float_t f)     { fMean = f;     }
     void SetSigma(Float_t f)    { fSigma = f;    }
     void SetMeanRms(Float_t f)  { fMeanRms = f;  }
     void SetSigmaRms(Float_t f) { fSigmaRms = f; }
+    */
 
-    void SetPedestal(Float_t m, Float_t s) { fMean = m; fSigma = s; }
-    void SetPedestalRms(Float_t m, Float_t s) { fMeanRms = m; fSigmaRms = s; }
+    void SetPedestal(Float_t f)    { fPedestal = f; }
+    void SetPedestalRms(Float_t f) { fPedestalRms = f; }
+    void Set(Float_t m, Float_t r) { fPedestal = m; fPedestalRms = r; }
 
-    Bool_t IsValid() const { return fMean>=0||fSigma>=0||fMeanRms>=0||fSigmaRms>=0; }
+    Bool_t IsValid() const { return fPedestal>=0||fPedestalRms>=0; }
 
     ClassDef(MPedestalPix, 1)	// Storage Container for Pedestal information of one pixel
Index: /trunk/MagicSoft/Mars/manalysis/MSigmabar.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MSigmabar.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/manalysis/MSigmabar.cc	(revision 2237)
@@ -135,8 +135,8 @@
 	*/
 
-        const Int_t id = cerpix.GetPixId();
-        const Double_t area = geom.GetPixRatio(id);
-
-        if (id == 0)
+        const Int_t idx = cerpix.GetPixId();
+        const Double_t area = geom.GetPixRatio(idx);
+
+        if (idx == 0)
 	{
           //*fLog << "MSigmabar : id = 0;  pixel '0' is used, ignore it" 
@@ -145,5 +145,5 @@
         }
 
-        const MGeomPix &gpix = geom[id];
+        const MGeomPix &gpix = geom[idx];
 
         Int_t sector = (Int_t)(atan2(gpix.GetY(),gpix.GetX())*6 / (TMath::Pi()*2));
@@ -152,5 +152,5 @@
 
         // count only those pixels which have a sigma != 0.0
-        const Float_t sigma = ped[id].GetMeanRms();
+        const Float_t sigma = ped[idx].GetPedestalRms();
 
         if ( sigma <= 0 )
Index: /trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.cc	(revision 2237)
@@ -39,6 +39,8 @@
 #include "MHillasCalc.h"         // MHillasCalc
 #include "MHillasSrcCalc.h"      // MHillasSrcCalc
+#include "MPedestalPix.h"        // MPedestalPix
 #include "MPedestalCam.h"        // MPedestalCam
-#include "MCerPhotCalc.h"        // MCerPhotCalc
+#include "MCerPhotEvt.h"         // MCerPhotEvt::GetPixById
+#include "MCerPhotCalc.h"       // MCerPhotCalc
 #include "MMcPedestalCopy.h"     // MMcPedestalCopy
 #include "MMcPedestalNSBAdd.h"   // MMcPedestalNSBAdd
@@ -166,6 +168,6 @@
 
     fCanvas2[0] = fCanvas;
-    fCanvas2[1] = AddTab("Errors");
-    fCanvas2[2] = AddTab("Phot/Err");
+    fCanvas2[1] = AddTab("PedRMS");
+    fCanvas2[2] = AddTab("Phot/PedRMS");
     fCanvas2[3] = AddTab("Levels");
     fCanvas2[4] = AddTab("Pedestals");
@@ -184,9 +186,9 @@
     }
 
-    fDisplay[0]->SetNameTitle("photons",   "Number of Photons");
-    fDisplay[1]->SetNameTitle("errors",    "Error of Photons");
-    fDisplay[2]->SetNameTitle("photerr",   "Number of Photons / Error");
-    fDisplay[3]->SetNameTitle("levels",    "Cleaning Levels");
-    fDisplay[4]->SetNameTitle("pedestals", "Pedestals");
+    fDisplay[0]->SetNameTitle("photons",    "Number of Photons");
+    fDisplay[1]->SetNameTitle("pedrms",     "Pedestal RMS");
+    fDisplay[2]->SetNameTitle("photpedrms", "Number of Photons / Pedestal RMS");
+    fDisplay[3]->SetNameTitle("levels",     "Cleaning Levels");
+    fDisplay[4]->SetNameTitle("pedestals",  "Pedestals");
 
     ReadFirstEvent();
@@ -247,9 +249,25 @@
     const MPedestalCam *ped   = (MPedestalCam*)plist->FindObject("MPedestalCam");
 
-    fDisplay[0]->SetCamContent((MCamEvent&)*evt, 0);
-    fDisplay[1]->SetCamContent((MCamEvent&)*evt, 1);
-    fDisplay[2]->SetCamContent((MCamEvent&)*evt, 2);
+    // FIXME: Make this publicly available
+    TArrayD val(577);
+    TArrayC use(577);
+    for (int i=0; i<577;i++)
+    {
+        // FIXME: photon event first!
+        MCerPhotPix *pix = evt->GetPixById(i);
+        if (!pix)
+            continue;
+        MPedestalPix &ppix = (*ped)[i];
+        if (ppix.GetPedestalRms()<0)
+            continue;
+        val[i] = pix->GetNumPhotons()/ppix.GetPedestalRms();
+        use[i] = 1;
+    }
+
+    fDisplay[0]->SetCamContent(*evt, 0);
+    fDisplay[1]->SetCamContent(*ped, 1);
+    fDisplay[2]->SetCamContent(val, &use);
     fDisplay[3]->FillLevels(*evt, *clean);
-    fDisplay[4]->SetCamContent((MCamEvent&)*ped);
+    fDisplay[4]->SetCamContent(*ped, 0);
 
     if (fDisplayHillas)
Index: /trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 2237)
@@ -263,9 +263,14 @@
 
 #include "MParList.h"
+#include "MSigmabar.h"
+
 #include "MGeomPix.h"
 #include "MGeomCam.h"
+
 #include "MCerPhotPix.h"
 #include "MCerPhotEvt.h"
-#include "MSigmabar.h"
+
+#include "MPedestalPix.h"
+#include "MPedestalCam.h"
 
 #include "MGGroupFrame.h" // MGGroupFrame
@@ -328,14 +333,14 @@
         MCerPhotPix &pix = (*fEvt)[i];
 
-        const Int_t id = pix.GetPixId();
-
-        const Float_t  entry = pix.GetNumPhotons();
-        const Float_t  noise = pix.GetErrorPhot();
-
-	//
+        const Int_t idx = pix.GetPixId();
+
+        const Float_t entry = pix.GetNumPhotons();
+        const Float_t noise = (*fPed)[idx].GetSigma();
+
+        //
 	// We calculate a correction factor which accounts for the 
 	// fact that pixels have different size (see TDAS 02-14).
 	//
-        const Double_t factor = TMath::Sqrt(fCam->GetPixRatio(id));
+        const Double_t factor = TMath::Sqrt(fCam->GetPixRatio(idx));
 
         // COBB: '<=' to skip entry=noise=0
@@ -485,11 +490,11 @@
     // get pixel id of this entry
     //
-    const Int_t id = pix.GetPixId();
+    const Int_t idx = pix.GetPixId();
 
     //
     // check the num of photons against the noise level
     //
-    const Float_t  entry = pix.GetNumPhotons();
-    const Float_t  noise = pix.GetErrorPhot();
+    const Float_t entry = pix.GetNumPhotons();
+    const Float_t noise = (*fPed)[idx].GetSigma();
 
     //
@@ -497,5 +502,5 @@
     // fact that pixels have different size (see TDAS 02-14).
     //
-    const Double_t factor = TMath::Sqrt(fCam->GetPixRatio(id));
+    const Double_t factor = TMath::Sqrt(fCam->GetPixRatio(idx));
 
     return (entry * factor <= fCleanLvl2 * noise);
@@ -653,12 +658,21 @@
     }
 
-    if (fCleaningMethod != kDemocratic)
-        return kTRUE;
-
-    fSgb = (MSigmabar*)pList->FindObject("MSigmabar");
-    if (!fSgb)
-    {
-        *fLog << dbginf << "MSigmabar not found... aborting." << endl;
-        return kFALSE;
+    if (fCleaningMethod == kDemocratic)
+    {
+        fSgb = (MSigmabar*)pList->FindObject("MSigmabar");
+        if (!fSgb)
+        {
+            *fLog << dbginf << "MSigmabar not found... aborting." << endl;
+            return kFALSE;
+        }
+    }
+    else
+    {
+        fPed = (MPedestalCam*)pList->FindObject("MPedestalCam");
+        if (!fPed)
+        {
+            *fLog << dbginf << "MPedestalCam not found... aborting." << endl;
+            return kFALSE;
+        }
     }
 
@@ -674,8 +688,19 @@
     if (fSgb)
         fInnerNoise = fSgb->GetSigmabarInner();
-
+#ifdef DEBUG
+    *fLog << all << "CleanStep 1" << endl;
+#endif
     CleanStep1();
+#ifdef DEBUG
+    *fLog << all << "CleanStep 2" << endl;
+#endif
     CleanStep2();
+#ifdef DEBUG
+    *fLog << all << "CleanStep 3" << endl;
+#endif
     CleanStep3();
+#ifdef DEBUG
+    *fLog << all << "Done." << endl;
+#endif
 
     return kTRUE;
Index: /trunk/MagicSoft/Mars/mimage/MImgCleanStd.h
===================================================================
--- /trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 2236)
+++ /trunk/MagicSoft/Mars/mimage/MImgCleanStd.h	(revision 2237)
@@ -10,4 +10,5 @@
 class MCerPhotPix;
 class MCerPhotEvt;
+class MPedestalCam;
 
 class MGGroupFrame;
@@ -22,7 +23,8 @@
 
 private:
-    const MGeomCam    *fCam;  //!
-          MCerPhotEvt *fEvt;  //!
-	  MSigmabar   *fSgb;  //!
+    const MGeomCam     *fCam;  //!
+          MCerPhotEvt  *fEvt;  //!
+          MSigmabar    *fSgb;  //!
+          MPedestalCam *fPed;  //!
 
     CleaningMethod_t fCleaningMethod;
Index: /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc	(revision 2236)
+++ /trunk/MagicSoft/Mars/mmontecarlo/MMcCollectionAreaCalc.cc	(revision 2237)
@@ -84,6 +84,6 @@
     fEmax                     =  -1;
     fSlope                    =   0;
-    fTotalNumSimulatedShowers =  0;
-    fCorsikaVersion           =  0;
+    fTotalNumSimulatedShowers =   0;
+    fCorsikaVersion           =   0;
     fAllEvtsTriggered         = kFALSE;
 
