Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 5003)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 5007)
@@ -1181,4 +1181,14 @@
     const Int_t size = array.GetSize();
 
+    TH1I *h1=0;
+
+    //check if histogram with identical name exist
+    TObject *h1obj = gROOT->FindObject(name);
+    if (h1obj && h1obj->InheritsFrom("TH1I"))
+    {
+        h1 = (TH1I*)h1obj;
+        h1->Reset();
+    }
+
     Double_t min = size>0 ? array[0] : 0;
     Double_t max = size>0 ? array[0] : 1;
@@ -1193,9 +1203,12 @@
     Int_t newbins = 0;
     FindGoodLimits(nbins, newbins, min, max, kFALSE);
-    
-    TH1I *h1 = new TH1I(name, title, nbins, min, max);
-    h1->SetXTitle("");
-    h1->SetYTitle("Counts");
-    h1->SetDirectory(NULL);
+
+    if (!h1)
+    {
+        h1 = new TH1I(name, title, nbins, min, max);
+        h1->SetXTitle("");
+        h1->SetYTitle("Counts");
+        h1->SetDirectory(gROOT);
+    }
 
     // Second loop to fill the histogram
@@ -1217,4 +1230,14 @@
     Double_t max = size>0 ? array[0] : 1;
 
+    TH1I *h1=0;
+
+    //check if histogram with identical name exist
+    TObject *h1obj = gROOT->FindObject(name);
+    if (h1obj && h1obj->InheritsFrom("TH1I"))
+    {
+        h1 = (TH1I*)h1obj;
+        h1->Reset();
+    }
+
     // first loop over array to find the min and max
     for (Int_t i=1; i<size;i++)
@@ -1227,9 +1250,12 @@
     FindGoodLimits(nbins, newbins, min, max, kFALSE);
 
-    TH1I *h1 = new TH1I(name, title, newbins, min, max);
-    h1->SetXTitle("");
-    h1->SetYTitle("Counts");
-    h1->SetDirectory(NULL);
-
+    if (!h1)
+    {
+      h1 = new TH1I(name, title, newbins, min, max);
+      h1->SetXTitle("");
+      h1->SetYTitle("Counts");
+      h1->SetDirectory(gROOT);
+    }
+    
     // Second loop to fill the histogram
     for (Int_t i=0;i<size;i++)
@@ -1246,6 +1272,5 @@
                        const char* name, const char* title)
 {
-    const TArrayF arr(array.GetSize(), array.GetArray());
-    return ProjectArray(arr, nbins, name, title);
+    return ProjectArray(TArrayF(array.GetSize(),array.GetArray()), nbins, name, title);
 }
 
@@ -1256,6 +1281,5 @@
 TH1I* MH::ProjectArray(const MArrayD &array, Int_t nbins, const char* name, const char* title)
 {
-    const TArrayD arr(array.GetSize(), array.GetArray());
-    return ProjectArray(arr, nbins, name, title);
+    return ProjectArray(TArrayD(array.GetSize(),array.GetArray()), nbins, name, title);
 }
 
