Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 8977)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 8978)
@@ -24,4 +24,8 @@
      - small improvement to output
      - handle underflow bin of effective on-time more accurate
+     - reddid the formattig of the spectral fit
+
+   * mbase/MMath.[h,cc]:
+     - added Format member function
 
 
Index: /trunk/MagicSoft/Mars/mbase/MMath.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 8977)
+++ /trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 8978)
@@ -1,4 +1,4 @@
 /* ======================================================================== *\
-! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.38 2008-06-14 15:55:50 tbretz Exp $
+! $Name: not supported by cvs2svn $:$Id: MMath.cc,v 1.39 2008-06-18 20:39:48 tbretz Exp $
 ! --------------------------------------------------------------------------
 !
@@ -811,2 +811,28 @@
     return 3;
 }
+
+// --------------------------------------------------------------------------
+//
+// Format a value and its error corresponding to the rules (note
+// this won't work if the error is more then eight orders smaller than
+// the value)
+//
+void MMath::Format(Double_t &v, Double_t &e)
+{
+    // Valid digits
+    Int_t i = TMath::FloorNint(TMath::Log10(v))-TMath::FloorNint(TMath::Log10(e));
+
+    // Check if error starts with 1 or 2. In this case use one
+    // more valid digit
+    TString error = Form("%.0e", e);
+    if (error[0]=='1' || error[0]=='2')
+    {
+        i++;
+        error = Form("%.1e", e);
+    }
+
+    const char *fmt = Form("%%.%de", i);
+
+    v = atof(Form(fmt, v));
+    e = error.Atof();
+}
Index: /trunk/MagicSoft/Mars/mbase/MMath.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MMath.h	(revision 8977)
+++ /trunk/MagicSoft/Mars/mbase/MMath.h	(revision 8978)
@@ -1,4 +1,8 @@
 #ifndef MARS_MMath
 #define MARS_MMath
+
+#ifndef	_MATH_H
+#include <math.h>  // Needed for darwin
+#endif
 
 #ifndef ROOT_TMath
@@ -69,9 +73,11 @@
     TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y);
 
-    inline Int_t ModF(Double_t dbl, Double_t &frac) { Double_t rc; frac = modf(dbl, &rc); return TMath::Nint(rc); }
+    inline Int_t ModF(Double_t dbl, Double_t &frac) { Double_t rc; frac = ::modf(dbl, &rc); return TMath::Nint(rc); }
 
-    inline Double_t Sqrt3(Double_t x) { return cbrt(x); }
+    inline Double_t Sqrt3(Double_t x) { return ::cbrt(x); }
 
     inline Double_t Sgn(Double_t d) { return d<0 ? -1 : 1; }
+
+    void Format(Double_t &v, Double_t &e);
 }
 
Index: /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8977)
+++ /trunk/MagicSoft/Mars/mjobs/MJSpectrum.cc	(revision 8978)
@@ -48,4 +48,5 @@
 #include "MLogManip.h"
 
+#include "MMath.h"
 #include "MDirIter.h"
 
@@ -292,4 +293,6 @@
 
     const Double_t ufl = vstime->GetBinContent(0);
+    const Double_t ofl = vstime->GetBinContent(vstime->GetNbinsX()+1);
+    const Double_t eff = vstime->Integral()+ufl+ofl;
     if (ufl>0)
     {
@@ -301,7 +304,4 @@
         *fLog << warn << "WARNING - " << Form("%.1f%% (%.0fs)", 100*ufl/eff, ufl) << " of the eff. observation time is in the underflow bin." << endl;
     }
-
-    const Double_t ofl = vstime->GetBinContent(vstime->GetNbinsX()+1);
-    const Double_t eff = vstime->Integral()+ufl+ofl;
     if (ofl>0)
         *fLog << warn << "WARNING - " << Form("%.1f%% (%.0fs)", 100*ofl/eff, ofl) << " of the eff. observation time is in the overflow bin." << endl;
@@ -872,19 +872,12 @@
 TString MJSpectrum::FormString(const TF1 &f, Byte_t type)
 {
-    const Double_t p0 = f.GetParameter(0);
-    const Double_t p1 = f.GetParameter(1);
-
-    const Double_t e0 = f.GetParError(0);
-    const Double_t e1 = f.GetParError(1);
-
-    const Int_t    np  = TMath::Nint(TMath::Floor(TMath::Log10(p1)));
-    const Double_t exp = TMath::Power(10, np);
-
-    const Float_t fe0 = TMath::Log10(e0);
-    const Float_t fe1 = TMath::Log10(e1);
-
-    // calc number of (gueltige ziffern) digits to be displayed
-    const char *f0  = fe0-TMath::Floor(fe0)>0.3 ? "3.1" : "1.0";
-    const char *f1  = fe1-TMath::Floor(fe1)>0.3 ? "3.1" : "1.0";
+    Double_t p0 = f.GetParameter(0);
+    Double_t p1 = f.GetParameter(1);
+
+    Double_t e0 = f.GetParError(0);
+    Double_t e1 = f.GetParError(1);
+
+    MMath::Format(p0, e0);
+    MMath::Format(p1, e1);
 
     TString str;
@@ -893,9 +886,9 @@
     case 0:
         {
-            const TString fmt0 = Form("(%%%sf#pm%%%sf)\\bullet10^{%%d}",  f1, f1);
-            const TString fmt1 = Form("(\\frac{E}{500GeV})^{%%%sf#pm%%%sf}", f0, f0);
-
-            str  = Form(fmt0.Data(), p1/exp, e1/exp, np);
-            str += Form(fmt1.Data(), p0, e0);
+            const Int_t    i   = TMath::FloorNint(TMath::Log10(p1));
+            const Double_t exp = TMath::Power(10, i);
+
+            str  = Form("(%f#pm%f)\\bullet10^{%d}",      p1/exp, e1/exp, i);
+            str += Form("(\\frac{E}{500GeV})^{%f#pm%f}", p0, e0);
             str += "\\frac{ph}{TeVm^{2}s}";
         }
