Index: trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1574)
@@ -8,4 +8,5 @@
 
 #pragma link C++ class MH+;
+#pragma link C++ class MHArray+;
 #pragma link C++ class MH3+;
 
Index: trunk/MagicSoft/Mars/mhist/MFillH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1574)
@@ -71,11 +71,95 @@
 #include <fstream.h>
 
+#include <TClass.h>
+
+#include "MDataChain.h"
+
 #include "MLog.h"
 #include "MLogManip.h"
 
 #include "MH.h"
+#include "MHArray.h"
+
 #include "MParList.h"
 
 ClassImp(MFillH);
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MMap
+//
+// This class maps a key-value to a given value. In its simple versions it
+// maps a key to an index.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include <TArrayI.h>
+
+class MMap
+{
+private:
+    TArrayI fKeys;
+    TArrayI fValues;
+
+    Int_t K(Int_t i) const { return ((TArrayI)fKeys)[i]; }
+    Int_t V(Int_t i) const { return ((TArrayI)fValues)[i]; }
+
+public:
+    // --------------------------------------------------------------------------
+    //
+    // Get the value which corresponds to the given key-value
+    //
+    Int_t GetValue(Int_t key) const
+    {
+        const Int_t n = fKeys.GetSize();
+        for (int i=0; i<n; i++)
+        {
+            if (K(i)==key)
+                return V(i);
+        }
+        return -1;
+    }
+
+    // --------------------------------------------------------------------------
+    //
+    // Adds a new pair key-value. While the key is the key to the value.
+    // if the key already exists the pair is ignored.
+    //
+    void Add(Int_t key, Int_t value)
+    {
+        if (GetValue(key)>=0)
+            return;
+
+        const Int_t n = fKeys.GetSize();
+
+        fKeys.Set(n+1);
+        fValues.Set(n+1);
+
+        fKeys[n] = key;
+        fValues[n] = value;
+    }
+
+    // --------------------------------------------------------------------------
+    //
+    // Adds a new pair key-value. While the key is the key to the value.
+    // In this case the value is an automatically sequential created index.
+    // if the key already exists the pair is ignored.
+    //
+    Int_t Add(Int_t key)
+    {
+        const Int_t k = GetValue(key);
+        if (k>=0)
+            return k;
+
+        const Int_t n = fKeys.GetSize();
+
+        fKeys.Set(n+1);
+        fValues.Set(n+1);
+
+        fKeys[n] = key;
+        fValues[n] = n;
+
+        return n;
+    }
+};
 
 // --------------------------------------------------------------------------
@@ -91,4 +175,7 @@
     fH            = NULL;
     fParContainer = NULL;
+
+    fIndex  = NULL;
+    fMapIdx = new MMap;
 }
 
@@ -194,4 +281,6 @@
     fParContainerName = par;
 
+    AddToBranchList(fH->GetDataMember());
+
     if (title)
         return;
@@ -222,8 +311,54 @@
     fParContainerName = par->GetName();
 
+    AddToBranchList(fH->GetDataMember());
+
     if (!title)
         fTitle = (TString)"Fill " + hist->GetDescriptor() + " from " + par->GetDescriptor();
 }
 
+// --------------------------------------------------------------------------
+//
+// Destructor. Delete fData if existing and kCanDelete is set.
+//
+MFillH::~MFillH()
+{
+    if (fIndex)
+        if (fIndex->TestBit(kCanDelete))
+            delete fIndex;
+
+    delete fMapIdx;
+}
+
+// --------------------------------------------------------------------------
+//
+// If the histogram to be filles is a MHArray you can specify a 'rule'
+// This rule is used to create an MDataChain. The return value of the chain
+// is casted to int. Each int acts as a key. For each (new) key a new
+// histogram is created in the array. (eg for the rule
+// "MRawEvtHeader::fRunNumber" you would get one histogram per run-number)
+//
+void MFillH::SetRuleForIdx(const TString rule)
+{
+    fIndex = new MDataChain(rule);
+    fIndex->SetBit(kCanDelete);
+}
+
+// --------------------------------------------------------------------------
+//
+// If the histogram to be filles is a MHArray you can specify a MData-object
+// The return value of the object is casted to int. Each int acts as a key.
+// For each (new) key a new histogram is created in the array. (eg for
+// MDataMember("MRawEvtHeader::fRunNumber") you would get one histogram per
+// run-number)
+//
+void MFillH::SetRuleForIdx(MData *data)
+{
+    fIndex = data;
+}
+
+// --------------------------------------------------------------------------
+//
+// Extracts the name of the histogram from the MFillH argument
+//
 TString MFillH::ExtractName(const char *name) const
 {
@@ -239,4 +374,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Extracts the class-name of the histogram from the MFillH argument
+//
 TString MFillH::ExtractClass(const char *name) const
 {
@@ -265,4 +404,19 @@
 Bool_t MFillH::PreProcess(MParList *pList)
 {
+    if (fIndex)
+    {
+        if (!fIndex->PreProcess(pList))
+        {
+            *fLog << all << "PreProcessing of Index rule failed... aborting." << endl;
+            return kFALSE;
+        }
+
+        if (!fIndex->IsValid())
+        {
+            *fLog << all << "Given Index rule invalid... aborting." << endl;
+            return kFALSE;
+        }
+    }
+
     //
     // Try to get the histogram container with name fHName from list
@@ -293,8 +447,10 @@
         // 'type'.
         //
-        if (!obj->InheritsFrom(MH::Class()))
+        TClass *tcls = fIndex ? MHArray::Class() : MH::Class();
+        if (!obj->InheritsFrom(tcls))
         {
             *fLog << err << dbginf << obj->GetName() << " doesn't inherit ";
-            *fLog << "from MH - cannot be used for MFillH... aborting." << endl;
+            *fLog << "from " << tcls->GetName() << " - cannot be used for MFillH...";
+            *fLog << "aborting." << endl;
             return kFALSE;
         }
@@ -343,4 +499,11 @@
 Bool_t MFillH::Process()
 {
+    if (fIndex)
+    {
+        const Int_t key = (Int_t)fIndex->GetValue();
+        const Int_t idx = fMapIdx->Add(key);
+        ((MHArray*)fH)->SetIndex(idx);
+    }
+
     return fH->Fill(fParContainer);
 } 
@@ -396,3 +559,9 @@
 
     out << ");" << endl;
-}
+
+    if (!fIndex)
+        return;
+
+    out << "   " << GetUniqueName() << ".SetRuleForIdx(\"";
+    out << fIndex->GetRule() << "\");" << endl;
+}
Index: trunk/MagicSoft/Mars/mhist/MFillH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 1574)
@@ -7,5 +7,8 @@
 
 class MH;
+class MData;
 class MParList;
+
+class MMap;
 
 class MFillH : public MTask
@@ -15,6 +18,9 @@
     TString fParContainerName;
 
-    MH* fH;                   
+    MH* fH;
     TString fHName;
+
+    MData *fIndex;    // MData object describing the 'key' to an automatic index for an MHArray
+    MMap  *fMapIdx;   //! Map to map key-index-pair for an MHArray (MMap see MFillH.cc)
 
     TString ExtractName(const char *name) const;
@@ -32,4 +38,9 @@
     MFillH(MH *hist,         MParContainer *par,   const char *name=NULL, const char *title=NULL);
 
+    ~MFillH();
+
+    void SetRuleForIdx(const TString rule);
+    void SetRuleForIdx(MData *rule);
+
     Bool_t PreProcess(MParList *pList);
     Bool_t Process();
Index: trunk/MagicSoft/Mars/mhist/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1574)
@@ -45,4 +45,7 @@
 //  the histogram(s) by the data of a corresponding parameter container.    //
 //                                                                          //
+//  Remark: the static member function (eg MakeDefCanvas) can be called     //
+//          from everywhere using: MH::MakeDefCanvas(...)                   //
+//                                                                          //
 //////////////////////////////////////////////////////////////////////////////
 
@@ -93,6 +96,17 @@
 Bool_t MH::Fill(const MParContainer *par)
 {
-    *fLog << GetDescriptor() << ": Fill not overloaded! Can't be used!" << endl;
+    *fLog << warn << GetDescriptor() << ": Fill not overloaded! Can't be used!" << endl;
     return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// This virtual function is ment as a generalized interface to retrieve
+// a pointer to a root histogram from the MH-derived class.
+//
+TH1 *MH::GetHistByName(const TString name)
+{
+    *fLog << warn << GetDescriptor() << ": GetHistByName not overloaded! Can't be used!" << endl;
+    return NULL;
 }
 
@@ -665,2 +679,3 @@
     l.Draw();
 }
+
Index: trunk/MagicSoft/Mars/mhist/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MH.h	(revision 1574)
@@ -24,4 +24,8 @@
     virtual Bool_t Fill(const MParContainer *par);
     virtual Bool_t Finalize() { return kTRUE; }
+
+    virtual TString GetDataMember() const { return ""; }
+
+    virtual TH1 *GetHistByName(const TString name);
 
     static TCanvas *MakeDefCanvas(TString name="", const char *title="",
Index: trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1574)
@@ -83,4 +83,8 @@
 static const TString gsDefTitle = "Container for a %dD Mars Histogram";
 
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
 MH3::MH3() : fDimension(0), fHist(NULL)
 {
@@ -179,4 +183,25 @@
         if (fData[i])
             delete fData[i];
+}
+
+// --------------------------------------------------------------------------
+//
+// Return the data members used by the data chain to be used in
+// MTask::AddBranchToList
+//
+TString MH3::GetDataMember() const
+{
+    TString str=fData[0]->GetDataMember();
+    if (fData[1])
+    {
+        str += ";";
+        str += fData[1]->GetDataMember();
+    }
+    if (fData[2])
+    {
+        str += ";";
+        str += fData[2]->GetDataMember();
+    }
+    return str;
 }
 
@@ -526,2 +551,34 @@
     }
 }
+
+// --------------------------------------------------------------------------
+//
+// Used to rebuild a MH3 object of the same type (data members,
+// dimension, ...)
+//
+MParContainer *MH3::New() const
+{
+    MH3 *h = NULL;
+    switch (fDimension)
+    {
+    case 1:
+        h=new MH3(fData[0]->GetRule());
+        break;
+    case 2:
+        h=new MH3(fData[0]->GetRule(), fData[1]->GetRule());
+        break;
+    case 3:
+        h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule());
+        break;
+    }
+    switch (fDimension)
+    {
+    case 3:
+        h->SetScaleZ(fScale[2]);
+    case 2:
+        h->SetScaleY(fScale[1]);
+    case 1:
+        h->SetScaleX(fScale[0]);
+    }
+    return h;
+}
Index: trunk/MagicSoft/Mars/mhist/MH3.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1574)
@@ -51,6 +51,10 @@
     Bool_t Fill(const MParContainer *par);
 
+    TString GetDataMember() const;
+
     TH1 &GetHist() { return *fHist; }
     const TH1 &GetHist() const { return *fHist; }
+
+    TH1 *GetHistByName(const TString name) { return fHist; }
 
     void SetColors() const;
@@ -58,4 +62,6 @@
     TObject *DrawClone(Option_t *opt=NULL) const;
 
+    MParContainer *New() const;
+
     ClassDef(MH3, 1) // Generalized 1/2/3D-histogram for Mars variables
 };
Index: trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.h	(revision 1574)
@@ -39,4 +39,6 @@
     const TH3D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.h	(revision 1574)
@@ -29,5 +29,4 @@
     TH3D    fHist;
 
-
 public:
     MHAlphaEnergyTime(const char *name=NULL, const char *title=NULL);
@@ -38,4 +37,6 @@
     const TH3D *GetHist()       { return &fHist; }
     const TH3D *GetHist() const { return &fHist; }
+
+    TH1 *GetHistByName(const TString name) { return &fHist; }
 
     void Draw(Option_t *option="");
Index: trunk/MagicSoft/Mars/mhist/MHArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHArray.cc	(revision 1574)
+++ trunk/MagicSoft/Mars/mhist/MHArray.cc	(revision 1574)
@@ -0,0 +1,428 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  07/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//  MHArray
+//
+//  is a sequential collection of mars histograms. If the given index to
+//  call the Fill function of the histogram excceeds the size of the
+//  array by 1 a new entry is created.
+//
+//  With Set/Inc/DecIndex you may specify the actual index of the histogram
+//  wich should be filles by Fill.
+//
+//  Use GetH to get the current histogram, the []-operator get the histogram
+//  by its index.
+//
+//  To map a key to the index use/see MFillH, which automatically maps a
+//  key-value to the array index.
+//
+//  In the constructor istempl leads to two different behaviours of the
+//  MHArray:
+//
+//  - istempl=kTRUE tells MHArray to use the first histogram retrieved from
+//    the Parameterlist by hname to be used as a template. New histograms
+//    are not created using the root dictionary, but the New-member function
+//    (see MParConatiner)
+//  - In the case istempl=kFALSE new histograms are created using the root
+//    dictionary while hname is the class name. For the creation their
+//    default constructor is used.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MHArray.h"
+
+#include <TH1.h>
+#include <TH2.h>
+#include <TH3.h>
+#include <TStyle.h>
+#include <TGaxis.h>
+#include <TCanvas.h>
+#include <TLegend.h>
+#include <TPaveStats.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MParContainer.h"
+
+#include "MBinning.h"
+
+ClassImp(MHArray);
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. hname is the name of the histogram class which
+// is in the array.
+//
+// istempl=kTRUE tells MHArray to use the first histogram retrieved from the
+// ParameterList by hname to be used as a template. New histograms are not
+// created using the root dictionary, but the New-member function (see
+// MParConatiner)
+// In the case istempl=kFALSE new histograms are created using the root
+// dictionary while hname is the class name. For the creation their
+// default constructor is used.
+//
+MHArray::MHArray(const TString hname, Bool_t istempl, const char *name, const char *title)
+    : fIdx(0), fClass(NULL), fTemplate(NULL)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHArray";
+    fTitle = title ? TString(title) : (TString("Base class for Mars histogram arrays:") + hname);
+
+    fArray = new TList;
+    fArray->SetOwner();
+
+    if (istempl)
+    {
+        fTemplateName = hname;
+        return;
+    }
+
+    //
+    // try to get class from root environment
+    //
+    fClass = gROOT->GetClass(hname);
+    if (!fClass)
+    {
+        //
+        // if class is not existing in the root environment
+        //
+        *fLog << err << dbginf << "Class '" << hname << "' not existing in dictionary." << endl;
+    }
+
+    //
+    // check for ineritance from MH
+    //
+    if (!fClass->InheritsFrom(MH::Class()))
+    {
+        //
+        // if class doesn't inherit from MH --> error
+        //
+        *fLog << err << dbginf << "Class '" << hname << "' doesn't inherit from MH." << endl;
+        fClass = NULL;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor: Deleteing the array and all histograms which are part of the
+// array.
+//
+MHArray::~MHArray()
+{
+    fArray->Delete();
+    delete fArray;
+}
+
+
+MH &MHArray::operator[](Int_t i)
+{
+    return *(MH*)fArray->At(i);
+}
+
+MH *MHArray::At(Int_t i)
+{
+    return (MH*)fArray->At(i);
+}
+
+MH *MHArray::GetH()
+{
+    return (MH*)fArray->At(fIdx);
+}
+
+// --------------------------------------------------------------------------
+//
+// Tries to create a new histogram, adds it as last entry to the array
+// and tries to call SetupFill for it. In case of success the last entry
+// in the array is the new histogram and kTRUE is returned. Otherwise
+// kFALSE is returned.
+//
+Bool_t MHArray::CreateH()
+{
+    TString cname = fClass ? fClass->GetName() : fTemplate->IsA()->GetName();
+
+    MH *hist = NULL;
+    if (fTemplate)
+    {
+        hist = (MH*)fTemplate->New();
+    }
+    else
+    {
+        //
+        // create the parameter container of the the given class type
+        //
+        hist = (MH*)fClass->New();
+    }
+    if (!hist)
+    {
+        *fLog << err << dbginf << "Cannot create new instance of class '";
+        *fLog << cname << "' (Maybe no def. constructor)" << endl;
+        return kFALSE;
+    }
+
+    //
+    // Set the name of the container
+    //
+    if (!fTemplate)
+    {
+        TString name = TString(hist->GetName())+";";
+        name += fIdx;
+
+        hist->SetName(name);
+    }
+
+    //
+    // Try to setup filling for the histogram
+    //
+    if (!hist->SetupFill(fParList))
+    {
+        *fLog << err << dbginf << "SetupFill for new histogram of type '";
+        *fLog << cname << "' with Index #" << fIdx << " failed." << endl;
+        delete hist;
+        return kFALSE;
+    }
+
+    fArray->AddLast(hist);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns kFALSE if the class couldn't be found in the root dictionary or
+// if it doesn't inherit from MH.
+// The parameter list is remembert to be used for SetupFill in case a new
+// histogram is created.
+// The index is reset to 0
+//
+Bool_t MHArray::SetupFill(const MParList *pList)
+{
+    fParList = pList;
+    fIdx = 0;
+
+    if (!fTemplateName.IsNull())
+    {
+        fTemplate = (MH*)pList->FindObject(fTemplateName, "MH");
+        return fTemplate ? kTRUE : kFALSE;
+    }
+
+    return fClass ? kTRUE : kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Call Fill for the present histogram index. If the index is out of
+// bounds the event is skipped. If the index is the number of current
+// histograms in the array a new histogram is created and if creation was
+// successfull filled.
+//
+Bool_t MHArray::Fill(const MParContainer *par)
+{
+    const Int_t n = fArray->GetSize();
+
+    if (fIdx <0 || fIdx>n)
+    {
+        *fLog << warn << "Histogram Index #" << fIdx << " out of bounds (>";
+        *fLog << n << ")... skipped." << endl;
+        return kCONTINUE;
+    }
+
+    if (fIdx==n)
+        if (!CreateH())
+            return kFALSE;
+
+    return GetH()->Fill(par);
+}
+
+// --------------------------------------------------------------------------
+//
+// Calls Finalize for all histograms in the list. If at least one Finalize
+// fails kFALSE is returned.
+//
+Bool_t MHArray::Finalize()
+{
+    Bool_t rc = kTRUE;
+
+    TIter Next(fArray);
+    MH *hist = NULL;
+
+    while ((hist=(MH*)Next()))
+        if (!hist->Finalize())
+            rc = kFALSE;
+
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the number of entries in the array
+//
+void MHArray::Print(Option_t *option="") const
+{
+    *fLog << all << GetDescriptor() << " contains " << fArray->GetSize();
+    *fLog << " histograms." << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// The option is the name of the histogram, used to get a histogram from
+// the MH entries by calling their GetHist function.
+//
+void MHArray::Draw(Option_t *opt="")
+{
+    if (!gPad)
+        MH::MakeDefCanvas(this);
+
+    const Stat_t sstyle = gStyle->GetOptStat();
+    gStyle->SetOptStat(0);
+
+    TIter Next(fArray);
+    MH *hist = (MH*)Next();
+
+    Int_t col=2;
+    Double_t max=0;
+    Double_t min=0;
+
+    TH1 *h1=NULL;
+
+    if (hist)
+    {
+        if ((h1 = hist->GetHistByName(opt)))
+        {
+            h1->Draw();
+            h1->SetLineColor(col++);
+            max = h1->GetMaximum();
+            min = h1->GetMinimum();
+        }
+    }
+
+    while ((hist=(MH*)Next()))
+    {
+        TH1 *h=NULL;
+
+        if (!(h = hist->GetHistByName(opt)))
+            continue;
+
+        h->Draw("same");
+        h->SetLineColor(col++);
+        if (max<h->GetMaximum())
+            max = h->GetMaximum();
+        if (min>h->GetMinimum())
+            min = h->GetMinimum();
+    }
+
+    if (h1)
+    {
+        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
+        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
+    }
+    gPad->Modified();
+    gPad->Update();
+
+    gStyle->SetOptStat(sstyle);
+}
+
+// --------------------------------------------------------------------------
+//
+// The option is the name of the histogram, used to get a histogram from
+// the MH entries by calling their GetHistByName function.
+// If the option also contains 'nonew' no new canvas is created.
+//
+TObject *MHArray::DrawClone(Option_t *opt="") const
+{
+    TString o(opt);
+
+    TCanvas *c = NULL;
+
+    Int_t nonew = o.Index("nonew", TString::kIgnoreCase);
+    if (nonew>=0)
+    {
+        c = MH::MakeDefCanvas(this);
+
+        //
+        // This is necessary to get the expected bahviour of DrawClone
+        //
+        gROOT->SetSelectedPad(NULL);
+
+        o.Remove(nonew, 5);
+    }
+
+    const Stat_t sstyle = gStyle->GetOptStat();
+    gStyle->SetOptStat(0);
+
+    TIter Next(fArray);
+    MH *hist = (MH*)Next();
+
+    Int_t col=2;
+    Double_t max=0;
+    Double_t min=0;
+
+    TH1 *h1=NULL;
+
+    if (hist)
+    {
+        if ((h1 = hist->GetHistByName(o)))
+        {
+            h1 = (TH1*)h1->DrawCopy();
+            h1->SetMarkerColor(col);
+            h1->SetLineColor(col++);
+            h1->SetFillStyle(4000);
+            max = h1->GetMaximum();
+            min = h1->GetMinimum();
+        }
+    }
+
+    while ((hist=(MH*)Next()))
+    {
+        TH1 *h=NULL;
+
+        if (!(h = hist->GetHistByName(o)))
+            continue;
+
+        h = (TH1*)h->DrawCopy("same");
+        h->SetMarkerColor(col);
+        h->SetLineColor(col++);
+        h->SetFillStyle(4000);
+        if (max<h->GetMaximum())
+            max = h->GetMaximum();
+        if (min>h->GetMinimum())
+            min = h->GetMinimum();
+    }
+
+    if (h1)
+    {
+        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
+        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
+    }
+    gPad->Modified();
+    gPad->Update();
+
+    gStyle->SetOptStat(sstyle);
+
+    return c;
+}
Index: trunk/MagicSoft/Mars/mhist/MHArray.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHArray.h	(revision 1574)
+++ trunk/MagicSoft/Mars/mhist/MHArray.h	(revision 1574)
@@ -0,0 +1,54 @@
+#ifndef MARS_MHArray
+#define MARS_MHArray
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+class TList;
+
+class MHArray : public MH
+{
+private:
+    Int_t  fIdx;              // current index for the fill function
+    TList *fArray;            //-> Array storing the histograms
+
+    const MParList *fParList; //! pointer to parameter list used for SetupFill when a new Hist is created
+    TClass *fClass;           //! pointer to class entry in root dictionary
+
+    MH *fTemplate;            //! pointer to a template histogram
+    TString fTemplateName;    //! name of the template class
+
+    Bool_t CreateH();
+
+    enum { kUseTemplate=BIT(14) };
+
+public:
+    MHArray(const TString hname, Bool_t istempl=kFALSE, const char *name=NULL, const char *title=NULL);
+    ~MHArray();
+
+    virtual Bool_t SetupFill(const MParList *pList);
+    virtual Bool_t Fill(const MParContainer *par);
+    virtual Bool_t Finalize();
+
+    MH &operator[](Int_t i);
+    MH *At(Int_t i);
+
+    MH *GetH();
+
+    void SetIndex(Int_t i) { fIdx=i; }
+    void IncIndex() { fIdx++; }
+    void DecIndex() { fIdx--; }
+
+    Int_t GetIndex() const { return fIdx; }
+
+    void Print(Option_t *option="") const;
+
+    void Draw(Option_t *opt="");
+    TObject *DrawClone(Option_t *opt="") const;
+
+    ClassDef(MHArray, 0) //A histogram class for an array of Mars histograms
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mhist/MHEnergyTheta.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEnergyTheta.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHEnergyTheta.h	(revision 1574)
@@ -32,4 +32,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Divide(const TH2D *h1, const TH2D *h2);
     void Divide(const MHEnergyTheta *h1, const MHEnergyTheta *h2)
Index: trunk/MagicSoft/Mars/mhist/MHEnergyTime.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHEnergyTime.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHEnergyTime.h	(revision 1574)
@@ -33,4 +33,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Divide(const TH2D *h1, const TH2D *h2);
     void Divide(const MHEnergyTime *h1, const MHEnergyTime *h2)
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1574)
@@ -43,6 +43,6 @@
 //    - red:   histogram of all hadronesses for non gammas
 //  * Upper Right Corner:
-//    - black: acceptance of gammas vs. the hadroness
-//    - red:   acceptance of non gammas vs. the hadroness
+//    - black: acceptance of gammas (Ag) vs. the hadroness
+//    - red:   acceptance of non gammas (Ah) vs. the hadroness
 //    - blue:  2D distance of (acceptance_hadrons, acceptances_gammas)
 //             to optimum (0, 1)
@@ -221,5 +221,5 @@
     }
 
-    return val1y - (val2y-val1y)/(val2x-val1x) * (0.5-val1x);
+    return val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
 }
 
@@ -265,5 +265,5 @@
     }
 
-    fQfac->SetMaximum(max+1);
+    fQfac->SetMaximum(max*1.05);
 
     return kTRUE;
@@ -342,4 +342,11 @@
     *fLog << "Hadronness histograms:" << endl;
     *fLog << "---------------------" << endl;
+
+    if (fGraph->GetN()==0)
+    {
+        *fLog << " <No Entries>" << endl;
+        return;
+    }
+
     *fLog << "Used " << fGhness->GetEntries() << " Gammas and " << fPhness->GetEntries() << " Hadrons." << endl;
     *fLog << "Acc Gammas @  1% Hadron-acc: " << Form("%3.0f", GetGammaAcceptance(0.01)*100) << "%" << endl;
@@ -368,4 +375,7 @@
 TObject *MHHadronness::DrawClone(Option_t *opt) const
 {
+    if (fGraph->GetN()==0)
+        return NULL;
+
     TCanvas &c = *MakeDefCanvas("Hadronness", fTitle);
     c.Divide(2, 2);
@@ -435,5 +445,8 @@
 void MHHadronness::Draw(Option_t *)
 {
-    if (!gPad)
+   if (fGraph->GetN()==0)
+        return;
+
+   if (!gPad)
         MakeDefCanvas("Hadronness", fTitle);
 
Index: trunk/MagicSoft/Mars/mhist/MHHadronness.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1574)
@@ -18,12 +18,12 @@
     const MHadronness *fHadronness;    //!
 
-    TH1D* fPhness;        // Hadrons Hadronness
-    TH1D* fGhness;        // Gammas Hadronness
-    TH1D* fIntPhness;     // Hadrons Acceptance
-    TH1D* fIntGhness;     // Gammas Acceptance
-    TH1D* fMinDist;       // Minimum Distance to optimum acceptance
+    TH1D* fPhness;        //-> Hadrons Hadronness
+    TH1D* fGhness;        //-> Gammas Hadronness
+    TH1D* fIntPhness;     //-> Hadrons Acceptance
+    TH1D* fIntGhness;     //-> Gammas Acceptance
+    TH1D* fMinDist;       //-> Minimum Distance to optimum acceptance
 
-    TGraph *fQfac;        // Quality factor
-    TGraph *fGraph;       // gamma acceptance vs. hadron acceptance
+    TGraph *fQfac;        //-> Quality factor
+    TGraph *fGraph;       //-> gamma acceptance vs. hadron acceptance
 
 public:
Index: trunk/MagicSoft/Mars/mhist/MHHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 1574)
@@ -365,2 +365,24 @@
     gPad->Update();
 }
+
+TH1 *MHHillas::GetHistByName(const TString name)
+{
+    if (name.Contains("Width", TString::kIgnoreCase))
+        return fWidth;
+    if (name.Contains("Length", TString::kIgnoreCase))
+        return fLength;
+    if (name.Contains("Size", TString::kIgnoreCase))
+        return fSize;
+    if (name.Contains("Core", TString::kIgnoreCase))
+        return fCorePix;
+    if (name.Contains("Used", TString::kIgnoreCase))
+        return fUsedPix;
+    if (name.Contains("Delta", TString::kIgnoreCase))
+        return fDelta;
+    if (name.Contains("DistC", TString::kIgnoreCase))
+        return fDistC;
+    if (name.Contains("Center", TString::kIgnoreCase))
+        return fCenter;
+
+    return NULL;
+}
Index: trunk/MagicSoft/Mars/mhist/MHHillas.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHillas.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHillas.h	(revision 1574)
@@ -41,4 +41,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name);
+
     TH1F *GetHistLength() { return fLength; }
     TH1F *GetHistWidth()  { return fWidth; }
Index: trunk/MagicSoft/Mars/mhist/MHHillasExt.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHillasExt.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHillasExt.cc	(revision 1574)
@@ -312,2 +312,18 @@
     gPad->Update();
 }
+
+TH1 *MHHillasExt::GetHistByName(const TString name)
+{
+    if (name.Contains("Conc", TString::kIgnoreCase))
+        return &fHConc;
+    if (name.Contains("Conc1", TString::kIgnoreCase))
+        return &fHConc1;
+    if (name.Contains("Asym", TString::kIgnoreCase))
+        return &fHAsym;
+    if (name.Contains("M3Long", TString::kIgnoreCase))
+        return &fHM3Long;
+    if (name.Contains("M3Trans", TString::kIgnoreCase))
+        return &fHM3Trans;
+
+    return NULL;
+}
Index: trunk/MagicSoft/Mars/mhist/MHHillasExt.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHillasExt.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHillasExt.h	(revision 1574)
@@ -35,4 +35,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name);
+
     void Draw(Option_t *opt=NULL);
     TObject *DrawClone(Option_t *opt=NULL) const;
Index: trunk/MagicSoft/Mars/mhist/MHHillasSrc.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHillasSrc.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHillasSrc.cc	(revision 1574)
@@ -271,2 +271,16 @@
     gPad->Update();
 }
+
+TH1 *MHHillasSrc::GetHistByName(const TString name)
+{
+    if (name.Contains("Alpha", TString::kIgnoreCase))
+        return fAlpha;
+    if (name.Contains("Dist", TString::kIgnoreCase))
+        return fDist;
+    if (name.Contains("HeadTail", TString::kIgnoreCase))
+        return fHeadTail;
+    if (name.Contains("CosDA", TString::kIgnoreCase))
+        return fCosDA;
+
+    return NULL;
+}
Index: trunk/MagicSoft/Mars/mhist/MHHillasSrc.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHHillasSrc.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHHillasSrc.h	(revision 1574)
@@ -30,4 +30,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name);
+
     TH1F *GetHistAlpha()         { return fAlpha; }
     TH1F *GetHistDist()          { return fDist; }
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1574)
@@ -487,4 +487,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MHMatrix::StreamPrimitive(ofstream &out) const
 {
@@ -583,2 +589,12 @@
     return kTRUE;
 }
+
+// --------------------------------------------------------------------------
+//
+// Return a comma seperated list of all data members used in the matrix.
+// This is mainly used in MTask::AddToBranchList
+//
+TString MHMatrix::GetDataMember() const
+{
+    return fData ? fData->GetDataMember() : TString("");
+}
Index: trunk/MagicSoft/Mars/mhist/MHMatrix.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1574)
@@ -87,4 +87,6 @@
     Bool_t Fill(MParList *plist, MTask *read);
 
+    TString GetDataMember() const;
+
     ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events
 };
Index: trunk/MagicSoft/Mars/mhist/MHMcDifRate.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcDifRate.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcDifRate.h	(revision 1574)
@@ -31,4 +31,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: trunk/MagicSoft/Mars/mhist/MHMcEfficiencyEnergy.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEfficiencyEnergy.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcEfficiencyEnergy.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: trunk/MagicSoft/Mars/mhist/MHMcEfficiencyImpact.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEfficiencyImpact.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcEfficiencyImpact.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: trunk/MagicSoft/Mars/mhist/MHMcEnergy.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEnergy.cc	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcEnergy.cc	(revision 1574)
@@ -260,2 +260,6 @@
 }
 
+TH1 *MHMcEnergy::GetHistByName(const TString name)
+{
+    return fHist;
+}
Index: trunk/MagicSoft/Mars/mhist/MHMcEnergy.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEnergy.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcEnergy.h	(revision 1574)
@@ -6,4 +6,5 @@
 #endif
 
+class TH1;
 class TH1F;
 class TF1;
@@ -45,6 +46,9 @@
     void SetNumBins(Int_t nbins = 100);
 
+    TH1 *GetHistByName(const TString name);
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
+
     void Print(Option_t* option = NULL) const;
 
Index: trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h	(revision 1574)
@@ -29,4 +29,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: trunk/MagicSoft/Mars/mhist/MHMcEnergyMigration.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcEnergyMigration.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcEnergyMigration.h	(revision 1574)
@@ -23,4 +23,5 @@
     MMcEvt      *fMcEvt;
     MEnergyEst  *fEnergy;
+
     TH3D        fHist;
 
@@ -33,4 +34,6 @@
     const TH3D *GetHist() { return &fHist; }
     const TH3D *GetHist() const { return &fHist; }
+
+    TH1 *GetHistByName(const TString name) { return &fHist; }
 
     void Draw(Option_t *option="");
Index: trunk/MagicSoft/Mars/mhist/MHMcIntRate.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHMcIntRate.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHMcIntRate.h	(revision 1574)
@@ -29,4 +29,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: trunk/MagicSoft/Mars/mhist/MHStarMap.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHStarMap.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHStarMap.h	(revision 1574)
@@ -33,4 +33,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name) { return fStarMap; }
+
     TH2F *GetHist() { return fStarMap; }
 
Index: trunk/MagicSoft/Mars/mhist/MHThetabarTheta.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHThetabarTheta.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHThetabarTheta.h	(revision 1574)
@@ -31,4 +31,6 @@
     const TProfile *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: trunk/MagicSoft/Mars/mhist/MHThetabarTime.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHThetabarTime.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHThetabarTime.h	(revision 1574)
@@ -34,4 +34,6 @@
     const TProfile *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: trunk/MagicSoft/Mars/mhist/MHTimeDiffTheta.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHTimeDiffTheta.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHTimeDiffTheta.h	(revision 1574)
@@ -32,4 +32,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: trunk/MagicSoft/Mars/mhist/MHTimeDiffTime.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHTimeDiffTime.h	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/MHTimeDiffTime.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 1573)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 1574)
@@ -32,4 +32,5 @@
            MBinning.cc \
            MH.cc \
+           MHArray.cc \
            MH3.cc \
            MHMatrix.cc \
