Index: trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 4920)
+++ trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 4928)
@@ -103,5 +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))
 {  
     switch (fDimension)
@@ -171,5 +173,5 @@
 //
 MH3::MH3(const char *memberx, const char *membery)
-    : fDimension(2)
+    : fDimension(2), fNameProfX(Form("ProjX_%p", this)), fNameProfY(Form("ProjY_%p", this))
 {
     fHist = new TH2F;
@@ -313,5 +315,4 @@
                 return kFALSE;
             }
-
         }
         if (fData[0] && !fData[0]->PreProcess(plist))
@@ -325,28 +326,21 @@
     }
 
-    fHist->SetName(fName);
-    fHist->SetDirectory(0);
-
-    if (fTitle!=gsDefTitle)
-    {
-        fHist->SetTitle(fTitle);
-        return kTRUE;
-    }
-
     TString title("Histogram for ");
     title += fName;
-
-    switch (fDimension)
-    {
-    case 1:
-        fHist->SetTitle(title+" (1D)");
+    title += Form(" (%dD)", fDimension);
+
+    fHist->SetName(fName);
+    fHist->SetTitle(fTitle==gsDefTitle ? title : fTitle);
+    fHist->SetDirectory(0);
+
+    switch (fDimension)
+    {
+    case 1:
         SetBinning(fHist, binsx);
         return kTRUE;
     case 2:
-        fHist->SetTitle(title+" (2D)");
         SetBinning((TH2*)fHist, binsx, binsy);
         return kTRUE;
     case 3:
-        fHist->SetTitle(title+" (3D)");
         SetBinning((TH3*)fHist, binsx, binsy, binsz);
         return kTRUE;
@@ -479,7 +473,55 @@
 }
 
-// --------------------------------------------------------------------------
-//
-// Draw clone of histogram. So that the object can be deleted
+void MH3::Paint(Option_t *o)
+{
+    TString str(o);
+
+    // FIXME: Do it in Paint()
+    if (str.Contains("COL", TString::kIgnoreCase))
+        SetColors();
+
+    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();
+
+    // Set pretty color palette
+    gStyle->SetPalette(1, 0);
+
+    TVirtualPad *padsave = gPad;
+
+    TProfile* h0;
+    if ((h0 = (TProfile*)gPad->FindObject(fNameProfX)))
+    {
+        // Get projection for range
+        TProfile *p = ((TH2*)fHist)->ProfileX(fNameProfX, -1, 9999, "s");
+
+        // Move contents from projection to h3
+        h0->Reset();
+        h0->Add(p);
+        delete p;
+
+        // Set Minimum as minimum value Greater Than 0
+        //h0->SetMinimum(GetMinimumGT(*h0));
+    }
+    if ((h0 = (TProfile*)gPad->FindObject(fNameProfY)))
+    {
+        // Get projection for range
+        TProfile *p = ((TH2*)fHist)->ProfileY(fNameProfY, -1, 9999, "s");
+
+        // Move contents from projection to h3
+        h0->Reset();
+        h0->Add(p);
+        delete p;
+
+        // Set Minimum as minimum value Greater Than 0
+        //h0->SetMinimum(GetMinimumGT(*h0));
+    }
+
+    gPad = padsave;
+}
+
+// --------------------------------------------------------------------------
+//
+// Creates a new canvas and draws the histogram into it.
 //
 // Possible options are:
@@ -491,35 +533,25 @@
 // eg this is set when applying a logarithmic MBinning
 //
-// and the histogram is still visible in the canvas.
-// The cloned object are deleted together with the canvas if the canvas is
-// destroyed. If you want to handle destroying the canvas you can get a
-// pointer to it from this function
-//
-/*
-TObject *MH3::DrawClone(Option_t *opt) const
-{
+// Be careful: The histogram belongs to this object and won't get deleted
+// together with the canvas.
+//
+void MH3::Draw(Option_t *opt)
+{
+    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fHist);
+    pad->SetBorderMode(0);
+
+    fHist->SetFillStyle(4000);
+
     TString str(opt);
-
-    TVirtualPad *c = gPad;
-    if (!str.Contains("nonew", TString::kIgnoreCase))
-    {
-        c = MH::MakeDefCanvas(fHist);
-
-        //
-        // This is necessary to get the expected bahviour of DrawClone
-        //
-        gROOT->SetSelectedPad(NULL);
-    }
-
-    if (str.Contains("COL", TString::kIgnoreCase))
-        SetColors();
+    str = str.Strip(TString::kBoth);
 
     Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2;
+    // FIXME: We may have to remove all our own options from str!
     if (!only)
-        fHist->DrawCopy(opt);
+        fHist->Draw(str);
 
     if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2)
     {
-        TProfile *p = ((TH2*)fHist)->ProfileX("_pfx", -1, 9999, "s");
+        TProfile *p = ((TH2*)fHist)->ProfileX(fNameProfX, -1, 9999, "s");
         p->SetLineColor(kBlue);
         p->Draw(only?"":"same");
@@ -529,121 +561,5 @@
     if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2)
     {
-        TProfile *p = ((TH2*)fHist)->ProfileY("_pfy", -1, 9999, "s");
-        p->SetLineColor(kBlue);
-        p->Draw(only?"":"same");
-        p->SetBit(kCanDelete);
-        p->SetDirectory(NULL);
-    }
-
-    if (fHist->TestBit(kIsLogx)) c->SetLogx();
-    if (fHist->TestBit(kIsLogy)) c->SetLogy();
-    if (fHist->TestBit(kIsLogz)) c->SetLogz();
-
-    c->Modified();
-    c->Update();
-
-    return c;
-}
-*/
-
-/*
-void MH3::Paint(Option_t *opt)
-{
-    if (fHist->TestBit(kIsLogx)) pad->SetLogx();
-    if (fHist->TestBit(kIsLogy)) pad->SetLogy();
-    if (fHist->TestBit(kIsLogz)) pad->SetLogz();
-}
-*/
-
-void MH3::Paint(Option_t *o)
-{
-    TString str(o);
-
-    // FIXME: Do it in Paint()
-    if (str.Contains("COL", TString::kIgnoreCase))
-        SetColors();
-
-    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();
-
-    // Set pretty color palette
-    gStyle->SetPalette(1, 0);
-
-    TVirtualPad *padsave = gPad;
-
-    TProfile* h0;
-    if ((h0 = (TProfile*)gPad->FindObject("_pfx")))
-    {
-        // Get projection for range
-        TProfile *p = ((TH2*)fHist)->ProfileX("_pfx", -1, 9999, "s");
-
-        // Move contents from projection to h3
-        h0->Reset();
-        h0->Add(p);
-        delete p;
-
-        // Set Minimum as minimum value Greater Than 0
-        //h0->SetMinimum(GetMinimumGT(*h0));
-    }
-    if ((h0 = (TProfile*)gPad->FindObject("_pfy")))
-    {
-        // Get projection for range
-        TProfile *p = ((TH2*)fHist)->ProfileY("_pfy", -1, 9999, "s");
-
-        // Move contents from projection to h3
-        h0->Reset();
-        h0->Add(p);
-        delete p;
-
-        // Set Minimum as minimum value Greater Than 0
-        //h0->SetMinimum(GetMinimumGT(*h0));
-    }
-
-    gPad = padsave;
-}
-
-// --------------------------------------------------------------------------
-//
-// Creates a new canvas and draws the histogram into it.
-//
-// Possible options are:
-//   PROFX: Draw a x-profile into the histogram (for 2D histograms only)
-//   PROFY: Draw a y-profile into the histogram (for 2D histograms only)
-//   ONLY:  Draw the profile histogram only (for 2D histograms only)
-//
-// If the kIsLog?-Bit is set the axis is displayed lkogarithmically.
-// eg this is set when applying a logarithmic MBinning
-//
-// Be careful: The histogram belongs to this object and won't get deleted
-// together with the canvas.
-//
-void MH3::Draw(Option_t *opt)
-{
-    TVirtualPad *pad = gPad ? gPad : MakeDefCanvas(fHist);
-    pad->SetBorderMode(0);
-
-    fHist->SetFillStyle(4000);
-
-    TString str(opt);
-    str = str.Strip(TString::kBoth);
-
-
-    Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2;
-    // FIXME: We may have to remove all our own options from str!
-    if (!only)
-        fHist->Draw(str);
-
-    if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2)
-    {
-        TProfile *p = ((TH2*)fHist)->ProfileX("_pfx", -1, 9999, "s");
-        p->SetLineColor(kBlue);
-        p->Draw(only?"":"same");
-        p->SetBit(kCanDelete);
-        p->SetDirectory(NULL);
-    }
-    if (str.Contains("PROFY", TString::kIgnoreCase) && fDimension==2)
-    {
-        TProfile *p = ((TH2*)fHist)->ProfileY("_pfy", -1, 9999, "s");
+        TProfile *p = ((TH2*)fHist)->ProfileY(fNameProfY, -1, 9999, "s");
         p->SetLineColor(kBlue);
         p->Draw(only?"":"same");
