Index: trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1967)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1968)
@@ -92,11 +92,15 @@
     fGraph->SetTitle("Acceptance Gammas vs. Hadrons");
     fGraph->SetMaximum(1);
-
-    fGhness = new TH1D("Ghness", "Hadronness", nbins, 0, 1);
-    fPhness = new TH1D("Phness", "Hadronness", nbins, 0, 1);
+    fGraph->SetMarkerStyle(kFullDotSmall);
+
+    fGhness = new TH1D("Ghness", "H. Gammas",  nbins, 0, 1);
+    fPhness = new TH1D("Phness", "H. Hadrons", nbins, 0, 1);
     fGhness->SetXTitle("Hadronness");
     fPhness->SetXTitle("Hadronness");
     fGhness->SetYTitle("Counts");
     fPhness->SetYTitle("Counts");
+    fPhness->SetLineColor(kRed);
+    fGhness->SetDirectory(NULL);
+    fPhness->SetDirectory(NULL);
     
     fIntGhness = new TH1D("AccGammas",  "Acceptance", nbins, 0, 1);
@@ -108,12 +112,13 @@
     fIntGhness->SetMaximum(1.1);
     fIntPhness->SetMaximum(1.1);
+    fIntGhness->SetDirectory(NULL);
+    fIntPhness->SetDirectory(NULL);
+    fIntPhness->SetLineColor(kRed);
+    fIntGhness->SetBit(TH1::kNoStats);
+    fIntPhness->SetBit(TH1::kNoStats);
 
     fQfac = new TGraph;
     fQfac->SetTitle(" Naive Quality factor ");
-
-    fGhness->SetDirectory(NULL);
-    fPhness->SetDirectory(NULL);
-    fIntGhness->SetDirectory(NULL);
-    fIntPhness->SetDirectory(NULL);
+    fQfac->SetMarkerStyle(kFullDotSmall);
 }
 
@@ -241,5 +246,5 @@
 //  - fill the Quality histogram (formular see class description)
 //
-Bool_t MHHadronness::Finalize()
+void MHHadronness::CalcGraph(Double_t sumg, Double_t sump)
 {
     Int_t n = fGhness->GetNbinsX();
@@ -248,48 +253,68 @@
     fQfac->Set(n);
 
+    // Calculate acceptances
+    Float_t max=0;
+
+    for (Int_t i=1; i<=n; i++)
+    {
+        const Stat_t ip = fPhness->Integral(1, i)/sump;
+        const Stat_t ig = fGhness->Integral(1, i)/sumg;
+
+        fIntPhness->SetBinContent(i, ip);
+        fIntGhness->SetBinContent(i, ig);
+
+        fGraph->SetPoint(i, ip, ig);
+
+        if (ip<=0)
+            continue;
+
+        const Double_t val = ig/sqrt(ip);
+        fQfac->SetPoint(i, ig, val);
+
+        if (val>max)
+            max = val;
+    }
+
+    fQfac->SetMaximum(max*1.05);
+}
+
+Bool_t MHHadronness::Finalize()
+{
     const Stat_t sumg = fGhness->Integral();
     const Stat_t sump = fPhness->Integral();
 
     *fLog << inf << "Sum Hadronness: gammas=" << sumg << " hadrons=" << sump << endl;
-
-    if (sumg==0 )
-        *fLog << warn << "Cannot calculate hadronness for 'gammas'." << endl;
-    if (sump==0)
-        *fLog << warn << "Cannot calculate hadronness for 'hadrons'." << endl;
 
     // Normalize photon distribution
     if (sumg>0)
         fGhness->Scale(1./sumg);
+    else
+        *fLog << warn << "Cannot calculate hadronness for 'gammas'." << endl;
 
     // Normalize hadron distribution
     if (sump>0)
         fPhness->Scale(1./sump);
-
-    // Calculate acceptances
-    Float_t max=0;
-
-    for (Int_t i=1; i<=n; i++)
-    {
-        const Stat_t ip = fPhness->Integral(1, i);
-        const Stat_t ig = fGhness->Integral(1, i);
-
-        fIntPhness->SetBinContent(i, ip);
-        fIntGhness->SetBinContent(i, ig);
-
-        fGraph->SetPoint(i, ip, ig);
-
-        if (ip<=0)
-            continue;
-
-        const Double_t val = ig/sqrt(ip);
-        fQfac->SetPoint(i, ig, val);
-
-        if (val>max)
-            max = val;
-    }
-
-    fQfac->SetMaximum(max*1.05);
+    else
+        *fLog << warn << "Cannot calculate hadronness for 'hadrons'." << endl;
+
+    CalcGraph(1, 1);
 
     return kTRUE;
+}
+
+void MHHadronness::Paint(Option_t *opt="")
+{
+    Stat_t sumg = fGhness->Integral();
+    Stat_t sump = fPhness->Integral();
+
+    // Normalize photon distribution
+    if (sumg<=0)
+        sumg=1;
+
+    // Normalize hadron distribution
+    if (sump<=0)
+        sump=1;
+
+    CalcGraph(sumg, sump);
 }
 
@@ -399,130 +424,52 @@
 // --------------------------------------------------------------------------
 //
-// Draw clone of all histograms. (For the Meaning see class description)
-//
-TObject *MHHadronness::DrawClone(Option_t *opt) const
-{
-    if (fGraph->GetN()==0)
-        return NULL;
-
-    TCanvas &c = *MakeDefCanvas("Hadronness", fTitle);
-    c.Divide(2, 2);
-
-    gROOT->SetSelectedPad(NULL);
-
-    c.cd(1);
+// Draw all histograms. (For the Meaning see class description)
+//
+void MHHadronness::Draw(Option_t *)
+{
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas("Hadronness", fTitle);
+    pad->SetBorderMode(0);
+
+    AppendPad("");
+
+    pad->Divide(2, 2);
+
+    TH1 *h;
+
+    pad->cd(1);
+    gPad->SetBorderMode(0);
     //gStyle->SetOptStat(10);
-    Getghness()->DrawCopy();
-    Getphness()->SetLineColor(kRed);
-    Getphness()->DrawCopy("same");
-
-    c.cd(2);
-    //gStyle->SetOptStat(0);
-    Getighness()->DrawCopy();
-    Getiphness()->SetLineColor(kRed);
-    Getiphness()->DrawCopy("same");
-
-    c.cd(3);
-    TGraph &g2 = (TGraph&)*fQfac->DrawClone("A*");
-    g2.SetBit(kCanDelete);
-    gPad->Modified();
-    gPad->Update();
-    if (g2.GetHistogram())
-    {
-        g2.GetXaxis()->SetRangeUser(0, 1);
-        g2.GetXaxis()->SetTitle("Acceptance Gammas");
-        g2.GetYaxis()->SetTitle("Quality");
-        g2.SetMarkerStyle(kFullDotSmall);
-        g2.Draw("P");
-
-        gPad->Modified();
-        gPad->Update();
-    }
-
-    c.cd(4);
-    gPad->Modified();
-    gPad->Update();
-    TGraph &g = (TGraph&)*fGraph->DrawClone("AC");
-    g.SetBit(kCanDelete);
-    gPad->Modified();
-    gPad->Update();
-    if (g.GetHistogram())
-    {
-        g.GetXaxis()->SetRangeUser(0, 1);
-        g.GetXaxis()->SetTitle("Acceptance Hadrons");
-        g.GetYaxis()->SetTitle("Acceptance Gammas");
-        g.SetMarkerStyle(kFullDotSmall);
-        g.Draw("P");
-
-        gPad->Modified();
-        gPad->Update();
-    }
-    /*
-    const Int_t h = fMinDist->GetMaximumBin();
-    TMarker *m = new TMarker(fIntPhness->GetBinContent(h),
-                             fIntGhness->GetBinContent(h), kStar);
-    m->SetMarkerColor(kBlue);
-    m->SetBit(kCanDelete);
-    m->Draw();
-    */
-
-    gStyle->SetOptStat(1111);
-
-    return &c;
-}
-
-// --------------------------------------------------------------------------
-//
-// Draw all histograms. (For the Meaning see class description)
-//
-void MHHadronness::Draw(Option_t *)
-{
-   if (fGraph->GetN()==0)
-        return;
-
-   if (!gPad)
-        MakeDefCanvas("Hadronness", fTitle);
-
-    gPad->Divide(2, 2);
-
-    gPad->cd(1);
-    //gStyle->SetOptStat(10);
-    Getghness()->Draw();
-    Getphness()->SetLineColor(kRed);
-    Getphness()->Draw("same");
-
-    gPad->cd(2);
-    //gStyle->SetOptStat(0);
-    Getighness()->Draw();
-    Getiphness()->SetLineColor(kRed);
-    Getiphness()->Draw("same");
-
-    gPad->cd(3);
+    MH::Draw(*fGhness, *fPhness, "Hadronness"); // Displ both stat boxes
+
+    pad->cd(2);
+    gPad->SetBorderMode(0);
+    fIntGhness->Draw();
+    fIntPhness->Draw("same");
+
+    pad->cd(3);
+    gPad->SetBorderMode(0);
     fQfac->Draw("A*");
     gPad->Modified();
     gPad->Update();
-    if (fQfac->GetHistogram())
-    {
-        fQfac->GetXaxis()->SetRangeUser(0, 1);
-        fQfac->GetXaxis()->SetTitle("Acceptance Gammas");
-        fQfac->GetYaxis()->SetTitle("Quality");
-        fQfac->SetMarkerStyle(kFullDotSmall);
+    if ((h=fQfac->GetHistogram()))
+    {
+        h->GetXaxis()->SetRangeUser(0, 1);
+        h->SetXTitle("Acceptance Gammas");
+        h->SetYTitle("Quality");
         fQfac->Draw("P");
-
         gPad->Modified();
         gPad->Update();
     }
-    gPad->cd(4);
-    gPad->Modified();
-    gPad->Update();
+
+    pad->cd(4);
+    gPad->SetBorderMode(0);
     fGraph->Draw("AC");
     gPad->Modified();
     gPad->Update();
-    if (fGraph->GetHistogram())
-    {
-        fGraph->GetXaxis()->SetRangeUser(0, 1);
-        fGraph->GetXaxis()->SetTitle("Acceptance Hadrons");
-        fGraph->GetYaxis()->SetTitle("Acceptance Gammas");
-        fGraph->SetMarkerStyle(kFullDotSmall);
+    if ((h=fGraph->GetHistogram()))
+    {
+        h->GetXaxis()->SetRangeUser(0, 1);
+        h->SetXTitle("Acceptance Hadrons");
+        h->SetYTitle("Acceptance Gammas");
         fGraph->Draw("P");
         gPad->Modified();
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1967)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1968)
@@ -26,4 +26,7 @@
     TGraph *fGraph;   //-> gamma acceptance vs. hadron acceptance
 
+    void Paint(Option_t *opt="");
+    void CalcGraph(Double_t sumg, Double_t sump);
+
 public:
     MHHadronness(Int_t nbins=100, const char *name=NULL, const char *title=NULL);
@@ -48,5 +51,4 @@
 
     void Draw(Option_t *opt="");
-    TObject *DrawClone(Option_t *opt="") const;
 
     ClassDef(MHHadronness, 1) // Gamma/Hadron Separation Quality Histograms
Index: trunk/MagicSoft/Mars/mmain/MGMenu.cc
===================================================================
--- trunk/MagicSoft/Mars/mmain/MGMenu.cc	(revision 1968)
+++ trunk/MagicSoft/Mars/mmain/MGMenu.cc	(revision 1968)
@@ -0,0 +1,226 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MGMenu, MGPopupMenu
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MGMenu.h"
+
+
+MGMenuEntry::MGMenuEntry(TGMenuEntry *ent)
+{
+    memcpy(this, ent, sizeof(*ent));
+}
+
+// -------------------------------------------------------------
+//
+// Return the keycode corresponding to the hot string of
+// a TGmenuEntry
+//
+UInt_t MGPopupMenu::GetKeyCode(TGMenuEntry *el)
+{
+    TGHotString *str = MGMenuEntry(el).GetLabel();
+    return gVirtualX->KeysymToKeycode(str->GetHotChar());
+}
+
+// -------------------------------------------------------------
+//
+// Bind all hot keys used in this popup menu subsequentlt
+// to the TGMainFrame and send a HandleKey message to the
+// TGWindow
+//
+void MGPopupMenu::BindKeys(const TGWindow *w, TGMainFrame *frame)
+{
+    TIter Next(fEntryList);
+    TGMenuEntry *el;
+
+    //
+    // Loop Through all entries
+    //
+    while ((el=(TGMenuEntry*)Next()))
+    {
+        switch (el->GetType())
+        {
+            //
+            // For seperators and labels nothing to do
+            //
+        case kMenuSeparator:
+        case kMenuLabel:
+            continue;
+
+            //
+            // For an entry and a popup menu bind the hot key
+            // In case of a popup menu call BindKeys subsequently
+            //
+        case kMenuEntry:
+        case kMenuPopup:
+            frame->BindKey(w, GetKeyCode(el), kKeyMod1Mask);
+            if (el->GetType()==kMenuPopup)
+                MGMenuEntry(el).GetPopup()->BindKeys(w, frame);
+            continue;
+        }
+    }
+}
+
+/*
+ kMenuActiveMask  = BIT(0),
+ kMenuEnableMask  = BIT(1),
+ kMenuDefaultMask = BIT(2),
+ kMenuCheckedMask = BIT(3),
+ kMenuRadioMask   = BIT(4),
+ kMenuHideMask    = BIT(5)
+ */
+
+// -------------------------------------------------------------
+//
+//  Handle a keyboard event. Return kFALSE in case of a
+//  successfully send message, which means: close all open
+//  popups.
+//
+Bool_t MGPopupMenu::HandleKey(Event_t *evt)
+{
+    //
+    // Loop through all entries in this popup menu. If the entry is
+    // an open popup menu send the key event to the open popup.
+    //
+    TIter Next(fEntryList);
+    TGMenuEntry *el;
+    while ((el=(TGMenuEntry*)Next()))
+    {
+        if (el->GetType()==kMenuPopup && el->GetStatus()&kMenuActiveMask)
+            return MGMenuEntry(el).GetPopup()->HandleKey(evt);
+    }
+
+    Next.Reset();
+
+    //
+    // If no open popup is found search the pressed key in this
+    // popup menu.
+    //
+    while ((el=(TGMenuEntry*)Next()))
+    {
+        switch (el->GetType())
+        {
+            //
+            // Do nothing
+            //
+        case kMenuSeparator:
+        case kMenuLabel:
+            continue;
+
+            //
+            // If the keycode corresponds to the hot key
+            // of this entry and the entry is enabled activate the entry
+            // and send the corresponding message/
+            //
+        case kMenuEntry:
+            if (GetKeyCode(el)==evt->fCode && el->GetStatus()&kMenuEnableMask)
+            {
+                Activate(el);
+                SendMessage(fMsgWindow, MK_MSG(kC_COMMAND, kCM_MENU),
+                            el->GetEntryId(), (Long_t)MGMenuEntry(el).GetUserData());
+                return kFALSE;
+            }
+            continue;
+
+            //
+            // If the keycode corresponds to the hot key
+            // of this popup menu activate the popup menu.
+            //
+        case kMenuPopup:
+            if (GetKeyCode(el)!=evt->fCode)
+                continue;
+
+            Activate(el);
+            HandleTimer(NULL);
+            return kTRUE;
+        }
+    }
+    return kTRUE;
+}
+
+// -------------------------------------------------------------
+//
+// Bind the keys of all popups subsequently to the given main
+// frame. The menu bar hot keys are already bound by TGMenuBar.
+// Bind the Escape key to close the popups, too.
+//
+void MGMenuBar::BindKeys(TGMainFrame *frame)
+{
+    TGFrameElement *el=NULL;
+    TIter Next(fList);
+    while ((el = (TGFrameElement *)Next()))
+        ((MGPopupMenu*)((TGMenuTitle *) el->fFrame)->GetMenu())->BindKeys(this, frame);
+
+    frame->BindKey(this, 9/*ESC*/, 0);
+}
+
+// -------------------------------------------------------------
+//
+// Handle the keyboard event send to this menu bar.
+//
+Bool_t MGMenuBar::HandleKey(Event_t *event)
+{
+    //
+    // If this isn't a pressed key do nothing
+    //
+    if (event->fType != kGKeyPress)
+        return kTRUE;
+
+    //
+    // Check whether one popup is alreadu open
+    //
+    TGFrameElement *el=NULL;
+    TIter Next(fList);
+    while ((el = (TGFrameElement *)Next()))
+    {
+        if (!((TGMenuTitle*)el->fFrame)->GetState())
+            continue;
+
+        TGMenuTitle &f = *(TGMenuTitle*)el->fFrame;
+
+        //
+        // If a open popup is found redirect the key event to this
+        // popup menu
+        //
+        Bool_t rc = ((MGPopupMenu*)f.GetMenu())->HandleKey(event);
+
+        //
+        // If a message could be successfully send or the escape key
+        // was pressed close the popup.
+        //
+        if (!rc || event->fCode==9/*ESC*/)
+        {
+            f.SetState(kFALSE);
+            gVirtualX->GrabPointer(0, 0, 0, 0, kFALSE);  // ungrab pointer
+            fCurrent = 0;
+        }
+
+        return kTRUE;
+    }
+
+    return TGMenuBar::HandleKey(event);
+}
Index: trunk/MagicSoft/Mars/mmain/MGMenu.h
===================================================================
--- trunk/MagicSoft/Mars/mmain/MGMenu.h	(revision 1968)
+++ trunk/MagicSoft/Mars/mmain/MGMenu.h	(revision 1968)
@@ -0,0 +1,53 @@
+#ifndef MARS_MGMenu
+#define MARS_MGMenu
+
+#ifndef ROOT_TGMenu
+#include <TGMenu.h>
+#endif
+
+class MGPopupMenu;
+
+class MGMenuEntry : public TGMenuEntry
+{
+    /*
+     Workaround for the protected data mambers of TGMenuEntry
+     */
+public:
+    MGMenuEntry(TGMenuEntry *ent);
+    ~MGMenuEntry()
+    {
+        fLabel=0;
+    }
+
+    MGPopupMenu *GetPopup() { return (MGPopupMenu*)fPopup; }
+    TGHotString *GetLabel() { return fLabel; }
+    void *GetUserData()     { return fUserData; }
+};
+
+class MGPopupMenu : public TGPopupMenu
+{
+public:
+    MGPopupMenu(const TGWindow* p = 0, UInt_t w = 10, UInt_t h = 10, UInt_t options = 0) :
+        TGPopupMenu(p, w, h, options)
+    {
+    }
+
+    UInt_t GetKeyCode(TGMenuEntry *el);
+
+    void BindKeys(const TGWindow *w, TGMainFrame *frame);
+
+    Bool_t HandleKey(Event_t *evt);
+};
+
+class MGMenuBar : public TGMenuBar
+{
+public:
+    MGMenuBar(const TGWindow* p, UInt_t w, UInt_t h, UInt_t options = kHorizontalFrame|kRaisedFrame) :
+        TGMenuBar(p, w, h, options) {}
+
+    void BindKeys(TGMainFrame *frame);
+
+    Bool_t HandleKey(Event_t *event);
+};
+
+#endif
