Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1573)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1574)
@@ -1,3 +1,98 @@
                                                                   -*-*- END -*-*-
+ 2002/11/04: Thomas Bretz
+
+   * macros/estimate.C, macros/estfit.C:
+     - added
+     
+   * mfileio/structures.h, mfileio/defines.h:
+     - added from CT1 PreProc 0.5
+
+   * mfileio/MCT1ReadPreProc.[h,cc]:
+     - added 
+
+   * mhist/MHArray.[h,cc]:
+     - added
+
+   * Makefile:
+     - changed the order of the libs to make the linker happy
+     
+   * manalysis/MBlindPixelCalc.[h,cc]:
+     - changed to be able to use also an existing MBlindPixels from the 
+       parlist
+     - changed to use the pixel Id instead of its index number from the evt
+
+   * manalysis/MCameraSmooth.cc:
+     - changed to use the pixel Id instead of its index number from the evt
+       
+   * manalysis/MCerPhotEvt.[h,cc]:
+     - added GetPixById member function
+
+   * manalysis/MCompProbCalc.[h,cc]:
+     - changed Hadroness to Hadronness
+   
+   * manalysis/MHillasExt.cc:
+     - fixed a typo in a comment
+
+   * mbase/MParContainer.[h,cc]:
+     - added New-virtual member function
+
+   * mbase/MTask.[h,cc]:
+     - changed AddToBranchList so that it also accepts comma seperated
+       lists (only when using TString)
+       
+   * mdata/MData.[h,cc], mdata/MDataArray.[h,cc], mdata/MDataChain.[h,cc],
+     mdata/MDataElement.[h,cc], mdata/MDataList.[h,cc]
+     - updated comments
+     - added new GetDataMember member function
+     
+   * mdata/MDataArray.[h,cc]:
+     - added new member function AddEntry(MData*)
+     
+   * mfileio/FileIOLinkDef.h, mfileio/Makefile:
+     - added MCT1ReadPreProc
+     
+   * mfileio/MCT1ReadAscii.cc:
+     - removed fNphot->Clear() (automatically called for each event by
+       Reset();
+       
+   * mhist/HistLinkDef.h, mhist/Makefile:
+     - added MHArray
+     
+   * mhist/MFillH.[h,cc]:
+     - made work with arrays of histograms (MHArray) the mapping is
+       done by a preliminary class MMap
+       
+   * mhist/MH.[h,cc]:
+     - implemented GetHistByName virtual function
+     - implemented GetDataMember virtual function
+     - small changes to debug output
+     
+   * mhist/MH3.[h,cc]:
+     - implemented usage of GetDataMember for AddBranchToList
+     - implemented GetHistByName
+     - implemented New to be used in MHArray
+
+   * mhist/MHAlphaEnergyTheta.h, mhist/MHAlphaEnergyTime.h,
+     mhist/MHEnergyTheta.h, mhist/MHEnergyTime.h,
+     mhist/MHHillas.[h,cc], mhist/MHHillasExt.[h,cc],
+     mhist/MHHillasSrc.[h,cc], mhist/MHMcDifRate.h,
+     mhist/MHMcEfficiency.h, mhist/MHMcEfficiencyEnergy.h,
+     mhist/MHMcEfficiencyImpact.h, mhist/MHMcEnergy.[h,cc],
+     mhist/MHMcEnergyImpact.h, mhist/MHMcEnergyMigration.h,
+     mhist/MHMcIntRate.h, mhist/MHStarMap.h, mhist/MHThetabarTheta.h,
+     mhist/MHThetabarTime.h, mhist/MHTimeDiffTheta.h, 
+     mhist/MHTimeDiffTime.h:
+     - implemented GetHistByName
+   
+   * mhist/MHHadronness.[h,cc]:
+     - some small changes and checks
+     - changed histogram io from standard pointer to '->'
+
+   * mhist/MHMatrix.cc:
+     - updated comments
+     - implemented GetDataMembers
+
+
+
  2002/10/31: Thomas Bretz
 
Index: /trunk/MagicSoft/Mars/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/Makefile	(revision 1573)
+++ /trunk/MagicSoft/Mars/Makefile	(revision 1574)
@@ -36,8 +36,8 @@
 #
 SUBDIRS = mmain       \
+          mbase       \
+          mfileio     \
+	  manalysis   \
           mmc         \
-	  manalysis   \
-          mfileio     \
-          mbase       \
           meventdisp  \
           mdatacheck  \
Index: /trunk/MagicSoft/Mars/NEWS
===================================================================
--- /trunk/MagicSoft/Mars/NEWS	(revision 1573)
+++ /trunk/MagicSoft/Mars/NEWS	(revision 1574)
@@ -81,4 +81,9 @@
 
    - Introduced more output to the camera displays
+
+   - Added an array of histograms (eg one hist per run), MHArray
+
+   - Added a _preliminary_ version of the reader for CT1 PreProc files
+     (MCT1ReadPreProc)
 
 
Index: /trunk/MagicSoft/Mars/macros/estfit.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/estfit.C	(revision 1574)
+++ /trunk/MagicSoft/Mars/macros/estfit.C	(revision 1574)
@@ -0,0 +1,331 @@
+#include <fstream.h>
+
+#include "MTask.h"
+#include "MParList.h"
+
+#include "MDataChain.h"
+
+class MChisqEval : public MTask
+{
+private:
+    static const TString gsDefName;
+    static const TString gsDefTitle;
+
+    Double_t fChisq; //! Evaluated chi square
+
+    MData   *fData0; // Data Member one (monte carlo data or chisq function)
+    MData   *fData1; // Data Member two (measured data)
+
+    // --------------------------------------------------------------------------
+    //
+    // 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 StreamPrimitive(ofstream &out) const
+    {
+        out << "   MChisqEval " << GetUniqueName() << ";";
+        if (fData0)
+            out << "   " << GetUniqueName() << ".SetY1(\"" << fData0->GetRule() << "\");" << endl;
+        if (fData1)
+            out << "   " << GetUniqueName() << ".SetY1(\"" << fData1->GetRule() << "\");" << endl;
+    }
+
+    enum { kIsOwner = BIT(14) };
+
+public:
+    MChisqEval(const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
+    {
+        fName  = name  ? name  : gsDefName.Data();
+        fTitle = title ? title : gsDefTitle.Data();
+    }
+
+    MChisqEval(MData *y1, const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
+    {
+        fName  = name  ? name  : gsDefName.Data();
+        fTitle = title ? title : gsDefTitle.Data();
+        SetY1(y1);
+    }
+    MChisqEval(MData *y1, MData *y2, const char *name=NULL, const char *title=NULL) : fData0(NULL), fData1(NULL)// : fMatrix(mat), fColumn(col), fEvalE(evale)
+    {
+        fName  = name  ? name  : gsDefName.Data();
+        fTitle = title ? title : gsDefTitle.Data();
+        SetY1(y1);
+        SetY2(y2);
+    }
+    ~MChisqEval()
+    {
+        if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
+            delete fData0;
+
+        if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
+            delete fData1;
+    }
+
+    void SetY1(MData *data)
+    {
+        // Set MC value
+        if (fData0 && (fData0->TestBit(kCanDelete) || TestBit(kIsOwner)))
+            delete fData0;
+        fData0 = data;
+        fData0->SetBit(kCanDelete);
+        AddToBranchList(fData0->GetDataMember());
+    }
+    void SetY2(MData *data)
+    {
+        // Set measured/estimated value
+        if (fData1 && (fData1->TestBit(kCanDelete) || TestBit(kIsOwner)))
+            delete fData1;
+        fData1 = data;
+        fData1->SetBit(kCanDelete);
+        AddToBranchList(fData1->GetDataMember());
+    }
+    void SetY1(const TString data) { SetY1(new MDataChain(data)); }
+    void SetY2(const TString data) { SetY2(new MDataChain(data)); }
+
+    void SetOwner(Bool_t o=kTRUE) { o ? SetBit(kIsOwner) : ResetBit(kIsOwner); }
+
+    Bool_t PreProcess(MParList *plist)
+    {
+        fChisq = 0;
+
+        if (!fData0)
+            return kFALSE;
+
+        if (!fData0->PreProcess(plist))
+            return kFALSE;
+
+        if (fData1)
+            if (!fData1->PreProcess(plist))
+                return kFALSE;
+
+        return kTRUE;
+    }
+
+    Bool_t Process()
+    {
+        const Double_t y1 = fData0->GetValue();
+        const Double_t y2 = fData1 ? fData1->GetValue() : 0;
+
+        const Double_t dy  = y2-y1;
+        const Double_t err = fData1 ? y1*y1 : 1;
+
+        fChisq += dy*dy/err;
+        return kTRUE;
+    }
+
+    Bool_t PostProcess()
+    {
+        fChisq /= GetNumExecutions();
+        return kTRUE;
+    }
+
+    Double_t GetChisq() const { return fChisq; }
+ 
+    ClassDef(MChisqEval, 0)
+};
+
+ClassImp(MChisqEval);
+
+const TString MChisqEval::gsDefName  = "MChisqEval";
+const TString MChisqEval::gsDefTitle = "Evaluate a chisq";
+
+// --------------------------------------------------------------------------
+
+#include <TMinuit.h>
+
+#include "MEvtLoop.h"
+#include "MTaskList.h"
+#include "MEnergyEstParam.h"
+
+void fcn(Int_t &npar, Double_t *gin, Double_t &f, Double_t *par, Int_t iflag)
+{
+    MEvtLoop &evtloop = *(MEvtLoop*)gMinuit->GetObjectFit();
+
+    MTaskList &tlist  = *(MTaskList*)evtloop.GetParList()->FindObject("MTaskList"); //GetTaskList();
+
+    MChisqEval      &eval = *(MChisqEval*)     tlist.FindObject("MChisqEval");
+    MEnergyEstParam &eest = *(MEnergyEstParam*)tlist.FindObject("MEnergyEstParam");
+
+    eest.SetCoeff(TArrayD(eest.GetNumCoeff(), par));
+
+    evtloop.Eventloop();
+
+    f = eval.GetChisq();
+}
+
+// --------------------------------------------------------------------------
+#include <TStopwatch.h>
+
+#include "MHMatrix.h"
+#include "MEnergyEst.h"
+
+#include "MDataMember.h"
+#include "MDataElement.h"
+
+#include "MReadTree.h"
+#include "MMatrixLoop.h"
+
+void estfit(Bool_t evalenergy=kFALSE)
+{
+    //
+    // Fill events into a MHMatrix
+    //
+    MParList parlist;
+    MHMatrix matrix;
+
+    Int_t col = matrix.AddColumn(evalenergy?"MMcEvt.fEnergy":"MMcEvt.fImpact");
+
+    MEnergyEstParam eest;
+    eest.Add("HillasSource");
+    eest.InitMapping(&matrix);
+
+    MReadTree read("Events", "gammas.root");
+    read.DisableAutoScheme();
+
+    if (!matrix.Fill(&parlist, &read))
+        return;
+
+    //
+    // Setup the tasklist used to evaluate the needed chisq
+    //
+    MTaskList tasklist;
+    parlist.AddToList(&tasklist);
+
+    MMatrixLoop loop(&matrix);
+
+    MChisqEval eval;
+    eval.SetY1(new MDataElement(&matrix, col));
+    eval.SetY2(new MDataMember(evalenergy ? "MEnergyEst.fEnergy" : "MEnergyEst.fImpact"));
+    eval.SetOwner();
+
+    tasklist.AddToList(&loop);
+    tasklist.AddToList(&eest);
+    tasklist.AddToList(&eval);
+
+    MEvtLoop evtloop;
+    evtloop.SetParList(&parlist);
+
+    //
+    // Be carefull: This is not thread safe
+    //
+    TMinuit minuit(12);
+    minuit.SetFCN(fcn);
+
+    // Ready for: minuit.mnexcm("SET ERR", arglist, 1, ierflg)
+    if (minuit.SetErrorDef(1))
+    {
+        cout << "SetErrorDef failed." << endl;
+        return;
+    }
+
+    //
+    // Set initial values
+    //
+    TArrayD fA(5);
+    fA[0] =  -2539; // [cm]
+    fA[1] =    900; // [cm]
+    fA[2] =   17.5; // [cm]
+    fA[3] =  1;//    4;
+    fA[4] =   58.3;
+
+    TArrayD fB(7);
+    fB[0] =    -8.64; // [GeV]
+    fB[1] =   -0.069; // [GeV]
+    fB[2] =  0.00066; // [GeV]
+    fB[3] =    0.033; // [GeV]
+    fB[4] = 0.000226; // [GeV]
+    fB[5] =  4.14e-8; // [GeV]
+    fB[6] =    -0.06;
+
+    // Set starting values and step sizes for parameters
+    for (Int_t i=0; i<fA.GetSize(); i++)
+    {
+        TString name = "fA[";
+        name += i;
+        name += "]";
+        Double_t vinit = fA[i];
+        Double_t step  = fabs(fA[i]/3);
+
+        Double_t limlo = 0; // limlo=limup=0: no limits
+        Double_t limup = 0; 
+
+        Bool_t rc = minuit.DefineParameter(i, name, vinit, step, limlo, limup);
+        if (evalenergy)
+            minuit.FixParameter(i);
+
+        if (!rc)
+            continue;
+
+        cout << "Error in defining parameter #" << i << endl;
+        return;
+    }
+
+    for (Int_t i=0; i<fB.GetSize(); i++)
+    {
+        TString name = "fB[";
+        name += i;
+        name += "]";
+        Double_t vinit = fB[i];
+        Double_t step  = fabs(fB[i]/3);
+
+        Double_t limlo = 0; // limlo=limup=0: no limits
+        Double_t limup = 0;
+
+        Bool_t rc = minuit.DefineParameter(i+fA.GetSize(), name, vinit, step, limlo, limup);
+        if (!evalenergy)
+            minuit.FixParameter(i+fA.GetSize());
+
+        if (!rc)
+            continue;
+
+        cout << "Error in defining parameter #" << i+fA.GetSize() << endl;
+        return;
+    }
+
+    //
+    // Setup globals used in FCN
+    //
+    minuit.SetObjectFit(&evtloop);
+
+    TStopwatch clock;
+    clock.Start();
+
+    // Now ready for minimization step: minuit.mnexcm("MIGRAD", arglist, 1, ierflg)
+    gLog.SetNullOutput(kTRUE);
+    Bool_t rc = minuit.Migrad();
+    gLog.SetNullOutput(kFALSE);
+
+    if (rc)
+    {
+        cout << "Migrad failed." << endl;
+        return;
+    }
+
+    cout << endl;
+    clock.Stop();
+    clock.Print();
+    cout << endl;
+
+    for (Int_t i=(evalenergy?fA.GetSize():0); i<(evalenergy?fA.GetSize()+fB.GetSize():fA.GetSize()); i++)
+    {
+        Double_t val;
+        Double_t er;
+
+        if (!minuit.GetParameter(i, val, er))
+        {
+            cout << "Error getting parameter #" << i << endl;
+            return;
+        }
+
+        cout << i << ":  " << val << "  +-  " << er << endl;
+    }
+
+    /*
+     // Print results
+     Double_t amin, edm, errdef;
+     Int_t nvpar, nparx, icstat;
+     minuit.mnstat(amin, edm, errdef, nvpar, nparx, icstat);
+     minuit.mnprin(3, amin);
+     */
+}
Index: /trunk/MagicSoft/Mars/macros/estimate.C
===================================================================
--- /trunk/MagicSoft/Mars/macros/estimate.C	(revision 1574)
+++ /trunk/MagicSoft/Mars/macros/estimate.C	(revision 1574)
@@ -0,0 +1,195 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 et al,  09/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+
+void estimate()
+{
+    //
+    // This is a demonstration program which calculates the Hillas
+    // parameter out of a Magic root file (raw data file).
+    //
+
+    //
+    // Create a empty Parameter List and an empty Task List
+    // The tasklist is identified in the eventloop by its name
+    //
+    MParList plist;
+
+
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    //
+    // Now setup the tasks and tasklist:
+    // ---------------------------------
+    //
+    MReadMarsFile read("Events");
+    read.DisableAutoScheme();
+    /*
+     read.AddFile("star.root");
+     read.AddFile("star2.root");
+     */
+    read.AddFile("gammas.root");
+
+    // Create a filter for the gamma events
+    MFParticleId fgamma("MMcEvt", '=', kGAMMA);
+
+    MTaskList tlist2;
+    tlist2.SetFilter(&fgamma);
+
+    MEnergyEstParam eest;
+    eest.Add("HillasSource");
+
+    TArrayD fA(5);
+    fA[0] =  -2539; // [cm]
+    fA[1] =    900; // [cm]
+    fA[2] =   17.5; // [cm]
+    fA[3] =      4;
+    fA[4] =   58.3;
+
+    TArrayD fB(7);
+    fB[0] =    -8.64; // [GeV]
+    fB[1] =   -0.069; // [GeV]
+    fB[2] =  0.00066; // [GeV]
+    fB[3] =    0.033; // [GeV]
+    fB[4] = 0.000226; // [GeV]
+    fB[5] =  4.14e-8; // [GeV]
+    fB[6] =    -0.06;
+    /* fb5=size*width, ir 29.8% (RMS=23%)
+     fB[0] =    -8.64; // [GeV]
+     fB[1] =   -0.069; // [GeV]
+     fB[2] =  0.00066; // [GeV]
+     fB[3] =    0.033; // [GeV]
+     fB[4] = 0.000226; // [GeV]
+     fB[5] =  4.14e-8; // [GeV]
+     fB[6] =    -0.06;*/
+    /* size*dist, ir 30%
+     fB[0] =   -32; // [GeV]
+     fB[1] =  -0.0295; // [GeV]
+     fB[2] =   0.00112; // [GeV]
+     fB[3] =   0.0644; // [GeV]
+     fB[4] = 1e-5; // [GeV]
+     fB[5] =  6.3e-6; // [GeV]
+     fB[6] =   -0.06;
+     */
+    /* size*width, ir 30%
+     fB[0] =   -17; // [GeV]
+     fB[1] =  -0.06; // [GeV]
+     fB[2] =   0.0013; // [GeV]
+     fB[3] =   0.039; // [GeV]
+     fB[4] = 0.00036; // [GeV]
+     fB[5] =  5.6e-6; // [GeV]
+     fB[6] =   -0.06;
+     */
+    /* fb5=width, ir 31%
+     fB[0] =   0.14; // [GeV]
+     fB[1] =  -0.078; // [GeV]
+     fB[2] =   0.0003; // [GeV]
+     fB[3] =  -0.171; // [GeV]
+     fB[4] = 0.00038; // [GeV]
+     fB[5] =  3e-5; // [GeV]
+     fB[6] =   -0.06;
+     */
+    /* size*length, ir  32%
+     fB[0] =   -1.14; // [GeV]
+     fB[1] =  -0.075; // [GeV]
+     fB[2] =   0.0008; // [GeV]
+     fB[3] =  -0.148; // [GeV]
+     fB[4] = 0.00037; // [GeV]
+     fB[5] =  8e-7; // [GeV]
+     fB[6] =   -0.06;
+     */
+    /* ir/dist 35%
+     fB[0] =     7.7; // [GeV]
+     fB[1] =  -0.076; // [GeV]
+     fB[2] =   0.011; // [GeV]
+     fB[3] =  -0.175; // [GeV]
+     fB[4] = 0.00038; // [GeV]
+     fB[5] = -0.0001; // [GeV]
+     fB[6] =   -0.06;
+     */
+
+
+    eest.SetCoeffA(fA);
+    eest.SetCoeffB(fB);
+
+    MH3 mh3e("MMcEvt.fEnergy",     "abs(MEnergyEst.fEnergy/MMcEvt.fEnergy-1)");
+    MH3 mh3i("MMcEvt.fImpact/100", "abs(MEnergyEst.fImpact/MMcEvt.fImpact-1)");
+
+    mh3e.SetName("HistEnergy");
+    mh3i.SetName("HistImpact");
+
+    MFillH hfille(&mh3e);
+    MFillH hfilli(&mh3i);
+
+    MBinning binsex("BinningHistEnergyX");
+    MBinning binsey("BinningHistEnergyY");
+    MBinning binsix("BinningHistImpactX");
+    MBinning binsiy("BinningHistImpactY");
+
+    binsex.SetEdgesLog(50, 10, 1e4);
+    binsey.SetEdges(50, 0, 7);
+
+    binsix.SetEdges(50, 0, 300);
+    binsiy.SetEdges(50, 0, 3);
+
+    plist.AddToList(&binsex);
+    plist.AddToList(&binsey);
+    plist.AddToList(&binsix);
+    plist.AddToList(&binsiy);
+
+    //
+    //  Setup tasklists
+    //
+    tlist.AddToList(&read);
+    tlist.AddToList(&fgamma);
+    tlist.AddToList(&tlist2);
+
+    tlist2.AddToList(&eest);
+    tlist2.AddToList(&hfille);
+    tlist2.AddToList(&hfilli);
+
+    /*
+     MPrint p("MEnergyEst");
+     tlist2.AddToList(&p);
+     */
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    mh3i.DrawClone("PROFX");
+    mh3e.DrawClone("PROFX");
+}
+
Index: /trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.cc	(revision 1574)
@@ -93,5 +93,8 @@
 Bool_t MBlindPixelCalc::PreProcess (MParList *pList)
 {
-    fPixels = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
+    if (TESTBIT(fFlags, kUseBlindPixels))
+        fPixels = (MBlindPixels*)pList->FindObject("MBlindPixels");
+    else
+        fPixels = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
     if (!fPixels)
 	return kFALSE; 
@@ -106,5 +109,8 @@
     fGeomCam = (MGeomCam*)pList->FindObject("MGeomCam");
     if (!fGeomCam)
-        *fLog << warn << dbginf << "No camera geometry available... can't ude interpolation." << endl;
+        *fLog << warn << dbginf << "No camera geometry available... can't use interpolation." << endl;
+
+    if (TESTBIT(fFlags, kUseBlindPixels))
+        return kTRUE;
 
     const UShort_t size = fPixelsID.GetSize();
@@ -162,6 +168,6 @@
         Int_t num = TESTBIT(fFlags, kUseCentralPixel) ? 1 : 0;
 
-        nphot[i] = TESTBIT(fFlags, kUseCentralPixel) ? (*fEvt)[id].GetNumPhotons() : 0;
-        perr[i]  = TESTBIT(fFlags, kUseCentralPixel) ? (*fEvt)[id].GetErrorPhot()  : 0;
+        nphot[i] = TESTBIT(fFlags, kUseCentralPixel) ? pix.GetNumPhotons() : 0;
+        perr[i]  = TESTBIT(fFlags, kUseCentralPixel) ? pix.GetErrorPhot()  : 0;
         for (int j=0; j<n; j++)
         {
@@ -171,7 +177,10 @@
                 continue;
 
-            nphot[i] += (*fEvt)[nid].GetNumPhotons();
-            perr[i]  += (*fEvt)[nid].GetErrorPhot();
-
+            const MCerPhotPix *evtpix = fEvt->GetPixById(nid);
+            if (evtpix)
+            {
+                nphot[i] += evtpix->GetNumPhotons();
+                perr[i]  += evtpix->GetErrorPhot();
+            }
             num++;
         }
@@ -253,4 +262,7 @@
 Bool_t MBlindPixelCalc::ReInit(MParList *pList)
 {
+    if (TESTBIT(fFlags, kUseBlindPixels))
+        return kTRUE;
+
     //
     // If pixels are given by the user, we are already done
Index: /trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MBlindPixelCalc.h	(revision 1574)
@@ -28,5 +28,6 @@
     {
         kUseInterpolation = 1,
-        kUseCentralPixel  = 2
+        kUseCentralPixel  = 2,
+        kUseBlindPixels   = 3
     };
 
@@ -46,4 +47,8 @@
         b ? SETBIT(fFlags, kUseCentralPixel) : CLRBIT(fFlags, kUseCentralPixel);
     }
+    void SetUseBlindPixels(Bool_t b=kTRUE)
+    {
+        b ? SETBIT(fFlags, kUseBlindPixels) : CLRBIT(fFlags, kUseBlindPixels);
+    }
 
     Bool_t PreProcess(MParList *pList);
Index: /trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MCameraSmooth.cc	(revision 1574)
@@ -111,16 +111,23 @@
             const Int_t n = gpix.GetNumNeighbors();
 
-            photons[i] = fUseCentralPixel ? (*fEvt)[id].GetNumPhotons() : 0;
-            errors[i]  = fUseCentralPixel ? (*fEvt)[id].GetErrorPhot()  : 0;
+            Int_t num  = fUseCentralPixel ? 1 : 0;
+            photons[i] = fUseCentralPixel ? pix.GetNumPhotons() : 0;
+            errors[i]  = fUseCentralPixel ? pix.GetErrorPhot()  : 0;
+
             for (int j=0; j<n; j++)
             {
                 const UShort_t nid = gpix.GetNeighbor(j);
 
-                photons[i] += (*fEvt)[nid].GetNumPhotons();
-                errors[i]  += (*fEvt)[nid].GetErrorPhot();
+                const MCerPhotPix *evtpix = fEvt->GetPixById(nid);
+                if (evtpix)
+                {
+                    photons[i] += evtpix->GetNumPhotons();
+                    errors[i]  += evtpix->GetErrorPhot();
+                }
+                num++;
             }
 
-            photons[i] /= fUseCentralPixel ? n+1 : n;
-            errors[i]  /= fUseCentralPixel ? n+1 : n;
+            photons[i] /= num;
+            errors[i]  /= num;
         }
 
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.cc	(revision 1574)
@@ -306,2 +306,18 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Return a pointer to the pixel with the requested id. NULL if it doesn't
+// exist.
+//
+MCerPhotPix *MCerPhotEvt::GetPixById(int id) const
+{
+    TIter Next(fPixels);
+    MCerPhotPix *pix = NULL;
+
+    while ((pix=(MCerPhotPix*)Next()))
+        if (pix->GetPixId()==id)
+            return pix;
+
+    return NULL;
+}
Index: /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MCerPhotEvt.h	(revision 1574)
@@ -47,4 +47,6 @@
     MCerPhotPix &operator[](int i) const { return *(MCerPhotPix*)(fPixels->UncheckedAt(i)); }
 
+    MCerPhotPix *GetPixById(int id) const;
+
     void Reset();
 
Index: /trunk/MagicSoft/Mars/manalysis/MCompProbCalc.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCompProbCalc.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MCompProbCalc.cc	(revision 1574)
@@ -77,5 +77,5 @@
 //  - MHCompProb
 //  - all data values which were used to build the MHCompProb
-//  - MHadroness
+//  - MHadronness
 //
 Bool_t MCompProbCalc::PreProcess(MParList *plist)
@@ -136,5 +136,5 @@
 //  - For all data members multiply the probabilities.
 //  - For normalization take the n-th root of the result.
-//  - This is the hadroness stored in the MHadroness container
+//  - This is the hadroness stored in the MHadronness container
 //
 Bool_t MCompProbCalc::Process()
Index: /trunk/MagicSoft/Mars/manalysis/MCompProbCalc.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MCompProbCalc.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MCompProbCalc.h	(revision 1574)
@@ -13,5 +13,5 @@
 {
 private:
-    MHadronness *fHadronness; //! Output container (Hadroness)
+    MHadronness *fHadronness; //! Output container (Hadronness)
 
     TList *fData;           //! List of MDataChains to be used
Index: /trunk/MagicSoft/Mars/manalysis/MHillasExt.cc
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MHillasExt.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/manalysis/MHillasExt.cc	(revision 1574)
@@ -39,5 +39,5 @@
 //
 // WARNING: Before you can use fAsym, fM3Long and fM3Trans you must
-//          multiply by the sign of MHillasSrc::fCosAlphaDelta
+//          multiply by the sign of MHillasSrc::fCosDeltaAlpha
 //
 ////////////////////////////////////////////////////////////////////////////
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.cc	(revision 1574)
@@ -435,2 +435,12 @@
     arr.Compress();
 }
+
+// --------------------------------------------------------------------------
+//
+// Creates a new instance of this class. The idea is to create a clone of
+// this class in its initial state.
+//
+MParContainer *MParContainer::New() const
+{
+    return (MParContainer*)IsA()->New();
+}
Index: /trunk/MagicSoft/Mars/mbase/MParContainer.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mbase/MParContainer.h	(revision 1574)
@@ -70,4 +70,5 @@
     virtual void        SavePrimitive(ofstream &out, Option_t *o="");
 
+    virtual MParContainer *New() const;
     virtual void   SetLogStream(MLog *lg) { fLog = lg; }
     virtual void   Reset() { }
Index: /trunk/MagicSoft/Mars/mbase/MTask.cc
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mbase/MTask.cc	(revision 1574)
@@ -122,4 +122,28 @@
 // --------------------------------------------------------------------------
 //
+// Using this overloaded member function you may cascade several branches
+// in acomma seperated list, eg: "MMcEvt.fTheta,MMcEvt.fEnergy"
+//
+// For moredetailed information see AddToBranchList(const char *b);
+//
+void MTask::AddToBranchList(const TString &str)
+{
+    TString s = str;
+
+    while (1)
+    {
+        Int_t fst = s.First(',');
+
+        if (fst<0)
+            return;
+
+        AddToBranchList(TString(s(0, fst)));
+
+        s.Remove(0, fst+1);
+    }
+}
+
+// --------------------------------------------------------------------------
+//
 // Copy constructor.
 //
Index: /trunk/MagicSoft/Mars/mbase/MTask.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MTask.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mbase/MTask.h	(revision 1574)
@@ -35,8 +35,5 @@
 protected:
     void AddToBranchList(const char *b);
-    void AddToBranchList(const TString &str)
-    {
-        AddToBranchList((const char*)str);
-    }
+    void AddToBranchList(const TString &str);
     void AddToBranchList(const char *master, const char *sub, const UInt_t first, const UInt_t last)
     {
Index: /trunk/MagicSoft/Mars/mdata/MData.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MData.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MData.cc	(revision 1574)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
@@ -44,4 +44,19 @@
 //      from the parlist.
 //
+//    - TString GetRule()
+//      returns the rule as a text which would recreate the same structure
+//      when used in a MDataChain
+//
+//    - TString GetDataMember()
+//      returns the names (seperated by a comma) used by this class. This
+//      is mainly used for the AutoScheme when reading data from a file.
+//      (s.MReadTree)
+//
+//   The 'must' ist represented by the =0 in the class header. In the C++
+//   language this is called an abstract member function. Because the
+//   class contains abstract member function which makes it impossible
+//   to create an instance of this class one calls it also:
+//   abstract base class
+//
 /////////////////////////////////////////////////////////////////////////////
 
Index: /trunk/MagicSoft/Mars/mdata/MData.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MData.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MData.h	(revision 1574)
@@ -21,4 +21,5 @@
     virtual Bool_t   PreProcess(const MParList *plist) = 0;
     virtual TString  GetRule() const = 0;
+    virtual TString  GetDataMember() const { return ""; }
 
     Double_t operator()() { return GetValue(); }
Index: /trunk/MagicSoft/Mars/mdata/MDataArray.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataArray.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataArray.cc	(revision 1574)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  08/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  08/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
@@ -26,4 +26,7 @@
 //
 //   MDataArray
+//
+//   An Array of MData derived classes.
+//   It can be used, eg, in MHMatrix for description of the columns.
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -42,4 +45,8 @@
 static const TString gsDefTitle = "Array to store MData cntainers";
 
+// --------------------------------------------------------------------------
+//
+// Constructor
+//
 MDataArray::MDataArray(const char *name, const char *title)
 {
@@ -48,4 +55,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Add a new data rule as a new entry (MDataChain)
+//
 void MDataArray::AddEntry(const TString rule)
 {
@@ -55,4 +66,18 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Add a new data as a new entry (MData). If the destructor of MDataArray
+// should delete the object set its bit kCanDelete
+//
+void MDataArray::AddEntry(MData *data)
+{
+    fList.Add(data);
+}
+
+// --------------------------------------------------------------------------
+//
+// Return the i-th entry
+//
 MData &MDataArray::operator[](Int_t i) const
 {
@@ -60,4 +85,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Return the data value of the i-th entry
+//
 Double_t MDataArray::operator()(Int_t i)
 {
@@ -65,4 +94,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// PreProcesses all members in the list
+//
 Bool_t MDataArray::PreProcess(const MParList *plist)
 {
@@ -82,4 +115,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Print the rules for all entries of the array
+//
 void MDataArray::Print(Option_t *opt) const
 {
@@ -102,4 +139,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MDataArray::StreamPrimitive(ofstream &out) const
 {
@@ -119,2 +162,24 @@
         out << "   " << GetUniqueName() << ".AddEntry(\"" << data->GetRule() << "\");" << endl;
 }
+
+// --------------------------------------------------------------------------
+//
+// Return the data members existing in this array in a comma-seperated list
+// (This is mainly used for MTask::AddToBranchList)
+//
+TString MDataArray::GetDataMember() const
+{
+    TString str;
+
+    TIter Next(&fList);
+    MData *data = NULL;
+    while ((data=(MData*)Next()))
+    {
+        if (data->GetDataMember().IsNull())
+            continue;
+
+        str += ",";
+        str += data->GetDataMember();
+    }
+    return str;
+}
Index: /trunk/MagicSoft/Mars/mdata/MDataArray.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataArray.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataArray.h	(revision 1574)
@@ -28,4 +28,5 @@
 
     void AddEntry(const TString rule);
+    void AddEntry(MData *data);
 
     MData &operator[](Int_t i) const;
@@ -33,4 +34,6 @@
 
     Bool_t PreProcess(const MParList *plist);
+
+    TString GetDataMember() const;
 
     void Print(Option_t *opt = "") const;
Index: /trunk/MagicSoft/Mars/mdata/MDataChain.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataChain.cc	(revision 1574)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
@@ -95,4 +95,8 @@
 ClassImp(MDataChain);
 
+// --------------------------------------------------------------------------
+//
+//  Constructor which takes a rule and a surrounding operator as argument
+//
 MDataChain::MDataChain(const char *rule, OperatorType_t op)
     : fOperatorType(op)
@@ -104,4 +108,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+//  Default constructor
+//
 MDataChain::MDataChain()
     : fMember(NULL), fOperatorType(kENoop)
@@ -109,4 +117,9 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Constructor taking a rule as an argument. For more details see
+// class description
+//
 MDataChain::MDataChain(const char *rule, const char *name, const char *title)
     : fOperatorType(kENoop)
@@ -220,4 +233,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Core of the data chain. Here the chain is constructed out of the rule.
+//
 MData *MDataChain::ParseString(TString txt, Int_t level)
 {
@@ -420,4 +437,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Returns the value described by the rule
+//
 Double_t MDataChain::GetValue() const
 {
@@ -498,4 +519,9 @@
         */
 
+// --------------------------------------------------------------------------
+//
+// Builds a rule from all the chain members. This is a rule which could
+// be used to rebuild the chain.
+//
 TString MDataChain::GetRule() const
 {
@@ -541,2 +567,12 @@
     return str;
 }
+
+// --------------------------------------------------------------------------
+//
+// Return a comma seperated list of all data members used in the chain.
+// This is mainly used in MTask::AddToBranchList
+//
+TString MDataChain::GetDataMember() const
+{
+    return fMember->GetDataMember();
+}
Index: /trunk/MagicSoft/Mars/mdata/MDataChain.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataChain.h	(revision 1574)
@@ -66,4 +66,5 @@
 
     TString GetRule() const;
+    TString GetDataMember() const;
 
     ClassDef(MDataChain, 1) // A chain/concatenation of MData objects
Index: /trunk/MagicSoft/Mars/mdata/MDataElement.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataElement.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataElement.cc	(revision 1574)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
Index: /trunk/MagicSoft/Mars/mdata/MDataList.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataList.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataList.cc	(revision 1574)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
@@ -182,4 +182,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// PreProcesses all members in the list
+//
 Bool_t MDataList::PreProcess(const MParList *plist)
 {
@@ -259,4 +263,9 @@
     */
 
+// --------------------------------------------------------------------------
+//
+// Builds a rule from all the list members. This is a rule which could
+// be used to rebuild the list using the constructor of a MDataChain
+//
 TString MDataList::GetRule() const
 {
@@ -306,2 +315,30 @@
     return str;
 }
+
+// --------------------------------------------------------------------------
+//
+// Return a comma seperated list of all data members used in the chain.
+// This is mainly used in MTask::AddToBranchList
+//
+TString MDataList::GetDataMember() const
+{
+    TString str;
+
+    TIter Next(&fMembers);
+
+    MData *member=(MData*)Next();
+
+    if (!member->GetDataMember().IsNull())
+        str += member->GetDataMember();
+
+    while ((member=(MData*)Next()))
+    {
+        if (!member->GetDataMember().IsNull())
+        {
+            str += ",";
+            str += member->GetDataMember();
+        }
+    }
+
+    return str;
+}
Index: /trunk/MagicSoft/Mars/mdata/MDataList.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataList.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataList.h	(revision 1574)
@@ -49,4 +49,5 @@
 //    void Print(Option_t *opt = "") const;
     TString GetRule() const;
+    TString GetDataMember() const;
 
     ClassDef(MDataList, 1) // A concatenation of MData objects by one operator
Index: /trunk/MagicSoft/Mars/mdata/MDataMember.cc
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataMember.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataMember.cc	(revision 1574)
@@ -16,5 +16,5 @@
 !
 !
-!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Thomas Bretz  04/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
 !
 !   Copyright: MAGIC Software Development, 2000-2002
@@ -170,6 +170,20 @@
 */
 
+// --------------------------------------------------------------------------
+//
+// Builds a rule which cn be used in a MDataChain to describe this object
+//
 TString MDataMember::GetRule() const
 {
     return fDataMember;
 }
+
+// --------------------------------------------------------------------------
+//
+// Returns the data member.
+// This is mainly used in MTask::AddToBranchList
+//
+TString MDataMember::GetDataMember() const
+{
+    return fDataMember;
+}
Index: /trunk/MagicSoft/Mars/mdata/MDataMember.h
===================================================================
--- /trunk/MagicSoft/Mars/mdata/MDataMember.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mdata/MDataMember.h	(revision 1574)
@@ -37,4 +37,5 @@
     //void Print(Option_t *opt = "") const;
     TString GetRule() const;
+    TString GetDataMember() const;
 
     ClassDef(MDataMember, 1) // MData object corresponding to a single data member of a Mars container
Index: /trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mfileio/FileIOLinkDef.h	(revision 1574)
@@ -16,4 +16,5 @@
 
 #pragma link C++ class MCT1ReadAscii+;
+#pragma link C++ class MCT1ReadPreProc+;
 
 #endif
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadAscii.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadAscii.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadAscii.cc	(revision 1574)
@@ -216,8 +216,10 @@
 void MCT1ReadAscii::ReadData()
 {
-    //
-    // clear the list of cerphot-events
-    //
-    fNphot->Clear();
+    /*
+     //
+     // clear the list of cerphot-events
+     //
+     fNphot->Clear();
+     */
 
     //
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1574)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1574)
@@ -0,0 +1,641 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  12/2000 <mailto:tbretz@uni-sw.gwdg.de>
+!   Author(s): Harald Kornmayer 1/2001 (harald@mppmu.mpg.de)
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MCT1ReadPreProc
+//
+// Reads a output file of the CT1 preproc.
+//
+//  Input Containers:
+//   -/-
+//
+//  Output Containers:
+//    MCerPhotEvt     the data container for all data.
+//    MPedestalCam    ct1 pedestals
+//    MMcEvt          monte carlo data container for MC files
+//    MMcTrig         mc data container for trigger information
+//    MSrcPosCam      source position in the camera
+//    MBlindPixels    Array holding blind pixels
+//
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MCT1ReadPreProc.h"
+
+#include <fstream.h>
+
+#include <TList.h>
+#include <TSystem.h>
+
+#define LINUX
+#define HISTO void
+#define HBOOK_FILE int
+#include "defines.h"
+#include "structures.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MCerPhotEvt.h"
+
+#include "MPedestalPix.h"
+#include "MPedestalCam.h"
+
+#include "MGeomCam.h"
+#include "MSrcPosCam.h"
+#include "MBlindPixels.h"
+
+#include "MMcEvt.hxx"
+#include "MMcTrig.hxx"
+
+ClassImp(MCT1ReadPreProc);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor. Creates an array which stores the file names of
+// the files which should be read. If a filename is given it is added
+// to the list.
+//
+MCT1ReadPreProc::MCT1ReadPreProc(const char *fname, const char *name,
+                                 const char *title) : fIn(NULL)
+{
+    fName  = name  ? name  : "MCT1ReadPreProc";
+    fTitle = title ? title : "Task to loop over events in CT1 ascii file";
+
+    //
+    // remember file name for opening the file in the preprocessor
+    //
+    fFileNames = new TList;
+    fFileNames->SetOwner();
+
+    if (fname)
+        AddFile(fname);
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the filename list and the input stream if one exists.
+//
+MCT1ReadPreProc::~MCT1ReadPreProc()
+{
+    delete fFileNames;
+    if (fIn)
+        delete fIn;
+}
+
+// --------------------------------------------------------------------------
+//
+// Add this file as the last entry in the chain
+//
+void MCT1ReadPreProc::AddFile(const char *txt)
+{
+    TNamed *name = new TNamed(txt, "");
+    fFileNames->AddLast(name);
+}
+
+// --------------------------------------------------------------------------
+//
+// Print data from the header to the screen and analyse the header data,
+// means store and copy the needed data into Mars structures and
+// data members
+//
+void MCT1ReadPreProc::ProcessHeader(const struct outputpars &outpars)
+{
+    fNumPixels = outpars.inumpixels; // number of pixels in the camera
+
+    if (fNumPixels>iMAXNUMPIX || fNumPixels==0)
+        fNumPixels=iMAXNUMPIX;
+
+    //
+    // ------------------- Output some stuff -----------------------
+    //
+
+    // int     itelescope;       // number of the CT which took the data
+    *fLog << inf << "Telescope: CT" << outpars.itelescope;
+
+    // float   flongitude_deg;   // longitude (counted positive towards West) of CT position */
+    // float   flatitude_deg;    // latitude (counted positive towards North) of CT position */
+    *fLog << " located @ Longitude=" << outpars.flongitude_deg;
+    *fLog << "deg  Latitude=" << outpars.flatitude_deg << "deg" << endl;
+
+    // int     irunnum;          // run number (from parameters file)
+    // enum    onoroff {NEITHER_ON_NOR_OFF, OFF_SOURCE, ON_SOURCE} eruntype; // runtype
+    *fLog << "Run:       #" << outpars.irunnum << "  (";
+    switch (outpars.eruntype)
+    {
+    case NEITHER_ON_NOR_OFF: *fLog << "unknown";    break;
+    case OFF_SOURCE:         *fLog << "off-source"; break;
+    case ON_SOURCE:          *fLog << "on-source";  break;
+    default:                 *fLog << (int)outpars.eruntype; break;
+    }
+    *fLog << ", ";
+    switch (outpars.etrackmode)
+    {
+    case NORMAL:  *fLog << "normal tracking";  break;
+    case REVERSE: *fLog << "reverse tracking"; break;
+    case DUNNO:   *fLog << "unknown tracking"; break;
+    default:      *fLog << (int)outpars.etrackmode; break;
+    }
+    *fLog << ")" << endl;
+
+    //double  dsourcera_hours;  // right ascension of observed source in hours
+    //double  dsourcedec_deg;   // declination of observed source in degrees
+    *fLog << "Source:    RA=" << outpars.dsourcera_hours << "h  DEC=";
+    *fLog << outpars.dsourcedec_deg << "deg" << endl;
+
+    *fLog << "Pixels:    " << fNumPixels << endl;
+
+    //int     inummuonpixels;   // number of pixels in the muon shield
+    //int     inumcointdcs;     // number of coincidence tdcs recorded in the runfile
+    //float   fpixdiameter_deg; // smallest pixel diameter (degrees) (from parameters file) */
+
+    // enum    axes {RA, DEC, ALT, AZ} ese1_is; // name of the axis to which shaft encoder 1 is attached (implies the type of mount)
+    *fLog << "Shaftencoder 1 @ ";
+    switch (outpars.ese1_is)
+    {
+    case RA:  *fLog << "RA";  break;
+    case DEC: *fLog << "DEC"; break;
+    case ALT: *fLog << "ALT"; break;
+    case AZ:  *fLog << "AZ";  break;
+    default:  *fLog << (int)outpars.ese1_is; break;
+    }
+    *fLog << endl;
+
+    // int     isezeropos[2];       // zero position of shaftencoders 1 and 2 (from parameters file)
+    *fLog << "SE Zero:   SE(1)=" << outpars.isezeropos[0] << "  ";
+    *fLog << "SE(2)=" << outpars.isezeropos[1] << endl;
+
+    // int     iaz_rev_track_corr;  // correction for the azimuth shaft encoder (ALT/AZ mount only) in reverse tracking mode
+    // int     ialt_rev_track_corr; // correction for the altitude shaft encoder (ALT/AZ mount only) in reverse tracking mode
+    *fLog << "Reverse tracking corrections: SE(az)=" << outpars.iaz_rev_track_corr;
+    *fLog << "  SE(alt)=" << outpars.ialt_rev_track_corr << endl;
+
+    // float   fbendingcorr;        // bending correction factor (ALT/AZ mount only)
+    // float   fextinction;         // atmospheric extinction (typically taken from the Carlsberg Meridian Circle data)
+    *fLog << "Bending: Correction factor=" << outpars.fbendingcorr << "  ";
+    *fLog << "Extinction=" << outpars.fextinction << endl;
+
+    // Boolean bdontusepix[iMAXNUMPIX]; // bdontusepix is set true if the pixel should not be used in image analysis, otherwise it is true;
+    fBlinds->Clear();
+    *fLog << "Don't use pixels: ";
+    for (int i=0; i<iMAXNUMPIX; i++)
+        if (outpars.bdontusepix[i])
+        {
+            *fLog << i << " ";
+            fBlinds->SetPixelBlind(i);
+        }
+    *fLog << endl;
+
+    *fLog << "Exclude: ";
+    // Boolean bexcludepix[iMAXNUMPIX];
+    for (int i=0; i<iMAXNUMPIX; i++)
+        if (outpars.bdontusepix[i])
+            *fLog << i << " ";
+    *fLog << endl;
+    /* bexcludepix[] is set TRUE (== exclude from pedestal, Laser
+     * calibration and the further analysis) when the Mean value
+     * of a pixel inside a pedestal Run is larger than 50 or ( || )
+     * if the pedestal RMS value of this pixel is larger than 5.0
+     * This is reflected in the (new for versions >= 0.4)
+     * variable "pixonoff" in the ntuple written by preproc:
+     * preproc.nt.hbook
+     *
+     * When the pixel is excluded by the user it will get a -2 otherwise
+     * pixonoff = 0.
+     * Additive to this a -1 is added when preproc excludes the pixel
+     * for a given Run. So the actual value tells you whether you caught
+     * it already by hand or not.
+     *
+     * A plot of pixonoff may also be handy to tell you the status of your
+     * ADC equipment. */
+
+    // float   fphotoel_per_adccnt[iMAXNUMPIX]; // conversion factors for the pixel signals */
+    /*
+    float padc = outpars.fphotoel_per_adccnt[0];
+    *fLog << "Phe/ADC (pixel 0): " << padc << endl;
+    for (int i=0; i<iMAXNUMPIX; i++)
+        *fLog << outpars.fphotoel_per_adccnt[i] << " ";
+    *fLog << endl;
+    */
+    /*
+     --- USEFULL? NEEDED? ---
+     int     irubminusutc_usecs;              // difference between rubidium clock and UTC in microseconds
+     int     isum_thresh_phot;                // threshold for the total sum of photoelectrons filter
+     int     i2out_thresh_phot;               // threshold for the two-pixels-out-of-all software
+     int     imuoncut_thresh_adccnt[iMAXNUMMUONPIX]; // thresholds for the muon cut
+     Boolean bmuon_suppression;               // "Dolby" noise reduction flag
+     float   ftolerated_pointerror_deg;       // maximum tolerated pointing error in the position
+     */
+
+    // float fxpointcorr_deg; // pointing correction (to be added along the camera x axis) e.g. from point run */
+    // float fypointcorr_deg; // pointing correction (to be added along the camera y axis) e.g. from point run */
+    *fLog << "Pointing correction: dx=" << outpars.fxpointcorr_deg << "deg  ";
+    *fLog << "dy=" << outpars.fxpointcorr_deg << "deg" << endl;
+
+    /*
+     fSrcPos->SetXY( outpars.fxpointcorr_deg/fGeom->GetConvMm2Deg(),
+     outpars.fypointcorr_deg/fGeom->GetConvMm2Deg());
+     */
+
+    /*
+     --- USEFULL? NEEDED? ---
+     float   fcamera_align_angle_deg;         // the angle between the camera y-axis and the meridian when a culminating object is observed (defined counter-clockwise looking at the sky)
+     int     iratecalc_numevents_odd;         // number of events used in the rate calculation (must be odd)
+     int     inumpedfile;                     // number of the pedestal file used
+     int     inumpedrun;                      // number of the pedestal run used in the file (starting at 0)
+     int     inumcalfile;                     // number of the calibration file used
+     int     inumlaserrun;                    // number of the laserrun used in the file (starting at 0)
+     int     inumtellogfile;                  // number of the TelLog file to be used
+     int     inumtellogrun;                   // number of the tellog entry (Runnumber) used from the log file
+     int     imcparticle;                     // CORSIKA-coded Monte Carlo particle type.
+    */
+
+    // ----- preprocessing results -----
+
+    // int     istart_mjdate_day;                 // MJD of run start (first event) */
+    // int     iend_mjdate_day;                   // MJD of run end (last event) */
+    // int     irunduration_secs;                 // difference between start and end time (secs) */
+    *fLog << "Run Time: From " << outpars.istart_mjdate_day << " to ";
+    *fLog << outpars.iend_mjdate_day << " (MJD),  Duration=";
+    *fLog << outpars.irunduration_secs/3600 << "h";
+    *fLog << (outpars.irunduration_secs/60)%60 << "m";
+    *fLog << outpars.irunduration_secs%60 << "s" << endl;
+
+    /*
+     --- USEFULL? NEEDED? ---
+     int     iproc_mjdate;                      // MJD of data processing (i.e. creation of this file)
+     */
+
+    // int     iproc_evts;                        // number of events processed */
+    *fLog << "Number of processed events: " << outpars.iproc_evts << endl;
+
+    // --- USEFULL? NEEDED? ---
+    // double  dactual_sourcera_hours;            // for off runs: the false source (that should have been) observed */
+
+    // float   frms_pedsig_phot[iMAXNUMPIX];      // standard deviation of the calibrated signals from the pedestal run */
+    fPedest->InitSize(iMAXNUMPIX);
+    for (Int_t i=0; i<iMAXNUMPIX; i++)
+        (*fPedest)[i].SetMeanRms(outpars.frms_pedsig_phot[i]);
+
+    // Used to communicate the mean over all pixels
+    // pedestal RMS into the Runs NTuple, as it might
+    // be used for e.g. quality cuts.
+    // float   fpedrms_mean;
+    *fLog << "Pedestal RMS: " << outpars.fpedrms_mean << endl;
+
+    // The average current over the active pixels
+    // for this run. This is done separately for
+    // ON and OF runs.
+    //float   fcurrent_mean;
+
+    // enum eERRORTOLERANCE {CAUTIOUS=0, GOODPHYSICS, TANK} eerrortolerance;
+    /* 0 == "cautious", exits on any reason (but tells in
+     * the .err file,
+     * 1 == "goodphysics", exits when physics could be affected
+     * by the error,
+     * 2 == "tank", never exits except on coredumps and when
+     * all files have been processed. Do not use such files for
+     * physics analysis!
+     *
+     * NOTE: the capital letter words are the enums, the small letter
+     * words must be used inside the parameter file. */
+
+    // enum eMCTRIGGERFLAG {ALL=0, FLAG, NOFLAG} emctriggerflag;
+    /* all: all events which survive the filter are written to the
+     *      events NTuple.
+     * flag: When Dorota's triggerflag is set to 1 for a particular
+     *       event, it shall be written to the output. All others shall
+     *       just be disregarded. (Default)
+     * noflag: Opposite of 'flag': only events with triggerflag = 0 shall
+     *         be treated further. */
+
+    if (outpars.bmontecarlo)
+        *fLog << "File is a Monte Carlo file." << endl;
+
+    fIsMcFile = outpars.bmontecarlo==TRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Read CT1 PreProc File Header:
+//
+void MCT1ReadPreProc::ReadHeader()
+{
+    char cheadertitle[iHEADERTITLELENGTH];
+    fIn->read(cheadertitle, iHEADERTITLELENGTH);
+
+    *fLog << cheadertitle << flush;
+
+    // cTITLE_TEMPLATE "PREPROC V%f/S%f CT %d RUN %d %d PROCMJD %d\n"
+    struct outputpars outpars;
+
+    Float_t fpreprocversion, structversion;
+    sscanf(cheadertitle, cTITLE_TEMPLATE,
+           &fpreprocversion,    &structversion,
+           &outpars.itelescope, &outpars.irunnum,
+           &outpars.eruntype,   &outpars.iproc_mjdate);
+
+    if (STRUCT_VERSION != structversion)
+    {
+        *fLog << warn << "WARNING: Version of C-structures of file (V";
+        *fLog << structversion << ") not identical with current structures (V";
+        *fLog << STRUCT_VERSION << ")" << endl;
+    }
+
+    fIn->read(&outpars, sizeof(struct outputpars));
+
+    ProcessHeader(outpars);
+}
+
+void MCT1ReadPreProc::ReadFooter()
+{
+    char cheadertitle[iHEADERTITLELENGTH];
+    fIn->read(cheadertitle, iHEADERTITLELENGTH);
+    /*
+     ssscanf(cheadertitle, cEND_EVENTS_TEMPLATE,
+             &filterres.ifilter_passed_evts);
+     */
+
+    struct filterresults filterres;
+    fIn->read(&filterres, sizeof(struct filterresults));
+    /*
+     int   imax_alt_arcs;            // maximum altitude reached during the run
+     int   iaz_at_max_alt_arcs;      // azimuth at the time the max. alt. was reached
+     int   itimeaverage_alt_arcs;    // altitude averaged over the runtime
+     int   icoord_inconsist_evts;    // number of events with time-coordinate inconsistency in this run
+     int   ifilter_passed_evts;      // number of events which passed the filter
+     int   imuon_fail_evts;          // number of events rejected as muons (other filters passed)
+     int   i2out_fail_evts;          // number of events which failed in the two out of all pixels software trigger
+     int   imuon_and_2out_fail_evts; // number of events failing in both muon and 2out filter
+     int   isum_fail_evts;           // number of events which failed the sum-of-all-calibrated ADC counts filter
+     int   isum_and_muon_fail_evts;  // number of events which failed in both the sum and the muon filter
+     int   isum_and_2out_fail_evts;  // number of events which failed in both the sum and the 2out filter
+     int   iall_filters_fail_evts;   // number of events which failed in all filters
+     float favg_event_rate_hz;       // average rate before filtering
+     float fstddev_event_rate_hz;    // standard deviation of the rate before filtering
+     */
+}
+
+// --------------------------------------------------------------------------
+//
+// This opens the next file in the list and deletes its name from the list.
+//
+Bool_t MCT1ReadPreProc::OpenNextFile()
+{
+    //
+    // open the input stream and check if it is really open (file exists?)
+    //
+    if (fIn)
+        delete fIn;
+    fIn = NULL;
+
+    //
+    // Check for the existance of a next file to read
+    //
+    TNamed *file = (TNamed*)fFileNames->First();
+    if (!file)
+        return kFALSE;
+
+    //
+    // open the file which is the first one in the chain
+    //
+    const char *name = file->GetName();
+
+    fIn = new ifstream(gSystem->ExpandPathName(name));
+
+    if (!(*fIn))
+    {
+        *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
+        return kFALSE;
+    }
+
+    *fLog << "Open file: '" << name << "'" << endl;
+
+    //
+    // Remove this file from the list of pending files
+    //
+    fFileNames->Remove(file);
+
+    *fLog << inf << "-----------------------------------------------------------------------" << endl;
+    const Int_t sizef = sizeof(struct filterresults)+iHEADERTITLELENGTH;
+    const Int_t sizeh = sizeof(struct outputpars)   +iHEADERTITLELENGTH;
+
+    fIn->seekg(0, ios::end);
+    const Int_t filesize = fIn->tellg();
+
+    fIn->seekg(filesize-sizef, ios::beg);
+    ReadFooter();
+    fIn->seekg(0, ios::beg);
+    ReadHeader();
+
+    struct eventrecord event;
+    const int size1   = sizeof(event)-sizeof(event.spixsig_10thphot);
+    const int size2   = sizeof(event.spixsig_10thphot[0])*fNumPixels;
+    const int evtsize = size1+size2;
+
+    *fLog << "Storage for events: " << filesize-sizef-sizeh << "b" << endl;
+    *fLog << "Size of one Event:  " << evtsize << "b" << endl;
+
+    fNumEvents = (filesize-sizef-sizeh)/evtsize-1;
+    fNumEvent = 0;
+
+    *fLog << "Calculated Number of Events: " << (float)(filesize-sizef-sizeh)/evtsize << " " <<  (filesize-sizef-sizeh)%evtsize << endl;
+
+    *fLog << "-----------------------------------------------------------------------" << endl;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Open the first file in the list. Check for the output containers or create
+// them if they don't exist.
+//
+// Initialize the size of the MPedestalCam container to 127 pixels (CT1 camera)
+//
+Bool_t MCT1ReadPreProc::PreProcess(MParList *pList)
+{
+    //
+    //  look for the MCerPhotEvt class in the plist
+    //
+    fNphot = (MCerPhotEvt*)pList->FindCreateObj("MCerPhotEvt");
+    if (!fNphot)
+        return kFALSE;
+
+    //
+    //  look for the pedestal class in the plist
+    //
+    fPedest = (MPedestalCam*)pList->FindCreateObj("MPedestalCam");
+    if (!fPedest)
+        return kFALSE;
+
+    //
+    //  look for the pedestal class in the plist
+    //
+    fBlinds = (MBlindPixels*)pList->FindCreateObj("MBlindPixels");
+    if (!fBlinds)
+        return kFALSE;
+
+    //
+    //  look for the source position in the camera
+    //
+    fSrcPos = (MSrcPosCam*)pList->FindCreateObj("MSrcPosCam");
+    if (!fSrcPos)
+        return kFALSE;
+
+    //
+    //  look for the camera geometry
+    //
+    fGeom = (MGeomCam*)pList->FindCreateObj("MGeomCamCT1", "MGeomCam");
+    if (!fGeom)
+        return kFALSE;
+
+    //
+    //  look for the mc event class
+    //
+    fMcEvt = (MMcEvt*)pList->FindCreateObj("MMcEvt");
+    if (!fMcEvt)
+        return kFALSE;
+
+    //
+    //  look for the mc trigger class
+    //
+    fMcTrig = (MMcTrig*)pList->FindCreateObj("MMcTrig");
+    if (!fMcTrig)
+        return kFALSE;
+
+    //
+    // Try to open at least one (the first) file
+    //
+    if (!OpenNextFile())
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Analyse the event data, means store and copy the needed data into
+// Mars structures and data members
+//
+void MCT1ReadPreProc::ProcessEvent(const struct eventrecord &event)
+{
+    /*
+     --- USEFULL? NEEDED? ---
+     int   isecs_since_midday; // seconds passed since midday before sunset (JD of run start)
+     int   isecfrac_200ns;     // fractional part of isecs_since_midday
+     short snot_ok_flags;      // the bits in these two bytes are flags for additional information on the event: Everything OK =: all Bits = 0
+     int   ialt_arcs;          // altitude (arcseconds)
+     int   iaz_arcs;           // azimuth (arcseconds)
+     int   ipreproc_alt_arcs;  // "should be" alt according to preproc (arcseconds)
+     int   ipreproc_az_arcs;   // "should be" az according to preproc (arcseconds)
+
+     // for ALT-AZ mount telescopes: rotation angle of the field of
+     // view; this angle is defined mathematically positive looking
+     // towards the sky as the angle between the hour circle through
+     // the object being tracked and the line through pixel 1 and 2
+     int   ifieldrot_arcs;
+
+     // event rate in milli Hertz before filtering calculated by
+     // iratecalc_numevents_odd/(time[i+iratecalc_numevents_odd/2] -
+     // time[i-iratecalc_numevents_odd/2])
+     // For the first and the last iratecalc_numevents_odd/2
+     // events the rate is assumed to be constant
+     unsigned short srate_millihz;
+
+     // This is the angle between the observation of this event and the
+     // culmination point. It is going to be written into the events NTuple.
+     float fhourangle;
+     */
+    /*
+     *fLog << event.isecs_since_midday << "s ";
+     *fLog << event.ialt_arcs << "s ";
+     *fLog << event.iaz_arcs << "s ";
+     *fLog << event.ipreproc_alt_arcs << "s ";
+     *fLog << event.ipreproc_az_arcs << "s ";
+     *fLog << event.ifieldrot_arcs << "s ";
+     *fLog << event.fhourangle << endl;
+     */
+
+    //
+    // read in the number of cerenkov photons and add the 'new' pixel
+    // too the list with it's id, number of photons and error
+    //
+    fNphot->InitSize(fNumPixels);
+
+    // number of photoelectrons measured in each pixel only the
+    // actual number of pixels (outputpars.inumpixels) is written out
+    // short spixsig_10thphot[iMAXNUMPIX];
+    for (Int_t i=0; i<fNumPixels; i++)
+    {
+        if (event.spixsig_10thphot[i]>0)
+            fNphot->AddPixel(i, 0.1*event.spixsig_10thphot[i],
+                             (*fPedest)[i].GetMeanRms());
+    }
+
+    if (!fIsMcFile)
+        return;
+
+    fMcEvt->SetPartId(event.imcparticle);        // corsika particle type
+    fMcEvt->SetEnergy(event.fmcenergy_tev*1000); // simulated energy
+    fMcEvt->SetImpact(event.imcimpact_m*100);    // simulated impact
+
+    fMcTrig->SetFirstLevel(event.imctriggerflag); // MC data from Dorota get a triggerflag: 1 means triggered, 0 not. */
+
+    //float fmcsize_phel;   // Simulated SIZE
+}
+
+// --------------------------------------------------------------------------
+//
+// Check for the event number and depending on this number decide if
+// pedestals or event data has to be read.
+//
+// If the end of the file is reached try to open the next in the list. If
+// there is now next file stop the eventloop.
+//
+Bool_t MCT1ReadPreProc::Process()
+{
+    //
+    // check if we are done. Try to open the next file in chain.
+    // If it was possible start reading. If not break the event loop
+    //
+    if (fNumEvent++==fNumEvents-1)
+        return OpenNextFile() ? kCONTINUE : kFALSE;
+
+    // event data to be read from the file
+    struct eventrecord event;
+
+    const int size1 = sizeof(event)-sizeof(event.spixsig_10thphot);
+    const int size2 = sizeof(event.spixsig_10thphot[0])*fNumPixels;
+
+    // read the eventrecord with the recorded number of stored pixels
+    fIn->read(&event, size1+size2);
+
+    ProcessEvent(event);
+
+    return kTRUE;
+}
+
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1574)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1574)
@@ -0,0 +1,63 @@
+#ifndef MARS_MCT1ReadPreProc
+#define MARS_MCT1ReadPreProc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class TList;
+class MMcEvt;
+class MMcTrig;
+class MGeomCam;
+class MSrcPosCam;
+class MCerPhotEvt;
+class MPedestalCam;
+class MBlindPixels;
+
+struct outputpars;
+struct eventrecord;
+
+class MCT1ReadPreProc : public MTask
+{
+private:
+    ifstream     *fIn;          // the inputfile
+    MGeomCam     *fGeom;        // camera geometry
+    MCerPhotEvt  *fNphot;       // the data container for all data.
+    MPedestalCam *fPedest;      // ct1 pedestals
+    MMcEvt       *fMcEvt;       // monte carlo data container for MC files
+    MMcTrig      *fMcTrig;      // mc data container for trigger information
+    MSrcPosCam   *fSrcPos;      // source position in the camera
+    TList        *fFileNames;   // Array which stores the \0-terminated filenames
+    MBlindPixels *fBlinds;      // Array holding blind pixels
+
+    Int_t fNumPixels;
+    Bool_t fIsMcFile;
+
+    UInt_t fNumEvents;
+    UInt_t fNumEvent;
+
+    Bool_t OpenNextFile();
+
+    void ReadPedestals();
+    void ReadHeader();
+    void ReadFooter();
+    void ProcessHeader(const struct outputpars &outpars);
+    void ProcessEvent(const struct eventrecord &event);
+
+public:
+    MCT1ReadPreProc(const char *filename=NULL,
+                  const char *name=NULL,
+                  const char *title=NULL);
+
+    ~MCT1ReadPreProc();
+
+    void AddFile(const char *fname);
+
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+
+    ClassDef(MCT1ReadPreProc, 0)	// Reads the CT1 data file
+};
+
+#endif
+
Index: /trunk/MagicSoft/Mars/mfileio/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/Makefile	(revision 1573)
+++ /trunk/MagicSoft/Mars/mfileio/Makefile	(revision 1574)
@@ -20,5 +20,5 @@
 # @endcode 
 
-INCLUDES = -I. -I../mbase -I../mraw -I../mmc -I../mdata -I../manalysis
+INCLUDES = -I. -I../mbase -I../mraw -I../mmc -I../mdata -I../manalysis -I../mgeom
 
 # @code 
@@ -37,5 +37,6 @@
            MWriteAsciiFile.cc \
            MWriteRootFile.cc \
-           MCT1ReadAscii.cc
+           MCT1ReadAscii.cc \
+           MCT1ReadPreProc.cc
 
 SRCS    = $(SRCFILES)
Index: /trunk/MagicSoft/Mars/mfileio/defines.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/defines.h	(revision 1574)
+++ /trunk/MagicSoft/Mars/mfileio/defines.h	(revision 1574)
@@ -0,0 +1,788 @@
+/******************************************************************/
+/*              GGG   AAA   M   M M   M  AAA   SSS                */
+/*             G   G A   A  MM MM MM MM A   A S   S               */
+/*             G     A   A  M M M M M M A   A  SS                 */
+/*             G  GG AAAAA  M   M M   M AAAAA   SS                */
+/*             G   G A   A  M   M M   M A   A S   S               */
+/*              GGG  A   A  M   M M   M A   A  SSS                */
+/*       Gamma Astronomer's Munich Madrid Analysis Suite          */
+/*   An Atmospheric Cherenkov Telescope Data Analysis Software    */
+/*  MPI f"ur Physik, M"unchen & Universidad Complutense, Madrid   */
+/******************************************************************/
+
+/******************************************************************/
+/* This File belongs to the programs                              */
+/*                                                                */
+/*  P R E P R O C E S S O R   and   I M A G E R                   */
+/*                                                                */
+/* Purpose: provide the structure definitions common to both      */
+/*          programs, especially the output structures of the     */
+/*          preprocessor                                          */ 
+/*                                                                */
+/******************************************************************/
+
+#ifndef _defines_h_
+#define _defines_h_ "__defines_h__"
+
+#define cIDSTRING(x,y,z) "@(#) GAMMAS "#x" version "#y", date "#z"."
+#define CAT(x,y) #x#y
+#define XCAT(x,y) CAT(x,y)
+
+#define Boolean int
+
+#ifndef TRUE
+#define TRUE 1
+#endif
+#ifndef FALSE
+#define FALSE 0
+#endif
+
+/*************** DEFINES ******************************************/
+
+/* General defines */
+
+#define cHELLOSTRING(x,y) "This is preproc.\nVersion "#x", date "#y"\n\n"
+#define PREPROCVERSIONSTRING(x) "V"#x  
+
+#define dDEG_PER_HOUR 15.
+#define dRAD_PER_DEG 0.0174532925199 /* = 3.14159265359/180. */
+#define dSECS_PER_DAY 86400.
+#define SQUARE(x) ((x) * (x))
+
+/* defines for histograms and ntuple creation */
+
+#define HMAX 2000000 /* memory reserved for pawc common block 
+		     * used by hbook */
+#define DAB -999 /* if a histogramm parameter is to be Defined 
+		  * At Booking enter -999 */
+#define iADCHISTID 1000 /* id of the first histogram for ADC 
+			 * count spectra */
+#define cADCHISTTITLE "Pixel signals before calibration;pixel \
+number;ADC counts"
+#define iADCHIST_BINS 127 /* This is a good guess. bparametersok()
+			   * will look at parameters for the bins 
+			   * in X direction and adjust the other,
+			   * similar histograms acoordingly. */
+#define fADCHIST_LOLIMX 0.5
+#define fADCHIST_HILIMX 127.5 /* For both of them, see above. */
+
+
+
+#define iPHEHISTID 2000 /* id of the first histogram for photo 
+			 *electron spectra */
+#define cPHEHISTTITLE "Pixel signals after calibration;pixel \
+number;photo electrons"
+#define iPHEHIST_BINS 127 /* This is a good guess. bparametersok()
+			   * will look at parameters for the bins 
+			   * in X direction and adjust the other,
+			   * similar histograms acoordingly. */
+#define fPHEHIST_LOLIMX 0.5
+#define fPHEHIST_HILIMX 127.5 /* For both of them, see above. */
+
+#define iPEDONHISTID 12000 /* id of the first histogram for the 
+			    *signals taken in pedestalruns for ON */
+#define iPEDOFHISTID 11000 /* id of the first histogram for the 
+			    *signals taken in pedestalruns for OF */
+#define cPEDONHISTTITLE "Pixel signals from ON pedestal runs;\
+pixel number;ADC Counts"
+#define cPEDOFHISTTITLE "Pixel signals from OF pedestal runs;\
+pixel number;ADC Counts"
+#define iPEDONMEANHISTID 14000 /* id of the first histogram for the 
+				*signals taken in pedestalruns for ON */
+#define iPEDOFMEANHISTID 13000 /* id of the first histogram for the 
+				*signals taken in pedestalruns for OF */
+#define cPEDONMEANHISTTITLE "Pedestal Means from ON pedestal runs;\
+Event Index;ADC Counts"
+#define cPEDOFMEANHISTTITLE "Pedestal Means from OF pedestal runs;\
+Event Index;ADC Counts"
+#define iPEDONJITTHISTID 16000 /* id of the first histogram for the 
+				*signals taken in pedestalruns for ON */
+#define iPEDOFJITTHISTID 15000 /* id of the first histogram for the 
+				*signals taken in pedestalruns for OF */
+#define cPEDONJITTHISTTITLE "Deviation from Pedestal Means from \
+ON pedestal runs;Pixel Number;ADC Counts"
+#define cPEDOFJITTHISTTITLE "Deviation from Pedestal Means from \
+OF pedestal runs;Pixel Number;ADC Counts"
+#define iCALONHISTID 18000 /* id of the first histogram for the 
+			    *signals taken in laserruns for ON */
+#define iCALOFHISTID 17000 /* id of the first histogram for the 
+			    *signals taken in plaserruns for OF */
+#define cCALONHISTTITLE "Pixel signals from ON laser runs;\
+pixel number;ADC Counts"
+#define cCALOFHISTTITLE "Pixel signals from OF laser runs;\
+Pixel Number;ADC Counts"
+#define iCALONMEANHISTID 20000 /* id of the first histogram for the 
+				*signals taken in laserruns for ON */
+#define iCALOFMEANHISTID 19000 /* id of the first histogram for the 
+			    *signals taken in plaserruns for OF */
+#define cCALONMEANHISTTITLE "Laser Means from ON laser runs;\
+Event Index;ADC Counts"
+#define cCALOFMEANHISTTITLE "Laser Means from OF laser runs;\
+Event Index;ADC Counts"
+#define iCALONJITTHISTID 22000 /* id of the first histogram for the 
+				*signals taken in laserruns for ON */
+#define iCALOFJITTHISTID 21000 /* id of the first histogram for the 
+			    *signals taken in plaserruns for OF */
+#define cCALONJITTHISTTITLE "Deviation from Laser Means from \
+ON laser runs;Pixel Number;ADC counts"
+#define cCALOFJITTHISTTITLE "Deviation from Laser Means from \
+OF laser runs;Pixel Number;ADC counts"
+#define iZENONHISTID 200 /* id of the histogram for the zenith 
+			  * angle distribution before filter ON */
+#define iZENOFHISTID 100 /* id of the histogram for the zenith 
+			  * angle distribution before filter OF */
+#define cZENONHISTTITLE "zenith angle distribution before filter \
+ON;zenith angle;number of events ON"
+#define cZENOFHISTTITLE "zenith angle distribution before filter \
+OFF;zenith angle;number of events OFF"
+#define iZENHISTNUMBINS 90
+#define fZENHISTLOLIM 0.
+#define fZENHISTHILIM 90.
+/* defines for noise pickup correction of pedestal (added D.K.)
+ */
+#define iCORRPEDHISTID 400 /* id of histogram for pedestal correction values
+			      (noise pickup) */
+#define cCORRPEDHISTTIT "Pickup Correction;ADC counts;Nr. of Events"
+#define iCPEDFWHMHISTID 410 /* id of the histogram for FWHM of pedestal
+			       correction values (noise pickup) */
+#define cCPEDFWHMHISTTIT "FWHM of Pickup Correction;ADC counts;Nr. of Events"
+#define fMIN_CORRPEDHIST -20.
+#define fMAX_CORRPEDHIST 20.
+#define iCORRPEDHIST_BINS 80
+#define fMIN_CPEDFWHMHIST 0.
+#define fMAX_CPEDFWHMHIST 20
+#define iCPEDFWHMHIST_BINS 40
+#define iBIAS 50             /* is used to make the pedestals peak at 'iBIAS' */
+#define dPEDCORRSIZELIMIT 500. /* maximum event SIZE for which noise-pickup is
+				  corrected */
+/* end: defines for noise pickup correction of pedestal
+ */
+
+/* MKA May 8 2000: Version > 0.4 */
+#define cHISTOFILENAME ".hbook" 
+#define cCALNTFILENAME ".nt.hbook"
+#define cOUTDIRNAME "preproc_out/"
+#define cPROJECTNAME "check"
+#define iCALIBNTUPLE_ID  3
+#define iRECL 1024 /* the record length of the calibration ntuple */ 
+
+#define iPARTNERSEARCHDEPTH 20 /* Default search depth if not specified. */
+/* various parameters */
+
+#ifdef ALPHA
+#define iMAXNUMLASERRUNS 4 /* maximum number of laser runs 
+			    * recorded in one file 
+			    * (90 degrees * 4 minutes/degree / 20 minutes) */
+#endif
+#ifdef LINUX
+#define iMAXNUMLASERRUNS 6 /* maximum number of laser runs 
+			    * recorded in one file 
+			    * (90 degrees * 4 minutes/degree / 20 minutes) */
+#endif
+#define iMAXNUMLASEREVENTS 250 /* maximum number of laser shots
+				* recorded for one laser run */
+#ifdef ALPHA
+#define iMAXNUMPEDRUNS 4 /* maximum number of pedestal runs 
+			   * recorded in one file */
+#endif
+#ifdef LINUX
+#define iMAXNUMPEDRUNS 26 /* maximum number of pedestal runs 
+			   * recorded in one file */
+#endif
+#define iMAXNUMPEDEVENTS 500 /* maximum number of random triggers 
+			      * recorded for one pedestal run */
+#define iMAXNUMRUNEVENTS 40000 /* maximum number of events recorded 
+				* in one run data file */
+#define iNUMRMSFITXBINS 100 /* Bins in the (vector)histogram for the 
+			     * fit of the Pedestal RMS */
+#define iRMSFITXSTRETCH 50 /* strectch of the (vector)histogram for the 
+			     * fit of the Pedestal RMS */
+/* Attention: for iNUMRMSFITXBINS and iRMSFITXSTRETCH the following
+ * requirement must be fulfilled:
+ * A width of 1 must be achieveble as an integer multiple of the
+ * binwidth, i.e. 5 or 6 times (iRMSFITXSTRETCH/iNUMRMSFITXBINS) must
+ * make up 1. */
+
+#define iRMSFITXOFFSET 2 /* half a bin offset to the left: Start a bin 
+			 * with center at 0 at 1./2. binwidth earlier */
+
+#define iMAXFILENAMELENGTH 400
+/* general limit on the length of filename strings (including path) */ 
+#define iMAXNUMDIRENTRIES 1028 /* MKA: Nonsens to limit this; we 
+				* rewrite this in the future. 
+				* Make a chained list and allocate
+				* memory for it dynamically. Free
+				* this memory afterwards. 
+				* Put on to-do-list Nov 6 1999 */
+/* the maximum number of filenames expected in a directory to 
+ * be read by ireaddir() */
+#define cDIRFILENAME "preproc.dir" 
+/* intermediate file used by ireaddir() */
+#define iMAXNUMCALFILEOFFSET 400 /* That is the number of Runs, which 
+				  * is searched back to find a TelCal 
+				  * file for analysis. */
+
+#define iMAXNUMPEDFILEOFFSET 400 /* That is the number of Runs, which 
+				  * is searched back to find a TelPed 
+				  * file for analysis. */ 
+
+#define iMAXNUMTELLOGFILEOFFSET 400 /* That is the number of Runs, which 
+				     * is searched back to find a TelLog 
+				     * file for analysis. */
+
+/* keywords, numbers of arguments, values and ranges of values 
+   which define the syntax in the parameters file
+   
+   in order to introduce a new input parameter, you have to 
+   a) increase iNUMKEYWORDS
+   b) #define the keyword (cKEYWORDXX), the format for the 
+      arguments (cKEYWORDXXARG)
+      the number of arguments (iKEYWORDXXNUMARG), 
+      the minimum and maximum value 
+      (iMIN..., iMAX...) for numerical arguments
+   c) for enum-type arguments look at keywords 10 or 11 to see 
+      what to #define
+      (iKEYWORDXXARGYNUMVAL = the number of values the arguments 
+      no. Y of keyword no. XX can take, 
+      cKEYWORDXXARGYVALS  = enumeration of the different values 
+      (strings) the argument can have
+   d) put entries into the initialization of the arrays ckeyword, 
+      ckeywordarg, ikeywordnumarg, fargvalmin, fargvalmax, and 
+      for enum-type arguments declare a new array keywordXXvalues 
+      as for keywords 10 and 11
+   e) include the new parameter into the structure inputpars, 
+      and, if you wish to, in outputpars also.
+   f) add the corresponding case to the switch(k) statement in main()
+   g) modify bparametersok(), bprintinputpars() and 
+      vsetinputparsunfilled()
+   h) program the transfer of the parameter from inputpars to 
+      outputpars if necessary
+      .... to be continued  */
+
+
+#define iNUMKEYWORDS 46  /* the number of different kewords 
+			  * defined for use in the
+                          * parameters file */
+
+#define cKEYWORD01                "iTELESCOPE"
+/* keyword no. 1, this keyword must have this number, don't change it */
+#define cKEYWORD01ARG             "%d"
+#define iKEYWORD01NUMARG 1 /* number of arguments */
+#define iMINTELESCOPEID 1 /* minimum value */
+#define iMAXTELESCOPEID 2 /* maximum value */
+
+#define cKEYWORD02                "iRUNNUM"
+/* keyword no. 2, this keyword must have this number, don't change it */
+#define cKEYWORD02ARG             "%d"
+#define iKEYWORD02NUMARG 1
+#define iMINRUNNUM 0 /* minimum value */
+#define iMAXRUNNUM 99999 /* maximum value */
+
+#define cKEYWORD03                "inumpixels"
+/* keyword no. 3 */
+#define cKEYWORD03ARG             "%d"
+#define iKEYWORD03NUMARG 1
+#define iMINNUMPIX 37 /* minimum value for the number of camera 
+		       * pixels (excl. muon shield) */
+/* #define iMAXNUMPIX ..  maximum value defined in structures.h */
+
+#define cKEYWORD04                "fpixdiameter_deg"
+/* keyword no. 4 */
+#define cKEYWORD04ARG             "%f"
+#define iKEYWORD04NUMARG 1
+#define fMINPIXDIA_DEG 0.1 /* minimum value */
+#define fMAXPIXDIA_DEG 1.0 /* maximum value */
+
+#define cKEYWORD05                "ise1zeropos"
+/* keyword no. 5 */
+#define cKEYWORD05ARG             "%d"
+#define iKEYWORD05NUMARG 1
+#define iMINSE1POS 0 /* minimum value */
+#define iMAXSE1POS 50000 /* maximum value */
+
+#define cKEYWORD06                "ise2zeropos"
+/* keyword no. 6 */
+#define cKEYWORD06ARG             "%d"
+#define iKEYWORD06NUMARG 1
+#define iMINSE2POS 0 /* minimum value */
+#define iMAXSE2POS 50000 /* maximum value */
+
+#define cKEYWORD07               "idontusepix"
+/* keyword no. 7 */
+#define cKEYWORD07ARG             "%d"
+#define iKEYWORD07NUMARG 1 
+#define iMINPIXNUM 1 /* in the parameters file counting of the 
+		      * pixels starts at 1 */
+/* maximum value of this parameter is iMAXNUMPIX */
+/* negative parameters in the range -iMINPIXNUM to -iMAXNUMPIX 
+ * are also allowed: */
+/* they switch the pixel back on */
+
+#define cKEYWORD08               "isum_thresh_phot"
+/* keyword no. 8 */
+#define cKEYWORD08ARG             "%d"
+#define iKEYWORD08NUMARG 1
+#define iMINSUMTHRESH_PHOT 0 /* minimum value */
+#define iMAXSUMTHRESH_PHOT 65536 /* maximum value */
+
+#define cKEYWORD09              "i2out_thresh_phot"
+/* keyword no. 9 */
+#define cKEYWORD09ARG             "%d"
+#define iKEYWORD09NUMARG 1
+#define iMIN2OUTTHRESH_PHOT 0 /* minimum value */
+#define iMAX2OUTTHRESH_PHOT 65536 /* maximum value */
+
+#define cKEYWORD10               "usecalfile"
+/* keyword no. 10 */
+#define cKEYWORD10ARG             "%s %d %d"
+#define iKEYWORD10NUMARG 3 /* first arg: search direction, 
+			    * second arg: end of search or
+			    * search depth in case of 
+			    * pingpong method */
+#define iKEYWORD10ARG1NUMVAL 5
+#define cKEYWORD10ARG1VALS "match", "before", "after", "pingpong", "none"
+/* minimum and maximum value of the second argument are 
+ * identical with iMINRUNNUM and iMAXRUNNUM */
+
+#define cKEYWORD11               "usepedfile"
+/* keyword no. 11 */
+#define cKEYWORD11ARG             "%s %d %d"
+#define iKEYWORD11NUMARG 3 /* first arg: search direction,
+			    * second arg: end of search or
+			    * search depth in case of 
+			    * pingpong method */
+#define iKEYWORD11ARG1NUMVAL 5
+#define cKEYWORD11ARG1VALS "match", "before", "after", "pingpong", "none"
+/* minimum and maximum value of the second argument are 
+ * identical with iMINRUNNUM and iMAXRUNNUM */
+
+#define cKEYWORD12                "inummuonpixels"
+/* keyword no. 12 */
+#define cKEYWORD12ARG             "%d"
+#define iKEYWORD12NUMARG 1
+#define iMINNUMMUONPIX 0 /* minimum value */
+/* #define iMAXNUMMUONPIX ..  maximum value defined in structures.h */
+
+#define cKEYWORD13                "inumcointdcs"
+/* keyword no. 13 */
+#define cKEYWORD13ARG             "%d"
+#define iKEYWORD13NUMARG 1
+#define iMINNUMCOINTDCS 0 /* minimum value */
+/* #define iMAXNUMCOINTDCS ..  maximum value defined in structures.h */
+
+#define cKEYWORD14                "fphotoel_per_adccnt"
+/* keyword no. 14 */
+#define cKEYWORD14ARG             "%s %f"
+#define iKEYWORD14NUMARG 2
+#define fMINPHOTOEL_PER_ADCCNT 0.1 /* minimum value for the 
+				    * second argument */
+#define fMAXPHOTOEL_PER_ADCCNT 999.0 /* maximum value for the 
+				      * second argument */
+/* as first argument either a single integer number or a 
+ * range may be given (format: e.g. 10-20) minimum and 
+ * maximum value of the first argument are identical with 
+ * iMINPIXNUM and the number of pixels in the camera */
+
+#define cKEYWORD15               "bmuon_suppression"       
+/* keyword no. 15 */
+#define cKEYWORD15ARG             "%s"
+#define iKEYWORD15NUMARG 1 /* this keyword is a switch */
+#define iKEYWORD15ARG1NUMVAL 2
+#define cKEYWORD15ARG1VALS "off", "on" /* the order of this 
+					* enumeration is essential 
+					* to make off equivalent 
+					* to FALSE */
+
+#define cKEYWORD16                "ftolerated_pointerror_deg"
+/* keyword no. 16 */
+#define cKEYWORD16ARG             "%f"
+#define iKEYWORD16NUMARG 1
+#define fMINTOLERATED_POINTERROR_DEG 0. /* minimum value for 
+					 * the maximum tolerated 
+					 * pointing error in the 
+					 * position check in 
+					 * iprocessdata */
+#define fMAXTOLERATED_POINTERROR_DEG 180. /* maximum value */
+
+#define cKEYWORD17                "iratecalc_numevents_odd"
+/* keyword no. 17 */
+#define cKEYWORD17ARG             "%d"
+#define iKEYWORD17NUMARG 1
+#define iMINRATECALC_NUMEVENTS_ODD 3 /* minimum value for the 
+				      * number of events used 
+				      * in the event rate 
+				      * calculation */
+#define iMAXRATECALC_NUMEVENTS_ODD 999 /* maximum value */
+
+#define cKEYWORD18                "fdegrees_per_step1"
+/* keyword no. 18 */
+#define cKEYWORD18ARG             "%f"
+#define iKEYWORD18NUMARG 1
+#define fMINDEGREES_PER_STEP 0.0001 /* minimum value for the 
+				     * resolution of shaft encoder 1 */
+#define fMAXDEGREES_PER_STEP 0.1 /* maximum value */
+
+#define cKEYWORD19                "fdegrees_per_step2"
+/* keyword no. 19 */
+#define cKEYWORD19ARG             "%f"
+#define iKEYWORD19NUMARG 1
+/* minimum and maximum values as for keyword 18 */
+
+#define cKEYWORD20               "se1_is"
+/* keyword no. 20 */
+#define cKEYWORD20ARG             "%s"
+#define iKEYWORD20NUMARG 1 
+#define iKEYWORD20ARG1NUMVAL 4
+#define cKEYWORD20ARG1VALS "RA", "DEC", "ALT", "AZ"
+
+#define cKEYWORD21                "flongitude_deg"
+/* keyword no. 21 */
+#define cKEYWORD21ARG             "%f"
+#define iKEYWORD21NUMARG 1
+#define fMIN_LONG_DEG 0. /* minimum value for the longitude 
+			  * of the telescope position */
+#define fMAX_LONG_DEG 359.99999 /* maximum value (the 
+				 * longitude is counted 
+				 * positive towards West */
+
+#define cKEYWORD22                "flatitude_deg"
+/* keyword no. 22 */
+#define cKEYWORD22ARG             "%f"
+#define iKEYWORD22NUMARG 1
+#define fMIN_LAT_DEG  -90.0 /* minimum value for the latitude 
+			     * of the telescope position */
+#define fMAX_LAT_DEG +90.0 /* maximum value */
+
+#define cKEYWORD23                "irubminusutc_usecs"
+/* keyword no. 23 */
+#define cKEYWORD23ARG             "%d"
+#define iKEYWORD23NUMARG 1
+#define iMINRUBMINUSUTC_USECS -60E6 /* minimum value for the 
+				     * time difference between 
+				     * rubidium clock and UTC*/
+#define iMAXRUBMINUSUTC_USECS 60e6 /* maximum value */
+
+#define cKEYWORD24                "iaz_rev_track_corr"
+/* keyword no. 24 */
+#define cKEYWORD24ARG             "%d"
+#define iKEYWORD24NUMARG 1
+#define iMINAZ_REV_TRACK_CORR -1000 /* minimum value for the 
+				     * correction of the az 
+				     * shaft encoder values 
+				     * in reverse tracking mode
+				     * see Calc_corr in TIJARAFE */
+#define iMAXAZ_REV_TRACK_CORR 1000 /* maximum value */
+
+#define cKEYWORD25                "ialt_rev_track_corr"
+/* keyword no. 25 */
+#define cKEYWORD25ARG             "%d"
+#define iKEYWORD25NUMARG 1
+#define iMINALT_REV_TRACK_CORR -1000 /* minimum value for the 
+				      * correction of the alt 
+				      * shaft encoder values 
+				      * in reverse tracking mode
+				      * see Calc_corr in TIJARAFE */
+#define iMAXALT_REV_TRACK_CORR 1000 /* maximum value */
+
+#define cKEYWORD26                "fbendingcorr"
+/* keyword no. 26 */
+#define cKEYWORD26ARG             "%f"
+#define iKEYWORD26NUMARG 1
+#define fMINBENDINGCORR  -0.5 /* minimum value for the bending 
+			       * correction factor for the alt 
+			       * shaft encoder values
+			       * see Calc_corr in TIJARAFE */
+#define fMAXBENDINGCORR 0.5 /* maximum value */
+
+#define cKEYWORD27                "fextinction"
+/* keyword no. 27 */
+#define cKEYWORD27ARG             "%f"
+#define iKEYWORD27NUMARG 1
+#define fMINEXTINCTION  0. /* minimum value for the 
+			    * atmospheric extinction */
+#define fMAXEXTINCTION  1. /* maximum value */
+
+#define cKEYWORD28                "dsource_ra_hours"
+/* keyword no. 28 */
+#define cKEYWORD28ARG             "%lf"
+#define iKEYWORD28NUMARG 1
+#define fMINRA_HOURS 0.0   /* minimum value for the right 
+			    * ascension of the assumed source */
+#define fMAXRA_HOURS 23.99999999 /* maximum value */
+
+#define cKEYWORD29                "dsource_dec_deg"
+/* keyword no. 29 */
+#define cKEYWORD29ARG             "%lf"
+#define iKEYWORD29NUMARG 1
+#define fMINDEC_DEG -90.0 /* minimum value for the 
+			   * declination of the assumed source */
+#define fMAXDEC_DEG 90.0        /* maximum value */
+
+#define cKEYWORD30                "imuoncut_thresh_adccnt"
+/* keyword no. 30 */
+#define cKEYWORD30ARG             "%s %d"
+#define iKEYWORD30NUMARG 2
+#define iMINMUONCUT_THRESH_ADCCNT 0 /* minimum value for the 
+				     * second argument */
+#define iMAXMUONCUT_THRESH_ADCCNT 65536 /* maximum value for 
+					 * the second argument */
+/* as first argument either a single integer number or a 
+ * range may be given (format: e.g. 3-5) minimum and maximum 
+ * value of the first argument are the number of pixels in 
+ * the camera +1 and the number of pixels in the camera + 
+ * the number of muonpixels in the camera */
+
+#define cKEYWORD31                "fxpointcorr_deg"
+/* keyword no. 31 */
+#define cKEYWORD31ARG             "%f"
+#define iKEYWORD31NUMARG 1
+#define fMINRAPOINTERROR_DEG -10. /* minimum value for the 
+				   * pointing error correction 
+				   * along camera x axis as known 
+				   * from e.g. a pointrun */
+#define fMAXRAPOINTERROR_DEG +10. /* maximum value */
+
+#define cKEYWORD32                "fypointcorr_deg"
+/* keyword no. 32 */
+#define cKEYWORD32ARG             "%f"
+#define iKEYWORD32NUMARG 1
+#define fMINDECPOINTERROR_DEG -10. /* minimum value for the 
+				    * pointing error correction 
+				    * along camera y axis as known 
+				    * from e.g. a pointrun */
+#define fMAXDECPOINTERROR_DEG +10. /* maximum value */
+
+#define cKEYWORD33                "fcamera_align_angle_deg"
+/* keyword no. 33 */
+#define cKEYWORD33ARG             "%f"
+#define iKEYWORD33NUMARG 1
+#define fMINCAMALIGNANGLE_DEG -180. /* minimum value for the 
+				     * angle between the camera 
+				     * y-axis and the meridian 
+				     * when a culminating object
+				     * is observed (defined 
+				     * counter-clockwise looking 
+				     * at the sky) */
+#define fMAXCAMALIGNANGLE_DEG 180. /* maximum value */
+
+#define cKEYWORD34               "bhistograms"
+/* keyword no. 34 */
+#define cKEYWORD34ARG             "%s"
+#define iKEYWORD34NUMARG 1 /* this keyword is a threefold switch */
+#define iKEYWORD34ARG1NUMVAL 3
+#define cKEYWORD34ARG1VALS "off", "on", "new" /* the order of this 
+					       * enumeration is 
+					       * essential to make 
+					       * off equivalent to FALSE */
+
+#define cKEYWORD35                "iadc_histopars"
+/* keyword no. 35 */
+#define cKEYWORD35ARG             "%d %f %f"
+#define iKEYWORD35NUMARG 3
+#define iMINBINS 3
+#define iMAXBINS 300
+#define fMIN_ADCHIST_LOLIM -50.5
+#define fMAX_ADCHIST_LOLIM 1000.
+#define fMIN_ADCHIST_HILIM 0.5
+#define fMAX_ADCHIST_HILIM 65535.5
+
+#define cKEYWORD36                "iphe_histopars"
+/* keyword no. 36 */
+#define cKEYWORD36ARG             "%d %f %f"
+#define iKEYWORD36NUMARG 3
+#define fMIN_PHEHIST_LOLIM -10000.
+#define fMAX_PHEHIST_LOLIM 1000.
+#define fMIN_PHEHIST_HILIM -1000.
+#define fMAX_PHEHIST_HILIM 10000.
+
+#define cKEYWORD37                "idontusepix_in_trig"
+/* keyword no. 37 */
+#define cKEYWORD37ARG             "%s"
+#define iKEYWORD37NUMARG 1    /* in the parameters file 
+			       * counting of the pixels starts at 1
+                              * minimum value is iMINPIXNUM 
+                              * maximum value of this parameter 
+			      * is iMAXNUMPIX the pixel can only be 
+			      * taken back into trigger by resetting all
+                              * parameters */
+
+#define cKEYWORD38                "fpadlevel_phot_pix"
+/* keyword no. 38 */
+#define cKEYWORD38ARG             "%s %f"
+#define iKEYWORD38NUMARG 2
+#define fMINPADLEVEL_PHOT  0. /* minimum value for the software 
+			       * padding level for each pixel */
+#define fMAXPADLEVEL_PHOT  100. /* maximum value */
+
+#define cKEYWORD39                "frandomseeds"
+/* keyword no. 39 */
+#define cKEYWORD39ARG             "%f %f "
+#define iKEYWORD39NUMARG 2
+#define fMINSEED 1. /* minimum value for the maximum tolerated 
+		     * pointing error in the position check in 
+		     * iprocessmcdata */
+#define fMAXSEED 1.e10 /* maximum value */
+
+#define cKEYWORD40                "iswap_pixels"
+/* keyword no. 40 */
+#define cKEYWORD40ARG             "%d %d " /* the number of the 
+					    * two pixels for which 
+					    * the numbering should 
+					    * be swapped (in 
+					    * ireadrunfile, 
+					    * -pedfile, -calfile) */
+#define iKEYWORD40NUMARG 2
+/* the minimum value for this argument is iMINPIXNUM, the maximum 
+ * is iMAXNUMPIX */
+
+#define cKEYWORD41                "%"
+/* keyword no. 41 */
+#define cKEYWORD41ARG             "\n" /* using this keyword, 
+					* comments can be added 
+					* to the parameter file */
+#define iKEYWORD41NUMARG 0
+
+#define cKEYWORD42           "errortolerance"
+/* keyword no. 42 */
+#define cKEYWORD42ARG        "%s"
+#define iKEYWORD42NUMARG 1
+#define iKEYWORD42ARG1NUMVAL 3
+#define cKEYWORD42ARG1VALS "cautious", "goodphysics", "tank"
+/* cautious: exits on any reason 
+ * normal: the usual way: exit only, when the physics would 
+ *         be affected
+ * tank: exits only when all runs are processed. Otherwise
+ *       it goes through everything, even through the pain of 
+ *       a coredump. */
+
+#define cKEYWORD43           "montecarlo"
+/* keyword no. 43 */
+#define cKEYWORD43ARG        "%s"
+#define iKEYWORD43NUMARG 1
+#define iKEYWORD43ARG1NUMVAL 3
+#define cKEYWORD43ARG1VALS "all", "flag", "noflag"
+/* Whenever this one is specified, there shell apply certain 
+ * limitations: No pedestal and calibration files shall be read in. 
+ * Maybe more.... 
+ * Arguments:
+ * all: all events which survive the filter are written to the 
+ *      events NTuple. 
+ * flag: When Dorota's triggerflag is set to 1 for a particular
+ *       event, it shall be written to the output. All others shall
+ *       just be disregarded.
+ * noflag: Opposite of 'flag': only events with triggerflag = 0 shall
+ *         be treated further. */
+
+#define cKEYWORD44           "mcfile"
+/* keyword no. 44 */
+#define cKEYWORD44ARG        "%s"
+#define iKEYWORD44NUMARG 1
+
+#define cKEYWORD45           "fmean_nsb_pe_pix"
+/* keyword no. 45 */
+#define cKEYWORD45ARG             "%s %f"
+#define iKEYWORD45NUMARG 2
+#define fMIN_NSB_PE_PIX  0.
+#define fMAX_NSB_PE_PIX  2000000000. /* some ridiculous number...*/
+
+#define cKEYWORD46           "fitmypedrms"
+/* keyword no. 46 */
+/* Setting this keyword in the parameterfile shall trigger the 
+ * pedestal MEAN and SIGMA=sqrt(MEAN) to be fitted from pickup
+ * corrected pedestal data and not calculated from the pickup 
+ * corrected ADC values, as it was done up to ~November 2000. */
+
+/* Macintosh variable formats */
+#define lMACSIZEOFSHORT  2L
+#define lMACSIZEOFLONG   4L
+#define lMACSIZEOFDOUBLE 8L
+
+/* Time Offsets */
+#define iMACTIMEOFFSET 2082844800 /* offset to be subtracted 
+				   * from the Macintosh time 
+				   * read from the various data 
+				   * files to get DECSTATION/ALPHA 
+				   * time */
+
+/* TIJARAFE filename conventions */
+
+#define cCALFILENAME_TEMPLATE "Te%1sCal_*%s_%2s_*"
+#define cLOGFILENAME_TEMPLATE "Te%1sLog_*%s_%2s_*"
+#define cPEDFILENAME_TEMPLATE "Te%1sPed_*%s_%2s_???????_*"
+#define cRUNFILENAME_TEMPLATE "Te%1sRun_*%s_%2s_*"
+#define cPOIFILENAME_TEMPLATE "Te%1sPoi_*%s_%2s_*"
+#define cCTIDPOSITION_TIJ "2" /* element of the filename character 
+			   * array which contains the telescope id
+			   * a length of 1 character is assumed */
+#define cRUNNUMPOSITION_TIJ "7" /* element of the filename character 
+			     * array which contains the run number */
+#define cRUNNUMLENGTH_TIJ "4" /* number of characters in the run number */
+#define cRUNTYPEPOSITION_TIJ "12" /* element of the filename character 
+			       * array which contains the ON or OF 
+			       * string a length of 2 characters is 
+			       * assumed */
+#define iTIJ_DUMMYLENGTH 20
+
+/* ROBERTO filename conventions */
+
+#define cCTIDPOSITION_ROB "2" /* element of the filename character 
+			       * array which contains the telescope id
+			       * a length of 1 character is assumed */
+#define cRUNNUMPOSITION_ROB "7" /* element of the filename character 
+				 * array which contains the run number */
+#define cRUNNUMLENGTH_ROB "5" /* number of characters in the run number */
+#define cRUNTYPEPOSITION_ROB "13" /* element of the filename character 
+				   * array which contains the ON or OF 
+				   * string a length of 2 characters is 
+				   * assumed */
+#define iROB_DUMMYLENGTH 26
+
+/* Razmick's Method's F Factor for the PMTs: */
+/* #define FIXED_F_VALUE 1.09 */
+/* #define FIXED_F_VALUE 1.15 */
+#define FIXED_F_VALUE 1.075
+
+/* Monte Carlo defines, that _MUST_ be exactly the same as in
+ * zorp's defines.h. */
+#define iMAXNUMCTS 1
+#define iNUMENERGYBINS 19
+#define iNUMIMPACTBINS 60
+#define iNUMZENANGLEBINS 24
+#define iMAXNUMNFLSHIFTS 1
+#define fMAXIMPACTPAR 600.
+
+/* exit codes */
+
+#define iERRORINPROCESSDATA 100
+#define iERRORINMAKEFILENAME 101
+#define iERRORCT2TRACKMODE 102
+#define iERRORGAINZERO 103
+
+/*************** GLOBAL VARIABLES *********************************/
+
+#define FILEHANDLING_VERSION 4.2
+
+#endif
+
+#ifdef _defines_h_
+
+extern char G_cfilehandlingident[];
+extern char G_filehandhfilehident[];
+
+extern char G_cfatalerrortext[22];
+extern Boolean G_bhbook_is_init;
+extern float G_fpreprocversion;
+extern char G_preprocident[];
+extern char G_preprocstrucident[];
+extern char G_preprocfilehident[];
+
+extern char *calnt_var_list[22];
+extern char cprojectname[40];
+
+extern HBOOK_FILE calnt;
+extern HBOOK_FILE calhb;
+extern int G_oferfloweventID;
+extern int G_oferfloweventoffset;
+extern float pixcoords[271][2]; /* For the 2-dim camera pictures of the 
+				 * overflow events */
+#endif
Index: /trunk/MagicSoft/Mars/mfileio/structures.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/structures.h	(revision 1574)
+++ /trunk/MagicSoft/Mars/mfileio/structures.h	(revision 1574)
@@ -0,0 +1,878 @@
+/******************************************************************/
+/*              GGG   AAA   M   M M   M  AAA   SSS                */
+/*             G   G A   A  MM MM MM MM A   A S   S               */
+/*             G     A   A  M M M M M M A   A  SS                 */
+/*             G  GG AAAAA  M   M M   M AAAAA   SS                */
+/*             G   G A   A  M   M M   M A   A S   S               */
+/*              GGG  A   A  M   M M   M A   A  SSS                */
+/*       Gamma Astronomer's Munich Madrid Analysis Suite          */
+/*   An Atmospheric Cherenkov Telescope Data Analysis Software    */
+/*  MPI f"ur Physik, M"unchen & Universidad Complutense, Madrid   */
+/******************************************************************/
+
+/******************************************************************/
+/* This File belongs to the programs                              */
+/*                                                                */
+/*  P R E P R O C E S S O R   and   I M A G E R                   */
+/*                                                                */
+/* Purpose: provide the structure definitions common to both      */
+/*          programs, especially the output structures of the     */
+/*          preprocessor                                          */ 
+/*                                                                */
+/******************************************************************/
+
+/******************************************************************/
+/* @(#) File name structures.h
+   @(#) latest SID 0.5  
+   @(#) Date of latest delta 26/6/00  
+   Author: D. Petry 
+   changed by M. Kestel */
+/******************************************************************/
+
+#ifndef _structures_h_
+#define _structures_h_ "__structures_h__"
+
+#define STRUCT_VERSION 0.5
+
+#define iHEADERTITLELENGTH 60
+/* length of the string written at the beginning of the */
+/* output for each runfile */
+#define cTITLE_TEMPLATE "PREPROC V%f/S%f CT %d RUN %d %d PROCMJD %d\n"
+
+#define cEND_EVENTS_TEMPLATE "EVENTS AFTER FILTER = %d\n"
+
+#define iMAXNUMPIX 127
+/* maximum value for the number of camera pixels (excl. muon shield) */
+#define iMAXNUMMUONPIX 5 
+/* maximum value for the number of pixels in the muon shield */
+#define iMAXNUMCOINTDCS 5
+/* maximum value for the number of coincidence tdcs */
+
+
+#define iBADMACTIME_BIT 1
+/* snot_ok_flags is ORed with this number to set the bit which 
+ * indicates that the mactime measurement didn't work */
+#define iBADRUBTIME_BIT 2 
+/* snot_ok_flags is ORed with this number to set the bit which 
+ * indicates that the Rubidium time measurement didn't work */
+#define iBADPOINTING_BIT 4 
+/* snot_ok_flags is ORed with this number to set the bit which 
+ * indicates that the shaft encoder values were inconsistent with 
+ * time OR source coordinates */
+#define iMUON_BIT 8
+ /* snot_ok_flags is ORed with this number to set the bit which 
+  * indicates that the event didn't pass the muon filter 
+  * (for test puposes) */
+
+#define i2OUTFAIL_BIT 16 
+/* snot_ok_flags is ORed with this number to set the bit which 
+ * indicates that the event didn't pass the "two out of all" 
+ * software trigger */
+#define iSUMFAIL_BIT 32 
+/* snot_ok_flags is ORed with this number to set the bit which
+ * indicates that the event didn't pass the "sum of all
+ * photoelectrons" filter */
+
+#define iPARTICLETYPE_FACTOR 1024 
+/* for MC data: the particle type multiplied with this number 
+ * is ORed with snot_ok_flags */
+
+enum onoroff {NEITHER_ON_NOR_OFF, OFF_SOURCE, ON_SOURCE};
+enum trackmodes {NORMAL, REVERSE, DUNNO};
+enum axes {RA, DEC, ALT, AZ};
+enum eERRORTOLERANCE {CAUTIOUS=0, GOODPHYSICS, TANK};
+enum eMCTRIGGERFLAG {ALL=0, FLAG, NOFLAG};
+ 
+struct outputpars {
+  /* preprocessing parameters that are passed to imager.
+   * Note: Not all parameters from the parameter file are passed to
+   * imager, only those that are repeated in this struct outputpars 
+   * here !! That's why these two structs must be the same for both
+   * preproc and imager. */
+
+  int     itelescope;
+  /* number of the CT which took the data (from parameters file */
+  /* crosschecked with run file name) */
+  float   flongitude_deg;
+  /* longitude (counted positive towards West) of CT position */
+  float   flatitude_deg;
+  /* latitude (counted positive towards North) of CT position */
+  int     irunnum;
+  /* run number (from parameters file cross checked with run */
+  /* file name) */
+  enum onoroff eruntype;
+  /* indicates if the */
+  /* run is on- or off source (from runfile cross checked with */
+  /* file name) */
+  double  dsourcera_hours;
+  /* right ascension of observed source in hours */
+  double  dsourcedec_deg; 
+  /* declination of observed source in degrees */
+  int     inumpixels; 
+  /* number of pixels in the camera (from parameters file cross */
+  /* checked with run file, calibration file and pedestal file) */
+  int     inummuonpixels;
+  /* number of pixels in the muon shield (from parameters file */
+  /* cross checked with run file, calibration file and pedestal */
+  /* file) */
+  int     inumcointdcs;
+  /* number of coincidence tdcs recorded in the runfile (from */
+  /* parameters file cross checked */
+  /* with run file) */
+  float   fpixdiameter_deg;
+  /* smallest pixel diameter (degrees) (from parameters file) */ 
+  axes ese1_is;
+  /* name of the axis to which shaft encoder 1 is attached */
+  /* (implies the type of mount) */
+  int     isezeropos[2];
+  /* zero position of shaftencoders 1 and 2 (from parameters file) */
+  int     iaz_rev_track_corr;
+  /* correction for the azimuth shaft encoder (ALT/AZ mount */
+  /* only) in reverse tracking mode */
+  int     ialt_rev_track_corr;
+  /* correction for the altitude shaft encoder (ALT/AZ mount */
+  /* only) in reverse tracking mode */
+  float   fbendingcorr;
+  /* bending correction factor (ALT/AZ mount only) */
+  float   fextinction;
+  /* atmospheric extinction (typically taken from the Carlsberg */
+  /* Meridian Circle data) */
+  Boolean bdontusepix[iMAXNUMPIX];
+  /* bdontusepix is set true if the pixel should due to whatever
+   * reason not be used in image analysis, otherwise it is true; 
+   * 
+   * bdontusepix is set by the user inside preproc.par and is 
+   * untouched by preproc (version >= 0.4). */
+  Boolean bexcludepix[iMAXNUMPIX];
+  /* bexcludepix[] is set TRUE (== exclude from pedestal, Laser 
+   * calibration and the further analysis) when the Mean value
+   * of a pixel inside a pedestal Run is larger than 50 or ( || )
+   * if the pedestal RMS value of this pixel is larger than 5.0
+   * This is reflected in the (new for versions >= 0.4) 
+   * variable "pixonoff" in the ntuple written by preproc:
+   * preproc.nt.hbook
+   *
+   * When the pixel is excluded by the user it will get a -2 otherwise 
+   * pixonoff = 0.
+   * Additive to this a -1 is added when preproc excludes the pixel
+   * for a given Run. So the actual value tells you whether you caught 
+   * it already by hand or not.
+   *
+   * A plot of pixonoff may also be handy to tell you the status of your
+   * ADC equipment. */
+  float   fphotoel_per_adccnt[iMAXNUMPIX];
+  /* conversion factors for the pixel signals */
+  int     irubminusutc_usecs;
+  /* difference between rubidium clock and UTC in microseconds */
+  int     isum_thresh_phot;
+  /* threshold for the total sum of photoelectrons filter */
+  /* from the parameters file */
+  int     i2out_thresh_phot;
+  /* threshold for the two-pixels-out-of-all software */
+  /* trigger from parameters file */
+  int     imuoncut_thresh_adccnt[iMAXNUMMUONPIX]; 
+  /* thresholds for the muon cut */
+  Boolean bmuon_suppression;
+  /* "Dolby" noise reduction flag */
+  float   ftolerated_pointerror_deg;
+  /* maximum tolerated pointing error in the position 
+   * check in iprocessdata */
+  float   fxpointcorr_deg;
+  /* pointing correction (to be added along the camera
+   * x axis) e.g. from point run */ 
+  float   fypointcorr_deg;  
+  /* pointing correction (to be added along the camera 
+   * y axis) e.g. from point run */ 
+  float   fcamera_align_angle_deg;
+  /* the angle between the camera y-axis and the meridian 
+   * when a culminating object is observed (defined 
+   * counter-clockwise looking at the sky) */ 
+  int     iratecalc_numevents_odd;
+  /* number of events used in the rate calculation (must be odd) */
+  int     inumpedfile;
+  /* number of the pedestal file used */
+  int     inumpedrun;
+  /* number of the pedestal run used in the file (starting at 0) */
+  int     inumcalfile;
+  /* number of the calibration file used */
+  int     inumlaserrun;
+  /* number of the laserrun used in the file (starting at 0) */ 
+  int     inumtellogfile;
+  /* number of the TelLog file to be used */
+  int     inumtellogrun;
+  /* number of the tellog entry (Runnumber) used from the log file */
+  int imcparticle; /* CORSIKA-coded Monte Carlo particle type.
+		    * This is given once per run. */
+
+  /* preprocessing results: */
+
+  int     istart_mjdate_day;
+  /* MJD of run start (first event) */
+  int     iend_mjdate_day;
+  /* MJD of run end (last event) */
+  int     irunduration_secs;
+  /* difference between start and end time (secs) */
+  int     iproc_mjdate; 
+  /* MJD of data processing (i.e. creation of this file) */ 
+  enum trackmodes etrackmode;
+  /* tracking mode (for ALT/AZ CTs) */
+  int     iproc_evts;
+  /* number of events processed */
+  double  dactual_sourcera_hours;
+  /* for off runs: the false source (that should have been) observed */
+  float   frms_pedsig_phot[iMAXNUMPIX];
+  /* standard deviation of the calibrated signals from the pedestal run */ 
+  float   fpedrms_mean; /* Used to communicate the mean over all pixels 
+			 * pedestal RMS into the Runs NTuple, as it might 
+			 * be used for e.g. quality cuts. */
+  float   fcurrent_mean; /* The average current over the active pixels
+			  * for this run. This is done separately for
+			  * ON and OF runs. */
+
+  enum eERRORTOLERANCE eerrortolerance;
+  /* 0 == "cautious", exits on any reason (but tells in 
+   * the .err file,
+   * 1 == "goodphysics", exits when physics could be affected
+   * by the error,
+   * 2 == "tank", never exits except on coredumps and when
+   * all files have been processed. Do not use such files for
+   * physics analysis! 
+   *
+   * NOTE: the capital letter words are the enums, the small letter
+   * words must be used inside the parameter file. */
+  enum eMCTRIGGERFLAG emctriggerflag;
+  /* all: all events which survive the filter are written to the 
+   *      events NTuple. 
+   * flag: When Dorota's triggerflag is set to 1 for a particular
+   *       event, it shall be written to the output. All others shall
+   *       just be disregarded. (Default)
+   * noflag: Opposite of 'flag': only events with triggerflag = 0 shall
+   *         be treated further. */
+  Boolean bmontecarlo;
+  /* if TRUE we have a monte carlo dataset before us, if FALSE 
+   * (default value) it is just normal data. */
+};
+
+struct filterresults {
+  int     imax_alt_arcs;
+  /* maximum altitude reached during the run */
+  int     iaz_at_max_alt_arcs;
+  /* azimuth at the time the max. alt. was reached */
+  int     itimeaverage_alt_arcs;
+  /* altitude averaged over the runtime */
+  int     icoord_inconsist_evts;
+  /* number of events with time-coordinate */
+  /* inconsistency in this run */
+  int     ifilter_passed_evts;
+  /* number of events which passed the filter */
+  int     imuon_fail_evts;
+  /* number of events rejected as muons (other filters passed) */
+  int     i2out_fail_evts;
+  /* number of events which failed in the two out of all */
+  /* pixels software trigger */
+  int     imuon_and_2out_fail_evts;
+  /* number of events failing in both muon and */
+  /* 2out filter */  
+  int     isum_fail_evts;
+  /* number of events which failed the sum-of-all-calibrated */
+  /* ADC counts filter */
+  int     isum_and_muon_fail_evts;
+  /* number of events which failed in both the sum and */
+  /* the muon filter */
+  int     isum_and_2out_fail_evts;
+  /* number of events which failed in both the sum and */
+  /* the 2out filter */
+  int     iall_filters_fail_evts;
+  /* number of events which failed in all filters */ 
+  float   favg_event_rate_hz;
+  /* average rate before filtering */
+  float   fstddev_event_rate_hz;
+  /* standard deviation of the rate before filtering */
+
+};
+
+struct eventrecord {
+  int   isecs_since_midday;
+  /* seconds passed since midday before sunset (JD of run start) */
+  int   isecfrac_200ns;
+  /* fractional part of isecs_since_midday */
+  short snot_ok_flags;
+  /* the bits in these two bytes are flags for additional */
+  /* information on the event: Everything OK =: all Bits = 0 */
+  int   ialt_arcs;
+  /* altitude (arcseconds) */
+  int   iaz_arcs;
+  /* azimuth (arcseconds) */
+  int   ipreproc_alt_arcs;
+  /* "should be" alt according to preproc (arcseconds) */
+  int   ipreproc_az_arcs;
+  /* "should be" az according to preproc (arcseconds) */
+  int   ifieldrot_arcs;
+  /* for ALT-AZ mount telescopes: rotation angle of the field of 
+   * view; this angle is defined mathematically positive looking 
+   * towards the sky as the angle between the hour circle through 
+   * the object being tracked and the line through pixel 1 and 2 */
+  unsigned short srate_millihz;
+  /* event rate in milli Hertz before filtering calculated by 
+   * iratecalc_numevents_odd/(time[i+iratecalc_numevents_odd/2] - 
+   * time[i-iratecalc_numevents_odd/2]) 
+   * For the first and the last iratecalc_numevents_odd/2 
+   * events the rate is assumed to be constant */
+  float fhourangle; /* This is the angle between the observation of this
+		     * event and the culmination point. It is going to 
+		     * be written into the events NTuple. */
+  float fmcenergy_tev; /* Simulated Energy.... dropping through to
+			* the Events NTuple. */
+  float fmcsize_phel; /* Simulated SIZE.... dropping through to
+			* the Events NTuple. */
+  int imcimpact_m;
+  /* MC data contain the impact parameter, which is given here in 
+   * meters. */
+  int imcparticle;
+  /* MC data know which particle they are.... all in CORSIKA standard. */
+  int imctriggerflag;
+  /* MC data from Dorota get a triggerflag: 1 means triggered, 0 not. */
+  short spixsig_10thphot[iMAXNUMPIX];
+  /* number of photoelectrons measured in each pixel only the 
+   * actual number of pixels (outputpars.inumpixels) is written out */
+};
+
+struct camera { /* camera parameters for imaging */
+  int inumpixels;
+  int inumrings;
+  double dpixdiameter_deg;
+  double dxc[iMAXNUMPIX]; 
+/* Pixel coordinates in camera coordinate system (x points from
+ * pixel 1 to 2). */
+  double dyc[iMAXNUMPIX];
+  /* The numbering of the pixels in these arrays starts at 0! */
+  double dxpointcorr_deg; 
+  /* correction of the pixel coordinates; to be added to dxc[] 
+   * to get correct value */
+  double dypointcorr_deg; 
+  /* correction of the pixel coordinates; to be added to dxc[] 
+   * to get correct value */
+};
+
+
+/* two structures for better file handling */
+struct inputfile {
+  char cname[iMAXFILENAMELENGTH];
+  /* filename (including path) */
+  FILE *pointer;
+  /* filepointer */
+  char ccannotopentext[161];
+  /* Error text printed when file cannot be opened */
+  int  icannotopencode; 
+  /* Error code for the exit statement when file could not be opened */
+  int  iearlyeofcode;
+  /* Error code for the exit statement for unexpected EOF */
+  int  ierroratclosecode;
+  /* Error code for the exit statement for error while trying to close */
+};
+
+struct outputfile {
+  char cname[iMAXFILENAMELENGTH]; /* filename (including path) */
+  FILE *pointer;  /* filepointer */
+  char ccannotopentext[161]; 
+  /* Error text printed when file cannot be opened */
+  int  icannotopencode; 
+  /* Error code for the exit statement when file could not be opened */
+  int  icannotwritecode; 
+  /* Error code for the exit statement for failed fprintf */
+  int  ierroratclosecode; 
+  /* Error code for the exit statement for error while trying to close */
+};
+
+struct P2ALLHISTOS {
+
+  HISTO *p2adchist;
+  HISTO *p2pedonhist;
+  HISTO *p2pedofhist;
+  HISTO *p2pedonmeanhist;
+  HISTO *p2pedofmeanhist;
+  HISTO *p2pedonjitthist;
+  HISTO *p2pedofjitthist;
+  HISTO *p2calonhist;
+  HISTO *p2calofhist;
+  HISTO *p2calonmeanhist;
+  HISTO *p2calofmeanhist;
+  HISTO *p2calonjitthist;
+  HISTO *p2calofjitthist;
+  HISTO *p2phehist;
+  HISTO *p2zenonhist;
+  HISTO *p2zenofhist;
+  HISTO *p2corrpedhist;
+  HISTO *p2pedfwhmhist;
+};
+
+struct CALNT_DAT { 
+  /* the structure for an entry in the calibration ntuple */
+  float CTrunnum;
+  float runtype;
+  float ALT_deg; /* the ALT taken from the first event of the run */
+  float extinct; /* extinction */
+  float RtiSecBF; /* runtime in seconds before filter */
+  float pixnum;  /* number of the pixel for which the following 
+		  * data is given */
+  float pixonoff; /* Quantity telling whether this pixel was switched
+		   * off by the user (-= 2.) or by preproc (-= 1.).
+		   * If ON, its value = 0. */
+  float ped_adcc; /* the standard deviation of the pedestal as 
+		   * calculated by TIJARAFE */
+  float pedrmsac; /* the standard deviation of the pedestal in
+		   * ADC counts as calculated by TIJARAFE */
+  float pedrmsPE; /* the calibrated ped RMS in photoelectrons 
+		   * which is also given to the imager */
+  float las_adcc; /* the mean signal for this pixel from the 
+		   * laser run */
+  float lasrmsac; /* RMS of the laser events after cleaning from cosmics */
+  float conv_fac; /* conversion factor = <Q>/Var(Q) * F^2 */
+  float F;        /* The F from the line before */
+  float rel_gain; /* the relative gain of the pixel */
+  float numtrig;  /* number of events in which the pixel was 
+		   * above trigger threshold */
+  float num3sig;  /* number of events in which the pixel was 
+		   * 3 sigma above its pedestal */ 
+  float HV1;      /* Adjustment of HV1 for this run, if available. */
+  float HV2;      /* Adjustment of HV2 for this run, if available. */
+  float ThrCurr;
+  float AvgCurr;  /* the sum of all currents during this run (with the
+		   * particular runtype in question) from the TelLog 
+		   * file. The currents are averaged over the 2-minute
+		   * intervals but summed over all pixels with currents
+		   * higher than the threshold current value. This sum
+		   * is then stored in the runs ntuple. 
+		   * Same for the scaler values --> */
+  float AvgScal;
+};
+
+struct inputpars {
+  Boolean bkeywordgiven[iNUMKEYWORDS+1]; /* if a valid keyword 
+					  * is given in the 
+					  * parameters file 
+					  * the corresponding
+					  * element in this 
+					  * array is set to true */ 
+  int     itelescope;       /* number of the CT which took the data */
+  float   flongitude_deg;   /* longitude (counted positive 
+			     * towards West) of CT position */
+  float   flatitude_deg;    /* latitude (counted positive 
+			     * towards North) of CT position */
+  int     ifirstrunnum;     /* first run number to which these 
+			     * parameters apply*/
+  int     ilastrunnum;      /* last run number to which these 
+			     * parameters apply, */
+                            /* i.e. this run will be processed 
+			     * with these parameters */
+  int     inumpixels;       /* number of pixels in the camera */
+  int     inummuonpixels;   /* number of pixels in the muon shield */
+  int     inumcointdcs;     /* number of coincidence tdcs recorded 
+			     * in the runfile */
+  float   fpixdiameter_deg; /* smallest pixel diameter (degrees) */
+  enum axes ese1_is;        /* name of the axis to which shaft
+			     * encoder 1 is attached
+			     * (implies the type of mount) (the 
+			     * type axes is declared in structures.h) */
+  float   fdegrees_per_step[2]; /* angular resolution of shaft 
+				 * encoders 1 and 2 */
+  int     isezeropos[2];    /* zero position of shaftencoders 1 and 
+			     * 2 from parameters file */
+  int     iaz_rev_track_corr; /* correction for the azimuth shaft 
+			       * encoder (ALT/AZ mount only) in 
+			       * reverse tracking mode */
+  int     ialt_rev_track_corr; /* correction for the altitude 
+				* shaft encoder (ALT/AZ mount only) 
+				* in reverse tracking mode */
+  float   fbendingcorr;     /* bending correction factor 
+			     * (ALT/AZ mount only) */
+  Boolean bdontusepix[iMAXNUMPIX]; /* bdontusepix is set true 
+				    * if the pixel should due 
+				    * to whatever reason not be 
+				    * used in image analysis, 
+				    * otherwise it is false;
+				    * this is a copy of the 
+				    * input from the parameters file */
+  Boolean bdontusepix_in_trig[iMAXNUMPIX]; /* is set true if the 
+					    * pixel should due 
+					    * to whatever reason not 
+					    * be used in the two out 
+					    * of all trigger, otherwise 
+					    * it is false; this is a 
+					    * copy of the input from 
+					    * the parameters file */
+  float   fphotoel_per_adccnt[iMAXNUMPIX]; /* conversion factors for 
+					    * the pixel signals */
+  float   fextinction;      /* atmospheric extinction (typically 
+			     * taken from the Carlsberg Meridian
+			     * Circle data) */
+  int     irubminusutc_usecs; /* difference between rubidium clock 
+			       * and UTC in microseconds */
+  int     isum_thresh_phot; /* threshold for the total sum of 
+			     * photoelectrons filter from the 
+			     * parameters file */
+  int     i2out_thresh_phot; /* threshold for the 
+			      * two-pixels-out-of-all software 
+			      * trigger from parameters file */
+  int     imuoncut_thresh_adccnt[iMAXNUMMUONPIX]; /* thresholds for 
+						   * the muon cut */
+  Boolean bmuon_suppression;       /* if true, the events which do 
+				    * not pass the muon cut are not 
+				    * written to the output */
+  float   ftolerated_pointerror_deg; /* maximum tolerated pointing 
+				      * error in the position check 
+				      * in iprocessdata */
+  float   fxpointcorr_deg;  /* pointing correction (to be added 
+			     * along the camera x axis) e.g. 
+			     * from point run */ 
+  float   fypointcorr_deg;  /* pointing correction (to be added 
+			     * along the camera y axis) e.g. 
+			     * from point run */ 
+  float   fcamera_align_angle_deg; /* the angle between the camera 
+				    * y-axis and the meridian when 
+				    * a culminating object is 
+				    * observed (defined 
+				    * counter-clockwise looking at 
+				    * the sky) */ 
+  int     iratecalc_numevents_odd; /* number of events used in the 
+				    * rate calculation (must be odd) */
+  enum pedsearchdirs {MATCH=0, BEFORE, AFTER, PINGPONG, 
+		      PEAKFWHM, NONE} epedsearchdir ; 
+  /* MATCH = only same number as run file (if ipedendofsearch is 0) or 
+     exactly ipedendofsearch;
+     BEFORE = search backwards until pedendofsearch; 
+     AFTER = search forward until pedendofsearch, 
+     PINGPONG = Try to fibnd the matching partner, try run#-1, run#+1,
+     run#-2, run#+2 etc. up to the third argument, the partnerfindrange 
+     NONE = use none of both. This is only useful for Monte Carlo
+     Analysis, for everything else it is highly unrecommended.*/
+  int     ipedendofsearch;  /* pedestal file number until which to 
+			     * search (see epedsearchdir) */
+  int     ipedsearchdepth;  /* depth, until which preproc should
+			     * try to find TelPed* partnerfiles */
+  enum    pedsearchdirs ecalsearchdir; 
+  /* MATCH = only same number as run file (if ipedendofsearch is 0) or 
+     exactly ipedendofsearch;
+     BEFORE = search backwards until pedendofsearch; 
+     AFTER = search forward until pedendofsearch, 
+     PINGPONG = Try to fibnd the matching partner, try run#-1, run#+1,
+     run#-2, run#+2 etc. up to the third argument, the partnerfindrange 
+     NONE = use none of both. This is only useful for Monte Carlo
+     Analysis, for everything else it is highly unrecommended.*/
+  int     icalendofsearch;  /* calibration file number until which 
+			     * to search (see ecalsearchdir)*/
+  int     icalsearchdepth;  /* depth, until which preproc should
+			     * try to find TelCal* partnerfiles */
+  double  dsourcera_hours;  /* right ascension of observed source 
+			     * in hours */
+  double  dsourcedec_deg;   /* declination of observed source in 
+			     * degrees */
+  float   fpadlevel_phot_pix[iMAXNUMPIX];   /* if > 0., software 
+					     * padding to this 
+					     * level is applied 
+					     * for the given pixel */
+  float   fseed1; /* seed for random generators */
+  float   fseed2;
+
+  int iswap_partner_of_pix[iMAXNUMPIX]; /* if >= 0, pixel i is 
+					 * swapped with 
+					 * iswap_partner_of_pix[i] 
+					 * in ireadrunfile, -pedfile, 
+					 * -calfile (internal 
+					 * numbering starting at 0)*/
+
+  Boolean bnewhistograms; /* set to true if new histograms shall be booked */
+  Boolean bhisto_on; /* set to true if histogramming is on */
+
+  enum eERRORTOLERANCE eerrortolerance; 
+  /* 0 == "cautious", exits on any reason (but tells in 
+   * the .err file,
+   * 1 == "normal", exits when physics could be affected
+   * by the error,
+   * 2 == "tank", never exits except on coredumps and when
+   * all files have been processed. Do not use such files for
+   * physics analysis! 
+   *
+   * NOTE: the capital letter words are the enums, the small letter
+   * words are to be used inside the parameter file. */
+  Boolean bmontecarlo;
+  /* if TRUE we have a monte carlo dataset before us, if FALSE 
+   * (default value) it is just normal data. */
+  enum eMCTRIGGERFLAG emctriggerflag;
+  /* all: all events which survive the filter are written to the 
+   *      events NTuple. 
+   * flag: When Dorota's triggerflag is set to 1 for a particular
+   *       event, it shall be written to the output. All others shall
+   *       just be disregarded. (Default)
+   * noflag: Opposite of 'flag': only events with triggerflag = 0 shall
+   *         be treated further. */
+  char mcfile[FILENAME_MAX];
+  float fmean_nsb_pe_pix[iMAXNUMPIX];
+  Boolean bfitmypedrms;
+  /* If TRUE, the pedestal MEAN and SIGMA=sqrt(MEAN) is fitted
+   * from pickup corrected pedestal data and not calculated from 
+   * the pickup corrected ADC values, as it was done up to 
+   * ~November 2000. */
+};
+
+struct calibrationdata { /* Calibration (Laser Run) Data to be read 
+			  * from the Te?Cal files */
+  int iid; /* no useful information, is long in the Macintosh format */
+  int itelescope; /* number of the CT which took the data */
+  int irunnum; /* run number from the file name */
+  enum onoroff eruntype; /* indicates if the run is on- or off 
+			  * (taken from filename) */
+  int inumruns; /* number of laser runs recorded in this file, is 
+		 * long in the Macintosh format */
+  char cname[iMAXFILENAMELENGTH]; /* copy of the filename used when 
+				   * the data was read */
+  double dmean_adc[iMAXNUMLASERRUNS][iMAXNUMPIX]; 
+  /* means of pixel signals over all shots calculated by TIJARAFE /
+   * Roberto: in processdata.c this number is recalculated. */
+  double dmean_lasoutput[iMAXNUMLASERRUNS][iMAXNUMLASEREVENTS]; 
+  /* This new (April 26 2000) quantity monitors the laser mean
+   * output recorded in events, which are not considered cosmics. */
+  double dmean_alladc[iMAXNUMPIX]; 
+  /* means of pixel signals over all triggers calculated by 
+   * preproc. */
+  double dmean_laserjitter[iMAXNUMPIX]; 
+  /* Here we calc. the deviation from the actual lasergain in a 
+   * single laser shot to the laser mean as averaged over the camera */
+  double drms_adc[iMAXNUMPEDRUNS][iMAXNUMPIX];
+  /* the standard deviations of the pixel signals */
+  int inumpixels; /* number of pixels in the camera, short in 
+		   * Macintosh format */
+  int inumevents[iMAXNUMLASERRUNS]; /* number laser shots, 
+				     * short in Macintosh format */
+  int ipixsig_adc[iMAXNUMLASERRUNS][iMAXNUMLASEREVENTS][iMAXNUMPIX]; 
+  /* the signals obtained from each pixel for each laser shot and 
+   * each laser run, unsigned short in the Macintosh format */
+};
+
+struct pedestaldata { /* Pedestal Run Data to be read from the 
+		       * Te?Ped files */
+  int iid; /* no useful information, is long in the Macintosh 
+	    * format */
+  int itelescope; /* number of the CT which took the data */
+  int irunnum; /* run number from the file name */
+  enum onoroff eruntype; /* indicates if the run is on- or of 
+			  * (taken from filename) */
+  int inumruns; /* number of pedestal events recorded in this file, 
+		 * is long in the Macintosh format */
+  char cname[iMAXFILENAMELENGTH]; /* copy of the filename used 
+				   * when the data was read */
+  double dmean_adc[iMAXNUMPEDRUNS][iMAXNUMPIX]; 
+  /* means of pixel signals over all triggers calculated by 
+   * TIJARAFE using a sigma cut of 2 */
+  double dmean_alladc[iMAXNUMPIX]; 
+  /* means of pixel signals over all triggers calculated by 
+   * preproc. */
+  double dmean_allPE[iMAXNUMPIX]; 
+  /* means of pixel signals over all triggers calculated by 
+   * preproc. */
+  double dmean_pedlevel[iMAXNUMPEDRUNS][iMAXNUMPEDEVENTS]; 
+  /* This new (preproc_0.4) quantity monitors the pedestal mean
+   * output recorded in events, which are not considered cosmics. 
+   * The calc.ing is done inside processdata.c */
+  double dmean_pedlevelPE[iMAXNUMPEDRUNS][iMAXNUMPEDEVENTS]; 
+  /* This new (preproc_0.4) quantity monitors the pedestal mean
+   * output recorded in events, which are not considered cosmics. 
+   * The calc.ing is done inside processdata.c */
+  double dmean_pedoffset[iMAXNUMPIX]; 
+  /* Mean Offset from the ADC spectrum of a pixel to the mean of the
+   * pedestal events. */
+  double dmean_pedoffsetPE[iMAXNUMPIX]; 
+  /* Mean Offset from the ADC spectrum of a pixel to the mean of the
+   * pedestal events. */
+  double drms_adc[iMAXNUMPEDRUNS][iMAXNUMPIX];
+  /* the standard deviations of the pixel signals used in the 
+   * sigma cut mentioned above */
+  double drms_alladc[iMAXNUMPIX];
+  /* The RMS value of the as-is ADC spectrum for all events inside a 
+   * Pedestal file. */
+  double drms_allPE[iMAXNUMPIX];
+  /* The RMS value of the as-is ADC spectrum for all events inside a 
+   * Pedestal file. */
+  double drms_nopickup[iMAXNUMPIX];
+  /* the standard deviations of the pixel signals' deviation from
+   * the events' mean (in ADC counts, of course...)  ---
+   * This is the same as the RMS of the pickup corrected pedestals! */
+  double drms_nopickupPE[iMAXNUMPIX];
+  /* the standard deviations of the pixel signals' deviation from
+   * the events' mean (in ADC counts, of course...)  ---
+   * This is the same as the RMS of the pickup corrected pedestals! */
+  int inumpixels; /* number of pixels in the camera, short in 
+		   * Macintosh format */
+  int inumevents[iMAXNUMPEDRUNS]; /* number of random triggers, 
+				   * short in Macintosh format */
+  int ipixsig_adc[iMAXNUMPEDRUNS][iMAXNUMPEDEVENTS][iMAXNUMPIX]; 
+  /* the signals obtained from each pixel for each random trigger 
+   * and each pedestal event, short in the Macintosh format */
+}; 
+
+struct runfiledata { /* Data read from Te?Run files */
+  int iformatid; /* Format ID of the data, long in Macintosh format */
+  int iversid;   /* Version ID of the data, long in Macintosh format */
+  int irevid;    /* Revision ID..., long in Macintosh format */
+  int itelescope; /* number of the CT which took the data */
+  int irunnum; /* run number from the file name */
+  int irunnumx; /* number read from the file, long in Macintosh format */
+  int inumevents; /* number of events recorded in this run, long in 
+		   * Macintosh format */
+  char cname[iMAXFILENAMELENGTH]; /* copy of the filename used when 
+				   * the data was read */
+  int ieventheaderlength; /* number of bytes in the event header,
+			   * long in Macintosh format */
+  int ieventheaderoffset; /* unknown meaning, long in Macintosh 
+			   * format */
+  int isignalslength; /* number of bytes used by the pixel signals, 
+		       * long in Macintosh format */
+  int isignalsoffset; /* unknown meaning, long in Macintosh format */
+  int itdccountslength; /* number of bytes used by the TDC signals, 
+			 * long in Macintosh format */
+  int itdccountsoffset; /* unknown meaning, long in Macintosh format */
+  int iobservtime_mins; /* (planned) observational time (minutes), 
+			 * short in Macintosh format */
+  enum onoroff eruntype; /* indicates if the run is on- or off-source; 
+			  * in the Macintosh format, this is a short
+			  * where 1 means off and 2 means on */
+  int ileapsecs; /* Leap seconds, introduced into UTC in order to 
+		  * keep track of some very small differences 
+		  * accumulated through the years. */
+  int ihv1;
+  int ihv2; /* these two numbers represent the HV adjustment made
+	     * by the shiftpersonnel. The last three items are 
+	     * only read for Roberto files, but not for Tijarafe 
+	     * files, as e.g. the HVs are not written out correctly. */
+  char cdummy[40]; /* unknown meaning */
+  int imactime_secs[iMAXNUMRUNEVENTS]; 
+  /* Macintosh time (time_t mydatum) in seconds since 1970, this is 
+   * put together from two Macintosh shorts and converted to the time 
+   * format required by SYSTEM */
+  unsigned int uigpstime_secs[iMAXNUMRUNEVENTS]; 
+  /* GPS time (time_t mydatum) in seconds since 1970, this is 
+   * put together from two Macintosh shorts and converted to the time 
+   * format required by SYSTEM 
+   * This time is new from Roberto and is coming from the PC-GPS card.
+   * There is another flag available in the runheader, which gives an
+   * overall flag for the run, whether or not the GPS time had been
+   * working. It is, however, not a good idea to use this flag, as 
+   * the workability of this card can also be dedued from the GPS time
+   * itself. This allows to check for failures on a event-by-event 
+   * basis, which seems more reasonable than using the global flag. */
+  unsigned int uigpstime_usecs[iMAXNUMRUNEVENTS]; 
+  /* GPS microseconds -- available from the card, that's why it is 
+   * put to the data, here it is.
+   * This is put together from two Macintosh shorts and converted
+   * to the time format required by SYSTEM */
+  unsigned int uirubsecs_secs[iMAXNUMRUNEVENTS]; 
+  /* the seconds of the Rubidium clock time this is put together 
+   * from two Macintosh shorts and converted to the time format 
+   * required by SYSTEM */
+  unsigned int uirubsecfrac_200ns[iMAXNUMRUNEVENTS]; 
+  /* the fractional part of the Rubidium clock time second, this is 
+   * put together from two Macintosh shorts, unit is 200 ns */
+  int isepos[2][iMAXNUMRUNEVENTS]; 
+  /* positions of shaft encoders 1 and 2, short in Macintosh format */
+  float fhourangle; /* This is the angle between the observation of this
+		     * event and the culmination point. It is going to 
+		     * be written into the events NTuple. */
+  int ieventnumber[iMAXNUMRUNEVENTS]; 
+/* number of the event, short in Macintosh format */
+  int inumpixels; /* number of pixels in the camera, short in 
+		   * Macintosh format */
+  int inummuonpixels; /* number of pixels in  the muon shield; 
+		       * the sum of inumpixels and inummuonpixels is 
+		       * part of the event record but should be the 
+		       * same for all events, so it is not put into 
+		       * an array */
+  int inumcointdcs; /* number of coincidence TDCs for which counts 
+		     * were recorded, short in Macintosh format
+                     * this value is part of the event record but 
+		     * should be the same for all events, so it is 
+		     * not put into an array */
+  int ipixsig_adc[iMAXNUMRUNEVENTS][iMAXNUMPIX]; 
+  /* signals from the camera photo multipliers (ADC counts) */
+  int imuonpixsig_adc[iMAXNUMRUNEVENTS][iMAXNUMMUONPIX]; 
+  /* signals from the muon shield photo multipliers (ADC counts) */
+  int itdcsig_cnts[iMAXNUMRUNEVENTS][iMAXNUMCOINTDCS]; 
+  /* counts from the coincidence TDCs if itdccountslength > 0 */
+};
+
+struct TELLOGDATA {
+  int irunnum; /* The runnumber which we are interested in. 
+		* Only data for this runnumber are written into 
+		* this structure and then copied to the calnt NTuple.
+		* 
+		* This runnumber is generally the closest match 
+		* inside the TelLog file. */
+  float pixel_timeaveraged_current[127];
+  float pixel_timeaveraged_scaler[127];
+};
+
+/************************************************
+ * structures in output file                    *
+ * (Konopelko files format)                     *
+ * (from structures.h file 4.4)                 *
+ ************************************************/
+struct mcbankheader { /* Once in every file */
+  int iparticle_type;  
+  /* Primary particle type: 0 = gamma; +-1= e+-; 
+   * +-2 = mu+-; +-3 = p+-, n; +-4 = pi+- */
+  int inum_cts;
+  /* Number of simulated telescopes */
+  int inum_nfl_shifts; 
+  /* Number of NFL shifts for hadrons (per event) */
+  int itrigger_thresh_phot; 
+  /* Only images with two pixels above this threshold are 
+   * in the MC data file */
+  int imin_signal;
+  /* "Tail cut" = smallest signal saved */
+  int inum_sim_showers; 
+  /* Total number of showers simulated for this file */
+  float fatmothick_gcm2; 
+  /* Atmosphere above the telescope [g/cm2] */
+  float fcos_zenangle;
+  /* Cosine of the zenith angle */
+  float fnfl_shift_radius_deg; 
+  /* Maximum angular radius within which a shifted 
+   * hadron shower is sampled [degrees] */
+  float fenergybin_bound_tev[iNUMENERGYBINS+1]; 
+  /* Boundaries for the 14 energy bins [TeV] 
+   * (newline after the first 8 numbers) */
+  float fzenithanglebin_bound[iNUMZENANGLEBINS+1]; 
+  /* Boundaries for the 11 zenith angle bins [degrees] */
+  int inum_show_in_bin[iNUMENERGYBINS]; 
+  /* Number of simulated (or saved) showers 
+   * per energy bin (newline after the first 8 numbers) */
+  float fmaxdist_impact_m[iNUMIMPACTBINS]; 
+  /* Maximum distance of the impact point to the 
+   * central telescope [m] for each energy bin 
+   * (newline after the first 8 numbers) */
+  int inumpixels_for_ct[iMAXNUMCTS]; 
+  /* Number of pixels in the camera of each simulated CT */
+  float fpixwidth_deg_ct[iMAXNUMCTS]; 
+  /* Pixel width [degrees] for each CT */
+  float fmirrsize_m2_ct[iMAXNUMCTS];  
+  /* Mirror area [m^2] for each CT  */
+  float fmean_nsb_phot_ct[iMAXNUMCTS]; 
+  /* Mean signal caused by the NSB in each pixel for each CT 
+   * [photoelectrons]. This is the simulation of the NSB, 
+   * not the electronic noise */
+  float fphes_per_photon_ct[iMAXNUMCTS]; 
+  /* Conversion factor photoelectron per photon */
+  float frelative_x_ct[iMAXNUMCTS]; 
+  /* x position relative to the central CT for each CT */
+  float frelative_y_ct[iMAXNUMCTS]; 
+  /* y position relative to the central CT for each CT */
+}; 
+
+
+#endif
+
+
+
+
+
+
+
Index: /trunk/MagicSoft/Mars/mhist/HistLinkDef.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/HistLinkDef.h	(revision 1574)
@@ -8,4 +8,5 @@
 
 #pragma link C++ class MH+;
+#pragma link C++ class MHArray+;
 #pragma link C++ class MH3+;
 
Index: /trunk/MagicSoft/Mars/mhist/MFillH.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MFillH.cc	(revision 1574)
@@ -71,11 +71,95 @@
 #include <fstream.h>
 
+#include <TClass.h>
+
+#include "MDataChain.h"
+
 #include "MLog.h"
 #include "MLogManip.h"
 
 #include "MH.h"
+#include "MHArray.h"
+
 #include "MParList.h"
 
 ClassImp(MFillH);
+
+//////////////////////////////////////////////////////////////////////////////
+//
+// MMap
+//
+// This class maps a key-value to a given value. In its simple versions it
+// maps a key to an index.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include <TArrayI.h>
+
+class MMap
+{
+private:
+    TArrayI fKeys;
+    TArrayI fValues;
+
+    Int_t K(Int_t i) const { return ((TArrayI)fKeys)[i]; }
+    Int_t V(Int_t i) const { return ((TArrayI)fValues)[i]; }
+
+public:
+    // --------------------------------------------------------------------------
+    //
+    // Get the value which corresponds to the given key-value
+    //
+    Int_t GetValue(Int_t key) const
+    {
+        const Int_t n = fKeys.GetSize();
+        for (int i=0; i<n; i++)
+        {
+            if (K(i)==key)
+                return V(i);
+        }
+        return -1;
+    }
+
+    // --------------------------------------------------------------------------
+    //
+    // Adds a new pair key-value. While the key is the key to the value.
+    // if the key already exists the pair is ignored.
+    //
+    void Add(Int_t key, Int_t value)
+    {
+        if (GetValue(key)>=0)
+            return;
+
+        const Int_t n = fKeys.GetSize();
+
+        fKeys.Set(n+1);
+        fValues.Set(n+1);
+
+        fKeys[n] = key;
+        fValues[n] = value;
+    }
+
+    // --------------------------------------------------------------------------
+    //
+    // Adds a new pair key-value. While the key is the key to the value.
+    // In this case the value is an automatically sequential created index.
+    // if the key already exists the pair is ignored.
+    //
+    Int_t Add(Int_t key)
+    {
+        const Int_t k = GetValue(key);
+        if (k>=0)
+            return k;
+
+        const Int_t n = fKeys.GetSize();
+
+        fKeys.Set(n+1);
+        fValues.Set(n+1);
+
+        fKeys[n] = key;
+        fValues[n] = n;
+
+        return n;
+    }
+};
 
 // --------------------------------------------------------------------------
@@ -91,4 +175,7 @@
     fH            = NULL;
     fParContainer = NULL;
+
+    fIndex  = NULL;
+    fMapIdx = new MMap;
 }
 
@@ -194,4 +281,6 @@
     fParContainerName = par;
 
+    AddToBranchList(fH->GetDataMember());
+
     if (title)
         return;
@@ -222,8 +311,54 @@
     fParContainerName = par->GetName();
 
+    AddToBranchList(fH->GetDataMember());
+
     if (!title)
         fTitle = (TString)"Fill " + hist->GetDescriptor() + " from " + par->GetDescriptor();
 }
 
+// --------------------------------------------------------------------------
+//
+// Destructor. Delete fData if existing and kCanDelete is set.
+//
+MFillH::~MFillH()
+{
+    if (fIndex)
+        if (fIndex->TestBit(kCanDelete))
+            delete fIndex;
+
+    delete fMapIdx;
+}
+
+// --------------------------------------------------------------------------
+//
+// If the histogram to be filles is a MHArray you can specify a 'rule'
+// This rule is used to create an MDataChain. The return value of the chain
+// is casted to int. Each int acts as a key. For each (new) key a new
+// histogram is created in the array. (eg for the rule
+// "MRawEvtHeader::fRunNumber" you would get one histogram per run-number)
+//
+void MFillH::SetRuleForIdx(const TString rule)
+{
+    fIndex = new MDataChain(rule);
+    fIndex->SetBit(kCanDelete);
+}
+
+// --------------------------------------------------------------------------
+//
+// If the histogram to be filles is a MHArray you can specify a MData-object
+// The return value of the object is casted to int. Each int acts as a key.
+// For each (new) key a new histogram is created in the array. (eg for
+// MDataMember("MRawEvtHeader::fRunNumber") you would get one histogram per
+// run-number)
+//
+void MFillH::SetRuleForIdx(MData *data)
+{
+    fIndex = data;
+}
+
+// --------------------------------------------------------------------------
+//
+// Extracts the name of the histogram from the MFillH argument
+//
 TString MFillH::ExtractName(const char *name) const
 {
@@ -239,4 +374,8 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Extracts the class-name of the histogram from the MFillH argument
+//
 TString MFillH::ExtractClass(const char *name) const
 {
@@ -265,4 +404,19 @@
 Bool_t MFillH::PreProcess(MParList *pList)
 {
+    if (fIndex)
+    {
+        if (!fIndex->PreProcess(pList))
+        {
+            *fLog << all << "PreProcessing of Index rule failed... aborting." << endl;
+            return kFALSE;
+        }
+
+        if (!fIndex->IsValid())
+        {
+            *fLog << all << "Given Index rule invalid... aborting." << endl;
+            return kFALSE;
+        }
+    }
+
     //
     // Try to get the histogram container with name fHName from list
@@ -293,8 +447,10 @@
         // 'type'.
         //
-        if (!obj->InheritsFrom(MH::Class()))
+        TClass *tcls = fIndex ? MHArray::Class() : MH::Class();
+        if (!obj->InheritsFrom(tcls))
         {
             *fLog << err << dbginf << obj->GetName() << " doesn't inherit ";
-            *fLog << "from MH - cannot be used for MFillH... aborting." << endl;
+            *fLog << "from " << tcls->GetName() << " - cannot be used for MFillH...";
+            *fLog << "aborting." << endl;
             return kFALSE;
         }
@@ -343,4 +499,11 @@
 Bool_t MFillH::Process()
 {
+    if (fIndex)
+    {
+        const Int_t key = (Int_t)fIndex->GetValue();
+        const Int_t idx = fMapIdx->Add(key);
+        ((MHArray*)fH)->SetIndex(idx);
+    }
+
     return fH->Fill(fParContainer);
 } 
@@ -396,3 +559,9 @@
 
     out << ");" << endl;
-}
+
+    if (!fIndex)
+        return;
+
+    out << "   " << GetUniqueName() << ".SetRuleForIdx(\"";
+    out << fIndex->GetRule() << "\");" << endl;
+}
Index: /trunk/MagicSoft/Mars/mhist/MFillH.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MFillH.h	(revision 1574)
@@ -7,5 +7,8 @@
 
 class MH;
+class MData;
 class MParList;
+
+class MMap;
 
 class MFillH : public MTask
@@ -15,6 +18,9 @@
     TString fParContainerName;
 
-    MH* fH;                   
+    MH* fH;
     TString fHName;
+
+    MData *fIndex;    // MData object describing the 'key' to an automatic index for an MHArray
+    MMap  *fMapIdx;   //! Map to map key-index-pair for an MHArray (MMap see MFillH.cc)
 
     TString ExtractName(const char *name) const;
@@ -32,4 +38,9 @@
     MFillH(MH *hist,         MParContainer *par,   const char *name=NULL, const char *title=NULL);
 
+    ~MFillH();
+
+    void SetRuleForIdx(const TString rule);
+    void SetRuleForIdx(MData *rule);
+
     Bool_t PreProcess(MParList *pList);
     Bool_t Process();
Index: /trunk/MagicSoft/Mars/mhist/MH.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MH.cc	(revision 1574)
@@ -45,4 +45,7 @@
 //  the histogram(s) by the data of a corresponding parameter container.    //
 //                                                                          //
+//  Remark: the static member function (eg MakeDefCanvas) can be called     //
+//          from everywhere using: MH::MakeDefCanvas(...)                   //
+//                                                                          //
 //////////////////////////////////////////////////////////////////////////////
 
@@ -93,6 +96,17 @@
 Bool_t MH::Fill(const MParContainer *par)
 {
-    *fLog << GetDescriptor() << ": Fill not overloaded! Can't be used!" << endl;
+    *fLog << warn << GetDescriptor() << ": Fill not overloaded! Can't be used!" << endl;
     return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// This virtual function is ment as a generalized interface to retrieve
+// a pointer to a root histogram from the MH-derived class.
+//
+TH1 *MH::GetHistByName(const TString name)
+{
+    *fLog << warn << GetDescriptor() << ": GetHistByName not overloaded! Can't be used!" << endl;
+    return NULL;
 }
 
@@ -665,2 +679,3 @@
     l.Draw();
 }
+
Index: /trunk/MagicSoft/Mars/mhist/MH.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MH.h	(revision 1574)
@@ -24,4 +24,8 @@
     virtual Bool_t Fill(const MParContainer *par);
     virtual Bool_t Finalize() { return kTRUE; }
+
+    virtual TString GetDataMember() const { return ""; }
+
+    virtual TH1 *GetHistByName(const TString name);
 
     static TCanvas *MakeDefCanvas(TString name="", const char *title="",
Index: /trunk/MagicSoft/Mars/mhist/MH3.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MH3.cc	(revision 1574)
@@ -83,4 +83,8 @@
 static const TString gsDefTitle = "Container for a %dD Mars Histogram";
 
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
 MH3::MH3() : fDimension(0), fHist(NULL)
 {
@@ -179,4 +183,25 @@
         if (fData[i])
             delete fData[i];
+}
+
+// --------------------------------------------------------------------------
+//
+// Return the data members used by the data chain to be used in
+// MTask::AddBranchToList
+//
+TString MH3::GetDataMember() const
+{
+    TString str=fData[0]->GetDataMember();
+    if (fData[1])
+    {
+        str += ";";
+        str += fData[1]->GetDataMember();
+    }
+    if (fData[2])
+    {
+        str += ";";
+        str += fData[2]->GetDataMember();
+    }
+    return str;
 }
 
@@ -526,2 +551,34 @@
     }
 }
+
+// --------------------------------------------------------------------------
+//
+// Used to rebuild a MH3 object of the same type (data members,
+// dimension, ...)
+//
+MParContainer *MH3::New() const
+{
+    MH3 *h = NULL;
+    switch (fDimension)
+    {
+    case 1:
+        h=new MH3(fData[0]->GetRule());
+        break;
+    case 2:
+        h=new MH3(fData[0]->GetRule(), fData[1]->GetRule());
+        break;
+    case 3:
+        h=new MH3(fData[0]->GetRule(), fData[1]->GetRule(), fData[2]->GetRule());
+        break;
+    }
+    switch (fDimension)
+    {
+    case 3:
+        h->SetScaleZ(fScale[2]);
+    case 2:
+        h->SetScaleY(fScale[1]);
+    case 1:
+        h->SetScaleX(fScale[0]);
+    }
+    return h;
+}
Index: /trunk/MagicSoft/Mars/mhist/MH3.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MH3.h	(revision 1574)
@@ -51,6 +51,10 @@
     Bool_t Fill(const MParContainer *par);
 
+    TString GetDataMember() const;
+
     TH1 &GetHist() { return *fHist; }
     const TH1 &GetHist() const { return *fHist; }
+
+    TH1 *GetHistByName(const TString name) { return fHist; }
 
     void SetColors() const;
@@ -58,4 +62,6 @@
     TObject *DrawClone(Option_t *opt=NULL) const;
 
+    MParContainer *New() const;
+
     ClassDef(MH3, 1) // Generalized 1/2/3D-histogram for Mars variables
 };
Index: /trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTheta.h	(revision 1574)
@@ -39,4 +39,6 @@
     const TH3D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: /trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHAlphaEnergyTime.h	(revision 1574)
@@ -29,5 +29,4 @@
     TH3D    fHist;
 
-
 public:
     MHAlphaEnergyTime(const char *name=NULL, const char *title=NULL);
@@ -38,4 +37,6 @@
     const TH3D *GetHist()       { return &fHist; }
     const TH3D *GetHist() const { return &fHist; }
+
+    TH1 *GetHistByName(const TString name) { return &fHist; }
 
     void Draw(Option_t *option="");
Index: /trunk/MagicSoft/Mars/mhist/MHArray.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHArray.cc	(revision 1574)
+++ /trunk/MagicSoft/Mars/mhist/MHArray.cc	(revision 1574)
@@ -0,0 +1,428 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  07/2001 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//
+//  MHArray
+//
+//  is a sequential collection of mars histograms. If the given index to
+//  call the Fill function of the histogram excceeds the size of the
+//  array by 1 a new entry is created.
+//
+//  With Set/Inc/DecIndex you may specify the actual index of the histogram
+//  wich should be filles by Fill.
+//
+//  Use GetH to get the current histogram, the []-operator get the histogram
+//  by its index.
+//
+//  To map a key to the index use/see MFillH, which automatically maps a
+//  key-value to the array index.
+//
+//  In the constructor istempl leads to two different behaviours of the
+//  MHArray:
+//
+//  - istempl=kTRUE tells MHArray to use the first histogram retrieved from
+//    the Parameterlist by hname to be used as a template. New histograms
+//    are not created using the root dictionary, but the New-member function
+//    (see MParConatiner)
+//  - In the case istempl=kFALSE new histograms are created using the root
+//    dictionary while hname is the class name. For the creation their
+//    default constructor is used.
+//
+//////////////////////////////////////////////////////////////////////////////
+#include "MHArray.h"
+
+#include <TH1.h>
+#include <TH2.h>
+#include <TH3.h>
+#include <TStyle.h>
+#include <TGaxis.h>
+#include <TCanvas.h>
+#include <TLegend.h>
+#include <TPaveStats.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MParContainer.h"
+
+#include "MBinning.h"
+
+ClassImp(MHArray);
+
+// --------------------------------------------------------------------------
+//
+// Default Constructor. hname is the name of the histogram class which
+// is in the array.
+//
+// istempl=kTRUE tells MHArray to use the first histogram retrieved from the
+// ParameterList by hname to be used as a template. New histograms are not
+// created using the root dictionary, but the New-member function (see
+// MParConatiner)
+// In the case istempl=kFALSE new histograms are created using the root
+// dictionary while hname is the class name. For the creation their
+// default constructor is used.
+//
+MHArray::MHArray(const TString hname, Bool_t istempl, const char *name, const char *title)
+    : fIdx(0), fClass(NULL), fTemplate(NULL)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MHArray";
+    fTitle = title ? TString(title) : (TString("Base class for Mars histogram arrays:") + hname);
+
+    fArray = new TList;
+    fArray->SetOwner();
+
+    if (istempl)
+    {
+        fTemplateName = hname;
+        return;
+    }
+
+    //
+    // try to get class from root environment
+    //
+    fClass = gROOT->GetClass(hname);
+    if (!fClass)
+    {
+        //
+        // if class is not existing in the root environment
+        //
+        *fLog << err << dbginf << "Class '" << hname << "' not existing in dictionary." << endl;
+    }
+
+    //
+    // check for ineritance from MH
+    //
+    if (!fClass->InheritsFrom(MH::Class()))
+    {
+        //
+        // if class doesn't inherit from MH --> error
+        //
+        *fLog << err << dbginf << "Class '" << hname << "' doesn't inherit from MH." << endl;
+        fClass = NULL;
+    }
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor: Deleteing the array and all histograms which are part of the
+// array.
+//
+MHArray::~MHArray()
+{
+    fArray->Delete();
+    delete fArray;
+}
+
+
+MH &MHArray::operator[](Int_t i)
+{
+    return *(MH*)fArray->At(i);
+}
+
+MH *MHArray::At(Int_t i)
+{
+    return (MH*)fArray->At(i);
+}
+
+MH *MHArray::GetH()
+{
+    return (MH*)fArray->At(fIdx);
+}
+
+// --------------------------------------------------------------------------
+//
+// Tries to create a new histogram, adds it as last entry to the array
+// and tries to call SetupFill for it. In case of success the last entry
+// in the array is the new histogram and kTRUE is returned. Otherwise
+// kFALSE is returned.
+//
+Bool_t MHArray::CreateH()
+{
+    TString cname = fClass ? fClass->GetName() : fTemplate->IsA()->GetName();
+
+    MH *hist = NULL;
+    if (fTemplate)
+    {
+        hist = (MH*)fTemplate->New();
+    }
+    else
+    {
+        //
+        // create the parameter container of the the given class type
+        //
+        hist = (MH*)fClass->New();
+    }
+    if (!hist)
+    {
+        *fLog << err << dbginf << "Cannot create new instance of class '";
+        *fLog << cname << "' (Maybe no def. constructor)" << endl;
+        return kFALSE;
+    }
+
+    //
+    // Set the name of the container
+    //
+    if (!fTemplate)
+    {
+        TString name = TString(hist->GetName())+";";
+        name += fIdx;
+
+        hist->SetName(name);
+    }
+
+    //
+    // Try to setup filling for the histogram
+    //
+    if (!hist->SetupFill(fParList))
+    {
+        *fLog << err << dbginf << "SetupFill for new histogram of type '";
+        *fLog << cname << "' with Index #" << fIdx << " failed." << endl;
+        delete hist;
+        return kFALSE;
+    }
+
+    fArray->AddLast(hist);
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Returns kFALSE if the class couldn't be found in the root dictionary or
+// if it doesn't inherit from MH.
+// The parameter list is remembert to be used for SetupFill in case a new
+// histogram is created.
+// The index is reset to 0
+//
+Bool_t MHArray::SetupFill(const MParList *pList)
+{
+    fParList = pList;
+    fIdx = 0;
+
+    if (!fTemplateName.IsNull())
+    {
+        fTemplate = (MH*)pList->FindObject(fTemplateName, "MH");
+        return fTemplate ? kTRUE : kFALSE;
+    }
+
+    return fClass ? kTRUE : kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Call Fill for the present histogram index. If the index is out of
+// bounds the event is skipped. If the index is the number of current
+// histograms in the array a new histogram is created and if creation was
+// successfull filled.
+//
+Bool_t MHArray::Fill(const MParContainer *par)
+{
+    const Int_t n = fArray->GetSize();
+
+    if (fIdx <0 || fIdx>n)
+    {
+        *fLog << warn << "Histogram Index #" << fIdx << " out of bounds (>";
+        *fLog << n << ")... skipped." << endl;
+        return kCONTINUE;
+    }
+
+    if (fIdx==n)
+        if (!CreateH())
+            return kFALSE;
+
+    return GetH()->Fill(par);
+}
+
+// --------------------------------------------------------------------------
+//
+// Calls Finalize for all histograms in the list. If at least one Finalize
+// fails kFALSE is returned.
+//
+Bool_t MHArray::Finalize()
+{
+    Bool_t rc = kTRUE;
+
+    TIter Next(fArray);
+    MH *hist = NULL;
+
+    while ((hist=(MH*)Next()))
+        if (!hist->Finalize())
+            rc = kFALSE;
+
+    return rc;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the number of entries in the array
+//
+void MHArray::Print(Option_t *option="") const
+{
+    *fLog << all << GetDescriptor() << " contains " << fArray->GetSize();
+    *fLog << " histograms." << endl;
+}
+
+// --------------------------------------------------------------------------
+//
+// The option is the name of the histogram, used to get a histogram from
+// the MH entries by calling their GetHist function.
+//
+void MHArray::Draw(Option_t *opt="")
+{
+    if (!gPad)
+        MH::MakeDefCanvas(this);
+
+    const Stat_t sstyle = gStyle->GetOptStat();
+    gStyle->SetOptStat(0);
+
+    TIter Next(fArray);
+    MH *hist = (MH*)Next();
+
+    Int_t col=2;
+    Double_t max=0;
+    Double_t min=0;
+
+    TH1 *h1=NULL;
+
+    if (hist)
+    {
+        if ((h1 = hist->GetHistByName(opt)))
+        {
+            h1->Draw();
+            h1->SetLineColor(col++);
+            max = h1->GetMaximum();
+            min = h1->GetMinimum();
+        }
+    }
+
+    while ((hist=(MH*)Next()))
+    {
+        TH1 *h=NULL;
+
+        if (!(h = hist->GetHistByName(opt)))
+            continue;
+
+        h->Draw("same");
+        h->SetLineColor(col++);
+        if (max<h->GetMaximum())
+            max = h->GetMaximum();
+        if (min>h->GetMinimum())
+            min = h->GetMinimum();
+    }
+
+    if (h1)
+    {
+        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
+        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
+    }
+    gPad->Modified();
+    gPad->Update();
+
+    gStyle->SetOptStat(sstyle);
+}
+
+// --------------------------------------------------------------------------
+//
+// The option is the name of the histogram, used to get a histogram from
+// the MH entries by calling their GetHistByName function.
+// If the option also contains 'nonew' no new canvas is created.
+//
+TObject *MHArray::DrawClone(Option_t *opt="") const
+{
+    TString o(opt);
+
+    TCanvas *c = NULL;
+
+    Int_t nonew = o.Index("nonew", TString::kIgnoreCase);
+    if (nonew>=0)
+    {
+        c = MH::MakeDefCanvas(this);
+
+        //
+        // This is necessary to get the expected bahviour of DrawClone
+        //
+        gROOT->SetSelectedPad(NULL);
+
+        o.Remove(nonew, 5);
+    }
+
+    const Stat_t sstyle = gStyle->GetOptStat();
+    gStyle->SetOptStat(0);
+
+    TIter Next(fArray);
+    MH *hist = (MH*)Next();
+
+    Int_t col=2;
+    Double_t max=0;
+    Double_t min=0;
+
+    TH1 *h1=NULL;
+
+    if (hist)
+    {
+        if ((h1 = hist->GetHistByName(o)))
+        {
+            h1 = (TH1*)h1->DrawCopy();
+            h1->SetMarkerColor(col);
+            h1->SetLineColor(col++);
+            h1->SetFillStyle(4000);
+            max = h1->GetMaximum();
+            min = h1->GetMinimum();
+        }
+    }
+
+    while ((hist=(MH*)Next()))
+    {
+        TH1 *h=NULL;
+
+        if (!(h = hist->GetHistByName(o)))
+            continue;
+
+        h = (TH1*)h->DrawCopy("same");
+        h->SetMarkerColor(col);
+        h->SetLineColor(col++);
+        h->SetFillStyle(4000);
+        if (max<h->GetMaximum())
+            max = h->GetMaximum();
+        if (min>h->GetMinimum())
+            min = h->GetMinimum();
+    }
+
+    if (h1)
+    {
+        h1->SetMinimum(min>0 ? min*0.95 : min*1.05);
+        h1->SetMaximum(max>0 ? max*1.05 : max*0.95);
+    }
+    gPad->Modified();
+    gPad->Update();
+
+    gStyle->SetOptStat(sstyle);
+
+    return c;
+}
Index: /trunk/MagicSoft/Mars/mhist/MHArray.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHArray.h	(revision 1574)
+++ /trunk/MagicSoft/Mars/mhist/MHArray.h	(revision 1574)
@@ -0,0 +1,54 @@
+#ifndef MARS_MHArray
+#define MARS_MHArray
+
+#ifndef MARS_MH
+#include "MH.h"
+#endif
+
+class TList;
+
+class MHArray : public MH
+{
+private:
+    Int_t  fIdx;              // current index for the fill function
+    TList *fArray;            //-> Array storing the histograms
+
+    const MParList *fParList; //! pointer to parameter list used for SetupFill when a new Hist is created
+    TClass *fClass;           //! pointer to class entry in root dictionary
+
+    MH *fTemplate;            //! pointer to a template histogram
+    TString fTemplateName;    //! name of the template class
+
+    Bool_t CreateH();
+
+    enum { kUseTemplate=BIT(14) };
+
+public:
+    MHArray(const TString hname, Bool_t istempl=kFALSE, const char *name=NULL, const char *title=NULL);
+    ~MHArray();
+
+    virtual Bool_t SetupFill(const MParList *pList);
+    virtual Bool_t Fill(const MParContainer *par);
+    virtual Bool_t Finalize();
+
+    MH &operator[](Int_t i);
+    MH *At(Int_t i);
+
+    MH *GetH();
+
+    void SetIndex(Int_t i) { fIdx=i; }
+    void IncIndex() { fIdx++; }
+    void DecIndex() { fIdx--; }
+
+    Int_t GetIndex() const { return fIdx; }
+
+    void Print(Option_t *option="") const;
+
+    void Draw(Option_t *opt="");
+    TObject *DrawClone(Option_t *opt="") const;
+
+    ClassDef(MHArray, 0) //A histogram class for an array of Mars histograms
+};
+
+#endif
+
Index: /trunk/MagicSoft/Mars/mhist/MHEnergyTheta.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHEnergyTheta.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHEnergyTheta.h	(revision 1574)
@@ -32,4 +32,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Divide(const TH2D *h1, const TH2D *h2);
     void Divide(const MHEnergyTheta *h1, const MHEnergyTheta *h2)
Index: /trunk/MagicSoft/Mars/mhist/MHEnergyTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHEnergyTime.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHEnergyTime.h	(revision 1574)
@@ -33,4 +33,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Divide(const TH2D *h1, const TH2D *h2);
     void Divide(const MHEnergyTime *h1, const MHEnergyTime *h2)
Index: /trunk/MagicSoft/Mars/mhist/MHHadronness.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHadronness.cc	(revision 1574)
@@ -43,6 +43,6 @@
 //    - red:   histogram of all hadronesses for non gammas
 //  * Upper Right Corner:
-//    - black: acceptance of gammas vs. the hadroness
-//    - red:   acceptance of non gammas vs. the hadroness
+//    - black: acceptance of gammas (Ag) vs. the hadroness
+//    - red:   acceptance of non gammas (Ah) vs. the hadroness
 //    - blue:  2D distance of (acceptance_hadrons, acceptances_gammas)
 //             to optimum (0, 1)
@@ -221,5 +221,5 @@
     }
 
-    return val1y - (val2y-val1y)/(val2x-val1x) * (0.5-val1x);
+    return val1y - (val2y-val1y)/(val2x-val1x) * (val1x-0.5);
 }
 
@@ -265,5 +265,5 @@
     }
 
-    fQfac->SetMaximum(max+1);
+    fQfac->SetMaximum(max*1.05);
 
     return kTRUE;
@@ -342,4 +342,11 @@
     *fLog << "Hadronness histograms:" << endl;
     *fLog << "---------------------" << endl;
+
+    if (fGraph->GetN()==0)
+    {
+        *fLog << " <No Entries>" << endl;
+        return;
+    }
+
     *fLog << "Used " << fGhness->GetEntries() << " Gammas and " << fPhness->GetEntries() << " Hadrons." << endl;
     *fLog << "Acc Gammas @  1% Hadron-acc: " << Form("%3.0f", GetGammaAcceptance(0.01)*100) << "%" << endl;
@@ -368,4 +375,7 @@
 TObject *MHHadronness::DrawClone(Option_t *opt) const
 {
+    if (fGraph->GetN()==0)
+        return NULL;
+
     TCanvas &c = *MakeDefCanvas("Hadronness", fTitle);
     c.Divide(2, 2);
@@ -435,5 +445,8 @@
 void MHHadronness::Draw(Option_t *)
 {
-    if (!gPad)
+   if (fGraph->GetN()==0)
+        return;
+
+   if (!gPad)
         MakeDefCanvas("Hadronness", fTitle);
 
Index: /trunk/MagicSoft/Mars/mhist/MHHadronness.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHadronness.h	(revision 1574)
@@ -18,12 +18,12 @@
     const MHadronness *fHadronness;    //!
 
-    TH1D* fPhness;        // Hadrons Hadronness
-    TH1D* fGhness;        // Gammas Hadronness
-    TH1D* fIntPhness;     // Hadrons Acceptance
-    TH1D* fIntGhness;     // Gammas Acceptance
-    TH1D* fMinDist;       // Minimum Distance to optimum acceptance
+    TH1D* fPhness;        //-> Hadrons Hadronness
+    TH1D* fGhness;        //-> Gammas Hadronness
+    TH1D* fIntPhness;     //-> Hadrons Acceptance
+    TH1D* fIntGhness;     //-> Gammas Acceptance
+    TH1D* fMinDist;       //-> Minimum Distance to optimum acceptance
 
-    TGraph *fQfac;        // Quality factor
-    TGraph *fGraph;       // gamma acceptance vs. hadron acceptance
+    TGraph *fQfac;        //-> Quality factor
+    TGraph *fGraph;       //-> gamma acceptance vs. hadron acceptance
 
 public:
Index: /trunk/MagicSoft/Mars/mhist/MHHillas.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHillas.cc	(revision 1574)
@@ -365,2 +365,24 @@
     gPad->Update();
 }
+
+TH1 *MHHillas::GetHistByName(const TString name)
+{
+    if (name.Contains("Width", TString::kIgnoreCase))
+        return fWidth;
+    if (name.Contains("Length", TString::kIgnoreCase))
+        return fLength;
+    if (name.Contains("Size", TString::kIgnoreCase))
+        return fSize;
+    if (name.Contains("Core", TString::kIgnoreCase))
+        return fCorePix;
+    if (name.Contains("Used", TString::kIgnoreCase))
+        return fUsedPix;
+    if (name.Contains("Delta", TString::kIgnoreCase))
+        return fDelta;
+    if (name.Contains("DistC", TString::kIgnoreCase))
+        return fDistC;
+    if (name.Contains("Center", TString::kIgnoreCase))
+        return fCenter;
+
+    return NULL;
+}
Index: /trunk/MagicSoft/Mars/mhist/MHHillas.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHillas.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHillas.h	(revision 1574)
@@ -41,4 +41,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name);
+
     TH1F *GetHistLength() { return fLength; }
     TH1F *GetHistWidth()  { return fWidth; }
Index: /trunk/MagicSoft/Mars/mhist/MHHillasExt.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHillasExt.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHillasExt.cc	(revision 1574)
@@ -312,2 +312,18 @@
     gPad->Update();
 }
+
+TH1 *MHHillasExt::GetHistByName(const TString name)
+{
+    if (name.Contains("Conc", TString::kIgnoreCase))
+        return &fHConc;
+    if (name.Contains("Conc1", TString::kIgnoreCase))
+        return &fHConc1;
+    if (name.Contains("Asym", TString::kIgnoreCase))
+        return &fHAsym;
+    if (name.Contains("M3Long", TString::kIgnoreCase))
+        return &fHM3Long;
+    if (name.Contains("M3Trans", TString::kIgnoreCase))
+        return &fHM3Trans;
+
+    return NULL;
+}
Index: /trunk/MagicSoft/Mars/mhist/MHHillasExt.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHillasExt.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHillasExt.h	(revision 1574)
@@ -35,4 +35,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name);
+
     void Draw(Option_t *opt=NULL);
     TObject *DrawClone(Option_t *opt=NULL) const;
Index: /trunk/MagicSoft/Mars/mhist/MHHillasSrc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHillasSrc.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHillasSrc.cc	(revision 1574)
@@ -271,2 +271,16 @@
     gPad->Update();
 }
+
+TH1 *MHHillasSrc::GetHistByName(const TString name)
+{
+    if (name.Contains("Alpha", TString::kIgnoreCase))
+        return fAlpha;
+    if (name.Contains("Dist", TString::kIgnoreCase))
+        return fDist;
+    if (name.Contains("HeadTail", TString::kIgnoreCase))
+        return fHeadTail;
+    if (name.Contains("CosDA", TString::kIgnoreCase))
+        return fCosDA;
+
+    return NULL;
+}
Index: /trunk/MagicSoft/Mars/mhist/MHHillasSrc.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHHillasSrc.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHHillasSrc.h	(revision 1574)
@@ -30,4 +30,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name);
+
     TH1F *GetHistAlpha()         { return fAlpha; }
     TH1F *GetHistDist()          { return fDist; }
Index: /trunk/MagicSoft/Mars/mhist/MHMatrix.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMatrix.cc	(revision 1574)
@@ -487,4 +487,10 @@
 }
 
+// --------------------------------------------------------------------------
+//
+// Implementation of SavePrimitive. Used to write the call to a constructor
+// to a macro. In the original root implementation it is used to write
+// gui elements to a macro-file.
+//
 void MHMatrix::StreamPrimitive(ofstream &out) const
 {
@@ -583,2 +589,12 @@
     return kTRUE;
 }
+
+// --------------------------------------------------------------------------
+//
+// Return a comma seperated list of all data members used in the matrix.
+// This is mainly used in MTask::AddToBranchList
+//
+TString MHMatrix::GetDataMember() const
+{
+    return fData ? fData->GetDataMember() : TString("");
+}
Index: /trunk/MagicSoft/Mars/mhist/MHMatrix.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMatrix.h	(revision 1574)
@@ -87,4 +87,6 @@
     Bool_t Fill(MParList *plist, MTask *read);
 
+    TString GetDataMember() const;
+
     ClassDef(MHMatrix, 1) // Multidimensional Matrix to store events
 };
Index: /trunk/MagicSoft/Mars/mhist/MHMcDifRate.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcDifRate.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcDifRate.h	(revision 1574)
@@ -31,4 +31,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: /trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcEfficiency.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: /trunk/MagicSoft/Mars/mhist/MHMcEfficiencyEnergy.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcEfficiencyEnergy.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcEfficiencyEnergy.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: /trunk/MagicSoft/Mars/mhist/MHMcEfficiencyImpact.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcEfficiencyImpact.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcEfficiencyImpact.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: /trunk/MagicSoft/Mars/mhist/MHMcEnergy.cc
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcEnergy.cc	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcEnergy.cc	(revision 1574)
@@ -260,2 +260,6 @@
 }
 
+TH1 *MHMcEnergy::GetHistByName(const TString name)
+{
+    return fHist;
+}
Index: /trunk/MagicSoft/Mars/mhist/MHMcEnergy.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcEnergy.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcEnergy.h	(revision 1574)
@@ -6,4 +6,5 @@
 #endif
 
+class TH1;
 class TH1F;
 class TF1;
@@ -45,6 +46,9 @@
     void SetNumBins(Int_t nbins = 100);
 
+    TH1 *GetHistByName(const TString name);
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
+
     void Print(Option_t* option = NULL) const;
 
Index: /trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcEnergyImpact.h	(revision 1574)
@@ -29,4 +29,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: /trunk/MagicSoft/Mars/mhist/MHMcEnergyMigration.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcEnergyMigration.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcEnergyMigration.h	(revision 1574)
@@ -23,4 +23,5 @@
     MMcEvt      *fMcEvt;
     MEnergyEst  *fEnergy;
+
     TH3D        fHist;
 
@@ -33,4 +34,6 @@
     const TH3D *GetHist() { return &fHist; }
     const TH3D *GetHist() const { return &fHist; }
+
+    TH1 *GetHistByName(const TString name) { return &fHist; }
 
     void Draw(Option_t *option="");
Index: /trunk/MagicSoft/Mars/mhist/MHMcIntRate.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHMcIntRate.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHMcIntRate.h	(revision 1574)
@@ -29,4 +29,6 @@
     const TH1D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t* option = "");
     TObject *DrawClone(Option_t* option = "") const;
Index: /trunk/MagicSoft/Mars/mhist/MHStarMap.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHStarMap.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHStarMap.h	(revision 1574)
@@ -33,4 +33,6 @@
     Bool_t Fill(const MParContainer *par);
 
+    TH1 *GetHistByName(const TString name) { return fStarMap; }
+
     TH2F *GetHist() { return fStarMap; }
 
Index: /trunk/MagicSoft/Mars/mhist/MHThetabarTheta.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHThetabarTheta.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHThetabarTheta.h	(revision 1574)
@@ -31,4 +31,6 @@
     const TProfile *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: /trunk/MagicSoft/Mars/mhist/MHThetabarTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHThetabarTime.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHThetabarTime.h	(revision 1574)
@@ -34,4 +34,6 @@
     const TProfile *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: /trunk/MagicSoft/Mars/mhist/MHTimeDiffTheta.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHTimeDiffTheta.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHTimeDiffTheta.h	(revision 1574)
@@ -32,4 +32,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: /trunk/MagicSoft/Mars/mhist/MHTimeDiffTime.h
===================================================================
--- /trunk/MagicSoft/Mars/mhist/MHTimeDiffTime.h	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/MHTimeDiffTime.h	(revision 1574)
@@ -30,4 +30,6 @@
     const TH2D *GetHist() const { return &fHist; }
 
+    TH1 *GetHistByName(const TString name) { return &fHist; }
+
     void Draw(Option_t *option="");
     TObject *DrawClone(Option_t *option="") const;
Index: /trunk/MagicSoft/Mars/mhist/Makefile
===================================================================
--- /trunk/MagicSoft/Mars/mhist/Makefile	(revision 1573)
+++ /trunk/MagicSoft/Mars/mhist/Makefile	(revision 1574)
@@ -32,4 +32,5 @@
            MBinning.cc \
            MH.cc \
+           MHArray.cc \
            MH3.cc \
            MHMatrix.cc \
