Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 7408)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 7409)
@@ -22,4 +22,42 @@
    * mhflux/MMcSpectrumWeight.cc:
      - fixed a problem with using X more than once in the formula
+
+   * ganymed.cc:
+     - improved UsageInfo
+
+   * macros/optim/optimdisp.C, macros/optim/optimenergy.C:
+     - added some  more examples
+
+   * mbadpixels/MBadPixelsCalc.cc:
+     - updated authors
+
+   * mbase/BaseIncl.h:
+     - added TArrayD
+
+   * mbase/MLogHtml.cc:
+     - added some includes suggested by Ching-Cheng
+
+   * mbase/MMath.[h,cc]:
+     - added some function for the analytical result of special fits
+
+   * mfilter/MFEnergySlope.[h,cc]:
+     - some updated to make it better fit into Mars
+     - upadted the user interface
+
+   * mhflux/MHEnergyEst.[h,cc]:
+     - updated to let everything fit what is commonly used. This
+       was just discussed with Abelardo
+     - some updates to the plots
+
+   * mjobs/MDataSet.cc:
+     - added some includes suggested by Ching-Cheng
+     - upadted some output
+     - remove whitespaces from read TString
+
+   * mmc/MMcCorsikaRunHeader.h:
+     - added new Getter
+
+   * mranforest/MRanForest.cc:
+     - some updates to Grow-output
 
 
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 7408)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 7409)
@@ -2,4 +2,7 @@
 
  *** Version  <cvs>
+
+   - general: Updated MMath with new functions to calculate the results of
+     a exponential, logarithmic and powerlaw fits analytically.
 
    - general: Updated some macros with comments:
@@ -44,4 +47,10 @@
 
    - sponde: Added a plot E^2*dN/dE
+
+   - sponde: The energy estimator plot should now show values like
+     they are commonly used.
+
+   - sponde: Now MMcSpectrumWeight also excepts formulas with two X
+     (a powerlaw with cutoff didn't work before)
 
 
Index: /trunk/MagicSoft/Mars/ganymed.cc
===================================================================
--- /trunk/MagicSoft/Mars/ganymed.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/ganymed.cc	(revision 7409)
@@ -61,5 +61,5 @@
     gLog << "   -q                        Quit when job is finished" << endl;
     gLog << "   -f                        Force overwrite of existing files" << endl;
-    gLog << "   --n=[n]                   Analysis number" << endl;
+    gLog << "   --n=number                Analysis number (required if not in dataset file)" << endl;
     gLog << "   --out=path                Path to write the all output to [def=local path]" << endl;
     gLog << "   --ind=path                Path to data/star files [default=datacenter path]" << endl;
Index: /trunk/MagicSoft/Mars/macros/optim/optimdisp.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/optim/optimdisp.C	(revision 7408)
+++ /trunk/MagicSoft/Mars/macros/optim/optimdisp.C	(revision 7409)
@@ -42,4 +42,8 @@
      opt.AddPreCut(&cuts);
 
+     -------------------- Energy Slope --------------------
+     MFEnergySlope slope(-2.8);
+     opt.AddPreCut(&slope);
+
      -------------------- Other cuts ----------------------
      opt.AddPreCut("MNewImagePar.fLeakage1<0.0001");
Index: /trunk/MagicSoft/Mars/macros/optim/optimenergy.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/optim/optimenergy.C	(revision 7408)
+++ /trunk/MagicSoft/Mars/macros/optim/optimenergy.C	(revision 7409)
@@ -38,4 +38,8 @@
      opt.AddPreCut(&cuts);
 
+     -------------------- Energy Slope --------------------
+     MFEnergySlope slope(-2.8);
+     opt.AddPreCut(&slope);
+
      -------------------- Other cuts ----------------------
      opt.AddPreCut("MPointingPos.fZd<7");
Index: /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/mbadpixels/MBadPixelsCalc.cc	(revision 7409)
@@ -17,6 +17,7 @@
 !
 !   Author(s): Thomas Bretz, 02/2004 <mailto:tbretz@astro.uni.wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2004
+!   Author(s): Stefan Ruegamer, 08/2005 <mailto:snruegam@astro.uni.wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2005
 !
 !
Index: /trunk/MagicSoft/Mars/mbase/BaseIncl.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/BaseIncl.h	(revision 7408)
+++ /trunk/MagicSoft/Mars/mbase/BaseIncl.h	(revision 7409)
@@ -1,14 +1,6 @@
 #ifndef __CINT__
 
+#include <TArrayD.h>
 #include <TVector3.h>
 
-/*
-#include <fstream.h>
-
-#include <TFile.h>
-#include <TTree.h>
-
-#include <TGListBox.h>
-*/
-
 #endif // __CINT__
Index: /trunk/MagicSoft/Mars/mbase/MLogHtml.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MLogHtml.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/mbase/MLogHtml.cc	(revision 7409)
@@ -30,4 +30,7 @@
 //////////////////////////////////////////////////////////////////////////////
 #include "MLogHtml.h"
+
+#include <string.h>  // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
+#include <errno.h>   // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
 
 #include <fstream>  // ofstream
Index: /trunk/MagicSoft/Mars/mbase/MMath.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/mbase/MMath.cc	(revision 7409)
@@ -36,4 +36,7 @@
 #endif
 
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
 // --------------------------------------------------------------------------
 //
@@ -248,2 +251,140 @@
     return InterpolParabLin(vx0, vy, TMath::Cos(x));
 }
+
+// --------------------------------------------------------------------------
+//
+// Analytically calculated result of a least square fit of:
+//    y = A*e^(B*x)
+// Equal weights
+//
+// It returns TArrayD(2) = { A, B };
+//
+// see: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html
+//
+TArrayD MMath::LeastSqFitExpW1(Int_t n, Double_t *x, Double_t *y)
+{
+    Double_t sumxsqy  = 0;
+    Double_t sumylny  = 0;
+    Double_t sumxy    = 0;
+    Double_t sumy     = 0;
+    Double_t sumxylny = 0;
+    for (int i=0; i<n; i++)
+    {
+        sumylny  += y[i]*TMath::Log(y[i]);
+        sumxy    += x[i]*y[i];
+        sumxsqy  += x[i]*x[i]*y[i];
+        sumxylny += x[i]*y[i]*TMath::Log(y[i]);
+        sumy     += y[i];
+    }
+
+    const Double_t dev = sumy*sumxsqy - sumxy*sumxy;
+
+    const Double_t a = (sumxsqy*sumylny - sumxy*sumxylny)/dev;
+    const Double_t b = (sumy*sumxylny - sumxy*sumylny)/dev;
+
+    TArrayD rc(2);
+    rc[0] = TMath::Exp(a);
+    rc[1] = b;
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Analytically calculated result of a least square fit of:
+//    y = A*e^(B*x)
+// Greater weights to smaller values
+//
+// It returns TArrayD(2) = { A, B };
+//
+// see: http://mathworld.wolfram.com/LeastSquaresFittingExponential.html
+//
+TArrayD MMath::LeastSqFitExp(Int_t n, Double_t *x, Double_t *y)
+{
+    // -------- Greater weights to smaller values ---------
+    Double_t sumlny  = 0;
+    Double_t sumxlny = 0;
+    Double_t sumxsq  = 0;
+    Double_t sumx    = 0;
+    for (int i=0; i<n; i++)
+    {
+        sumlny  += TMath::Log(y[i]);
+        sumxlny += x[i]*TMath::Log(y[i]);
+
+        sumxsq  += x[i]*x[i];
+        sumx    += x[i];
+    }
+
+    const Double_t dev = n*sumxsq-sumx*sumx;
+
+    const Double_t a = (sumlny*sumxsq - sumx*sumxlny)/dev;
+    const Double_t b = (n*sumxlny - sumx*sumlny)/dev;
+
+    TArrayD rc(2);
+    rc[0] = TMath::Exp(a);
+    rc[1] = b;
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Analytically calculated result of a least square fit of:
+//    y = A+B*ln(x)
+//
+// It returns TArrayD(2) = { A, B };
+//
+// see: http://mathworld.wolfram.com/LeastSquaresFittingLogarithmic.html
+//
+TArrayD LeastSqFitLog(Int_t n, Double_t *x, Double_t *y)
+{
+    Double_t sumylnx  = 0;
+    Double_t sumy     = 0;
+    Double_t sumlnx   = 0;
+    Double_t sumlnxsq = 0;
+    for (int i=0; i<n; i++)
+    {
+        sumylnx  += y[i]*TMath::Log(x[i]);
+        sumy     += y[i];
+        sumlnx   += TMath::Log(x[i]);
+        sumlnxsq += TMath::Log(x[i])*TMath::Log(x[i]);
+    }
+
+    const Double_t b = (n*sumylnx-sumy*sumlnx)/(n*sumlnxsq-sumlnx*sumlnx);
+    const Double_t a = (sumy-b*sumlnx)/n;
+
+    TArrayD rc(2);
+    rc[0] = a;
+    rc[1] = b;
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Analytically calculated result of a least square fit of:
+//    y = A*x^B
+//
+// It returns TArrayD(2) = { A, B };
+//
+// see: http://mathworld.wolfram.com/LeastSquaresFittingPowerLaw.html
+//
+TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y)
+{
+    Double_t sumlnxlny  = 0;
+    Double_t sumlnx   = 0;
+    Double_t sumlny    = 0;
+    Double_t sumlnxsq   = 0;
+    for (int i=0; i<n; i++)
+    {
+        sumlnxlny  += TMath::Log(x[i])*TMath::Log(y[i]);
+        sumlnx     += TMath::Log(x[i]);
+        sumlny     += TMath::Log(y[i]);
+        sumlnxsq   += TMath::Log(x[i])*TMath::Log(x[i]);
+    }
+
+    const Double_t b = (n*sumlnxlny-sumlnx*sumlny)/(n*sumlnxsq-sumlnx*sumlnx);
+    const Double_t a = (sumlny-b*sumlnx)/n;
+
+    TArrayD rc(2);
+    rc[0] = TMath::Exp(a);
+    rc[1] = b;
+    return rc;
+}
Index: /trunk/MagicSoft/Mars/mbase/MMath.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MMath.h	(revision 7408)
+++ /trunk/MagicSoft/Mars/mbase/MMath.h	(revision 7409)
@@ -7,4 +7,5 @@
 
 class TVector3;
+class TArrayD;
 
 namespace MMath
@@ -31,4 +32,9 @@
     Double_t InterpolParabCos(const TVector3 &vx, const TVector3 &vy, Double_t x);
 
+    TArrayD LeastSqFitExpW1(Int_t n, Double_t *x, Double_t *y);
+    TArrayD LeastSqFitExp(Int_t n, Double_t *x, Double_t *y);
+    TArrayD LeastSqFitLog(Int_t n, Double_t *x, Double_t *y);
+    TArrayD LeastSqFitPowerLaw(Int_t n, Double_t *x, Double_t *y);
+
     inline Double_t Sgn(Double_t d) { return d<0 ? -1 : 1; }
 }
Index: /trunk/MagicSoft/Mars/mfilter/MFEnergySlope.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFEnergySlope.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/mfilter/MFEnergySlope.cc	(revision 7409)
@@ -18,5 +18,5 @@
 !   Author(s): Antonio Stamerra  02/2003 <mailto:antonio.stamerra@pi.infn.it>
 !
-!   Copyright: MAGIC Software Development, 2000-2003
+!   Copyright: MAGIC Software Development, 2000-2005
 !
 !
@@ -65,12 +65,22 @@
 // --------------------------------------------------------------------------
 //
+//  Default Constructor
+//
+MFEnergySlope::MFEnergySlope(const char *name, const char *title):
+    fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
+{
+    fName  = name  ? name  : "MFEnergySlope";
+    fTitle = title ? title : "Filter to select energy with given slope";
+}
+
+// --------------------------------------------------------------------------
+//
 //     Constructor
 //
-MFEnergySlope::MFEnergySlope(const char *name, const char *title):
-  fNumSelectedEvts(0), fNewSlope(-1), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
-{
-  //    fContName = cname;
-  fName  = name  ? name  : "MFEnergySlope";
-  fTitle = title ? title : "Filter to select energy with given slope";
+MFEnergySlope::MFEnergySlope(Float_t slope, const char *name, const char *title):
+    fNewSlope(TMath::Abs(slope)), fMcMinEnergy(-1.), fMcMaxEnergy(-1.)
+{
+    fName  = name  ? name  : "MFEnergySlope";
+    fTitle = title ? title : "Filter to select energy with given slope";
 }
 
@@ -84,48 +94,61 @@
 Int_t MFEnergySlope::PreProcess(MParList *pList)
 {
- 
+    if (fNewSlope<0)
+    {
+        *fLog << err << "New slope still undefined... aborting." << endl;
+        return kFALSE;
+    }
+
+    fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
+    if (!fEvt)
+    {
+        *fLog << err << "MMcEvt not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+//   Preprocess
+//  
+//  MC slope and min/max energy are read
+//  Normalization factor is computed
+//
+Bool_t MFEnergySlope::ReInit(MParList *pList)
+{
     MMcCorsikaRunHeader *runheader = (MMcCorsikaRunHeader*)pList->FindObject("MMcCorsikaRunHeader");
-
     if (!runheader)
-      {
-	*fLog << err << dbginf << fName << " [MMcCorsikaRunHeader] not found... aborting." << endl;
-	return kFALSE;
-      }
+    {
+        *fLog << err << "MMcCorsikaRunHeader not found... aborting." << endl;
+        return kFALSE;
+    }
+
     //
-    // Read info from the MC sample (it must be generated with 
+    // Read info from the MC sample (it must be generated with
     //   reflector ver.0.6 and camera ver. 0.6)
     //
-    fMcSlope = runheader->GetSlopeSpec();    
+    fMcSlope = runheader->GetSlopeSpec();
     if (fMcMinEnergy<0)
-      fMcMinEnergy = runheader->GetELowLim();
+        fMcMinEnergy = runheader->GetELowLim();
     if (fMcMinEnergy<0)
-      fMcMaxEnergy = runheader->GetEUppLim();
-
-    *fLog << inf;
-    *fLog << "MFEnergySlope::PreProcess: fetched MC info:" << endl;
-    *fLog << "  E Slope:     " << fMcSlope << endl;
-    *fLog << "  E Min:       " << fMcMinEnergy << endl;
-    *fLog << "  E Max:       " << fMcMaxEnergy << endl;
-    *fLog << "  New E Slope: " << fNewSlope << endl;
-    
+        fMcMaxEnergy = runheader->GetEUppLim();
+
     // Slope is used with positive values in the code
     if (fNewSlope < 0)
-      fNewSlope *= -1; 
+        fNewSlope *= -1;
     if (fMcSlope < 0)
-      fMcSlope *= -1;
-
-
-  // Set normalization on energy  
-    fN0 = pow(fNewSlope>fMcSlope?fMcMinEnergy:fMcMaxEnergy,fNewSlope-fMcSlope);
-
-  *fLog << "Normalization factor:" <<fN0 << endl;
-
-  //---
-    fEvt = (MMcEvt*)pList->FindObject("MMcEvt");
-    if (!fEvt)
-      {
-	*fLog << err << dbginf << fName << " [MMcEvt] not found... aborting." << endl;
-        return kFALSE;
-      }
+        fMcSlope *= -1;
+
+    // Calculate normalization factor
+    fN0 = TMath::Power(fNewSlope>fMcSlope ? fMcMinEnergy : fMcMaxEnergy, fNewSlope-fMcSlope);
+
+    // Print some infos
+    *fLog << inf;
+    *fLog << "Fetched MC info:" << endl;
+    *fLog << "  Change E Slope " << fMcSlope << " (" << fMcMinEnergy << " < E < ";
+    *fLog << fMcMaxEnergy << ") to " << fNewSlope << endl;
+    *fLog << "  Norm factor: " << fN0 << endl;
 
     return kTRUE;
@@ -144,38 +167,52 @@
 Int_t MFEnergySlope::Process()
 {
-  fResult = kTRUE;
-
-  // Energy slopes are the same: skip it
-  if (fNewSlope == fMcSlope)
+    fResult = kTRUE;
+
+    // Energy slopes are the same: skip it
+    if (fNewSlope == fMcSlope)
+        return kTRUE;
+
+    //  The value of the normalized spectrum is compared with a
+    //   random value in [0,1];
+    //   if the latter is higher the event is accepted
+    const Float_t energy = fEvt->GetEnergy();
+
+    /*
+     //
+     // If energy bounds different from MC ones are selected, then
+     // events outside these bounds are rejected, as their slope has
+     // not been changed.
+     //
+     if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
+     {
+        fResult = kFALSE;
+        return kTRUE;
+     }
+     */
+
+    const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
+    const Float_t Nrnd = gRandom->Uniform();
+
+    fResult = Nexp > Nrnd;
+
+    //if (fResult)
+    //    fNumSelectedEvts++;
+
     return kTRUE;
-  
-  //  The value of the normalized spectrum is compared with a 
-  //   random value in [0,1]; 
-  //   if the latter is higher the event is accepted
-  const Float_t energy = fEvt->GetEnergy();
-
-  /*
-  //
-  // If energy bounds different from MC ones are selected, then
-  // events outside these bounds are rejected, as their slope has
-  // not been changed.
-  //
-  if (energy > fMcMaxEnergy || energy < fMcMinEnergy)
-    {
-      fResult = kFALSE;
-      return kTRUE;
-    }
-  */
-
-  const Float_t Nexp = fN0 * pow(energy,fMcSlope-fNewSlope);
-  const Float_t Nrnd = gRandom->Uniform();
-
-  fResult = Nexp > Nrnd;
-
-  if (!fResult)
-      return kTRUE;
-
-  fNumSelectedEvts++;
-  return kTRUE;
-}
-
+}
+
+
+// --------------------------------------------------------------------------
+//
+//   MFEnergySlope.NewSlope: -2.8
+//
+Int_t MFEnergySlope::ReadEnv(const TEnv &env, TString prefix, Bool_t print)
+{
+    Bool_t rc = kFALSE;
+    if (IsEnvDefined(env, prefix, "NewSlope", print))
+    {
+        rc = kTRUE;
+        SetNewSlope(GetEnvValue(env, prefix, "NewSlope", fNewSlope));
+    }
+    return rc;
+}
Index: /trunk/MagicSoft/Mars/mfilter/MFEnergySlope.h
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFEnergySlope.h	(revision 7408)
+++ /trunk/MagicSoft/Mars/mfilter/MFEnergySlope.h	(revision 7409)
@@ -1,9 +1,4 @@
 #ifndef MARS_MFEnergySlope
 #define MARS_MFEnergySlope
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-// MFEnergySlope                                                           //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
 
 #ifndef MARS_MFilter
@@ -11,6 +6,6 @@
 #endif
 
+class MMcEvt;
 class MParList;
-class MMcEvt;
 class MMcCorsikaRunHeader;
 
@@ -18,31 +13,39 @@
 {
 private:
-    Int_t fNumSelectedEvts; // counter for number of selected events
+    //Int_t fNumSelectedEvts; // counter for number of selected events
 
-    MMcEvt *fEvt;           // Events used to determin energy slope
+    MMcEvt *fEvt;           //! Events used to determin energy slope
 
-    Bool_t fResult;         // Result returned by IsExpressionTrue
     Float_t fNewSlope;      // New slope set by user
+    Float_t fMcSlope;       //! Original energy slope from MC data
 
-    Float_t fMcSlope;       // Original energy slope from MC data
-    Float_t fMcMinEnergy;   // Starting energy of MC data
-    Float_t fMcMaxEnergy;   // Ending energy of MC data
+    Float_t fMcMinEnergy;   //! Starting energy of MC data
+    Float_t fMcMaxEnergy;   //! Ending energy of MC data
 
-    Float_t fN0;            // Normalization factor
+    Float_t fN0;            //! Normalization factor
 
-    Int_t PreProcess(MParList *pList);
-    Int_t Process();
+    Bool_t  fResult;        //! Result returned by IsExpressionTrue
+
+    // MTask
+    Int_t  PreProcess(MParList *pList);
+    Bool_t ReInit(MParList *pList);
+    Int_t  Process();
+
+    // MFilter
+    Bool_t IsExpressionTrue() const { return fResult; }
 
 public:
     MFEnergySlope(const char *name=NULL, const char *title=NULL);
+    MFEnergySlope(Float_t slope, const char *name=NULL, const char *title=NULL);
 
-    Bool_t IsExpressionTrue() const { return fResult; }
+    // Setter
+    void SetNewSlope(Float_t f)    { fNewSlope = TMath::Abs(f); }
+    void SetMcSlope(Float_t f)     { fMcSlope  = TMath::Abs(f); }
 
-    // Slope is used with positive values in the code 
-    void SetNewSlope(Float_t f) {fNewSlope = TMath::Abs(f);}
-    void SetMcSlope(Float_t f) {fMcSlope = TMath::Abs(f);}
+    void SetMcMinEnergy(Float_t f) { fMcMinEnergy = f; }
+    void SetMcMaxEnergy(Float_t f) { fMcMaxEnergy = f; }
 
-    void SetMcMinEnergy(Float_t f) {fMcMinEnergy = f;}
-    void SetMcMaxEnergy(Float_t f) {fMcMaxEnergy = f;}
+    // MParContainer
+    Int_t ReadEnv(const TEnv &env, TString prefix, Bool_t print);
 
     ClassDef(MFEnergySlope, 0) // A Filter to select events with a given energy slope
Index: /trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/mhflux/MHEnergyEst.cc	(revision 7409)
@@ -35,4 +35,5 @@
 #include "MHEnergyEst.h"
 
+#include <TF1.h>
 #include <TLine.h>
 #include <TCanvas.h>
@@ -79,14 +80,14 @@
     fHResolution.SetDirectory(NULL);
     fHResolution.SetName("EnergyRes");
-    fHResolution.SetTitle("Histogram in \\Delta lg(E) vs E_{est} and E_{mc}");
+    fHResolution.SetTitle("Histogram in \\Delta E/E vs E_{est} and E_{mc}");
     fHResolution.SetXTitle("E_{est} [GeV]");
     fHResolution.SetYTitle("E_{mc} [GeV]");
-    fHResolution.SetZTitle("lg(E_{est}) - lg(E_{mc})");
+    fHResolution.SetZTitle("E_{est}/E_{mc}-1");
 
     fHImpact.SetDirectory(NULL);
     fHImpact.SetName("Impact");
-    fHImpact.SetTitle("\\Delta lg(E) vs Impact parameter");
+    fHImpact.SetTitle("\\Delta E/E vs Impact parameter");
     fHImpact.SetXTitle("Impact parameter [m]");
-    fHImpact.SetYTitle("lg(E_{est}) - lg(E_{mc})");
+    fHImpact.SetYTitle("E_{est}/E_{mc}-1");
 
     fHEnergy.Sumw2();
@@ -95,8 +96,8 @@
 
     MBinning binsi, binse, binst, binsr;
-    binse.SetEdgesLog(15, 10, 1000000);
+    binse.SetEdgesLog(25, 10, 1000000);
     binst.SetEdgesASin(51, -0.005, 0.505);
     binsi.SetEdges(10, 0, 400);
-    binsr.SetEdges(50, -1.3, 1.3);
+    binsr.SetEdges(75, -1.75, 1.75);
 
     SetBinning(&fHEnergy,     &binse, &binse, &binst);
@@ -149,4 +150,5 @@
     fChisq = 0;
     fBias  = 0;
+
     fHEnergy.Reset();
     fHImpact.Reset();
@@ -155,11 +157,5 @@
     return kTRUE;
 }
-/*
-#include <TSpline.h>
-Double_t x[] = {33, 75, 153, 343, 745, 1617, 3509, 7175};
-Double_t y[] = {2,  24, 302, 333, 132,   53,   11,    1};
-Int_t n = 8;
-TSpline3 spline("", x, y, n);
-*/
+
 // --------------------------------------------------------------------------
 //
@@ -172,5 +168,4 @@
     const Double_t imp   = fMatrix ? GetVal(1) : fMcEvt->GetImpact()/100;
     const Double_t theta = fMatrix ? GetVal(2) : fMcEvt->GetTelescopeTheta()*TMath::RadToDeg();
-    const Double_t res   = log10(eest)-log10(etru);///log10(etru);
     const Double_t resE  = (eest-etru)/etru;
 
@@ -179,65 +174,21 @@
     fHImpact.Fill(imp, resE, w);
 
-    //if (etru>125 && etru<750)
-    //    return kCONTINUE;
-
-    // lg(N)  = 4.3*lg(E)-6
-    // lg(N0) = 4.3*2.2-6
-
-    const Double_t n  = 2.;///spline.Eval(etru); //pow(10, -4.3*(log10(etru)-2.2));
-    if (n<=0)
-        return kCONTINUE;
-
-    fChisq += log10(etru)>0 ? res*res*n/2   : res*res;
-    fBias  += log10(etru)>0 ? res*sqrt(n/2) : res;
+    // For the fit we use a different quantity
+    //const Double_t res = TMath::Log10(eest/etru);
+    const Double_t res = eest-etru;
+
+    fChisq += res*res;
+    fBias  += res;
 
     return kTRUE;
 }
-/*
-void MHEnergyEst::CalcChisq(Double_t &chisq, Double_t &prob) const
-{
-    TH1D *h1 = (TH1D*)fHEnergy.Project3D("dum2_ex");
-    TH1D *h2 = (TH1D*)fHEnergy.Project3D("dum2_ey");
-
-    Int_t df = 0;
-    chisq    = 0;
-    prob     = 0;
-
-    for (Int_t i=1; i<=h1->GetNbinsX(); i++)
-    {
-        if (h1->GetBinContent(i)>0 && h2->GetBinContent(i)>0)
-        {
-            const Double_t bin1 = log10(h1->GetBinContent(i));
-            const Double_t bin2 = log10(h2->GetBinContent(i));
-
-            const Double_t temp = bin1-bin2;
-
-            chisq += temp*temp/(bin1+bin2);
-            df ++;
-        }
-    }
-  
-    prob = TMath::Prob(0.5*chisq, Int_t(0.5*df));
-
-    chisq /= df;
-  
-    delete h1;
-    delete h2;
-}
-*/
+
 Bool_t MHEnergyEst::Finalize()
 {
-    //Double_t chisq, prob;
-    //CalcChisq(chisq, prob);
-  
     fChisq /= GetNumExecutions();
     fBias  /= GetNumExecutions();
 
-    fResult->SetVal(TMath::Sqrt(fChisq));
-
-/*
-    Double_t sigma = TMath::Sqrt(fChisq);//+TMath::Abs(fBias);
-    fResult->SetVal(sigma);
-*/
+    fResult->SetVal(fChisq);
+
     Print();
 
@@ -247,8 +198,8 @@
 void MHEnergyEst::Print(Option_t *o) const
 {
-    const Double_t res  =   TMath::Sqrt(fChisq-fBias*fBias);
-    const Double_t resp =   TMath::Power(10,  res)-1;
-    const Double_t resm = 1-TMath::Power(10, -res);
-
+    //    const Double_t resp =   TMath::Power(10,  res)-1;
+    //    const Double_t resm = 1-TMath::Power(10, -res);
+
+    const Double_t res = TMath::Sqrt(fChisq-fBias*fBias);
     if (TMath::IsNaN(res))
     {
@@ -257,8 +208,19 @@
     }
 
-    *fLog << all;
-    *fLog << "Mean log10(Energy) Resoltion: +/- " << Form("%4.2f", res) << endl;
-    *fLog << "Mean log10(Energy) Bias:         "  << Form("%+4.2f", fBias) << endl;
-    *fLog << "Asymmetric Energy  Resoltion:   +"  << Form("%4.1f%%", resp*100) << " -" << Form("%4.1f%%", resm*100) << endl;
+    TH1D *h = (TH1D*)fHResolution.ProjectionZ("Resolution");
+    h->Fit("gaus", "Q0");
+
+    TF1 *f = h->GetFunction("gaus");
+
+    *fLog << all << "F=" << fChisq << endl;
+    *fLog << "Results from Histogram:" << endl;
+    *fLog << " Mean  of Delta E/E: " << Form("%+4.2f%%", 100*h->GetMean()) << endl;
+    *fLog << " RMS   of Delta E/E: " << Form("%4.2f%%",  100*h->GetRMS()) << endl;
+    *fLog << "Results from Histogram-Fit:" << endl;
+    *fLog << " Bias  of Delta E/E: " << Form("%+4.2f%%", 100*f->GetParameter(1)) << endl;
+    *fLog << " Sigma of Delta E/E: " << Form("%4.2f%%",  100*f->GetParameter(2)) << endl;
+    *fLog << " Res   of Delta E/E: " << Form("%4.2f%%",  100*TMath::Hypot(f->GetParameter(1), f->GetParameter(2))) << endl;
+
+    delete h;
 }
 
@@ -411,10 +373,10 @@
     h1->SetBit(kCanDelete);
     h1->SetLineWidth(2);
-    h1->SetLineColor(kRed);
+    h1->SetLineColor(kBlue);
     h1->SetFillStyle(4000);
     h1->SetStats(kFALSE);
 
     h2->Draw("");
-    h1->Draw("E3 hist C same");
+    h1->Draw("E0 hist C same");
 //    h1->Draw("Chistsame");
 
@@ -509,5 +471,5 @@
     //h->SetXTitle("\\frac{lg(E_{est}) - lg(E_{mc})}{lg(E_{mc})}");
     h->SetYTitle("Counts");
-    h->SetTitle("Distribution of \\Delta lg(E)");
+    h->SetTitle("Distribution of \\Delta E/E");
     h->SetDirectory(NULL);
     h->SetBit(kCanDelete);
@@ -535,6 +497,6 @@
     h = MakePlot(fHResolution, "zy");
     h->SetXTitle("E_{mc} [GeV]");
-    h->SetYTitle("lg(E_{est}) - lg(E_{mc})");
-    h->SetTitle("Energy resolution \\Delta lg(E) vs Monte Carlo energy E_{mc}");
+    h->SetYTitle("(E_{est}/E_{mc}-1");
+    h->SetTitle("Energy resolution \\Delta E/E vs Monte Carlo Energy E_{mc}");
     h->SetMinimum(-1.3);
     h->SetMaximum(1.3);
@@ -543,6 +505,6 @@
     h = MakePlot(fHResolution, "zx");
     h->SetXTitle("E_{est} [GeV]");
-    h->SetYTitle("lg(E_{est}) - lg(E_{mc})");
-    h->SetTitle("Energy Resolution \\Delta lg(E) vs estimated Energy E_{est}");
+    h->SetYTitle("(E_{est}/E_{mc}-1");
+    h->SetTitle("Energy resolution \\Delta E/E vs estimated Energy E_{est}");
     h->SetMinimum(-1.3);
     h->SetMaximum(1.3);
Index: /trunk/MagicSoft/Mars/mjobs/MDataSet.cc
===================================================================
--- /trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/mjobs/MDataSet.cc	(revision 7409)
@@ -74,4 +74,7 @@
 #include "MDataSet.h"
 
+#include <string.h>  // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
+#include <errno.h>   // necessary for Fedora core 2 with kernel 2.6.9-1.667 #1 and gcc 3.4.2
+
 #include <stdlib.h>
 #include <fstream>
@@ -222,4 +225,7 @@
     fIsWobbleMode = env.GetValue("WobbleMode", kFALSE);
     fComment      = env.GetValue("Comment",    "");
+
+    fNameSource = fNameSource.Strip(TString::kBoth);
+    fCatalog    = fCatalog.Strip(TString::kBoth);
 }
 
@@ -246,5 +252,5 @@
     if (!IsValid())
     {
-        gLog << "Dataset: " << fName << " <invalid>" << endl;
+        gLog << "Dataset: " << fName << " <invalid - no analysis number available>" << endl;
         return;
     }
Index: /trunk/MagicSoft/Mars/mranforest/MRanForest.cc
===================================================================
--- /trunk/MagicSoft/Mars/mranforest/MRanForest.cc	(revision 7408)
+++ /trunk/MagicSoft/Mars/mranforest/MRanForest.cc	(revision 7409)
@@ -419,7 +419,7 @@
 
         if(calcResolution)
-            *fLog << "no. of tree    no. of nodes    resolution in % (from oob-data -> overest. of error)" << endl;
+            *fLog << "no. of tree  no. of nodes  resolution in % (from oob-data -> overest. of error)" << endl;
         else
-            *fLog << "no. of tree    no. of nodes    rms in % (from oob-data -> overest. of error)" << endl;
+            *fLog << "no. of tree  no. of nodes  rms in % (from oob-data -> overest. of error)" << endl;
                      //        12345678901234567890123456789012345678901234567890
     }
@@ -509,6 +509,6 @@
     // give running output
     *fLog << inf << setw(5)  << fTreeNo;
-    *fLog << inf << setw(20) << fRanTree->GetNumEndNodes();
-    *fLog << inf << Form("%20.2f", ferr*100.);
+    *fLog << inf << setw(18) << fRanTree->GetNumEndNodes();
+    *fLog << inf << Form("%18.2f", ferr*100.);
     *fLog << inf << endl;
 
Index: /trunk/MagicSoft/include-Classes/MMcFormat/MMcCorsikaRunHeader.h
===================================================================
--- /trunk/MagicSoft/include-Classes/MMcFormat/MMcCorsikaRunHeader.h	(revision 7408)
+++ /trunk/MagicSoft/include-Classes/MMcFormat/MMcCorsikaRunHeader.h	(revision 7409)
@@ -97,4 +97,5 @@
     Float_t GetSlopeSpec() const { return fSlopeSpec; }
     Float_t GetWobbleMode() const { return fWobbleMode; }
+    Float_t GetCorsikaVersion() const { return fCorsikaVersion; }
 
     Int_t GetNumCT() const { return fNumCT; }
