Index: trunk/Mars/mhbase/MH3.cc
===================================================================
--- trunk/Mars/mhbase/MH3.cc	(revision 9851)
+++ trunk/Mars/mhbase/MH3.cc	(revision 9858)
@@ -128,5 +128,5 @@
 //
 //
-// Class Version 3:
+// Class Version 1:
 // ----------------
 //   - MData      *fData[3];
@@ -147,4 +147,8 @@
 //   + TFormula *fConversion
 //
+// Class Version 5:
+// ----------------
+//   + MData      *fWeight;
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MH3.h"
@@ -168,4 +172,5 @@
 #include <TProfile.h>
 #include <TProfile2D.h>
+#include <TProfile3D.h>
 
 #include "MLog.h"
@@ -195,4 +200,9 @@
     fStyleBits = 0;
 
+    fWeight  = NULL;
+
+    fData[0] = NULL;
+    fData[1] = NULL;
+    fData[2] = NULL;
     fData[3] = NULL;
 
@@ -257,15 +267,15 @@
         fHist = new TProfile2D;
         fHist->SetZTitle("Average");
-        if (type==kProfileSpread)
-            static_cast<TProfile2D*>(fHist)->SetErrorOption("s");
+        static_cast<TProfile2D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
         break;
     case 3:
         fHist = new TH3D;
         break;
-    }
-
-    fData[0] = NULL;
-    fData[1] = NULL;
-    fData[2] = NULL;
+    case -3:
+        fHist = new TProfile2D;
+        fHist->SetZTitle("Average");
+        static_cast<TProfile2D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
+        break;
+    }
 
     Init();
@@ -282,9 +292,7 @@
     fHist->SetYTitle("Counts");
 
+    Init();
+
     fData[0] = new MDataPhrase(memberx);
-    fData[1] = NULL;
-    fData[2] = NULL;
-
-    Init();
 }
 
@@ -300,4 +308,9 @@
         fDimension = 2;
 
+    if (h1.InheritsFrom(TProfile3D::Class()))
+    {
+        fDimension = -3;
+        *fLog << warn << "WARNING - MH3::MH3(TH1&) does not support TProfile3D." << endl;
+    }
     if (h1.InheritsFrom(TProfile2D::Class()))
         fDimension = -2;
@@ -307,7 +320,5 @@
     fHist = (TH1*)h1.Clone();
 
-    fData[0] = NULL;
-    fData[1] = NULL;
-    fData[2] = NULL;
+    Init(); // Before without SeUseCurrentStyle!
 
     switch (fDimension)
@@ -322,6 +333,4 @@
         fData[0] = new MDataPhrase(h1.GetXaxis()->GetTitle());
     }
-
-    Init(); // Before without SeUseCurrentStyle!
 }
 
@@ -351,9 +360,8 @@
     fHist->SetZTitle(fDimension>0?"Counts":"Average");
 
+    Init();
+
     fData[0] = new MDataPhrase(memberx);
     fData[1] = new MDataPhrase(membery);
-    fData[2] = NULL;
-
-    Init();
 }
 
@@ -374,13 +382,33 @@
     case -2:
         fHist = static_cast<TH1*>(new TProfile2D);
-        if (type==kProfileSpread)
-            static_cast<TProfile2D*>(fHist)->SetErrorOption("s");
-    }
+        static_cast<TProfile2D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
+    }
+
+    Init();
 
     fData[0] = new MDataPhrase(memberx);
     fData[1] = new MDataPhrase(membery);
     fData[2] = new MDataPhrase(memberz);
+}
+
+// --------------------------------------------------------------------------
+//
+// Creates an TH3D. memberx is filled into the X-bins. membery is filled
+// into the Y-bins. membery is filled into the Z-bins. Weight is used as a
+// weight for the profile histogram. For a more detailed description see the
+// class description above.
+//
+MH3::MH3(const char *memberx, const char *membery, const char *memberz, const char *weight, Type_t type)
+    : fDimension(-3)
+{
+    fHist = static_cast<TH1*>(new TProfile3D);
+    static_cast<TProfile3D*>(fHist)->BuildOptions(0, 0, type==kProfileSpread?"s":"");
 
     Init();
+
+    fData[0] = new MDataPhrase(memberx);
+    fData[1] = new MDataPhrase(membery);
+    fData[2] = new MDataPhrase(memberz);
+    fData[3] = new MDataPhrase(weight);
 }
 
@@ -396,4 +424,7 @@
     if (fConversion)
         delete fConversion;
+
+    if (fWeight)
+        delete fWeight;
 
     for (int i=0; i<4; i++)
@@ -414,7 +445,7 @@
 void MH3::SetWeight(const char *phrase)
 {
-    if (fData[3])
-        delete fData[3];
-    fData[3] = new MDataPhrase(phrase);
+    if (fWeight)
+        delete fWeight;
+    fWeight = new MDataPhrase(phrase);
 }
 
@@ -573,6 +604,7 @@
 Bool_t MH3::SetupFill(const MParList *plist)
 {
-    // reset histogram (necessary if the same eventloop is run more than once) 
-    fHist->Reset();
+    // reset histogram (necessary if the same eventloop is run more than once)
+    if (!TestBit(kDoNotReset))
+        fHist->Reset();
 
     // Tokenize name into name and binnings names
@@ -660,4 +692,7 @@
             return kFALSE;
 
+    if (fWeight && !fWeight->PreProcess(plist))
+        return kFALSE;
+
     TString title(fDimension>0?"Histogram":"Profile");
     title += " for ";
@@ -748,8 +783,11 @@
     Double_t y=0;
     Double_t z=0;
+    Double_t t=0;
     Double_t w=ww;
 
     switch (fDimension)
     {
+    case -3:
+        t = fData[3]->GetValue();
     case -2:
     case  3:
@@ -762,6 +800,6 @@
     }
 
-    if (fData[3])
-        w *= fData[3]->GetValue();
+    if (fData[4])
+        w *= fData[4]->GetValue();
 
     // If label option is set, convert value to label
@@ -862,4 +900,14 @@
         }
         break;
+    case  -3:
+        switch (type)
+        {
+        case kNoLabels:
+            static_cast<TProfile3D*>(fHist)->Fill(x, y, z, t, w);
+            return kTRUE;
+        default:
+            *fLog << err << "ERROR - Labels not supported in TProfile3D." << endl;
+        }
+        break;
     }
 
@@ -1148,9 +1196,12 @@
         out << "   " << name << ".SetTitle(\"" << fTitle << "\");" << endl;
 
-    if (fData[3])
-        out << "   " << name << ".SetWeight(\"" << fData[3]->GetRule() << "\");" << endl;
+    if (fWeight)
+        out << "   " << name << ".SetWeight(\"" << fWeight->GetRule() << "\");" << endl;
 
     switch (fDimension)
     {
+    case -3:
+        if (fScale[3]!=1)
+            out << "   " << name << ".SetScaleT(" << fScale[3] << ");" << endl;
     case -2:
     case 3:
@@ -1175,4 +1226,6 @@
     case -2:
         return TString(static_cast<TProfile2D*>(fHist)->GetErrorOption())=="s" ? kProfileSpread : kProfile;
+    case -3:
+        return TString(static_cast<TProfile3D*>(fHist)->GetErrorOption())=="s" ? kProfileSpread : kProfile;
     }
     return kHistogram;
@@ -1206,4 +1259,7 @@
             h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), GetType());
             break;
+        case -3:
+            h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule(), fData[3]->GetRule());
+            break;
         }
 
@@ -1220,6 +1276,6 @@
     }
 
-    if (fData[3])
-        h->SetWeight(fData[3]->GetRule());
+    if (fData[4])
+        h->SetWeight(fData[4]->GetRule());
 
     return h;
@@ -1243,7 +1299,10 @@
     case 'Z':
         return fData[2] ? fData[2]->GetRule() : TString("");
+    case 't':
+    case 'T':
+        return fData[3] ? fData[3]->GetRule() : TString("");
     case 'w':
     case 'W':
-        return fData[3] ? fData[3]->GetRule() : TString("");
+        return fWeight  ? fWeight->GetRule() : TString("");
     default:
         return "<n/a>";
Index: trunk/Mars/mhbase/MH3.h
===================================================================
--- trunk/Mars/mhbase/MH3.h	(revision 9851)
+++ trunk/Mars/mhbase/MH3.h	(revision 9858)
@@ -37,4 +37,9 @@
     };
 
+    enum {
+        kDoNotReset = BIT(20)
+    };
+
+
 private:
     static const TString gsDefName;
@@ -63,5 +68,6 @@
     Int_t       fDimension;      // Number of dimensions of histogram
     TH1        *fHist;           // Histogram to fill
-    MData      *fData[4];        // Object from which the data is filled (+additional weight)
+    MData      *fData[4];        // Object from which the data is filled
+    MData      *fWeight;         // Additional weight
     MBinning   *fBins[3];        // Binning set omitting the parlist access
     Double_t    fScale[3];       // Scale for the three axis (eg unit)
@@ -76,7 +82,7 @@
 
     enum {
-        kIsLogx = BIT(17),
-        kIsLogy = BIT(18),
-        kIsLogz = BIT(19)
+        kIsLogx     = BIT(17),
+        kIsLogy     = BIT(18),
+        kIsLogz     = BIT(19)
     };
 
@@ -87,4 +93,5 @@
     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(const char *memberx, const char *membery, const char *memberz, const char *weight, Type_t type=MH3::kProfile);
     ~MH3();
 
@@ -171,5 +178,5 @@
     void RecursiveRemove(TObject *obj);
 
-    ClassDef(MH3, 5) // Generalized 1/2/3D-histogram for Mars variables
+    ClassDef(MH3, 6) // Generalized 1/2/3D-histogram for Mars variables
 };
 
Index: trunk/Mars/mhbase/MHn.cc
===================================================================
--- trunk/Mars/mhbase/MHn.cc	(revision 9851)
+++ trunk/Mars/mhbase/MHn.cc	(revision 9858)
@@ -254,4 +254,27 @@
 // --------------------------------------------------------------------------
 //
+// Add a new 3D-MH3 histogram. An internal pointer is set to it, so that
+// InitName and InitTitle can be used for this histogram until a new
+// histogram is added using AddHist
+//
+//  e.g. AddHist("MHillas.fWidth", "MHillas.fLength", "MHillas.fSize", "MWeight.fVal")
+//
+Bool_t MHn::AddHist(const char *memberx, const char *membery, const char *memberz, const char *weight)
+{
+    if (fNum==8)
+    {
+        *fLog << err << "ERROR - MHn doesn't support more than six histograms... AddHist ignored." << endl;
+        return kFALSE;
+    }
+
+    fHist[fNum] = new MH3(memberx, membery, memberz, weight);
+
+    InitHist();
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
 // Set the draw option of the n-th MH3. See MH3 for more details of the
 // meaning of it.
@@ -500,6 +523,10 @@
 {
     for (int i=0; i<fNum; i++)
+    {
+        TestBit(kDoNotReset) ? fHist[i]->SetBit(kDoNotReset) : fHist[i]->ResetBit(kDoNotReset);
+
         if (!fHist[i]->SetupFill(plist))
             return kFALSE;
+    }
 
     return kTRUE;
@@ -581,4 +608,9 @@
             break;
         case 13:  // 3
+            pad->Divide(2,2, 1e-5, 1e-5);
+            pad->GetPad(1)->SetPad(0.01, 0.505, 0.33, 0.99);
+            pad->GetPad(2)->SetPad(0.01, 0.01,  0.33, 0.495);
+            pad->GetPad(3)->SetPad(0.34, 0.01,  0.99, 0.99);
+            delete pad->GetPad(4);
             break;
         case 14:  // 4
Index: trunk/Mars/mhbase/MHn.h
===================================================================
--- trunk/Mars/mhbase/MHn.h	(revision 9851)
+++ trunk/Mars/mhbase/MHn.h	(revision 9858)
@@ -10,4 +10,6 @@
 public:
     enum Layout_t { kSimple, kComplex };
+
+    enum { kDoNotReset = BIT(20) };
 
 protected:
@@ -36,4 +38,5 @@
     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);
+    Bool_t AddHist(const char *memberx, const char *membery, const char *memberz, const char *weight);
 
     void InitName(const char *n)  { InitName(fNum-1, n); }
