Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 2858)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 3081)
@@ -1081,2 +1081,86 @@
     return NULL;
 }
+
+TH1I* MH::ProjectArray(const TArrayF *array, Int_t nbins, const char* name, const char* title)
+{
+
+  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 max = 0.;
+  Double_t min = 0.;
+  Int_t newbins = 0;
+
+  // first loop over array to find the maximum:
+  for (Int_t i=0; i<size;i++)
+    if (array->At(i) > max)
+      max = array->At(i);
+
+  FindGoodLimits(nbins, newbins, min, max, kFALSE);
+
+  if (!h1)
+    {
+      h1 = new TH1I(name, title, newbins, min, max);
+      h1->SetXTitle("");
+      h1->SetYTitle("Counts");
+      h1->SetDirectory(NULL);
+    }
+  
+    // Second loop to fill the histogram
+    for (Int_t i=0;i<size;i++) 
+      h1->Fill(array->At(i));
+
+    h1->SetEntries(size);
+    
+    return h1;
+}
+
+TH1I* MH::ProjectArray(const TArrayD *array, Int_t nbins, const char* name, const char* title)
+{
+
+  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 max = 0.;
+  Double_t min = 0.;
+  Int_t newbins = 0;
+
+  // first loop over array to find the maximum:
+  for (Int_t i=0; i<size;i++)
+    if (array->At(i) > max)
+      max = array->At(i);
+
+  FindGoodLimits( nbins, newbins, min, max, kFALSE);
+
+  if (!h1)
+    {
+      h1 = new TH1I(name, title, newbins, min, max);
+      h1->SetXTitle("");
+      h1->SetYTitle("Counts");
+      h1->SetDirectory(NULL);
+    }
+  
+    // Second loop to fill the histogram
+    for (Int_t i=0;i<size;i++) 
+      h1->Fill(array->At(i));
+
+    h1->SetEntries(size);
+    
+    return h1;
+}
+
Index: trunk/MagicSoft/Mars/mhbase/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.h	(revision 2858)
+++ trunk/MagicSoft/Mars/mhbase/MH.h	(revision 3081)
@@ -7,8 +7,10 @@
 
 class TH1;
+class TH1I;
 class TH1D;
 class TH2;
 class TH3;
 class TAxis;
+class TArrayF;
 class TArrayD;
 class TCanvas;
@@ -89,4 +91,9 @@
     static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0);
     static Int_t CutEdges(TH1 *h, Int_t nbins);
+
+    static TH1I* ProjectArray(const TArrayF *array, Int_t nbins=30, const char* name="ProjectArray",
+                                                              const char* title="Projected Array");
+    static TH1I* ProjectArray(const TArrayD *array, Int_t nbins=30, const char* name="ProjectArray",
+                                                              const char* title="Projected Array");
     
     static void ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin=-1, Int_t lastybin=9999);
