Index: trunk/Mars/Changelog
===================================================================
--- trunk/Mars/Changelog	(revision 9820)
+++ trunk/Mars/Changelog	(revision 9821)
@@ -25,4 +25,13 @@
        from float to int)
 
+   * mhbase/MHn.[h,cc]:
+     - added SetConversion to allow for setting a conversion function
+
+   * mhbase/MH3.[h,cc]:
+     - added conversion function for displaying the histogram
+     - added new data member fConversion
+     - added new member functions Convert and SetConversion
+     - implemented conversion before displaying
+
 
 
Index: trunk/Mars/mhbase/MH3.cc
===================================================================
--- trunk/Mars/mhbase/MH3.cc	(revision 9820)
+++ trunk/Mars/mhbase/MH3.cc	(revision 9821)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz  2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2008
+!   Copyright: MAGIC Software Development, 2000-2010
 !
 !
@@ -143,4 +143,8 @@
 //   + MBinning fBins[3]
 //
+// Class Version 5:
+// ----------------
+//   + TFormula *fConversion
+//
 /////////////////////////////////////////////////////////////////////////////
 #include "MH3.h"
@@ -151,4 +155,5 @@
 
 #include <TMath.h>
+#include <TFormula.h>
 
 #include <THashList.h>
@@ -200,4 +205,6 @@
     fScale[2] = 1;
 
+    fConversion = NULL;
+
     fName  = gsDefName;
     fTitle = gsDefTitle;
@@ -239,4 +246,5 @@
         fHist = new TProfile;
         fHist->SetYTitle("Average");
+        static_cast<TProfile*>(fHist)->SetErrorOption("s");
         break;
     case 2:
@@ -247,4 +255,5 @@
         fHist = new TProfile2D;
         fHist->SetZTitle("Average");
+        static_cast<TProfile2D*>(fHist)->SetErrorOption("s");
         break;
     case 3:
@@ -331,4 +340,6 @@
     case -1:
         fHist = static_cast<TH1*>(new TProfile);
+        static_cast<TProfile*>(fHist)->SetErrorOption("s");
+
         break;
     }
@@ -352,5 +363,12 @@
     : fDimension(type==kHistogram?3:-2)
 {
-    fHist = type&kProfile ? static_cast<TH1*>(new TProfile2D) : static_cast<TH1*>(new TH3D);
+    if (type&kProfile)
+    {
+        fHist = static_cast<TH1*>(new TProfile2D);
+        static_cast<TProfile2D*>(fHist)->SetErrorOption("s");
+    }
+    else
+        fHist = static_cast<TH1*>(new TH3D);
+
 
     fData[0] = new MDataPhrase(memberx);
@@ -370,4 +388,7 @@
         delete fHist;
 
+    if (fConversion)
+        delete fConversion;
+
     for (int i=0; i<4; i++)
         if (fData[i])
@@ -390,4 +411,37 @@
         delete fData[3];
     fData[3] = new MDataPhrase(phrase);
+}
+
+// --------------------------------------------------------------------------
+//
+// Set a function which is applied to the histogram before it is displayed.
+// Note, that it only effects the displayed histogram.
+//
+//   e.g. SetConversion("sqrt(x)");
+//
+Bool_t MH3::SetConversion(const char *func)
+{
+    if (TString(func).IsNull())
+    {
+        delete fConversion;
+        fConversion = 0;
+        return kTRUE;
+    }
+
+    fConversion = new TFormula;
+
+    // Must have a name otherwise all axis labels disappear like a miracle
+    fConversion->SetName("ConversionFunction");
+    if (fConversion->Compile(func))
+    {
+        *fLog << err << dbginf << "Syntax Error: TFormula::Compile failed for " << func << endl;
+        delete fConversion;
+        fConversion = 0;
+        return kFALSE;
+    }
+
+    gROOT->GetListOfFunctions()->Remove(fConversion);
+
+    return kTRUE;
 }
 
@@ -845,4 +899,28 @@
 // --------------------------------------------------------------------------
 //
+// Apply the conversion function to the contents stored in fHist and
+// store the result in h.
+//
+void MH3::Convert(TH1 &h) const
+{
+    for (Int_t z=0; z<=h.GetNbinsZ()+1; z++)
+        for (Int_t y=0; y<=h.GetNbinsY()+1; y++)
+            for (Int_t x=0; x<=h.GetNbinsX()+1; x++)
+            {
+                h.SetBinContent(x, y, z, fConversion->Eval(fHist->GetBinContent(x, y, z)));
+                h.SetBinError(  x, y, z, fConversion->Eval(fHist->GetBinError(  x, y, z)));
+            }
+
+    if (h.InheritsFrom(TProfile::Class()))
+        for (Int_t x=0; x<=h.GetNbinsX()+1; x++)
+            static_cast<TProfile&>(h).SetBinEntries(x, 1);
+
+    if (h.InheritsFrom(TProfile2D::Class()))
+        for (Int_t x=0; x<=h.GetNbinsX()+1; x++)
+            static_cast<TProfile2D&>(h).SetBinEntries(x, 1);
+}
+
+// --------------------------------------------------------------------------
+//
 // FIXME
 //
@@ -853,4 +931,11 @@
     if (TMath::Abs(fDimension)==2)
         MH::SetPalette("pretty");
+
+    if (fConversion)
+    {
+        TH1 *h = 0;
+        if ((h=dynamic_cast<TH1*>(gPad->FindObject(fHist->GetName()))))
+            Convert(*h);
+    }
 
     const TString pfx(MString::Format("%sProfX", fHist->GetName()));
@@ -963,7 +1048,19 @@
     }
 
+
+    TH1 *h = fHist;
+
+    if (fConversion)
+    {
+        h = static_cast<TH1*>(fHist->Clone());
+        h->SetDirectory(0);
+        h->SetBit(kCanDelete);
+
+        Convert(*h);
+    }
+
     // FIXME: We may have to remove all our own options from str!
     if (!only)
-        fHist->Draw(str);
+        h->Draw(str);
 
     AppendPad();
@@ -972,32 +1069,32 @@
     if (profx)
     {
-        const TString pfx(MString::Format("%sProfX", fHist->GetName()));
+        const TString pfx(MString::Format("%sProfX", h->GetName()));
 
         if (same && (p=dynamic_cast<TProfile*>(gPad->FindObject(pfx))))
             *fLog << warn << "TProfile " << pfx << " already in pad." << endl;
 
-        p = ((TH2*)fHist)->ProfileX(pfx, -1, -1, "s");
+        p = ((TH2*)h)->ProfileX(pfx, -1, -1, "s");
         p->UseCurrentStyle();
-        p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
+        p->SetLineColor(blue ? kBlue : h->GetLineColor());
         p->SetBit(kCanDelete);
         p->SetDirectory(NULL);
-        p->SetXTitle(fHist->GetXaxis()->GetTitle());
-        p->SetYTitle(fHist->GetYaxis()->GetTitle());
+        p->SetXTitle(h->GetXaxis()->GetTitle());
+        p->SetYTitle(h->GetYaxis()->GetTitle());
         p->Draw(only&&!same?"":"same");
     }
     if (profy)
     {
-        const TString pfy(MString::Format("%sProfY", fHist->GetName()));
+        const TString pfy(MString::Format("%sProfY", h->GetName()));
 
         if (same && (p=dynamic_cast<TProfile*>(gPad->FindObject(pfy))))
             *fLog << warn << "TProfile " << pfy << " already in pad." << endl;
 
-        p = ((TH2*)fHist)->ProfileY(pfy, -1, -1, "s");
+        p = ((TH2*)h)->ProfileY(pfy, -1, -1, "s");
         p->UseCurrentStyle();
-        p->SetLineColor(blue ? kBlue : fHist->GetLineColor());
+        p->SetLineColor(blue ? kBlue : h->GetLineColor());
         p->SetBit(kCanDelete);
         p->SetDirectory(NULL);
-        p->SetYTitle(fHist->GetXaxis()->GetTitle());
-        p->SetXTitle(fHist->GetYaxis()->GetTitle());
+        p->SetYTitle(h->GetXaxis()->GetTitle());
+        p->SetXTitle(h->GetYaxis()->GetTitle());
         p->Draw(only&&!same?"":"same");
     }
Index: trunk/Mars/mhbase/MH3.h
===================================================================
--- trunk/Mars/mhbase/MH3.h	(revision 9820)
+++ trunk/Mars/mhbase/MH3.h	(revision 9821)
@@ -15,4 +15,5 @@
 class MData;
 class MBinning;
+class TFormula;
 
 class MH3 : public MH
@@ -55,9 +56,11 @@
     Byte_t      fStyleBits;      // Set the range of a histogram automatically in Finalize
 
-//    TH1        *fHistDraw;       //!
+    TFormula   *fConversion;     // Conversion function for displaying the histogram
 
     void HandleLogAxis(TAxis &axe) const;
+    void Convert(TH1 &h) const;
 
     void StreamPrimitive(ostream &out) const;
+
 
     enum {
@@ -122,4 +125,6 @@
     void SetWeight(const char *phrase);
 
+    Bool_t SetConversion(const char *func="");
+
     // Getter
     Int_t GetDimension() const { return TMath::Abs(fDimension); }
@@ -160,5 +165,5 @@
     void RecursiveRemove(TObject *obj);
 
-    ClassDef(MH3, 4) // Generalized 1/2/3D-histogram for Mars variables
+    ClassDef(MH3, 5) // Generalized 1/2/3D-histogram for Mars variables
 };
 
Index: trunk/Mars/mhbase/MHn.cc
===================================================================
--- trunk/Mars/mhbase/MHn.cc	(revision 9820)
+++ trunk/Mars/mhbase/MHn.cc	(revision 9821)
@@ -18,5 +18,5 @@
 !   Author(s): Thomas Bretz  2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
-!   Copyright: MAGIC Software Development, 2000-2007
+!   Copyright: MAGIC Software Development, 2000-2010
 !
 !
@@ -485,4 +485,14 @@
 // --------------------------------------------------------------------------
 //
+// call MH3::SetConversion for the current histogram
+//
+void MHn::SetConversion(const char *func)
+{
+    if (fHist[fNum-1])
+        fHist[fNum-1]->SetConversion(func);
+}
+
+// --------------------------------------------------------------------------
+//
 // Call SetupFill for all initialized histograms
 //
Index: trunk/Mars/mhbase/MHn.h
===================================================================
--- trunk/Mars/mhbase/MHn.h	(revision 9820)
+++ trunk/Mars/mhbase/MHn.h	(revision 9821)
@@ -65,4 +65,7 @@
     void SetWeight(const char *phrase);
 
+    // Set a conversion function for displaying the histogram
+    void SetConversion(const char *func="");
+
     // MH
     Bool_t SetupFill(const MParList *pList);
