Index: trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 8719)
+++ trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 8888)
@@ -124,7 +124,20 @@
 // Default constructor.
 //
-MH3::MH3(const unsigned int dim)
-    : fDimension(dim>3?3:dim), fHist(NULL), fStyleBits(0)
-{  
+MH3::MH3(const Int_t dim, Type_t type)
+    : fDimension(dim), fHist(NULL), fStyleBits(0)
+{
+    switch (type)
+    {
+    case kHistogram:
+        if (fDimension>3)
+            fDimension=3;
+        break;
+    case kProfile:
+        fDimension = -TMath::Abs(fDimension);
+        if (fDimension<-2)
+            fDimension = -2;
+        break;
+    }
+
     switch (fDimension)
     {
@@ -132,4 +145,8 @@
         fHist = new TH1D;
         fHist->SetYTitle("Counts");
+        break;
+    case -1:
+        fHist = new TProfile;
+        fHist->SetYTitle("Average");
         break;
     case 2:
@@ -137,4 +154,8 @@
         fHist->SetZTitle("Counts");
         break;
+    case -2:
+        fHist = new TProfile2D;
+        fHist->SetZTitle("Average");
+        break;
     case 3:
         fHist = new TH3D;
@@ -194,4 +215,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Adapt a given histogram
+//
 MH3::MH3(const TH1 &h1)
     : fDimension(1), fStyleBits(0)
@@ -237,8 +262,8 @@
 // description above.
 //
-MH3::MH3(const char *memberx, const char *membery)
-    : fDimension(2), fStyleBits(0)
-{
-    fHist = new TH2D;
+MH3::MH3(const char *memberx, const char *membery, Type_t type)
+    : fDimension(type==kHistogram?2:-1), fStyleBits(0)
+{
+    fHist = type==kHistogram ? static_cast<TH1*>(new TH2D) : static_cast<TH1*>(new TProfile); //new TH2D;
 
     fData[0] = new MDataPhrase(memberx);
@@ -255,5 +280,5 @@
     fHist->UseCurrentStyle();
     fHist->SetDirectory(NULL);
-    fHist->SetZTitle("Counts");
+    fHist->SetZTitle(fDimension>0?"Counts":"Average");
 
     fScale[0] = 1;
@@ -268,8 +293,8 @@
 // description see the class description above.
 //
-MH3::MH3(const char *memberx, const char *membery, const char *memberz)
-    : fDimension(3), fStyleBits(0)
-{
-    fHist = new TH3D;
+MH3::MH3(const char *memberx, const char *membery, const char *memberz, Type_t type)
+    : fDimension(type==kHistogram?3:-2), fStyleBits(0)
+{
+    fHist = type==kHistogram ? static_cast<TH1*>(new TH3D) : static_cast<TH1*>(new TProfile2D); //new TH2D;
 
     fData[0] = new MDataPhrase(memberx);
@@ -357,5 +382,5 @@
     MBinning *binsz = NULL;
 
-    switch (fDimension)
+    switch (TMath::Abs(fDimension))
     {
     case 3:
@@ -366,6 +391,4 @@
             return kFALSE;
         }
-        if (fData[2] && !fData[2]->PreProcess(plist))
-            return kFALSE;
         if (fData[2])
             fHist->SetZTitle(fData[2]->GetTitle());
@@ -381,6 +404,4 @@
             return kFALSE;
         }
-        if (fData[1] && !fData[1]->PreProcess(plist))
-            return kFALSE;
         if (fData[1])
             fHist->SetYTitle(fData[1]->GetTitle());
@@ -402,6 +423,4 @@
             }
         }
-        if (fData[0] && !fData[0]->PreProcess(plist))
-            return kFALSE;
         if (fData[0]!=NULL)
             fHist->SetXTitle(fData[0]->GetTitle());
@@ -412,7 +431,13 @@
     }
 
-    TString title("Histogram for ");
+    // PreProcess existing fData members
+    for (int i=0; i<3; i++)
+        if (fData[i] && !fData[i]->PreProcess(plist))
+            return kFALSE;
+
+    TString title(fDimension>0?"Histogram":"Profile");
+    title += " for ";
     title += name;
-    title += Form(" (%dD)", fDimension);
+    title += Form(" (%dD)", TMath::Abs(fDimension));
 
     fHist->SetName(name);
@@ -420,5 +445,5 @@
     fHist->SetDirectory(0);
 
-    switch (fDimension)
+    switch (TMath::Abs(fDimension))
     {
     case 1:
@@ -433,5 +458,5 @@
     }
 
-    *fLog << err << "ERROR - MH3 has " << fDimension << " dimensions!" << endl;
+    *fLog << err << "ERROR - MH3 has " << TMath::Abs(fDimension) << " dimensions!" << endl;
     return kFALSE;
 }
@@ -487,9 +512,11 @@
     switch (fDimension)
     {
-    case 3:
+    case -2:
+    case  3:
         z = fData[2]->GetValue()*fScale[2];
-    case 2:
+    case -1:
+    case  2:
         y = fData[1]->GetValue()*fScale[1];
-    case 1:
+    case  1:
         x = fData[0]->GetValue()*fScale[0];
     }
@@ -497,13 +524,19 @@
     switch (fDimension)
     {
-    case 3:
-        ((TH3*)fHist)->Fill(x, y, z, w);
+    case  3:
+        static_cast<TH3*>(fHist)->Fill(x, y, z, w);
         return kTRUE;
-    case 2:
-        ((TH2*)fHist)->Fill(x, y, w);
+    case  2:
+        static_cast<TH2*>(fHist)->Fill(x, y, w);
         return kTRUE;
     case 1:
         fHist->Fill(x, w);
         return kTRUE;
+    case -1:
+        static_cast<TProfile*>(fHist)->Fill(x, y, w);
+        return kTRUE;
+    case -2:
+        static_cast<TProfile2D*>(fHist)->Fill(x, y, z, w);
+        return kTRUE;
     }
 
@@ -549,5 +582,5 @@
     TProfile *p=0;
 
-    if (fDimension==2)
+    if (TMath::Abs(fDimension)==2)
         MH::SetPalette("pretty");
 
@@ -629,9 +662,9 @@
     str.ToLower();
 
-    const Bool_t only  = str.Contains("only")  && fDimension==2;
-    const Bool_t same  = str.Contains("same")  && fDimension<3;
-    const Bool_t blue  = str.Contains("blue")  && fDimension==2;
-    const Bool_t profx = str.Contains("profx") && fDimension==2;
-    const Bool_t profy = str.Contains("profy") && fDimension==2;
+    const Bool_t only  = str.Contains("only")  && TMath::Abs(fDimension)==2;
+    const Bool_t same  = str.Contains("same")  && TMath::Abs(fDimension)<3;
+    const Bool_t blue  = str.Contains("blue")  && TMath::Abs(fDimension)==2;
+    const Bool_t profx = str.Contains("profx") && TMath::Abs(fDimension)==2;
+    const Bool_t profy = str.Contains("profy") && TMath::Abs(fDimension)==2;
 
     str.ReplaceAll("only",  "");
@@ -641,5 +674,5 @@
     str.ReplaceAll(" ", "");
 
-    if (same && fDimension==1)
+    if (same && TMath::Abs(fDimension)==1)
     {
         fHist->SetLineColor(kBlue);
@@ -702,7 +735,7 @@
     out << "   MH3 " << name << "(\"";
     out << fData[0]->GetRule() << "\"";
-    if (fDimension>1)
+    if (fDimension>1 || fDimension<0)
         out << ", \"" << fData[1]->GetRule() << "\"";
-    if (fDimension>2)
+    if (fDimension>2 || fDimension<-1)
         out << ", \"" << fData[2]->GetRule() << "\"";
 
@@ -717,7 +750,9 @@
     switch (fDimension)
     {
+    case -2:
     case 3:
         if (fScale[2]!=1)
             out << "   " << name << ".SetScaleZ(" << fScale[2] << ");" << endl;
+    case -1:
     case 2:
         if (fScale[1]!=1)
@@ -749,13 +784,21 @@
             h=new MH3(fData[0]->GetRule(), fData[1]->GetRule());
             break;
+        case -1:
+            h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), MH3::kProfile);
+            break;
         case 3:
             h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule());
             break;
+        case -2:
+            h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), MH3::kProfile);
+            break;
         }
     switch (fDimension)
     {
+    case -2:
     case 3:
         h->SetScaleZ(fScale[2]);
     case 2:
+    case -1:
         h->SetScaleY(fScale[1]);
     case 1:
@@ -789,5 +832,5 @@
     Int_t num = 1;
 
-    switch (fDimension)
+    switch (TMath::Abs(fDimension))
     {
     case 3:
@@ -820,8 +863,10 @@
     {
     case 3:
+    case -2:
         binz = axez.FindFixBin(z);
         if (binz>axez.GetLast() || binz<axez.GetFirst())
             return -1;
     case 2:
+    case -1:
         biny = axey.FindFixBin(y);
         if (biny>axey.GetLast() || biny<axey.GetFirst())
Index: trunk/MagicSoft/Mars/mhbase/MH3.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 8719)
+++ trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 8888)
@@ -28,4 +28,6 @@
     Byte_t      fStyleBits;      // Set the range of a histogram automatically in Finalize
 
+//    TH1        *fHistDraw;       //!
+
     void HandleLogAxis(TAxis &axe) const;
 
@@ -39,9 +41,14 @@
 
 public:
-    MH3(const unsigned int dim=0);
+    enum Type_t {
+        kHistogram,
+        kProfile
+    };
+
+    MH3(const Int_t dim=0, Type_t type=MH3::kHistogram);
     MH3(const TH1 &h1);
     MH3(const char *memberx);
-    MH3(const char *memberx, const char *membery);
-    MH3(const char *memberx, const char *membery, const char *memberz);
+    MH3(const char *memberx, const char *membery, Type_t type=MH3::kHistogram);
+    MH3(const char *memberx, const char *membery, const char *memberz, Type_t type=MH3::kHistogram);
     ~MH3();
 
@@ -70,5 +77,5 @@
 
     // Getter
-    Int_t GetDimension() const { return fDimension; }
+    Int_t GetDimension() const { return TMath::Abs(fDimension); }
     Int_t GetNbins() const;
     Int_t FindFixBin(Double_t x, Double_t y=0, Double_t z=0) const;
Index: trunk/MagicSoft/Mars/mhbase/MHn.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 8719)
+++ trunk/MagicSoft/Mars/mhbase/MHn.cc	(revision 8888)
@@ -213,5 +213,5 @@
 //  e.g. AddHist("MHillas.fLength", "MHillas.fSize")
 //
-Bool_t MHn::AddHist(const char *memberx, const char *membery)
+Bool_t MHn::AddHist(const char *memberx, const char *membery, MH3::Type_t type)
 {
     if (fNum==8)
@@ -221,5 +221,5 @@
     }
 
-    fHist[fNum] = new MH3(memberx, membery);
+    fHist[fNum] = new MH3(memberx, membery, type);
 
     InitHist();
@@ -236,5 +236,5 @@
 //  e.g. AddHist("MHillas.fWidth", "MHillas.fLength", "MHillas.fSize")
 //
-Bool_t MHn::AddHist(const char *memberx, const char *membery, const char *memberz)
+Bool_t MHn::AddHist(const char *memberx, const char *membery, const char *memberz, MH3::Type_t type)
 {
     if (fNum==8)
@@ -244,5 +244,5 @@
     }
 
-    fHist[fNum] = new MH3(memberx, membery, memberz);
+    fHist[fNum] = new MH3(memberx, membery, memberz, type);
 
     InitHist();
Index: trunk/MagicSoft/Mars/mhbase/MHn.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHn.h	(revision 8719)
+++ trunk/MagicSoft/Mars/mhbase/MHn.h	(revision 8888)
@@ -2,12 +2,7 @@
 #define MARS_MHn
 
-#ifndef ROOT_TH1
-#include <TH1.h>
+#ifndef MARS_MH3
+#include "MH3.h"
 #endif
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-class MH3;
 
 class MHn : public MH
@@ -39,6 +34,6 @@
 
     Bool_t AddHist(const char *memberx);
-    Bool_t AddHist(const char *memberx, const char *membery);
-    Bool_t AddHist(const char *memberx, const char *membery, const char *memberz);
+    Bool_t AddHist(const char *memberx, const char *membery, MH3::Type_t type=MH3::kHistogram);
+    Bool_t AddHist(const char *memberx, const char *membery, const char *memberz, MH3::Type_t type=MH3::kHistogram);
 
     void InitName(const char *n)
