Index: trunk/MagicSoft/Mars/manalysis/MCT1PadSchweizer.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCT1PadSchweizer.cc	(revision 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 2229)
+++ 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 )
