Index: trunk/MagicSoft/Mars/mhbase/HBaseIncl.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/HBaseIncl.h	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/HBaseIncl.h	(revision 2735)
@@ -0,0 +1,6 @@
+#ifndef __CINT__
+
+#include <TF1.h>
+#include <TArrayI.h>
+
+#endif // __CINT__
Index: trunk/MagicSoft/Mars/mhbase/HBaseLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/HBaseLinkDef.h	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/HBaseLinkDef.h	(revision 2735)
@@ -0,0 +1,15 @@
+#ifdef __CINT__
+
+#pragma link off all globals;
+#pragma link off all classes;
+#pragma link off all functions;
+
+#pragma link C++ class MFillH+;
+
+#pragma link C++ class MH+;
+#pragma link C++ class MHArray+;
+
+#pragma link C++ class MBinning+;
+#pragma link C++ class MWeight+;
+
+#endif
Index: trunk/MagicSoft/Mars/mhbase/MBinning.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.cc	(revision 2735)
@@ -0,0 +1,205 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MBinning                                                                //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+#include "MBinning.h"
+
+#include <ctype.h>      // tolower
+#include <fstream>
+
+#include <TH1.h>        // InheritsFrom
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MH.h"
+
+ClassImp(MBinning);
+
+using namespace std;
+
+static const TString gsDefName  = "MBinning";
+static const TString gsDefTitle = "Container describing the binning of an axis";
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. It sets name and title only. Typically you won't
+// need to change this.
+//
+MBinning::MBinning(const char *name, const char *title)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : gsDefName.Data();
+    fTitle = title ? title : gsDefTitle.Data();
+
+    SetEdges(10, 0, 1);
+
+    fType = kIsDefault;
+}
+
+void MBinning::SetEdges(const TAxis &axe)
+{
+    const TArrayD &arr = *((TAxis&)axe).GetXbins();
+    if (arr.GetSize()>0)
+    {
+        SetEdges(arr);
+        return;
+    }
+
+    SetEdges(axe.GetNbins(), axe.GetXmin(), axe.GetXmax());
+}
+
+void MBinning::SetEdges(const TH1 &h, const Char_t axis)
+{
+    TH1 &hist = (TH1&)h; // get rid of const qualifier
+    switch (tolower(axis))
+    {
+    case 'x':
+        SetEdges(*hist.GetXaxis());
+        return;
+    case 'y':
+        SetEdges(*hist.GetYaxis());
+        return;
+    case 'z':
+        SetEdges(*hist.GetZaxis());
+        return;
+    default:
+        *fLog << warn << "MBinning::SetEdges: Axis '" << axis << "' unknown... using x." << endl;
+        SetEdges(*hist.GetXaxis());
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Specify the number of bins <nbins> (not the number of edges), the
+// lowest <lo> and highest <up> Edge (of your histogram)
+//
+void MBinning::SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up)
+{
+    const Double_t binsize = (up-lo)/nbins;
+    fEdges.Set(nbins+1);
+    for (int i=0; i<=nbins; i++)
+            fEdges[i] = binsize*i + lo;
+
+    fType = kIsLinear;
+}
+
+// --------------------------------------------------------------------------
+//
+// Specify the number of bins <nbins> (not the number of edges), the
+// lowest <lo> and highest <up> Edge (of your histogram)
+//
+void MBinning::SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up)
+{
+    // if (lo==0) ...
+
+    const Double_t binsize = log10(up/lo)/nbins;
+    fEdges.Set(nbins+1);
+    for (int i=0; i<=nbins; i++)
+        fEdges[i] = pow(10, binsize*i) * lo;
+
+    fType = kIsLogarithmic;
+}
+
+// --------------------------------------------------------------------------
+//
+// Specify the number of bins <nbins> (not the number of edges), the
+// lowest [deg] <lo> and highest [deg] <up> Edge (of your histogram)
+//
+void MBinning::SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up)
+{
+    // if (lo==0) ...
+    const Axis_t ld = lo/kRad2Deg;
+    const Axis_t ud = up/kRad2Deg;
+
+    const Double_t binsize = (cos(ld)-cos(ud))/nbins;
+    fEdges.Set(nbins+1);
+    for (int i=0; i<=nbins; i++)
+        fEdges[i] = acos(cos(ld)-binsize*i)*kRad2Deg;
+
+    fType = kIsCosinic;
+}
+
+// --------------------------------------------------------------------------
+//
+// Apply this binning to the given histogram.
+// (By definition this works only for 1D-histograms. For 2D- and 3D-
+//  histograms use MH::SetBinning directly)
+//
+void MBinning::Apply(TH1 &h)
+{
+    if (h.InheritsFrom("TH2") || h.InheritsFrom("TH3"))
+    {
+        *fLog << warn << "MBinning::Apply: '" << h.GetName() << "' is not a basic TH1 object... no binning applied." << endl;
+        return;
+    }
+
+    MH::SetBinning(&h, this);
+}
+
+// --------------------------------------------------------------------------
+//
+// 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 MBinning::StreamPrimitive(ofstream &out) const
+{
+    out << "   MBinning " << GetUniqueName();
+    if (fName!=gsDefName || fTitle!=gsDefTitle)
+    {
+        out << "(\"" << fName << "\"";
+        if (fTitle!=gsDefTitle)
+            out << ", \"" << fTitle << "\"";
+        out <<")";
+    }
+    out << ";" << endl;
+
+    if (IsDefault())
+        return;
+
+    if (IsLinear() || IsLogarithmic() || IsCosinic())
+    {
+        out << "   " << GetUniqueName() << ".SetEdges";
+        if (IsLogarithmic())
+            out << "Log";
+        if (IsCosinic())
+            out << "Cos";
+        out << "(" << GetNumBins() << ", " << GetEdgeLo() << ", " << GetEdgeHi() << ");" << endl;
+        return;
+    }
+
+    out << "   {" << endl;
+    out << "      TArrayD dummy;" << endl;
+    for (int i=0; i<GetNumEdges(); i++)
+        out << "      dummy[" << i << "]=" << GetEdges()[i] << ";" << endl;
+    out << "      " << GetUniqueName() << ".SetEdges(dummy);" << endl;
+    out << "   }" << endl;
+}
Index: trunk/MagicSoft/Mars/mhbase/MBinning.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MBinning.h	(revision 2735)
@@ -0,0 +1,86 @@
+#ifndef MARS_MBinning
+#define MARS_MBinning
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+#ifndef ROOT_TArrayD
+#include <TArrayD.h>
+#endif
+
+class TH1;
+class TAxis;
+
+class MBinning : public MParContainer
+{
+private:
+    TArrayD fEdges;
+
+    Byte_t  fType;
+
+    void StreamPrimitive(ofstream &out) const;
+
+    enum {
+        kIsDefault,
+        kIsLinear,
+        kIsLogarithmic,
+        kIsCosinic,
+        kIsUserArray
+    };
+
+public:
+    MBinning(const char *name=NULL, const char *title=NULL);
+
+    void SetEdges(const TArrayD &arr)
+    {
+        fEdges = arr;
+        fType = kIsUserArray;
+    }
+
+    void SetEdges(const TAxis &axe);
+    void SetEdges(const TH1 &h, const Char_t axis='x');
+    void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
+    void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
+    void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
+
+    Int_t FindLoEdge(Double_t val) const
+    {
+        if (val<GetEdgeLo() || val>=GetEdgeHi())
+            return -1;
+
+	for (int i=1; i<fEdges.GetSize(); i++)
+        {
+            if (((TArrayD)fEdges)[i] >= val)
+                return i-1;
+        }
+        return -1;
+    }
+    Int_t FindHiEdge(Double_t val) const
+    {
+        const Int_t i = FindLoEdge(val);
+        return i<0 ? -1 : i+1;
+    }
+
+    // FIXME: ROOT workaround: "operator[] const" missing
+    Double_t GetEdgeLo() const { return ((TArrayD)fEdges)[0]; }
+    Double_t GetEdgeHi() const { return ((TArrayD)fEdges)[fEdges.GetSize()-1]; }
+
+    Int_t GetNumEdges() const { return fEdges.GetSize(); }
+    Int_t GetNumBins() const { return fEdges.GetSize()-1; }
+
+    Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); }
+
+    Bool_t IsLinear() const { return fType==kIsLinear; }
+    Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
+    Bool_t IsCosinic() const { return fType==kIsCosinic; }
+    Bool_t IsDefault() const { return fType==kIsDefault; }
+    Bool_t IsUserArray() const { return fType==kIsUserArray; }
+
+    void Apply(TH1 &);
+
+    ClassDef(MBinning, 1) //Container to store the binning of a histogram
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mhbase/MFillH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MFillH.cc	(revision 2735)
@@ -0,0 +1,589 @@
+/* ======================================================================== *\
+!
+! *
+! * 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-2003
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MFillH                                                                  //
+//                                                                          //
+//  This is a common interface (task) to fill mars histograms. Every mars   //
+//  histogram which is derived from MH can be filled with this task.        //
+//                                                                          //
+//  There are two options to use:                                           //
+//                                                                          //
+//  1) You specifiy the parameter container with which data the             //
+//     histogram container should be filled, and the histogram container    //
+//     which has to be filled. This can be done by either specifing the     //
+//     name of the objects in the parameter list or by specifiing a pointer //
+//     to the object. (s. Constructor)                                      //
+//                                                                          //
+//  2) You specify the name and/or type of the histogram to become filled.  //
+//     Any other action imust be taken by the histogram class.              //
+//                                                                          //
+//  PreProcess: In the preprocessing of this task we setup all pointers     //
+//              to instances which are needed and call FillSetup of the     //
+//              histogram class with the parameter list as an argument.     //
+//                                                                          //
+//  Process: The process function calls the Fill member function of the     //
+//           histogram class instance (inheriting from MH) with either      //
+//           a NULL pointer or a pointer to the corresponding container     //
+//           as an argument.                                                //
+//                                                                          //
+// To use a weight for each event filled in a histogram call                //
+// SetWeight(). You can eithe use the name of a MWeight container stored    //
+// in the parameter list or a pointer to it as an argument.                 //
+//                                                                          //
+//                                                                          //
+//  WARNING:                                                                //
+//   Because MFillH is a generalized task to fill histograms it doesn't     //
+//   know about which branches from a file are necessary to fill the        //
+//   histograms. If you are reading data from a file which is directly      //
+//   filled into a histogram via MFillH, please call either                 //
+//   MReadTree::DisableAutoScheme() or enable the necessary branches by     //
+//   yourself, using MReadTree::EnableBranch()                              //
+//                                                                          //
+//   Checkout the Warning in MTaskList.                                     //
+//                                                                          //
+//  Input Containers:                                                       //
+//   A parameter container                                                  //
+//                                                                          //
+//  Output Containers:                                                      //
+//   A histogram container                                                  //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+#include "MFillH.h"
+
+#include <fstream>
+
+#include <TClass.h>
+#include <TCanvas.h>
+
+#include "MDataChain.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MH.h"
+#include "MHArray.h"
+
+#include "MWeight.h"
+
+#include "MParList.h"
+#include "MStatusDisplay.h"
+
+ClassImp(MFillH);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Initializes name and title of the object. It is called by all
+// constructors.
+//
+void MFillH::Init(const char *name, const char *title)
+{
+    fName  = name  ? name  : "MFillH";
+    fTitle = title ? title : "Task to fill Mars histograms";
+
+    fH            = NULL;
+    fParContainer = NULL;
+
+    fIndex  = NULL;
+    fCanvas = NULL;
+
+    fWeight     = NULL;
+    fWeightName = "";
+}
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. This is to support some root-stuff.
+// Never try to use it yourself!
+//
+MFillH::MFillH()
+{
+    Init(NULL, NULL);
+}
+
+// --------------------------------------------------------------------------
+//
+// Constructor.
+//
+// 1) - par is the name of the parameter container which should be filled into
+//      the histogram
+//    - hist is the name of the histogram container (which must have been
+//      derived from MH)
+//
+//    In this case MH::Fill is called with a pointer to the corresponding
+//    histogram instance.
+//
+// 2) - hist is the name and/or type of the histogram.
+//      1) The name and type is identical, eg: "MHHillas"
+//      2) They are not identical, eg: "MyHistogram [MHHillas]"
+//         This searches for a class instance of MHHillas with the name
+//         "MyHistogram". If it doesn't exist one is created.
+//
+//    In this case PreProcess calls MH::SetupFill with a pointer to the
+//    parameter list and MH::Fill is called with a NULL-pointer.
+//
+MFillH::MFillH(const char *hist, const char *par, const char *name, const char *title)
+{
+    Init(name, title);
+
+    fHName = hist;
+    fParContainerName = par;
+
+    AddToBranchList(Form("%s.*", (const char*)ExtractName(hist)));
+    if (par)
+        AddToBranchList(Form("%s.*", (const char*)ExtractName(par)));
+
+    if (title)
+        return;
+
+    fTitle = "Fill " + fHName;
+    if (fParContainerName.IsNull())
+        return;
+
+    fTitle += " from " + fParContainerName;
+}
+
+// --------------------------------------------------------------------------
+//
+// Constructor.
+//
+// 1) - par is a pointer to the instance of your parameter container from which
+//      the data should be used to fill the histogram.
+//    - hist is the name of the histogram container (which must have been
+//      derived from MH)
+//
+//    In this case MH::Fill is called with a pointer to the corresponding
+//    histogram instance.
+//
+// 2) - hist is the name and/or type of the histogram.
+//      1) The name and type is identical, eg: "MHHillas"
+//      2) They are not identical, eg: "MyHistogram [MHHillas]"
+//         This searches for a class instance of MHHillas with the name
+//         "MyHistogram". If it doesn't exist one is created. Everything
+//         which is between the first '[' and the last ']' in the string
+//         is used as the histogram type.
+//
+//    In this case PreProcess calls MH::SetupFill with a pointer to the
+//    parameter list and MH::Fill is called with a NULL-pointer.
+//
+//
+MFillH::MFillH(const char *hist, MParContainer *par, const char *name, const char *title)
+{
+    Init(name, title);
+
+    fHName = hist;
+    fParContainer = par;
+    fParContainerName = par->GetName();
+
+    AddToBranchList(Form("%s.*", (const char*)ExtractName(hist)));
+    AddToBranchList(Form("%s.*", par->GetName()));
+
+    if (!title)
+        fTitle = "Fill " + fHName + " from " + par->GetDescriptor();
+}
+
+// --------------------------------------------------------------------------
+//
+// Constructor.
+//
+// - par is a pointer to the instance of your parameter container from which
+//   the data should be used to fill the histogram.
+// - hist is a pointer to the instance of your histogram container (which must
+//   have been derived from MH) into which the data should flow
+//
+MFillH::MFillH(MH *hist, const char *par, const char *name, const char *title)
+{
+    Init(name, title);
+
+    fH = hist;
+    fHName = hist->GetName();
+    fParContainerName = par;
+
+    AddToBranchList(fH->GetDataMember());
+    if (par)
+        AddToBranchList(Form("%s.*", (const char*)ExtractName(par)));
+
+    if (title)
+        return;
+
+    fTitle = (TString)"Fill " + hist->GetDescriptor();
+    if (!par)
+        return;
+
+    fTitle += " from " + fParContainerName;
+}
+
+// --------------------------------------------------------------------------
+//
+// Constructor.
+//
+// - par is a pointer to the instance of your parameter container from which
+//   the data should be used to fill the histogram.
+// - hist is the name of the histogram container (which must have been
+//   derived from MH)
+//
+MFillH::MFillH(MH *hist, MParContainer *par, const char *name, const char *title)
+{
+    Init(name, title);
+
+    fH = hist;
+    fHName = hist->GetName();
+    fParContainer = par;
+    fParContainerName = par->GetName();
+
+    AddToBranchList(fH->GetDataMember());
+    AddToBranchList(Form("%s.*", par->GetName()));
+
+    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;
+}
+
+// --------------------------------------------------------------------------
+//
+// 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
+{
+    TString type = name;
+
+    const Ssiz_t first = type.First('[');
+    const Ssiz_t last  = type.First(']');
+
+    if (!first || !last || first>=last)
+        return type;
+
+    return type.Remove(first).Strip(TString::kBoth);
+}
+
+// --------------------------------------------------------------------------
+//
+// Extracts the class-name of the histogram from the MFillH argument
+//
+TString MFillH::ExtractClass(const char *name) const
+{
+    TString type = name;
+
+    const Ssiz_t first = type.First('[');
+    const Ssiz_t last  = type.First(']');
+
+    if (!first || !last || first>=last)
+        return type;
+
+    const Ssiz_t length = last-first-1;
+
+    TString strip = fHName(first+1, length);
+    return strip.Strip(TString::kBoth);
+}
+
+// --------------------------------------------------------------------------
+//
+// Creates a new tab in a status display with the name of the MH class,
+// if fDisplay is set and the MH-class overwrites the Draw function
+//
+Bool_t MFillH::DrawToDisplay()
+{
+    fCanvas = NULL;
+
+    if (!fDisplay)
+        return kTRUE;
+
+    if (!fH->OverwritesDraw())
+        return kTRUE;
+
+    if (TestBit(kDoNotDisplay))
+        return kTRUE;
+
+    fCanvas = &fDisplay->AddTab(fH->GetName());
+    fH->Draw();
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Checks the parameter list for the existance of the parameter container. If
+// the name of it was given in the constructor. It checks also for the
+// existance of the histogram container in the parameter list if a name was
+// given. If it is not available it tried to create a histogram container
+// with the same type as the given object name.
+//
+Int_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;
+        }
+    }
+
+    //
+    // If the user defined the use of a weight: search for it.
+    //
+    if (!fWeight && !fWeightName.IsNull())
+    {
+        fWeight = (MWeight*)pList->FindObject(fWeightName, "MWeight");
+
+	if (!fWeight)
+	  {
+	    *fLog << err << fWeightName << " [MWeight] not found... aborting." << endl;
+	    return kFALSE;
+	  }
+    }
+
+    //
+    // Try to get the histogram container with name fHName from list
+    // or create one with this name
+    //
+    if (!fH)
+    {
+        const TString cls  = ExtractClass(fHName);
+        const TString name = ExtractName(fHName);
+
+        TObject *obj=NULL;
+        if (cls==name)
+            obj = pList->FindObject(fHName);
+
+        if (!obj)
+        {
+            /*
+            if (cls==name)
+            *fLog << inf << "Object '" << fHName << "' not found in parlist... creating." << endl;
+            */
+            obj = pList->FindCreateObj(cls, name);
+        }
+
+        if (!obj)
+            return kFALSE;
+
+        //
+        // We were successfull getting it. Check whether it really inherits
+        // from MH, FindCreateObj does only check for inheritance from
+        // 'type'.
+        //
+        TClass *tcls = fIndex ? MHArray::Class() : MH::Class();
+        if (!obj->InheritsFrom(tcls))
+        {
+            *fLog << err << obj->GetName() << " doesn't inherit ";
+            *fLog << "from " << tcls->GetName() << " - cannot be used for MFillH...";
+            *fLog << "aborting." << endl;
+            return kFALSE;
+        }
+
+        fH = (MH*)obj;
+    }
+
+    //
+    // Now we have the histogram container available. Try to Setup Fill.
+    //
+    fH->SetSerialNumber(GetSerialNumber());
+    if (!fH->SetupFill(pList))
+    {
+        *fLog << err << "ERROR - Calling SetupFill for ";
+        *fLog << fH->GetDescriptor() << "... aborting." << endl;
+        return kFALSE;
+    }
+
+    //
+    // If also a parameter container is already set we are done.
+    //
+    if (fParContainer)
+        return DrawToDisplay();
+
+    //
+    // This case means, that the MH sets up its container to be filled
+    // by itself. Check there if it has something to be filled with!
+    //
+    if (fParContainerName.IsNull())
+    {
+        fParContainer = NULL;
+        return DrawToDisplay();
+    }
+
+    fParContainer = (MParContainer*)pList->FindObject(fParContainerName);
+    if (fParContainer)
+        return DrawToDisplay();
+
+    *fLog << err << fParContainerName << " [MParContainer] not found... aborting." << endl;
+    return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Call the ReInit function of the contained Histogram
+//
+Bool_t MFillH::ReInit(MParList *pList)
+{
+    return fH->ReInit(pList);
+} 
+
+// --------------------------------------------------------------------------
+//
+// Fills the data from the parameter conatiner into the histogram container
+//
+Int_t MFillH::Process()
+{
+    if (fIndex)
+        ((MHArray*)fH)->SetIndexByKey(fIndex->GetValue());
+    /*
+     const Int_t key = (Int_t)fIndex->GetValue();
+     const Int_t idx = fMapIdx->Add(key);
+     ((MHArray*)fH)->SetIndex(idx);
+     */
+
+    return fH->Fill(fParContainer, fWeight?fWeight->GetWeight():1);
+} 
+
+// --------------------------------------------------------------------------
+//
+// Set the ReadyToSave flag of the histogram container, because now all data
+// has been filled into the histogram.
+//
+Int_t MFillH::PostProcess()
+{
+    //
+    // Now all data is in the histogram. Maybe some final action is
+    // necessary.
+    //
+    if (!fH->Finalize())
+    {
+        *fLog << err << "ERROR - Calling Finalize for ";
+        *fLog << fH->GetDescriptor() << "... aborting." << endl;
+        return kFALSE;
+    }
+
+    fH->SetReadyToSave();
+
+    //
+    // Check whether fDisplay has previously been used (fCanvas),
+    // fDisplay is still open and the corresponding Canvas/Tab is
+    // still existing.
+    //
+    if (fDisplay && fDisplay->HasCanvas(fCanvas))
+    {
+        fCanvas->cd();
+        fH->DrawClone("nonew");
+        fCanvas->Modified();
+        fCanvas->Update();
+    }
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// 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 MFillH::StreamPrimitive(ofstream &out) const
+{
+    if (fH)
+        fH->SavePrimitive(out);
+
+    if (fParContainer)
+        fParContainer->SavePrimitive(out);
+
+    if (fWeight)
+        fWeight->SavePrimitive(out);
+
+    out << "   MFillH " << GetUniqueName() << "(";
+
+    if (fH)
+        out << "&" << fH->GetUniqueName();
+    else
+        out << "\"" << fHName << "\"";
+
+    if (fParContainer)
+        out << ", &" << fParContainer->GetUniqueName();
+    else
+        if (!fParContainerName.IsNull())
+            out << ", \"" << fParContainerName << "\"";
+
+    out << ");" << endl;
+
+    if (fWeight || !fWeightName.IsNull())
+    {
+        out << "   " << GetUniqueName() << ".SetWeight(";
+        if (fWeight)
+            out << "&" << fWeight->GetUniqueName() << ");" << endl;
+        else
+            if (!fWeightName.IsNull())
+                out << "\"" << fWeightName << "\");" << endl;
+    }
+
+    if (fIndex)
+    {
+        out << "   " << GetUniqueName() << ".SetRuleForIdx(\"";
+        out << fIndex->GetRule() << "\");" << endl;
+    }
+}
Index: trunk/MagicSoft/Mars/mhbase/MFillH.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MFillH.h	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MFillH.h	(revision 2735)
@@ -0,0 +1,72 @@
+#ifndef MARS_MFillH
+#define MARS_MFillH
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MH;
+class MMap;
+class MData;
+class MWeight;
+class MParList;
+
+class TCanvas;
+
+class MFillH : public MTask
+{
+public:
+    enum {
+        kDoNotDisplay = BIT(17)
+    };
+
+private:
+    MParContainer *fParContainer; // Pointer to the data container storing
+    TString fParContainerName;    // Name to a data container
+
+    MH* fH;                       // Pointer to the MH container to get filled
+    TString fHName;               // Name to a MH container to get filled
+
+    MWeight *fWeight;             // Pointer to the container storing a weight
+    TString fWeightName;          // Name of a container storing a weight
+
+    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)
+
+    TCanvas *fCanvas;             //! Canvas used to update a MStatusDisplay at the end of a loop
+
+    TString ExtractName(const char *name) const;
+    TString ExtractClass(const char *name) const;
+
+    void Init(const char *name, const char *title);
+
+    void StreamPrimitive(ofstream &out) const;
+
+    Bool_t DrawToDisplay();
+
+public:
+    MFillH();
+    MFillH(const char *hist, const char *par=NULL, const char *name=NULL, const char *title=NULL);
+    MFillH(const char *hist, MParContainer *par,   const char *name=NULL, const char *title=NULL);
+    MFillH(MH *hist,         const char *par=NULL, const char *name=NULL, const char *title=NULL);
+    MFillH(MH *hist,         MParContainer *par,   const char *name=NULL, const char *title=NULL);
+    ~MFillH();
+
+    void SetRuleForIdx(const TString rule);
+    void SetRuleForIdx(MData *rule);
+
+    void SetWeight(MWeight *w)       { fWeight = w; }
+    void SetWeight(const char *name) { fWeightName = name; }
+
+    Int_t  PreProcess(MParList *pList);
+    Bool_t ReInit(MParList *pList);
+    Int_t  Process();
+    Int_t  PostProcess();
+
+    TCanvas *GetCanvas() { return fCanvas; }
+
+    ClassDef(MFillH, 2) // Task to fill a histogram with data from a parameter container
+};
+    
+#endif
+
Index: trunk/MagicSoft/Mars/mhbase/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MH.cc	(revision 2735)
@@ -0,0 +1,1081 @@
+/* ======================================================================== *\
+!
+! *
+! * 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
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+//  MH                                                                      //
+//                                                                          //
+//  This is a base tasks for mars histograms. It defines a common interface //
+//  for filling the histograms with events (MH::Fill) which is used by a    //
+//  common 'filler' And a SetupFill member function which may be used       //
+//  by MFillH. The idea is:                                                 //
+//   1) If your Histogram can become filled by one single container         //
+//      (like MHHillas) you overload MH::Fill and it gets called with       //
+//      a pointer to the container with which it should be filled.          //
+//                                                                          //
+//   2) You histogram needs several containers to get filled. Than you      //
+//      have to overload MH::SetupFill and get the necessary objects from   //
+//      the parameter list. Use this objects in Fill to fill your           //
+//      histogram.                                                          //
+//                                                                          //
+//  If you want to create your own histogram class the new class must be    //
+//  derived from MH (instead of the base MParContainer) and you must        //
+//  the fill function of MH. This is the function which is called to fill   //
+//  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(...)                   //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+
+#include "MH.h"
+
+#include <TH1.h>
+#include <TH2.h>
+#include <TH3.h>
+#include <TStyle.h>       // TStyle::GetScreenFactor
+#include <TGaxis.h>
+#include <TCanvas.h>
+#include <TLegend.h>
+#include <TPaveStats.h>
+#include <TBaseClass.h>
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
+#include <THLimitsFinder.h>
+#endif
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MParContainer.h"
+
+#include "MBinning.h"
+
+ClassImp(MH);
+
+using namespace std;
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. It sets name and title only. Typically you won't
+// need to change this.
+//
+MH::MH(const char *name, const char *title)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MH";
+    fTitle = title ? title : "Base class for Mars histograms";
+}
+
+// --------------------------------------------------------------------------
+//
+// If you want to use the automatic filling of your derived class you
+// must overload this function. If it is not overloaded you cannot use
+// FillH with this class. The argument is a pointer to a container
+// in your paremeter list which is specified in the MFillH constructor.
+// If you are not going to use it you should at least add
+//   Bool_t MH::Fill(const MParContainer *) { return kTRUE; }
+// to your class definition.
+//
+Bool_t MH::Fill(const MParContainer *par, const Stat_t w)
+{
+    *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;
+}
+
+// --------------------------------------------------------------------------
+//
+// This is a function which should replace the creation of default
+// canvases like root does. Because this is inconvinient in some aspects.
+// need to change this.
+// You can specify a name for the default canvas and a title. Also
+// width and height can be given.
+// MakeDefCanvas looks for a canvas with the given name. If now name is
+// given the DefCanvasName of root is used. If no such canvas is existing
+// it is created and returned. If such a canvas already exists a new canvas
+// with a name plus anumber is created (the number is calculated by the
+// number of all existing canvases plus one)
+//
+// Normally the canvas size is scaled with gStyle->GetScreenFactor() so
+// that on all screens it looks like the same part of the screen.
+// To suppress this scaling use usescreenfactor=kFALSE. In this case
+// you specify directly the size of the embedded pad.
+//
+TCanvas *MH::MakeDefCanvas(TString name, const char *title,
+                           UInt_t w, UInt_t h, Bool_t usescreenfactor)
+{
+    const TList *list = (TList*)gROOT->GetListOfCanvases();
+
+    if (name.IsNull())
+        name = gROOT->GetDefCanvasName();
+
+    if (list->FindObject(name))
+        name += Form(" <%d>", list->GetSize()+1);
+
+    if (!usescreenfactor)
+    {
+        const Float_t cx = gStyle->GetScreenFactor();
+        w += 4;
+        h += 28;
+        w = (int)(w/cx+1);
+        h = (int)(h/cx+1);
+    }
+
+    return new TCanvas(name, title, w, h);
+}
+
+// --------------------------------------------------------------------------
+//
+// This function works like MakeDefCanvas(name, title, w, h) but name
+// and title are retrieved from the given TObject.
+//
+// Normally the canvas size is scaled with gStyle->GetScreenFactor() so
+// that on all screens it looks like the same part of the screen.
+// To suppress this scaling use usescreenfactor=kFALSE. In this case
+// you specify directly the size of the embedded pad.
+//
+TCanvas *MH::MakeDefCanvas(const TObject *obj,
+                           UInt_t w, UInt_t h, Bool_t usescreenfactor)
+{
+    if (!usescreenfactor)
+    {
+        const Float_t cx = gStyle->GetScreenFactor();
+        w += 4;
+        h += 28;
+        h = (int)(h/cx+1);
+        w = (int)(w/cx+1);
+    }
+
+    return MakeDefCanvas(obj->GetName(), obj->GetTitle(), w, h);
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies a given binning to a 1D-histogram
+//
+void MH::SetBinning(TH1 *h, const MBinning *binsx)
+{
+    //
+    // Another strange behaviour: TAxis::Set deletes the axis title!
+    //
+    TAxis &x = *h->GetXaxis();
+
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
+    TString xtitle = x.GetTitle();
+#endif
+
+    //
+    // This is a necessary workaround if one wants to set
+    // non-equidistant bins after the initialization
+    // TH1D::fNcells must be set correctly.
+    //
+    h->SetBins(binsx->GetNumBins(), 0, 1);
+
+    //
+    // Set the binning of the current histogram to the binning
+    // in one of the two given histograms
+    //
+    x.Set(binsx->GetNumBins(), binsx->GetEdges());
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
+    x.SetTitle(xtitle);
+#endif
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies given binnings to the two axis of a 2D-histogram
+//
+void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy)
+{
+    TAxis &x = *h->GetXaxis();
+    TAxis &y = *h->GetYaxis();
+
+    //
+    // Another strange behaviour: TAxis::Set deletes the axis title!
+    //
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
+    TString xtitle = x.GetTitle();
+    TString ytitle = y.GetTitle();
+#endif
+
+    //
+    // This is a necessary workaround if one wants to set
+    // non-equidistant bins after the initialization
+    // TH1D::fNcells must be set correctly.
+    //
+    h->SetBins(binsx->GetNumBins(), 0, 1,
+               binsy->GetNumBins(), 0, 1);
+
+    //
+    // Set the binning of the current histogram to the binning
+    // in one of the two given histograms
+    //
+    x.Set(binsx->GetNumBins(), binsx->GetEdges());
+    y.Set(binsy->GetNumBins(), binsy->GetEdges());
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
+    x.SetTitle(xtitle);
+    y.SetTitle(ytitle);
+#endif
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies given binnings to the three axis of a 3D-histogram
+//
+void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
+{
+    //
+    // Another strange behaviour: TAxis::Set deletes the axis title!
+    //
+    TAxis &x = *h->GetXaxis();
+    TAxis &y = *h->GetYaxis();
+    TAxis &z = *h->GetZaxis();
+
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
+    TString xtitle = x.GetTitle();
+    TString ytitle = y.GetTitle();
+    TString ztitle = z.GetTitle();
+#endif
+
+    //
+    // This is a necessary workaround if one wants to set
+    // non-equidistant bins after the initialization
+    // TH1D::fNcells must be set correctly.
+    //
+    h->SetBins(binsx->GetNumBins(), 0, 1,
+               binsy->GetNumBins(), 0, 1,
+               binsz->GetNumBins(), 0, 1);
+
+    //
+    // Set the binning of the current histogram to the binning
+    // in one of the two given histograms
+    //
+    x.Set(binsx->GetNumBins(), binsx->GetEdges());
+    y.Set(binsy->GetNumBins(), binsy->GetEdges());
+    z.Set(binsz->GetNumBins(), binsz->GetEdges());
+#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
+    x.SetTitle(xtitle);
+    y.SetTitle(ytitle);
+    z.SetTitle(ztitle);
+#endif
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies given binning (the n+1 edges)  to the axis of a 1D-histogram
+//
+void MH::SetBinning(TH1 *h, const TArrayD &binsx)
+{
+    MBinning bx;
+    bx.SetEdges(binsx);
+    SetBinning(h, &bx);
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies given binning (the n+1 edges) to the two axis of a
+// 2D-histogram
+//
+void MH::SetBinning(TH2 *h, const TArrayD &binsx, const TArrayD &binsy)
+{
+    MBinning bx;
+    MBinning by;
+    bx.SetEdges(binsx);
+    by.SetEdges(binsy);
+    SetBinning(h, &bx, &by);
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies given binning (the n+1 edges) to the three axis of a
+// 3D-histogram
+//
+void MH::SetBinning(TH3 *h, const TArrayD &binsx, const TArrayD &binsy, const TArrayD &binsz)
+{
+    MBinning bx;
+    MBinning by;
+    MBinning bz;
+    bx.SetEdges(binsx);
+    by.SetEdges(binsy);
+    bz.SetEdges(binsz);
+    SetBinning(h, &bx, &by, &bz);
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies the binning of a TAxis (eg from a root histogram) to the axis
+// of a 1D-histogram
+//
+void MH::SetBinning(TH1 *h, const TAxis *binsx)
+{
+    const Int_t nx = binsx->GetNbins();
+
+    TArrayD bx(nx+1);
+    for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
+    bx[nx] = binsx->GetXmax();
+
+    SetBinning(h, bx);
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies the binnings of the TAxis' (eg from a root histogram) to the
+// two axis' of a 2D-histogram
+//
+void MH::SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy)
+{
+    const Int_t nx = binsx->GetNbins();
+    const Int_t ny = binsy->GetNbins();
+
+    TArrayD bx(nx+1);
+    TArrayD by(ny+1);
+    for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
+    for (int i=0; i<ny; i++) by[i] = binsy->GetBinLowEdge(i+1);
+    bx[nx] = binsx->GetXmax();
+    by[ny] = binsy->GetXmax();
+
+    SetBinning(h, bx, by);
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies the binnings of the TAxis' (eg from a root histogram) to the
+// three axis' of a 3D-histogram
+//
+void MH::SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
+{
+    const Int_t nx = binsx->GetNbins();
+    const Int_t ny = binsy->GetNbins();
+    const Int_t nz = binsz->GetNbins();
+
+    TArrayD bx(nx+1);
+    TArrayD by(ny+1);
+    TArrayD bz(nz+1);
+    for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
+    for (int i=0; i<ny; i++) by[i] = binsy->GetBinLowEdge(i+1);
+    for (int i=0; i<nz; i++) bz[i] = binsz->GetBinLowEdge(i+1);
+    bx[nx] = binsx->GetXmax();
+    by[ny] = binsy->GetXmax();
+    bz[nz] = binsz->GetXmax();
+
+    SetBinning(h, bx, by, bz);
+}
+
+// --------------------------------------------------------------------------
+//
+// Applies the binnings of one root-histogram x to another one h
+// Both histograms must be of the same type: TH1, TH2 or TH3
+//
+void MH::SetBinning(TH1 *h, const TH1 *x)
+{
+    if (h->InheritsFrom(TH3::Class()) && x->InheritsFrom(TH3::Class()))
+    {
+        SetBinning((TH3*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis(), ((TH1*)x)->GetZaxis());
+        return;
+    }
+    if (h->InheritsFrom(TH3::Class()) || x->InheritsFrom(TH3::Class()))
+        return;
+    if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class()))
+    {
+        SetBinning((TH2*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis());
+        return;
+    }
+    if (h->InheritsFrom(TH2::Class()) || x->InheritsFrom(TH2::Class()))
+        return;
+    if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class()))
+    {
+        SetBinning(h, ((TH1*)x)->GetXaxis());
+        return;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Multiplies all entries in a TArrayD by a float f
+//
+void MH::ScaleArray(TArrayD &bins, Double_t f)
+{
+    for (int i=0; i<bins.GetSize(); i++)
+        bins[i] *= f;
+}
+
+// --------------------------------------------------------------------------
+//
+// Scales the binning of a TAxis by a float f
+//
+TArrayD MH::ScaleAxis(TAxis &axe, Double_t f)
+{
+    TArrayD arr(axe.GetNbins()+1);
+
+    for (int i=1; i<=axe.GetNbins()+1; i++)
+        arr[i-1] = axe.GetBinLowEdge(i);
+
+    ScaleArray(arr, f);
+
+    return arr;
+}
+
+// --------------------------------------------------------------------------
+//
+// Scales the binning of one, two or three axis of a histogram by a float f
+//
+void MH::ScaleAxis(TH1 *h, Double_t fx, Double_t fy, Double_t fz)
+{
+    if (h->InheritsFrom(TH3::Class()))
+    {
+        SetBinning((TH3*)h,
+                   ScaleAxis(*h->GetXaxis(), fx),
+                   ScaleAxis(*h->GetYaxis(), fy),
+                   ScaleAxis(*h->GetZaxis(), fz));
+        return;
+    }
+
+    if (h->InheritsFrom(TH2::Class()))
+    {
+        SetBinning((TH2*)h,
+                   ScaleAxis(*h->GetXaxis(), fx),
+                   ScaleAxis(*h->GetYaxis(), fy));
+        return;
+    }
+
+    if (h->InheritsFrom(TH1::Class()))
+        SetBinning(h, ScaleAxis(*h->GetXaxis(), fx));
+}
+
+// --------------------------------------------------------------------------
+//
+// Tries to find a MBinning container with the name "Binning"+name
+// in the given parameter list. If it was found it is applied to the
+// given histogram. This is only valid for 1D-histograms
+//
+Bool_t MH::ApplyBinning(const MParList &plist, TString name, TH1 *h)
+{
+    if (h->InheritsFrom(TH2::Class()) || h->InheritsFrom(TH3::Class()))
+    {
+        gLog << warn << "MH::ApplyBinning: '" << h->GetName() << "' is not a basic TH1 object... no binning applied." << endl;
+        return kFALSE;
+    }
+
+    const MBinning *bins = (MBinning*)plist.FindObject("Binning"+name);
+    if (!bins)
+    {
+        gLog << warn << "Object 'Binning" << name << "' [MBinning] not found... no binning applied." << endl;
+        return kFALSE;
+    }
+
+    SetBinning(h, bins);
+    return kTRUE;
+}
+
+void MH::FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger)
+{
+#if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
+    THLimitsFinder::OptimizeLimits(nbins, newbins, xmin, xmax, isInteger);
+#else
+//*-*-*-*-*-*-*-*-*Find reasonable bin values*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
+//*-*              ==========================
+
+    Double_t dx = 0.1*(xmax-xmin);
+    Double_t umin = xmin - dx;
+    Double_t umax = xmax + dx;
+
+    if (umin < 0 && xmin >= 0)
+        umin = 0;
+
+    if (umax > 0 && xmax <= 0)
+        umax = 0;
+
+    Double_t binlow  =0;
+    Double_t binhigh =0;
+    Double_t binwidth=0;
+
+    TGaxis::Optimize(umin, umax, nbins, binlow, binhigh, nbins, binwidth, "");
+
+    if (binwidth <= 0 || binwidth > 1.e+39)
+    {
+        xmin = -1;
+        xmax = 1;
+    }
+    else
+    {
+        xmin = binlow;
+        xmax = binhigh;
+    }
+
+    if (isInteger)
+    {
+        Int_t ixmin = (Int_t)xmin;
+        Int_t ixmax = (Int_t)xmax;
+        Double_t dxmin = (Double_t)ixmin;
+        Double_t dxmax = (Double_t)ixmax;
+
+        xmin = xmin<0 && xmin!=dxmin ? dxmin - 1 : dxmin;
+        xmax = xmax>0 && xmax!=dxmax ? dxmax + 1 : dxmax;
+
+        if (xmin>=xmax)
+            xmax = xmin+1;
+
+        Int_t bw = 1 + (Int_t)((xmax-xmin)/nbins);
+
+        nbins = (Int_t)((xmax-xmin)/bw);
+
+        if (xmin+nbins*bw < xmax)
+        {
+            nbins++;
+            xmax = xmin +nbins*bw;
+        }
+    }
+
+    newbins = nbins;
+#endif
+}
+
+// --------------------------------------------------------------------------
+//
+//  Returns the lowest entry in a histogram which is greater than gt (eg >0)
+//
+Double_t MH::GetMinimumGT(const TH1 &h, Double_t gt)
+{
+    Double_t min = FLT_MAX;
+
+    const TAxis &axe = *((TH1&)h).GetXaxis();
+
+    for (int i=1; i<=axe.GetNbins(); i++)
+    {
+        Double_t x = h.GetBinContent(i);
+        if (gt<x && x<min)
+            min = x;
+    }
+    return min;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Returns the bin center in a logarithmic scale. If the given bin
+//  number is <1 it is set to 1. If it is =GetNbins() it is set to
+//  GetNbins()
+//
+Double_t MH::GetBinCenterLog(const TAxis &axe, Int_t nbin)
+{
+    if (nbin>axe.GetNbins())
+        nbin = axe.GetNbins();
+
+    if (nbin<1)
+        nbin = 1;
+
+    const Double_t lo = axe.GetBinLowEdge(nbin);
+    const Double_t hi = axe.GetBinUpEdge(nbin);
+
+    const Double_t val = log10(lo) + log10(hi);
+
+    return pow(10, val/2);
+}
+
+// --------------------------------------------------------------------------
+//
+// Draws a copy of the two given histograms. Uses title as the pad title.
+// Also layout the two statistic boxes and a legend.
+//
+void MH::DrawSameCopy(const TH1 &hist1, const TH1 &hist2, const TString title)
+{
+    //
+    // Draw first histogram
+    //
+    TH1 *h1 = ((TH1&)hist1).DrawCopy();
+    gPad->SetBorderMode(0);
+    gPad->Update();
+
+    // FIXME: Also align max/min with set Maximum/Minimum
+    const Double_t maxbin1 = hist1.GetBinContent(hist1.GetMaximumBin());
+    const Double_t maxbin2 = hist2.GetBinContent(hist2.GetMaximumBin());
+    const Double_t minbin1 = hist1.GetBinContent(hist1.GetMinimumBin());
+    const Double_t minbin2 = hist2.GetBinContent(hist2.GetMinimumBin());
+
+    const Double_t max = TMath::Max(maxbin1, maxbin2);
+    const Double_t min = TMath::Min(minbin1, minbin2);
+
+    h1->SetMaximum(max>0?max*1.05:max*0.95);
+    h1->SetMinimum(max>0?min*0.95:min*1.05);
+
+    TPaveText *t = (TPaveText*)gPad->FindObject("title");
+    if (t)
+    {
+        t->SetName((TString)"MHTitle");     // rename object
+        t->Clear();                         // clear old lines
+        t->AddText((TString)" "+title+" "); // add the new title
+        t->SetBit(kCanDelete);              // make sure object is deleted
+
+        //
+        // FIXME: This is a stupid workaround to hide the redrawn
+        // (see THistPainter::PaintTitle) title
+        //
+        gPad->Modified();  // indicates a change
+        gPad->Update();    // recreates the original title
+        t->Pop();          // bring our title on top
+    }
+
+    //
+    // Rename first statistics box
+    //
+    TPaveStats *s1 = (TPaveStats*)gPad->FindObject("stats");
+    if (!s1)
+        s1 = (TPaveStats*)hist1.GetListOfFunctions()->FindObject("stats");
+    else
+        s1->SetName((TString)"Stat"+hist1.GetTitle());
+
+    if (s1 && s1->GetX2NDC()>0.95)
+    {
+        const Double_t x1 = s1->GetX1NDC()-0.01;
+        s1->SetX1NDC(x1-(s1->GetX2NDC()-s1->GetX1NDC()));
+        s1->SetX2NDC(x1);
+    }
+
+    //
+    // Draw second histogram
+    //
+    TH1 *h2 = ((TH1&)hist2).DrawCopy("sames");
+    gPad->Update();
+
+    //
+    // Draw Legend
+    //
+    TPaveStats *s2 = (TPaveStats*)gPad->FindObject("stats");
+    if (!s2)
+        s2 = (TPaveStats*)hist2.GetListOfFunctions()->FindObject("stats");
+
+    if (s2)
+    {
+        TLegend &l = *new TLegend(s2->GetX1NDC(),
+                                  s2->GetY1NDC()-0.015-(s2->GetY2NDC()-s2->GetY1NDC())/2,
+                                  s2->GetX2NDC(),
+                                  s2->GetY1NDC()-0.01
+                                 );
+        l.AddEntry(h1, h1->GetTitle());
+        l.AddEntry(h2, h2->GetTitle());
+        l.SetTextSize(s2->GetTextSize());
+        l.SetTextFont(s2->GetTextFont());
+        l.SetBorderSize(s2->GetBorderSize());
+        l.SetBit(kCanDelete);
+        l.Draw();
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Draws the two given histograms. Uses title as the pad title.
+// Also layout the two statistic boxes and a legend.
+//
+void MH::DrawSame(TH1 &hist1, TH1 &hist2, const TString title)
+{
+    //
+    // Draw first histogram
+    //
+    hist1.Draw();
+    gPad->SetBorderMode(0);
+    gPad->Update();
+
+    if (hist1.GetEntries()>0 && hist2.GetEntries()>0)
+    {
+        const Double_t maxbin1 = hist1.GetBinContent(hist1.GetMaximumBin());
+        const Double_t maxbin2 = hist2.GetBinContent(hist2.GetMaximumBin());
+        const Double_t minbin1 = hist1.GetBinContent(hist1.GetMinimumBin());
+        const Double_t minbin2 = hist2.GetBinContent(hist2.GetMinimumBin());
+
+        const Double_t max = TMath::Max(maxbin1, maxbin2);
+        const Double_t min = TMath::Min(minbin1, minbin2);
+
+        if (max!=min)
+        {
+            hist1.SetMaximum(max>0?max*1.05:max*0.95);
+            hist1.SetMinimum(max>0?min*0.95:min*1.05);
+        }
+    }
+
+    TPaveText *t = (TPaveText*)gPad->FindObject("title");
+    if (t)
+    {
+        t->SetName((TString)"MHTitle");     // rename object
+        t->Clear();                         // clear old lines
+        t->AddText((TString)" "+title+" "); // add the new title
+        t->SetBit(kCanDelete);              // make sure object is deleted
+
+        //
+        // FIXME: This is a stupid workaround to hide the redrawn
+        // (see THistPainter::PaintTitle) title
+        //
+        gPad->Modified();  // indicates a change
+        gPad->Update();    // recreates the original title
+        t->Pop();          // bring our title on top
+    }
+
+    //
+    // Rename first statistics box
+    //
+    // Where to get the TPaveStats depends on the root version
+    TPaveStats *s1 = (TPaveStats*)gPad->FindObject("stats");
+    if (!s1)
+        s1 = (TPaveStats*)hist1.GetListOfFunctions()->FindObject("stats");
+    else
+        s1->SetName((TString)"Stat"+hist1.GetTitle());
+
+    if (s1 && s1->GetX2NDC()>0.95)
+    {
+        const Double_t x1 = s1->GetX1NDC()-0.01;
+        s1->SetX1NDC(x1-(s1->GetX2NDC()-s1->GetX1NDC()));
+        s1->SetX2NDC(x1);
+    }
+
+    //
+    // Draw second histogram
+    //
+    hist2.Draw("sames");
+    gPad->Update();
+
+    //
+    // Draw Legend
+    //
+    // Where to get the TPaveStats depends on the root version
+    TPaveStats *s2 = (TPaveStats*)gPad->FindObject("stats");
+    if (!s2)
+        s2 = (TPaveStats*)hist2.GetListOfFunctions()->FindObject("stats");
+
+    if (s2)
+    {
+        TLegend &l = *new TLegend(s2->GetX1NDC(),
+                                  s2->GetY1NDC()-0.015-(s2->GetY2NDC()-s2->GetY1NDC())/2,
+                                  s2->GetX2NDC(),
+                                  s2->GetY1NDC()-0.01
+                                 );
+        l.AddEntry(&hist1, hist1.GetTitle());
+        l.AddEntry(&hist2, hist2.GetTitle());
+        l.SetTextSize(s2->GetTextSize());
+        l.SetTextFont(s2->GetTextFont());
+        l.SetBorderSize(s2->GetBorderSize());
+        l.SetBit(kCanDelete);
+        l.Draw();
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// If the opt string contains 'nonew' or gPad is not given NULL is returned.
+// Otherwise the present gPad is returned.
+//
+TVirtualPad *MH::GetNewPad(TString &opt)
+{
+    opt.ToLower();
+
+    if (!opt.Contains("nonew"))
+        return NULL;
+
+    opt.ReplaceAll("nonew", "");
+
+    return gPad;
+}
+
+// --------------------------------------------------------------------------
+//
+// Encapsulate the TObject::Clone such, that a cloned TH1 (or derived)
+// object is not added to the current directory, when cloned.
+//
+TObject *MH::Clone(const char *name) const
+{
+    const Bool_t store = TH1::AddDirectoryStatus();
+
+    TH1::AddDirectory(kFALSE);
+    TObject *o = MParContainer::Clone(name);
+    TH1::AddDirectory(store);
+
+    return o;
+}
+
+// --------------------------------------------------------------------------
+//
+// If the opt string contains 'nonew' or gPad is not given a new canvas
+// with size w/h is created. Otherwise the object is cloned and drawn
+// to the present pad. The kCanDelete bit is set for the clone.
+//
+TObject *MH::DrawClone(Option_t *opt, Int_t w, Int_t h) const
+{
+    TString option(opt);
+
+    TVirtualPad *p = GetNewPad(option);
+    if (!p)
+        p = MakeDefCanvas(this, w, h);
+    else
+        p->Clear();
+
+    gROOT->SetSelectedPad(NULL);
+
+    TObject *o = MParContainer::DrawClone(option);
+    o->SetBit(kCanDelete);
+    return o;
+}
+
+// --------------------------------------------------------------------------
+//
+// Check whether a class inheriting from MH overwrites the Draw function
+//
+Bool_t MH::OverwritesDraw(TClass *cls) const
+{
+    if (!cls)
+        cls = IsA();
+
+    //
+    // Check whether we reached the base class MTask
+    //
+    if (TString(cls->GetName())=="MH")
+        return kFALSE;
+
+    //
+    // Check whether the class cls overwrites Draw
+    //
+    if (cls->GetMethodAny("Draw"))
+        return kTRUE;
+
+    //
+    // If the class itself doesn't overload it check all it's base classes
+    //
+    TBaseClass *base=NULL;
+    TIter NextBase(cls->GetListOfBases());
+    while ((base=(TBaseClass*)NextBase()))
+    {
+        if (OverwritesDraw(base->GetClassPointer()))
+            return kTRUE;
+    }
+
+    return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Cuts the bins containing only zeros at the edges.
+//
+//  A new number of bins can be defined with nbins != 0
+//        In the case of nbins == 0, no rebinning will take place
+//
+//  Returns the new (real) number of bins
+//
+Int_t MH::CutEdges(TH1 *h, Int_t nbins)
+{
+    TAxis* axe = h->GetXaxis();
+
+    const Int_t min1   = axe->GetFirst();
+    const Int_t max1   = axe->GetLast();
+    const Int_t range1 = max1-min1;
+
+    //
+    // Check for useless zeros
+    //
+    if (range1 == 0)
+        return 0;
+
+    Int_t min2 = 0;
+    for (int i=min1; i<=max1; i++)
+        if (h->GetBinContent(i) != 0)
+        {
+            min2 = i;
+            break;
+        }
+
+    //
+    // If the histogram consists of zeros only
+    //
+    if (min2 == max1)
+        return 0;
+
+    Int_t max2 = 0;
+    for (int i=max1; i>=min2; i--)
+        if (h->GetBinContent(i) != 0)
+        {
+            max2 = i;
+            break;
+        }
+
+    //
+    // Check for rebinning
+    //
+    if (nbins < 1)
+    {
+        axe->SetRange(min2,max2);
+        return axe->GetLast()-axe->GetFirst();
+    }
+
+    //
+    // Appying TAxis->SetRange before ReBin does not work ...
+    // But this workaround helps quite fine
+    //
+    const Axis_t min = h->GetBinLowEdge(min2);
+    const Axis_t max = h->GetBinLowEdge(max2)+h->GetBinWidth(max2);
+
+    const Int_t ngroup = (int)((max2-min2)*h->GetNbinsX()/nbins/(max1-min1));
+
+    if (ngroup > 1)
+        h->Rebin(ngroup);
+
+    axe->SetRangeUser(min,max);
+
+    return axe->GetLast()-axe->GetFirst();
+}
+
+void MH::ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin, Int_t lastybin)
+{
+    //*-*-*-*-*Project a 2-D histogram into a 1-D histogram along X*-*-*-*-*-*-*
+    //*-*      ====================================================
+    //
+    //   The projection dest is always of the type TH1D.
+    //   The projection is made from the channels along the Y axis
+    //   ranging from firstybin to lastybin included.
+    //   By default, bins 1 to ny are included
+    //   When all bins are included, the number of entries in the projection
+    //   is set to the number of entries of the 2-D histogram, otherwise
+    //   the number of entries is incremented by 1 for all non empty cells.
+    //
+    //   if Sumw2() was called for dest, the errors are computed.
+    //
+    TAxis &axex = *((TH2&)src).GetXaxis();
+    TAxis &axey = *((TH2&)src).GetYaxis();
+
+    const Int_t nx = axex.GetNbins();
+    const Int_t ny = axey.GetNbins();
+    if (firstybin < 0)
+        firstybin = 1;
+    if (lastybin > ny)
+        lastybin = ny;
+
+    dest.Reset();
+    SetBinning(&dest, &axex);
+
+    // Create the projection histogram
+    const Bool_t computeErrors = dest.GetSumw2N() ? 1 : 0;
+
+    // Fill the projected histogram
+    for (Int_t binx=0; binx<=nx+1; binx++)
+    {
+        Double_t err2 = 0;
+        for (Int_t biny=firstybin; biny<=lastybin; biny++)
+        {
+            const Double_t cont = src.GetCellContent(binx,biny);
+            const Double_t err1 = src.GetCellError(binx,biny);
+            err2 += err1*err1;
+            if (cont)
+                dest.Fill(axex.GetBinCenter(binx), cont);
+        }
+        if (computeErrors)
+            dest.SetBinError(binx, TMath::Sqrt(err2));
+    }
+    if (firstybin <=1 && lastybin >= ny)
+        dest.SetEntries(src.GetEntries());
+}
+
+void MH::ProjectionY(TH1D &dest, const TH2 &src, Int_t firstxbin, Int_t lastxbin)
+{
+    //*-*-*-*-*Project a 2-D histogram into a 1-D histogram along X*-*-*-*-*-*-*
+    //*-*      ====================================================
+    //
+    //   The projection dest is always of the type TH1D.
+    //   The projection is made from the channels along the Y axis
+    //   ranging from firstybin to lastybin included.
+    //   By default, bins 1 to ny are included
+    //   When all bins are included, the number of entries in the projection
+    //   is set to the number of entries of the 2-D histogram, otherwise
+    //   the number of entries is incremented by 1 for all non empty cells.
+    //
+    //   if Sumw2() was called for dest, the errors are computed.
+    //
+    TAxis &axex = *((TH2&)src).GetXaxis();
+    TAxis &axey = *((TH2&)src).GetYaxis();
+
+    const Int_t nx = axex.GetNbins();
+    const Int_t ny = axey.GetNbins();
+    if (firstxbin < 0)
+        firstxbin = 1;
+    if (lastxbin > nx)
+        lastxbin = nx;
+
+    dest.Reset();
+    SetBinning(&dest, &axey);
+
+    // Create the projection histogram
+    const Bool_t computeErrors = dest.GetSumw2N() ? 1 : 0;
+
+    // Fill the projected histogram
+    for (Int_t biny=0; biny<=ny+1; biny++)
+    {
+        Double_t err2 = 0;
+        for (Int_t binx=firstxbin; binx<=lastxbin; binx++)
+        {
+            const Double_t cont = src.GetCellContent(binx,biny);
+            const Double_t err1 = src.GetCellError(binx,biny);
+            err2 += err1*err1;
+            if (cont)
+                dest.Fill(axey.GetBinCenter(biny), cont);
+        }
+        if (computeErrors)
+            dest.SetBinError(biny, TMath::Sqrt(err2));
+    }
+    if (firstxbin <=1 && lastxbin >= nx)
+        dest.SetEntries(src.GetEntries());
+}
+
+// --------------------------------------------------------------------------
+//
+// In contradiction to TPad::FindObject this function searches recursively
+// in a pad for an object. gPad is the default.
+//
+TObject *MH::FindObjectInPad(const char *name, TVirtualPad *pad)
+{
+    if (!pad)
+        pad = gPad;
+
+    if (!pad)
+        return NULL;
+
+    TObject *o;
+
+    TIter Next(pad->GetListOfPrimitives());
+    while ((o=Next()))
+    {
+        if (!strcmp(o->GetName(), name))
+            return o;
+
+        if (o->InheritsFrom("TPad"))
+            if ((o = FindObjectInPad(name, (TVirtualPad*)o)))
+                return o;
+    }
+    return NULL;
+}
Index: trunk/MagicSoft/Mars/mhbase/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MH.h	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MH.h	(revision 2735)
@@ -0,0 +1,101 @@
+#ifndef MARS_MH
+#define MARS_MH
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class TH1;
+class TH1D;
+class TH2;
+class TH3;
+class TAxis;
+class TArrayD;
+class TCanvas;
+
+class MBinning;
+class MParList;
+
+class MH : public MParContainer
+{
+private:
+    Byte_t fSerialNumber;
+
+public:
+    MH(const char *name=NULL, const char *title=NULL);
+
+
+    virtual void SetSerialNumber(Byte_t num) { fSerialNumber = num; }
+    Byte_t  GetSerialNumber() const { return fSerialNumber; }
+    TString AddSerialNumber(const char *str) const { TString s(str); if (fSerialNumber==0) return s; s += ";"; s += fSerialNumber; return s; }
+    TString AddSerialNumber(const TString &str) const { return AddSerialNumber((const char*)str); }
+
+    Bool_t OverwritesDraw(TClass *cls=NULL) const;
+
+    virtual Bool_t SetupFill(const MParList *pList) { return kTRUE; }
+    virtual Bool_t ReInit(MParList *pList) { return kTRUE; }
+    virtual Bool_t Fill(const MParContainer *par, const Stat_t weight=1);
+    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="",
+                                  UInt_t w=625, UInt_t h=440,
+                                  Bool_t usescreenfactor=kTRUE);
+    static TCanvas *MakeDefCanvas(const TObject *obj,
+                                  UInt_t w=625, UInt_t h=440,
+                                  Bool_t usescreenfactor=kFALSE);
+
+    // FIXME: * --> & !!!
+
+    static void SetBinning(TH1 *h, const MBinning *binsx);
+    static void SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy);
+    static void SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz);
+
+    static void SetBinning(TH1 *h, const TArrayD &binsx);
+    static void SetBinning(TH2 *h, const TArrayD &binsx, const TArrayD &binsy);
+    static void SetBinning(TH3 *h, const TArrayD &binsx, const TArrayD &binsy, const TArrayD &binsz);
+
+    static void SetBinning(TH1 *h, const TAxis *binsx);
+    static void SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy);
+    static void SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz);
+
+    static void SetBinning(TH1 *h, const TH1 *x);
+
+    static Bool_t ApplyBinning(const MParList &plist, TString name, TH1 *h);
+
+    static void    ScaleArray(TArrayD &bins, Double_t f);
+    static TArrayD ScaleAxis(TAxis &axe, Double_t f);
+    static void    ScaleAxis(TH1 *bins, Double_t fx=1, Double_t fy=1, Double_t fz=1);
+
+    static Double_t GetBinCenterLog(const TAxis &axe, Int_t nbin);
+
+    static void DrawSameCopy(const TH1 &hist1, const TH1 &hist2, const TString title);
+    static void DrawSame(TH1 &hist1, TH1 &hist2, const TString title);
+
+    TObject *Clone(const char *name="") const;
+
+    TObject *DrawClone(Option_t *opt, Int_t w, Int_t h) const;
+    TObject *DrawClone(Option_t *opt="") const
+    {
+        return MH::DrawClone(opt, 625, 440);
+    }
+
+    static TVirtualPad *GetNewPad(TString &opt);
+
+    static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger);
+    static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0);
+    static Int_t CutEdges(TH1 *h, Int_t nbins);
+    
+    static void ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin=-1, Int_t lastybin=9999);
+    static void ProjectionY(TH1D &dest, const TH2 &src, Int_t firstxbin=-1, Int_t lastxbin=9999);
+
+    static TObject *FindObjectInPad(const char *name, TVirtualPad *pad=NULL);
+
+    ClassDef(MH, 1) //A base class for Mars histograms
+};
+
+#endif
+
Index: trunk/MagicSoft/Mars/mhbase/MHArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHArray.cc	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MHArray.cc	(revision 2735)
@@ -0,0 +1,772 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 access the histograms by a key instead of an index use SetIndexByKey
+//  instead of Set/Inc/DecIndex. It will take the integerpart of the
+//  floating point value (2 in case of 2.9). For each new key a new
+//  index in the Mapping Table is created. So that you can access your
+//  histograms by the key (eg in case of the Angle Theta=23.2deg use
+//  SetIndexByKey(23.2)
+//
+//  If the index is equal to the number of histograms in the array a call
+//  to the Fill-member-function will create a new histogram.
+//
+//  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);
+
+using namespace std;
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// 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:
+    // --------------------------------------------------------------------------
+    //
+    // Return the size of the table
+    //
+    Int_t GetSize() const
+    {
+        return fKeys.GetSize();
+    }
+
+    // --------------------------------------------------------------------------
+    //
+    // 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;
+    }
+
+    // --------------------------------------------------------------------------
+    //
+    // Get the key which corresponds to the given index
+    //
+    Int_t GetKey(Int_t value) const
+    {
+        const Int_t n = fKeys.GetSize();
+        for (int i=0; i<n; i++)
+        {
+            if (V(i)==value)
+                return K(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;
+    }
+};
+
+void MHArray::Init(const char *name)
+{
+    fName  = name  ? name  : "MHArray";
+
+    fMapIdx = new MMap;
+
+    fArray = new TList;
+    fArray->SetOwner();
+}
+
+// --------------------------------------------------------------------------
+//
+// Can replace a constructor. Use the default constructor and afterwards
+// the Set function of your need.
+//
+void MHArray::Set(const TString hname, Bool_t istempl)
+{
+    if (fTemplate || fClass || fTemplateName!="<dummy>")
+    {
+        *fLog << warn << "WARNING - MHArray already setup... Set ignored." << endl;
+        return;
+    }
+
+    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;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Can replace a constructor. Use the default constructor and afterwards
+// the Set function of your need.
+//
+void MHArray::Set(const MH *hist)
+{
+    fIdx=0;
+    fClass=NULL;
+    fTemplate=hist;
+    fTemplateName="<dummy>";
+}
+
+
+// --------------------------------------------------------------------------
+//
+// 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
+    //
+    Init(name);
+    fTitle = title ? TString(title) : (TString("Base class for Mars histogram arrays:") + hname);
+
+    Set(hname, istempl);
+}
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. Use MHArray::Set to setup the MHArray afterwards
+//
+MHArray::MHArray(const char *name, const char *title)
+    : fIdx(0), fClass(NULL), fTemplate(NULL), fTemplateName("<dummy>")
+{
+    //
+    //   set the name and title of this object
+    //
+    Init(name);
+    fTitle = title ? title : "A Mars histogram array";
+}
+
+// --------------------------------------------------------------------------
+//
+// 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 MH *hist, const char *name, const char *title)
+    : fIdx(0), fClass(NULL), fTemplate(hist), fTemplateName("<dummy>")
+{
+    //
+    //   set the name and title of this object
+    //
+    Init(name);
+    fTitle = title ? TString(title) : (TString("Base class for Mars histogram arrays:") + hist->GetName());
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor: Deleteing the array and all histograms which are part of the
+// array.
+//
+MHArray::~MHArray()
+{
+    fArray->Delete();
+    delete fArray;
+    delete fMapIdx;
+}
+
+// --------------------------------------------------------------------------
+//
+//  Use this to access the histograms by a key. If you use values like
+//   (in this order) 2.5, 7.2, 2.5, 9.3, 9.3, 3.3, 2.2, 1.1
+//  it will be mapped to the following indices internally:
+//                    0    1    0    2    2    3    4    5
+//
+//  WARNING: Make sure that you don't create new histograms by setting
+//           a new index (SetIndex or IncIndex) which is equal the size
+//           of the array and create new histogram by CreateH. In this
+//           case you will confuse the mapping completely.
+//
+void MHArray::SetIndexByKey(Double_t key)
+{
+    fIdx = fMapIdx->Add((Int_t)key);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Use this function to access a histogram by its index in the array.
+//  Becarefull the index isn't checked!
+//
+MH &MHArray::operator[](Int_t i)
+{
+    return *(MH*)fArray->At(i);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Use this function to access a histogram by its index in the array.
+//  Becarefull the index isn't checked!
+//
+MH *MHArray::At(Int_t i)
+{
+    return (MH*)fArray->At(i);
+}
+
+// --------------------------------------------------------------------------
+//
+//  Use this function to access the histogram corresponding to the
+//  currently set index (by Set/Inc/DecIndex or SetIndexByKey)
+//  Becarefull the index set isn't checked!
+//
+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)
+    {
+        //
+        // create the parameter container as a clone of the existing
+        // template histogram.
+        //
+        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 (fTemplate)
+        return kTRUE;
+
+    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 Stat_t w)
+{
+    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, w);
+}
+
+Bool_t MHArray::AddHistogram()
+{
+    fIdx=fArray->GetSize();
+
+    return CreateH();
+}
+
+// --------------------------------------------------------------------------
+//
+// 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;
+
+    if (fMapIdx->GetSize()<=0)
+        return;
+
+    *fLog << " idx\t     key" << endl;
+    for (int i=0; i<fMapIdx->GetSize(); i++)
+        *fLog << "  " << i << "\t<-->  " << fMapIdx->GetKey(i) << endl;
+    *fLog << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// Adds the given object to the given legend (if != NULL). The Legend
+// entry name is created from the key...
+//
+void MHArray::AddLegendEntry(TLegend *leg, TObject *obj, Int_t idx) const
+{
+    if (!leg)
+        return;
+
+    TString name = " ";
+    name += fMapIdx->GetKey(idx);
+    leg->AddEntry(obj, name, "lpf"); // l=line, p=polymarker, f=fill
+}
+
+
+// --------------------------------------------------------------------------
+//
+// 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 Int_t sstyle = gStyle->GetOptStat();
+    gStyle->SetOptStat(0);
+
+    //
+    // if the keymapping is used create a legend to identify the histograms
+    //
+    TLegend *leg = NULL;
+    if (fMapIdx->GetSize()>0)
+    {
+        leg = new TLegend(0.85, 0.80, 0.99, 0.99);
+        leg->SetBit(kCanDelete);
+    }
+
+    TIter Next(fArray);
+    MH *hist = (MH*)Next();
+
+    Int_t idx=0;
+    Double_t max=0;
+    Double_t min=0;
+
+    TH1 *h1=NULL;
+
+    //
+    // If the array has at least one entry:
+    //  - find the starting boundaries
+    //  - draw it and set its line color
+    //
+    if (hist)
+    {
+        if ((h1 = hist->GetHistByName(opt)))
+        {
+            h1->Draw();
+            h1->SetLineColor(idx+2);
+            max = h1->GetMaximum();
+            min = h1->GetMinimum();
+
+            AddLegendEntry(leg, h1, idx);
+        }
+    }
+
+    //
+    // For all following histograms:
+    //  - update the boundaries
+    //  - draw it and set its line color
+    //
+    while ((hist=(MH*)Next()))
+    {
+        TH1 *h=NULL;
+
+        if (!(h = hist->GetHistByName(opt)))
+            continue;
+
+        h->Draw("same");
+        h->SetLineColor(idx+2);
+        if (max<h->GetMaximum())
+            max = h->GetMaximum();
+        if (min>h->GetMinimum())
+            min = h->GetMinimum();
+
+        AddLegendEntry(leg, h, idx++);
+    }
+
+    //
+    // Now update the drawing region so that everything is displayed
+    //
+    if (h1)
+    {
+        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
+        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
+    }
+
+    if (leg)
+        leg->Draw();
+
+    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.
+// The option "Scale=1" scales the area of all histogram to 1
+// The option "Scale=max" scales the maximum of all histogram to 1
+//
+TObject *MHArray::DrawClone(Option_t *opt) const
+{
+    TString o(opt);
+
+    TCanvas *c = NULL;
+
+    Int_t scale1   = o.Index("scale=1",   TString::kIgnoreCase);
+    Int_t scalemax = o.Index("scale=max", TString::kIgnoreCase);
+    Int_t nonew    = o.Index("nonew",     TString::kIgnoreCase);
+
+    if (o.BeginsWith("scale=1", TString::kIgnoreCase))
+        scale1 = 0;
+    if (o.BeginsWith("scale=max", TString::kIgnoreCase))
+        scalemax = 0;
+    if (o.BeginsWith("nonew", TString::kIgnoreCase))
+        nonew = 0;
+
+    if (nonew>=0)
+    {
+        c = MH::MakeDefCanvas(this);
+
+        //
+        // This is necessary to get the expected bahviour of DrawClone
+        //
+        gROOT->SetSelectedPad(NULL);
+
+        o.Remove(nonew, 5);
+    }
+    if (scale1>=0)
+        o.Remove(scale1, 7);
+    if (scalemax>=0)
+        o.Remove(scalemax, 9);
+
+    const Int_t sstyle = gStyle->GetOptStat();
+    gStyle->SetOptStat(0);
+
+    //
+    // if the keymapping is used create a legend to identify the histograms
+    //
+    TLegend *leg = NULL;
+    if (fMapIdx->GetSize()>0)
+    {
+        leg = new TLegend(0.85, 0.80, 0.99, 0.99);
+        leg->SetBit(kCanDelete);
+    }
+
+    TIter Next(fArray);
+    MH *hist = (MH*)Next();
+
+    Int_t idx=0;
+    Double_t max=0;
+    Double_t min=0;
+
+    TH1 *h1=NULL;
+
+     //
+    // If the array has at least one entry:
+    //  - find the starting boundaries
+    //  - draw it and set its line color
+    //
+    if (hist)
+    {
+        if ((h1 = hist->GetHistByName(o)))
+        {
+            h1 = (TH1*)h1->DrawCopy();
+
+            if (scale1>=0)
+                h1->Scale(1./h1->Integral());
+            if (scalemax>=0)
+                h1->Scale(1./h1->GetMaximum());
+
+            h1->SetMarkerColor(idx);
+            h1->SetLineColor(idx+2);
+            h1->SetFillStyle(4000);
+            max = h1->GetMaximum();
+            min = h1->GetMinimum();
+
+            AddLegendEntry(leg, h1, idx++);
+        }
+    }
+
+    //
+    // For all following histograms:
+    //  - update the boundaries
+    //  - draw it and set its line color
+    //
+    while ((hist=(MH*)Next()))
+    {
+        TH1 *h=NULL;
+
+        if (!(h = hist->GetHistByName(o)))
+            continue;
+
+        h = (TH1*)h->DrawCopy("same");
+
+        if (scale1>=0)
+            h->Scale(1./h->Integral());
+        if (scalemax>=0)
+            h->Scale(1./h->GetMaximum());
+
+        h->SetMarkerColor(idx);
+        h->SetLineColor(idx+2);
+        h->SetFillStyle(4000); // transperent (why is this necessary?)
+        if (max<h->GetMaximum())
+            max = h->GetMaximum();
+        if (min>h->GetMinimum())
+            min = h->GetMinimum();
+
+        AddLegendEntry(leg, h, idx++);
+    }
+
+    //
+    // Now update the drawing region so that everything is displayed
+    //
+    if (h1)
+    {
+        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
+        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
+    }
+
+    if (leg)
+        leg->Draw();
+
+    gPad->Modified();
+    gPad->Update();
+
+    gStyle->SetOptStat(sstyle);
+
+    return c;
+}
Index: trunk/MagicSoft/Mars/mhbase/MHArray.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MHArray.h	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MHArray.h	(revision 2735)
@@ -0,0 +1,71 @@
+#ifndef MARS_MHArray
+#define MARS_MHArray
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+class TList;
+class TLegend;
+
+class MMap;
+
+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
+
+    const MH *fTemplate;      //-> pointer to a template histogram
+    TString fTemplateName;    // name of the template class
+
+    MMap *fMapIdx;            //! Table to map keys to array indices
+
+    Bool_t CreateH();
+    void   AddLegendEntry(TLegend *leg, TObject *obj, Int_t idx) const;
+
+    enum { kUseTemplate=BIT(14) };
+
+    void Init(const char *name);
+
+public:
+    MHArray(const char *name=NULL, const char *title=NULL);
+    MHArray(const TString hname, Bool_t istempl=kFALSE, const char *name=NULL, const char *title=NULL);
+    MHArray(const MH *hist, const char *name=NULL, const char *title=NULL);
+    ~MHArray();
+
+    void Set(const TString hname, Bool_t istempl=kFALSE);
+    void Set(const MH *hist);
+
+    Bool_t SetupFill(const MParList *pList);
+    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
+    Bool_t Finalize();
+
+    Bool_t AddHistogram();
+
+    MH &operator[](Int_t i);
+    MH *At(Int_t i);
+
+    MH *GetH();
+
+    void SetIndexByKey(Double_t key);
+
+    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/mhbase/MWeight.cc
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MWeight.cc	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MWeight.cc	(revision 2735)
@@ -0,0 +1,35 @@
+/* ======================================================================== *\
+!
+! *
+! * 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/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2003
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//   MWeight
+//
+//   Storage container for a weight to fill histograms
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MWeight.h"
+
+ClassImp(MWeight);
+
Index: trunk/MagicSoft/Mars/mhbase/MWeight.h
===================================================================
--- trunk/MagicSoft/Mars/mhbase/MWeight.h	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/MWeight.h	(revision 2735)
@@ -0,0 +1,32 @@
+#ifndef MARS_MWeight
+#define MARS_MWeight
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//  MWeight                                                                //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MWeight : public MParContainer
+{
+private:
+    Double_t fWeight;
+
+public:
+    MWeight(const char *name=NULL, const char *title=NULL) : fWeight(1)
+    {
+        fName  = name  ? name  : "MWeight";
+        fTitle = title ? title : "A weight for filling histograms";
+    }
+
+    void SetWeight(Double_t weight) { fWeight = weight; }
+    Double_t GetWeight() const { return fWeight; }
+
+    ClassDef(MWeight, 1) // A weight for filling histograms
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mhbase/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhbase/Makefile	(revision 2735)
+++ trunk/MagicSoft/Mars/mhbase/Makefile	(revision 2735)
@@ -0,0 +1,58 @@
+##################################################################
+#
+#   makefile
+# 
+#   for the MARS software
+#
+##################################################################
+include ../Makefile.conf.$(OSTYPE)
+include ../Makefile.conf.general
+
+#
+# Handling name of the Root Dictionary Files
+#
+CINT  = HBase
+
+#
+# Library name to creatre
+#
+LIB   = mhbase.a
+
+#
+#  connect the include files defined in the config.mk file
+#
+INCLUDES = -I. -I../mbase -I../mdata
+
+#------------------------------------------------------------------------------
+
+.SUFFIXES: .c .cc .cxx .h .hxx .o 
+
+SRCFILES = MFillH.cc \
+           MBinning.cc \
+           MWeight.cc \
+           MH.cc \
+           MHArray.cc
+
+SRCS    = $(SRCFILES)
+HEADERS = $(SRCFILES:.cc=.h)
+OBJS    = $(SRCFILES:.cc=.o) 
+
+############################################################
+
+all: $(LIB)
+
+include ../Makefile.rules
+
+clean:	rmcint rmobjs rmcore rmlib
+
+mrproper:	clean rmbak
+
+# @endcode
+
+
+
+
+
+
+
+
Index: trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 2734)
+++ trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 2735)
@@ -5,13 +5,6 @@
 #pragma link off all functions;
 
-#pragma link C++ class MFillH+;
-
-#pragma link C++ class MH+;
-#pragma link C++ class MHArray+;
 #pragma link C++ class MH3+;
 #pragma link C++ class MHVsTime+;
-
-#pragma link C++ class MBinning+;
-#pragma link C++ class MWeight+;
 
 #pragma link C++ class MHMatrix+;
Index: trunk/MagicSoft/Mars/mhist/MBinning.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MBinning.cc	(revision 2734)
+++ 	(revision )
@@ -1,205 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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, 01/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MBinning                                                                //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-#include "MBinning.h"
-
-#include <ctype.h>      // tolower
-#include <fstream>
-
-#include <TH1.h>        // InheritsFrom
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MH.h"
-
-ClassImp(MBinning);
-
-using namespace std;
-
-static const TString gsDefName  = "MBinning";
-static const TString gsDefTitle = "Container describing the binning of an axis";
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor. It sets name and title only. Typically you won't
-// need to change this.
-//
-MBinning::MBinning(const char *name, const char *title)
-{
-    //
-    //   set the name and title of this object
-    //
-    fName  = name  ? name  : gsDefName.Data();
-    fTitle = title ? title : gsDefTitle.Data();
-
-    SetEdges(10, 0, 1);
-
-    fType = kIsDefault;
-}
-
-void MBinning::SetEdges(const TAxis &axe)
-{
-    const TArrayD &arr = *((TAxis&)axe).GetXbins();
-    if (arr.GetSize()>0)
-    {
-        SetEdges(arr);
-        return;
-    }
-
-    SetEdges(axe.GetNbins(), axe.GetXmin(), axe.GetXmax());
-}
-
-void MBinning::SetEdges(const TH1 &h, const Char_t axis)
-{
-    TH1 &hist = (TH1&)h; // get rid of const qualifier
-    switch (tolower(axis))
-    {
-    case 'x':
-        SetEdges(*hist.GetXaxis());
-        return;
-    case 'y':
-        SetEdges(*hist.GetYaxis());
-        return;
-    case 'z':
-        SetEdges(*hist.GetZaxis());
-        return;
-    default:
-        *fLog << warn << "MBinning::SetEdges: Axis '" << axis << "' unknown... using x." << endl;
-        SetEdges(*hist.GetXaxis());
-    }
-}
-
-// --------------------------------------------------------------------------
-//
-// Specify the number of bins <nbins> (not the number of edges), the
-// lowest <lo> and highest <up> Edge (of your histogram)
-//
-void MBinning::SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up)
-{
-    const Double_t binsize = (up-lo)/nbins;
-    fEdges.Set(nbins+1);
-    for (int i=0; i<=nbins; i++)
-            fEdges[i] = binsize*i + lo;
-
-    fType = kIsLinear;
-}
-
-// --------------------------------------------------------------------------
-//
-// Specify the number of bins <nbins> (not the number of edges), the
-// lowest <lo> and highest <up> Edge (of your histogram)
-//
-void MBinning::SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up)
-{
-    // if (lo==0) ...
-
-    const Double_t binsize = log10(up/lo)/nbins;
-    fEdges.Set(nbins+1);
-    for (int i=0; i<=nbins; i++)
-        fEdges[i] = pow(10, binsize*i) * lo;
-
-    fType = kIsLogarithmic;
-}
-
-// --------------------------------------------------------------------------
-//
-// Specify the number of bins <nbins> (not the number of edges), the
-// lowest [deg] <lo> and highest [deg] <up> Edge (of your histogram)
-//
-void MBinning::SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up)
-{
-    // if (lo==0) ...
-    const Axis_t ld = lo/kRad2Deg;
-    const Axis_t ud = up/kRad2Deg;
-
-    const Double_t binsize = (cos(ld)-cos(ud))/nbins;
-    fEdges.Set(nbins+1);
-    for (int i=0; i<=nbins; i++)
-        fEdges[i] = acos(cos(ld)-binsize*i)*kRad2Deg;
-
-    fType = kIsCosinic;
-}
-
-// --------------------------------------------------------------------------
-//
-// Apply this binning to the given histogram.
-// (By definition this works only for 1D-histograms. For 2D- and 3D-
-//  histograms use MH::SetBinning directly)
-//
-void MBinning::Apply(TH1 &h)
-{
-    if (h.InheritsFrom("TH2") || h.InheritsFrom("TH3"))
-    {
-        *fLog << warn << "MBinning::Apply: '" << h.GetName() << "' is not a basic TH1 object... no binning applied." << endl;
-        return;
-    }
-
-    MH::SetBinning(&h, this);
-}
-
-// --------------------------------------------------------------------------
-//
-// 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 MBinning::StreamPrimitive(ofstream &out) const
-{
-    out << "   MBinning " << GetUniqueName();
-    if (fName!=gsDefName || fTitle!=gsDefTitle)
-    {
-        out << "(\"" << fName << "\"";
-        if (fTitle!=gsDefTitle)
-            out << ", \"" << fTitle << "\"";
-        out <<")";
-    }
-    out << ";" << endl;
-
-    if (IsDefault())
-        return;
-
-    if (IsLinear() || IsLogarithmic() || IsCosinic())
-    {
-        out << "   " << GetUniqueName() << ".SetEdges";
-        if (IsLogarithmic())
-            out << "Log";
-        if (IsCosinic())
-            out << "Cos";
-        out << "(" << GetNumBins() << ", " << GetEdgeLo() << ", " << GetEdgeHi() << ");" << endl;
-        return;
-    }
-
-    out << "   {" << endl;
-    out << "      TArrayD dummy;" << endl;
-    for (int i=0; i<GetNumEdges(); i++)
-        out << "      dummy[" << i << "]=" << GetEdges()[i] << ";" << endl;
-    out << "      " << GetUniqueName() << ".SetEdges(dummy);" << endl;
-    out << "   }" << endl;
-}
Index: trunk/MagicSoft/Mars/mhist/MBinning.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MBinning.h	(revision 2734)
+++ 	(revision )
@@ -1,86 +1,0 @@
-#ifndef MARS_MBinning
-#define MARS_MBinning
-
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
-#endif
-
-#ifndef ROOT_TArrayD
-#include <TArrayD.h>
-#endif
-
-class TH1;
-class TAxis;
-
-class MBinning : public MParContainer
-{
-private:
-    TArrayD fEdges;
-
-    Byte_t  fType;
-
-    void StreamPrimitive(ofstream &out) const;
-
-    enum {
-        kIsDefault,
-        kIsLinear,
-        kIsLogarithmic,
-        kIsCosinic,
-        kIsUserArray
-    };
-
-public:
-    MBinning(const char *name=NULL, const char *title=NULL);
-
-    void SetEdges(const TArrayD &arr)
-    {
-        fEdges = arr;
-        fType = kIsUserArray;
-    }
-
-    void SetEdges(const TAxis &axe);
-    void SetEdges(const TH1 &h, const Char_t axis='x');
-    void SetEdges(const Int_t nbins, const Axis_t lo, Axis_t up);
-    void SetEdgesLog(const Int_t nbins, const Axis_t lo, Axis_t up);
-    void SetEdgesCos(const Int_t nbins, const Axis_t lo, Axis_t up);
-
-    Int_t FindLoEdge(Double_t val) const
-    {
-        if (val<GetEdgeLo() || val>=GetEdgeHi())
-            return -1;
-
-	for (int i=1; i<fEdges.GetSize(); i++)
-        {
-            if (((TArrayD)fEdges)[i] >= val)
-                return i-1;
-        }
-        return -1;
-    }
-    Int_t FindHiEdge(Double_t val) const
-    {
-        const Int_t i = FindLoEdge(val);
-        return i<0 ? -1 : i+1;
-    }
-
-    // FIXME: ROOT workaround: "operator[] const" missing
-    Double_t GetEdgeLo() const { return ((TArrayD)fEdges)[0]; }
-    Double_t GetEdgeHi() const { return ((TArrayD)fEdges)[fEdges.GetSize()-1]; }
-
-    Int_t GetNumEdges() const { return fEdges.GetSize(); }
-    Int_t GetNumBins() const { return fEdges.GetSize()-1; }
-
-    Double_t *GetEdges() const { return (Double_t*)fEdges.GetArray(); }
-
-    Bool_t IsLinear() const { return fType==kIsLinear; }
-    Bool_t IsLogarithmic() const { return fType==kIsLogarithmic; }
-    Bool_t IsCosinic() const { return fType==kIsCosinic; }
-    Bool_t IsDefault() const { return fType==kIsDefault; }
-    Bool_t IsUserArray() const { return fType==kIsUserArray; }
-
-    void Apply(TH1 &);
-
-    ClassDef(MBinning, 1) //Container to store the binning of a histogram
-};
-
-#endif
-
Index: trunk/MagicSoft/Mars/mhist/MFillH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 2734)
+++ 	(revision )
@@ -1,589 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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-2003
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MFillH                                                                  //
-//                                                                          //
-//  This is a common interface (task) to fill mars histograms. Every mars   //
-//  histogram which is derived from MH can be filled with this task.        //
-//                                                                          //
-//  There are two options to use:                                           //
-//                                                                          //
-//  1) You specifiy the parameter container with which data the             //
-//     histogram container should be filled, and the histogram container    //
-//     which has to be filled. This can be done by either specifing the     //
-//     name of the objects in the parameter list or by specifiing a pointer //
-//     to the object. (s. Constructor)                                      //
-//                                                                          //
-//  2) You specify the name and/or type of the histogram to become filled.  //
-//     Any other action imust be taken by the histogram class.              //
-//                                                                          //
-//  PreProcess: In the preprocessing of this task we setup all pointers     //
-//              to instances which are needed and call FillSetup of the     //
-//              histogram class with the parameter list as an argument.     //
-//                                                                          //
-//  Process: The process function calls the Fill member function of the     //
-//           histogram class instance (inheriting from MH) with either      //
-//           a NULL pointer or a pointer to the corresponding container     //
-//           as an argument.                                                //
-//                                                                          //
-// To use a weight for each event filled in a histogram call                //
-// SetWeight(). You can eithe use the name of a MWeight container stored    //
-// in the parameter list or a pointer to it as an argument.                 //
-//                                                                          //
-//                                                                          //
-//  WARNING:                                                                //
-//   Because MFillH is a generalized task to fill histograms it doesn't     //
-//   know about which branches from a file are necessary to fill the        //
-//   histograms. If you are reading data from a file which is directly      //
-//   filled into a histogram via MFillH, please call either                 //
-//   MReadTree::DisableAutoScheme() or enable the necessary branches by     //
-//   yourself, using MReadTree::EnableBranch()                              //
-//                                                                          //
-//   Checkout the Warning in MTaskList.                                     //
-//                                                                          //
-//  Input Containers:                                                       //
-//   A parameter container                                                  //
-//                                                                          //
-//  Output Containers:                                                      //
-//   A histogram container                                                  //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-#include "MFillH.h"
-
-#include <fstream>
-
-#include <TClass.h>
-#include <TCanvas.h>
-
-#include "MDataChain.h"
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MH.h"
-#include "MHArray.h"
-
-#include "MWeight.h"
-
-#include "MParList.h"
-#include "MStatusDisplay.h"
-
-ClassImp(MFillH);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Initializes name and title of the object. It is called by all
-// constructors.
-//
-void MFillH::Init(const char *name, const char *title)
-{
-    fName  = name  ? name  : "MFillH";
-    fTitle = title ? title : "Task to fill Mars histograms";
-
-    fH            = NULL;
-    fParContainer = NULL;
-
-    fIndex  = NULL;
-    fCanvas = NULL;
-
-    fWeight     = NULL;
-    fWeightName = "";
-}
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor. This is to support some root-stuff.
-// Never try to use it yourself!
-//
-MFillH::MFillH()
-{
-    Init(NULL, NULL);
-}
-
-// --------------------------------------------------------------------------
-//
-// Constructor.
-//
-// 1) - par is the name of the parameter container which should be filled into
-//      the histogram
-//    - hist is the name of the histogram container (which must have been
-//      derived from MH)
-//
-//    In this case MH::Fill is called with a pointer to the corresponding
-//    histogram instance.
-//
-// 2) - hist is the name and/or type of the histogram.
-//      1) The name and type is identical, eg: "MHHillas"
-//      2) They are not identical, eg: "MyHistogram [MHHillas]"
-//         This searches for a class instance of MHHillas with the name
-//         "MyHistogram". If it doesn't exist one is created.
-//
-//    In this case PreProcess calls MH::SetupFill with a pointer to the
-//    parameter list and MH::Fill is called with a NULL-pointer.
-//
-MFillH::MFillH(const char *hist, const char *par, const char *name, const char *title)
-{
-    Init(name, title);
-
-    fHName = hist;
-    fParContainerName = par;
-
-    AddToBranchList(Form("%s.*", (const char*)ExtractName(hist)));
-    if (par)
-        AddToBranchList(Form("%s.*", (const char*)ExtractName(par)));
-
-    if (title)
-        return;
-
-    fTitle = "Fill " + fHName;
-    if (fParContainerName.IsNull())
-        return;
-
-    fTitle += " from " + fParContainerName;
-}
-
-// --------------------------------------------------------------------------
-//
-// Constructor.
-//
-// 1) - par is a pointer to the instance of your parameter container from which
-//      the data should be used to fill the histogram.
-//    - hist is the name of the histogram container (which must have been
-//      derived from MH)
-//
-//    In this case MH::Fill is called with a pointer to the corresponding
-//    histogram instance.
-//
-// 2) - hist is the name and/or type of the histogram.
-//      1) The name and type is identical, eg: "MHHillas"
-//      2) They are not identical, eg: "MyHistogram [MHHillas]"
-//         This searches for a class instance of MHHillas with the name
-//         "MyHistogram". If it doesn't exist one is created. Everything
-//         which is between the first '[' and the last ']' in the string
-//         is used as the histogram type.
-//
-//    In this case PreProcess calls MH::SetupFill with a pointer to the
-//    parameter list and MH::Fill is called with a NULL-pointer.
-//
-//
-MFillH::MFillH(const char *hist, MParContainer *par, const char *name, const char *title)
-{
-    Init(name, title);
-
-    fHName = hist;
-    fParContainer = par;
-    fParContainerName = par->GetName();
-
-    AddToBranchList(Form("%s.*", (const char*)ExtractName(hist)));
-    AddToBranchList(Form("%s.*", par->GetName()));
-
-    if (!title)
-        fTitle = "Fill " + fHName + " from " + par->GetDescriptor();
-}
-
-// --------------------------------------------------------------------------
-//
-// Constructor.
-//
-// - par is a pointer to the instance of your parameter container from which
-//   the data should be used to fill the histogram.
-// - hist is a pointer to the instance of your histogram container (which must
-//   have been derived from MH) into which the data should flow
-//
-MFillH::MFillH(MH *hist, const char *par, const char *name, const char *title)
-{
-    Init(name, title);
-
-    fH = hist;
-    fHName = hist->GetName();
-    fParContainerName = par;
-
-    AddToBranchList(fH->GetDataMember());
-    if (par)
-        AddToBranchList(Form("%s.*", (const char*)ExtractName(par)));
-
-    if (title)
-        return;
-
-    fTitle = (TString)"Fill " + hist->GetDescriptor();
-    if (!par)
-        return;
-
-    fTitle += " from " + fParContainerName;
-}
-
-// --------------------------------------------------------------------------
-//
-// Constructor.
-//
-// - par is a pointer to the instance of your parameter container from which
-//   the data should be used to fill the histogram.
-// - hist is the name of the histogram container (which must have been
-//   derived from MH)
-//
-MFillH::MFillH(MH *hist, MParContainer *par, const char *name, const char *title)
-{
-    Init(name, title);
-
-    fH = hist;
-    fHName = hist->GetName();
-    fParContainer = par;
-    fParContainerName = par->GetName();
-
-    AddToBranchList(fH->GetDataMember());
-    AddToBranchList(Form("%s.*", par->GetName()));
-
-    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;
-}
-
-// --------------------------------------------------------------------------
-//
-// 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
-{
-    TString type = name;
-
-    const Ssiz_t first = type.First('[');
-    const Ssiz_t last  = type.First(']');
-
-    if (!first || !last || first>=last)
-        return type;
-
-    return type.Remove(first).Strip(TString::kBoth);
-}
-
-// --------------------------------------------------------------------------
-//
-// Extracts the class-name of the histogram from the MFillH argument
-//
-TString MFillH::ExtractClass(const char *name) const
-{
-    TString type = name;
-
-    const Ssiz_t first = type.First('[');
-    const Ssiz_t last  = type.First(']');
-
-    if (!first || !last || first>=last)
-        return type;
-
-    const Ssiz_t length = last-first-1;
-
-    TString strip = fHName(first+1, length);
-    return strip.Strip(TString::kBoth);
-}
-
-// --------------------------------------------------------------------------
-//
-// Creates a new tab in a status display with the name of the MH class,
-// if fDisplay is set and the MH-class overwrites the Draw function
-//
-Bool_t MFillH::DrawToDisplay()
-{
-    fCanvas = NULL;
-
-    if (!fDisplay)
-        return kTRUE;
-
-    if (!fH->OverwritesDraw())
-        return kTRUE;
-
-    if (TestBit(kDoNotDisplay))
-        return kTRUE;
-
-    fCanvas = &fDisplay->AddTab(fH->GetName());
-    fH->Draw();
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Checks the parameter list for the existance of the parameter container. If
-// the name of it was given in the constructor. It checks also for the
-// existance of the histogram container in the parameter list if a name was
-// given. If it is not available it tried to create a histogram container
-// with the same type as the given object name.
-//
-Int_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;
-        }
-    }
-
-    //
-    // If the user defined the use of a weight: search for it.
-    //
-    if (!fWeight && !fWeightName.IsNull())
-    {
-        fWeight = (MWeight*)pList->FindObject(fWeightName, "MWeight");
-
-	if (!fWeight)
-	  {
-	    *fLog << err << fWeightName << " [MWeight] not found... aborting." << endl;
-	    return kFALSE;
-	  }
-    }
-
-    //
-    // Try to get the histogram container with name fHName from list
-    // or create one with this name
-    //
-    if (!fH)
-    {
-        const TString cls  = ExtractClass(fHName);
-        const TString name = ExtractName(fHName);
-
-        TObject *obj=NULL;
-        if (cls==name)
-            obj = pList->FindObject(fHName);
-
-        if (!obj)
-        {
-            /*
-            if (cls==name)
-            *fLog << inf << "Object '" << fHName << "' not found in parlist... creating." << endl;
-            */
-            obj = pList->FindCreateObj(cls, name);
-        }
-
-        if (!obj)
-            return kFALSE;
-
-        //
-        // We were successfull getting it. Check whether it really inherits
-        // from MH, FindCreateObj does only check for inheritance from
-        // 'type'.
-        //
-        TClass *tcls = fIndex ? MHArray::Class() : MH::Class();
-        if (!obj->InheritsFrom(tcls))
-        {
-            *fLog << err << obj->GetName() << " doesn't inherit ";
-            *fLog << "from " << tcls->GetName() << " - cannot be used for MFillH...";
-            *fLog << "aborting." << endl;
-            return kFALSE;
-        }
-
-        fH = (MH*)obj;
-    }
-
-    //
-    // Now we have the histogram container available. Try to Setup Fill.
-    //
-    fH->SetSerialNumber(GetSerialNumber());
-    if (!fH->SetupFill(pList))
-    {
-        *fLog << err << "ERROR - Calling SetupFill for ";
-        *fLog << fH->GetDescriptor() << "... aborting." << endl;
-        return kFALSE;
-    }
-
-    //
-    // If also a parameter container is already set we are done.
-    //
-    if (fParContainer)
-        return DrawToDisplay();
-
-    //
-    // This case means, that the MH sets up its container to be filled
-    // by itself. Check there if it has something to be filled with!
-    //
-    if (fParContainerName.IsNull())
-    {
-        fParContainer = NULL;
-        return DrawToDisplay();
-    }
-
-    fParContainer = (MParContainer*)pList->FindObject(fParContainerName);
-    if (fParContainer)
-        return DrawToDisplay();
-
-    *fLog << err << fParContainerName << " [MParContainer] not found... aborting." << endl;
-    return kFALSE;
-}
-
-// --------------------------------------------------------------------------
-//
-// Call the ReInit function of the contained Histogram
-//
-Bool_t MFillH::ReInit(MParList *pList)
-{
-    return fH->ReInit(pList);
-} 
-
-// --------------------------------------------------------------------------
-//
-// Fills the data from the parameter conatiner into the histogram container
-//
-Int_t MFillH::Process()
-{
-    if (fIndex)
-        ((MHArray*)fH)->SetIndexByKey(fIndex->GetValue());
-    /*
-     const Int_t key = (Int_t)fIndex->GetValue();
-     const Int_t idx = fMapIdx->Add(key);
-     ((MHArray*)fH)->SetIndex(idx);
-     */
-
-    return fH->Fill(fParContainer, fWeight?fWeight->GetWeight():1);
-} 
-
-// --------------------------------------------------------------------------
-//
-// Set the ReadyToSave flag of the histogram container, because now all data
-// has been filled into the histogram.
-//
-Int_t MFillH::PostProcess()
-{
-    //
-    // Now all data is in the histogram. Maybe some final action is
-    // necessary.
-    //
-    if (!fH->Finalize())
-    {
-        *fLog << err << "ERROR - Calling Finalize for ";
-        *fLog << fH->GetDescriptor() << "... aborting." << endl;
-        return kFALSE;
-    }
-
-    fH->SetReadyToSave();
-
-    //
-    // Check whether fDisplay has previously been used (fCanvas),
-    // fDisplay is still open and the corresponding Canvas/Tab is
-    // still existing.
-    //
-    if (fDisplay && fDisplay->HasCanvas(fCanvas))
-    {
-        fCanvas->cd();
-        fH->DrawClone("nonew");
-        fCanvas->Modified();
-        fCanvas->Update();
-    }
-
-    return kTRUE;
-}
-
-// --------------------------------------------------------------------------
-//
-// 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 MFillH::StreamPrimitive(ofstream &out) const
-{
-    if (fH)
-        fH->SavePrimitive(out);
-
-    if (fParContainer)
-        fParContainer->SavePrimitive(out);
-
-    if (fWeight)
-        fWeight->SavePrimitive(out);
-
-    out << "   MFillH " << GetUniqueName() << "(";
-
-    if (fH)
-        out << "&" << fH->GetUniqueName();
-    else
-        out << "\"" << fHName << "\"";
-
-    if (fParContainer)
-        out << ", &" << fParContainer->GetUniqueName();
-    else
-        if (!fParContainerName.IsNull())
-            out << ", \"" << fParContainerName << "\"";
-
-    out << ");" << endl;
-
-    if (fWeight || !fWeightName.IsNull())
-    {
-        out << "   " << GetUniqueName() << ".SetWeight(";
-        if (fWeight)
-            out << "&" << fWeight->GetUniqueName() << ");" << endl;
-        else
-            if (!fWeightName.IsNull())
-                out << "\"" << fWeightName << "\");" << endl;
-    }
-
-    if (fIndex)
-    {
-        out << "   " << GetUniqueName() << ".SetRuleForIdx(\"";
-        out << fIndex->GetRule() << "\");" << endl;
-    }
-}
Index: trunk/MagicSoft/Mars/mhist/MFillH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 2734)
+++ 	(revision )
@@ -1,72 +1,0 @@
-#ifndef MARS_MFillH
-#define MARS_MFillH
-
-#ifndef MARS_MTask
-#include "MTask.h"
-#endif
-
-class MH;
-class MMap;
-class MData;
-class MWeight;
-class MParList;
-
-class TCanvas;
-
-class MFillH : public MTask
-{
-public:
-    enum {
-        kDoNotDisplay = BIT(17)
-    };
-
-private:
-    MParContainer *fParContainer; // Pointer to the data container storing
-    TString fParContainerName;    // Name to a data container
-
-    MH* fH;                       // Pointer to the MH container to get filled
-    TString fHName;               // Name to a MH container to get filled
-
-    MWeight *fWeight;             // Pointer to the container storing a weight
-    TString fWeightName;          // Name of a container storing a weight
-
-    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)
-
-    TCanvas *fCanvas;             //! Canvas used to update a MStatusDisplay at the end of a loop
-
-    TString ExtractName(const char *name) const;
-    TString ExtractClass(const char *name) const;
-
-    void Init(const char *name, const char *title);
-
-    void StreamPrimitive(ofstream &out) const;
-
-    Bool_t DrawToDisplay();
-
-public:
-    MFillH();
-    MFillH(const char *hist, const char *par=NULL, const char *name=NULL, const char *title=NULL);
-    MFillH(const char *hist, MParContainer *par,   const char *name=NULL, const char *title=NULL);
-    MFillH(MH *hist,         const char *par=NULL, const char *name=NULL, const char *title=NULL);
-    MFillH(MH *hist,         MParContainer *par,   const char *name=NULL, const char *title=NULL);
-    ~MFillH();
-
-    void SetRuleForIdx(const TString rule);
-    void SetRuleForIdx(MData *rule);
-
-    void SetWeight(MWeight *w)       { fWeight = w; }
-    void SetWeight(const char *name) { fWeightName = name; }
-
-    Int_t  PreProcess(MParList *pList);
-    Bool_t ReInit(MParList *pList);
-    Int_t  Process();
-    Int_t  PostProcess();
-
-    TCanvas *GetCanvas() { return fCanvas; }
-
-    ClassDef(MFillH, 2) // Task to fill a histogram with data from a parameter container
-};
-    
-#endif
-
Index: trunk/MagicSoft/Mars/mhist/MH.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.cc	(revision 2734)
+++ 	(revision )
@@ -1,1081 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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
-!
-!
-\* ======================================================================== */
-
-//////////////////////////////////////////////////////////////////////////////
-//                                                                          //
-//  MH                                                                      //
-//                                                                          //
-//  This is a base tasks for mars histograms. It defines a common interface //
-//  for filling the histograms with events (MH::Fill) which is used by a    //
-//  common 'filler' And a SetupFill member function which may be used       //
-//  by MFillH. The idea is:                                                 //
-//   1) If your Histogram can become filled by one single container         //
-//      (like MHHillas) you overload MH::Fill and it gets called with       //
-//      a pointer to the container with which it should be filled.          //
-//                                                                          //
-//   2) You histogram needs several containers to get filled. Than you      //
-//      have to overload MH::SetupFill and get the necessary objects from   //
-//      the parameter list. Use this objects in Fill to fill your           //
-//      histogram.                                                          //
-//                                                                          //
-//  If you want to create your own histogram class the new class must be    //
-//  derived from MH (instead of the base MParContainer) and you must        //
-//  the fill function of MH. This is the function which is called to fill   //
-//  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(...)                   //
-//                                                                          //
-//////////////////////////////////////////////////////////////////////////////
-
-#include "MH.h"
-
-#include <TH1.h>
-#include <TH2.h>
-#include <TH3.h>
-#include <TStyle.h>       // TStyle::GetScreenFactor
-#include <TGaxis.h>
-#include <TCanvas.h>
-#include <TLegend.h>
-#include <TPaveStats.h>
-#include <TBaseClass.h>
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
-#include <THLimitsFinder.h>
-#endif
-
-#include "MLog.h"
-#include "MLogManip.h"
-
-#include "MParList.h"
-#include "MParContainer.h"
-
-#include "MBinning.h"
-
-ClassImp(MH);
-
-using namespace std;
-
-// --------------------------------------------------------------------------
-//
-// Default Constructor. It sets name and title only. Typically you won't
-// need to change this.
-//
-MH::MH(const char *name, const char *title)
-{
-    //
-    //   set the name and title of this object
-    //
-    fName  = name  ? name  : "MH";
-    fTitle = title ? title : "Base class for Mars histograms";
-}
-
-// --------------------------------------------------------------------------
-//
-// If you want to use the automatic filling of your derived class you
-// must overload this function. If it is not overloaded you cannot use
-// FillH with this class. The argument is a pointer to a container
-// in your paremeter list which is specified in the MFillH constructor.
-// If you are not going to use it you should at least add
-//   Bool_t MH::Fill(const MParContainer *) { return kTRUE; }
-// to your class definition.
-//
-Bool_t MH::Fill(const MParContainer *par, const Stat_t w)
-{
-    *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;
-}
-
-// --------------------------------------------------------------------------
-//
-// This is a function which should replace the creation of default
-// canvases like root does. Because this is inconvinient in some aspects.
-// need to change this.
-// You can specify a name for the default canvas and a title. Also
-// width and height can be given.
-// MakeDefCanvas looks for a canvas with the given name. If now name is
-// given the DefCanvasName of root is used. If no such canvas is existing
-// it is created and returned. If such a canvas already exists a new canvas
-// with a name plus anumber is created (the number is calculated by the
-// number of all existing canvases plus one)
-//
-// Normally the canvas size is scaled with gStyle->GetScreenFactor() so
-// that on all screens it looks like the same part of the screen.
-// To suppress this scaling use usescreenfactor=kFALSE. In this case
-// you specify directly the size of the embedded pad.
-//
-TCanvas *MH::MakeDefCanvas(TString name, const char *title,
-                           UInt_t w, UInt_t h, Bool_t usescreenfactor)
-{
-    const TList *list = (TList*)gROOT->GetListOfCanvases();
-
-    if (name.IsNull())
-        name = gROOT->GetDefCanvasName();
-
-    if (list->FindObject(name))
-        name += Form(" <%d>", list->GetSize()+1);
-
-    if (!usescreenfactor)
-    {
-        const Float_t cx = gStyle->GetScreenFactor();
-        w += 4;
-        h += 28;
-        w = (int)(w/cx+1);
-        h = (int)(h/cx+1);
-    }
-
-    return new TCanvas(name, title, w, h);
-}
-
-// --------------------------------------------------------------------------
-//
-// This function works like MakeDefCanvas(name, title, w, h) but name
-// and title are retrieved from the given TObject.
-//
-// Normally the canvas size is scaled with gStyle->GetScreenFactor() so
-// that on all screens it looks like the same part of the screen.
-// To suppress this scaling use usescreenfactor=kFALSE. In this case
-// you specify directly the size of the embedded pad.
-//
-TCanvas *MH::MakeDefCanvas(const TObject *obj,
-                           UInt_t w, UInt_t h, Bool_t usescreenfactor)
-{
-    if (!usescreenfactor)
-    {
-        const Float_t cx = gStyle->GetScreenFactor();
-        w += 4;
-        h += 28;
-        h = (int)(h/cx+1);
-        w = (int)(w/cx+1);
-    }
-
-    return MakeDefCanvas(obj->GetName(), obj->GetTitle(), w, h);
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies a given binning to a 1D-histogram
-//
-void MH::SetBinning(TH1 *h, const MBinning *binsx)
-{
-    //
-    // Another strange behaviour: TAxis::Set deletes the axis title!
-    //
-    TAxis &x = *h->GetXaxis();
-
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-    TString xtitle = x.GetTitle();
-#endif
-
-    //
-    // This is a necessary workaround if one wants to set
-    // non-equidistant bins after the initialization
-    // TH1D::fNcells must be set correctly.
-    //
-    h->SetBins(binsx->GetNumBins(), 0, 1);
-
-    //
-    // Set the binning of the current histogram to the binning
-    // in one of the two given histograms
-    //
-    x.Set(binsx->GetNumBins(), binsx->GetEdges());
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-    x.SetTitle(xtitle);
-#endif
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies given binnings to the two axis of a 2D-histogram
-//
-void MH::SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy)
-{
-    TAxis &x = *h->GetXaxis();
-    TAxis &y = *h->GetYaxis();
-
-    //
-    // Another strange behaviour: TAxis::Set deletes the axis title!
-    //
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-    TString xtitle = x.GetTitle();
-    TString ytitle = y.GetTitle();
-#endif
-
-    //
-    // This is a necessary workaround if one wants to set
-    // non-equidistant bins after the initialization
-    // TH1D::fNcells must be set correctly.
-    //
-    h->SetBins(binsx->GetNumBins(), 0, 1,
-               binsy->GetNumBins(), 0, 1);
-
-    //
-    // Set the binning of the current histogram to the binning
-    // in one of the two given histograms
-    //
-    x.Set(binsx->GetNumBins(), binsx->GetEdges());
-    y.Set(binsy->GetNumBins(), binsy->GetEdges());
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-    x.SetTitle(xtitle);
-    y.SetTitle(ytitle);
-#endif
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies given binnings to the three axis of a 3D-histogram
-//
-void MH::SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz)
-{
-    //
-    // Another strange behaviour: TAxis::Set deletes the axis title!
-    //
-    TAxis &x = *h->GetXaxis();
-    TAxis &y = *h->GetYaxis();
-    TAxis &z = *h->GetZaxis();
-
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-    TString xtitle = x.GetTitle();
-    TString ytitle = y.GetTitle();
-    TString ztitle = z.GetTitle();
-#endif
-
-    //
-    // This is a necessary workaround if one wants to set
-    // non-equidistant bins after the initialization
-    // TH1D::fNcells must be set correctly.
-    //
-    h->SetBins(binsx->GetNumBins(), 0, 1,
-               binsy->GetNumBins(), 0, 1,
-               binsz->GetNumBins(), 0, 1);
-
-    //
-    // Set the binning of the current histogram to the binning
-    // in one of the two given histograms
-    //
-    x.Set(binsx->GetNumBins(), binsx->GetEdges());
-    y.Set(binsy->GetNumBins(), binsy->GetEdges());
-    z.Set(binsz->GetNumBins(), binsz->GetEdges());
-#if ROOT_VERSION_CODE < ROOT_VERSION(3,03,03)
-    x.SetTitle(xtitle);
-    y.SetTitle(ytitle);
-    z.SetTitle(ztitle);
-#endif
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies given binning (the n+1 edges)  to the axis of a 1D-histogram
-//
-void MH::SetBinning(TH1 *h, const TArrayD &binsx)
-{
-    MBinning bx;
-    bx.SetEdges(binsx);
-    SetBinning(h, &bx);
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies given binning (the n+1 edges) to the two axis of a
-// 2D-histogram
-//
-void MH::SetBinning(TH2 *h, const TArrayD &binsx, const TArrayD &binsy)
-{
-    MBinning bx;
-    MBinning by;
-    bx.SetEdges(binsx);
-    by.SetEdges(binsy);
-    SetBinning(h, &bx, &by);
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies given binning (the n+1 edges) to the three axis of a
-// 3D-histogram
-//
-void MH::SetBinning(TH3 *h, const TArrayD &binsx, const TArrayD &binsy, const TArrayD &binsz)
-{
-    MBinning bx;
-    MBinning by;
-    MBinning bz;
-    bx.SetEdges(binsx);
-    by.SetEdges(binsy);
-    bz.SetEdges(binsz);
-    SetBinning(h, &bx, &by, &bz);
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies the binning of a TAxis (eg from a root histogram) to the axis
-// of a 1D-histogram
-//
-void MH::SetBinning(TH1 *h, const TAxis *binsx)
-{
-    const Int_t nx = binsx->GetNbins();
-
-    TArrayD bx(nx+1);
-    for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
-    bx[nx] = binsx->GetXmax();
-
-    SetBinning(h, bx);
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies the binnings of the TAxis' (eg from a root histogram) to the
-// two axis' of a 2D-histogram
-//
-void MH::SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy)
-{
-    const Int_t nx = binsx->GetNbins();
-    const Int_t ny = binsy->GetNbins();
-
-    TArrayD bx(nx+1);
-    TArrayD by(ny+1);
-    for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
-    for (int i=0; i<ny; i++) by[i] = binsy->GetBinLowEdge(i+1);
-    bx[nx] = binsx->GetXmax();
-    by[ny] = binsy->GetXmax();
-
-    SetBinning(h, bx, by);
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies the binnings of the TAxis' (eg from a root histogram) to the
-// three axis' of a 3D-histogram
-//
-void MH::SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz)
-{
-    const Int_t nx = binsx->GetNbins();
-    const Int_t ny = binsy->GetNbins();
-    const Int_t nz = binsz->GetNbins();
-
-    TArrayD bx(nx+1);
-    TArrayD by(ny+1);
-    TArrayD bz(nz+1);
-    for (int i=0; i<nx; i++) bx[i] = binsx->GetBinLowEdge(i+1);
-    for (int i=0; i<ny; i++) by[i] = binsy->GetBinLowEdge(i+1);
-    for (int i=0; i<nz; i++) bz[i] = binsz->GetBinLowEdge(i+1);
-    bx[nx] = binsx->GetXmax();
-    by[ny] = binsy->GetXmax();
-    bz[nz] = binsz->GetXmax();
-
-    SetBinning(h, bx, by, bz);
-}
-
-// --------------------------------------------------------------------------
-//
-// Applies the binnings of one root-histogram x to another one h
-// Both histograms must be of the same type: TH1, TH2 or TH3
-//
-void MH::SetBinning(TH1 *h, const TH1 *x)
-{
-    if (h->InheritsFrom(TH3::Class()) && x->InheritsFrom(TH3::Class()))
-    {
-        SetBinning((TH3*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis(), ((TH1*)x)->GetZaxis());
-        return;
-    }
-    if (h->InheritsFrom(TH3::Class()) || x->InheritsFrom(TH3::Class()))
-        return;
-    if (h->InheritsFrom(TH2::Class()) && x->InheritsFrom(TH2::Class()))
-    {
-        SetBinning((TH2*)h, ((TH1*)x)->GetXaxis(), ((TH1*)x)->GetYaxis());
-        return;
-    }
-    if (h->InheritsFrom(TH2::Class()) || x->InheritsFrom(TH2::Class()))
-        return;
-    if (h->InheritsFrom(TH1::Class()) && x->InheritsFrom(TH1::Class()))
-    {
-        SetBinning(h, ((TH1*)x)->GetXaxis());
-        return;
-    }
-}
-
-// --------------------------------------------------------------------------
-//
-// Multiplies all entries in a TArrayD by a float f
-//
-void MH::ScaleArray(TArrayD &bins, Double_t f)
-{
-    for (int i=0; i<bins.GetSize(); i++)
-        bins[i] *= f;
-}
-
-// --------------------------------------------------------------------------
-//
-// Scales the binning of a TAxis by a float f
-//
-TArrayD MH::ScaleAxis(TAxis &axe, Double_t f)
-{
-    TArrayD arr(axe.GetNbins()+1);
-
-    for (int i=1; i<=axe.GetNbins()+1; i++)
-        arr[i-1] = axe.GetBinLowEdge(i);
-
-    ScaleArray(arr, f);
-
-    return arr;
-}
-
-// --------------------------------------------------------------------------
-//
-// Scales the binning of one, two or three axis of a histogram by a float f
-//
-void MH::ScaleAxis(TH1 *h, Double_t fx, Double_t fy, Double_t fz)
-{
-    if (h->InheritsFrom(TH3::Class()))
-    {
-        SetBinning((TH3*)h,
-                   ScaleAxis(*h->GetXaxis(), fx),
-                   ScaleAxis(*h->GetYaxis(), fy),
-                   ScaleAxis(*h->GetZaxis(), fz));
-        return;
-    }
-
-    if (h->InheritsFrom(TH2::Class()))
-    {
-        SetBinning((TH2*)h,
-                   ScaleAxis(*h->GetXaxis(), fx),
-                   ScaleAxis(*h->GetYaxis(), fy));
-        return;
-    }
-
-    if (h->InheritsFrom(TH1::Class()))
-        SetBinning(h, ScaleAxis(*h->GetXaxis(), fx));
-}
-
-// --------------------------------------------------------------------------
-//
-// Tries to find a MBinning container with the name "Binning"+name
-// in the given parameter list. If it was found it is applied to the
-// given histogram. This is only valid for 1D-histograms
-//
-Bool_t MH::ApplyBinning(const MParList &plist, TString name, TH1 *h)
-{
-    if (h->InheritsFrom(TH2::Class()) || h->InheritsFrom(TH3::Class()))
-    {
-        gLog << warn << "MH::ApplyBinning: '" << h->GetName() << "' is not a basic TH1 object... no binning applied." << endl;
-        return kFALSE;
-    }
-
-    const MBinning *bins = (MBinning*)plist.FindObject("Binning"+name);
-    if (!bins)
-    {
-        gLog << warn << "Object 'Binning" << name << "' [MBinning] not found... no binning applied." << endl;
-        return kFALSE;
-    }
-
-    SetBinning(h, bins);
-    return kTRUE;
-}
-
-void MH::FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger)
-{
-#if ROOT_VERSION_CODE > ROOT_VERSION(3,04,01)
-    THLimitsFinder::OptimizeLimits(nbins, newbins, xmin, xmax, isInteger);
-#else
-//*-*-*-*-*-*-*-*-*Find reasonable bin values*-*-*-*-*-*-*-*-*-*-*-*-*-*-*
-//*-*              ==========================
-
-    Double_t dx = 0.1*(xmax-xmin);
-    Double_t umin = xmin - dx;
-    Double_t umax = xmax + dx;
-
-    if (umin < 0 && xmin >= 0)
-        umin = 0;
-
-    if (umax > 0 && xmax <= 0)
-        umax = 0;
-
-    Double_t binlow  =0;
-    Double_t binhigh =0;
-    Double_t binwidth=0;
-
-    TGaxis::Optimize(umin, umax, nbins, binlow, binhigh, nbins, binwidth, "");
-
-    if (binwidth <= 0 || binwidth > 1.e+39)
-    {
-        xmin = -1;
-        xmax = 1;
-    }
-    else
-    {
-        xmin = binlow;
-        xmax = binhigh;
-    }
-
-    if (isInteger)
-    {
-        Int_t ixmin = (Int_t)xmin;
-        Int_t ixmax = (Int_t)xmax;
-        Double_t dxmin = (Double_t)ixmin;
-        Double_t dxmax = (Double_t)ixmax;
-
-        xmin = xmin<0 && xmin!=dxmin ? dxmin - 1 : dxmin;
-        xmax = xmax>0 && xmax!=dxmax ? dxmax + 1 : dxmax;
-
-        if (xmin>=xmax)
-            xmax = xmin+1;
-
-        Int_t bw = 1 + (Int_t)((xmax-xmin)/nbins);
-
-        nbins = (Int_t)((xmax-xmin)/bw);
-
-        if (xmin+nbins*bw < xmax)
-        {
-            nbins++;
-            xmax = xmin +nbins*bw;
-        }
-    }
-
-    newbins = nbins;
-#endif
-}
-
-// --------------------------------------------------------------------------
-//
-//  Returns the lowest entry in a histogram which is greater than gt (eg >0)
-//
-Double_t MH::GetMinimumGT(const TH1 &h, Double_t gt)
-{
-    Double_t min = FLT_MAX;
-
-    const TAxis &axe = *((TH1&)h).GetXaxis();
-
-    for (int i=1; i<=axe.GetNbins(); i++)
-    {
-        Double_t x = h.GetBinContent(i);
-        if (gt<x && x<min)
-            min = x;
-    }
-    return min;
-}
-
-// --------------------------------------------------------------------------
-//
-//  Returns the bin center in a logarithmic scale. If the given bin
-//  number is <1 it is set to 1. If it is =GetNbins() it is set to
-//  GetNbins()
-//
-Double_t MH::GetBinCenterLog(const TAxis &axe, Int_t nbin)
-{
-    if (nbin>axe.GetNbins())
-        nbin = axe.GetNbins();
-
-    if (nbin<1)
-        nbin = 1;
-
-    const Double_t lo = axe.GetBinLowEdge(nbin);
-    const Double_t hi = axe.GetBinUpEdge(nbin);
-
-    const Double_t val = log10(lo) + log10(hi);
-
-    return pow(10, val/2);
-}
-
-// --------------------------------------------------------------------------
-//
-// Draws a copy of the two given histograms. Uses title as the pad title.
-// Also layout the two statistic boxes and a legend.
-//
-void MH::DrawSameCopy(const TH1 &hist1, const TH1 &hist2, const TString title)
-{
-    //
-    // Draw first histogram
-    //
-    TH1 *h1 = ((TH1&)hist1).DrawCopy();
-    gPad->SetBorderMode(0);
-    gPad->Update();
-
-    // FIXME: Also align max/min with set Maximum/Minimum
-    const Double_t maxbin1 = hist1.GetBinContent(hist1.GetMaximumBin());
-    const Double_t maxbin2 = hist2.GetBinContent(hist2.GetMaximumBin());
-    const Double_t minbin1 = hist1.GetBinContent(hist1.GetMinimumBin());
-    const Double_t minbin2 = hist2.GetBinContent(hist2.GetMinimumBin());
-
-    const Double_t max = TMath::Max(maxbin1, maxbin2);
-    const Double_t min = TMath::Min(minbin1, minbin2);
-
-    h1->SetMaximum(max>0?max*1.05:max*0.95);
-    h1->SetMinimum(max>0?min*0.95:min*1.05);
-
-    TPaveText *t = (TPaveText*)gPad->FindObject("title");
-    if (t)
-    {
-        t->SetName((TString)"MHTitle");     // rename object
-        t->Clear();                         // clear old lines
-        t->AddText((TString)" "+title+" "); // add the new title
-        t->SetBit(kCanDelete);              // make sure object is deleted
-
-        //
-        // FIXME: This is a stupid workaround to hide the redrawn
-        // (see THistPainter::PaintTitle) title
-        //
-        gPad->Modified();  // indicates a change
-        gPad->Update();    // recreates the original title
-        t->Pop();          // bring our title on top
-    }
-
-    //
-    // Rename first statistics box
-    //
-    TPaveStats *s1 = (TPaveStats*)gPad->FindObject("stats");
-    if (!s1)
-        s1 = (TPaveStats*)hist1.GetListOfFunctions()->FindObject("stats");
-    else
-        s1->SetName((TString)"Stat"+hist1.GetTitle());
-
-    if (s1 && s1->GetX2NDC()>0.95)
-    {
-        const Double_t x1 = s1->GetX1NDC()-0.01;
-        s1->SetX1NDC(x1-(s1->GetX2NDC()-s1->GetX1NDC()));
-        s1->SetX2NDC(x1);
-    }
-
-    //
-    // Draw second histogram
-    //
-    TH1 *h2 = ((TH1&)hist2).DrawCopy("sames");
-    gPad->Update();
-
-    //
-    // Draw Legend
-    //
-    TPaveStats *s2 = (TPaveStats*)gPad->FindObject("stats");
-    if (!s2)
-        s2 = (TPaveStats*)hist2.GetListOfFunctions()->FindObject("stats");
-
-    if (s2)
-    {
-        TLegend &l = *new TLegend(s2->GetX1NDC(),
-                                  s2->GetY1NDC()-0.015-(s2->GetY2NDC()-s2->GetY1NDC())/2,
-                                  s2->GetX2NDC(),
-                                  s2->GetY1NDC()-0.01
-                                 );
-        l.AddEntry(h1, h1->GetTitle());
-        l.AddEntry(h2, h2->GetTitle());
-        l.SetTextSize(s2->GetTextSize());
-        l.SetTextFont(s2->GetTextFont());
-        l.SetBorderSize(s2->GetBorderSize());
-        l.SetBit(kCanDelete);
-        l.Draw();
-    }
-}
-
-// --------------------------------------------------------------------------
-//
-// Draws the two given histograms. Uses title as the pad title.
-// Also layout the two statistic boxes and a legend.
-//
-void MH::DrawSame(TH1 &hist1, TH1 &hist2, const TString title)
-{
-    //
-    // Draw first histogram
-    //
-    hist1.Draw();
-    gPad->SetBorderMode(0);
-    gPad->Update();
-
-    if (hist1.GetEntries()>0 && hist2.GetEntries()>0)
-    {
-        const Double_t maxbin1 = hist1.GetBinContent(hist1.GetMaximumBin());
-        const Double_t maxbin2 = hist2.GetBinContent(hist2.GetMaximumBin());
-        const Double_t minbin1 = hist1.GetBinContent(hist1.GetMinimumBin());
-        const Double_t minbin2 = hist2.GetBinContent(hist2.GetMinimumBin());
-
-        const Double_t max = TMath::Max(maxbin1, maxbin2);
-        const Double_t min = TMath::Min(minbin1, minbin2);
-
-        if (max!=min)
-        {
-            hist1.SetMaximum(max>0?max*1.05:max*0.95);
-            hist1.SetMinimum(max>0?min*0.95:min*1.05);
-        }
-    }
-
-    TPaveText *t = (TPaveText*)gPad->FindObject("title");
-    if (t)
-    {
-        t->SetName((TString)"MHTitle");     // rename object
-        t->Clear();                         // clear old lines
-        t->AddText((TString)" "+title+" "); // add the new title
-        t->SetBit(kCanDelete);              // make sure object is deleted
-
-        //
-        // FIXME: This is a stupid workaround to hide the redrawn
-        // (see THistPainter::PaintTitle) title
-        //
-        gPad->Modified();  // indicates a change
-        gPad->Update();    // recreates the original title
-        t->Pop();          // bring our title on top
-    }
-
-    //
-    // Rename first statistics box
-    //
-    // Where to get the TPaveStats depends on the root version
-    TPaveStats *s1 = (TPaveStats*)gPad->FindObject("stats");
-    if (!s1)
-        s1 = (TPaveStats*)hist1.GetListOfFunctions()->FindObject("stats");
-    else
-        s1->SetName((TString)"Stat"+hist1.GetTitle());
-
-    if (s1 && s1->GetX2NDC()>0.95)
-    {
-        const Double_t x1 = s1->GetX1NDC()-0.01;
-        s1->SetX1NDC(x1-(s1->GetX2NDC()-s1->GetX1NDC()));
-        s1->SetX2NDC(x1);
-    }
-
-    //
-    // Draw second histogram
-    //
-    hist2.Draw("sames");
-    gPad->Update();
-
-    //
-    // Draw Legend
-    //
-    // Where to get the TPaveStats depends on the root version
-    TPaveStats *s2 = (TPaveStats*)gPad->FindObject("stats");
-    if (!s2)
-        s2 = (TPaveStats*)hist2.GetListOfFunctions()->FindObject("stats");
-
-    if (s2)
-    {
-        TLegend &l = *new TLegend(s2->GetX1NDC(),
-                                  s2->GetY1NDC()-0.015-(s2->GetY2NDC()-s2->GetY1NDC())/2,
-                                  s2->GetX2NDC(),
-                                  s2->GetY1NDC()-0.01
-                                 );
-        l.AddEntry(&hist1, hist1.GetTitle());
-        l.AddEntry(&hist2, hist2.GetTitle());
-        l.SetTextSize(s2->GetTextSize());
-        l.SetTextFont(s2->GetTextFont());
-        l.SetBorderSize(s2->GetBorderSize());
-        l.SetBit(kCanDelete);
-        l.Draw();
-    }
-}
-
-// --------------------------------------------------------------------------
-//
-// If the opt string contains 'nonew' or gPad is not given NULL is returned.
-// Otherwise the present gPad is returned.
-//
-TVirtualPad *MH::GetNewPad(TString &opt)
-{
-    opt.ToLower();
-
-    if (!opt.Contains("nonew"))
-        return NULL;
-
-    opt.ReplaceAll("nonew", "");
-
-    return gPad;
-}
-
-// --------------------------------------------------------------------------
-//
-// Encapsulate the TObject::Clone such, that a cloned TH1 (or derived)
-// object is not added to the current directory, when cloned.
-//
-TObject *MH::Clone(const char *name) const
-{
-    const Bool_t store = TH1::AddDirectoryStatus();
-
-    TH1::AddDirectory(kFALSE);
-    TObject *o = MParContainer::Clone(name);
-    TH1::AddDirectory(store);
-
-    return o;
-}
-
-// --------------------------------------------------------------------------
-//
-// If the opt string contains 'nonew' or gPad is not given a new canvas
-// with size w/h is created. Otherwise the object is cloned and drawn
-// to the present pad. The kCanDelete bit is set for the clone.
-//
-TObject *MH::DrawClone(Option_t *opt, Int_t w, Int_t h) const
-{
-    TString option(opt);
-
-    TVirtualPad *p = GetNewPad(option);
-    if (!p)
-        p = MakeDefCanvas(this, w, h);
-    else
-        p->Clear();
-
-    gROOT->SetSelectedPad(NULL);
-
-    TObject *o = MParContainer::DrawClone(option);
-    o->SetBit(kCanDelete);
-    return o;
-}
-
-// --------------------------------------------------------------------------
-//
-// Check whether a class inheriting from MH overwrites the Draw function
-//
-Bool_t MH::OverwritesDraw(TClass *cls) const
-{
-    if (!cls)
-        cls = IsA();
-
-    //
-    // Check whether we reached the base class MTask
-    //
-    if (TString(cls->GetName())=="MH")
-        return kFALSE;
-
-    //
-    // Check whether the class cls overwrites Draw
-    //
-    if (cls->GetMethodAny("Draw"))
-        return kTRUE;
-
-    //
-    // If the class itself doesn't overload it check all it's base classes
-    //
-    TBaseClass *base=NULL;
-    TIter NextBase(cls->GetListOfBases());
-    while ((base=(TBaseClass*)NextBase()))
-    {
-        if (OverwritesDraw(base->GetClassPointer()))
-            return kTRUE;
-    }
-
-    return kFALSE;
-}
-
-// --------------------------------------------------------------------------
-//
-//  Cuts the bins containing only zeros at the edges.
-//
-//  A new number of bins can be defined with nbins != 0
-//        In the case of nbins == 0, no rebinning will take place
-//
-//  Returns the new (real) number of bins
-//
-Int_t MH::CutEdges(TH1 *h, Int_t nbins)
-{
-    TAxis* axe = h->GetXaxis();
-
-    const Int_t min1   = axe->GetFirst();
-    const Int_t max1   = axe->GetLast();
-    const Int_t range1 = max1-min1;
-
-    //
-    // Check for useless zeros
-    //
-    if (range1 == 0)
-        return 0;
-
-    Int_t min2 = 0;
-    for (int i=min1; i<=max1; i++)
-        if (h->GetBinContent(i) != 0)
-        {
-            min2 = i;
-            break;
-        }
-
-    //
-    // If the histogram consists of zeros only
-    //
-    if (min2 == max1)
-        return 0;
-
-    Int_t max2 = 0;
-    for (int i=max1; i>=min2; i--)
-        if (h->GetBinContent(i) != 0)
-        {
-            max2 = i;
-            break;
-        }
-
-    //
-    // Check for rebinning
-    //
-    if (nbins < 1)
-    {
-        axe->SetRange(min2,max2);
-        return axe->GetLast()-axe->GetFirst();
-    }
-
-    //
-    // Appying TAxis->SetRange before ReBin does not work ...
-    // But this workaround helps quite fine
-    //
-    const Axis_t min = h->GetBinLowEdge(min2);
-    const Axis_t max = h->GetBinLowEdge(max2)+h->GetBinWidth(max2);
-
-    const Int_t ngroup = (int)((max2-min2)*h->GetNbinsX()/nbins/(max1-min1));
-
-    if (ngroup > 1)
-        h->Rebin(ngroup);
-
-    axe->SetRangeUser(min,max);
-
-    return axe->GetLast()-axe->GetFirst();
-}
-
-void MH::ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin, Int_t lastybin)
-{
-    //*-*-*-*-*Project a 2-D histogram into a 1-D histogram along X*-*-*-*-*-*-*
-    //*-*      ====================================================
-    //
-    //   The projection dest is always of the type TH1D.
-    //   The projection is made from the channels along the Y axis
-    //   ranging from firstybin to lastybin included.
-    //   By default, bins 1 to ny are included
-    //   When all bins are included, the number of entries in the projection
-    //   is set to the number of entries of the 2-D histogram, otherwise
-    //   the number of entries is incremented by 1 for all non empty cells.
-    //
-    //   if Sumw2() was called for dest, the errors are computed.
-    //
-    TAxis &axex = *((TH2&)src).GetXaxis();
-    TAxis &axey = *((TH2&)src).GetYaxis();
-
-    const Int_t nx = axex.GetNbins();
-    const Int_t ny = axey.GetNbins();
-    if (firstybin < 0)
-        firstybin = 1;
-    if (lastybin > ny)
-        lastybin = ny;
-
-    dest.Reset();
-    SetBinning(&dest, &axex);
-
-    // Create the projection histogram
-    const Bool_t computeErrors = dest.GetSumw2N() ? 1 : 0;
-
-    // Fill the projected histogram
-    for (Int_t binx=0; binx<=nx+1; binx++)
-    {
-        Double_t err2 = 0;
-        for (Int_t biny=firstybin; biny<=lastybin; biny++)
-        {
-            const Double_t cont = src.GetCellContent(binx,biny);
-            const Double_t err1 = src.GetCellError(binx,biny);
-            err2 += err1*err1;
-            if (cont)
-                dest.Fill(axex.GetBinCenter(binx), cont);
-        }
-        if (computeErrors)
-            dest.SetBinError(binx, TMath::Sqrt(err2));
-    }
-    if (firstybin <=1 && lastybin >= ny)
-        dest.SetEntries(src.GetEntries());
-}
-
-void MH::ProjectionY(TH1D &dest, const TH2 &src, Int_t firstxbin, Int_t lastxbin)
-{
-    //*-*-*-*-*Project a 2-D histogram into a 1-D histogram along X*-*-*-*-*-*-*
-    //*-*      ====================================================
-    //
-    //   The projection dest is always of the type TH1D.
-    //   The projection is made from the channels along the Y axis
-    //   ranging from firstybin to lastybin included.
-    //   By default, bins 1 to ny are included
-    //   When all bins are included, the number of entries in the projection
-    //   is set to the number of entries of the 2-D histogram, otherwise
-    //   the number of entries is incremented by 1 for all non empty cells.
-    //
-    //   if Sumw2() was called for dest, the errors are computed.
-    //
-    TAxis &axex = *((TH2&)src).GetXaxis();
-    TAxis &axey = *((TH2&)src).GetYaxis();
-
-    const Int_t nx = axex.GetNbins();
-    const Int_t ny = axey.GetNbins();
-    if (firstxbin < 0)
-        firstxbin = 1;
-    if (lastxbin > nx)
-        lastxbin = nx;
-
-    dest.Reset();
-    SetBinning(&dest, &axey);
-
-    // Create the projection histogram
-    const Bool_t computeErrors = dest.GetSumw2N() ? 1 : 0;
-
-    // Fill the projected histogram
-    for (Int_t biny=0; biny<=ny+1; biny++)
-    {
-        Double_t err2 = 0;
-        for (Int_t binx=firstxbin; binx<=lastxbin; binx++)
-        {
-            const Double_t cont = src.GetCellContent(binx,biny);
-            const Double_t err1 = src.GetCellError(binx,biny);
-            err2 += err1*err1;
-            if (cont)
-                dest.Fill(axey.GetBinCenter(biny), cont);
-        }
-        if (computeErrors)
-            dest.SetBinError(biny, TMath::Sqrt(err2));
-    }
-    if (firstxbin <=1 && lastxbin >= nx)
-        dest.SetEntries(src.GetEntries());
-}
-
-// --------------------------------------------------------------------------
-//
-// In contradiction to TPad::FindObject this function searches recursively
-// in a pad for an object. gPad is the default.
-//
-TObject *MH::FindObjectInPad(const char *name, TVirtualPad *pad)
-{
-    if (!pad)
-        pad = gPad;
-
-    if (!pad)
-        return NULL;
-
-    TObject *o;
-
-    TIter Next(pad->GetListOfPrimitives());
-    while ((o=Next()))
-    {
-        if (!strcmp(o->GetName(), name))
-            return o;
-
-        if (o->InheritsFrom("TPad"))
-            if ((o = FindObjectInPad(name, (TVirtualPad*)o)))
-                return o;
-    }
-    return NULL;
-}
Index: trunk/MagicSoft/Mars/mhist/MH.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MH.h	(revision 2734)
+++ 	(revision )
@@ -1,101 +1,0 @@
-#ifndef MARS_MH
-#define MARS_MH
-
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
-#endif
-
-class TH1;
-class TH1D;
-class TH2;
-class TH3;
-class TAxis;
-class TArrayD;
-class TCanvas;
-
-class MBinning;
-class MParList;
-
-class MH : public MParContainer
-{
-private:
-    Byte_t fSerialNumber;
-
-public:
-    MH(const char *name=NULL, const char *title=NULL);
-
-
-    virtual void SetSerialNumber(Byte_t num) { fSerialNumber = num; }
-    Byte_t  GetSerialNumber() const { return fSerialNumber; }
-    TString AddSerialNumber(const char *str) const { TString s(str); if (fSerialNumber==0) return s; s += ";"; s += fSerialNumber; return s; }
-    TString AddSerialNumber(const TString &str) const { return AddSerialNumber((const char*)str); }
-
-    Bool_t OverwritesDraw(TClass *cls=NULL) const;
-
-    virtual Bool_t SetupFill(const MParList *pList) { return kTRUE; }
-    virtual Bool_t ReInit(MParList *pList) { return kTRUE; }
-    virtual Bool_t Fill(const MParContainer *par, const Stat_t weight=1);
-    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="",
-                                  UInt_t w=625, UInt_t h=440,
-                                  Bool_t usescreenfactor=kTRUE);
-    static TCanvas *MakeDefCanvas(const TObject *obj,
-                                  UInt_t w=625, UInt_t h=440,
-                                  Bool_t usescreenfactor=kFALSE);
-
-    // FIXME: * --> & !!!
-
-    static void SetBinning(TH1 *h, const MBinning *binsx);
-    static void SetBinning(TH2 *h, const MBinning *binsx, const MBinning *binsy);
-    static void SetBinning(TH3 *h, const MBinning *binsx, const MBinning *binsy, const MBinning *binsz);
-
-    static void SetBinning(TH1 *h, const TArrayD &binsx);
-    static void SetBinning(TH2 *h, const TArrayD &binsx, const TArrayD &binsy);
-    static void SetBinning(TH3 *h, const TArrayD &binsx, const TArrayD &binsy, const TArrayD &binsz);
-
-    static void SetBinning(TH1 *h, const TAxis *binsx);
-    static void SetBinning(TH2 *h, const TAxis *binsx, const TAxis *binsy);
-    static void SetBinning(TH3 *h, const TAxis *binsx, const TAxis *binsy, const TAxis *binsz);
-
-    static void SetBinning(TH1 *h, const TH1 *x);
-
-    static Bool_t ApplyBinning(const MParList &plist, TString name, TH1 *h);
-
-    static void    ScaleArray(TArrayD &bins, Double_t f);
-    static TArrayD ScaleAxis(TAxis &axe, Double_t f);
-    static void    ScaleAxis(TH1 *bins, Double_t fx=1, Double_t fy=1, Double_t fz=1);
-
-    static Double_t GetBinCenterLog(const TAxis &axe, Int_t nbin);
-
-    static void DrawSameCopy(const TH1 &hist1, const TH1 &hist2, const TString title);
-    static void DrawSame(TH1 &hist1, TH1 &hist2, const TString title);
-
-    TObject *Clone(const char *name="") const;
-
-    TObject *DrawClone(Option_t *opt, Int_t w, Int_t h) const;
-    TObject *DrawClone(Option_t *opt="") const
-    {
-        return MH::DrawClone(opt, 625, 440);
-    }
-
-    static TVirtualPad *GetNewPad(TString &opt);
-
-    static void FindGoodLimits(Int_t nbins, Int_t &newbins, Double_t &xmin, Double_t &xmax, Bool_t isInteger);
-    static Double_t GetMinimumGT(const TH1 &h, Double_t gt=0);
-    static Int_t CutEdges(TH1 *h, Int_t nbins);
-    
-    static void ProjectionX(TH1D &dest, const TH2 &src, Int_t firstybin=-1, Int_t lastybin=9999);
-    static void ProjectionY(TH1D &dest, const TH2 &src, Int_t firstxbin=-1, Int_t lastxbin=9999);
-
-    static TObject *FindObjectInPad(const char *name, TVirtualPad *pad=NULL);
-
-    ClassDef(MH, 1) //A base class for Mars histograms
-};
-
-#endif
-
Index: trunk/MagicSoft/Mars/mhist/MHArray.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHArray.cc	(revision 2734)
+++ 	(revision )
@@ -1,772 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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 access the histograms by a key instead of an index use SetIndexByKey
-//  instead of Set/Inc/DecIndex. It will take the integerpart of the
-//  floating point value (2 in case of 2.9). For each new key a new
-//  index in the Mapping Table is created. So that you can access your
-//  histograms by the key (eg in case of the Angle Theta=23.2deg use
-//  SetIndexByKey(23.2)
-//
-//  If the index is equal to the number of histograms in the array a call
-//  to the Fill-member-function will create a new histogram.
-//
-//  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);
-
-using namespace std;
-
-//////////////////////////////////////////////////////////////////////////////
-//
-// 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:
-    // --------------------------------------------------------------------------
-    //
-    // Return the size of the table
-    //
-    Int_t GetSize() const
-    {
-        return fKeys.GetSize();
-    }
-
-    // --------------------------------------------------------------------------
-    //
-    // 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;
-    }
-
-    // --------------------------------------------------------------------------
-    //
-    // Get the key which corresponds to the given index
-    //
-    Int_t GetKey(Int_t value) const
-    {
-        const Int_t n = fKeys.GetSize();
-        for (int i=0; i<n; i++)
-        {
-            if (V(i)==value)
-                return K(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;
-    }
-};
-
-void MHArray::Init(const char *name)
-{
-    fName  = name  ? name  : "MHArray";
-
-    fMapIdx = new MMap;
-
-    fArray = new TList;
-    fArray->SetOwner();
-}
-
-// --------------------------------------------------------------------------
-//
-// Can replace a constructor. Use the default constructor and afterwards
-// the Set function of your need.
-//
-void MHArray::Set(const TString hname, Bool_t istempl)
-{
-    if (fTemplate || fClass || fTemplateName!="<dummy>")
-    {
-        *fLog << warn << "WARNING - MHArray already setup... Set ignored." << endl;
-        return;
-    }
-
-    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;
-    }
-}
-
-// --------------------------------------------------------------------------
-//
-// Can replace a constructor. Use the default constructor and afterwards
-// the Set function of your need.
-//
-void MHArray::Set(const MH *hist)
-{
-    fIdx=0;
-    fClass=NULL;
-    fTemplate=hist;
-    fTemplateName="<dummy>";
-}
-
-
-// --------------------------------------------------------------------------
-//
-// 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
-    //
-    Init(name);
-    fTitle = title ? TString(title) : (TString("Base class for Mars histogram arrays:") + hname);
-
-    Set(hname, istempl);
-}
-
-// --------------------------------------------------------------------------
-//
-// Default constructor. Use MHArray::Set to setup the MHArray afterwards
-//
-MHArray::MHArray(const char *name, const char *title)
-    : fIdx(0), fClass(NULL), fTemplate(NULL), fTemplateName("<dummy>")
-{
-    //
-    //   set the name and title of this object
-    //
-    Init(name);
-    fTitle = title ? title : "A Mars histogram array";
-}
-
-// --------------------------------------------------------------------------
-//
-// 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 MH *hist, const char *name, const char *title)
-    : fIdx(0), fClass(NULL), fTemplate(hist), fTemplateName("<dummy>")
-{
-    //
-    //   set the name and title of this object
-    //
-    Init(name);
-    fTitle = title ? TString(title) : (TString("Base class for Mars histogram arrays:") + hist->GetName());
-}
-
-// --------------------------------------------------------------------------
-//
-// Destructor: Deleteing the array and all histograms which are part of the
-// array.
-//
-MHArray::~MHArray()
-{
-    fArray->Delete();
-    delete fArray;
-    delete fMapIdx;
-}
-
-// --------------------------------------------------------------------------
-//
-//  Use this to access the histograms by a key. If you use values like
-//   (in this order) 2.5, 7.2, 2.5, 9.3, 9.3, 3.3, 2.2, 1.1
-//  it will be mapped to the following indices internally:
-//                    0    1    0    2    2    3    4    5
-//
-//  WARNING: Make sure that you don't create new histograms by setting
-//           a new index (SetIndex or IncIndex) which is equal the size
-//           of the array and create new histogram by CreateH. In this
-//           case you will confuse the mapping completely.
-//
-void MHArray::SetIndexByKey(Double_t key)
-{
-    fIdx = fMapIdx->Add((Int_t)key);
-}
-
-// --------------------------------------------------------------------------
-//
-//  Use this function to access a histogram by its index in the array.
-//  Becarefull the index isn't checked!
-//
-MH &MHArray::operator[](Int_t i)
-{
-    return *(MH*)fArray->At(i);
-}
-
-// --------------------------------------------------------------------------
-//
-//  Use this function to access a histogram by its index in the array.
-//  Becarefull the index isn't checked!
-//
-MH *MHArray::At(Int_t i)
-{
-    return (MH*)fArray->At(i);
-}
-
-// --------------------------------------------------------------------------
-//
-//  Use this function to access the histogram corresponding to the
-//  currently set index (by Set/Inc/DecIndex or SetIndexByKey)
-//  Becarefull the index set isn't checked!
-//
-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)
-    {
-        //
-        // create the parameter container as a clone of the existing
-        // template histogram.
-        //
-        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 (fTemplate)
-        return kTRUE;
-
-    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 Stat_t w)
-{
-    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, w);
-}
-
-Bool_t MHArray::AddHistogram()
-{
-    fIdx=fArray->GetSize();
-
-    return CreateH();
-}
-
-// --------------------------------------------------------------------------
-//
-// 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;
-
-    if (fMapIdx->GetSize()<=0)
-        return;
-
-    *fLog << " idx\t     key" << endl;
-    for (int i=0; i<fMapIdx->GetSize(); i++)
-        *fLog << "  " << i << "\t<-->  " << fMapIdx->GetKey(i) << endl;
-    *fLog << endl;
-}
-
-// --------------------------------------------------------------------------
-//
-// Adds the given object to the given legend (if != NULL). The Legend
-// entry name is created from the key...
-//
-void MHArray::AddLegendEntry(TLegend *leg, TObject *obj, Int_t idx) const
-{
-    if (!leg)
-        return;
-
-    TString name = " ";
-    name += fMapIdx->GetKey(idx);
-    leg->AddEntry(obj, name, "lpf"); // l=line, p=polymarker, f=fill
-}
-
-
-// --------------------------------------------------------------------------
-//
-// 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 Int_t sstyle = gStyle->GetOptStat();
-    gStyle->SetOptStat(0);
-
-    //
-    // if the keymapping is used create a legend to identify the histograms
-    //
-    TLegend *leg = NULL;
-    if (fMapIdx->GetSize()>0)
-    {
-        leg = new TLegend(0.85, 0.80, 0.99, 0.99);
-        leg->SetBit(kCanDelete);
-    }
-
-    TIter Next(fArray);
-    MH *hist = (MH*)Next();
-
-    Int_t idx=0;
-    Double_t max=0;
-    Double_t min=0;
-
-    TH1 *h1=NULL;
-
-    //
-    // If the array has at least one entry:
-    //  - find the starting boundaries
-    //  - draw it and set its line color
-    //
-    if (hist)
-    {
-        if ((h1 = hist->GetHistByName(opt)))
-        {
-            h1->Draw();
-            h1->SetLineColor(idx+2);
-            max = h1->GetMaximum();
-            min = h1->GetMinimum();
-
-            AddLegendEntry(leg, h1, idx);
-        }
-    }
-
-    //
-    // For all following histograms:
-    //  - update the boundaries
-    //  - draw it and set its line color
-    //
-    while ((hist=(MH*)Next()))
-    {
-        TH1 *h=NULL;
-
-        if (!(h = hist->GetHistByName(opt)))
-            continue;
-
-        h->Draw("same");
-        h->SetLineColor(idx+2);
-        if (max<h->GetMaximum())
-            max = h->GetMaximum();
-        if (min>h->GetMinimum())
-            min = h->GetMinimum();
-
-        AddLegendEntry(leg, h, idx++);
-    }
-
-    //
-    // Now update the drawing region so that everything is displayed
-    //
-    if (h1)
-    {
-        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
-        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
-    }
-
-    if (leg)
-        leg->Draw();
-
-    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.
-// The option "Scale=1" scales the area of all histogram to 1
-// The option "Scale=max" scales the maximum of all histogram to 1
-//
-TObject *MHArray::DrawClone(Option_t *opt) const
-{
-    TString o(opt);
-
-    TCanvas *c = NULL;
-
-    Int_t scale1   = o.Index("scale=1",   TString::kIgnoreCase);
-    Int_t scalemax = o.Index("scale=max", TString::kIgnoreCase);
-    Int_t nonew    = o.Index("nonew",     TString::kIgnoreCase);
-
-    if (o.BeginsWith("scale=1", TString::kIgnoreCase))
-        scale1 = 0;
-    if (o.BeginsWith("scale=max", TString::kIgnoreCase))
-        scalemax = 0;
-    if (o.BeginsWith("nonew", TString::kIgnoreCase))
-        nonew = 0;
-
-    if (nonew>=0)
-    {
-        c = MH::MakeDefCanvas(this);
-
-        //
-        // This is necessary to get the expected bahviour of DrawClone
-        //
-        gROOT->SetSelectedPad(NULL);
-
-        o.Remove(nonew, 5);
-    }
-    if (scale1>=0)
-        o.Remove(scale1, 7);
-    if (scalemax>=0)
-        o.Remove(scalemax, 9);
-
-    const Int_t sstyle = gStyle->GetOptStat();
-    gStyle->SetOptStat(0);
-
-    //
-    // if the keymapping is used create a legend to identify the histograms
-    //
-    TLegend *leg = NULL;
-    if (fMapIdx->GetSize()>0)
-    {
-        leg = new TLegend(0.85, 0.80, 0.99, 0.99);
-        leg->SetBit(kCanDelete);
-    }
-
-    TIter Next(fArray);
-    MH *hist = (MH*)Next();
-
-    Int_t idx=0;
-    Double_t max=0;
-    Double_t min=0;
-
-    TH1 *h1=NULL;
-
-     //
-    // If the array has at least one entry:
-    //  - find the starting boundaries
-    //  - draw it and set its line color
-    //
-    if (hist)
-    {
-        if ((h1 = hist->GetHistByName(o)))
-        {
-            h1 = (TH1*)h1->DrawCopy();
-
-            if (scale1>=0)
-                h1->Scale(1./h1->Integral());
-            if (scalemax>=0)
-                h1->Scale(1./h1->GetMaximum());
-
-            h1->SetMarkerColor(idx);
-            h1->SetLineColor(idx+2);
-            h1->SetFillStyle(4000);
-            max = h1->GetMaximum();
-            min = h1->GetMinimum();
-
-            AddLegendEntry(leg, h1, idx++);
-        }
-    }
-
-    //
-    // For all following histograms:
-    //  - update the boundaries
-    //  - draw it and set its line color
-    //
-    while ((hist=(MH*)Next()))
-    {
-        TH1 *h=NULL;
-
-        if (!(h = hist->GetHistByName(o)))
-            continue;
-
-        h = (TH1*)h->DrawCopy("same");
-
-        if (scale1>=0)
-            h->Scale(1./h->Integral());
-        if (scalemax>=0)
-            h->Scale(1./h->GetMaximum());
-
-        h->SetMarkerColor(idx);
-        h->SetLineColor(idx+2);
-        h->SetFillStyle(4000); // transperent (why is this necessary?)
-        if (max<h->GetMaximum())
-            max = h->GetMaximum();
-        if (min>h->GetMinimum())
-            min = h->GetMinimum();
-
-        AddLegendEntry(leg, h, idx++);
-    }
-
-    //
-    // Now update the drawing region so that everything is displayed
-    //
-    if (h1)
-    {
-        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
-        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
-    }
-
-    if (leg)
-        leg->Draw();
-
-    gPad->Modified();
-    gPad->Update();
-
-    gStyle->SetOptStat(sstyle);
-
-    return c;
-}
Index: trunk/MagicSoft/Mars/mhist/MHArray.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MHArray.h	(revision 2734)
+++ 	(revision )
@@ -1,71 +1,0 @@
-#ifndef MARS_MHArray
-#define MARS_MHArray
-
-#ifndef MARS_MH
-#include "MH.h"
-#endif
-
-class TList;
-class TLegend;
-
-class MMap;
-
-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
-
-    const MH *fTemplate;      //-> pointer to a template histogram
-    TString fTemplateName;    // name of the template class
-
-    MMap *fMapIdx;            //! Table to map keys to array indices
-
-    Bool_t CreateH();
-    void   AddLegendEntry(TLegend *leg, TObject *obj, Int_t idx) const;
-
-    enum { kUseTemplate=BIT(14) };
-
-    void Init(const char *name);
-
-public:
-    MHArray(const char *name=NULL, const char *title=NULL);
-    MHArray(const TString hname, Bool_t istempl=kFALSE, const char *name=NULL, const char *title=NULL);
-    MHArray(const MH *hist, const char *name=NULL, const char *title=NULL);
-    ~MHArray();
-
-    void Set(const TString hname, Bool_t istempl=kFALSE);
-    void Set(const MH *hist);
-
-    Bool_t SetupFill(const MParList *pList);
-    Bool_t Fill(const MParContainer *par, const Stat_t w=1);
-    Bool_t Finalize();
-
-    Bool_t AddHistogram();
-
-    MH &operator[](Int_t i);
-    MH *At(Int_t i);
-
-    MH *GetH();
-
-    void SetIndexByKey(Double_t key);
-
-    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/MWeight.cc
===================================================================
--- trunk/MagicSoft/Mars/mhist/MWeight.cc	(revision 2734)
+++ 	(revision )
@@ -1,35 +1,0 @@
-/* ======================================================================== *\
-!
-! *
-! * 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/2003 <mailto:tbretz@astro.uni-wuerzburg.de>
-!
-!   Copyright: MAGIC Software Development, 2000-2003
-!
-!
-\* ======================================================================== */
-
-/////////////////////////////////////////////////////////////////////////////
-//
-//   MWeight
-//
-//   Storage container for a weight to fill histograms
-//
-/////////////////////////////////////////////////////////////////////////////
-#include "MWeight.h"
-
-ClassImp(MWeight);
-
Index: trunk/MagicSoft/Mars/mhist/MWeight.h
===================================================================
--- trunk/MagicSoft/Mars/mhist/MWeight.h	(revision 2734)
+++ 	(revision )
@@ -1,32 +1,0 @@
-#ifndef MARS_MWeight
-#define MARS_MWeight
-
-/////////////////////////////////////////////////////////////////////////////
-//                                                                         //
-//  MWeight                                                                //
-//                                                                         //
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef MARS_MParContainer
-#include "MParContainer.h"
-#endif
-
-class MWeight : public MParContainer
-{
-private:
-    Double_t fWeight;
-
-public:
-    MWeight(const char *name=NULL, const char *title=NULL) : fWeight(1)
-    {
-        fName  = name  ? name  : "MWeight";
-        fTitle = title ? title : "A weight for filling histograms";
-    }
-
-    void SetWeight(Double_t weight) { fWeight = weight; }
-    Double_t GetWeight() const { return fWeight; }
-
-    ClassDef(MWeight, 1) // A weight for filling histograms
-};
-
-#endif
Index: trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mhist/Makefile	(revision 2734)
+++ trunk/MagicSoft/Mars/mhist/Makefile	(revision 2735)
@@ -30,10 +30,5 @@
 .SUFFIXES: .c .cc .cxx .h .hxx .o 
 
-SRCFILES = MFillH.cc \
-           MBinning.cc \
-           MH.cc \
-           MHVsTime.cc \
-           MHArray.cc \
-           MWeight.cc \
+SRCFILES = MHVsTime.cc \
            MH3.cc \
            MHEvent.cc \
