Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1508)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1540)
@@ -28,5 +28,6 @@
 // MCamDisplay
 //
-// Camera Display
+// Camera Display. The Pixels are displayed in
+// contents/area [somthing/mm^2]
 //
 ////////////////////////////////////////////////////////////////////////////
@@ -38,4 +39,5 @@
 #include <TBox.h>
 #include <TText.h>
+#include <TArrow.h>
 #include <TStyle.h>
 #include <TCanvas.h>
@@ -45,5 +47,4 @@
 #include "MHexagon.h"
 
-#include "MGeomPix.h"
 #include "MGeomCam.h"
 
@@ -51,4 +52,9 @@
 #include "MCerPhotEvt.h"
 
+#include "MPedestalPix.h"
+#include "MPedestalCam.h"
+
+#include "MImgCleanStd.h"
+
 #define kItemsLegend 50 // see SetPalette(1,0)
 
@@ -60,5 +66,5 @@
 //
 MCamDisplay::MCamDisplay(MGeomCam *geom)
-    : fAutoScale(kTRUE), fMinPhe(-2), fMaxPhe(50), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
+    : fAutoScale(kTRUE), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
 {
     fGeomCam = (MGeomCam*)geom; // FIXME: Clone doesn't work! (MGeomCam*)geom->Clone();
@@ -108,4 +114,20 @@
         newtxt->SetTextAlign(12);
     }
+
+    fArrowX = new TArrow(-fRange*.9, -fRange*.9, -fRange*.6, -fRange*.9, 0.025);
+    fArrowY = new TArrow(-fRange*.9, -fRange*.9, -fRange*.9, -fRange*.6, 0.025);
+
+    TString text;
+    text += (int)(fRange*.3);
+    text += "mm";
+
+    fLegRadius = new TText(-fRange*.85, -fRange*.85, text);
+    text = "";
+    text += (float)((int)(fRange*.3*geom->GetConvMm2Deg()*10))/10;
+    text += "°";
+    text = text.Strip(TString::kLeading);
+    fLegDegree = new TText(-fRange*.85, -fRange*.75, text);
+    fLegRadius->SetTextSize(0.04);
+    fLegDegree->SetTextSize(0.04);
 }
 
@@ -124,8 +146,14 @@
     delete fLegText;
 
+    delete fArrowX;
+    delete fArrowY;
+
+    delete fLegRadius;
+    delete fLegDegree;
+
     // delete fGeomCam;
 
-    if (fDrawingPad->GetListOfPrimitives()->FindObject(this)==this &&
-        fIsAllocated)
+    // Maybe harmfull! Don't exchange the order!
+    if (fIsAllocated && fDrawingPad->GetListOfPrimitives()->FindObject(this)==this)
     {
         fDrawingPad->RecursiveRemove(this);
@@ -134,13 +162,61 @@
 }
 
-inline void MCamDisplay::SetPixColor(const MCerPhotPix &pix, const Int_t i)
-{
-    //
-    // Fixme: Divide pnum by the (real) area of the pixel
-    //
-    const Float_t ratio = (*fGeomCam)[0].GetA()/(*fGeomCam)[i].GetA();
+inline void MCamDisplay::SetPixColor(const MCerPhotPix &pix, const Int_t i, Float_t min, Float_t max)
+{
+    //
+    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
+    //
+    const Float_t ratio = fGeomCam->GetPixRatio(i);
     const Float_t pnum  = ratio*pix.GetNumPhotons();
 
-    (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum));
+    (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
+}
+
+inline void MCamDisplay::SetPixColorPedestal(const MPedestalPix &pix, const Int_t i, Float_t min, Float_t max)
+{
+    //
+    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
+    //
+    const Float_t ratio = fGeomCam->GetPixRatio(i);
+    const Float_t pnum  = ratio*pix.GetMean();
+
+    (*this)[i].SetFillColor(GetColor(pnum, min, max));
+}
+
+inline void MCamDisplay::SetPixColorError(const MCerPhotPix &pix, const Int_t i, Float_t min, Float_t max)
+{
+    //
+    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
+    //
+    const Float_t ratio = fGeomCam->GetPixRatio(i);
+    const Float_t pnum  = ratio*pix.GetErrorPhot();
+
+    (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
+}
+
+inline void MCamDisplay::SetPixColorRatio(const MCerPhotPix &pix, Float_t min, Float_t max)
+{
+    //
+    // Fixme: Use absolute value per mm^2. Needs another scaling algorithm.
+    //
+    const Float_t pnum  = pix.GetNumPhotons()/pix.GetErrorPhot();
+    (*this)[pix.GetPixId()].SetFillColor(GetColor(pnum, min, max));
+}
+
+inline void MCamDisplay::SetPixColorLevel(const MCerPhotPix &pix, Float_t lvl1, Float_t lvl2)
+{
+    const Int_t maxcolidx = kItemsLegend-1;
+
+    MHexagon &hex = (*this)[pix.GetPixId()];
+
+    const Float_t r = pix.GetNumPhotons()/pix.GetErrorPhot();
+
+    if (r>lvl1)
+        hex.SetFillColor(fColors[4*maxcolidx/5]);
+    else
+        if (r>lvl2)
+            hex.SetFillColor(fColors[maxcolidx/2]);
+        else
+            hex.SetFillColor(fColors[maxcolidx/5]);
 }
 
@@ -189,4 +265,11 @@
     //
     gPad->Range(-fRange, -y, x, y);
+
+    //
+    // Make sure, that the correct aspect is always displayed also
+    // if - by chance - there is not update for the pad after the
+    // Paint function was called.
+    //
+    gPad->Update();
 }
 
@@ -359,4 +442,10 @@
     }
 
+    fArrowX->Draw();
+    fArrowY->Draw();
+
+    fLegRadius->Draw();
+    fLegDegree->Draw();
+
     //
     // initialize and draw legend
@@ -433,4 +522,119 @@
         return;
 
+    Draw();
+
+    fDrawingPad->cd();
+
+    for (int i=0; i<kItemsLegend; i++)
+        GetBox(i)->SetFillColor(fColors[i]);
+
+    //
+    // Reset pixel colors to default value
+    //
+    Reset();
+
+    //
+    //  if the autoscale is true, set the values for the range for
+    //  each event
+    //
+    Float_t min = 0;
+    Float_t max = 50;
+    if (fAutoScale)
+    {
+        min = event->GetNumPhotonsMin(fGeomCam);
+        max = event->GetNumPhotonsMax(fGeomCam);
+
+        if (max < 20.)
+            max = 20.;
+
+        UpdateLegend(min, max);
+    }
+
+    //
+    //   update the colors in the picture
+    //
+    const Int_t entries = event->GetNumPixels();
+
+    for (Int_t i=0; i<entries; i++)
+    {
+        const MCerPhotPix &pix = (*event)[i];
+
+        if (!pix.IsPixelUsed())
+            continue;
+
+        SetPixColor(pix, i, min, max);
+    }
+
+    //
+    // Update display physically
+    //
+    fDrawingPad->Modified();
+    fDrawingPad->Update();
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to draw the number of photo electron into the
+// camera.
+//
+void MCamDisplay::DrawPedestals(const MPedestalCam *event)
+{
+    if (!event)
+        return;
+
+    Draw();
+
+    fDrawingPad->cd();
+
+    for (int i=0; i<kItemsLegend; i++)
+        GetBox(i)->SetFillColor(fColors[i]);
+
+    //
+    // Reset pixel colors to default value
+    //
+    Reset();
+
+    //
+    //  if the autoscale is true, set the values for the range for
+    //  each event
+    //
+    Float_t min = 0;
+    Float_t max = 50;
+    if (fAutoScale)
+    {
+        min = event->GetMeanMin(fGeomCam);
+        max = event->GetMeanMax(fGeomCam);
+
+        if (max < 20.)
+            max = 20.;
+
+        UpdateLegend(min, max);
+    }
+
+    //
+    //   update the colors in the picture
+    //
+    const Int_t entries = event->GetSize();
+
+    for (Int_t i=0; i<entries; i++)
+        SetPixColorPedestal((*event)[i], i, min, max);
+
+    //
+    // Update display physically
+    //
+    fDrawingPad->Modified();
+    fDrawingPad->Update();
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to draw the error of number of photo electron
+// into the camera.
+//
+void MCamDisplay::DrawErrorPhot(const MCerPhotEvt *event)
+{
+    if (!event)
+        return;
+
     if (!fDrawingPad)
         Draw();
@@ -450,13 +654,15 @@
     //  each event
     //
+    Float_t min = 0;
+    Float_t max = 50;
     if (fAutoScale)
     {
-        fMinPhe = event->GetNumPhotonsMin(fGeomCam);
-        fMaxPhe = event->GetNumPhotonsMax(fGeomCam);
-
-        if (fMaxPhe < 20.)
-            fMaxPhe = 20.;
-
-        UpdateLegend();
+        min = event->GetErrorPhotMin(fGeomCam);
+        max = event->GetErrorPhotMax(fGeomCam);
+
+        if (max < 20.)
+            max = 20.;
+
+        UpdateLegend(min, max);
     }
 
@@ -473,5 +679,5 @@
             continue;
 
-        SetPixColor(pix, i);
+        SetPixColorError(pix, i, min, max);
     }
 
@@ -481,4 +687,116 @@
     fDrawingPad->Modified();
     fDrawingPad->Update();
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to draw the ratio of the number of photons
+// divided by its error
+//
+void MCamDisplay::DrawRatio(const MCerPhotEvt *event)
+{
+    if (!event)
+        return;
+
+    if (!fDrawingPad)
+        Draw();
+
+    fDrawingPad->cd();
+
+    for (int i=0; i<kItemsLegend; i++)
+        GetBox(i)->SetFillColor(fColors[i]);
+
+    //
+    // Reset pixel colors to default value
+    //
+    Reset();
+
+    //
+    //  if the autoscale is true, set the values for the range for
+    //  each event
+    //
+    Float_t min = 0;
+    Float_t max = 20;
+    if (fAutoScale)
+    {
+        min = event->GetRatioMin();
+        max = event->GetRatioMax();
+
+        UpdateLegend(min, max);
+    }
+
+    //
+    //   update the colors in the picture
+    //
+    const Int_t entries = event->GetNumPixels();
+
+    for (Int_t i=0; i<entries; i++)
+    {
+        const MCerPhotPix &pix = (*event)[i];
+
+        if (!pix.IsPixelUsed())
+            continue;
+
+        SetPixColorRatio(pix, min, max);
+    }
+
+    //
+    // Update display physically
+    //
+    fDrawingPad->Modified();
+    fDrawingPad->Update();
+}
+
+// ------------------------------------------------------------------------
+//
+// Draw the colors in respect to the cleaning levels
+//
+void MCamDisplay::DrawLevels(const MCerPhotEvt *event, Float_t lvl1, Float_t lvl2)
+{
+    if (!event)
+        return;
+
+    if (!fDrawingPad)
+        Draw();
+
+    fDrawingPad->cd();
+
+    for (int i=0; i<kItemsLegend; i++)
+        GetBox(i)->SetFillColor(fColors[i]);
+
+    //
+    // Reset pixel colors to default value
+    //
+    Reset();
+
+    //
+    //   update the colors in the picture
+    //
+    const Int_t entries = event->GetNumPixels();
+
+    for (Int_t i=0; i<entries; i++)
+    {
+        const MCerPhotPix &pix = (*event)[i];
+
+        if (!pix.IsPixelUsed())
+            continue;
+
+        SetPixColorLevel(pix, lvl1, lvl2);
+    }
+
+    //
+    // Update display physically
+    //
+    fDrawingPad->Modified();
+    fDrawingPad->Update();
+}
+
+// ------------------------------------------------------------------------
+//
+// Draw the colors in respect to the cleaning levels
+//
+void MCamDisplay::DrawLevels(const MCerPhotEvt *event, const MImgCleanStd &clean)
+{
+    DrawLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
 }
 
@@ -504,5 +822,5 @@
 //   with 0 up to 49.
 //
-Int_t MCamDisplay::GetColor(Float_t val)
+Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max)
 {
     //
@@ -511,8 +829,8 @@
     const Int_t maxcolidx = kItemsLegend-1;
 
-    if (val >= fMaxPhe)
+    if (val >= max)
         return fColors[maxcolidx];
 
-    if (val <= fMinPhe)
+    if (val <= min)
         return fColors[0];
 
@@ -520,5 +838,5 @@
     // calculate the color index
     //
-    const Float_t ratio  = (val-fMinPhe) / (fMaxPhe-fMinPhe);
+    const Float_t ratio  = (val-min) / (max-min);
     const Int_t   colidx = (Int_t)(ratio*maxcolidx + .5);
 
@@ -531,5 +849,5 @@
 //    Display
 //
-void MCamDisplay::UpdateLegend()
+void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe)
 {
     char text[10];
@@ -537,5 +855,5 @@
     for (Int_t i=0; i<kItemsLegend; i+=3)
     {
-        const Float_t val = fMinPhe + (Float_t)i/kItemsLegend * (fMaxPhe-fMinPhe) ;
+        const Float_t val = minphe + (Float_t)i/kItemsLegend * (maxphe-minphe) ;
 
         sprintf(text, "%5.1f", val);
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 1508)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 1540)
@@ -11,4 +11,5 @@
 class TBox;
 class TText;
+class TArrow;
 class TVirtualPad;
 
@@ -17,4 +18,7 @@
 class MCerPhotEvt;
 class MCerPhotPix;
+class MImgCleanStd;
+class MPedestalPix;
+class MPedestalCam;
 
 class MCamDisplay : public TObject
@@ -28,8 +32,11 @@
     Float_t        fRange;       // the range in millimeters of the present geometry
 
-    Float_t        fMinPhe;      // The minimal number of Phe
-    Float_t        fMaxPhe;      // The maximum number of Phe
+    Int_t          fColors[50];
 
-    Int_t          fColors[50];
+    TArrow        *fArrowX;      // Coordinate System
+    TArrow        *fArrowY;      // Coordinate System
+
+    TText         *fLegRadius;   // Coordinate System
+    TText         *fLegDegree;   // Coordinate System
 
     TClonesArray  *fPixels;      // array of all hexagons
@@ -47,8 +54,12 @@
     MHexagon &operator[](int i) { return *((MHexagon*)fPixels->At(i)); }
 
-    void  SetPixColor(const MCerPhotPix &pix, const Int_t i);
-    Int_t GetColor(Float_t wert);
+    void  SetPixColor(const MCerPhotPix &pix, const Int_t i, Float_t min, Float_t max);
+    void  SetPixColorRatio(const MCerPhotPix &pix, Float_t min, Float_t max);
+    void  SetPixColorLevel(const MCerPhotPix &pix, Float_t lvl1, Float_t lvl2);
+    void  SetPixColorError(const MCerPhotPix &pix, const Int_t i, Float_t min, Float_t max);
+    void  SetPixColorPedestal(const MPedestalPix &pix, Int_t i, Float_t min, Float_t max);
+    Int_t GetColor(Float_t val, Float_t min, Float_t max);
 
-    void UpdateLegend();
+    void UpdateLegend(Float_t min, Float_t max);
     void Paint(Option_t *option="");
 
@@ -59,4 +70,9 @@
     void SetAutoScale(Bool_t input=kTRUE) { fAutoScale = input; }
     void DrawPhotNum(const MCerPhotEvt *event);
+    void DrawRatio(const MCerPhotEvt *event);
+    void DrawLevels(const MCerPhotEvt *event, Float_t lvl1, Float_t lvl2);
+    void DrawErrorPhot(const MCerPhotEvt *event);
+    void DrawLevels(const MCerPhotEvt *event, const MImgCleanStd &clean);
+    void DrawPedestals(const MPedestalCam *event);
 
     void DrawPixelNumbers();
