Index: trunk/MagicSoft/Mars/mhbase/HBaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/HBaseLinkDef.h	(revision 8679)
+++ trunk/MagicSoft/Mars/mhbase/HBaseLinkDef.h	(revision 8695)
@@ -9,4 +9,5 @@
 #pragma link C++ class MH+;
 #pragma link C++ class MH3+;
+#pragma link C++ class MHn+;
 #pragma link C++ class MHArray+;
 #pragma link C++ class MHMatrix+;
Index: trunk/MagicSoft/Mars/mhbase/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 8679)
+++ trunk/MagicSoft/Mars/mhbase/MH3.cc	(revision 8695)
@@ -54,7 +54,7 @@
 // If the binning should have a different name than the histogram name
 // the binning name can be added to the name, eg.:
-//    SetName("MyHistName;MyBinning")
+//    SetName("MyHistName;MyXBins;MyYBins")
 // Instead of BinningMyHistName[XYZ] the parameter list will be searched
-// for BinningMyBinning[XYZ].
+// for BinningMyXBinning, BinningMyYBins and BinningMyHistNameZ
 //
 //
@@ -86,4 +86,7 @@
 //   + MData      *fData[3];        // Object from which the data is filled
 //
+// Class Version 3:
+// ----------------
+//   - Byte_t fStyleBits
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -93,5 +96,5 @@
 #include <fstream>
 
-#include <TPad.h>
+//#include <TPad.h>
 #include <TStyle.h>
 #include <TCanvas.h>
@@ -121,5 +124,5 @@
 //
 MH3::MH3(const unsigned int dim)
-    : fDimension(dim>3?3:dim), fHist(NULL)
+    : fDimension(dim>3?3:dim), fHist(NULL), fStyleBits(0)
 {  
     switch (fDimension)
@@ -162,5 +165,5 @@
 //
 MH3::MH3(const char *memberx)
-    : fDimension(1)
+    : fDimension(1), fStyleBits(0)
 {
     fHist = new TH1D;
@@ -182,5 +185,6 @@
 }
 
-MH3::MH3(const TH1 &h1) : fDimension(1)
+MH3::MH3(const TH1 &h1)
+    : fDimension(1), fStyleBits(0)
 {
     if (h1.InheritsFrom(TH3::Class()))
@@ -221,5 +225,5 @@
 //
 MH3::MH3(const char *memberx, const char *membery)
-    : fDimension(2)
+    : fDimension(2), fStyleBits(0)
 {
     fHist = new TH2D;
@@ -248,5 +252,5 @@
 //
 MH3::MH3(const char *memberx, const char *membery, const char *memberz)
-    : fDimension(3)
+    : fDimension(3), fStyleBits(0)
 {
     fHist = new TH3D;
@@ -312,11 +316,19 @@
     fHist->Reset();
 
-    const Int_t split = fName.First(';');
-
-    const TString name = split<0 ? fName : fName(0, split);
-    const TString bins = split<0 ? fName : fName(split+1, fName.Length());
-
-    TString bname("Binning");
-    bname += bins;
+    // Tokenize name into name and binnings names
+    TObjArray *tok = fName.Tokenize(";");
+
+    const TString name = (*tok)[0] ? (*tok)[0]->GetName() : fName.Data();
+
+    TString bx = (*tok)[1] ? (*tok)[1]->GetName() : Form("%sX", name.Data());
+    TString by = (*tok)[2] ? (*tok)[2]->GetName() : Form("%sY", name.Data());
+    TString bz = (*tok)[3] ? (*tok)[3]->GetName() : Form("%sZ", name.Data());
+
+    bx.Prepend("Binning");
+    by.Prepend("Binning");
+    bz.Prepend("Binning");
+
+    delete tok;
+
 
     MBinning *binsx = NULL;
@@ -327,8 +339,8 @@
     {
     case 3:
-        binsz = (MBinning*)plist->FindObject(bname+"Z", "MBinning");
+        binsz = (MBinning*)plist->FindObject(bz, "MBinning");
         if (!binsz)
         {
-            *fLog << err << dbginf << "MBinning '" << bname << "X' not found... aborting." << endl;
+            *fLog << err << dbginf << "MBinning '" << bz << "' not found... aborting." << endl;
             return kFALSE;
         }
@@ -342,8 +354,8 @@
             fHist->SetBit(kIsLogz);
     case 2:
-        binsy = (MBinning*)plist->FindObject(bname+"Y", "MBinning");
+        binsy = (MBinning*)plist->FindObject(by, "MBinning");
         if (!binsy)
         {
-            *fLog << err << dbginf << "MBinning '" << bname << "Y' not found... aborting." << endl;
+            *fLog << err << dbginf << "MBinning '" << by << "' not found... aborting." << endl;
             return kFALSE;
         }
@@ -357,13 +369,13 @@
             fHist->SetBit(kIsLogy);
     case 1:
-        binsx = (MBinning*)plist->FindObject(bname+"X", "MBinning");
+        binsx = (MBinning*)plist->FindObject(bx, "MBinning");
         if (!binsx)
         {
             if (fDimension==1)
-                binsx = (MBinning*)plist->FindObject(bname, "MBinning");
+                binsx = (MBinning*)plist->FindObject("Binning"+fName, "MBinning");
 
             if (!binsx)
             {
-                *fLog << err << dbginf << "Neither MBinning '" << bname << "X' nor '" << bname << "' found... aborting." << endl;
+                *fLog << err << dbginf << "Neither '" << bx << "' nor '" << binsx << fName << "' found... aborting." << endl;
                 return kFALSE;
             }
@@ -477,52 +489,40 @@
     return kFALSE;
 }
-/*
-// --------------------------------------------------------------------------
-//
-// Set the palette you wanna use:
-//  - you could set the root "Pretty Palette Violet->Red" by
-//    gStyle->SetPalette(1, 0), but in some cases this may look
-//    confusing
-//  - The maximum colors root allowes us to set by ourself
-//    is 50 (idx: 51-100). This colors are set to a grayscaled
-//    palette
-//  - the number of contours must be two less than the number
-//    of palette entries
-//
-void MHStarMap::PrepareDrawing() const
-{
-    const Int_t numg = 32; // number of gray scaled colors
-    const Int_t numw = 32; // number of white
-
-    Int_t palette[numg+numw];
-
-    //
-    // The first half of the colors are white.
-    // This is some kind of optical background supression
-    //
-    gROOT->GetColor(51)->SetRGB(1, 1, 1);
-
-    Int_t i;
-    for (i=0; i<numw; i++)
-        palette[i] = 51;
-
-    //
-    // now the (gray) scaled part is coming
-    //
-    for (;i<numw+numg; i++)
-    {
-        const Float_t gray = 1.0-(float)(i-numw)/(numg-1.0);
-
-        gROOT->GetColor(52+i)->SetRGB(gray, gray, gray);
-        palette[i] = 52+i;
-    }
-
-    //
-    // Set the palette and the number of contour levels
-    //
-    gStyle->SetPalette(numg+numw, palette);
-    fStarMap->SetContour(numg+numw-2);
-}
-*/
+
+// --------------------------------------------------------------------------
+//
+// If an auto range bit is set the histogram range of the corresponding
+// axis is set to show only the non-empty bins (with a single empty bin
+// on both sides)
+//
+Bool_t MH3::Finalize()
+{
+    Bool_t autorangex=TESTBIT(fStyleBits, 0);
+    Bool_t autorangey=TESTBIT(fStyleBits, 1);
+    //Bool_t autorangez=TESTBIT(fStyleBits, 2);
+
+    Int_t lo, hi;
+
+    if (autorangex)
+    {
+        GetRangeX(*fHist, lo, hi);
+        cout << "====> " << GetName() << " " << fHist->GetName() << ": " << lo << " " << hi <<" " << fHist->GetNbinsX() <<  endl;
+        fHist->GetXaxis()->SetRange(lo-2, hi+1);
+    }
+    if (autorangey)
+    {
+        GetRangeY(*fHist, lo, hi);
+        fHist->GetYaxis()->SetRange(lo-2, hi+1);
+    }
+    /*
+    if (autorangez)
+    {
+        GetRangeZ(*fHist, lo, hi);
+        fHist->GetZaxis()->SetRange(lo-2, hi+1);
+    }
+    */
+    return kTRUE;
+}
+
 // --------------------------------------------------------------------------
 //
@@ -547,5 +547,5 @@
     {
         Int_t col = p->GetLineColor();
-        p = ((TH2*)fHist)->ProfileX(pfx, -1, 9999, "s");
+        p = ((TH2*)fHist)->ProfileX(pfx, -1, -1, "s");
         p->SetLineColor(col);
     }
@@ -555,11 +555,12 @@
     {
         Int_t col = p->GetLineColor();
-        p = ((TH2*)fHist)->ProfileY(pfy, -1, 9999, "s");
+        p = ((TH2*)fHist)->ProfileY(pfy, -1, -1, "s");
         p->SetLineColor(col);
     }
-
+/*
     if (fHist->TestBit(kIsLogx) && fHist->GetEntries()>0) gPad->SetLogx();
     if (fHist->TestBit(kIsLogy) && fHist->GetEntries()>0) gPad->SetLogy();
     if (fHist->TestBit(kIsLogz) && fHist->GetEntries()>0) gPad->SetLogz();
+    */
 }
 
@@ -587,4 +588,8 @@
     pad->SetGridy();
 
+    if (fHist->TestBit(kIsLogx)) pad->SetLogx();
+    if (fHist->TestBit(kIsLogy)) pad->SetLogy();
+    if (fHist->TestBit(kIsLogz)) pad->SetLogz();
+
     fHist->SetFillStyle(4000);
 
@@ -624,5 +629,5 @@
             *fLog << warn << "TProfile " << pfx << " already in pad." << endl;
 
-        p = ((TH2*)fHist)->ProfileX(pfx, -1, 9999, "s");
+        p = ((TH2*)fHist)->ProfileX(pfx, -1, -1, "s");
         p->UseCurrentStyle();
         p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
@@ -640,5 +645,5 @@
             *fLog << warn << "TProfile " << pfy << " already in pad." << endl;
 
-        p = ((TH2*)fHist)->ProfileY(pfy, -1, 9999, "s");
+        p = ((TH2*)fHist)->ProfileY(pfy, -1, -1, "s");
         p->UseCurrentStyle();
         p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
Index: trunk/MagicSoft/Mars/mhbase/MH3.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 8679)
+++ trunk/MagicSoft/Mars/mhbase/MH3.h	(revision 8695)
@@ -10,5 +10,4 @@
 
 class TH1;
-class TMethodCall;
 class MData;
 
@@ -25,4 +24,5 @@
     MData      *fData[3];        // Object from which the data is filled
     Double_t    fScale[3];       // Scale for the three axis (eg unit)
+    Byte_t      fStyleBits;      // Set the range of a histogram automatically in Finalize
 
     void StreamPrimitive(ostream &out) const;
@@ -46,8 +46,15 @@
     void SetScaleY(Double_t scale) { fScale[1] = scale; }
     void SetScaleZ(Double_t scale) { fScale[2] = scale; }
+    void SetScale(Double_t x, Double_t y=1, Double_t z=2) { SetScaleX(x); SetScaleY(y); SetScaleZ(z); }
 
     void SetLogx(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogx) : fHist->ResetBit(kIsLogx); }
     void SetLogy(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogy) : fHist->ResetBit(kIsLogy); }
     void SetLogz(Bool_t b=kTRUE) { b ? fHist->SetBit(kIsLogz) : fHist->ResetBit(kIsLogz); }
+    void SetLog(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetLogx(x); SetLogy(y); SetLogz(z); }
+
+    void SetAutoRangeX(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 0) : CLRBIT(fStyleBits, 0); }
+    void SetAutoRangeY(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 1) : CLRBIT(fStyleBits, 1); }
+    void SetAutoRangeZ(Bool_t b=kTRUE) { b ? SETBIT(fStyleBits, 2) : CLRBIT(fStyleBits, 2); }
+    void SetAutoRange(Bool_t x=kTRUE, Bool_t y=kTRUE, Bool_t z=kTRUE) { SetAutoRangeX(x); SetAutoRangeY(y); SetAutoRangeZ(z); }
 
     void Sumw2() const { if (fHist) fHist->Sumw2(); }
@@ -67,4 +74,5 @@
     Bool_t SetupFill(const MParList *pList);
     Bool_t Fill(const MParContainer *par, const Stat_t w=1);
+    Bool_t Finalize();
 
     TH1 *GetHistByName(const TString name="") const { return fHist; }
@@ -86,5 +94,5 @@
     void Paint(Option_t *opt="");
 
-    ClassDef(MH3, 2) // Generalized 1/2/3D-histogram for Mars variables
+    ClassDef(MH3, 3) // Generalized 1/2/3D-histogram for Mars variables
 };
 
Index: trunk/MagicSoft/Mars/mhbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhbase/Makefile	(revision 8679)
+++ trunk/MagicSoft/Mars/mhbase/Makefile	(revision 8695)
@@ -25,4 +25,5 @@
            MH.cc \
            MH3.cc \
+	   MHn.cc \
            MHArray.cc \
            MHMatrix.cc
