Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 5619)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 5620)
@@ -28,4 +28,29 @@
    * mcalib/MCalibColorSet.cc:
      - replaced arbitrary number for run type by correct enum
+
+   * mbase/MStatusDisplay.[h,cc]:
+     - changed DrawClonePad such that
+       + before cloning we change into the pad (necessary for 
+         GetDrawOption)
+       + removed SetSelectedPad (seems not necessary at all)
+       + SetBit(kCanDelete) for all cloned object
+       + copy bits kMustCleanup, kCannotPick and kNoContextMenu
+       + oldc is not const anymore (cd()!)
+
+   * mhbase/MH3.[h,cc]:
+     - removed fNameProfX, fNameProfY - didn't work with a more accurate
+       scheme to get the handle to the profile histograms
+     - moved most code from Draw to Paint so that a more accurate handling
+       of read pads containing these histograms is possible
+
+   * mhvstime/MHVsTime.[h,cc]:
+     - moved most code from Draw to Paint so that a more accurate handling
+       of read pads containing these histograms is possible
+
+   * mhflux/MHEffectiveOnTime.[h,cc]:
+     - removed fNameProj* - didn't work with a more accurate
+       scheme to get the handle to the profile histograms
+     - set no option for default AppendPad (istead of "fit" which 
+       didn't work for saved files - for unknown reasons)
 
 
Index: /trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 5619)
+++ /trunk/MagicSoft/Mars/mbase/MStatusDisplay.cc	(revision 5620)
@@ -1588,5 +1588,5 @@
 // Draws a clone of a canvas into a new canvas. Taken from TCanvas.
 //
-void MStatusDisplay::DrawClonePad(TCanvas &newc, const TCanvas &oldc) const
+void MStatusDisplay::DrawClonePad(TCanvas &newc, TCanvas &oldc) const
 {
     //copy pad attributes
@@ -1605,13 +1605,32 @@
     ((TAttPad&)oldc).Copy((TAttPad&)newc);
 
+    // This must be there: Otherwise GetDrawOption() won't work
+    TVirtualPad *padsav = gPad;
+    oldc.cd();
+
     //copy primitives
     TObject *obj;
     TIter next(oldc.GetListOfPrimitives());
-    while ((obj=next())) {
-        gROOT->SetSelectedPad(&newc);
-        newc.GetListOfPrimitives()->Add(obj->Clone(),obj->GetDrawOption());
+    while ((obj=next()))
+    {
+        // Old line - I think it is not necessary anymore because of the cd()
+        //gROOT->SetSelectedPad(&newc);
+
+        // Now make a clone of the object
+        TObject *clone = obj->Clone();
+
+        // Clone also important bits (FIXME: Is this correct)
+        clone->SetBit(obj->TestBits(kMustCleanup|kCannotPick|kNoContextMenu));
+
+        // Now make sure that the clones are deleted at a later time
+        clone->SetBit(kCanDelete);
+
+        // Add the clone and its draw-option to the current pad
+        newc.GetListOfPrimitives()->Add(clone, obj->GetDrawOption());
     }
     newc.Modified();
     newc.Update();
+
+    padsav->cd();
 }
 
Index: /trunk/MagicSoft/Mars/mbase/MStatusDisplay.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 5619)
+++ /trunk/MagicSoft/Mars/mbase/MStatusDisplay.h	(revision 5620)
@@ -117,5 +117,5 @@
     void UpdateTab(TGCompositeFrame *f);
 
-    void DrawClonePad(TCanvas &newc, const TCanvas &oldc) const;
+    void DrawClonePad(TCanvas &newc, TCanvas &oldc) const;
     void CanvasSetFillColor(TPad &c, Int_t col) const;
     Bool_t Display(const TObjArray &list);
Index: /trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 5619)
+++ /trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 5620)
@@ -103,7 +103,7 @@
 //
 MH3::MH3(const unsigned int dim)
-    : fDimension(dim>3?3:dim), fHist(NULL),
+    : fDimension(dim>3?3:dim), fHist(NULL)/*,
     fNameProfX(Form("ProfX_%p", this)),
-    fNameProfY(Form("ProfY_%p", this))
+    fNameProfY(Form("ProfY_%p", this))*/
 {  
     switch (fDimension)
@@ -205,5 +205,5 @@
 //
 MH3::MH3(const char *memberx, const char *membery)
-    : fDimension(2), fNameProfX(Form("ProjX_%p", this)), fNameProfY(Form("ProjY_%p", this))
+    : fDimension(2)/*, fNameProfX(Form("ProjX_%p", this)), fNameProfY(Form("ProjY_%p", this))*/
 {
     fHist = new TH2F;
@@ -507,14 +507,11 @@
 void MH3::Paint(Option_t *o)
 {
+    /*
+     *fLog << all << fHist << " " << gPad->GetName() << " ----> Paint " << o << endl;
+     TListIter Next(gPad->GetListOfPrimitives()); TObject *obj;
+     while ((obj=Next())) *fLog << obj << " " << obj->GetName() << " " << obj->ClassName() << " " << Next.GetOption() << " " << (int)obj->TestBit(kCanDelete) << endl;
+     */
+    /*
     TString str(o);
-
-    // FIXME: Do it in Paint()
-    /*
-     if (str.Contains("COL", TString::kIgnoreCase))
-    {
-        SetColors();
-        return;
-    }
-    */
 
     if (str.Contains("log", TString::kIgnoreCase))
@@ -536,5 +533,52 @@
         if ((h0 = (TProfile*)gPad->FindObject(fNameProfY)))
             ((TH2*)fHist)->ProfileY(fNameProfY, -1, 9999, "s");
-    }
+            }
+            */
+
+    fHist->SetFillStyle(4000);
+
+    TString str(o);
+    str = str.Strip(TString::kBoth);
+
+    Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2;
+    Bool_t same = str.Contains("SAME", TString::kIgnoreCase) && fDimension==2;
+    Bool_t blue = str.Contains("BLUE", TString::kIgnoreCase) && fDimension==2;
+
+    // FIXME: We may have to remove all our own options from str!
+    if (!only && !gPad->GetListOfPrimitives()->FindObject(fHist))
+        fHist->Draw(str);
+
+    if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2)
+    {
+        TProfile *p = ((TH2*)fHist)->ProfileX("ProfX", -1, 9999, "s");
+        if (!gPad->GetListOfPrimitives()->FindObject(p))
+        {
+            p->UseCurrentStyle();
+            p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
+            p->SetBit(kCanDelete);
+            p->SetDirectory(NULL);
+            p->SetXTitle(fHist->GetXaxis()->GetTitle());
+            p->SetYTitle(fHist->GetYaxis()->GetTitle());
+            p->Draw(only&&!same?"":"same");
+        }
+    }
+    if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2)
+    {
+        TProfile *p = ((TH2*)fHist)->ProfileY("ProfY", -1, 9999, "s");
+        if (!gPad->GetListOfPrimitives()->FindObject(p))
+        {
+            p->UseCurrentStyle();
+            p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
+            p->SetBit(kCanDelete);
+            p->SetDirectory(NULL);
+            p->SetYTitle(fHist->GetXaxis()->GetTitle());
+            p->SetXTitle(fHist->GetYaxis()->GetTitle());
+            p->Draw(only&&!same?"":"same");
+        }
+    }
+
+    if (fHist->TestBit(kIsLogx) && fHist->GetEntries()>0) gPad->SetLogx();
+    if (fHist->TestBit(kIsLogy) && fHist->GetEntries()>0) gPad->SetLogy();
+    if (fHist->TestBit(kIsLogz) && fHist->GetEntries()>0) gPad->SetLogz();
 }
 
@@ -559,5 +603,8 @@
     TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fHist);
     pad->SetBorderMode(0);
-
+    AppendPad(opt);
+
+    return;
+/*
     fHist->SetFillStyle(4000);
 
@@ -597,5 +644,5 @@
     }
 
-    AppendPad("log");
+    AppendPad("log");*/
 }
 
Index: /trunk/MagicSoft/Mars/mhbase/MH3.h
===================================================================
--- /trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 5619)
+++ /trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 5620)
@@ -26,6 +26,6 @@
     Double_t    fScale[3];       // Scale for the three axis (eg unit)
 
-    TString     fNameProfX;      //! This should make sure, that gROOT doen't confuse the profile with something else
-    TString     fNameProfY;      //! This should make sure, that gROOT doen't confuse the profile with something else
+    // TString     fNameProfX;      //! This should make sure, that gROOT doen't confuse the profile with something else
+    // TString     fNameProfY;      //! This should make sure, that gROOT doen't confuse the profile with something else
 
     void StreamPrimitive(ofstream &out) const;
@@ -36,4 +36,7 @@
         kIsLogz = BIT(19)
     };
+
+//    Int_t DistancetoPrimitive(Int_t px, Int_t py);
+//    void  ExecuteEvent(Int_t event, Int_t px, Int_t py);
 
 public:
Index: /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 5619)
+++ /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.cc	(revision 5620)
@@ -107,6 +107,6 @@
 MHEffectiveOnTime::MHEffectiveOnTime(const char *name, const char *title)
     : fPointPos(0), fTime(0), fParam(0), fIsFinalized(kFALSE), 
-    fNumEvents(200*60), fNameProjDeltaT(Form("DeltaT_%p", this)),
-    fNameProjTheta(Form("Theta_%p", this))
+    fNumEvents(200*60)/*, fNameProjDeltaT(Form("DeltaT_%p", this)),
+    fNameProjTheta(Form("Theta_%p", this))*/
 {
     //
@@ -646,4 +646,6 @@
 void MHEffectiveOnTime::Paint(Option_t *opt)
 {
+    *fLog << all << "Paint: '" << opt << "'" << endl;
+
     TH1D *h=0;
     TPaveStats *st=0;
@@ -675,7 +677,7 @@
 
         pad->GetPad(1)->cd(1);
-        if ((h = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
+        if ((h = (TH1D*)gPad->FindObject("ProjDeltaT"/*fNameProjDeltaT*/)))
         {
-            h = fH2DeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
+            h = fH2DeltaT.ProjectionX("ProjDeltaT"/*fNameProjDeltaT*/, -1, 9999, "E");
             if (h->GetEntries()>0)
                 gPad->SetLogy();
@@ -683,6 +685,6 @@
 
         pad->GetPad(2)->cd(1);
-        if ((h = (TH1D*)gPad->FindObject(fNameProjTheta)))
-            fH2DeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
+        if ((h = (TH1D*)gPad->FindObject("ProjTheta"/*fNameProjTheta*/)))
+            fH2DeltaT.ProjectionY("ProjTheta"/*fNameProjTheta*/, -1, 9999, "E");
 
         if (!fIsFinalized)
@@ -692,5 +694,5 @@
     if (o==(TString)"paint")
     {
-        if ((h = (TH1D*)gPad->FindObject(fNameProjDeltaT)))
+        if ((h = (TH1D*)gPad->FindObject("ProjDeltaT"/*fNameProjDeltaT*/)))
         {
             Double_t res[7];
@@ -771,5 +773,5 @@
     pad->GetPad(1)->cd(1);
     gPad->SetBorderMode(0);
-    h = fH2DeltaT.ProjectionX(fNameProjDeltaT, -1, 9999, "E");
+    h = fH2DeltaT.ProjectionX("ProjDeltaT"/*fNameProjDeltaT*/, -1, 9999, "E");
     h->SetTitle("Distribution of \\Delta t [s]");
     h->SetXTitle("\\Delta t [s]");
@@ -801,5 +803,5 @@
     pad->GetPad(2)->cd(1);
     gPad->SetBorderMode(0);
-    h = fH2DeltaT.ProjectionY(fNameProjTheta, -1, 9999, "E");
+    h = fH2DeltaT.ProjectionY("ProjTheta"/*fNameProjTheta*/, -1, 9999, "E");
     h->SetTitle("Distribution of  \\Theta [\\circ]");
     h->SetXTitle("\\Theta [\\circ]");
Index: /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.h	(revision 5619)
+++ /trunk/MagicSoft/Mars/mhflux/MHEffectiveOnTime.h	(revision 5620)
@@ -50,6 +50,6 @@
     Int_t fNumEvents;    // Number of events to be used for a bin in time
 
-    const TString fNameProjDeltaT; //! This should make sure, that gROOT doen't confuse the projection with something else
-    const TString fNameProjTheta;  //! This should make sure, that gROOT doen't confuse the projection with something else
+    //const TString fNameProjDeltaT; //! This should make sure, that gROOT doen't confuse the projection with something else
+    //const TString fNameProjTheta;  //! This should make sure, that gROOT doen't confuse the projection with something else
 
     Bool_t FitH(TH1D *h, Double_t *res, Bool_t paint=kFALSE) const;
Index: /trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc	(revision 5619)
+++ /trunk/MagicSoft/Mars/mhvstime/MHVsTime.cc	(revision 5620)
@@ -83,5 +83,5 @@
 //
 MHVsTime::MHVsTime(const char *rule, const char *error)
-    : fGraph(NULL), fData(NULL), fError(0), fScale(1), fMaxPts(-1),
+    : fGraph(NULL), fData(NULL), fError(NULL), fScale(1), fMaxPts(-1),
     fNumEvents(1), fUseEventNumber(0)
 {
@@ -114,4 +114,7 @@
     if (fData)
         delete fData;
+
+    if (fError)
+        delete fError;
 }
 
@@ -169,5 +172,5 @@
 {
     fGraph->SetName(name);
-    MParContainer::SetName(name);
+    MH::SetName(name);
 }
 
@@ -179,5 +182,5 @@
 {
     fGraph->SetTitle(title);
-    MParContainer::SetTitle(title);
+    MH::SetTitle(title);
 }
 
@@ -247,4 +250,29 @@
 void MHVsTime::Paint(Option_t *opt)
 {
+    /*
+     *fLog << all << fGraph << " " << gPad->GetName() << " ----> Paint " << opt << endl;
+     TListIter Next(gPad->GetListOfPrimitives()); TObject *obj;
+     while ((obj=Next())) *fLog << obj << " " << obj->GetName() << " " << obj->ClassName() << " " << Next.GetOption() << endl;
+     */
+
+    if (!fGraph)
+        return;
+
+//    *fLog << all << fGraph->GetN() << " " << opt << endl;
+
+    if (fGraph->GetN()==0)
+        return;
+
+    TString str(opt);
+    if (!str.Contains("A"))
+        str += "A";
+    if (!str.Contains("P"))
+        str += "P";
+    if (str.Contains("same", TString::kIgnoreCase))
+    {
+        str.ReplaceAll("same", "");
+        str.ReplaceAll("A", "");
+    }
+
     // SetPoint deletes the histogram!
     if (fUseEventNumber)
@@ -264,5 +292,9 @@
     // Otherwise MStatusDisplay::Update hangs.
     gPad->GetListOfPrimitives()->Remove(fGraph);
-    gPad->GetListOfPrimitives()->Add(fGraph, fGraph->GetN()<2 ? "A" : opt);
+    fGraph->Draw(fGraph->GetN()<2 ? "A" : str);
+    //gPad->GetListOfPrimitives()->Add(fGraph, fGraph->GetN()<2 ? "A" : opt);
+    //    AppendPad(str);
+    //    fGraph->Draw(str);
+
 }
 
@@ -275,28 +307,7 @@
 void MHVsTime::Draw(Option_t *opt)
 {
-    if (!fGraph)
-        return;
-
-    if (fGraph->GetN()==0)
-        return;
-
     TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fGraph);
     pad->SetBorderMode(0);
-
-    TString str(opt);
-
-    if (!str.Contains("A"))
-        str += "A";
-    if (!str.Contains("P"))
-        str += "P";
-
-    if (str.Contains("same", TString::kIgnoreCase))
-    {
-        str.ReplaceAll("same", "");
-        str.ReplaceAll("A", "");
-    }
-
-    AppendPad(str);
-    fGraph->Draw(str);
+    AppendPad(opt);
 }
 
