Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1964)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1965)
@@ -1,3 +1,95 @@
                                                  -*-*- END OF LINE -*-*-
+
+   * Makefile:
+     - exchanged mbase and mmain
+   
+   * Makefile.conf.general:
+     - added MARSVER
+   
+   * mars.cc:
+     - use MARSVER
+   
+   * macros/readMagic.C:
+     - updated to work with the new MH-stuff
+     
+   * macros/status.C:
+     - added
+     
+   * manalysis/MBlindPixelCalc.cc, manalysis/MCerPhotCalc.cc,
+     manalysis/MMcPedestalCopy.ccm, manalysis/MMcPedestalNSBAdd.cc,
+     mfileio/MReadMarsFile.cc, mimage/MHillasCalc.cc,
+     mimage/MImgCleanStd.cc:
+     - changed def. title
+   
+   * manalysis/MCT1PointingCorrCalc.h:
+     - minor change
+     
+   * manalysis/MCerPhotEvt.[h,cc]:
+     - don't use unused pixels for calculation of min/max
+     - added Scale member function
+   
+   * manalysis/MCerPhotPix.h:
+     - added Scale inline function
+     
+   * mbase/MEvtLoop.[h,cc], mbase/MParContainer.[h,cc],
+     mbase/MParList.[h,cc], mbase/MTaskList.[h,cc],
+     mfileio/MReadMarsFile.cc, mhist/MFillH.[h,cc]:
+     - implemented use of fDisplay 
+   
+   * mbase/MParContainer.h:
+     - Don't display name and class name if it is the same (GetDescriptor)
+
+   * meventdisp/MGCamDisplay.[h,cc]:
+     - made working with new MH-stuff
+   
+   * mfileio/Makefile:
+     - added -I../mmain
+   
+   * mgeom/MGeomCam.[h,cc]:
+     - added Clone function
+
+   * mgeom/MGeomCamCT1.cc, mgeom/MGeomCamMagic.cc:
+     - commented out informal output at constructor
+   
+   * mgui/MCamDisplay.[h,cc], mhist/MHStarMap.[h,cc], 
+     mimage/MHH*.[h,cc]:
+     - changed to be more root oriented
+   
+   * mgui/MHexagon.cc:
+     - small changes
+     
+   * mgui/Makefile:
+     - added mhist
+     
+   * mhist/MH.[h,cc]:
+     - changed to be more root oriented
+     - removed border
+     - added DrawClone
+     - GetNewPad
+
+   * mhist/MH3.cc:
+     - removed some strange debug output
+     
+   * mhist/MHCerPhotEvt.[h,cc]:
+     - fixed some bug
+     - made working with fDisplay
+   
+   * mhist/Makefile:
+     - added mmain
+     
+   * mmain/MProgressBar.cc:
+     - fixed a typo
+     
+   * mmain/MStatusDisplay.[h,cc]:
+     - new implementation
+     
+   * mmain/MainLinkDef.h, mmain/Makefile:
+     - added MStatusDisplay
+     - added MGMenu
+
+   * mmain/MGMenu.[h,cc]:
+     - added
+
+
 
  2003/04/19: Abelardo Moralejo
@@ -8,6 +100,8 @@
 
    * mmontecarlo/MMcEnergyMigration.[h,cc]
-     -Added. Task to fill the energy migration matrix histograms 
-      contained in class MHMcEnergyMigration.
+     - Added. Task to fill the energy migration matrix histograms 
+       contained in class MHMcEnergyMigration.
+
+
 
  2003/04/17: Wolfgang Wittek
@@ -37,5 +131,4 @@
      - add plot of Id of blind pixel
 
-   MHMcCT1CollectionArea.c
 
 
@@ -46,4 +139,5 @@
     - MNewImagePar and MNewImageParCalc removed
     
+
 
 
Index: trunk/MagicSoft/Mars/Makefile
===================================================================
--- trunk/MagicSoft/Mars/Makefile	(revision 1964)
+++ trunk/MagicSoft/Mars/Makefile	(revision 1965)
@@ -35,6 +35,6 @@
 #  ----->>>   mars libraries
 #
-SUBDIRS = mmain       \
-          mbase       \
+SUBDIRS = mbase       \
+          mmain       \
           mfileio     \
           mfilter     \
Index: trunk/MagicSoft/Mars/Makefile.conf.general
===================================================================
--- trunk/MagicSoft/Mars/Makefile.conf.general	(revision 1964)
+++ trunk/MagicSoft/Mars/Makefile.conf.general	(revision 1965)
@@ -12,5 +12,5 @@
 #
 
-DEFINES	  = -D__MARS__ -DROOTVER=\"$(ROOTVER)\" $(ARCHDEF)
+DEFINES	  = -D__MARS__ -DMARSVER=\"\<cvs\>\" -DROOTVER=\"$(ROOTVER)\" $(ARCHDEF)
 
 CXXFLAGS  = $(ROOTCFLAGS) $(INCLUDES) $(OPTIM) $(DEBUG) $(DEFINES)
Index: trunk/MagicSoft/Mars/macros/readMagic.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readMagic.C	(revision 1964)
+++ trunk/MagicSoft/Mars/macros/readMagic.C	(revision 1965)
@@ -100,5 +100,7 @@
         cout << "Event #" << read.GetNumEntry() ":" << endl;
 
-        display.DrawPhotNum((MCerPhotEvt*)clone.GetClone());
+        display.FillPhotNum(*(MCerPhotEvt*)clone.GetClone());
+        gPad->Modified();
+        gPad->Update();
 
         if (!HandleInput())
@@ -108,5 +110,7 @@
 	hillas.Draw();
 
-        display.DrawPhotNum((MCerPhotEvt*)plist.FindObject("MCerPhotEvt"));
+        display.FillPhotNum(*(MCerPhotEvt*)plist.FindObject("MCerPhotEvt"));
+        gPad->Modified();
+        gPad->Update();
 
         if (!HandleInput())
Index: trunk/MagicSoft/Mars/macros/status.C
===================================================================
--- trunk/MagicSoft/Mars/macros/status.C	(revision 1965)
+++ trunk/MagicSoft/Mars/macros/status.C	(revision 1965)
@@ -0,0 +1,157 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  4/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  Status - Example how to use the MStatusDisplay
+//
+//  Use a camera file as input
+//
+/////////////////////////////////////////////////////////////////////////////
+
+void status()
+{
+    //
+    // Update frequency by default = 1Hz
+    //
+    MStatusDisplay *d = new MStatusDisplay;
+
+    // Set update time to 5s
+    // d->SetUpdateTime(5000);
+
+    // Disable online update
+    // d->SetUpdateTime(-1);
+
+    d->SetLogStream(&gLog); // Disables output to stdout
+    gLog.SetOutputFile("status.log", kTRUE); // Enable output to file
+    //gLog.EnableOutputDevice(MLog::eStdout); // Enable output to stdout again
+
+    //
+    // Create a empty Parameter List and an empty Task List
+    // The tasklist is identified in the eventloop by its name
+    //
+    MParList  plist;
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    MSrcPosCam src;
+    src.SetReadyToSave();
+    plist.AddToList(&src);
+
+    // Use MHillasExt instead of MHillas
+    MHillasExt hext;
+    plist.AddToList(&hext);
+
+    //
+    // The geometry container must be created by yourself to make sure
+    // that you don't choose a wrong geometry by mistake
+    //
+    MGeomCamMagic geomcam;
+    plist.AddToList(&geomcam);
+
+    //
+    // Now setup the tasks and tasklist:
+    // ---------------------------------
+    //
+    MReadMarsFile read("Events");
+    read.DisableAutoScheme();
+
+    // ------------- user change -----------------
+    //read.AddFile("data/Pro*.root");
+    read.AddFile("data/Gam*.root");
+
+    MMcPedestalCopy   pcopy;
+    MMcPedestalNSBAdd pnsb;
+    MCerPhotCalc      ncalc;
+
+    MBlindPixelCalc   blind;
+    blind.SetUseInterpolation();
+
+    MImgCleanStd      clean;
+    MHillasCalc       hcalc;
+    MHillasSrcCalc    scalc; // !!Preliminary!! Will be removed later!
+
+    // -------------------------------------------
+    MFillH hfill1("MHHillas", "MHillas");
+    MFillH hfill2("MHHillasExt [MHHillasExt]");
+    MFillH hfill3("MHHillasExtSrc [MHHillasExt]");
+    MFillH hfill4("MHHillasSrc","MHillasSrc");
+    MFillH hfill5("MHStarMap", "MHillas");
+    MFillH hfill6("MHCerPhotEvt", "MCerPhotEvt");
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&pcopy);
+    tlist.AddToList(&pnsb);
+
+    tlist.AddToList(&ncalc);
+
+    tlist.AddToList(&blind);
+    tlist.AddToList(&clean);
+    tlist.AddToList(&hcalc);
+    tlist.AddToList(&scalc);
+    tlist.AddToList(&hfill1);
+    tlist.AddToList(&hfill2);
+    tlist.AddToList(&hfill3);
+    tlist.AddToList(&hfill4);
+    tlist.AddToList(&hfill5);
+    tlist.AddToList(&hfill6);
+
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+    evtloop.SetDisplay(d);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    //
+    // Make sure the display hasn't been deleted by the user while the
+    // eventloop was running.
+    //
+    if ((d = evtloop.GetDisplay()))
+    {
+        // Save data in a postscriptfile (status.ps)
+        d->SaveAsPS();
+        /*
+         * ----------- Write status to a root file ------------
+         *
+         TFile file("status.root", "RECREATE");
+         d->Write();
+         file.Close();
+         delete d;
+         */
+    }
+    /*
+     * ----------- Read status from a root file ------------
+     *
+     TFile file2("status.root", "READ");
+     MStatusDisplay *d2 = new MStatusDisplay;
+     d2->Read();
+     */
+}
Index: trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc	(revision 1965)
@@ -71,5 +71,5 @@
 
 static const TString gsDefName  = "MBlindPixelCalc";
-static const TString gsDefTitle = "Task to deal with hot spots (star, broken pixels, etc)";
+static const TString gsDefTitle = "Find hot spots (star, broken pixels, etc)";
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/manalysis/MCT1PointingCorrCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCT1PointingCorrCalc.h	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MCT1PointingCorrCalc.h	(revision 1965)
@@ -27,5 +27,5 @@
     MParameterD  *fHourAngle;
 
-    Float_t      fMm2Deg;
+    Float_t       fMm2Deg;
 
 public:
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotCalc.cc	(revision 1965)
@@ -64,5 +64,5 @@
 {
     fName  = name  ? name  : "MCerPhotCalc";
-    fTitle = title ? title : "Task to calculate pixel signal from raw data";
+    fTitle = title ? title : "Calculate pixel signal from FADC data";
 
     AddToBranchList("MRawEvtData.fHiGainPixId");
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 1965)
@@ -27,4 +27,5 @@
 
 #include <math.h>
+#include <limits.h>
 #include <fstream.h>
 
@@ -120,4 +121,6 @@
     {
         const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         if (id == pix.GetPixId() && pix.IsPixelUsed())
@@ -139,4 +142,6 @@
     {
         const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         if (id == pix.GetPixId() && pix.IsPixelCore())
@@ -160,9 +165,11 @@
     const UInt_t n = geom->GetNumPixels();
 
-    Float_t minval = (*this)[0].GetNumPhotons();
-
-    for (UInt_t i=1; i<fNumPixels; i++)
-    {
-        const MCerPhotPix &pix = (*this)[i];
+    Float_t minval = FLT_MAX;
+
+    for (UInt_t i=1; i<fNumPixels; i++)
+    {
+        const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         const UInt_t id = pix.GetPixId();
@@ -195,9 +202,11 @@
     const UInt_t n = geom->GetNumPixels();
 
-    Float_t maxval = (*this)[0].GetNumPhotons();
-
-    for (UInt_t i=1; i<fNumPixels; i++)
-    {
-        const MCerPhotPix &pix = (*this)[i];
+    Float_t maxval = -FLT_MAX;
+
+    for (UInt_t i=1; i<fNumPixels; i++)
+    {
+        const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         const UInt_t id = pix.GetPixId();
@@ -229,4 +238,6 @@
     {
         const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
@@ -247,9 +258,11 @@
         return -5.;
 
-    Float_t maxval = (*this)[0].GetNumPhotons()/(*this)[0].GetErrorPhot();
-
-    for (UInt_t i=1; i<fNumPixels; i++)
-    {
-        const MCerPhotPix &pix = (*this)[i];
+    Float_t maxval = -FLT_MAX;
+
+    for (UInt_t i=1; i<fNumPixels; i++)
+    {
+        const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         Float_t testval = pix.GetNumPhotons()/pix.GetErrorPhot();
@@ -272,9 +285,11 @@
         return 50.;
 
-    Float_t minval = (*this)[0].GetErrorPhot();
-
-    for (UInt_t i=1; i<fNumPixels; i++)
-    {
-        const MCerPhotPix &pix = (*this)[i];
+    Float_t minval = FLT_MAX;
+
+    for (UInt_t i=1; i<fNumPixels; i++)
+    {
+        const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         Float_t testval = pix.GetErrorPhot();
@@ -300,9 +315,11 @@
         return 50.;
 
-    Float_t maxval = (*this)[0].GetErrorPhot();
-
-    for (UInt_t i=1; i<fNumPixels; i++)
-    {
-        const MCerPhotPix &pix = (*this)[i];
+    Float_t maxval = -FLT_MAX;
+
+    for (UInt_t i=1; i<fNumPixels; i++)
+    {
+        const MCerPhotPix &pix = (*this)[i];
+        if (!pix.IsPixelUsed())
+            continue;
 
         Float_t testval = pix.GetErrorPhot();
@@ -368,2 +385,7 @@
 }
 */
+
+void MCerPhotEvt::Scale(Double_t f)
+{
+    fPixels->ForEach(MCerPhotPix, Scale)(f);
+}
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 1965)
@@ -48,4 +48,6 @@
     MCerPhotPix &operator[](int i) const { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); }
 
+    void Scale(Double_t f);
+
     MCerPhotPix *GetPixById(int id) const;
 
Index: trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MCerPhotPix.h	(revision 1965)
@@ -48,4 +48,6 @@
     void    AddNumPhotons(Float_t f)    { fPhot += f; }
 
+    void    Scale(Float_t f)            { fPhot/=f; }
+
     void    Print(Option_t *opt = NULL) const;
 
Index: trunk/MagicSoft/Mars/manalysis/MMcPedestalCopy.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcPedestalCopy.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MMcPedestalCopy.cc	(revision 1965)
@@ -57,5 +57,5 @@
 {
     fName  = name  ? name  : "MMcPedestalCopy";
-    fTitle = title ? title : "Task to copy monte carlo pedestals into MPedestal Container";
+    fTitle = title ? title : "Copy MC pedestals into MPedestal Container";
 
     //
Index: trunk/MagicSoft/Mars/manalysis/MMcPedestalNSBAdd.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMcPedestalNSBAdd.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/manalysis/MMcPedestalNSBAdd.cc	(revision 1965)
@@ -79,5 +79,5 @@
 {
     fName  = name  ? name  : "MMcPedestalNSBAdd";
-    fTitle = title ? title : "Task to copy monte carlo pedestals into MPedestal Container";
+    fTitle = title ? title : "Add diffuse NSB to the pedestal signal";
 
     //
Index: trunk/MagicSoft/Mars/mars.cc
===================================================================
--- trunk/MagicSoft/Mars/mars.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mars.cc	(revision 1965)
@@ -47,5 +47,5 @@
     //       12345678901234567890123456789012345678901234567890
     gLog << "==================================================" << endl;
-    gLog << "                    MARS V0.8                     " << endl;
+    gLog << "                    MARS V" << MARSVER << "                      " << endl;
     gLog << "    Magic Analysis and Reconstruction Software    " << endl;
     gLog << "            Compiled on <" << __DATE__ << ">"       << endl;
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.cc	(revision 1965)
@@ -46,8 +46,7 @@
 // Afterwards the PostProcess functions are executed.                       //
 //                                                                          //
-//                                                                          //
-//  Maybe we can add a TProgressMeter sometimes later to be able to show    //
-//  the progress graphically...                                             //
-//                                                                          //
+// If you want to display the progress in a gui you can use SetProgressBar  //
+// and a TGProgressBar or a MProgressBar. If you set a MStatusDisplay       //
+// using SetDisplay, the Progress bar from this display is used.            //
 //                                                                          //
 // You can create a macro from a completely setup eventloop by:             //
@@ -74,4 +73,5 @@
 #include <iostream.h>
 
+#include <TTime.h>          // TTime
 #include <TFile.h>          // gFile
 #include <TSystem.h>        // gSystem
@@ -87,4 +87,5 @@
 #include "MRead.h"           // for setting progress bar
 #include "MProgressBar.h"    // MProgressBar::GetBar
+#include "MStatusDisplay.h"  // MStatusDisplay::GetBar
 #endif
 
@@ -101,5 +102,5 @@
 // --------------------------------------------------------------------------
 //
-// default constructor - emty
+// default constructor
 //
 MEvtLoop::MEvtLoop(const char *name) : fParList(NULL), fProgress(NULL)
@@ -112,5 +113,5 @@
 // --------------------------------------------------------------------------
 //
-// default destructor - emty
+// destructor
 //
 MEvtLoop::~MEvtLoop()
@@ -171,4 +172,31 @@
     if (fLog != &gLog)
         fParList->SetLogStream(fLog);
+
+#ifdef __MARS__
+    //
+    // Check whether display is still existing
+    //
+    if (fDisplay && !gROOT->GetListOfSpecials()->FindObject(fDisplay))
+        fDisplay = NULL;
+    if (fDisplay)
+    {
+        // Lock display to prevent user from deleting it
+        fDisplay->Lock();
+        // Get pointer to update Progress bar
+        fProgress = fDisplay->GetBar();
+        // Don't display context menus
+        fDisplay->SetNoContextMenu();
+        // Set window and icon name
+        fDisplay->SetWindowName(TString("Status Display: ")+fName);
+        fDisplay->SetIconName(fName);
+        // Set status lines
+        fDisplay->SetStatusLine1("PreProcessing...");
+        fDisplay->SetStatusLine2("");
+        // Start automatic update
+        fDisplay->StartUpdate();
+        // Cascade display through childs
+        fParList->SetDisplay(fDisplay);
+    }
+#endif
 
     //
@@ -188,4 +216,67 @@
 }
 
+Bool_t MEvtLoop::ProcessGuiEvents(Int_t num)
+{
+    if (!fProgress)
+        return kTRUE;
+
+    //
+    // Check status of display
+    //
+    Bool_t rc = kTRUE;
+
+    if (fDisplay)
+        switch (fDisplay->CheckStatus())
+        {
+        case MStatusDisplay::kLoopNone:
+            break;
+        case MStatusDisplay::kLoopStop:
+            rc = kFALSE;
+            fDisplay->ClearStatus();
+            break;
+        case MStatusDisplay::kFileExit:
+            fParList->SetDisplay(NULL);
+            delete fDisplay;
+            SetDisplay(NULL);
+            fProgress = NULL;
+            gSystem->ProcessEvents();
+            return kTRUE;
+        default:
+            fDisplay->ClearStatus();
+            *fLog << warn << "Display shows unknown status... cleared." << endl;
+            break;
+        }
+
+    //
+    // Check System time (don't loose too much time by updates)
+    //
+    static TTime t0 = gSystem->Now();
+
+    const TTime t1 = gSystem->Now();
+    if (t1-t0 < (TTime)20)
+        return rc;
+
+    t0 = t1;
+
+    //
+    // Set new progress bar position
+    //
+    fProgress->SetPosition(num);
+
+    //
+    // Handle GUI events (display changes)
+    //
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
+    gSystem->ProcessEvents();
+#else
+    if (fDisplay)
+        gSystem->ProcessEvents();
+    else
+        gClient->ProcessEventsFor(fProgress);
+#endif
+
+    return rc;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -193,5 +284,5 @@
 // for developers or use in special jobs only!
 //
-Bool_t MEvtLoop::Process(Int_t maxcnt) const
+Bool_t MEvtLoop::Process(Int_t maxcnt)
 {
     //
@@ -208,10 +299,9 @@
     *fLog << " events)..." << flush;
 
+    Int_t entries = INT_MAX;
+
     if (fProgress)
     {
         fProgress->Reset();
-
-        Int_t entries = INT_MAX;
-
 #ifdef __MARS__
         // limits.h
@@ -228,4 +318,10 @@
     }
 
+    if (fDisplay)
+    {
+        fDisplay->SetStatusLine1("Processing...");
+        fDisplay->SetStatusLine2("");
+    }
+
     Int_t dummy = maxcnt<0 ? 0 : maxcnt;
 
@@ -246,37 +342,33 @@
     if (maxcnt<0)
         // process first and increment if sucessfull
-        if (fProgress)
-            while ((rc=fTaskList->Process())==kTRUE)
-            {
-                fProgress->SetPosition(++dummy);
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
-                gSystem->ProcessEvents();
-#else
-                gClient->ProcessEventsFor(fProgress);
-#endif
-                numcnts++;
-            }
-        else
-            while ((rc=fTaskList->Process())==kTRUE) numcnts++;
+        while ((rc=fTaskList->Process())==kTRUE)
+        {
+            numcnts++;
+            if (!ProcessGuiEvents(++dummy))
+                break;
+        }
     else
         // check for number and break if unsuccessfull
-        if (fProgress)
-            while (dummy-- && (rc=fTaskList->Process())==kTRUE)
-            {
-                fProgress->SetPosition(maxcnt - dummy);
+        while (dummy-- && (rc=fTaskList->Process())==kTRUE)
+        {
+            numcnts++;
+            if (!ProcessGuiEvents(maxcnt - dummy))
+                break;
+        }
+
+    //
+    // stop stop-watch, print results
+    //
+    clock.Stop();
+
+    if (fProgress)
+    {
+        fProgress->SetPosition(maxcnt>0 ? TMath::Min(maxcnt, entries) : entries);
 #if ROOT_VERSION_CODE < ROOT_VERSION(3,02,06)
-                gSystem->ProcessEvents();
+        gSystem->ProcessEvents();
 #else
-                gClient->ProcessEventsFor(fProgress);
+        gClient->ProcessEventsFor(fDisplay ? fDisplay : fProgress);
 #endif
-                numcnts++;
-            }
-        else
-            while (dummy-- && (rc=fTaskList->Process())==kTRUE) numcnts++;
-
-    //
-    // stop stop-watch, print results
-    //
-    clock.Stop();
+    }
 
     *fLog << all << "Ready!" << endl << endl;
@@ -306,4 +398,10 @@
     //  execute the post process of all tasks
     //
+    if (fDisplay)
+    {
+        // Set status lines
+        fDisplay->SetStatusLine1("PostProcessing...");
+        fDisplay->SetStatusLine2("");
+    }
     return fTaskList->PostProcess();
 }
@@ -329,4 +427,17 @@
     if (!PostProcess())
         return kFALSE;
+
+    if (!fDisplay)
+        return rc;
+
+    // Set status lines
+    fDisplay->SetStatusLine1(fName);
+    fDisplay->SetStatusLine2(rc ? "Done." : "ERROR");
+    // Stop automatic update
+    fDisplay->StopUpdate();
+    // Reallow context menus
+    fDisplay->SetNoContextMenu(kFALSE);
+    // Reallow user to exit window by File menu
+    fDisplay->UnLock();
 
     //
Index: trunk/MagicSoft/Mars/mbase/MEvtLoop.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MEvtLoop.h	(revision 1965)
@@ -27,5 +27,5 @@
     MTaskList *fTaskList;      //!
 
-    TGProgressBar *fProgress;  //!
+    TGProgressBar   *fProgress;  //!
 
     enum { kIsOwner = BIT(14) };
@@ -35,4 +35,6 @@
 
     void StreamPrimitive(ofstream &out) const;
+
+    Bool_t ProcessGuiEvents(Int_t num);
 
 public:
@@ -44,4 +46,6 @@
     MTaskList *GetTaskList() const      { return fTaskList; }
 
+    MStatusDisplay *GetDisplay() { return fDisplay; }
+
     void SetOwner(Bool_t enable=kTRUE);
 
@@ -52,5 +56,5 @@
 
     Bool_t PreProcess(const char *tlist="MTaskList");
-    Bool_t Process(Int_t maxcnt) const;
+    Bool_t Process(Int_t maxcnt);
     Bool_t PostProcess() const;
 
Index: trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1965)
@@ -37,14 +37,14 @@
 #include "MParContainer.h"
 
-#include <ctype.h>       // isdigit
-#include <fstream.h>     // ofstream, AsciiWrite
-
-#include <TEnv.h>        // Env::Lookup
-#include <TClass.h>      // IsA
-#include <TObjArray.h>   // TObjArray
-#include <TBaseClass.h>  // GetClassPointer
-#include <TMethodCall.h> // TMethodCall, AsciiWrite
-#include <TDataMember.h> // TDataMember, AsciiWrite
-#include <TVirtualPad.h> // gPad
+#include <ctype.h>        // isdigit
+#include <fstream.h>      // ofstream, AsciiWrite
+
+#include <TEnv.h>         // Env::Lookup
+#include <TClass.h>       // IsA
+#include <TObjArray.h>    // TObjArray
+#include <TBaseClass.h>   // GetClassPointer
+#include <TMethodCall.h>  // TMethodCall, AsciiWrite
+#include <TDataMember.h>  // TDataMember, AsciiWrite
+#include <TVirtualPad.h>  // gPad
 
 #include "MLog.h"
@@ -52,5 +52,5 @@
 
 #ifndef __COSY__
-#include "MEvtLoop.h"    // gListOfPrimitives
+#include "MEvtLoop.h"     // gListOfPrimitives
 #else
 TList *gListOfPrimitives; // forard declaration in MParContainer.h
@@ -71,4 +71,6 @@
 
     fReadyToSave = named.fReadyToSave;
+
+    fDisplay = named.fDisplay;
 }
 
Index: trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1965)
@@ -26,4 +26,5 @@
 class TDataMember;
 class TMethodCall;
+class MStatusDisplay;
 
 class MParContainer : public TObject
@@ -34,4 +35,6 @@
 
     MLog   *fLog;         // The general log facility for this object, initialized with the global object
+
+    MStatusDisplay *fDisplay;
 
 private:
@@ -49,6 +52,6 @@
     };
 
-    MParContainer(const char *name="", const char *title="") : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) {  }
-    MParContainer(const TString &name, const TString &title) : fName(name), fTitle(title), fLog(&gLog), fReadyToSave(kFALSE) {  }
+    MParContainer(const char *name="", const char *title="") : fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE) {  }
+    MParContainer(const TString &name, const TString &title) : fName(name), fTitle(title), fLog(&gLog), fDisplay(NULL), fReadyToSave(kFALSE) {  }
     MParContainer(const MParContainer &named);
     MParContainer& operator=(const MParContainer& rhs);
@@ -64,5 +67,5 @@
     virtual void        FillBuffer(char *&buffer);
 
-    virtual const char   *GetDescriptor() const { return Form("%s [%s]", fName.Data(), ClassName()); }
+    virtual const char   *GetDescriptor() const { return fName==ClassName() ? ClassName() : Form("%s [%s]", fName.Data(), ClassName()); }
     virtual const TString GetUniqueName() const;
     virtual const char   *GetName() const       { return fName.Data(); }
@@ -87,4 +90,6 @@
     virtual void   EnableGraphicalOutput(Bool_t flag=kTRUE) { flag ? SetBit(kEnableGraphicalOutput) : ResetBit(kEnableGraphicalOutput);}
     virtual Bool_t IsGraphicalOutputEnabled() const  { return TestBit(kEnableGraphicalOutput); }
+
+    virtual void SetDisplay(MStatusDisplay *d) { fDisplay = d; }
 
     TMethodCall *GetterMethod(const char *name) const;
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1965)
@@ -138,4 +138,10 @@
 }
 
+void MParList::SetDisplay(MStatusDisplay *d)
+{
+    fContainer->ForEach(MParContainer, SetDisplay)(d);
+    MParContainer::SetDisplay(d);
+}
+
 // --------------------------------------------------------------------------
 //
@@ -149,5 +155,4 @@
     //  check if the object (you want to add) exists
     //
-
     if (!cont)
         return kFALSE;
Index: trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1965)
@@ -50,4 +50,5 @@
 
     void SetLogStream(MLog *log);
+    void SetDisplay(MStatusDisplay *d);
 
     TObject *FindObject(const char *name) const;
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1965)
@@ -57,5 +57,5 @@
 #include "MTaskList.h"
 
-#include <fstream.h>     // ofstream, SavePrimitive
+#include <fstream.h>        // ofstream, SavePrimitive
 
 #include <TClass.h>
@@ -70,4 +70,6 @@
 #include "MInputStreamID.h"
 
+#include "MStatusDisplay.h"
+
 ClassImp(MTaskList);
 
@@ -133,4 +135,10 @@
     fTasks->ForEach(MTask, SetLogStream)(log);
     MParContainer::SetLogStream(log);
+}
+
+void MTaskList::SetDisplay(MStatusDisplay *d)
+{
+    fTasks->ForEach(MTask, SetDisplay)(d);
+    MParContainer::SetDisplay(d);
 }
 
@@ -350,5 +358,5 @@
 //
 Bool_t MTaskList::PreProcess(MParList *pList)
-{ 
+{
     *fLog << all << "Preprocessing... " << flush;
 
@@ -370,4 +378,6 @@
     {
         *fLog << all << task->GetName() << "... " << flush;
+        if (fDisplay)
+            fDisplay->SetStatusLine2(*task);
 
         //
@@ -539,4 +549,6 @@
     {
         *fLog << all << task->GetName() << "... " << flush;
+        if (fDisplay)
+            fDisplay->SetStatusLine2(*task);
 
         if (!task->CallPostProcess())
Index: trunk/MagicSoft/Mars/mbase/MTaskList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.h	(revision 1965)
@@ -44,4 +44,5 @@
 
     void SetLogStream(MLog *log);
+    void SetDisplay(MStatusDisplay *d);
 
     Bool_t AddToListBefore(MTask *task, const MTask *where, const char *tType="All");
Index: trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.cc	(revision 1965)
@@ -162,8 +162,8 @@
     AddSetupElements();
 
-    TCanvas *canv2 = AddTab("Errors");
-    TCanvas *canv3 = AddTab("Phot/Err");
-    TCanvas *canv4 = AddTab("Levels");
-    TCanvas *canv5 = AddTab("Pedestals");
+    fCanvas2 = AddTab("Errors");
+    fCanvas3 = AddTab("Phot/Err");
+    fCanvas4 = AddTab("Levels");
+    fCanvas5 = AddTab("Pedestals");
 
     //
@@ -184,11 +184,11 @@
     fCanvas->cd();
     fDisplay->Draw();
-    canv2->cd();
+    fCanvas2->cd();
     fDisplay2->Draw();
-    canv3->cd();
+    fCanvas3->cd();
     fDisplay3->Draw();
-    canv4->cd();
+    fCanvas4->cd();
     fDisplay4->Draw();
-    canv5->cd();
+    fCanvas5->cd();
     fDisplay5->Draw();
 
@@ -239,5 +239,5 @@
     // Display the requested event. This does a Canvas update, too.
     //
-    MCerPhotEvt  *evt = NULL;
+    MCerPhotEvt *evt = NULL;
     if (fDisplayRaw)
     {
@@ -259,9 +259,19 @@
     const MPedestalCam *ped   = (MPedestalCam*)plist->FindObject("MPedestalCam");
 
-    fDisplay->DrawPhotNum(evt);
-    fDisplay2->DrawErrorPhot(evt);
-    fDisplay3->DrawRatio(evt);
-    fDisplay4->DrawLevels(evt, *clean);
-    fDisplay5->DrawPedestals(ped);
+    fDisplay->FillPhotNum(*evt);
+    fCanvas->Modified();
+    fCanvas->Update();
+    fDisplay2->FillErrorPhot(*evt);
+    fCanvas2->Modified();
+    fCanvas2->Update();
+    fDisplay3->FillRatio(*evt);
+    fCanvas3->Modified();
+    fCanvas3->Update();
+    fDisplay4->FillLevels(*evt, *clean);
+    fCanvas4->Modified();
+    fCanvas4->Update();
+    fDisplay5->FillPedestals(*ped);
+    fCanvas5->Modified();
+    fCanvas5->Update();
 }
 
Index: trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.h	(revision 1964)
+++ trunk/MagicSoft/Mars/meventdisp/MGCamDisplay.h	(revision 1965)
@@ -25,4 +25,9 @@
     MCamDisplay *fDisplay5;
 
+    TCanvas *fCanvas2;
+    TCanvas *fCanvas3;
+    TCanvas *fCanvas4;
+    TCanvas *fCanvas5;
+
     void AddSetupElements();
     void UpdateDisplay();
Index: trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 1965)
@@ -43,4 +43,5 @@
 
 #include "MRawRunHeader.h"
+#include "MStatusDisplay.h"
 
 #include "MMcRunHeader.hxx"
@@ -55,5 +56,5 @@
 {
     fName  = "MRead";
-    fTitle = "Task to loop over all events in a tree of a Mars file.";
+    fTitle = "Read tree and run headers from Mars file.";
 }
 
@@ -68,5 +69,5 @@
 {
     fName  = name  ? name  : "MRead";
-    fTitle = title ? title : "Task to loop over all events in a tree of a Mars file.";
+    fTitle = title ? title : "Read tree and run headers from Mars file.";
 
     //
@@ -144,4 +145,12 @@
     *fLog << " '" << GetFileName() << "' (before event #";
     *fLog << GetNumEntry()-1 << ")" << endl;
+
+    if (fDisplay)
+    {
+        TString txt = GetFileName();
+        txt += " @ ";
+        txt += GetNumEntry()-1;
+        fDisplay->SetStatusLine2(txt);
+    }
 
     if (rawheader)
Index: trunk/MagicSoft/Mars/mfileio/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mfileio/Makefile	(revision 1964)
+++ trunk/MagicSoft/Mars/mfileio/Makefile	(revision 1965)
@@ -20,5 +20,6 @@
 # @endcode 
 
-INCLUDES = -I. -I../mbase -I../mraw -I../mmc -I../mdata -I../manalysis -I../mgeom -I../mhist
+INCLUDES = -I. -I../mbase -I../mraw -I../mmc -I../mdata -I../manalysis \
+	   -I../mgeom -I../mhist -I../mmain
 
 # @code 
@@ -35,4 +36,5 @@
            MReadTree.cc \
            MReadMarsFile.cc \
+           MRunHeader.cc \
            MWriteFile.cc \
            MWriteAsciiFile.cc \
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.cc	(revision 1965)
@@ -33,6 +33,7 @@
 //
 ///////////////////////////////////////////////////////////////////////
+#include "MGeomCam.h"
 
-#include "MGeomCam.h"
+#include <TClass.h>
 
 #include "MLog.h"
@@ -138,2 +139,6 @@
 } 
 
+TObject *MGeomCam::Clone(const char *newname) const
+{
+    return (TObject*)IsA()->New();
+}
Index: trunk/MagicSoft/Mars/mgeom/MGeomCam.h
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCam.h	(revision 1965)
@@ -28,6 +28,7 @@
 public:
     MGeomCam(UInt_t npix, Float_t dist, const char *name=NULL, const char *title=NULL);
+    virtual ~MGeomCam();
 
-    virtual ~MGeomCam();
+    virtual TObject *Clone(const char *newname=NULL) const;
 
     Float_t GetCameraDist() const      { return fCamDist; }
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamCT1.cc	(revision 1965)
@@ -214,5 +214,5 @@
     // fill the geometry class with the coordinates of the CT1 camera
     //
-    *fLog << inf << " Create CT1 geometry " << endl;
+    //*fLog << inf << " Create CT1 geometry " << endl;
 
     //
Index: trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc
===================================================================
--- trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mgeom/MGeomCamMagic.cc	(revision 1965)
@@ -66,5 +66,5 @@
     //   fill the geometry class with the coordinates of the MAGIC camera
     //
-    *fLog << inf << " Creating Magic geometry " << endl ;
+    //*fLog << inf << " Creating Magic geometry " << endl ;
 
     //
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.cc	(revision 1965)
@@ -38,11 +38,11 @@
 
 #include <TBox.h>
-#include <TText.h>
 #include <TArrow.h>
+#include <TLatex.h>
 #include <TStyle.h>
 #include <TCanvas.h>
-//#include <TButton.h>
 #include <TClonesArray.h>
 
+#include "MH.h"
 #include "MHexagon.h"
 
@@ -63,20 +63,35 @@
 // ------------------------------------------------------------------------
 //
-//  default constructor
+//  Default Constructor. To be used by the root system ONLY.
+//
+MCamDisplay::MCamDisplay()
+    : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
+{
+    fNumPixels = 0;
+    fRange     = 0;
+
+    fPixels    = NULL;
+    fLegend    = NULL;
+    fLegText   = NULL;
+    fArrowX    = NULL;
+    fArrowY    = NULL;
+    fLegRadius = NULL;
+    fLegDegree = NULL;
+}
+
+// ------------------------------------------------------------------------
+//
+//  Constructor. Makes a clone of MGeomCam.
 //
 MCamDisplay::MCamDisplay(MGeomCam *geom)
-    : fAutoScale(kTRUE), fW(0), fH(0), fDrawingPad(NULL), fIsAllocated(kFALSE)
-{
-    fGeomCam = (MGeomCam*)geom; // FIXME: Clone doesn't work! (MGeomCam*)geom->Clone();
+    : fGeomCam(NULL), fAutoScale(kTRUE), fW(0), fH(0)
+{
+    fGeomCam = (MGeomCam*)geom->Clone(); 
 
     //
     //  create the hexagons of the display
     //
-    fNumPixels = geom->GetNumPixels();
-    fRange     = geom->GetMaxRadius();
-
-    //
-    // Construct all hexagons. Use new-operator with placement
-    //
+    fNumPixels = fGeomCam->GetNumPixels();
+    fRange     = fGeomCam->GetMaxRadius();
 
     // root 3.02
@@ -85,11 +100,67 @@
     //    not get an automatic context menu when clicked with the right mouse button.
 
+    //
+    // Construct all hexagons. Use new-operator with placement
+    //
     fPixels = new TClonesArray("MHexagon", fNumPixels);
     for (UInt_t i=0; i<fNumPixels; i++)
-        new ((*fPixels)[i]) MHexagon((*geom)[i]);
-
-    //
-    // set the color palette for the TBox elements
-    //
+    {
+        MHexagon &pix = *new ((*fPixels)[i]) MHexagon((*fGeomCam)[i]);
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
+        pix.SetBit(/*kNoContextMenu|*/kCannotPick);
+#endif
+        pix.SetFillColor(16);
+    }
+
+    //
+    // set up the Legend
+    //
+    const Float_t H = 0.9*fRange;
+    const Float_t h = 2./kItemsLegend;
+
+    const Float_t w = fRange/sqrt(fNumPixels);
+
+    fLegend  = new TClonesArray("TBox",  kItemsLegend);
+    fLegText = new TClonesArray("TText", kItemsLegend);
+
+    for (Int_t i = 0; i<kItemsLegend; i++)
+    {
+        TBox  &newbox = *new ((*fLegend)[i])  TBox;
+        TText &newtxt = *new ((*fLegText)[i]) TText;
+
+        newbox.SetX1(fRange);
+        newbox.SetX2(fRange+w);
+        newbox.SetY1(H*( i   *h - 1.));
+        newbox.SetY2(H*((i+1)*h - 1.));
+        newbox.SetFillColor(16);
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
+        newbox.SetBit(/*kNoContextMenu|*/kCannotPick);
+#endif
+
+        newtxt.SetTextSize(0.025);
+        newtxt.SetTextAlign(12);
+        newtxt.SetX(fRange+1.5*w);
+        newtxt.SetY(H*((i+0.5)*h - 1.));
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
+        newtxt.SetBit(/*kNoContextMenu|*/kCannotPick);
+#endif
+    }
+
+    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*fGeomCam->GetConvMm2Deg()*10))/10;
+    text += "\\circ";
+    text = text.Strip(TString::kLeading);
+    fLegDegree = new TLatex(-fRange*.85, -fRange*.75, text);
+    fLegRadius->SetTextSize(0.04);
+    fLegDegree->SetTextSize(0.04);
+
 #if ROOT_VERSION_CODE < ROOT_VERSION(3,01,06)
     SetPalette(1, 0);
@@ -98,36 +169,4 @@
 #endif
 
-    //
-    // set up the Legend
-    //
-    fLegend  = new TClonesArray("TBox",  kItemsLegend);
-    fLegText = new TClonesArray("TText", kItemsLegend);
-
-    for (Int_t i = 0; i<kItemsLegend; i++)
-    {
-        TBox  *newbox = new ((*fLegend)[i])  TBox;
-        TText *newtxt = new ((*fLegText)[i]) TText;
-
-        newbox->SetFillColor(fColors[i]);
-
-        newtxt->SetTextSize(0.025);
-        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);
 }
 
@@ -152,17 +191,5 @@
     delete fLegDegree;
 
-    // delete fGeomCam;
-
-    // Not allocated by MCamDisplay or already deleted by the user
-    if (!fIsAllocated || !gROOT->GetListOfCanvases()->FindObject(fDrawingPad))
-        return;
-
-    // If it is not already removed make sure that nothing of this object
-    // maybe be deleted automatically by the canvas destructor
-    if (!fDrawingPad->GetListOfPrimitives()->FindObject(this))
-        return;
-
-    fDrawingPad->RecursiveRemove(this);
-    delete fDrawingPad;
+    delete fGeomCam;
 }
 
@@ -237,53 +264,96 @@
 // ------------------------------------------------------------------------
 //
+// Call this function to draw the camera layout into your canvas.
+// Setup a drawing canvas. Add this object and all child objects
+// (hexagons, etc) to the current pad. If no pad exists a new one is
+// created.
+//
+void MCamDisplay::Draw(Option_t *option)
+{
+    // root 3.02:
+    // gPad->SetFixedAspectRatio()
+
+    TVirtualPad *pad = gPad ? gPad : MH::MakeDefCanvas("CamDisplay", "Mars Camera Display", 750, 600);
+    pad->SetBorderMode(0);
+    pad->SetFillColor(16);
+
+    //
+    // All this is necessary to get the background in the correct color
+    //
+    pad->Divide(1,1);
+    pad->cd(1);
+
+    gPad->SetBorderMode(0);
+    gPad->SetFillColor(16);
+
+    //
+    // set the color palette for the TBox elements
+    //
+    AppendPad("");
+
+    //
+    // Necessary to visualize the background color (FIXME?)
+    //
+    gPad->Modified();
+    gPad->Update();
+}
+
+
+void MCamDisplay::SetRange()
+{
+    //
+    // Maintain aspect ratio
+    //
+    const float ratio = 1.15;
+
+    const float w = gPad->GetWw();
+    const float h = gPad->GetWh()*ratio;
+
+    if (h<w)
+        gPad->SetPad((1.-h/w)/2, 0, (h/w+1)/2, 0.9999999);
+    else
+        gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1)/2);
+
+    gPad->Range(-fRange, -fRange, (2*ratio-1)*fRange, fRange);
+}
+
+// ------------------------------------------------------------------------
+//
 // This is called at any time the canvas should get repainted.
-// Here we maintain an aspect ratio of 5/4=1.15. This makes sure,
+// Here we maintain an aspect ratio of 1.15. This makes sure,
 // that the camera image doesn't get distorted by resizing the canvas.
 //
 void MCamDisplay::Paint(Option_t *opt)
 {
-    const UInt_t w = (UInt_t)(gPad->GetWw()*gPad->GetAbsWNDC());
-    const UInt_t h = (UInt_t)(gPad->GetWh()*gPad->GetAbsHNDC());
-
-    //
-    // Check for a change in width or height, and make sure, that the
-    // first call also sets the range
-    //
-    if (w*fH == h*fW && fW && fH)
+    if (!fPixels)
         return;
 
     //
-    // Calculate aspect ratio (5/4=1.25 recommended)
-    //
-    const Double_t ratio = (Double_t)w/h;
-
-    Float_t x;
-    Float_t y;
-
-    if (ratio>1.25)
-    {
-        x = (ratio*2-1)*fRange; 
-        y = fRange;
-    }
-    else
-    {
-        x = fRange*1.5;
-        y = fRange*1.25/ratio;
-    }
-
-    fH = h;
-    fW = w;
-
-    //
-    // Set new range
-    //
-    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();
+    // Maintain aspect ratio
+    //
+    SetRange();
+
+    //
+    // Maintain colors
+    //
+    SetPalette();
+
+    //
+    // Paint primitives
+    //
+    for (UInt_t i=0; i<fNumPixels; i++)
+        (*this)[i].Paint();
+
+    for (Int_t i=0; i<kItemsLegend; i++)
+    {
+        GetBox(i)->Paint();
+        GetText(i)->Paint();
+    }
+
+    fArrowX->Paint(">");
+    fArrowY->Paint(">");
+
+    fLegRadius->Paint();
+    fLegDegree->Paint();
 }
 
@@ -321,61 +391,38 @@
         gStyle->SetPalette(ncolors, colors);
 
-    if (fDrawingPad)
+    //
+    // Change the colors of the pixels
+    //
+    for (unsigned int i=0; i<fNumPixels; i++)
     {
         //
-        // Set the colors of the legend
+        // Get the old color index and check whether it is
+        // background or transparent
         //
-        for (int i=0; i<kItemsLegend; i++)
+        Int_t col = (*this)[i].GetFillColor();
+        if (col==10 || col==16)
+            continue;
+
+        //
+        // Search for the color index (level) in the color table
+        //
+        int idx;
+        for (idx=0; idx<kItemsLegend; idx++)
+            if (col==fColors[idx])
+                break;
+
+        //
+        // Should not happen
+        //
+        if (idx==kItemsLegend)
         {
-            Int_t col = GetBox(i)->GetFillColor();
-
-            //
-            // Make sure, that the legend is already colored
-            //
-            if (col==10 || col==22)
-                continue;
-            GetBox(i)->SetFillColor(gStyle->GetColorPalette(i));
+            cout << "MCamDisplay::SetPalette: Strange... FIXME!" << endl;
+            continue;
         }
 
         //
-        // Change the colors of the pixels
+        // Convert the old color index (level) into the new one
         //
-        for (unsigned int i=0; i<fNumPixels; i++)
-        {
-            //
-            // Get the old color index and check whether it is
-            // background or transparent
-            //
-            Int_t col = (*this)[i].GetFillColor();
-            if (col==10 || col==22)
-                continue;
-
-            //
-            // Search for the color index (level) in the color table
-            //
-            int idx;
-            for (idx=0; idx<kItemsLegend; idx++)
-                if (col==fColors[idx])
-                    break;
-            //
-            // Should not happen
-            //
-            if (idx==kItemsLegend)
-            {
-                cout << "MCamDisplay::SetPalette: Strange... FIXME!" << endl;
-                continue;
-            }
-
-            //
-            // Convert the old color index (level) into the new one
-            //
-            (*this)[i].SetFillColor(gStyle->GetColorPalette(idx));
-        }
-
-        //
-        // Update the pad on the screen
-        //
-        fDrawingPad->Modified();
-        fDrawingPad->Update();
+        (*this)[i].SetFillColor(gStyle->GetColorPalette(idx));
     }
 
@@ -384,5 +431,8 @@
     //
     for (int i=0; i<kItemsLegend; i++)
+    {
         fColors[i] = gStyle->GetColorPalette(i);
+        GetBox(i)->SetFillColor(fColors[i]);
+    }
 }
 
@@ -402,129 +452,17 @@
 }
 
-// ------------------------------------------------------------------------
-//
-// Call this function to draw the camera layout into your canvas.
-// Setup a drawing canvas. Add this object and all child objects
-// (hexagons, etc) to the current pad. If no pad exists a new one is
-// created.
-//
-void MCamDisplay::Draw(Option_t *option)
-{
-    // root 3.02:
-    // gPad->SetFixedAspectRatio()
-
-    if (fDrawingPad)
-        return;
-
-    //
-    // if no canvas is yet existing to draw into, create a new one
-    //
+void MCamDisplay::SetPalette()
+{
+    for (int i=0; i<kItemsLegend; i++)
+        GetBox(i)->SetFillColor(fColors[i]);
+}
+
+void MCamDisplay::DrawPixelNumbers()
+{
+    for (int i=0; i<kItemsLegend; i++)
+        fColors[i] = 16;
+
     if (!gPad)
-    {
-        fDrawingPad = new TCanvas("CamDisplay", "Magic Camera Display", 0, 0, 750, 600);
-        fIsAllocated = kTRUE;
-    }
-    else
-    {
-        fDrawingPad = gPad;
-        fIsAllocated = kFALSE;
-    }
-
-    //
-    // Setup the correct environment
-    //
-    fDrawingPad->SetBorderMode(0);
-    fDrawingPad->SetFillColor(22);
-
-    //
-    // Set the initial coordinate range
-    //
-    Paint();
-
-    /*
-     //
-     // Create and draw the buttons which allows changing the
-     // color palette of the display
-     //
-     TButton *but;
-     char txt[100];
-     sprintf(txt, "((MCamDisplay*)0x%lx)->SetPalette(1,0);", this);
-     but = new TButton("Pretty", txt, 0.01, 0.95, 0.15, 0.99);
-     but->Draw();
-     sprintf(txt, "((MCamDisplay*)0x%lx)->SetPalette(51,0);", this);
-     but = new TButton("Deap Sea", txt, 0.16, 0.95, 0.30, 0.99);
-     but->Draw();
-     sprintf(txt, "((MCamDisplay*)0x%lx)->SetPalette(52,0);", this);
-     but = new TButton("Blue Inv", txt, 0.31, 0.95, 0.45, 0.99);
-     but->Draw();
-     */
-
-    //
-    // Draw all pixels of the camera
-    //  (means apend all pixelobjects to the current pad)
-    //
-    for (UInt_t i=0; i<fNumPixels; i++)
-    {
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        (*this)[i].SetBit(/*kNoContextMenu|*/kCannotPick);
-#endif
-        (*this)[i].SetFillColor(22);
-        (*this)[i].Draw();
-    }
-
-    fArrowX->Draw();
-    fArrowY->Draw();
-
-    fLegRadius->Draw();
-    fLegDegree->Draw();
-
-    //
-    // initialize and draw legend
-    //
-    const Float_t H = 0.9*fRange;
-    const Float_t h = 2./kItemsLegend;
-
-    const Float_t w = fRange/sqrt(fNumPixels);
-
-    for (Int_t i=0; i<kItemsLegend; i++)
-    {
-        TBox *box = GetBox(i);
-        box->SetX1(fRange);
-        box->SetX2(fRange+w);
-        box->SetY1(H*( i   *h - 1.));
-        box->SetY2(H*((i+1)*h - 1.));
-        box->SetFillColor(22);
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        box->SetBit(/*kNoContextMenu|*/kCannotPick);
-#endif
-        box->Draw();
-
-        TText *txt = GetText(i);
-        txt->SetX(fRange+1.5*w);
-        txt->SetY(H*((i+0.5)*h - 1.));
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,01,06)
-        txt->SetBit(/*kNoContextMenu|*/kCannotPick);
-#endif
-        txt->Draw();
-    }
-
-    //
-    // Append this object, so that the aspect ratio is maintained
-    // (Paint-function is called)
-    // Add it here so that root will have it first in the internal list:
-    // This means, that root 'sees' the whole camera instead of all the
-    // single hexagons.
-    //
-    AppendPad(option);
-
-    //fDrawingPad->SetEditable(kFALSE);
-}
-
-void MCamDisplay::DrawPixelNumbers()
-{
-    if (!fDrawingPad)
         Draw();
-
-    fDrawingPad->cd();
 
     TText txt;
@@ -545,19 +483,9 @@
 // ------------------------------------------------------------------------
 //
-// Call this function to draw the number of photo electron into the
+// Call this function to fill the number of photo electron into the
 // camera.
 //
-void MCamDisplay::DrawPhotNum(const MCerPhotEvt *event)
-{
-    if (!event)
-        return;
-
-    Draw();
-
-    fDrawingPad->cd();
-
-    for (int i=0; i<kItemsLegend; i++)
-        GetBox(i)->SetFillColor(fColors[i]);
-
+void MCamDisplay::FillPhotNum(const MCerPhotEvt &event)
+{
     //
     // Reset pixel colors to default value
@@ -573,9 +501,9 @@
     if (fAutoScale)
     {
-        min = event->GetNumPhotonsMin(fGeomCam);
-        max = event->GetNumPhotonsMax(fGeomCam);
-
-        if (max < 20.)
-            max = 20.;
+        min = event.GetNumPhotonsMin(fGeomCam);
+        max = event.GetNumPhotonsMax(fGeomCam);
+
+        if (max < 1.)
+            max = 1.;
 
         UpdateLegend(min, max);
@@ -585,9 +513,9 @@
     //   update the colors in the picture
     //
-    const Int_t entries = event->GetNumPixels();
+    const Int_t entries = event.GetNumPixels();
 
     for (Int_t i=0; i<entries; i++)
     {
-        const MCerPhotPix &pix = (*event)[i];
+        const MCerPhotPix &pix = event[i];
 
         if (!pix.IsPixelUsed())
@@ -596,29 +524,13 @@
         SetPixColor(pix, i, min, max);
     }
-
-    //
-    // Update display physically
-    //
-    fDrawingPad->Modified();
-    fDrawingPad->Update();
-}
-
-// ------------------------------------------------------------------------
-//
-// Call this function to draw the number of photo electron into the
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill 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]);
-
+void MCamDisplay::FillPedestals(const MPedestalCam &event)
+{
     //
     // Reset pixel colors to default value
@@ -634,6 +546,6 @@
     if (fAutoScale)
     {
-        min = event->GetMeanMin(fGeomCam);
-        max = event->GetMeanMax(fGeomCam);
+        min = event.GetMeanMin(fGeomCam);
+        max = event.GetMeanMax(fGeomCam);
 
         if (max < 20.)
@@ -646,34 +558,17 @@
     //   update the colors in the picture
     //
-    const Int_t entries = event->GetSize();
+    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
+        SetPixColorPedestal(event[i], i, min, max);
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill the error of number of photo electron
 // into the camera.
 //
-void MCamDisplay::DrawErrorPhot(const MCerPhotEvt *event)
-{
-    if (!event)
-        return;
-
-    if (!fDrawingPad)
-        Draw();
-
-    fDrawingPad->cd();
-
-    for (int i=0; i<kItemsLegend; i++)
-        GetBox(i)->SetFillColor(fColors[i]);
-
+void MCamDisplay::FillErrorPhot(const MCerPhotEvt &event)
+{
     //
     // Reset pixel colors to default value
@@ -689,6 +584,6 @@
     if (fAutoScale)
     {
-        min = event->GetErrorPhotMin(fGeomCam);
-        max = event->GetErrorPhotMax(fGeomCam);
+        min = event.GetErrorPhotMin(fGeomCam);
+        max = event.GetErrorPhotMax(fGeomCam);
 
         if (max < 20.)
@@ -701,9 +596,9 @@
     //   update the colors in the picture
     //
-    const Int_t entries = event->GetNumPixels();
+    const Int_t entries = event.GetNumPixels();
 
     for (Int_t i=0; i<entries; i++)
     {
-        const MCerPhotPix &pix = (*event)[i];
+        const MCerPhotPix &pix = event[i];
 
         if (!pix.IsPixelUsed())
@@ -712,30 +607,13 @@
         SetPixColorError(pix, i, min, max);
     }
-
-    //
-    // Update display physically
-    //
-    fDrawingPad->Modified();
-    fDrawingPad->Update();
-}
-
-// ------------------------------------------------------------------------
-//
-// Call this function to draw the ratio of the number of photons
+}
+
+// ------------------------------------------------------------------------
+//
+// Call this function to fill 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]);
-
+void MCamDisplay::FillRatio(const MCerPhotEvt &event)
+{
     //
     // Reset pixel colors to default value
@@ -751,6 +629,6 @@
     if (fAutoScale)
     {
-        min = event->GetRatioMin();
-        max = event->GetRatioMax();
+        min = event.GetRatioMin();
+        max = event.GetRatioMax();
 
         UpdateLegend(min, max);
@@ -760,9 +638,9 @@
     //   update the colors in the picture
     //
-    const Int_t entries = event->GetNumPixels();
+    const Int_t entries = event.GetNumPixels();
 
     for (Int_t i=0; i<entries; i++)
     {
-        const MCerPhotPix &pix = (*event)[i];
+        const MCerPhotPix &pix = event[i];
 
         if (!pix.IsPixelUsed())
@@ -771,29 +649,12 @@
         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]);
-
+}
+
+// ------------------------------------------------------------------------
+//
+// Fill the colors in respect to the cleaning levels
+//
+void MCamDisplay::FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2)
+{
     //
     // Reset pixel colors to default value
@@ -804,9 +665,9 @@
     //   update the colors in the picture
     //
-    const Int_t entries = event->GetNumPixels();
+    const Int_t entries = event.GetNumPixels();
 
     for (Int_t i=0; i<entries; i++)
     {
-        const MCerPhotPix &pix = (*event)[i];
+        const MCerPhotPix &pix = event[i];
 
         if (!pix.IsPixelUsed())
@@ -815,24 +676,18 @@
         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());
-}
-
-// ------------------------------------------------------------------------
-//
-// reset the all pixel colors to a default value
+}
+
+// ------------------------------------------------------------------------
+//
+// Fill the colors in respect to the cleaning levels
+//
+void MCamDisplay::FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean)
+{
+    FillLevels(event, clean.GetCleanLvl1(), clean.GetCleanLvl2());
+}
+
+// ------------------------------------------------------------------------
+//
+// Reset the all pixel colors to a default value
 //
 void MCamDisplay::Reset()
@@ -844,12 +699,12 @@
 // ------------------------------------------------------------------------
 //
-//   Here we calculate the color index for the current value.
-//   The color index is defined with the class TStyle and the
-//   Color palette inside. We use the command gStyle->SetPalette(1,0)
-//   for the display. So we have to convert the value "wert" into
-//   a color index that fits the color palette.
-//   The range of the color palette is defined by the values fMinPhe
-//   and fMaxRange. Between this values we have 50 color index, starting
-//   with 0 up to 49.
+//  Here we calculate the color index for the current value.
+//  The color index is defined with the class TStyle and the
+//  Color palette inside. We use the command gStyle->SetPalette(1,0)
+//  for the display. So we have to convert the value "wert" into
+//  a color index that fits the color palette.
+//  The range of the color palette is defined by the values fMinPhe
+//  and fMaxRange. Between this values we have 50 color index, starting
+//  with 0 up to 49.
 //
 Int_t MCamDisplay::GetColor(Float_t val, Float_t min, Float_t max)
@@ -877,20 +732,14 @@
 // ------------------------------------------------------------------------
 //
-//    change the text on the legend according to the range of the
-//    Display
+//  Change the text on the legend according to the range of the Display
 //
 void MCamDisplay::UpdateLegend(Float_t minphe, Float_t maxphe)
 {
-    char text[10];
-
     for (Int_t i=0; i<kItemsLegend; i+=3)
     {
         const Float_t val = minphe + (Float_t)i/kItemsLegend * (maxphe-minphe) ;
 
-        sprintf(text, "%5.1f", val);
-
         TText &txt = *GetText(i);
-
-        txt.SetText(txt.GetX(), txt.GetY(), text);
+        txt.SetText(txt.GetX(), txt.GetY(), Form("%5.1f", val));
     }
 }
@@ -902,4 +751,6 @@
 void MCamDisplay::SavePrimitive(ofstream &out, Option_t *opt)
 {
+    cout << "MCamDisplay::SavePrimitive: Must be rewritten!" << endl;
+    /*
     if (!gROOT->ClassSaved(TCanvas::Class()))
         fDrawingPad->SavePrimitive(out, opt);
@@ -907,4 +758,5 @@
     out << "   " << fDrawingPad->GetName() << "->SetWindowSize(";
     out << fDrawingPad->GetWw() << "," << fDrawingPad->GetWh() << ");" << endl;
+    */
 }
 
@@ -951,4 +803,4 @@
 { 
     (*this)[pixnum].SetFillColor(GetColor(color, min, max));
-
-}
+}
+
Index: trunk/MagicSoft/Mars/mgui/MCamDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mgui/MCamDisplay.h	(revision 1965)
@@ -12,5 +12,4 @@
 class TText;
 class TArrow;
-class TVirtualPad;
 
 class MGeomCam;
@@ -46,6 +45,4 @@
     UInt_t         fW;           // Width of canvas
     UInt_t         fH;           // Height of canvas
-    TVirtualPad   *fDrawingPad;  // pad in which we are drawing
-    Bool_t         fIsAllocated;
 
     TBox  *GetBox(Int_t i)  { return (TBox*) fLegend->At(i); }
@@ -62,24 +59,27 @@
 
     void UpdateLegend(Float_t min, Float_t max);
-    void Paint(Option_t *option="");
+    void SetRange();
+    void SetPalette();
 
 public:
+    MCamDisplay();
     MCamDisplay(MGeomCam *geom);
     ~MCamDisplay();
 
     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 FillPhotNum(const MCerPhotEvt &event);
+    void FillRatio(const MCerPhotEvt &event);
+    void FillLevels(const MCerPhotEvt &event, Float_t lvl1, Float_t lvl2);
+    void FillErrorPhot(const MCerPhotEvt &event);
+    void FillLevels(const MCerPhotEvt &event, const MImgCleanStd &clean);
+    void FillPedestals(const MPedestalCam &event);
 
     void DrawPixelNumbers();
 
-    virtual void  Reset();
-    virtual void  Draw(Option_t *option="");
-    virtual void  SavePrimitive(ofstream &out, Option_t *);
-    virtual Int_t DistancetoPrimitive(Int_t px, Int_t py);
+    void     Paint(Option_t *option="");
+    void     Reset();
+    void     Draw(Option_t *option="");
+    void     SavePrimitive(ofstream &out, Option_t *);
+    Int_t    DistancetoPrimitive(Int_t px, Int_t py);
     //virtual void  ExecuteEvent(Int_t event, Int_t px, Int_t py);
 
Index: trunk/MagicSoft/Mars/mgui/MHexagon.cc
===================================================================
--- trunk/MagicSoft/Mars/mgui/MHexagon.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mgui/MHexagon.cc	(revision 1965)
@@ -224,5 +224,4 @@
 void MHexagon::PaintHexagon(Float_t inX, Float_t inY, Float_t inD)
 { 
-
     const Int_t np = 6;
 
@@ -230,19 +229,20 @@
     const Float_t dy[np+1] = { .2886,  .5772,  .2886, -.2886, -.5772, -.2886, .2886 };
 
-    static Float_t x[np+1], y[np+1];
-
     TAttLine::Modify();    // Change line attributes only if neccessary
     TAttFill::Modify();    // Change fill attributes only if neccessary
 
+    //
     //  calculate the positions of the pixel corners
-
-    for (Int_t i=0; i<=np; i++)
+    //
+    Float_t x[np+1], y[np+1];
+    for (Int_t i=0; i<np+1; i++)
     {
-        x[i] = inX + dx[i]* inD;
-        y[i] = inY + dy[i]* inD;
+        x[i] = inX + dx[i]*inD;
+        y[i] = inY + dy[i]*inD;
     }
 
-    //   paint the pixel (hopefully)
-
+    //
+    //   paint the pixel
+    //
     if (GetFillColor())
         gPad->PaintFillArea(np, x, y);
@@ -250,5 +250,4 @@
     if (GetLineStyle())
         gPad->PaintPolyLine(np+1, x, y);
-
 }
 
Index: trunk/MagicSoft/Mars/mgui/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mgui/Makefile	(revision 1964)
+++ trunk/MagicSoft/Mars/mgui/Makefile	(revision 1965)
@@ -22,5 +22,5 @@
 #  connect the include files defined in the config.mk file
 #
-INCLUDES = -I. -I../mbase -I../mgeom -I../manalysis -I../mimage
+INCLUDES = -I. -I../mbase -I../mgeom -I../manalysis -I../mimage -I../mhist
 
 #------------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mhist/MFillH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1965)
@@ -72,4 +72,5 @@
 
 #include <TClass.h>
+#include <TCanvas.h>
 
 #include "MDataChain.h"
@@ -82,4 +83,5 @@
 
 #include "MParList.h"
+#include "MStatusDisplay.h"
 
 ClassImp(MFillH);
@@ -99,4 +101,5 @@
 
     fIndex  = NULL;
+    fCanvas = NULL;
 }
 
@@ -143,5 +146,5 @@
 
     fTitle = "Fill " + fHName;
-    if (!par)
+    if (fParContainerName.IsNull())
         return;
 
@@ -313,4 +316,15 @@
 }
 
+Bool_t MFillH::DrawToDisplay()
+{
+    if (!fDisplay)
+        return kTRUE;
+
+    fCanvas = &fDisplay->AddTab(fH->GetName());
+    fH->Draw();
+
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -353,6 +367,8 @@
         if (!obj)
         {
+            /*
             if (cls==name)
-                *fLog << inf << "Object '" << fHName << "' not found in parlist... creating." << endl;
+            *fLog << inf << "Object '" << fHName << "' not found in parlist... creating." << endl;
+            */
             obj = pList->FindCreateObj(cls, name);
         }
@@ -369,5 +385,5 @@
         if (!obj->InheritsFrom(tcls))
         {
-            *fLog << err << dbginf << obj->GetName() << " doesn't inherit ";
+            *fLog << err << obj->GetName() << " doesn't inherit ";
             *fLog << "from " << tcls->GetName() << " - cannot be used for MFillH...";
             *fLog << "aborting." << endl;
@@ -383,5 +399,5 @@
     if (!fH->SetupFill(pList))
     {
-        *fLog << err << dbginf << "Error: calling SetupFill for ";
+        *fLog << err << "ERROR - Calling SetupFill for ";
         *fLog << fH->GetDescriptor() << "... aborting." << endl;
         return kFALSE;
@@ -392,22 +408,21 @@
     //
     if (fParContainer)
-        return kTRUE;
-
-    //
-    // If a name is given try to find the input container in the
-    // list. If it could not be found we cannot proceed.
+        return DrawToDisplay();
+
+    //
+    // This case means, that the MH sets up its container to be filled
+    // by itself. Check there if it has something to be filled with!
     //
     if (fParContainerName.IsNull())
     {
-        fParContainer = NULL; 
-        return kTRUE;
+        fParContainer = NULL;
+        return DrawToDisplay();
     }
 
     fParContainer = (MParContainer*)pList->FindObject(fParContainerName);
-
     if (fParContainer)
-        return kTRUE;
-
-    *fLog << err << dbginf << "'" << fParContainerName << "' [MParContainer] not found... aborting." << endl;
+        return DrawToDisplay();
+
+    *fLog << err << fParContainerName << " [MParContainer] not found... aborting." << endl;
     return kFALSE;
 }
@@ -443,5 +458,5 @@
     if (!fH->Finalize())
     {
-        *fLog << err << dbginf << "Error: calling Finalize for ";
+        *fLog << err << "ERROR - Calling Finalize for ";
         *fLog << fH->GetDescriptor() << "... aborting." << endl;
         return kFALSE;
@@ -449,4 +464,11 @@
 
     fH->SetReadyToSave();
+
+    if (fDisplay)
+    {
+        fCanvas->cd();
+        fH->DrawClone("nonew");
+    }
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mhist/MFillH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 1965)
@@ -7,8 +7,9 @@
 
 class MH;
+class MMap;
 class MData;
 class MParList;
 
-class MMap;
+class TCanvas;
 
 class MFillH : public MTask
@@ -24,4 +25,6 @@
     MMap  *fMapIdx;   //! Map to map key-index-pair for an MHArray (MMap see MFillH.cc)
 
+    TCanvas *fCanvas;
+
     TString ExtractName(const char *name) const;
     TString ExtractClass(const char *name) const;
@@ -30,4 +33,6 @@
 
     void StreamPrimitive(ofstream &out) const;
+
+    Bool_t DrawToDisplay();
 
 public:
Index: trunk/MagicSoft/Mars/mhist/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1965)
@@ -585,4 +585,5 @@
     //
     TH1 *h1 = (TH1*)((TH1&)hist1).DrawCopy();
+    gPad->SetBorderMode(0);
     gPad->Update();
 
@@ -653,4 +654,5 @@
     //
     hist1.Draw();
+    gPad->SetBorderMode(0);
     gPad->Update();
 
@@ -710,2 +712,46 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// If the opt string contains 'nonew' or gPad is not given NULL is returned.
+// Other wise the present gPad is cleared and returned.
+//
+TVirtualPad *MH::GetNewPad(Option_t *opt)
+{
+    TString str(opt);
+
+    if (!str.Contains("nonew", TString::kIgnoreCase) || !gPad)
+        return NULL;
+
+    gPad->Clear();
+    return gPad;
+}
+
+// --------------------------------------------------------------------------
+//
+// The object is cloned and drawn to the present pad. The kCanDelete
+// bit is set for the clone.
+//
+TObject *MH::DrawClone(Option_t *opt="") const
+{
+    gROOT->SetSelectedPad(NULL);
+
+    TObject *o = MParContainer::DrawClone(opt);
+    o->SetBit(kCanDelete);
+    return o;
+}
+
+// --------------------------------------------------------------------------
+//
+// If the opt string contains 'nonew' or gPad is not given a new canvas
+// with size w/h is created. Otherwise the object is cloned and drawn
+// to the present pad. The kCanDelete bit is set for the clone.
+//
+TObject *MH::DrawClone(Option_t *opt, Int_t w, Int_t h) const
+{
+    TVirtualPad *p = GetNewPad(opt);
+    if (!p)
+        p = MakeDefCanvas(this, w, h);
+
+    return MH::DrawClone(opt);
+}
Index: trunk/MagicSoft/Mars/mhist/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MH.h	(revision 1965)
@@ -15,7 +15,17 @@
 class MBinning;
 class MParList;
-
+#include <iostream.h>
+#include <TClass.h>
 class MH : public MParContainer
 {
+private:
+    /*
+    void Draw(Option_t *opt="")
+    {
+        cout << "MH::Draw" << endl;
+        MParContainer::Draw(opt);
+        }
+        */
+
 public:
     MH(const char *name=NULL, const char *title=NULL);
@@ -59,6 +69,14 @@
     static void Draw(TH1 &hist1, TH1 &hist2, const TString title);
 
+    void Draw(Option_t *o="") { MParContainer::Draw(o); }
+    TObject *DrawClone(Option_t *opt="") const;
+    TObject *DrawClone(Option_t *opt, Int_t w, Int_t h) const;
+
+    static TVirtualPad *GetNewPad(Option_t *opt);
+
     static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger);
     static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0);
+
+
 
     ClassDef(MH, 1) //A histogram base class for Mars histograms
Index: trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1965)
@@ -600,25 +600,21 @@
 MParContainer *MH3::New() const
 {
-  cout << "1" <<endl;
     MH3 *h = NULL;
-  cout << "1a" <<endl;
-
-  if (fData[0] == NULL) 
-    {
-      h=new MH3(fDimension);
-    }
-  else
-    switch (fDimension)
-    {
-    case 1:
-        h=new MH3(fData[0]->GetRule());
-        break;
-    case 2:
-        h=new MH3(fData[0]->GetRule(), fData[1]->GetRule());
-        break;
-    case 3:
-        h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule());
-        break;
-    }
+
+    if (fData[0] == NULL)
+        h=new MH3(fDimension);
+    else
+        switch (fDimension)
+        {
+        case 1:
+            h=new MH3(fData[0]->GetRule());
+            break;
+        case 2:
+            h=new MH3(fData[0]->GetRule(), fData[1]->GetRule());
+            break;
+        case 3:
+            h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule());
+            break;
+        }
     switch (fDimension)
     {
Index: trunk/MagicSoft/Mars/mhist/MHCerPhotEvt.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCerPhotEvt.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MHCerPhotEvt.cc	(revision 1965)
@@ -30,4 +30,6 @@
 #include "MHCerPhotEvt.h"
 
+#include <TCanvas.h>
+
 #include "MLog.h"
 #include "MLogManip.h"
@@ -35,4 +37,8 @@
 #include "MParList.h"
 #include "MCerPhotEvt.h"
+#include "MCamDisplay.h"
+
+#include "MGeomCam.h"
+#include "MGeomPix.h"
 
 ClassImp(MHCerPhotEvt);
@@ -40,18 +46,39 @@
 // --------------------------------------------------------------------------
 //
-// Setup four histograms for Width, Length
-//
-MHCerPhotEvt::MHCerPhotEvt(const char *name, const char *title)
-    : fEvt(NULL)
-{
-    //
-    //   set the name and title of this object
-    //
-    fName  = name  ? name  : "MHCerPhotEvt";
-    fTitle = title ? title : "Sum up camera events";
-
+// Reset all pixels to 0 and reset fEntries to 0.
+//
+void MHCerPhotEvt::Clear()
+{
+    fSum.Reset();
     fSum.InitSize(577);
     for (int i=0; i<577; i++)
+    {
         fSum.AddPixel(i, 0, 0);
+        fSum[i].SetPixelUnused();
+    }
+
+    fEntries = 0;
+}
+
+// --------------------------------------------------------------------------
+//
+// Setup four histograms for Width, Length
+//
+MHCerPhotEvt::MHCerPhotEvt(const char *name, const char *title)
+    : fEvt(NULL), fCam(NULL), fDispl(NULL)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHCerPhotEvt";
+    fTitle = title ? title : "Average of MCerPhotEvts";
+
+    Clear();
+}
+
+MHCerPhotEvt::~MHCerPhotEvt()
+{
+    if (fDispl)
+        delete fDispl;
 }
 
@@ -72,4 +99,10 @@
         *fLog << warn << GetDescriptor() << ": No MCerPhotEvt available..." << endl;
 
+    fCam = (MGeomCam*)plist->FindObject("MGeomCam");
+    if (!fCam)
+        *fLog << warn << GetDescriptor() << ": No MGeomCam found." << endl;
+
+    Clear();
+
     return kTRUE;
 }
@@ -95,7 +128,74 @@
         const MCerPhotPix &pix = (*evt)[i];
 
-        fSum[pix.GetPixId()].AddNumPhotons(pix.GetNumPhotons());
-    }
+        const Int_t id = pix.GetPixId();
+
+        const Double_t ratio = fCam ? fCam->GetPixRatio(id) : 1;
+
+        const Double_t val = pix.GetNumPhotons()/ratio;
+
+        fSum[id].SetPixelUsed();
+        fSum[id].AddNumPhotons(val);
+    }
+
+    fEntries++;
+
     return kTRUE;
 }
 
+Bool_t MHCerPhotEvt::Finalize()
+{
+    fSum.Scale(fEntries);
+    return kTRUE;
+}
+
+TObject *MHCerPhotEvt::DrawClone(Option_t *opt) const
+{
+    return MH::DrawClone(opt, 750, 600);
+}
+
+void MHCerPhotEvt::Draw(Option_t *)
+{
+    if (!fCam)
+    {
+        *fLog << warn << "WARNING - Cannot draw " << GetDescriptor() << ": No Camera Geometry available." << endl;
+        return;
+    }
+
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 750, 600);
+    pad->SetBorderMode(0);
+
+    //
+    // All this is necessary to get the background in the correct color
+    //
+    pad->Divide(1,1);
+    pad->cd(1);
+
+    gPad->SetBorderMode(0);
+    gPad->SetFillColor(gPad->GetFillColor());
+
+    //
+    // set the color palette for the TBox elements
+    //
+    AppendPad("");
+
+    //
+    // Necessary to visualize the background color (FIXME?)
+    //
+    gPad->Modified();
+    gPad->Update();
+}
+
+void MHCerPhotEvt::Paint(Option_t *option="")
+{
+    if (!fCam)
+    {
+        *fLog << warn << "WARNING - Cannot paint " << GetDescriptor() << ": No Camera Geometry available." << endl;
+        return;
+    }
+
+    if (!fDispl)
+        fDispl = new MCamDisplay(fCam);
+
+    fDispl->FillPhotNum(fSum);
+    fDispl->Paint();
+}
Index: trunk/MagicSoft/Mars/mhist/MHCerPhotEvt.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHCerPhotEvt.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MHCerPhotEvt.h	(revision 1965)
@@ -11,4 +11,6 @@
 
 class TH1D;
+class MGeamCam;
+class MCamDisplay;
 
 class MHCerPhotEvt : public MH
@@ -16,11 +18,20 @@
 private:
     MCerPhotEvt  fSum;
-    MCerPhotEvt *fEvt; //!
+    Int_t        fEntries;
+    MCerPhotEvt *fEvt;   //!
+    MGeomCam    *fCam; 
+    MCamDisplay *fDispl; //!
 
 public:
     MHCerPhotEvt(const char *name=NULL, const char *title=NULL);
+    ~MHCerPhotEvt();
+
+    //    TObject *Clone(const char *newname="") const;
+
+    void Clear();
 
     Bool_t SetupFill(const MParList *pList);
     Bool_t Fill(const MParContainer *par);
+    Bool_t Finalize();
 
     TH1 *GetHistByName(const TString name) { return NULL; }
@@ -28,5 +39,9 @@
     const MCerPhotEvt &GetSum() const { return fSum; }
 
-    ClassDef(MHCerPhotEvt, 1) // Container which holds histograms for the source independent image parameters
+    TObject *DrawClone(Option_t *opt) const;
+    void Draw(Option_t *);
+    void Paint(Option_t *option="");
+
+    ClassDef(MHCerPhotEvt, 1) // Histogram to sum camera events
 };
 
Index: trunk/MagicSoft/Mars/mhist/MHStarMap.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 1965)
@@ -68,6 +68,4 @@
     fTitle = title ? title : "Container for a Star Map" ;
 
-    *fLog << warn << "WARNING - Using MHStarMap doesn't take care of the Source Position!" << endl;
-
     //
     //   loop over all Pixels and create two histograms
@@ -137,4 +135,6 @@
         return kTRUE;
     }
+
+    *fLog << warn << "WARNING - Using MHStarMap doesn't take care of the Source Position!" << endl;
 
     return kTRUE;
@@ -293,5 +293,4 @@
 }
 
-
 // --------------------------------------------------------------------------
 //
@@ -304,19 +303,5 @@
 TObject *MHStarMap::DrawClone(Option_t *opt) const
 {
-    TCanvas *c=MakeDefCanvas(fStarMap, 500, 500);
-
-    //
-    // This is necessary to get the expected bahviour of DrawClone
-    //
-    gROOT->SetSelectedPad(NULL);
-
-    PrepareDrawing();
-
-    fStarMap->DrawCopy("colz");
-
-    c->Modified();
-    c->Update();
-
-    return c;
+    return MH::DrawClone(opt, 500, 500);
 }
 
@@ -329,12 +314,36 @@
 void MHStarMap::Draw(Option_t *)
 {
-    if (!gPad)
-        MakeDefCanvas(fStarMap, 500, 500);
-
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 500, 500);
+    pad->SetBorderMode(0);
+
+    pad->Divide(1,1);
+
+    pad->cd(1);
+    gPad->SetBorderMode(0);
+
+    AppendPad("");
+}
+
+void MHStarMap::Paint(Option_t *opt="")
+{
+    //
+    // Maintain aspect ratio
+    //
+    const float w = gPad->GetWw();
+    const float h = gPad->GetWh();
+
+    if (h<w)
+        gPad->SetPad((1.-h/w)/2, 0, (h/w+1)/2, 1);
+    else
+        gPad->SetPad(0, (1.-w/h)/2, 1, (w/h+1)/2);
+
+    //
+    // Maintain colors
+    //
     PrepareDrawing();
 
-    fStarMap->Draw("colz");
-
-    gPad->Modified();
-    gPad->Update();
-}
+    //
+    // Paint Histogram
+    //
+    fStarMap->Paint("colz");
+}
Index: trunk/MagicSoft/Mars/mhist/MHStarMap.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHStarMap.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/MHStarMap.h	(revision 1965)
@@ -15,5 +15,5 @@
 {
 private:
-    TH2F *fStarMap;
+    TH2F *fStarMap; //->
 
     Float_t fMm2Deg;
@@ -22,4 +22,6 @@
 
     void PrepareDrawing() const;
+
+    void Paint(Option_t *opt="");
 
 public:
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 1964)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 1965)
@@ -23,5 +23,6 @@
 #
 INCLUDES = -I. -I../mbase -I../mraw -I../manalysis -I../mmc \
-	   -I../mgui -I../mgeom -I../mdata -I../mfilter -I../mimage
+	   -I../mgui -I../mgeom -I../mdata -I../mfilter -I../mimage \
+           -I../mmain
 
 #------------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mimage/MHHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHHillas.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MHHillas.cc	(revision 1965)
@@ -31,5 +31,4 @@
 //
 /////////////////////////////////////////////////////////////////////////////
-
 #include "MHHillas.h"
 
@@ -110,4 +109,5 @@
     fSize->GetXaxis()->SetTitleOffset(1.2);
     fSize->GetXaxis()->SetLabelOffset(-0.015);
+    fSize->SetFillStyle(4000);
 
     bins.Apply(*fSize);
@@ -280,5 +280,4 @@
 void MHHillas::SetColors() const
 {
-    // FIXME: This must be redone each time the canvas is repainted....
     gStyle->SetPalette(51, NULL);
     Int_t c[50];
@@ -298,33 +297,5 @@
 TObject *MHHillas::DrawClone(Option_t *opt) const
 {
-    TCanvas *c = MakeDefCanvas(this, 720, 810);
-    c->Divide(2,3);
-
-    gROOT->SetSelectedPad(NULL);
-
-    c->cd(1);
-    DrawCopy(*fWidth, *fLength, "Width / Length");
-
-    c->cd(2);
-    gPad->SetLogx();
-    fSize->DrawCopy();
-
-    c->cd(3);
-    DrawCopy(*fCorePix, *fUsedPix, "Number of core/used Pixels");
-
-    c->cd(4);
-    fDelta->DrawCopy();
-
-    c->cd(5);
-    fDistC->DrawCopy();
-
-    c->cd(6);
-    SetColors();
-    fCenter->DrawCopy("colz");
-
-    c->Modified();
-    c->Update();
-
-    return c;
+    return MH::DrawClone(opt, 720, 810);
 }
 
@@ -337,31 +308,38 @@
 void MHHillas::Draw(Option_t *)
 {
-    if (!gPad)
-        MakeDefCanvas(this, 720, 810);
-
-    gPad->Divide(2,3);
-
-    gPad->cd(1);
-    MH::Draw(*fWidth, *fLength, "Width / Length");
-
-    gPad->cd(2);
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 720, 810);
+    pad->SetBorderMode(0);
+
+    AppendPad("");
+
+    pad->Divide(2,3);
+
+    pad->cd(1);
+    MH::Draw(*fWidth, *fLength, "Width'n'Length");
+
+    pad->cd(2);
+    gPad->SetBorderMode(0);
     gPad->SetLogx();
     fSize->Draw();
 
-    gPad->cd(3);
+    pad->cd(3);
+    gPad->SetBorderMode(0);
     MH::Draw(*fCorePix, *fUsedPix, "Number of core/used Pixels");
 
-    gPad->cd(4);
+    pad->cd(4);
+    gPad->SetBorderMode(0);
     fDelta->Draw();
 
-    gPad->cd(5);
+    pad->cd(5);
+    gPad->SetBorderMode(0);
     fDistC->Draw();
 
-    gPad->cd(6);
+    pad->cd(6);
+    gPad->SetBorderMode(0);
     SetColors();
     fCenter->Draw("colz");
 
-    gPad->Modified();
-    gPad->Update();
+    pad->Modified();
+    pad->Update();
 }
 
@@ -387,2 +365,8 @@
     return NULL;
 }
+
+void MHHillas::Paint(Option_t *opt="")
+{
+    SetColors();
+    MH::Paint();
+}
Index: trunk/MagicSoft/Mars/mimage/MHHillas.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHHillas.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MHHillas.h	(revision 1965)
@@ -14,15 +14,15 @@
 private:
 
-    TH1F *fLength; //->
-    TH1F *fWidth;  //->
+    TH1F *fLength;  //-> Length
+    TH1F *fWidth;   //-> Width
 
-    TH1F *fDistC;  //->
-    TH1F *fDelta;  //->
+    TH1F *fDistC;   //-> Distance to Camera Center
+    TH1F *fDelta;   //-> Angle between Length axis and x-axis
 
-    TH1F *fSize;   //->
-    TH2F *fCenter; //->
+    TH1F *fSize;    //-> Sum of used pixels
+    TH2F *fCenter;  //-> Center
 
-    TH1F *fUsedPix; //->
-    TH1F *fCorePix; //->
+    TH1F *fUsedPix; //-> Number of used pixels
+    TH1F *fCorePix; //-> Number of core pixels
 
     void SetColors() const;
@@ -30,4 +30,6 @@
     Float_t fMm2Deg;
     Bool_t  fUseMmScale;
+
+    void Paint(Option_t *opt="");
 
 public:
@@ -55,4 +57,6 @@
     TObject *DrawClone(Option_t *opt=NULL) const;
 
+    //Int_t DistancetoPrimitive(Int_t px, Int_t py) { return 0; }
+
     ClassDef(MHHillas, 1) // Container which holds histograms for the source independent image parameters
 };
Index: trunk/MagicSoft/Mars/mimage/MHHillasExt.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHHillasExt.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MHHillasExt.cc	(revision 1965)
@@ -30,5 +30,4 @@
 //
 /////////////////////////////////////////////////////////////////////////////
-
 #include "MHHillasExt.h"
 
@@ -57,7 +56,6 @@
 // Setup four histograms for Width, Length
 //
-MHHillasExt::MHHillasExt(const char *name, const char *title,
-                         const char *hil)
-    : fMm2Deg(1), fUseMmScale(kTRUE)
+MHHillasExt::MHHillasExt(const char *name, const char *title)
+    : fMm2Deg(1), fUseMmScale(kTRUE), fHilName("MHillas")
 {
     //
@@ -66,7 +64,4 @@
     fName  = name  ? name  : "MHHillasExt";
     fTitle = title ? title : "Container for extended Hillas histograms";
-
-    fHilName = hil;
-    //*fLog << "MHHillasExt : fHilName = " << fHilName << endl;
 
     //
@@ -108,4 +103,9 @@
     fHM3Trans.SetYTitle("Counts");
 
+    fHConc.SetFillStyle(4000);
+    fHConc1.SetFillStyle(4000);
+    fHAsym.SetFillStyle(4000);
+    fHM3Long.SetFillStyle(4000);
+    fHM3Trans.SetFillStyle(4000);
 
     MBinning bins;
@@ -121,12 +121,4 @@
     bins.SetEdges(101, -593, 593);
     bins.Apply(fHAsym);
-}
-
-// --------------------------------------------------------------------------
-//
-// Delete the four histograms
-//
-MHHillasExt::~MHHillasExt()
-{
 }
 
@@ -143,17 +135,10 @@
 Bool_t MHHillasExt::SetupFill(const MParList *plist)
 {
-    TObject *obj = plist->FindObject(fHilName, "MHillas");
-    if (!obj)
-    {
-      *fLog << err << dbginf << "Sorry '" << fHilName 
-            << "' not found in parameter list... aborting." << endl;
+    fHillasExt = (MHillasExt*)plist->FindObject(fHilName, "MHillasExt");
+    if (!fHillasExt)
+    {
+        *fLog << err << fHilName << "[MHillasExt] not found in parameter list... aborting." << endl;
         return kFALSE;
     }
-    if (!obj->InheritsFrom(MHillasExt::Class()))
-    {
-        *fLog << err << dbginf << "Sorry 'MHillas' doesn't inherit from MHillasExt... aborting." << endl;
-        return kFALSE;
-    }
-    fHillasExt = (MHillasExt*)obj;
 
     const MGeomCam *geom = (MGeomCam*)plist->FindObject("MGeomCam");
@@ -184,5 +169,5 @@
     const MHillasSrc *src = (MHillasSrc*)par;
 
-    const Double_t scale = TMath::Sign(fUseMmScale?1:fMm2Deg, src ? src->GetCosDeltaAlpha() : 1);
+    const Double_t scale = TMath::Sign(fUseMmScale?1:fMm2Deg, (src ? src->GetCosDeltaAlpha() : 1));
 
     fHConc.Fill(fHillasExt->GetConc());
@@ -266,25 +251,5 @@
 TObject *MHHillasExt::DrawClone(Option_t *opt) const
 {
-    TCanvas &c = *MakeDefCanvas(this, 720, 540);
-    c.Divide(2, 2);
-
-    gROOT->SetSelectedPad(NULL);
-
-    c.cd(1);
-    DrawCopy(fHConc1, fHConc, "Concentrations");
-
-    c.cd(2);
-    ((TH1&)fHAsym).DrawCopy();
-
-    c.cd(3);
-    ((TH1&)fHM3Long).DrawCopy();
-
-    c.cd(4);
-    ((TH1&)fHM3Trans).DrawCopy();
-
-    c.Modified();
-    c.Update();
-
-    return &c;
+    return MH::DrawClone(opt, 720, 540);
 }
 
@@ -297,23 +262,29 @@
 void MHHillasExt::Draw(Option_t *)
 {
-    if (!gPad)
-        MakeDefCanvas(this, 720, 540);
-
-    gPad->Divide(2, 2);
-
-    gPad->cd(1);
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 720, 540);
+    pad->SetBorderMode(0);
+
+    AppendPad("");
+
+    pad->Divide(2, 2);
+
+    pad->cd(1);
+    gPad->SetBorderMode(0);
     MH::Draw(fHConc1, fHConc, "Concentrations");
 
-    gPad->cd(2);
+    pad->cd(2);
+    gPad->SetBorderMode(0);
     fHAsym.Draw();
 
-    gPad->cd(3);
+    pad->cd(3);
+    gPad->SetBorderMode(0);
     fHM3Long.Draw();
 
-    gPad->cd(4);
+    pad->cd(4);
+    gPad->SetBorderMode(0);
     fHM3Trans.Draw();
 
-    gPad->Modified();
-    gPad->Update();
+    pad->Modified();
+    pad->Update();
 }
 
Index: trunk/MagicSoft/Mars/mimage/MHHillasExt.h
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHHillasExt.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MHHillasExt.h	(revision 1965)
@@ -28,9 +28,7 @@
 
 public:
-    //MHHillasExt(const char *name=NULL, const char *title=NULL);
-    MHHillasExt(const char *name=NULL, const char *title=NULL,
-                const char *hil="MHillas");
+    MHHillasExt(const char *name=NULL, const char *title=NULL);
 
-    ~MHHillasExt();
+    void SetHillasName(const char *name) { fHilName = name; }
 
     void SetMmScale(Bool_t mmscale=kTRUE);
Index: trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MHHillasSrc.cc	(revision 1965)
@@ -211,31 +211,5 @@
 TObject *MHHillasSrc::DrawClone(Option_t *opt) const
 {
-    TCanvas *c = MakeDefCanvas(this, 700, 500);
-    c->Divide(2, 2);
-
-    // FIXME: Display Source position
-
-    gROOT->SetSelectedPad(NULL);
-
-    //
-    // This is necessary to get the expected bahviour of DrawClone
-    //
-    c->cd(1);
-    fAlpha->DrawCopy();
-
-    c->cd(2);
-    fDist->DrawCopy();
-
-    c->cd(3);
-    fHeadTail->DrawCopy();
-
-    c->cd(4);
-    gPad->SetLogy();
-    fCosDA->DrawCopy();
-
-    c->Modified();
-    c->Update();
-
-    return c;
+    return MH::DrawClone(opt, 700, 500);
 }
 
@@ -248,26 +222,32 @@
 void MHHillasSrc::Draw(Option_t *)
 {
-    if (!gPad)
-        MakeDefCanvas(this, 700, 500);
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 700, 500);
+    pad->SetBorderMode(0);
+
+    AppendPad("");
 
     // FIXME: Display Source position
 
-    gPad->Divide(2, 2);
-
-    gPad->cd(1);
+    pad->Divide(2, 2);
+
+    pad->cd(1);
+    gPad->SetBorderMode(0);
     fAlpha->Draw();
 
-    gPad->cd(2);
+    pad->cd(2);
+    gPad->SetBorderMode(0);
     fDist->Draw();
 
-    gPad->cd(1);
+    pad->cd(3);
+    gPad->SetBorderMode(0);
     fHeadTail->Draw();
 
-    gPad->cd(2);
+    pad->cd(4);
+    gPad->SetBorderMode(0);
     gPad->SetLogy();
     fCosDA->Draw();
 
-    gPad->Modified();
-    gPad->Update();
+    pad->Modified();
+    pad->Update();
 }
 
Index: trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MHNewImagePar.cc	(revision 1965)
@@ -188,19 +188,5 @@
 TObject *MHNewImagePar::DrawClone(Option_t *opt) const
 {
-    TCanvas *c = MakeDefCanvas(this, 300, 600);
-    c->Divide(1, 2);
-
-    gROOT->SetSelectedPad(NULL);
-
-    c->cd(1);
-    fLeakage1->DrawCopy();
-
-    c->cd(2);
-    fLeakage2->DrawCopy();
-
-    c->Modified();
-    c->Update();
-
-    return c;
+    return MH::DrawClone(opt, 300, 600);
 }
 
@@ -213,17 +199,21 @@
 void MHNewImagePar::Draw(Option_t *)
 {
-    if (!gPad)
-        MakeDefCanvas(this, 300, 600);
-
-    gPad->Divide(2, 2);
-
-    gPad->cd(1);
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(this, 300, 600);
+    pad->SetBorderMode(0);
+
+    AppendPad("");
+
+    pad->Divide(1, 2);
+
+    pad->cd(1);
+    pad->SetBorderMode(0);
     fLeakage1->Draw();
 
-    gPad->cd(2);
+    pad->cd(2);
+    pad->SetBorderMode(0);
     fLeakage2->Draw();
 
-    gPad->Modified();
-    gPad->Update();
+    pad->Modified();
+    pad->Update();
 }
 
Index: trunk/MagicSoft/Mars/mimage/MHillasCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MHillasCalc.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MHillasCalc.cc	(revision 1965)
@@ -57,5 +57,5 @@
 {
     fName  = name  ? name  : "MHillasCalc";
-    fTitle = title ? title : "Task to calculate Hillas parameters";
+    fTitle = title ? title : "Calculate Hillas parameters";
 
     fHilName = hil;
Index: trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mimage/MImgCleanStd.cc	(revision 1965)
@@ -69,5 +69,5 @@
 
 static const TString gsDefName  = "MImgCleanStd";
-static const TString gsDefTitle = "Task to perform a standard image cleaning";
+static const TString gsDefTitle = "Perform standard image cleaning";
 
 // --------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/mmain/MProgressBar.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MProgressBar.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mmain/MProgressBar.cc	(revision 1965)
@@ -16,7 +16,7 @@
 !
 !
-!   Author(s): Thomas Bretz  9/2002 <mailto:tbretz@astro-uni-wuerzburg.de>
+!   Author(s): Thomas Bretz, 9/2002 <mailto:tbretz@astro-uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2002
+!   Copyright: MAGIC Software Development, 2000-2003
 !
 !
@@ -25,5 +25,7 @@
 /////////////////////////////////////////////////////////////////////////////
 //
-// MHillasSrc
+// MProgressBar
+//
+// Simple window with progress bar. Can be used in an eventloop.
 //
 /////////////////////////////////////////////////////////////////////////////
Index: trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 1964)
+++ trunk/MagicSoft/Mars/mmain/MStatusDisplay.cc	(revision 1965)
@@ -27,5 +27,30 @@
 // MStatusDisplay
 //
-//  upon an idea of Robert Wagner
+// This status display can be used (and is used) to display results in
+// a tabbed window. The window can be written to and read from a root file
+// (see Read and Write) or printed as a postscript file (see SaveAsPS).
+//
+// It has also to half status lines which can be used to display the status
+// or something going on. Together with the status lines it has a progress
+// bar which can display the progress of a job or loop.
+// Access the progress bar by GetProgressBar()
+//
+// To add a new tab and get a pointer to the newly created TCanvas
+// use AddTab.
+//
+// If you have a MStatusDisplay and you are not sure whether it was
+// destroyed by the user meanwhile use:
+//   gROOT->GetListOfSpecials()->FindObject(pointer);
+// Each MStatusDisplay is added to list list by its constructor and
+// removed from the list by the destructor.
+//
+// You can redirect an output to a MLog-logstream by calling SetLogStream().
+// To disable redirction call SetLogStream(NULL)
+//
+// Because updates to the tabs are only done/displayed if a tab is active
+// using the gui doesn't make things slower (<1%) if the first (legend
+// tab) is displayed. This gives you the possibility to look into
+// the current progress of a loop without loosing more time than the
+// single update of the tab.
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -34,21 +59,243 @@
 #include <iostream.h>
 
-#include <TCanvas.h>        // TCanvas
-#include <TSystem.h>        // gSystem
-
-#include <TGTab.h>          // TGTab
-#include <TGLabel.h>        // TGLabel
-#include <TGButton.h>       // TGPictureButton
-#include <TGProgressBar.h>  // TGHProgressBar
+#include <TLine.h>                // TLine
+#include <TText.h>                // TText
+#include <TFile.h>                // gFile
+#include <TFrame.h>               // TFrame
+#include <TStyle.h>               // gStyle
+#include <TCanvas.h>              // TCanvas
+#include <TSystem.h>              // gSystem
+#include <TDatime.h>              // TDatime
+#include <TRandom.h>              // TRandom
+#include <TObjArray.h>            // TObjArray
+#include <TPostScript.h>          // TPostScript
+
+#include <TGTab.h>                // TGTab
+#include <TGLabel.h>              // TGLabel
+#include <TG3DLine.h>             // TGHorizontal3DLine
+#include <TGButton.h>             // TGPictureButton
+#include <TGListBox.h>            // TGListBox
+#include <TGProgressBar.h>        // TGHProgressBar
 
 #include <TRootEmbeddedCanvas.h>  // TRootEmbeddedCanvas
 
-#include "MGList.h"
+#include "MLog.h"                 // MLog
+#include "MLogManip.h"            // inf, warn, err
+
+#include "MGList.h"               // MGList
+#include "MGMenu.h"               // MGMenu, TGMenu
+#include "MParContainer.h"        // MParContainer::GetDescriptor
 
 ClassImp(MStatusDisplay);
 
+// --------------------------------------------------------------------------
+//
+// Add menu bar to the GUI
+//
+void MStatusDisplay::AddMenuBar()
+{
+    //
+    // File Menu
+    //
+    MGPopupMenu *filemenu = new MGPopupMenu(gClient->GetRoot());
+    // filemenu->AddEntry("S&ave [F2]", kFileSave);
+    // filemenu->AddEntry("Save &As... [Shift-F2]", kFileSaveAs);
+    filemenu->AddEntry("Save As status.&ps", kFileSaveAsPS);
+    // filemenu->AddEntry("Save As status.&gif", kFileSaveAsGIF);
+    // filemenu->AddEntry("Save As status.&C", kFileSaveAsC);
+    filemenu->AddEntry("Save As status.&root", kFileSaveAsRoot);
+    filemenu->AddSeparator();
+    filemenu->AddEntry("Print with &lpr", kFilePrint);
+    filemenu->AddEntry("Set printer &name", kFilePrinterName);
+    filemenu->AddSeparator();
+    filemenu->AddEntry("E&xit", kFileExit);
+    filemenu->Associate(this);
+
+    //
+    // Tab Menu
+    //
+    MGPopupMenu *tabmenu = new MGPopupMenu(gClient->GetRoot());
+    // tabmenu->AddEntry("S&ave [F2]", kFileSave);
+    // tabmenu->AddEntry("Save &As... [Shift-F2]", kFileSaveAs);
+    tabmenu->AddEntry("Save As tab-i.&ps", kTabSaveAsPS);
+    // tabmenu->AddEntry("Save As tab-i.&gif", kTabSaveAsGIF);
+    // tabmenu->AddEntry("Save As tab-i.&C", kTabSaveAsC);
+    tabmenu->AddEntry("Save As tab-i.&root", kTabSaveAsRoot);
+    tabmenu->AddSeparator();
+    tabmenu->AddEntry("Print with &lpr", kFilePrint);
+    tabmenu->AddSeparator();
+    tabmenu->AddEntry("Next [&+]",     kTabNext);
+    tabmenu->AddEntry("Previous [&-]", kTabPrevious);
+    tabmenu->Associate(this);
+
+    //
+    // Loop Menu
+    //
+    MGPopupMenu *loopmenu = new MGPopupMenu(gClient->GetRoot());
+    loopmenu->AddEntry("&Stop", kLoopStop);
+    loopmenu->Associate(this);
+
+    //
+    // Menu Bar
+    //
+    MGMenuBar *menubar = new MGMenuBar(this, 1, 1, kHorizontalFrame);
+    menubar->AddPopup("&File", filemenu, NULL);
+    menubar->AddPopup("&Tab",  tabmenu,  NULL);
+    menubar->AddPopup("&Loop", loopmenu, NULL);
+    menubar->BindKeys(this);
+    AddFrame(menubar);
+
+    //
+    // Line below menu bar
+    //
+    TGLayoutHints *laylinesep  = new TGLayoutHints(kLHintsTop|kLHintsExpandX);
+    fList->Add(laylinesep);
+
+    TGHorizontal3DLine *linesep = new TGHorizontal3DLine(this);
+    AddFrame(linesep, laylinesep);
+
+    //
+    // Add everything to autodel list
+    //
+    fList->Add(filemenu);
+    fList->Add(loopmenu);
+    fList->Add(menubar);
+    fList->Add(tabmenu);
+    fList->Add(linesep);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add the title tab
+//
+void MStatusDisplay::AddMarsTab()
+{
+    // Create Tab1
+    TGCompositeFrame *f = fTab->AddTab("-=MARS=-");
+
+    // Add MARS version
+    TString txt = "Official Release: V";
+    TGLabel *l = new TGLabel(f, txt+MARSVER);
+    fList->Add(l);
+
+    TGLayoutHints *layb = new TGLayoutHints(kLHintsCenterX|kLHintsTop, 10, 10, 10, 10);
+    fList->Add(layb);
+    f->AddFrame(l, layb);
+
+    // Add root version
+    txt = "Using ROOT v";
+    l = new TGLabel(f, txt+ROOTVER);
+    fList->Add(l);
+
+    TGLayoutHints *lay = new TGLayoutHints(kLHintsCenterX|kLHintsTop);
+    fList->Add(lay);
+    f->AddFrame(l, lay);
+
+    // Add Mars logo picture
+    const TGPicture *pic2 = fList->GetPicture("marslogo.xpm");
+    if (pic2)
+    {
+        TGPictureButton *mars  = new TGPictureButton(f, pic2, kPicMars);
+        fList->Add(mars);
+        mars->Associate(this);
+
+        TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 10, 10, 10, 10);
+        fList->Add(lay2);
+        f->AddFrame(mars, lay2);
+    }
+
+    // Add date and time
+    TDatime d;
+    l = new TGLabel(f, d.AsString());
+    fList->Add(l);
+    f->AddFrame(l, lay);
+
+    // Add copyright notice
+    l = new TGLabel(f, "(c) MAGIC Software Development, 2000-2003");
+    fList->Add(l);
+    f->AddFrame(l, layb);
+}
+
+// --------------------------------------------------------------------------
+//
+// Adds the logbook tab to the GUI if it was not added previously.
+//
+// The logbook is updated four times a second only if the tab is visible.
+//
+// You can redirect an output to a MLog-logstream by calling SetLogStream().
+// To disable redirction call SetLogStream(NULL)
+//
+void MStatusDisplay::SetLogStream(MLog *log)
+{
+    if (log && fLogBox==NULL)
+    {
+        fLogIdx = fTab->GetNumberOfTabs();
+
+        // Create Tab1
+        TGCompositeFrame *f = fTab->AddTab("-Logbook-");
+
+        // Create TGListBox for logging contents
+        fLogBox = new TGListBox(f, 1, 1);
+        fLogBox->ChangeBackground(TGFrame::GetBlackPixel());
+
+        // Add List box to the tab
+        TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY);//, 5, 6, 5);
+        f->AddFrame(fLogBox, lay);
+
+        // layout and map tab
+        Layout();
+        MapSubwindows();
+
+        // make it visible
+        gClient->ProcessEventsFor(fTab);
+    }
+
+    if (log)
+    {
+        fLog = log;
+
+        log->SetOutputGui(fLogBox, kTRUE);
+        log->DisableOutputDevice(MLog::eStdout);
+        log->EnableOutputDevice(MLog::eGui);
+
+        fLogTimer.Start();
+    }
+    else
+    {
+        fLogTimer.Stop();
+
+        fLog->DisableOutputDevice(MLog::eGui);
+        fLog->EnableOutputDevice(MLog::eStdout);
+        fLog->SetOutputGui(NULL);
+
+        fLog = &gLog;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Add the Tabs and the predifined Tabs to the GUI
+//
+void MStatusDisplay::AddTabs()
+{
+    fTab = new TGTab(this, 300, 300);
+
+    AddMarsTab();
+
+    // Add fTab to Frame
+    TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 5, 6, 5);
+    AddFrame(fTab, laytabs);
+
+    fList->Add(fTab);
+    fList->Add(laytabs);
+}
+
+// --------------------------------------------------------------------------
+//
+// Add the progress bar to the GUI
+//
 void MStatusDisplay::AddProgressBar()
 {
-    TGLayoutHints *laybar=new TGLayoutHints(kLHintsExpandX, 10,10,10,10);
+    TGLayoutHints *laybar=new TGLayoutHints(kLHintsExpandX, 5, 6, 5, 5);
     fList->Add(laybar);
 
@@ -59,97 +306,73 @@
 }
 
-enum {
-    kPicMagic,
-    kPicMars
-};
-
-void MStatusDisplay::AddTabs()
-{
-    fTab = new TGTab(this, 300, 300);
-
-    //
-    // Create Tab1
-    //
-    TGCompositeFrame *f = fTab->AddTab("-=MARS=-");
-
-    /*
-    TGHorizontalFrame *hf = new TGHorizontalFrame(f, 1, 1);
-
-    TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 10., 10., 10., 10.);
-    fList->Add(lay);
-    f->AddFrame(hf, lay);
-
-    const TGPicture *pic1 = fList->GetPicture("magiclogo.xpm");
-    if (pic1)
-    {
-        TGPictureButton *magic = new TGPictureButton(hf, pic1, kPicMagic);
-        fList->Add(magic);
-        magic->Associate(this);
-
-        TGLayoutHints *lay1 = new TGLayoutHints(kLHintsLeft|kLHintsTop,  10., 10., 20., 10.);
-        fList->Add(lay1);
-        hf->AddFrame(magic, lay1);
-    }
-    */
-    const TGPicture *pic2 = fList->GetPicture("marslogo.xpm");
-    if (pic2)
-    {
-        TGPictureButton *mars  = new TGPictureButton(f, pic2, kPicMars);
-        fList->Add(mars);
-        mars->Associate(this);
-
-        TGLayoutHints *lay2 = new TGLayoutHints(kLHintsCenterX|kLHintsCenterY, 10., 10., 10., 10.);
-        fList->Add(lay2);
-        f->AddFrame(mars, lay2);
-    }
-
-    //
-    // Crete second gui elemet for tab1 (TGVertical Frame)
-    //
-    TGLayoutHints *laytabs = new TGLayoutHints(kLHintsNormal|kLHintsExpandX|kLHintsExpandY, 10, 10, 10, 10);
-    AddFrame(fTab, laytabs);
-
-    fList->Add(fTab);
-    fList->Add(laytabs);
-}
-
-void MStatusDisplay::AddStatusLine1()
-{
-    TGCompositeFrame *f = new TGCompositeFrame(this, 1, 1, kSunkenFrame);
+
+// --------------------------------------------------------------------------
+//
+// Adds the status lines to the GUI
+//
+void MStatusDisplay::AddStatusLines()
+{
+    TGHorizontalFrame *hf = new TGHorizontalFrame(this, 1, 1);
+
+    TGCompositeFrame *f = new TGCompositeFrame(hf, 1, 1, kSunkenFrame);
 
     fLine1 = new TGLabel(f, "");
 
-    TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 5, 2, 2);
+    TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 0, 5);
     f->AddFrame(fLine1, lay);
-    AddFrame(f, lay);
+    hf->AddFrame(f, lay);
 
     fList->Add(f);
     fList->Add(fLine1);
     fList->Add(lay);
-}
-
-void MStatusDisplay::AddStatusLine2()
-{
-    TGCompositeFrame *f = new TGCompositeFrame(this, 1, 1, kSunkenFrame);
+
+    f = new TGCompositeFrame(hf, 1, 1, kSunkenFrame);
 
     fLine2 = new TGLabel(f, "");
-
-    TGLayoutHints *lay = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 5, 2, 2);
     f->AddFrame(fLine2, lay);
-    AddFrame(f, lay);
-
+    hf->AddFrame(f, lay);
+
+    TGLayoutHints *layf = new TGLayoutHints(kLHintsNormal|kLHintsExpandX, 5, 0, 0, 3);
+    AddFrame(hf, layf);
+
+    fList->Add(layf);
     fList->Add(f);
     fList->Add(fLine2);
-    fList->Add(lay);
-}
-
+    fList->Add(hf);
+}
+
+// --------------------------------------------------------------------------
+//
+// Change the text in the status line 1
+//
 void MStatusDisplay::SetStatusLine1(const char *txt)
 {
     fLine1->SetText(txt);
-}
-
+    gClient->ProcessEventsFor(fLine1);
+}
+
+// --------------------------------------------------------------------------
+//
+// Change the text in the status line 2
+//
 void MStatusDisplay::SetStatusLine2(const char *txt)
 {
     fLine2->SetText(txt);
+    gClient->ProcessEventsFor(fLine2);
+}
+
+// --------------------------------------------------------------------------
+//
+// Display information about the name of a container
+//
+void MStatusDisplay::SetStatusLine2(const MParContainer &cont)
+{
+    TString txt = cont.GetDescriptor();
+    txt += ": ";
+    txt += cont.GetTitle();
+
+    cout << txt << endl;
+
+    SetStatusLine2(txt);
 }
 
@@ -164,23 +387,42 @@
 //   always by deleting the corresponding object.
 //
-MStatusDisplay::MStatusDisplay() : TGTransientFrame(gClient->GetRoot(), gClient->GetRoot(), 1, 1)
-{
+// Update time default: 10s
+//
+MStatusDisplay::MStatusDisplay(Long_t t)
+: TGMainFrame(gClient->GetRoot(), 1, 1), fTimer(this, t, kTRUE), fLog(&gLog), fLogIdx(-1), fLogTimer(this, 250, kTRUE), fLogBox(NULL)
+{
+    gROOT->GetListOfSpecials()->Add(this);
+
+    //
+    // Create a list handling GUI widgets
+    //
     fList = new MGList;
     fList->SetOwner();
 
-    SetWMSizeHints(640, 480, 1280, 1024, 10, 10); // set the smallest and biggest size of the Main frame
+    //
+    // set the smallest and biggest size of the Main frame
+    // and move it to its appearance position
+    SetWMSizeHints(640, 548, 1280, 1024, 10, 10);
     Move(rand()%100+50, rand()%100+50);
 
-    fLayCanvas = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY, 3, 3, 3, 3);
+    //
+    // Create the layout hint for the root embedded canavses
+    //
+    fLayCanvas = new TGLayoutHints(kLHintsExpandX|kLHintsExpandY);
     fList->Add(fLayCanvas);
 
+    //
+    // Add Widgets (from top to bottom)
+    //
+    AddMenuBar();
     AddTabs();
     AddProgressBar();
-    AddStatusLine1();
-    AddStatusLine2();
-
+    AddStatusLines();
+
+    //
+    // Now do an automatic layout of the widgets and display the window
+    //
+    Layout();
     MapSubwindows();
-
-    Layout();
 
     SetWindowName("Status Display");
@@ -188,4 +430,7 @@
 
     MapWindow();
+
+    //lient->ProcessEventsFor(this);
+    gSystem->ProcessEvents();
 }
 
@@ -198,7 +443,15 @@
 {
     delete fList;
+
+    gROOT->GetListOfSpecials()->Remove(this);
 } 
 
-TCanvas *MStatusDisplay::GetCanvas(TGCompositeFrame *cf)
+// --------------------------------------------------------------------------
+//
+// Takes a TGCompositeFrame as argument. Searches for the first
+// TRootEmbeddedCanvas which is contained by it and returns a pointer
+// to the corresponding TCanvas. If it isn't found NULL is returned.
+//
+TCanvas *MStatusDisplay::GetCanvas(TGCompositeFrame *cf) const
 {
     TIter Next(cf->GetList());
@@ -212,9 +465,13 @@
 }
 
-TCanvas *MStatusDisplay::GetCanvas(int i)
+// --------------------------------------------------------------------------
+//
+// Returns GetCanvas of the i-th Tab.
+//
+TCanvas *MStatusDisplay::GetCanvas(int i) const
 {
     if (i<0 || i>=fTab->GetNumberOfTabs())
     {
-        cout << "MStatusDisplay::GetCanvas: Out of range." << endl;
+        *fLog << warn << "MStatusDisplay::GetCanvas: Out of range." << endl;
         return NULL;
     }
@@ -223,5 +480,11 @@
 }
 
-TCanvas *MStatusDisplay::GetCanvas(const TString &name)
+// --------------------------------------------------------------------------
+//
+// Searches for a TRootEmbeddedCanvas in the TGCompositeFramme of the
+// Tab with the name 'name'. Returns the corresponding TCanvas or
+// NULL if something isn't found.
+//
+TCanvas *MStatusDisplay::GetCanvas(const TString &name) const
 {
     TGFrameElement *f;
@@ -249,30 +512,250 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Calls TCanvas::cd(), for the canvas returned by GetCanvas.
+//
+Bool_t MStatusDisplay::CdCanvas(const TString &name)
+{
+    TCanvas *c = GetCanvas(name);
+    if (!c)
+        return kFALSE;
+
+    c->cd();
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Adds a new tab with the name 'name'. Adds a TRootEmbeddedCanvas to the
+// tab and returns a reference to the corresponding TCanvas.
+//
 TCanvas &MStatusDisplay::AddTab(const char *name)
 {
+    // Add new tab
     TGCompositeFrame *f = fTab->AddTab(name);
 
-    TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, 100, 100, 0);
+    // create root embedded canvas and add it to the tab
+    TRootEmbeddedCanvas *ec = new TRootEmbeddedCanvas(name, f, f->GetWidth(), f->GetHeight(), 0);
     f->AddFrame(ec, fLayCanvas);
     fList->Add(ec);
 
+    // set background and border mode of the canvas
     TCanvas &c = *ec->GetCanvas();
 
-    c.SetFillColor(/*165*/17);
+    c.SetFillColor(16/*165*//*17*//*203*/);
     c.SetBorderMode(0);
 
+    // If kNoContaxtMenu set set kNoCOntextMenu of the canvas
+    if (TestBit(kNoContextMenu))
+        c.SetBit(kNoContextMenu);
+
+    // layout and map new tab
+    Layout();
     MapSubwindows();
-    Layout();
-    // MapWindow();
-
-    cout << "Adding Tab '" << name << "' (TCanvas=" << &c << ")" <<  ec << endl;
-
+
+    // display new tab in the main frame
+    gClient->ProcessEventsFor(fTab);
+
+    *fLog << inf << "Adding Tab '" << name << "' (" << f->GetWidth() << "x";
+    *fLog << f->GetHeight() << ", TCanvas=" << &c << ")" << endl;
+
+    // return pointer to new canvas
     return c;
 }
 
+// --------------------------------------------------------------------------
+//
+// Update a canvas in a tab, takes the corresponding TGCompositeFrame
+// as an argument
+//
+void MStatusDisplay::UpdateTab(TGCompositeFrame *f)
+{
+    if (!f)
+        return;
+
+    TCanvas *c=GetCanvas(f);
+    if (!c)
+        return;
+
+    c->Modified();
+    c->Update();
+    c->Paint();
+}
+
+// --------------------------------------------------------------------------
+//
+// Saves the given canvas (pad) or all pads (num<0) as a temporary
+// postscript file and prints it using 'lpr'. If a printer name is set
+// via SetPrinter 'lpr -Pname' is used.
+//
+Int_t MStatusDisplay::PrintToLpr(Int_t num) const
+{
+    TString name = "mars";
+
+    for (int i=0; i<6; i++)
+        name += (char)(gRandom->Uniform(25)+65);
+
+    name += ".ps";
+
+    const Int_t pages = SaveAsPS(num, name);
+    if (!pages)
+    {
+        *fLog << warn << "MStatusDisplay::PrintToLpr: Sorry, couldn't save file as temporary postscript!" << endl;
+        return 0;
+    }
+
+    TString cmd="lpr ";
+    if (!fPrinter.IsNull())
+    {
+        cmd += "-P";
+        cmd += fPrinter;
+        cmd += " ";
+    }
+    cmd += name;
+
+    gSystem->Exec(cmd);
+    gSystem->Unlink(name);
+
+    return pages;
+}
+
+// --------------------------------------------------------------------------
+//
+// Process the kC_COMMAND, kCM_MENU  messages
+//
+Bool_t MStatusDisplay::ProcessMessageCommandMenu(Long_t id)
+{
+    //cout << "Menu #" << id << endl;
+    switch (id)
+    {
+    case kLoopStop:
+    case kFileExit:
+        if (id==kFileExit && !TestBit(kIsLocked))
+            delete this;
+        fStatus = (Status_t)id;
+        return kTRUE;
+/*
+    case kFileSave:
+        cout << "Save..." << endl;
+        return kTRUE;
+
+    case kFileSaveAs:
+        cout << "SaveAs..." << endl;
+        return kTRUE;
+*/
+    case kFileSaveAsPS:
+        //cout << "FileSaveAsPS..." << endl;
+        SaveAsPS();
+        return kTRUE;
+/*
+    case kFileSaveAsGIF:
+        cout << "FileSaveAsGIF..." << endl;
+        SaveAsGIF();
+        return kTRUE;
+
+    case kFileSaveAsC:
+        cout << "FileSaveAsC..." << endl;
+        SaveAsC();
+        return kTRUE;
+*/
+    case kFileSaveAsRoot:
+        SaveAsRoot();
+        return kTRUE;
+
+    case kFilePrint:
+        PrintToLpr();
+        return kTRUE;
+
+    case kTabSaveAsPS:
+        SaveAsPS(fTab->GetCurrent());
+        return kTRUE;
+/*
+    case kTabSaveAsGIF:
+        cout << "TabSaveAsGIF... " << fTab->GetCurrent() <<  endl;
+        SaveAsGIF(fTab->GetCurrent());
+        return kTRUE;
+
+    case kTabSaveAsC:
+        cout << "TabSaveAsC... " << fTab->GetCurrent() <<  endl;
+        SaveAsC(fTab->GetCurrent());
+        return kTRUE;
+*/
+    case kTabSaveAsRoot:
+        SaveAsRoot(fTab->GetCurrent());
+        return kTRUE;
+
+    case kTabPrint:
+        PrintToLpr(fTab->GetCurrent());
+        return kTRUE;
+
+    case kTabNext:
+        fTab->SetTab(fTab->GetCurrent()+1);
+        return kTRUE;
+
+    case kTabPrevious:
+        fTab->SetTab(fTab->GetCurrent()-1);
+        return kTRUE;
+    }
+    return kTRUE;
+
+    cout << "Command-Menu: Id=" << id << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Process the kC_COMMAND messages
+//
+Bool_t MStatusDisplay::ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2)
+{
+    switch (submsg)
+    {
+    case kCM_MENU:
+        return ProcessMessageCommandMenu(mp1);
+
+    case kCM_MENUSELECT:
+        cout << "Menuselect #" << mp1 << endl;
+        return kTRUE;
+
+    case kCM_TAB:
+        for (int i=1; i<fTab->GetNumberOfTabs(); i++)
+            fTab->GetTabContainer(i)->UnmapWindow();
+        UpdateTab(fTab->GetTabContainer(mp1));
+        fTab->GetTabContainer(mp1)->MapWindow();
+        /*
+        if (mp1>0)
+            fMenu->AddPopup("&CaOs", fCaOs, NULL);
+        else
+            fMenu->RemovePopup("CaOs");
+        fMenu->Resize(fMenu->GetDefaultSize());
+        MapSubwindows();
+        MapWindow();
+        */
+        return kTRUE;
+
+    case kCM_BUTTON:
+        if (mp1==kPicMars)
+            return kTRUE;
+        return kTRUE;
+    }
+
+    cout << "Command: " << "Submsg:" << submsg << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Process the messages from the GUI
+//
 Bool_t MStatusDisplay::ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2)
 {
-    cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg) << " Mp1=";
-    cout << mp1 << " Mp2=" << mp2 << endl;
+    switch (GET_MSG(msg))
+    {
+    case kC_COMMAND:
+        return ProcessMessageCommand(GET_SUBMSG(msg), mp1, mp2);
+    }
+
+    cout << "Msg: " << GET_MSG(msg) << " Submsg:" << GET_SUBMSG(msg);
+    cout << " Mp1=" << mp1 << " Mp2=" << mp2 << endl;
 
     return kTRUE;
@@ -292,2 +775,458 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Calls SetBit(kNoContextMenu) for all TCanvas objects found in the
+// Tabs.
+//
+void MStatusDisplay::SetNoContextMenu(Bool_t flag=kTRUE)
+{
+    flag ? SetBit(kNoContextMenu) : ResetBit(kNoContextMenu);
+    for (int i=1; i<fTab->GetNumberOfTabs(); i++)
+    {
+        TCanvas *c = GetCanvas(i);
+        if (c)
+            flag ? c->SetBit(kNoContextMenu) : c->ResetBit(kNoContextMenu);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Updates the canvas (if existing) in the currenly displayed Tab.
+// The update intervall is controlled by StartUpdate and StopUpdate
+//
+Bool_t MStatusDisplay::HandleTimer(TTimer *timer)
+{
+    const Int_t c = fTab->GetCurrent();
+
+    // Skip Legend Tab
+    if (c==0)
+        return kTRUE;
+
+    if (timer==&fTimer)
+    {
+        TGCompositeFrame *f=fTab->GetCurrentContainer();
+        if (f!=fLogBox)
+            return kTRUE;
+
+        UpdateTab(f);
+        return kTRUE;
+    }
+    if (timer==&fLogTimer && c==fLogIdx)
+    {
+        fLog->UpdateGui();
+
+        if (!fLogBox->TestBit(kHasChanged))
+            return kTRUE;
+
+        fLogBox->MapSubwindows();
+        fLogBox->Layout();
+        fLogBox->ResetBit(kHasChanged);
+        return kTRUE;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Draws a clone of a canvas into a new canvas. Taken from TCanvas.
+//
+void MStatusDisplay::DrawClonePad(TCanvas &newc, const TCanvas &oldc) const
+{
+    //copy pad attributes
+    newc.Range(oldc.GetX1(),oldc.GetY1(),oldc.GetX2(),oldc.GetY2());
+    newc.SetTickx(oldc.GetTickx());
+    newc.SetTicky(oldc.GetTicky());
+    newc.SetGridx(oldc.GetGridx());
+    newc.SetGridy(oldc.GetGridy());
+    newc.SetLogx(oldc.GetLogx());
+    newc.SetLogy(oldc.GetLogy());
+    newc.SetLogz(oldc.GetLogz());
+    newc.SetBorderSize(oldc.GetBorderSize());
+    newc.SetBorderMode(oldc.GetBorderMode());
+    ((TAttLine&)oldc).Copy((TAttLine&)newc);
+    ((TAttFill&)oldc).Copy((TAttFill&)newc);
+    ((TAttPad&)oldc).Copy((TAttPad&)newc);
+
+    //copy primitives
+    TObject *obj;
+    TIter next(oldc.GetListOfPrimitives());
+    while ((obj=next())) {
+        gROOT->SetSelectedPad(&newc);
+        newc.GetListOfPrimitives()->Add(obj->Clone(),obj->GetDrawOption());
+    }
+    newc.Modified();
+    newc.Update();
+}
+
+// --------------------------------------------------------------------------
+//
+// Reads the contents of a saved MStatusDisplay from a file.
+//
+Int_t MStatusDisplay::Read(const char *name)
+{
+    if (!gFile)
+    {
+        *fLog << warn << "MStatusDisplay::Read: No file found. Please create a TFile first." << endl;
+        return 0;
+    }
+
+    if (!gFile->IsOpen())
+    {
+        *fLog << warn << "MStatusDisplay::Read: File not open. Please open the TFile first." << endl;
+        return 0;
+    }
+
+    TObjArray list;
+
+    const Int_t n = list.Read(name);
+    if (n==0)
+    {
+        *fLog << warn << "MStatusDisplay::Read: No objects read." << endl;
+        return 0;
+    }
+
+    TIter Next(&list);
+    TCanvas *c;
+    while ((c=(TCanvas*)Next()))
+        DrawClonePad(AddTab(c->GetName()), *c);
+
+    *fLog << inf << "MStatusDisplay: Key " << name << " with " << n << " keys read from file." << endl;
+
+    return n;
+}
+
+// --------------------------------------------------------------------------
+//
+// Writes the contents of a MStatusDisplay to a file.
+//
+Int_t MStatusDisplay::Write(Int_t num, const char *name, Int_t option, Int_t bufsize)
+{
+    if (!gFile)
+    {
+        *fLog << warn << "MStatusDisplay::Write: No file found. Please create a TFile first." << endl;
+        return 0;
+    }
+
+    if (!gFile->IsOpen())
+    {
+        *fLog << warn << "MStatusDisplay::Write: File not open. Please open the TFile first." << endl;
+        return 0;
+    }
+
+    if (!gFile->IsWritable())
+    {
+        *fLog << warn << "MStatusDisplay::Write: File not writable." << endl;
+        return 0;
+    }
+
+    if (num==0)
+    {
+        *fLog << warn << "MStatusDisplay::Write: Tab doesn't contain an embedded Canvas... skipped." << endl;
+        return 0;
+    }
+
+    if (num>=fTab->GetNumberOfTabs())
+    {
+        *fLog << warn << "MStatusDisplay::Write: Tab doesn't exist... skipped." << endl;
+        return 0;
+    }
+
+    TObjArray list;
+
+    const Int_t from = num<0 ? 1 : num;
+    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
+
+    TCanvas *c;
+    for (int i=from; i<to; i++)
+        if ((c = GetCanvas(i)))
+            list.Add(c);
+
+    const Int_t n = list.Write(name, kSingleKey);
+
+    *fLog << inf << "MStatusDisplay: " << n << " keys written to file as key " << name << "." << endl;
+
+    return n;
+}
+
+// --------------------------------------------------------------------------
+//
+// Use this to start the synchronous (GUI eventloop driven) tab update.
+// Can also be used to change the update intervall. If millisec<0
+// the intervall given in SetUpdateTime is used. If the intervall in
+// SetUpdateTime is <0 nothing is done. (Call SetUpdateTime(-1) to
+// disable the automatic update in a MEventloop.
+//
+void MStatusDisplay::StartUpdate(Int_t millisec=-1)
+{
+    if (fTimer.GetTime()<TTime(0))
+        return;
+    fTimer.Start(millisec);
+}
+
+// --------------------------------------------------------------------------
+//
+// Stops the automatic GUI update
+//
+void MStatusDisplay::StopUpdate()
+{
+    fTimer.Stop();
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the update interval for the GUI update, see StartUpdate.
+//
+void MStatusDisplay::SetUpdateTime(Long_t t)
+{
+    fTimer.SetTime(t);
+}
+
+// --------------------------------------------------------------------------
+//
+// Set the background color in a canvas
+//
+void MStatusDisplay::CanvasSetFillColor(TPad &p, Int_t col) const
+{
+    TObject *obj;
+
+    TIter Next(p.GetListOfPrimitives());
+    while ((obj=Next()))
+    {
+        if (obj->InheritsFrom(TPad::Class()))
+            CanvasSetFillColor(*(TPad*)obj, col);
+        if (obj->InheritsFrom(TFrame::Class()))
+            ((TFrame*)obj)->SetFillColor(col);
+    }
+
+    p.SetFillColor(col);
+}
+
+void MStatusDisplay::AddExtension(TString &name, const TString &ext, Int_t num) const
+{
+    if (name.IsNull())
+    {
+        name = "status";
+        if (num>0)
+        {
+            name += "-";
+            name += num;
+        }
+    }
+
+    if (name.EndsWith("."+ext))
+        return;
+
+    name += ".";
+    name += ext;
+}
+
+// --------------------------------------------------------------------------
+//
+// In case of num<0 all tabs are written into the PS file. If num>0
+// the canvas in the corresponding tab is written to the file.
+// Name is the name of the file (with or without extension).
+//
+// Returns the number of pages written.
+//
+// To write all tabs you can also use SaveAsPS(name)
+//
+Int_t MStatusDisplay::SaveAsPS(Int_t num, TString name) const
+{
+    if (num>=fTab->GetNumberOfTabs())
+    {
+        *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
+        return 0;
+    }
+    if (num==0)
+    {
+        *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
+        return 0;
+    }
+    if (fTab->GetNumberOfTabs()<2 || !gPad)
+    {
+        *fLog << warn << "Sorry, you must have at least one existing canvas (gPad!=NULL)" << endl;
+        return 0;
+    }
+
+    AddExtension(name, "ps", num);
+
+    if (num<0)
+        *fLog << inf << "Open ps-File: " << name << endl;
+
+    TPad       *padsav = (TPad*)gPad;
+    TVirtualPS *psave  = gVirtualPS;
+
+    TPostScript ps(name, 112);
+    ps.SetBit(TPad::kPrintingPS);
+    ps.PrintFast(13, "/nan {1} def ");
+
+    gVirtualPS = &ps;
+
+    //
+    // Create a list to delete the canvas clones
+    //
+    TList l;
+    l.SetOwner();
+
+    //
+    // Create some GUI elements for a page legend
+    //
+    TLine line;
+
+    int page = 1;
+
+    //
+    // Maintain tab numbers
+    //
+    const Int_t from = num<0 ? 1 : num;
+    const Int_t to   = num<0 ? fTab->GetNumberOfTabs() : num+1;
+
+    for (int i=from; i<to; i++)
+    {
+        TCanvas *c;
+        if (!(c = GetCanvas(i)))
+        {
+            if (num<0)
+                *fLog << inf << " - ";
+            *fLog << "Tab #" << i << " doesn't contain an embedded Canvas... skipped." << endl;
+            continue;
+        }
+
+        //
+        // Init page and page size, make sure, that the canvas in the file
+        // has the same Aspect Ratio than on the screen.
+        //
+        ps.NewPage();
+
+        Float_t psw = 26; // A4 - width
+        Float_t psh = 20; // A4 - height
+
+        const Float_t cw = c->GetWw();
+        const Float_t ch = c->GetWh();
+
+        if (psw/psh>cw/ch)
+            psw = cw/ch*psh;
+        else
+            psh = ch/cw*psw;
+
+        ps.Range(psw, psh); // A4
+
+        //
+        // Clone canvas and change background color and schedule for
+        // deletion
+        //
+        TCanvas *n = (TCanvas*)c->Clone();
+        CanvasSetFillColor(*n, kWhite);
+        l.Add(n);
+
+        //
+        // Paint canvas into root file
+        //
+        if (num<0)
+            *fLog << inf << " - ";
+        *fLog << "Writing Tab #" << i << ": " << c->GetName() << " (" << n << ") ";
+        if (num>0)
+            *fLog << "to " << name;
+        *fLog << "..." << flush;
+
+        n->SetBatch(kTRUE);
+        n->Paint();
+
+        //
+        // Use the canvas as coordinate system for the overlaying text
+        //
+        gPad = n;
+
+        //
+        // Print overlaying text (NDC = %)
+        //
+        ps.SetTextColor(kBlack);
+        ps.SetTextSize(0.015);
+        ps.SetTextFont(22);
+        ps.SetTextAlign(11); // left top
+        ps.TextNDC(0, 1.02, TString("  ")+n->GetName());
+        ps.SetTextAlign(21); // cent top
+        ps.TextNDC(0.5, 1.02, "MARS - Magic Analysis and Reconstruction Software");
+        ps.SetTextAlign(31); // right top
+        ps.TextNDC(1, 1.02, Form("Page No.%i (%i)  ", page++, i));
+        line.PaintLineNDC(0, 1.015, 1, 1.015);
+
+        //
+        // Finish drawing page
+        //
+        n->SetBatch(kFALSE);
+        if (num<0)
+            *fLog << "done." << endl;
+    }
+
+    gPad = NULL; // Important!
+
+    l.Delete();
+
+    ps.Close();
+
+    gVirtualPS = psave;
+    padsav->cd();
+
+    *fLog << inf << "done." << endl;
+
+    return page-1;
+}
+
+/*
+void MStatusDisplay::SaveAsGIF(Int_t num, TString name) const
+{
+    AddExtension(name, "gif", num);
+
+    cout << "Open gif-File: " << name << endl;
+    cout << " SORRY, not implemented." << endl;
+}
+
+void MStatusDisplay::SaveAsC(Int_t num, TString name) const
+{
+    AddExtension(name, "C", num);
+
+    cout << "Open C-File: " << name << endl;
+    cout << " SORRY, not implemented." << endl;
+}
+*/
+
+// --------------------------------------------------------------------------
+//
+// In case of num<0 all tabs are written into the PS file. If num>0
+// the canvas in the corresponding tab is written to the file.
+// Name is the name of the file (with or without extension).
+//
+// Returns the number of keys written.
+//
+// To write all tabs you can also use SaveAsPS(name)
+//
+Int_t MStatusDisplay::SaveAsRoot(Int_t num, TString name)
+{
+    if (num>=fTab->GetNumberOfTabs())
+    {
+        *fLog << warn << "Tab #" << num << " doesn't exist..." << endl;
+        return 0;
+    }
+    if (num==0)
+    {
+        *fLog << warn << "Tab #" << num << " doesn't contain an embedded canvas..." << endl;
+        return 0;
+    }
+    if (fTab->GetNumberOfTabs()<2 || !gPad)
+    {
+        *fLog << warn << "Sorry, you must have at least one existing canvas." << endl;
+        return 0;
+    }
+
+    AddExtension(name, "root", num);
+
+    TFile *fsave = gFile;
+    TFile file(name, "RECREATE", "MARS - Status Window Contents", 9);
+    const Int_t keys = Write(num);
+    gFile = fsave;
+
+    return keys;
+}
Index: trunk/MagicSoft/Mars/mmain/MStatusDisplay.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mmain/MStatusDisplay.h	(revision 1965)
@@ -10,15 +10,50 @@
 #endif
 
+#ifndef ROOT_TTimer
+#include <TTimer.h>
+#endif
+
+class MLog;
 class MGList;
+class MParContainer;
 
+class TPad;
+class TTimer;
 class TCanvas;
 
 class TGTab;
 class TGLabel;
+class TGListBox;
 class TGProgressBar;
 class TGHProgressBar;
 
-class MStatusDisplay : public TGTransientFrame
+class MStatusDisplay : public TGMainFrame
 {
+public:
+    typedef enum {
+        kLoopNone,
+        kLoopStop,
+        kFileSave,
+        kFileSaveAs,
+        kFileSaveAsPS,
+        kFileSaveAsRoot,
+        kFileSaveAsGIF,
+        kFileSaveAsC,
+        kFilePrint,
+        kFilePrinterName,
+        kTabSave,
+        kTabSaveAs,
+        kTabSaveAsPS,
+        kTabSaveAsRoot,
+        kTabSaveAsGIF,
+        kTabSaveAsC,
+        kTabPrint,
+        kTabNext,
+        kTabPrevious,
+        kFileExit,
+        kPicMagic,
+        kPicMars
+    } Status_t;
+
 private:
     MGList         *fList;
@@ -27,21 +62,52 @@
     TGLayoutHints  *fLayCanvas;
 
+    TTimer fTimer;
 
     TGLabel *fLine1;
     TGLabel *fLine2;
 
+    Status_t fStatus;
+
+    TString fPrinter;
+
+    MLog *fLog;
+    Int_t fLogIdx;
+    TTimer fLogTimer;
+    TGListBox *fLogBox;
+
+    void AddMenuBar();
     void AddProgressBar();
+    void AddMarsTab();
+    void AddLogTab();
     void AddTabs();
-    void AddStatusLine1();
-    void AddStatusLine2();
+    void AddStatusLines();
 
-    TCanvas *GetCanvas(TGCompositeFrame *f);
+    TCanvas *GetCanvas(TGCompositeFrame *f) const;
 
+    Bool_t ProcessMessageCommandMenu(Long_t mp1);
+    Bool_t ProcessMessageCommand(Long_t submsg, Long_t mp1, Long_t mp2);
     Bool_t ProcessMessage(Long_t msg, Long_t mp1, Long_t mp2);
     void   CloseWindow();
 
+    Bool_t HandleTimer(TTimer *timer=NULL);
+    void UpdateTab(TGCompositeFrame *f);
+
+    void DrawClonePad(TCanvas &newc, const TCanvas &oldc) const;
+    void CanvasSetFillColor(TPad &c, Int_t col) const;
+
+    void AddExtension(TString &name, const TString &ext, Int_t num) const;
+
+    enum {
+        kIsLocked = BIT(14)
+    };
 public:
-     MStatusDisplay();
+     MStatusDisplay(Long_t t=1000);
      virtual ~MStatusDisplay();
+
+     void SetLogStream(MLog *log);
+
+     void StartUpdate(Int_t millisec=-1);
+     void StopUpdate();                  
+     void SetUpdateTime(Long_t t);       
 
      TGProgressBar *GetBar() const { return (TGProgressBar*)fBar; }
@@ -49,9 +115,41 @@
      void SetStatusLine1(const char *txt);
      void SetStatusLine2(const char *txt);
+     void SetStatusLine2(const MParContainer &cont);
+
+     void SetPrinter(const TString &lpr) { fPrinter = lpr; }
 
      TCanvas &AddTab(const char *name);
 
-     TCanvas *GetCanvas(int i);
-     TCanvas *GetCanvas(const TString &name);
+     TCanvas *GetCanvas(int i) const;
+     TCanvas *GetCanvas(const TString &name) const;
+
+     Int_t Read(const char *name="MStatusDisplay");
+     Int_t Write(const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0)
+     {
+         return Write(-1, name, option, bufsize);
+     }
+     Int_t Write(Int_t num, const char *name="MStatusDisplay", Int_t option=0, Int_t bufsize=0);
+
+     Bool_t CdCanvas(const TString &name);
+
+     void SetNoContextMenu(Bool_t flag=kTRUE);
+
+     Int_t SaveAsPS(TString name="") const { return SaveAsPS(-1, name); }
+     //Bool_t SaveAsGIF(TString name="") const { return SaveAsGIF(-1, name); }
+     //Bool_t SaveAsC(TString name="") const { return SaveAsC(-1, name); }
+     Int_t SaveAsRoot(TString name="") { return SaveAsRoot(-1, name); }
+     Int_t PrintToLpr() const { return PrintToLpr(-1); }
+
+     Int_t SaveAsPS(Int_t num, TString name="") const;
+     //Bool_t SaveAsGIF(Int_t num, TString name="") const;
+     //Bool_t SaveAsC(Int_t num, TString name="") const;
+     Int_t SaveAsRoot(Int_t num, TString name="");
+     Int_t PrintToLpr(Int_t num) const;
+
+     Status_t CheckStatus() const { return fStatus; }
+     void ClearStatus() { fStatus = kLoopNone; }
+
+     void Lock() { SetBit(kIsLocked); }
+     void UnLock() { ResetBit(kIsLocked); }
 
      ClassDef(MStatusDisplay, 0)   // Window for a status display
Index: trunk/MagicSoft/Mars/mmain/MainLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MainLinkDef.h	(revision 1964)
+++ trunk/MagicSoft/Mars/mmain/MainLinkDef.h	(revision 1965)
@@ -8,10 +8,12 @@
 
 #pragma link C++ class MMars+;
+#pragma link C++ class MEvtDisp+;
 #pragma link C++ class MAnalysis+;
-#pragma link C++ class MEvtDisp+;
+//#pragma link C++ class MTextEntry+;
 #pragma link C++ class MDataCheck+;
 #pragma link C++ class MMonteCarlo+;
 #pragma link C++ class MProgressBar+;
 #pragma link C++ class MCameraDisplay+;
+#pragma link C++ class MStatusDisplay+;
 
 #endif
Index: trunk/MagicSoft/Mars/mmain/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mmain/Makefile	(revision 1964)
+++ trunk/MagicSoft/Mars/mmain/Makefile	(revision 1965)
@@ -32,6 +32,8 @@
 SRCFILES = MBrowser.cc \
 	   MEvtDisp.cc \
+	   MStatusDisplay.cc \
 	   MDataCheck.cc \
 	   MMars.cc \
+           MGMenu.cc \
            MAnalysis.cc \
 	   MMonteCarlo.cc \
