Index: trunk/MagicSoft/Mars/macros/rootlogon.C
===================================================================
--- trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 1516)
+++ trunk/MagicSoft/Mars/macros/rootlogon.C	(revision 1524)
@@ -95,4 +95,14 @@
     gInterpreter->AddIncludePath("mtools");
 
+    if (TString("linux")==gSystem->GetBuildArch())
+    {
+        TString options = " -O -pipe -Wall -Woverloaded-virtual -fno-rtti -fno-exceptions -fPIC ";
+
+        TString s = "cd $BuildDir ; ";
+        s += "g++ -c" + options + "-Iinclude -D_REENTRANT $IncludePath $SourceFiles ; ";
+        s += "g++ $ObjectFiles -shared -Wl,-soname,$LibName.so -O -o $SharedLib";
+        gSystem->SetMakeSharedLib(s);
+    }
+
     cout << "Welcome to the Mars Root environment." << endl;
 
Index: trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1524)
@@ -36,4 +36,7 @@
 #pragma link C++ class MEnergyEst+;
 #pragma link C++ class MEnergyEstimate+;
+#pragma link C++ class MEnergyEstParam+;
+
+#pragma link C++ class MMatrixLoop+;
 
 #pragma link C++ class MPedCalcPedRun+;
Index: trunk/MagicSoft/Mars/manalysis/MEnergyEst.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MEnergyEst.h	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/MEnergyEst.h	(revision 1524)
@@ -10,4 +10,5 @@
 private:
     Double_t fEnergy; // [GeV] Estimated Energy
+    Double_t fImpact; // [cm]  Estimated Impact
 
 public:
@@ -15,7 +16,11 @@
 
     void SetEnergy(Double_t e) { fEnergy = e; }
+    void SetImpact(Double_t i) { fImpact = i; }
     Double_t GetEnergy() const { return fEnergy; }
+    Double_t GetImpact() const { return fImpact; }
 
-    ClassDef(MEnergyEst, 1) // Storage Container for the estimated Energy
+    void Print(Option_t *o="") const;
+
+    ClassDef(MEnergyEst, 0) // Storage Container for the estimated Energy
 };
 
Index: trunk/MagicSoft/Mars/manalysis/MHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 1524)
@@ -55,4 +55,5 @@
 #include <fstream.h>
 
+#include <TArrayF.h>
 #include <TEllipse.h>
 
@@ -78,5 +79,4 @@
 
     Reset();
-    // FIXME: (intelligent) initialization of values missing
 
     fEllipse = new TEllipse;
@@ -380,4 +380,26 @@
 // --------------------------------------------------------------------------
 //
+// This function is ment for special usage, please never try to set
+// values via this function
+//
+void MHillas::Set(const TArrayF &arr)
+{
+    if (arr.GetSize() != 8)
+        return;
+
+    fLength = arr.At(0);  // [mm]        major axis of ellipse
+    fWidth  = arr.At(1);  // [mm]        minor axis of ellipse
+    fDelta  = arr.At(2);  // [rad]       angle of major axis with x-axis
+    fSize   = arr.At(3);  // [#CerPhot]  sum of content of all pixels (number of Cherenkov photons)
+    fMeanX  = arr.At(4);  // [mm]        x-coordinate of center of ellipse
+    fMeanY  = arr.At(5);  // [mm]        y-coordinate of center of ellipse
+
+    fNumUsedPixels = (Short_t)arr.At(6); // Number of pixels which survived the image cleaning
+    fNumCorePixels = (Short_t)arr.At(7); // number of core pixels
+}
+
+
+// --------------------------------------------------------------------------
+//
 /*
 void MHillas::AsciiRead(ifstream &fin)
Index: trunk/MagicSoft/Mars/manalysis/MHillas.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillas.h	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/MHillas.h	(revision 1524)
@@ -6,4 +6,5 @@
 #endif
 
+class TArrayF;
 class TEllipse;
 
@@ -62,4 +63,6 @@
     Int_t GetNumCorePixels() const { return fNumCorePixels; }
 
+    virtual void Set(const TArrayF &arr);
+
     //virtual void AsciiRead(ifstream &fin);
     //virtual void AsciiWrite(ofstream &fout) const;
Index: trunk/MagicSoft/Mars/manalysis/MHillasExt.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasExt.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/MHillasExt.cc	(revision 1524)
@@ -37,6 +37,4 @@
 // fM3Long   third moment along major axis
 // fM3Trans  third moment along minor axis
-// fLeakage1 ratio : (photons in most outer ring of pixels) over fSize
-// fLeakage2 ratio : (photons in the 2 outer rings of pixels) over fSize
 //
 // WARNING: Before you can use fAsym, fM3Long and fM3Trans you must
@@ -45,4 +43,7 @@
 ////////////////////////////////////////////////////////////////////////////
 /*
+ // fLeakage1 ratio : (photons in most outer ring of pixels) over fSize
+ // fLeakage2 ratio : (photons in the 2 outer rings of pixels) over fSize
+ //
  // fAsymna   d/(d na) of ( sum(x*q^na)/sum(q^na), sum(y*q^na)/sum(q^na) )
  //           projected onto the major axis
@@ -52,4 +53,5 @@
 
 #include <fstream.h>
+#include <TArrayF.h>
 
 #include "MGeomPix.h"
@@ -238,4 +240,25 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// This function is ment for special usage, please never try to set
+// values via this function
+//
+void MHillasExt::Set(const TArrayF &arr)
+{
+    if (arr.GetSize() != 13)
+        return;
+
+    fConc    = arr.At(8);  // [ratio] concentration ratio: sum of the two highest pixels / fSize
+    fConc1   = arr.At(9);  // [ratio] concentration ratio: sum of the highest pixel / fSize
+    fAsym    = arr.At(10); // [mm]    fDist minus dist: center of ellipse, highest pixel
+    fM3Long  = arr.At(11); // [mm]    3rd moment (e-weighted) along major axis
+    fM3Trans = arr.At(12); // [mm]    3rd moment (e-weighted) along minor axis
+
+    TArrayF n(arr);
+    n.Set(8);
+    MHillas::Set(n);
+}
+
 /*
 // -------------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/manalysis/MHillasExt.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasExt.h	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/MHillasExt.h	(revision 1524)
@@ -34,4 +34,6 @@
     void Print(Option_t *opt=NULL) const;
 
+    void Set(const TArrayF &arr);
+
     //void AsciiRead(ifstream &fin);
     //void AsciiWrite(ofstream &fout) const;
Index: trunk/MagicSoft/Mars/manalysis/MHillasSrc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasSrc.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/MHillasSrc.cc	(revision 1524)
@@ -54,4 +54,5 @@
 
 #include <fstream.h>
+#include <TArrayF.h>
 
 #include "MLog.h"
@@ -141,4 +142,19 @@
     *fLog << " - CosDeltaAlpha       = " << fCosDeltaAlpha << endl;
 }
+// --------------------------------------------------------------------------
+//
+// This function is ment for special usage, please never try to set
+// values via this function
+//
+void MHillasSrc::Set(const TArrayF &arr)
+{
+    if (arr.GetSize() != 4)
+        return;
+
+    fAlpha = arr.At(0);         // [deg]  angle of major axis with vector to src
+    fDist  = arr.At(1);         // [mm]   distance between src and center of ellipse
+    fHeadTail  = arr.At(2);     // [mm]
+    fCosDeltaAlpha = arr.At(3); // [1]    cosine of angle between d and a
+}
 
 // -----------------------------------------------------------------------
Index: trunk/MagicSoft/Mars/manalysis/MHillasSrc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillasSrc.h	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/MHillasSrc.h	(revision 1524)
@@ -42,4 +42,6 @@
     virtual Bool_t Calc(const MHillas *hillas);
 
+    void Set(const TArrayF &arr);
+
     //virtual void AsciiRead(ifstream &fin);
     //virtual void AsciiWrite(ofstream &fout) const;
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1516)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1524)
@@ -36,7 +36,9 @@
            MEnergyEst.cc \
            MEnergyEstimate.cc \
+           MEnergyEstParam.cc \
            MSrcPosCam.cc \
            MCameraSmooth.cc \
            MHadroness.cc \
+           MMatrixLoop.cc \
            MCompProbCalc.cc \
            MMultiDimDistCalc.cc \
Index: trunk/MagicSoft/Mars/mbase/MFilter.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MFilter.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mbase/MFilter.cc	(revision 1524)
@@ -101,4 +101,4 @@
 TString MFilter::GetRule() const
 {
-    return "<GetRule not available for " + fName + ">";
+    return "<GetRule n/a for " + fName + ">";
 }
Index: trunk/MagicSoft/Mars/mbase/MLog.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mbase/MLog.cc	(revision 1524)
@@ -75,5 +75,5 @@
 // which is used for the output (i)
 //
-MLog::MLog(int i) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(i), fGuiLineId(0), fout(NULL), fOutAllocated(kFALSE), fgui(NULL)
+MLog::MLog(int i) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(i), fIsNull(kFALSE), fGuiLineId(0), fout(NULL), fOutAllocated(kFALSE), fgui(NULL)
 {
     Init();
@@ -85,5 +85,5 @@
 // ofstream as the default output device
 //
-MLog::MLog(ofstream &out) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fGuiLineId(0),  fout(&out), fOutAllocated(kFALSE), fgui(NULL)
+MLog::MLog(ofstream &out) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fIsNull(kFALSE), fGuiLineId(0),  fout(&out), fOutAllocated(kFALSE), fgui(NULL)
 {
     Init();
@@ -106,5 +106,5 @@
 // or not.
 //
-MLog::MLog(const char *fname, int flag) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fGuiLineId(0),  fgui(NULL)
+MLog::MLog(const char *fname, int flag) : ostream(this), fPPtr(fBase), fEPtr(fBase+bsz), fOutputLevel(0), fDebugLevel((unsigned)-1), fDevice(eFile), fIsNull(kFALSE), fGuiLineId(0),  fgui(NULL)
 {
     Init();
@@ -132,5 +132,13 @@
 void MLog::WriteBuffer()
 {
+    //
+    // restart writing to the buffer at its first char
+    //
     const int len = fPPtr - fBase;
+
+    fPPtr = fBase;
+
+    if (fIsNull)
+        return;
 
     if (fDevice&eStdout)
@@ -153,9 +161,4 @@
         delete dummy;
     }
-
-    //
-    // restart writing to the buffer at its first char
-    //
-    fPPtr = fBase;
 }
 
Index: trunk/MagicSoft/Mars/mbase/MLog.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLog.h	(revision 1516)
+++ trunk/MagicSoft/Mars/mbase/MLog.h	(revision 1524)
@@ -31,4 +31,6 @@
     UInt_t fDebugLevel;      //! Present global debug level
     UInt_t fDevice;          //! Flag to indicate the present streams
+
+    Bool_t fIsNull;          //! Switch output completely off
 
     Int_t fGuiLineId;
@@ -122,4 +124,6 @@
     }
 
+    void SetNullOutput(Bool_t n=kTRUE) { fIsNull = n; }
+
     ClassDef(MLog, 0) // This is what we call 'The logging system'
 };
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1524)
@@ -50,4 +50,6 @@
 #include "MLogManip.h"
 
+#include "MIter.h"
+
 ClassImp(MParList);
 
@@ -105,5 +107,9 @@
     //     automatically deleted.
     //
-    TestBit(kIsOwner) ? fContainer->SetOwner() : fAutodelete->SetOwner();
+    IsOwner() ? fContainer->SetOwner() : fAutodelete->SetOwner();
+
+    // FIXME? If fContainer is owner do we have to remove the object
+    //   from fAutodelete due to the acces when checking for a
+    //   garbage collection?
 
     delete fContainer;
@@ -236,16 +242,43 @@
     {
         *fLog << warn << "No object with the same name '";
-        *fLog << cont->GetName() << "' in list... ignored." << endl;
-        return kFALSE;
+        *fLog << cont->GetName() << "' in list... adding." << endl;
+        return AddToList(cont);
     }
 
     fContainer->Remove(obj);
 
-    if (TestBit(kIsOwner) && !fAutodelete->FindObject(obj))
+    if (IsOwner() && !fAutodelete->FindObject(obj))
         delete obj;
 
-    *fLog << inf << "MParContainer '" << obj->GetName() << "' found and replaced..." << endl;
+    *fLog << inf << "MParContainer '" << cont->GetName() << "' found and replaced..." << endl;
 
     return AddToList(cont);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Find an object with the same name in the list and remove it.
+//  If the kIsOwner flag is set and the object was not created
+//  automatically, the object is deleted.
+//
+void MParList::Remove(MParContainer *cont)
+{
+    //
+    //  check if the object (you want to add) exists
+    //
+    if (!cont)
+        return;
+
+    TObject *obj = fContainer->Remove(cont);
+    if (!obj)
+    {
+        *fLog << warn << "Object not found in list..." << endl;
+        return;
+    }
+
+    *fLog << inf << "MParContainer '" << cont->GetName() << "' removed..." << endl;
+
+    if (IsOwner() && !fAutodelete->FindObject(obj))
+        delete obj;
 }
 
@@ -470,5 +503,10 @@
     TIter Next(fContainer);
     while ((obj=(MParContainer*)Next()))
-        *fLog << " " << obj->GetDescriptor() << endl;
+    {
+        *fLog << " " << obj->GetDescriptor();
+        if (fAutodelete->FindObject(obj))
+            *fLog << " <autodel>";
+        *fLog << endl;
+    }
     *fLog << endl;
 }
@@ -492,5 +530,5 @@
 {
     fContainer->ForEach(MParContainer, Reset)();
-}
+ }
 
 // --------------------------------------------------------------------------
@@ -663,4 +701,30 @@
 }
 
+void MParList::SavePrimitive(ofstream &out, Option_t *o)
+{
+    Bool_t saved = IsSavedAsPrimitive();
+
+    MParContainer::SavePrimitive(out);
+
+    MIter Next(fContainer);
+
+    MParContainer *cont = NULL;
+    while ((cont=Next()))
+    {
+        //
+        // Because it was automatically created don't store its primitive
+        // I guess it will be automatically created again
+        //
+        if (fAutodelete->FindObject(cont) || cont->IsSavedAsPrimitive())
+            continue;
+
+        cont->SavePrimitive(out, "");
+
+        out << "   " << GetUniqueName() << ".";
+        out << (cont->InheritsFrom("MTaskList") && saved ? "Replace" : "AddToList");
+        out << "(&" << cont->GetUniqueName() << ");" << endl << endl;
+    }
+}
+
 // --------------------------------------------------------------------------
 //
@@ -680,15 +744,4 @@
     }
     out << ";" << endl << endl;
-
-    TIter Next(fContainer);
-
-    MParContainer *cont = NULL;
-    while ((cont=(MParContainer*)Next()))
-    {
-        cont->SavePrimitive(out, "");
-
-        out << "   " << GetUniqueName() << ".AddToList(&";
-        out << cont->GetUniqueName() << ");" << endl << endl;
-    }
 }
 
Index: trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1516)
+++ trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1524)
@@ -36,4 +36,6 @@
 
 public:
+    enum { kDoNotReset = BIT(15) };
+
     MParList(const char *name=NULL, const char *title=NULL);
     MParList(MParList &ts);
@@ -45,4 +47,5 @@
 
     Bool_t Replace(MParContainer *obj);
+    void   Remove(MParContainer *obj);
 
     void SetLogStream(MLog *log);
@@ -78,4 +81,5 @@
 
     void SetOwner(Bool_t enable=kTRUE);
+    Bool_t IsOwner() const { return TestBit(kIsOwner); }
 
     void Print(Option_t *t = NULL) const;
@@ -84,4 +88,6 @@
     void SetNames(TObjArray &arr);
 
+    void SavePrimitive(ofstream &out, Option_t *o="");
+
     ClassDef(MParList, 1) // list of parameter containers (MParContainer)
 };
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1524)
@@ -372,9 +372,14 @@
     // Reset all containers.
     //
-    // FIXME: To run a tasklist as a single task in another tasklist we
-    //        have to make sure, that the Parameter list isn't reset.
-    //
-    fParList->SetReadyToSave(kFALSE);
-    fParList->Reset();
+    // Make sure, that the parameter list is not reset from a tasklist
+    // running as a task in another tasklist.
+    //
+    const Bool_t noreset = fParList->TestBit(MParList::kDoNotReset);
+    if (!noreset)
+    {
+        fParList->SetReadyToSave();
+        fParList->Reset();
+        fParList->SetBit(MParList::kDoNotReset);
+    }
 
     //
@@ -428,4 +433,7 @@
     }
 
+    if (!noreset)
+        fParList->ResetBit(MParList::kDoNotReset);
+
     return kTRUE;
 }
Index: trunk/MagicSoft/Mars/mdata/DataLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/DataLinkDef.h	(revision 1516)
+++ trunk/MagicSoft/Mars/mdata/DataLinkDef.h	(revision 1524)
@@ -7,4 +7,5 @@
 #pragma link C++ class MData+;
 #pragma link C++ class MDataArray+;
+#pragma link C++ class MDataElement+;
 #pragma link C++ class MDataList+;
 #pragma link C++ class MDataValue+;
Index: trunk/MagicSoft/Mars/mdata/MDataChain.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 1524)
@@ -91,5 +91,6 @@
 #include "MDataValue.h"
 #include "MDataMember.h"
-#
+#include "MDataElement.h"
+
 ClassImp(MDataChain);
 
@@ -164,5 +165,5 @@
     for (int i=0; i<l; i++)
     {
-        if (!isalnum(txt[i]) && txt[i]!='.' &&
+        if (!isalnum(txt[i]) && txt[i]!='.' && /*txt[i]!='['&&txt[i]!=']'&&*/
             ((txt[i]!='-' && txt[i]!='+') || i!=0))
             return i;
@@ -172,12 +173,12 @@
 }
 
-Int_t MDataChain::GetBracket(TString txt)
+Int_t MDataChain::GetBracket(TString txt, char open, char close)
 {
     Int_t first=1;
     for (int cnt=0; first<txt.Length(); first++)
     {
-        if (txt[first]=='(')
+        if (txt[first]==open)
             cnt++;
-        if (txt[first]==')')
+        if (txt[first]==close)
             cnt--;
         if (cnt==-1)
@@ -197,4 +198,5 @@
 
     if (txt=="abs")   return kEAbs;
+    if (txt=="fabs")  return kEAbs;
     if (txt=="log")   return kELog;
     if (txt=="log10") return kELog10;
@@ -238,5 +240,5 @@
                 // Search for the corresponding bracket
                 //
-                Int_t first=GetBracket(txt);
+                Int_t first=GetBracket(txt, '(', ')');
 
                 if (first==txt.Length())
@@ -364,4 +366,13 @@
             txt = txt.Strip(TString::kBoth);
 
+            if (!txt.IsNull() && txt[0]=='[')
+            {
+                Int_t first = GetBracket(txt, '[', ']');
+                TString op  = txt(1, first-1);
+                txt.Remove(0, first+1);
+
+                newmember = new MDataElement(text, atoi(op));
+                break;
+            }
             if ((txt.IsNull() || txt[0]!='(') && text[0]!='-' && text[0]!='+')
             {
@@ -379,10 +390,9 @@
             }
 
-            Int_t first = GetBracket(txt);
+            Int_t first = GetBracket(txt, '(', ')');
             TString sub = op==kENegative || op==kEPositive ? text.Remove(0,1) + txt : txt(1, first-1);
             txt.Remove(0, first+1);
 
             newmember = new MDataChain(sub, op);
-
             if (!newmember->IsValid())
             {
Index: trunk/MagicSoft/Mars/mdata/MDataChain.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 1516)
+++ trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 1524)
@@ -46,5 +46,5 @@
 
     Int_t IsAlNum(TString txt);
-    Int_t GetBracket(TString txt);
+    Int_t GetBracket(TString txt, char open, char close);
 
     MData *ParseString(TString txt, Int_t level);
Index: trunk/MagicSoft/Mars/mdata/MDataElement.cc
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataElement.cc	(revision 1524)
+++ trunk/MagicSoft/Mars/mdata/MDataElement.cc	(revision 1524)
@@ -0,0 +1,118 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//   MDataElement
+//
+//  This MData class is used for accessing a column of an MHMatrix object.
+//    eg. MDataElement("Matrix", 5)
+//  will return the 5th column of the MHMatrix object called Matrix.
+//
+//  The row which is accessed must be set before by using
+//  MHMatrix::SetNumRow. If you want to loop through a matrix use
+//  MMatrixLoop.
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MDataElement.h"
+
+#include <fstream.h>
+
+#include "MHMatrix.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+
+ClassImp(MDataElement);
+
+// --------------------------------------------------------------------------
+//
+// Specify the name of the MHMatrix-object and the column you want to
+// access.
+//
+MDataElement::MDataElement(const char *member, Int_t col)
+    : fMatrixName(member), fNumCol(col), fMatrix(NULL)
+{
+}
+
+// --------------------------------------------------------------------------
+//
+// Specify the pointer of the MHMatrix-object and the column you want to
+// access.
+//
+MDataElement::MDataElement(MHMatrix *mat, Int_t col)
+    : fMatrixName(mat->GetName()), fNumCol(col), fMatrix(mat)
+{
+}
+
+// --------------------------------------------------------------------------
+//
+// returns the value you requested
+//
+Double_t MDataElement::GetValue() const
+{
+    return fMatrix ? (*fMatrix)[fNumCol] : 0;
+}
+
+// --------------------------------------------------------------------------
+//
+//  If the pointer to the MHMatrix isn't yet set search for it in the
+// parameter list.
+//
+Bool_t MDataElement::PreProcess(const MParList *plist)
+{
+    if (fMatrix)
+        return kTRUE;
+
+    fMatrix = (MHMatrix*)plist->FindObject(fMatrixName, "MHMatrix");
+    if (!fMatrix)
+    {
+        *fLog << err << "MHMatrix '" << fMatrixName << "' not in parameter list... aborting." << endl;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns the ready-to-save flag of the data member container
+//
+Bool_t MDataElement::IsReadyToSave() const
+{
+    return IsValid() ? fMatrix->IsReadyToSave() : kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Return the rule used to identify this object in a datachain
+//
+TString MDataElement::GetRule() const
+{
+    TString rule = fMatrixName + "[";
+    rule += fNumCol;
+    return rule+"]";
+}
Index: trunk/MagicSoft/Mars/mdata/MDataElement.h
===================================================================
--- trunk/MagicSoft/Mars/mdata/MDataElement.h	(revision 1524)
+++ trunk/MagicSoft/Mars/mdata/MDataElement.h	(revision 1524)
@@ -0,0 +1,41 @@
+#ifndef MARS_MDataElement
+#define MARS_MDataElement
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//  MDataElement                                                           //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+#ifndef MARS_MData
+#include "MData.h"
+#endif
+
+class MHMatrix;
+
+class MDataElement : public MData
+{
+private:
+    TString   fMatrixName;
+    Int_t     fNumCol;
+
+    MHMatrix *fMatrix;
+
+public:
+    MDataElement(const char *member=NULL, Int_t col=-1);
+    MDataElement(MHMatrix *mat, Int_t col=-1);
+
+    Double_t GetValue() const;
+    Bool_t PreProcess(const MParList *plist);
+
+    Bool_t IsValid() const { return kTRUE; }
+    Bool_t IsReadyToSave() const;
+
+    //void Print(Option_t *opt = "") const;
+    TString GetRule() const;
+
+    Double_t operator()() { return GetValue(); }
+
+    ClassDef(MDataElement, 1) // MData object corresponding to a element of an MHMatrix
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mdata/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mdata/Makefile	(revision 1516)
+++ trunk/MagicSoft/Mars/mdata/Makefile	(revision 1524)
@@ -20,5 +20,5 @@
 # @endcode 
 
-INCLUDES = -I. -I../mbase
+INCLUDES = -I. -I../mbase -I../mhist
 
 # @code 
@@ -33,4 +33,5 @@
 SRCFILES = MData.cc \
 	   MDataArray.cc \
+           MDataElement.cc \
 	   MDataMember.cc \
 	   MDataValue.cc \
Index: trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1524)
@@ -62,10 +62,12 @@
 #include <fstream.h>
 
+#include <TPad.h>
+#include <TStyle.h>
+#include <TCanvas.h>
+
 #include <TH2.h>
 #include <TH3.h>
 #include <TProfile.h>
 #include <TProfile2D.h>
-#include <TPad.h>
-#include <TCanvas.h>
 
 #include "MLog.h"
@@ -73,5 +75,5 @@
 
 #include "MParList.h"
-
+#include "MBinning.h"
 #include "MDataChain.h"
 
@@ -202,4 +204,6 @@
             return kFALSE;
         }
+        if (binsz->IsLogarithmic())
+            fHist->SetBit(kIsLogz);
         fHist->SetZTitle(fData[2]->GetTitle());
         if (!fData[2]->PreProcess(plist))
@@ -212,4 +216,6 @@
             return kFALSE;
         }
+        if (binsy->IsLogarithmic())
+            fHist->SetBit(kIsLogy);
         fHist->SetYTitle(fData[1]->GetTitle());
         if (!fData[1]->PreProcess(plist))
@@ -222,4 +228,6 @@
             return kFALSE;
         }
+        if (binsx->IsLogarithmic())
+            fHist->SetBit(kIsLogx);
         fHist->SetXTitle(fData[0]->GetTitle());
         if (!fData[0]->PreProcess(plist))
@@ -306,8 +314,78 @@
     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);
+}
+*/
+// --------------------------------------------------------------------------
+//
+// Setup a inversed deep blue sea palette for the fCenter histogram.
+//
+void MH3::SetColors() const
+{
+    // FIXME: This must be redone each time the canvas is repainted....
+    gStyle->SetPalette(51, NULL);
+    Int_t c[50];
+    for (int i=0; i<50; i++)
+        c[49-i] = gStyle->GetColorPalette(i);
+    gStyle->SetPalette(50, c);
+}
 
 // --------------------------------------------------------------------------
 //
 // Draw clone of histogram. So that the object can be deleted
+//
+// Possible options are:
+//   PROFX: Draw a x-profile into the histogram (for 2D histograms only)
+//   PROFY: Draw a y-profile into the histogram (for 2D histograms only)
+//   ONLY:  Draw the profile histogram only (for 2D histograms only)
+//
+// If the kIsLog?-Bit is set the axis is displayed lkogarithmically.
+// eg this is set when applying a logarithmic MBinning
+//
 // and the histogram is still visible in the canvas.
 // The cloned object are deleted together with the canvas if the canvas is
@@ -324,11 +402,17 @@
     gROOT->SetSelectedPad(NULL);
 
-    fHist->DrawCopy(opt);
-
     TString str(opt);
+
+    if (str.Contains("COL", TString::kIgnoreCase))
+        SetColors();
+
+    Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2;
+    if (!only)
+        fHist->DrawCopy(opt);
+
     if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2)
     {
         TProfile *p = ((TH2*)fHist)->ProfileX();
-        p->Draw("same");
+        p->Draw(only?"":"same");
         p->SetBit(kCanDelete);
         p->SetDirectory(NULL);
@@ -337,9 +421,13 @@
     {
         TProfile *p = ((TH2*)fHist)->ProfileY();
-        p->Draw("same");
+        p->Draw(only?"":"same");
         p->SetBit(kCanDelete);
         p->SetDirectory(NULL);
     }
 
+    if (fHist->TestBit(kIsLogx)) c.SetLogx();
+    if (fHist->TestBit(kIsLogy)) c.SetLogy();
+    if (fHist->TestBit(kIsLogz)) c.SetLogz();
+
     c.Modified();
     c.Update();
@@ -351,4 +439,13 @@
 //
 // Creates a new canvas and draws the histogram into it.
+//
+// Possible options are:
+//   PROFX: Draw a x-profile into the histogram (for 2D histograms only)
+//   PROFY: Draw a y-profile into the histogram (for 2D histograms only)
+//   ONLY:  Draw the profile histogram only (for 2D histograms only)
+//
+// If the kIsLog?-Bit is set the axis is displayed lkogarithmically.
+// eg this is set when applying a logarithmic MBinning
+//
 // Be careful: The histogram belongs to this object and won't get deleted
 // together with the canvas.
@@ -359,11 +456,17 @@
         MH::MakeDefCanvas(fHist);
 
-    fHist->Draw(opt);
-
     TString str(opt);
+
+    if (str.Contains("COL", TString::kIgnoreCase))
+        SetColors();
+
+    Bool_t only = str.Contains("ONLY", TString::kIgnoreCase) && fDimension==2;
+    if (!only)
+        fHist->Draw(opt);
+
     if (str.Contains("PROFX", TString::kIgnoreCase) && fDimension==2)
     {
         TProfile *p = ((TH2*)fHist)->ProfileX();
-        p->Draw("same");
+        p->Draw(only?"":"same");
         p->SetBit(kCanDelete);
         p->SetDirectory(NULL);
@@ -372,8 +475,12 @@
     {
         TProfile *p = ((TH2*)fHist)->ProfileY();
-        p->Draw("same");
+        p->Draw(only?"":"same");
         p->SetBit(kCanDelete);
         p->SetDirectory(NULL);
     }
+
+    if (fHist->TestBit(kIsLogx)) gPad->SetLogx();
+    if (fHist->TestBit(kIsLogy)) gPad->SetLogy();
+    if (fHist->TestBit(kIsLogz)) gPad->SetLogz();
 
     gPad->Modified();
Index: trunk/MagicSoft/Mars/mhist/MH3.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1516)
+++ trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1524)
@@ -26,4 +26,10 @@
     void StreamPrimitive(ofstream &out) const;
 
+    enum {
+        kIsLogx = BIT(15),
+        kIsLogy = BIT(16),
+        kIsLogz = BIT(17)
+    };
+
 public:
     MH3();
@@ -48,4 +54,5 @@
     const TH1 &GetHist() const { return *fHist; }
 
+    void SetColors() const;
     void Draw(Option_t *opt=NULL);
     TObject *DrawClone(Option_t *opt=NULL) const;
Index: trunk/MagicSoft/Mars/mhist/MHHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 1524)
@@ -170,7 +170,17 @@
     const MBinning *bins = (MBinning*)plist->FindObject("BinningCamera");
     if (!bins)
-        *fLog << warn << "Object 'BinningCamera' [MBinning] not found... no binning applied." << endl;
+    {
+        float r = geom ? geom->GetMaxRadius() : 600;
+        r *= 0.9;
+        if (!fUseMmScale)
+            r *= fMm2Deg;
+
+        MBinning b;
+        b.SetEdges(61, -r, r);
+        SetBinning(fCenter, &b, &b);
+    }
     else
         SetBinning(fCenter, bins, bins);
+
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1524)
@@ -56,5 +56,8 @@
 #include "MLogManip.h"
 
+#include "MFillH.h"
+#include "MEvtLoop.h"
 #include "MParList.h"
+#include "MTaskList.h"
 
 #include "MData.h"
@@ -63,6 +66,6 @@
 ClassImp(MHMatrix);
 
-static const TString gsDefName  = "MHMatrix";
-static const TString gsDefTitle = "Multidimensional Matrix";
+const TString MHMatrix::gsDefName  = "MHMatrix";
+const TString MHMatrix::gsDefTitle = "Multidimensional Matrix";
 
 // --------------------------------------------------------------------------
@@ -105,11 +108,19 @@
 // event (row) was filled into the matrix. For the syntax of the rule
 // see MDataChain.
-//
-void MHMatrix::AddColumn(const char *rule)
+// Returns the index of the new column, -1 in case of failure.
+// (0, 1, 2, ... for the 1st, 2nd, 3rd, ...)
+//
+Int_t MHMatrix::AddColumn(const char *rule)
 {
     if (fM.IsValid())
     {
         *fLog << warn << "Warning - matrix is already in use. Can't add a new column... skipped." << endl;
-        return;
+        return -1;
+    }
+
+    if (TestBit(kIsLocked))
+    {
+        *fLog << warn << "Warning - matrix is locked. Can't add new column... skipped." << endl;
+        return -1;
     }
 
@@ -121,4 +132,5 @@
 
     fData->AddEntry(rule);
+    return fData->GetNumEntries()-1;
 }
 
@@ -128,4 +140,10 @@
     {
         *fLog << warn << "Warning - matrix is already in use. Can't add new columns... skipped." << endl;
+        return;
+    }
+
+    if (TestBit(kIsLocked))
+    {
+        *fLog << warn << "Warning - matrix is locked. Can't add new columns... skipped." << endl;
         return;
     }
@@ -519,2 +537,30 @@
     fM = m;
 }
+
+Bool_t MHMatrix::Fill(MParList *plist, MTask *read)
+{
+    //
+    // Read data into Matrix
+    //
+    const Bool_t is = plist->IsOwner();
+    plist->SetOwner(kFALSE);
+
+    MTaskList tlist;
+    plist->Replace(&tlist);
+
+    MFillH fillh(this);
+
+    tlist.AddToList(read);
+    tlist.AddToList(&fillh);
+
+    MEvtLoop evtloop;
+    evtloop.SetParList(plist);
+
+    if (!evtloop.Eventloop())
+        return kFALSE;
+
+    plist->Remove(&tlist);
+    plist->SetOwner(is);
+
+    return kTRUE;
+}
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1516)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1524)
@@ -1,4 +1,8 @@
 #ifndef MARS_MHMatrix
 #define MARS_MHMatrix
+
+#ifdef MARS_MLogManip
+#error Please make ensure that MLogManip.h are included _after_ MHMatrix.h
+#endif
 
 #ifndef ROOT_TMatrix
@@ -10,10 +14,17 @@
 
 class TArrayI;
+
+class MTask;
+class MParList;
 class MDataArray;
 
 class MHMatrix : public MH
 {
-protected:
+private:
+    static const TString gsDefName;  //! Default Name
+    static const TString gsDefTitle; //! Default Title
+
     Int_t   fNumRow;    //! Number of dimensions of histogram
+    Int_t   fRow;       //! Present row
     TMatrix fM;         // Matrix to be filled
 
@@ -23,5 +34,6 @@
 
     enum {
-        kIsOwner = BIT(14)
+        kIsOwner  = BIT(14),
+        kIsLocked = BIT(16)
     };
 
@@ -39,5 +51,8 @@
     ~MHMatrix();
 
-    void AddColumn(const char *name);
+    void Lock()   { SetBit(kIsLocked); }
+    void Unlock() { ResetBit(kIsLocked); }
+
+    Int_t AddColumn(const char *name);
     void AddColumns(MDataArray *mat);
 
@@ -45,4 +60,7 @@
 
     const TMatrix &GetM() const { return fM; }
+
+    Bool_t IsValid() const { return fM.IsValid(); }
+    Int_t  GetNumRows() const { return fNumRow; }
 
     //void Draw(Option_t *opt=NULL);
@@ -56,5 +74,5 @@
     Double_t CalcDist(const TVector &v, Int_t num = 25);
 
-    void SetIOwner(Bool_t b=kTRUE) { b ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
+    void SetOwner(Bool_t b=kTRUE) { b ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
 
     void Reassign();
@@ -63,4 +81,10 @@
     void SortMatrixByColumn(Int_t ncol=0, Bool_t desc=kTRUE);
 
+    Bool_t SetNumRow(Int_t row) { if (row>=fNumRow || row<0) return kFALSE; fRow = row; return kTRUE; }
+    Int_t GetNumRow() const { return fRow; };
+    Double_t operator[](Int_t col) { return fM(fRow, col); }
+
+    Bool_t Fill(MParList *plist, MTask *read);
+
     ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events
 };
Index: trunk/MagicSoft/Mars/mhist/MHStarMap.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 1516)
+++ trunk/MagicSoft/Mars/mhist/MHStarMap.cc	(revision 1524)
@@ -73,5 +73,5 @@
     //   connect all the histogram with the container fHist
     //
-    fStarMap = new TH2F("StarMap", "2D Hillas Star Map",
+    fStarMap = new TH2F("StarMap", " 2D Hillas Star Map ",
                         150, -300, 300,
                         150, -300, 300);
@@ -96,5 +96,5 @@
 //
 // Setup the Binning for the histograms automatically if the correct
-// instances of MBinning (with the names 'BinningWidth' and 'BinningLength')
+// instances of MBinning (with the names 'BinningCamera')
 // are found in the parameter list
 // Use this function if you want to set the conversion factor which
