Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.cc
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 2992)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.cc	(revision 3051)
@@ -30,6 +30,8 @@
 #include "MJPedestal.h"
 
+#include <TF1.h>
 #include <TFile.h>
 #include <TStyle.h>
+#include <TString.h>
 #include <TCanvas.h>
 #include <TSystem.h>
@@ -46,4 +48,5 @@
 
 #include "MHCamera.h"
+#include "MPedestalCam.h"
 
 #include "MReadMarsFile.h"
@@ -109,5 +112,5 @@
 
     //
-    // Get coontainer from list
+    // Get container from list
     //
     MGeomCam &geomcam = *(MGeomCam*)plist.FindObject("MGeomCam");
@@ -120,5 +123,7 @@
 
     disp0.SetCamContent(fPedestalCam, 0);
-    disp1.SetCamContent(fPedestalCam, 1);
+    disp0.SetCamError(fPedestalCam, 1);
+    disp1.SetCamContent(fPedestalCam, 2);
+    disp1.SetCamError(fPedestalCam, 3);
 
     disp0.SetYTitle("P [fadc/slice]");
@@ -128,25 +133,96 @@
     // Display data
     //
-    TObject *obj;
-
     TCanvas &c3 = fDisplay->AddTab("Pedestals");
-    c3.Divide(2,2);
-
-    c3.cd(1);
+    c3.Divide(2,3);
+
+    *fLog << "BALBALBALBA" <<endl;
+
+    CamDraw(c3, 1, 2, disp0, 0);
+    CamDraw(c3, 2, 2, disp1, 1);
+
+}
+
+
+void MJPedestal::DrawProjection(MHCamera *obj1, Int_t fit) const
+{
+  
+  TH1D *obj2 = (TH1D*)obj1->Projection();
+  obj2->Draw();
+  obj2->SetBit(kCanDelete);
+  
+  const Double_t min   = obj2->GetBinCenter(obj2->GetXaxis()->GetFirst());
+  const Double_t max   = obj2->GetBinCenter(obj2->GetXaxis()->GetLast());
+  const Double_t integ = obj2->Integral("width")/2.5066283;
+  const Double_t mean  = obj2->GetMean();
+  const Double_t rms   = obj2->GetRMS();
+  const Double_t width = max-min;
+  
+  if (rms == 0. || width == 0. )
+    return;
+
+  const TString dgausformula = TString("([0]-[3])/[2]*exp(-0.5*(x-[1])*(x-[1])/[2]/[2])"
+                                       "+[3]/[5]*exp(-0.5*(x-[4])*(x-[4])/[5]/[5])");
+
+  TF1 *f=0;
+  switch (fit)
+    {
+    case 0:
+      f = new TF1("sgaus","gaus(0)",min,max);
+      f->SetLineColor(kYellow);
+      f->SetBit(kCanDelete);
+      f->SetParNames("Area","#mu","#sigma");
+      f->SetParameters(integ/rms,mean,rms);
+      f->SetParLimits(0, 0.  , integ);
+      f->SetParLimits(1, min , max);
+      f->SetParLimits(2, 0   , width/1.5);
+      obj2->Fit(f,"QLRM");
+      break;
+      
+    case 1:
+      f = new TF1("dgaus",dgausformula.Data(),min,max);
+      f->SetLineColor(kYellow);
+      f->SetBit(kCanDelete);
+      f->SetParNames("A_{tot}","#mu_{1}","#sigma_{1}","A_{2}","#mu_{2}","#sigma_{2}");
+      f->SetParameters(integ,(min+mean)/2.,width/4.,
+                       integ/width/2.,(max+mean)/2.,width/4.);
+      // The left-sided Gauss 
+      f->SetParLimits(0,integ-1.5      , integ+1.5);
+      f->SetParLimits(1,min+(width/10.), mean);
+      f->SetParLimits(2,0              , width/2.);
+      // The right-sided Gauss 
+      f->SetParLimits(3,0   , integ);
+      f->SetParLimits(4,mean, max-(width/10.));
+      f->SetParLimits(5,0   , width/2.);
+      obj2->Fit(f,"QLRM");
+      break;
+      
+    default:
+      obj2->Fit("gaus","Q");
+      obj2->GetFunction("gaus")->SetLineColor(kYellow);
+      break;
+    }
+}
+
+
+
+void MJPedestal::CamDraw(TCanvas &c, Int_t x, Int_t y, MHCamera &cam1, Int_t fit)
+{
+
+    c.cd(x);
     gPad->SetBorderMode(0);
-    gStyle->SetOptStat(1101);
-    obj=disp0.DrawCopy("hist");
-
-    c3.cd(3);
-    obj->Draw();
-
-    c3.cd(2);
+    MHCamera *obj1=(MHCamera*)cam1.DrawCopy("hist");
+    obj1->AddNotify(fPedestalCam);
+
+    c.cd(x+y);
     gPad->SetBorderMode(0);
-    gStyle->SetOptStat(1101);
-    obj=disp1.DrawCopy("hist");
-
-    c3.cd(4);
-    obj->Draw();
-}
+    obj1->Draw();
+    ((MHCamera*)obj1)->SetPrettyPalette();
+
+    c.cd(x+2*y);
+    gPad->SetBorderMode(0);
+    DrawProjection(obj1, fit);
+
+}
+
 
 Bool_t MJPedestal::WriteResult()
Index: trunk/MagicSoft/Mars/mjobs/MJPedestal.h
===================================================================
--- trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 2992)
+++ trunk/MagicSoft/Mars/mjobs/MJPedestal.h	(revision 3051)
@@ -8,4 +8,5 @@
 class MParList;
 class MRunIter;
+class MHCamera;
 
 class MJPedestal : public MParContainer
@@ -18,4 +19,6 @@
     MPedestalCam fPedestalCam;
 
+    void   DrawProjection(MHCamera *obj1, Int_t fit) const;
+    void   CamDraw(TCanvas &c, Int_t x, Int_t y, MHCamera &cam1, Int_t fit);
     void   DisplayResult(MParList &plist);
     Bool_t WriteResult();
