Index: trunk/MagicSoft/Mars/mhist/MHGamma.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHGamma.cc	(revision 1422)
+++ trunk/MagicSoft/Mars/mhist/MHGamma.cc	(revision 1668)
@@ -38,8 +38,9 @@
 #include <math.h>
 
-#include <TH1.h>
 #include <TH2.h>
 #include <TH3.h>
 
+#include "MHAlphaEnergyTheta.h"
+
 #include "MLog.h"
 #include "MLogManip.h"
@@ -52,6 +53,9 @@
 // Default Constructor. 
 //
-MHGamma::MHGamma()
-{
+MHGamma::MHGamma(const TString &name, const TString &title)
+    : fHist(NULL), fProject(NULL)
+{
+    fName  = name.IsNull()  ? (TString)"MHGamma" : name;
+    fTitle = title.IsNull() ? (TString)"3D-histogram of Alpha, E_est, Theta (Gamma sample)" : title;
 }
 
@@ -64,4 +68,87 @@
   return kTRUE;
 }
+
+TH3D *MHGamma::Subtract(const MHAlphaEnergyTheta &h1, const MHAlphaEnergyTheta &h2)
+{
+    return Subtract(h1.GetHist(), h2.GetHist());
+}
+
+TObject *MHGamma::DrawClone(Option_t *opt="") const
+{
+    DrawClone1();
+    DrawClone2();
+
+    return NULL;
+}
+
+void MHGamma::DrawClone1() const
+{
+    if (!fHist)
+        return;
+
+    //
+    // ------------- Part 1 ---------------------
+    //
+    TString titlex = fHist->GetXaxis()->GetTitle();
+    TString titley = fHist->GetYaxis()->GetTitle();
+    TString titlez = fHist->GetYaxis()->GetTitle();
+
+    TString canvtitle = "3D-plot "; //of ";
+    /*
+     canvtitle += titlex;
+     canvtitle += ", ";
+     canvtitle += titley;
+     canvtitle += ", ";
+     canvtitle += titlez+" ";
+     */
+    canvtitle += "for \'gamma\' sample";
+
+    TCanvas &c = *MakeDefCanvas("Alpha", canvtitle);
+
+    c.Divide(2, 2);
+
+    gROOT->SetSelectedPad(NULL);
+
+    TH1 *h;
+
+    c.cd(1);
+    h = ((TH3D*)(fHist))->Project3D(fName+"_ex");
+
+    TString title= "Source-Antisource: ";
+    h->SetTitle(title + titlex);
+    h->SetXTitle(titlex);
+    h->SetYTitle("Counts");
+
+    h->Draw();
+    h->SetBit(kCanDelete);
+
+    c.cd(2);
+    h = ((TH3D*)(fHist))->Project3D(fName+"_ey");
+
+    h->SetTitle(title + titley);
+    h->SetXTitle(titley);
+    h->SetYTitle("Counts");
+
+    h->Draw();
+    h->SetBit(kCanDelete);
+    gPad->SetLogx();
+
+    c.cd(3);
+    h = ((TH3D*)(fHist))->Project3D(fName+"_ez");
+
+    h->SetTitle(title + titlez);
+    h->SetXTitle(titlez);
+    h->SetYTitle("Counts");
+
+    h->Draw();
+    h->SetBit(kCanDelete);
+
+    c.cd(4);
+    ((TH3D*)fHist)->DrawCopy();
+
+    c.Modified();
+    c.Update();
+}
+
 
 // --------------------------------------------------------------------------
@@ -70,88 +157,21 @@
 //          fHist(gamma) = h1(source) - h2(antisource)
 // 
-TH3D *MHGamma::Subtract(const TH3D *h1, const TH3D *h2,
-                        const char *name, const char *title,
-                        Bool_t Draw)
-{
-    TH3D *fHist;
-    fHist = new TH3D();
-    fHist->SetName(name);
-    fHist->SetTitle(title);
-
+TH3D *MHGamma::Subtract(const TH3D *h1, const TH3D *h2)
+{
+    if (fHist)
+        delete fHist;
+
+    fHist = new TH3D;
+    fHist->SetName(fName);
+    fHist->SetTitle(fTitle);
     fHist->SetDirectory(NULL);
 
-    // SetBinning((TH3D*)fHist, (TH3D*)h1);
     SetBinning((TH1*)fHist, (TH1*)h1);
 
-    TString strg1 =   (((TH1*)h1)->GetXaxis())->GetTitle();
-    TString strg2 =   (((TH1*)h1)->GetYaxis())->GetTitle();
-    TString strg3 =   (((TH1*)h1)->GetZaxis())->GetTitle();
-    fHist->SetXTitle(strg1);
-    fHist->SetYTitle(strg2);
-    fHist->SetZTitle(strg3);
+    fHist->SetXTitle((((TH1*)h1)->GetXaxis())->GetTitle());
+    fHist->SetYTitle((((TH1*)h1)->GetYaxis())->GetTitle());
+    fHist->SetZTitle((((TH1*)h1)->GetZaxis())->GetTitle());
 
     fHist->Add((TH1*)h1, (TH1*)h2, 1, -1); // ROOT: FIXME!
-
-    //...........................................................
-    // draw histogram
-    if (Draw == kTRUE)
-    {
-      TString strg7 = "3D-plot of ";
-      strg7 += strg1;
-      strg7 += ",";
-      strg7 += strg2;
-      strg7 += ",";
-      strg7 += strg3;
-      strg7 += "  for \'gamma\' sample";
-
-      TCanvas &c = *MakeDefCanvas("Alpha", strg7); 
-
-      c.Divide(2, 2);
-
-      gROOT->SetSelectedPad(NULL);
-
-      TH1 *h;
-
-      c.cd(1);
-      h = ((TH3D*)(fHist))->Project3D("ex");
-
-      TString strg0 = "SRC-ASRC :    ";
-      TString strg4 = strg0 + strg1;
-      h->SetTitle(strg4);
-      h->SetXTitle(strg1);
-      h->SetYTitle("Counts");
-
-      h->Draw();
-      h->SetBit(kCanDelete);
-
-      c.cd(2);
-      h = ((TH3D*)(fHist))->Project3D("ey");
-
-      TString strg5 = strg0 + strg2;
-      h->SetTitle(strg5);
-      h->SetXTitle(strg2);
-      h->SetYTitle("Counts");
-
-      h->Draw();
-      h->SetBit(kCanDelete);
-      gPad->SetLogx();
-
-      c.cd(3);
-      h = ((TH3D*)(fHist))->Project3D("ez");
-
-      TString strg6 = strg0 + strg3;
-      h->SetTitle(strg6);
-      h->SetXTitle(strg3);
-      h->SetYTitle("Counts");
-
-      h->Draw();
-      h->SetBit(kCanDelete);
-
-      c.cd(4);
-      ((TH3D*)fHist)->DrawCopy();
-
-      c.Modified();
-      c.Update();
-    }
 
     return fHist;
@@ -162,6 +182,5 @@
 // Integrate fHist(gamma) in the alpha range (lo, up)
 // 
-TH2D *MHGamma::GetAlphaProjection(TH3D *fHist, Axis_t lo, Axis_t up,
-                                  Bool_t Drawp)
+TH2D *MHGamma::GetAlphaProjection(Axis_t lo, Axis_t up)
 {
     if (up < lo)
@@ -204,69 +223,72 @@
     axe.SetRange(ilo, iup);
 
-    TH2D &h2D = *(TH2D *)fHist->Project3D("ezy");
-
-    TString strg0 = "2D-plot of ";
-    TString strg1 = (fHist->GetYaxis())->GetTitle();
-    TString strg2 = (fHist->GetZaxis())->GetTitle();
-    strg0 += strg2;
-    strg0 += " vs. ";
-    strg0 += strg1;
-    h2D.SetTitle(strg0);
-    h2D.SetXTitle(strg1);
-    h2D.SetYTitle(strg2);
-
-
-    //...........................................................
-    // draw histogram
-    if (Drawp == kTRUE)
-    {
-      char txt[100];
-      TString strg3 = "No.of Gammas vs. ";
-      strg3 += strg1;
-      strg3 += " and ";
-      strg3 += strg2;
-      sprintf(txt, "   (%.1f < alpha < %.1f deg)", lo, up);
-      strg3 += txt;
-
-      TCanvas &c = *MakeDefCanvas("Gamma", strg3);
-
-      c.Divide(2, 2);
-
-      gROOT->SetSelectedPad(NULL);
-
-      TH1 *h;
-
-      c.cd(1);
-      h = h2D.ProjectionX("xpro", -1, 9999, "E");
-      TString strg0 = "No.of gammas : ";
-      TString strg7 = strg0 + strg1;
-      h->SetTitle(strg7);
-      h->SetXTitle(strg1);
-      h->SetYTitle("Counts");
-
-      h->Draw();
-      h->SetBit(kCanDelete);
-      gPad->SetLogx();
-
-      c.cd(2);
-      h = h2D.ProjectionY("ypro", -1, 9999, "E");
-      TString strg8 = strg0 + strg2;
-      h->SetTitle(strg8);
-      h->SetXTitle(strg2);
-      h->SetYTitle("Counts");
-
-      h->Draw();
-      h->SetBit(kCanDelete);
-
-      c.cd(3);
-
-      h2D.DrawCopy();
-      gPad->SetLogx();
-
-      c.Modified();
-      c.Update();
-    }
-    //...........................................................
-
-    return &h2D;
-}
+    fLo = lo;
+    fHi = up;
+
+    if (fProject)
+        delete fProject;
+    fProject = (TH2D*)fHist->Project3D(fName+"_ezy");
+
+    const TString title = "2D-plot of ";
+    const TString titley = fHist->GetYaxis()->GetTitle();
+    const TString titlez = fHist->GetZaxis()->GetTitle();
+
+    fProject->SetTitle(title + titley + " vs. " + titlez);
+    fProject->SetXTitle(titley);
+    fProject->SetYTitle(titlez);
+
+    return fProject;
+}
+
+void MHGamma::DrawClone2() const
+{
+    if (!fProject)
+        return;
+
+    const TString titley = fHist->GetYaxis()->GetTitle();
+    const TString titlez = fHist->GetZaxis()->GetTitle();
+
+    TString canvtitle = "No.of Gammas ";//vs. ";
+    /*
+     canvtitle += titley;
+     canvtitle += " and ";
+     canvtitle += titlez;
+     */
+    canvtitle += Form("(%.1f < alpha < %.1f deg)", fLo, fHi);
+
+    TCanvas &c = *MakeDefCanvas("Gamma", canvtitle);
+
+    c.Divide(2, 2);
+
+    gROOT->SetSelectedPad(NULL);
+
+    TH1 *h;
+
+    c.cd(1);
+    h = fProject->ProjectionX(fName+"_xpro", -1, 9999, "E");
+    TString title = "No.of gammas: ";
+    h->SetTitle(title+titley);
+    h->SetXTitle(titley);
+    h->SetYTitle("Counts");
+
+    h->Draw();
+    h->SetBit(kCanDelete);
+    gPad->SetLogx();
+
+    c.cd(2);
+    h = fProject->ProjectionY(fName+"_ypro", -1, 9999, "E");
+    h->SetTitle(title+titlez);
+    h->SetXTitle(titlez);
+    h->SetYTitle("Counts");
+
+    h->Draw();
+    h->SetBit(kCanDelete);
+
+    c.cd(3);
+
+    fProject->DrawCopy();
+    gPad->SetLogx();
+
+    c.Modified();
+    c.Update();
+}
