Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 1336)
+++ trunk/MagicSoft/Mars/Changelog	(revision 1337)
@@ -1,3 +1,86 @@
                                                                   -*-*- END -*-*-
+ 2002/06/03: Thomas Bretz
+
+   * mhist/MHCompProb.[h,cc]:
+     - added
+
+   * mhist/MHHadroness.[h,cc]:
+     - added
+
+   * mhist/HistLinkDef.h, mhist/Makefile:
+     - added MHCompProb
+     - added MHHadroness
+
+   * mhist/MFillH.cc:
+     - added a info-output
+
+   * mhist/MH3.cc:
+     - excluded temporary profiles from directory
+
+   * mhist/MHMatrix.[h,cc]:
+     - added code to calculate multi-dimensional distances
+     - added comments
+
+   * mbase/MAGIC.h:
+     - changed kGAMMA to 1
+
+   * mbase/MParList.[h,cc]:
+     - added Replace-function
+
+   * mbase/MReadMarsFile.[h,cc]:
+     - added correct seeking for the run headers
+
+   * mbase/MReadTree.[h,cc]:
+     - added GetFileIndex()
+
+   * mbase/MTaskList.cc:
+     - changed fTasksProcess.Delete() to fTasksProcess.Clear()
+
+   * mbase/MWriteAsciiFile.[h,cc]:
+     - added some code for future usage (in comments)
+
+   * mbase/MLogo.[h,cc]:
+     - added (not in use)
+
+   * mfilter/MFParticleId.[h,cc]:
+     - added
+
+   * mfilter/Makefile, mfilter/FilterLinkDef.h:
+     - added MFParticleId
+
+   * manalysis/MHadroness.[h,cc]:
+     - added
+
+   * manalysis/MCompProbCalc.[h,cc]:
+     - added
+
+   * manalysis/MMultiDimDistCalc.[h,cc]:
+     - added
+                                                           
+   * manalysis/AnalysisLinkDef.h, manalysis/Makefile:
+     - added MHadroness
+     - added MCompProbCalc
+     - added MMultiDimDistCalc
+
+   * manalysis/Makefile:
+     - added ../mdata
+     - added ../mhist
+
+   * macros/star.C:
+     - added
+
+   * macros/comprob.C:
+     - added
+
+   * macros/multidimdist.C:
+     - added
+  
+  * macros/dohtml.C:
+     - added star.C
+     - added comprob.C
+     - added multidimdist.C
+
+
+
  2002/05/29: Thomas Bretz
 
Index: trunk/MagicSoft/Mars/macros/comprob.C
===================================================================
--- trunk/MagicSoft/Mars/macros/comprob.C	(revision 1337)
+++ trunk/MagicSoft/Mars/macros/comprob.C	(revision 1337)
@@ -0,0 +1,115 @@
+/* ======================================================================== *\
+ !
+ ! *
+ ! * 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.
+ ! *
+ !
+ !   macro comprob.C
+ !
+ !   Author(s): Abelardo Moralejo
+ !   Author(s): Thomas Bretz, 2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+ !
+ !   Copyright: MAGIC Software Development, 2000-2002
+ !
+ !
+ \* ======================================================================== */
+
+void comprob()
+{
+    //
+    // Create a empty Parameter List and an empty Task List
+    // The tasklist is identified in the eventloop by its name
+    //
+    MParList  plist;
+
+    // Create task list and add it to the parameter list:
+    MTaskList tlist;
+    plist.AddToList(&tlist);
+
+    // First task in list: read mars file
+    MReadMarsFile read("Events", "star.root");
+    read.DisableAutoScheme();
+    tlist.AddToList(&read);
+
+    // Task to do the composite analysis of Hillas parameters:
+    MHCompProb compprob(500);
+    compprob.Add("MHillas.fWidth",              500,    0, 160);
+    compprob.Add("MHillas.fLength",             500,    0, 300);
+    compprob.Add("abs(MHillas.fAsym)",          500,    0, 400);
+    compprob.Add("HillasSource.fDist",          500,    0, 400);
+    compprob.Add("abs(HillasSource.fHeadTail)", 500,    0, 400);
+    compprob.Add("abs(MHillas.fM3Long)",        500,    0, 300);
+    compprob.Add("abs(MHillas.fM3Trans)",       500,    0, 150);
+    compprob.Add("MHillas.fConc1",              500,    0, 0.6);
+    compprob.Add("MHillas.fConc",               500,    0, 0.9);
+    compprob.Add("log10(MHillas.fSize)",        500,    0,   5);
+
+    plist.AddToList(&compprob);
+
+    MFillH fill(&compprob, "MMcEvt");
+
+    // Energy filter:
+    /*
+     MF filter("MMcEvt.fEnergy < 100");
+     fill->SetFilter(&filter);
+     tlist.AddToList(&filter);
+     */
+
+    tlist.AddToList(&fill);
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    // Loop over all data to fill the "normal" histograms:
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    gLog.SetDebugLevel(2);
+
+    // Loop to fill the variable bin histograms:
+    read.SetEventNum(0);
+    if (!evtloop.Eventloop())
+        return;
+
+    // ------------------------------------------------------------------
+
+    // Create task list and replace the old task list with the new one
+    MTaskList tlist2;
+    plist.Replace(&tlist2);
+
+    // First task in list: read mars file
+    MReadMarsFile read2("Events", "star2.root");
+    read2.DisableAutoScheme();
+    tlist2.AddToList(&read2);
+
+    // create task to calculate composite probabilities
+    MCompProbCalc calc;
+    tlist2.AddToList(&calc);
+
+    // fill probabilities (hadroness) into histogram
+    MFillH fill2("MHHadroness");
+    tlist2.AddToList(&fill2);
+
+    // Loop to fill the hadronness histograms:
+    if (!evtloop.Eventloop())
+        return;
+
+    plist.FindObject("MHHadroness")->DrawClone();
+    plist.FindObject("MHHadroness")->Print();
+}
+
Index: trunk/MagicSoft/Mars/macros/dohtml.C
===================================================================
--- trunk/MagicSoft/Mars/macros/dohtml.C	(revision 1336)
+++ trunk/MagicSoft/Mars/macros/dohtml.C	(revision 1337)
@@ -41,13 +41,16 @@
 
     html.SetSourceDir("macros");
-    html.Convert("merpp.C",       "MARS - Merging and Preprocessing");
-    html.Convert("readraw.C",     "MARS - How To Read A Raw");
-    html.Convert("rootlogon.C",   "MARS - rootlogon.C");
-    html.Convert("readCT1.C",     "MARS - Read and display CT1 Events");
-    html.Convert("readMagic.C",   "MARS - Read and display Magic Events");
-    html.Convert("CT1Hillas.C",   "MARS - Calculate CT1 Hillas");
-    html.Convert("MagicHillas.C", "MARS - Calculate Magic Hillas");
-    html.Convert("collarea.C",    "MARS - Calculate Collection Area from a MC root file");
-    html.Convert("threshold.C",   "MARS - Calculate Energy Threshold from a MC root file");
-    html.Convert("trigrate.C",    "MARS - Calculate Trigger Rate from a MC root file");
+    html.Convert("merpp.C",        "MARS - Merging and Preprocessing");
+    html.Convert("readraw.C",      "MARS - How To Read A Raw");
+    html.Convert("rootlogon.C",    "MARS - rootlogon.C");
+    html.Convert("readCT1.C",      "MARS - Read and display CT1 Events");
+    html.Convert("readMagic.C",    "MARS - Read and display Magic Events");
+    html.Convert("CT1Hillas.C",    "MARS - Calculate CT1 Hillas");
+    html.Convert("MagicHillas.C",  "MARS - Calculate Magic Hillas");
+    html.Convert("collarea.C",     "MARS - Calculate Collection Area from a MC root file");
+    html.Convert("threshold.C",    "MARS - Calculate Energy Threshold from a MC root file");
+    html.Convert("trigrate.C",     "MARS - Calculate Trigger Rate from a MC root file");
+    html.Convert("star.C",         "MARS - (St)andard (A)nalysis and (R)econstruction");
+    html.Convert("comprob.C",      "MARS - Calculation of composite probabilities for G/H-Seperation");
+    html.Convert("multidimdist.C", "MARS - Calculation of multidimensional distances for G/H-Seperation");
 }
Index: trunk/MagicSoft/Mars/macros/multidimdist.C
===================================================================
--- trunk/MagicSoft/Mars/macros/multidimdist.C	(revision 1337)
+++ trunk/MagicSoft/Mars/macros/multidimdist.C	(revision 1337)
@@ -0,0 +1,133 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Rudy Bock, 5/2002 <mailto:rkb@mppmu.mpg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+void multidimdist()
+{
+    //
+    // This is a demonstration program which calculates the Hillas
+    // parameter out of a Magic root 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:
+    // ---------------------------------
+    //
+    // The first argument is the tree you want to read.
+    //   Events:     Cosmic ray events
+    //   PedEvents:  Pedestal Events
+    //   CalEvents:  Calibration Events
+    //
+    MReadMarsFile  read("Events", "star.root");
+    read.DisableAutoScheme();
+    tlist.AddToList(&read);
+
+    MFParticleId fgamma("MMcEvt", '=', kGAMMA);
+    tlist.AddToList(&fgamma);
+
+    MFParticleId fhadrons("MMcEvt", '!', kGAMMA);
+    tlist.AddToList(&fhadrons);
+
+    MHMatrix matrix("MatrixGammas");
+    matrix.AddColumn("MHillas.fWidth");
+    matrix.AddColumn("MHillas.fLength");
+    matrix.AddColumn("MHillas.fWidth*MHillas.fLength/MHillas.fSize");
+    matrix.AddColumn("abs(MHillas.fAsym)");
+    matrix.AddColumn("abs(MHillas.fM3Long)");
+    matrix.AddColumn("abs(MHillas.fM3Trans)");
+    matrix.AddColumn("abs(HillasSource.fHeadTail)");
+    matrix.AddColumn("MHillas.fConc");
+    matrix.AddColumn("MHillas.fConc1");
+    matrix.AddColumn("HillasSource.fDist");
+    matrix.AddColumn("log10(MHillas.fSize)");
+    plist.AddToList(&matrix);
+
+    MHMatrix matrix2("MatrixHadrons");
+    matrix2.AddColumns(&matrix);
+    plist.AddToList(&matrix2);
+
+    MFillH fillmat("MatrixGammas");
+    fillmat.SetFilter(&fgamma);
+    tlist.AddToList(&fillmat);
+
+    MFillH fillmat2("MatrixHadrons");
+    fillmat2.SetFilter(&fhadrons);
+    tlist.AddToList(&fillmat2);
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+
+    // ---------------------------------------------------------
+
+    MTaskList tlist2;
+
+    plist.Replace(&tlist2);
+
+    MReadMarsFile read2("Events", "star2.root");
+    read2.DisableAutoScheme();
+    tlist2.AddToList(&read2);
+
+    MMultiDimDistCalc calc(5);
+    tlist2.AddToList(&calc);
+
+    MFillH fillh("MHHadroness");
+
+    /*
+     MF filter("MMcEvt.fEnergy < 100");
+     fillh.SetFilter(&filter);
+     tlist2.AddToList(&filter);
+     */
+
+    tlist2.AddToList(&fillh);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist2.PrintStatistics();
+
+    plist.FindObject("MHHadroness")->DrawClone();
+    plist.FindObject("MHHadroness")->Print();
+}
Index: trunk/MagicSoft/Mars/macros/star.C
===================================================================
--- trunk/MagicSoft/Mars/macros/star.C	(revision 1337)
+++ trunk/MagicSoft/Mars/macros/star.C	(revision 1337)
@@ -0,0 +1,132 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  5/2002 <mailto:(tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+//  STAR - STandard Analysis and Reconstruction
+//
+//  This macro is the standard converter to convert raw data into image
+//  parameters
+//
+/////////////////////////////////////////////////////////////////////////////
+
+void star()
+{
+    //
+    // This is a demonstration program which calculates the Hillas
+    // parameter out of a Magic root 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);
+
+    //
+    // Uncomment this two line if you want to use MHillasExt instead
+    // of MHillas
+    //
+    MHillasExt hext;
+    plist.AddToList(&hext);
+
+    //
+    // The geometry container must be created by yourself to make sure
+    // that you don't choos a wrong geometry by chance
+    //
+    MGeomCamMagic geomcam;
+    plist.AddToList(&geomcam);
+
+    //
+    // Craete the object which hlods the source positions in the camera
+    // plain in respect to which the image parameters will be calculated.
+    // For real data the containers will be filled by a task.
+    //
+    MSrcPosCam source("Source")
+    source.SetXY(0, 0);
+
+    MSrcPosCam antisrc("AntiSrc");
+    antisrc.SetXY(240, 0);
+
+    plist.AddToList(&source);
+    plist.AddToList(&antisrc);
+
+    //
+    // Now setup the tasks and tasklist:
+    // ---------------------------------
+    //
+    // The first argument is the tree you want to read.
+    //   Events:     Cosmic ray events
+    //   PedEvents:  Pedestal Events
+    //   CalEvents:  Calibration Events
+    //
+    MReadMarsFile read("Events");
+    read.AddFile("~/data/Gamma_0_7_1011*.root");
+    read.AddFile("~/data/prot_N_0*.root");
+    read.DisableAutoScheme();
+
+    MMcPedestalCopy   pcopy;
+    MMcPedestalNSBAdd pnsb;
+    MCerPhotCalc      ncalc;
+    MImgCleanStd      clean;
+    MBlindPixelCalc   blind;
+    MHillasCalc       hcalc;
+    MHillasSrcCalc    csrc1("Source",  "HillasSource");
+    MHillasSrcCalc    csrc2("AntiSrc", "HillasAntiSrc");
+
+    MWriteRootFile write("star2.root");
+    write.AddContainer("MHillas",       "Events");
+    write.AddContainer("HillasSource",  "Events");
+    write.AddContainer("HillasAntiSrc", "Events");
+    write.AddContainer("MMcEvt",        "Events");
+    write.AddContainer("MRawRunHeader", "RunHeaders");
+    write.AddContainer("MMcRunHeader",  "RunHeaders");
+
+    tlist.AddToList(&read);
+    tlist.AddToList(&pcopy);
+    tlist.AddToList(&pnsb);
+    tlist.AddToList(&ncalc);
+    tlist.AddToList(&clean);
+    tlist.AddToList(&blind);
+    tlist.AddToList(&hcalc);
+    tlist.AddToList(&csrc1);
+    tlist.AddToList(&csrc2);
+    tlist.AddToList(&write);
+
+    //
+    // Create and setup the eventloop
+    //
+    MEvtLoop evtloop;
+    evtloop.SetParList(&plist);
+
+    //
+    // Execute your analysis
+    //
+    if (!evtloop.Eventloop())
+        return;
+
+    tlist.PrintStatistics();
+}
Index: trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1336)
+++ trunk/MagicSoft/Mars/manalysis/AnalysisLinkDef.h	(revision 1337)
@@ -21,4 +21,9 @@
 #pragma link C++ class MMcPedestalNSBAdd+;
 
+#pragma link C++ class MHadroness+;
+
+#pragma link C++ class MCompProbCalc+;
+#pragma link C++ class MMultiDimDistCalc+;
+
 #pragma link C++ class MSrcPosCam+;
 #pragma link C++ class MHillas+;
Index: trunk/MagicSoft/Mars/manalysis/MCompProbCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCompProbCalc.cc	(revision 1337)
+++ trunk/MagicSoft/Mars/manalysis/MCompProbCalc.cc	(revision 1337)
@@ -0,0 +1,164 @@
+/* ======================================================================== *\
+!
+! *
+! * 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): Abelardo Moralejo <mailto:moralejo@pd.infn.it>
+!   Author(s): Thomas Bretz, 5/2002 <mailto:moralejo@pd.infn.it>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MCompProbCalc
+//
+// FIXME: Use A huge matrix to evaluate variable bins instead of a
+// histogram
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MCompProbCalc.h"
+
+#include <TH1.h>
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MDataChain.h"
+
+#include "MHCompProb.h"
+#include "MHadroness.h"
+
+ClassImp(MCompProbCalc);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor
+//
+MCompProbCalc::MCompProbCalc(const char *name, const char *title)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MCompProbCalc";
+    fTitle = title ? title : "Composite Probabilities Loop 1/2";
+
+    fData = new TList;
+    fData->SetOwner();
+}
+
+// --------------------------------------------------------------------------
+//
+// Destructor
+//
+MCompProbCalc::~MCompProbCalc()
+{
+    delete fData;
+}
+
+// --------------------------------------------------------------------------
+//
+// Needs:
+//  - MHCompProb
+//  - all data values which were used to build the MHCompProb
+//  - MHadroness
+//
+Bool_t MCompProbCalc::PreProcess(MParList *plist)
+{
+    MHCompProb *p = (MHCompProb*)plist->FindObject("MHCompProb");
+    if (!p)
+    {
+        *fLog << err << dbginf << "MHCompProb not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fHistVar = p->GetHistVar();
+    if (fHistVar->GetSize()==0)
+    {
+        *fLog << err << dbginf << "No Entries in MHCompProb::fHistVar... aborting." << endl;
+        return kFALSE;
+    }
+
+    const TList *rules = p->GetRules();
+    if (rules->GetSize()==0)
+    {
+        *fLog << err << dbginf << "No Entries in MHCompProb::fRules... aborting." << endl;
+        return kFALSE;
+    }
+
+    if (fHistVar->GetSize() != rules->GetSize())
+    {
+        *fLog << err << dbginf << "Number of rules doesn't match number of var.bin histograms.. aborting." << endl;
+        return kFALSE;
+    }
+
+    TIter Next(rules);
+    TObject *data=NULL;
+    while ((data=Next()))
+    {
+        MDataChain *chain = new MDataChain(data->GetName());
+        if (!chain->PreProcess(plist))
+        {
+            delete chain;
+            return kFALSE;
+        }
+        fData->Add(chain);
+    }
+
+    fHadroness = (MHadroness*)plist->FindCreateObj("MHadroness");
+    if (!fHadroness)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Calculate the hadroness (composite propability)
+//  - For each data member search the bin corresponding to the data value.
+//  - The value describes with which probability this value corresponds to
+//    a hadron
+//  - 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
+//
+Bool_t MCompProbCalc::Process()
+{
+    Double_t p = 1;
+
+    TIter NextH(fHistVar);
+    TIter NextD(fData);
+
+    TH1D *hist=NULL;
+
+    Int_t n = 0;
+
+    while ((hist=(TH1D*)NextH()))
+    {
+        MData *data = (MData*)NextD();
+
+        Int_t ibin = hist->FindBin(data->GetValue());
+
+        p *= hist->GetBinContent(ibin) / hist->GetEntries();
+        n++;
+    }
+
+    fHadroness->SetHadroness(pow(p, 1./n));
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MCompProbCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCompProbCalc.h	(revision 1337)
+++ trunk/MagicSoft/Mars/manalysis/MCompProbCalc.h	(revision 1337)
@@ -0,0 +1,33 @@
+#ifndef MARS_MCompProbCalc
+#define MARS_MCompProbCalc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MMcEvt;
+class MParList;
+class MHadroness;
+
+class MCompProbCalc : public MTask
+{
+private:
+    MHadroness *fHadroness; //! Output container (Hadroness)
+
+    TList *fData;           //! List of MDataChains to be used
+    TList *fHistVar;        //! List of variable bin size histograms
+
+    void Fill(TList &list);
+    void SetBinningHistVar();
+
+public:
+    MCompProbCalc(const char *name=NULL, const char *title=NULL);
+    ~MCompProbCalc();
+
+    Bool_t PreProcess(MParList *plist);
+    Bool_t Process();
+
+    ClassDef(MCompProbCalc, 1) // Task to calculate composite probabilities
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/MHadroness.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHadroness.cc	(revision 1337)
+++ trunk/MagicSoft/Mars/manalysis/MHadroness.cc	(revision 1337)
@@ -0,0 +1,69 @@
+/* ======================================================================== *\
+!
+! *
+! * 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 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MHadroness
+//
+// The Value must be in the range [0,1]
+// It should be the value used for gamma/hadron seperation.
+// For quality histograms look at MHHadroness
+//
+/////////////////////////////////////////////////////////////////////////////
+#include "MHadroness.h"
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+ClassImp(MHadroness);
+
+// --------------------------------------------------------------------------
+//
+// Default constructor.
+//
+MHadroness::MHadroness(const char *name, const char *title)
+    : fHadroness(-1)
+{
+    fName  = name  ? name  : "MHadroness";
+    fTitle = title ? title : "Storage container for hadroness value";
+}
+
+// --------------------------------------------------------------------------
+//
+// Reset hadroness, -1 indicates: invalid value
+//
+void MHadroness::Reset()
+{
+    fHadroness = -1;
+}
+
+// --------------------------------------------------------------------------
+//
+// Print the hillas Parameters to *fLog
+//
+void MHadroness::Print(Option_t *) const
+{
+    *fLog << all << GetDescriptor() << ": Hadroness = " << fHadroness << endl;
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MHadroness.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHadroness.h	(revision 1337)
+++ trunk/MagicSoft/Mars/manalysis/MHadroness.h	(revision 1337)
@@ -0,0 +1,26 @@
+#ifndef MARS_MHadroness
+#define MARS_MHadroness
+
+#ifndef MARS_MParContainer
+#include "MParContainer.h"
+#endif
+
+class MHadroness : public MParContainer
+{
+private:
+    Double_t fHadroness; // [0,1] Hadroness
+
+public:
+    MHadroness(const char *name=NULL, const char *title=NULL);
+
+    void Reset();
+
+    virtual void Print(Option_t *opt=NULL) const;
+
+    Double_t GetHadroness() const { return fHadroness; }
+    void     SetHadroness(Double_t h) { fHadroness = h; }
+
+    ClassDef(MHadroness, 1) // Storage Container for the hadroness
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.cc	(revision 1337)
+++ trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.cc	(revision 1337)
@@ -0,0 +1,161 @@
+/* ======================================================================== *\
+!
+! *
+! * 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, 5/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Rudy Bock, 5/2002 <mailto:rkb@mppmu.mpg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//
+// MMultiDimDistCalc
+//
+// Calculated a multidimensional distance. It calculates the distance to
+// all vectors in a given matrix describing Gammas and another one
+// describing Hadrons (non gammas). The shortest distances are avaraged.
+// How many distances are used for avaraging can be specified in the
+// constructor.
+//
+////////////////////////////////////////////////////////////////////////////
+#include "MMultiDimDistCalc.h"
+
+#include "MHMatrix.h" // must be before MLogManip.h
+
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MParList.h"
+#include "MDataChain.h"
+
+#include "MHadroness.h"
+
+ClassImp(MMultiDimDistCalc);
+
+// --------------------------------------------------------------------------
+//
+// Setup histograms and the number of distances which are used for
+// avaraging in CalcDist
+//
+MMultiDimDistCalc::MMultiDimDistCalc(Int_t num, const char *name, const char *title)
+    : fNum(num)
+{
+    //
+    //   set the name and title of this object
+    //
+    fName  = name  ? name  : "MMultiDimDistCalc";
+    fTitle = title ? title : "Composite Probabilities Loop 1/2";
+
+    fData = new TList;
+    fData->SetOwner();
+}
+
+// --------------------------------------------------------------------------
+//
+// Delete the data chains
+//
+MMultiDimDistCalc::~MMultiDimDistCalc()
+{
+    delete fData;
+}
+
+// --------------------------------------------------------------------------
+//
+// Needs:
+//  - MatrixGammas  [MHMatrix]
+//  - MatrixHadrons {MHMatrix]
+//  - MHadroness
+//  - all data containers used to build the matrixes
+//
+// The matrix object can be filles using MFillH. And must be of the same
+// number of columns (with the same meaning).
+//
+Bool_t MMultiDimDistCalc::PreProcess(MParList *plist)
+{
+    fMGammas = (MHMatrix*)plist->FindObject("MatrixGammas", "MHMatrix");
+    if (!fMGammas)
+    {
+        *fLog << err << dbginf << "MatrixGammas [MHMatrix] not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    fMHadrons = (MHMatrix*)plist->FindObject("MatrixHadrons", "MHMatrix");
+    if (!fMHadrons)
+    {
+        *fLog << err << dbginf << "MatrixHadrons [MHMatrix] not found... aborting." << endl;
+        return kFALSE;
+    }
+
+    if (fMGammas->GetM().GetNcols() != fMHadrons->GetM().GetNcols())
+    {
+        *fLog << err << dbginf << "Error matrices have different numbers of columns... aborting." << endl;
+        return kFALSE;
+    }
+
+    TIter Next(fMGammas->GetRules());
+    TObject *data=NULL;
+    while ((data=Next()))
+    {
+        MDataChain *chain = new MDataChain(data->GetName());
+        if (!chain->PreProcess(plist))
+        {
+            delete chain;
+            return kFALSE;
+        }
+        fData->Add(chain);
+    }
+
+    fHadroness = (MHadroness*)plist->FindCreateObj("MHadroness");
+    if (!fHadroness)
+        return kFALSE;
+
+    return kTRUE;
+}
+
+// --------------------------------------------------------------------------
+//
+// Evaluates the avarage over the fNum shortest distances in a
+// multidimensional space to a matrix (set of vectors) describing
+// gammas and hadrons.
+// The hadroness of the event is defines as the avarage distance to the
+// set of gammas (dg) divided by the avarage distance to the set of
+// hadrons (dh). Because this value is in teh range [0, inf] it is
+// transformed into [0,1] by:
+//  H = exp(-dh/dg);
+//
+Bool_t MMultiDimDistCalc::Process()
+{
+    const Double_t ncols = fMGammas->GetM().GetNcols();
+
+    TVector event(ncols);
+
+    Int_t n=0;
+    TIter Next(fData);
+    MData *data = NULL;
+    while ((data=(MData*)Next()))
+        event(n++) = data->GetValue();
+
+    Double_t dg = fMGammas->CalcDist(event, fNum);
+    Double_t dh = fMHadrons->CalcDist(event, fNum);
+
+    fHadroness->SetHadroness(exp(-dh/dg));
+
+    return kTRUE;
+}
+
Index: trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.h	(revision 1337)
+++ trunk/MagicSoft/Mars/manalysis/MMultiDimDistCalc.h	(revision 1337)
@@ -0,0 +1,34 @@
+#ifndef MARS_MMultiDimDistCalc
+#define MARS_MMultiDimDistCalc
+
+#ifndef MARS_MTask
+#include "MTask.h"
+#endif
+
+class MHMatrix;
+class MParList;
+class MHadroness;
+
+class MMultiDimDistCalc : public MTask
+{
+private:
+    Int_t fNum;             // number of distances used for an avarage
+
+    MHMatrix   *fMGammas;   //! Gammas describing matrix
+    MHMatrix   *fMHadrons;  //! Hadrons (non gammas) describing matrix
+
+    MHadroness *fHadroness; //! Output container for calculated hadroness
+
+    TList *fData;           //! Used to store the MDataChains to get the event values
+
+public:
+    MMultiDimDistCalc(Int_t num, const char *name=NULL, const char *title=NULL);
+    ~MMultiDimDistCalc();
+
+    Bool_t PreProcess(MParList *plist);
+    Bool_t Process();
+
+    ClassDef(MMultiDimDistCalc, 1) // Task to calculate multidimensional distances
+};
+
+#endif
Index: trunk/MagicSoft/Mars/manalysis/Makefile
===================================================================
--- trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1336)
+++ trunk/MagicSoft/Mars/manalysis/Makefile	(revision 1337)
@@ -22,5 +22,5 @@
 #  connect the include files defined in the config.mk file
 #
-INCLUDES = -I. -I../mbase -I../mgui -I../mmc -I../mraw
+INCLUDES = -I. -I../mbase -I../mgui -I../mmc -I../mraw -I../mdata -I../mhist
 
 #------------------------------------------------------------------------------
@@ -37,4 +37,7 @@
            MEnergyEstimate.cc \
            MSrcPosCam.cc \
+           MHadroness.cc \
+           MCompProbCalc.cc \
+           MMultiDimDistCalc.cc \
            MHillas.cc \
            MHillasSrc.cc \
Index: trunk/MagicSoft/Mars/mbase/MAGIC.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MAGIC.h	(revision 1337)
@@ -22,5 +22,5 @@
 //     ParticleId for Monte Carlo simulation
 //
-const Int_t kGAMMA  =    0;
+const Int_t kGAMMA  =    1;
 const Int_t kPROTON =   14;
 const Int_t kHELIUM =  402;
Index: trunk/MagicSoft/Mars/mbase/MLogo.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLogo.cc	(revision 1337)
+++ trunk/MagicSoft/Mars/mbase/MLogo.cc	(revision 1337)
@@ -0,0 +1,207 @@
+/* ======================================================================== *\
+!
+! *
+! * 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  05/2002 <mailto:tbretz@astro.uni-wuerzburg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2002
+!
+!
+\* ======================================================================== */
+
+//////////////////////////////////////////////////////////////////////////////
+//                                                                          //
+// MLogo                                                                    //
+//                                                                          //
+// X based logo displayer. Displays a given logo after a call to Popup()    //
+// until Popdown() or the destructor is called, but for a minimum of a      //
+// given number of milliseconds.                                            //
+//                                                                          //
+//////////////////////////////////////////////////////////////////////////////
+#include "MLogo.h"
+
+#include <unistd.h>    // usleep
+#include <iostream.h>  // cout
+#include <sys/time.h>  // gettimeofday
+
+#ifndef XpmSuccess
+#define XpmSuccess       0
+#endif
+#ifndef XpmColorError
+#define XpmColorError    1
+#endif
+
+MLogo::MLogo(int millisec)
+   : fDisplay(0), fLogoWindow(0), fLogoPixmap(0), fMilliSec(millisec)
+{
+    // millisec: time of minimum stayup
+}
+
+void MLogo::Wait() const
+{
+    struct timeval tv;
+
+    gettimeofday(&tv, 0);
+
+    tv.tv_sec  -= fPopupTime.tv_sec;
+    tv.tv_usec -= fPopupTime.tv_usec;
+
+    while (tv.tv_usec < 0)
+    {
+        tv.tv_usec += 1000000;
+        tv.tv_sec--;
+    }
+
+    while (tv.tv_sec > 0)
+        tv.tv_usec += 1000000;
+
+    long sleep = fMilliSec*1000-tv.tv_usec;
+
+    if (sleep <= 0)
+        return;
+
+    usleep(sleep);
+}
+
+Pixmap MLogo::GetLogo() const
+{
+#ifdef XpmVersion
+    int depth = PlanesOfScreen(XDefaultScreenOfDisplay(fDisplay));
+
+    if (depth <= 1)
+        return 0;
+
+    XWindowAttributes win_attr;
+    XGetWindowAttributes(fDisplay, fLogoWindow, &win_attr);
+
+    XpmAttributes attr;
+    attr.valuemask = XpmVisual | XpmColormap | XpmDepth;
+    attr.visual    = win_attr.visual;
+    attr.colormap  = win_attr.colormap;
+    attr.depth     = win_attr.depth;
+
+#ifdef XpmColorKey              // Not available in XPM 3.2 and earlier
+
+    switch (depth)
+    {
+    case 0:
+        attr.valuemask &= ~XpmColorKey;
+        break;
+    case 1:
+        attr.color_key = XPM_MONO;
+        break;
+    case 2:
+        attr.color_key = XPM_GRAY;
+        break;
+    case 3:
+    case 4:
+        attr.color_key = XPM_GRAY4;
+        break;
+    default:
+        attr.color_key = XPM_COLOR;
+    }
+#endif // defined(XpmColorKey)
+
+
+    Pixmap logo;
+#ifdef USE_MAGICLOGO
+#include "../magiclogo.xpm"
+    int ret = XpmCreatePixmapFromData(fDisplay, fLogoWindow,
+                                      mag1, &logo, 0, &attr);
+#else
+#include "../marslogo_neu.xpm"
+    int ret = XpmCreatePixmapFromData(fDisplay, fLogoWindow,
+                                      marslogo_neu_xpm, &logo, 0, &attr);
+#endif
+    XpmFreeAttributes(&attr);
+
+    if (ret == XpmSuccess || ret == XpmColorError)
+        return logo;
+
+    if (logo)
+        XFreePixmap(fDisplay, logo);
+#endif
+    return 0;
+}
+
+void MLogo::Popup()
+{
+#ifdef XpmVersion
+    if (fLogoWindow || fLogoPixmap || fDisplay)
+#endif
+        return;
+
+    fDisplay = XOpenDisplay("");
+    if (!fDisplay)
+        return;
+
+    int screen = DefaultScreen(fDisplay);
+
+    fLogoWindow = XCreateSimpleWindow(fDisplay, DefaultRootWindow(fDisplay),
+                                      -100, -100, 50, 50, 0,
+                                      BlackPixel(fDisplay, screen),
+                                      WhitePixel(fDisplay, screen));
+    fLogoPixmap = GetLogo();
+
+    Window root;
+    int x, y;
+    unsigned int w, h, bw, depth;
+    XGetGeometry(fDisplay, fLogoPixmap,
+                 &root, &x, &y, &w, &h, &bw, &depth);
+
+    Screen *xscreen = XDefaultScreenOfDisplay(fDisplay);
+    x = (WidthOfScreen(xscreen) - w) / 2;
+    y = (HeightOfScreen(xscreen) - h) / 2;
+
+    XMoveResizeWindow(fDisplay, fLogoWindow, x, y, w, h);
+    XSync(fDisplay, False);   // make sure move & resize is done before mapping
+
+    unsigned long valmask  = CWBackPixmap | CWOverrideRedirect;
+
+    XSetWindowAttributes xswa;
+    xswa.background_pixmap = fLogoPixmap;
+    xswa.override_redirect = True;
+    XChangeWindowAttributes(fDisplay, fLogoWindow, valmask, &xswa);
+
+    XMapRaised(fDisplay, fLogoWindow);
+    XSync(fDisplay, False);
+
+    gettimeofday(&fPopupTime, 0);
+}
+
+void MLogo::Popdown()
+{
+    if (fLogoWindow && fLogoPixmap && fDisplay)
+        Wait();
+
+    if (fLogoWindow)
+    {
+        XUnmapWindow(fDisplay, fLogoWindow);
+        XDestroyWindow(fDisplay, fLogoWindow);
+        fLogoWindow = 0;
+    }
+    if (fLogoPixmap)
+    {
+        XFreePixmap(fDisplay, fLogoPixmap);
+        fLogoPixmap = 0;
+    }
+    if (fDisplay)
+    {
+        XSync(fDisplay, False);
+        XCloseDisplay(fDisplay);
+        fDisplay = 0;
+    }
+}
Index: trunk/MagicSoft/Mars/mbase/MLogo.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MLogo.h	(revision 1337)
+++ trunk/MagicSoft/Mars/mbase/MLogo.h	(revision 1337)
@@ -0,0 +1,35 @@
+#ifndef MARS_MLogo
+#define MARS_MLogo
+
+#ifndef __CINT__
+
+#include <X11/Xlib.h>
+
+#include "Xpm.h"
+
+class MLogo
+{
+    Display *fDisplay;         // display handle
+    Window   fLogoWindow;      // window handle
+    Pixmap   fLogoPixmap;      // pixmap handle
+    long     fMilliSec;        // stayup time
+
+    struct timeval fPopupTime; // time of popup
+
+    void   Wait() const;
+    Pixmap GetLogo() const;
+
+public:
+    MLogo(int millisec=777);
+    ~MLogo()
+    {
+        Popdown();
+    }
+
+    void Popup();
+    void Popdown();
+};
+
+#endif
+
+#endif
Index: trunk/MagicSoft/Mars/mbase/MParList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MParList.cc	(revision 1337)
@@ -215,4 +215,36 @@
 // --------------------------------------------------------------------------
 //
+//  Find an object with the same name in the list and replace it with
+//  the new one. If the kIsOwner flag is set and the object was not
+//  created automatically, the object is deleted.
+//
+Bool_t MParList::Replace(MParContainer *cont)
+{
+    //
+    //  check if the object (you want to add) exists
+    //
+    if (!cont)
+        return kFALSE;
+
+    TObject *obj = FindObject(cont->GetName());
+    if (!obj)
+    {
+        *fLog << warn << "No object with the same name '";
+        *fLog << cont->GetName() << "' in list... ignored." << endl;
+        return kFALSE;
+    }
+
+    fContainer->Remove(obj);
+
+    if (TestBit(kIsOwner) && !fAutodelete->FindObject(obj))
+        delete obj;
+
+    *fLog << inf << "MParContainer '" << obj->GetName() << "' found and replaced..." << endl;
+
+    return AddToList(cont);
+}
+
+// --------------------------------------------------------------------------
+//
 //  Find an object in the list.
 //  'name' is the name of the object you are searching for.
Index: trunk/MagicSoft/Mars/mbase/MParList.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MParList.h	(revision 1337)
@@ -42,4 +42,6 @@
     void   AddToList(TObjArray *list);
 
+    Bool_t Replace(MParContainer *obj);
+
     void SetLogStream(MLog *log);
 
Index: trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MReadMarsFile.cc	(revision 1337)
@@ -108,13 +108,26 @@
 Bool_t MReadMarsFile::Notify()
 {
+    Int_t runtype = -1;
+/*
+    const MRawRunHeader *runheader = (MRawRunHeader*)fParList->FindObject("MRawRunHeader");
+    if (runheader)
+        runtype = runheader->GetRunType();
+*/
     //
     // Try to read the new run headers. If reading the new run header
     // was successfull call the ReInits
     //
+    const Int_t idx = GetFileIndex();
+    fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
     if (fRun->Process())
     {
-        *fLog << inf << "MReadMarsFile: Switching to '" << GetFileName() << "' ";
-        *fLog << "(before event #" << GetEventNum()-1 << ")" << endl;
-
+        *fLog << inf << "MReadMarsFile: Switching to #" << GetFileIndex();
+        *fLog << " '" << GetFileName() << "' (before event #";
+        *fLog << GetEventNum()-1 << ")" << endl;
+/*
+        if (runheader)
+            if (runtype != runheader->GetRunType())
+                *fLog << warn << "Warning - You are mixing files with different run types!" << endl;
+*/
         if (fTaskList->ReInit())
             return kTRUE;
@@ -137,13 +150,20 @@
 Bool_t MReadMarsFile::PreProcess(MParList *pList)
 {
+    fParList  = pList;
     fTaskList = (MTaskList*)pList->FindObject("MTaskList");
 
     if (!fRun->PreProcess(pList))
+    {
+        *fLog << err << "Error - PreProcessing MReadMarsFile::fRun... aborting." << endl;
         return kFALSE;
+    }
 
+    const Int_t idx = GetFileIndex();
+    fRun->SetEventNum(idx<0?0:idx); // Assumption: One Entry per File!
     if (!fRun->Process())
+    {
+        *fLog << err << "Error - Processing MReadMarsFile::fRun... aborting." << endl;
         return kFALSE;
-
-    fRun->SetEventNum(0);
+    }
 
     return MReadTree::PreProcess(pList);
Index: trunk/MagicSoft/Mars/mbase/MReadMarsFile.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadMarsFile.h	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MReadMarsFile.h	(revision 1337)
@@ -6,4 +6,5 @@
 #endif
 
+class MParList;
 class MTaskList;
 
@@ -12,4 +13,5 @@
 private:
     MReadTree *fRun;
+    MParList  *fParList;  //! Parlist for reinitialization
     MTaskList *fTaskList; //! Tasklist for reinitialization
 
Index: trunk/MagicSoft/Mars/mbase/MReadTree.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.cc	(revision 1337)
@@ -55,4 +55,5 @@
 #include <TFile.h>           // TFile::GetName
 #include <TChain.h>
+#include <TSystem.h>         // gSystem->ExpandPath
 #include <TGProgressBar.h>
 #include <TChainElement.h>
@@ -746,4 +747,28 @@
 // --------------------------------------------------------------------------
 //
+//  Return the number of the file in the chain, -1 in case of an error
+//
+Int_t MReadTree::GetFileIndex() const
+{
+    return fChain->GetTreeNumber();
+    /*
+    const TString filename = fChain->GetFile()->GetName();
+
+    int i=0;
+    TObject *file = NULL;
+
+    TIter Next(fChain->GetListOfFiles());
+    while ((file=Next()))
+    {
+        if (filename==gSystem->ExpandPathName(file->GetTitle()))
+            return i;
+        i++;
+    }
+    return -1;
+    */
+}
+
+// --------------------------------------------------------------------------
+//
 //  This schedules a TObject which Notify(9 function is called in case
 //  of MReadTree (TChain) switches from one file in the chain to another
@@ -759,5 +784,5 @@
     *fLog << all << GetDescriptor() << dec << endl;
     *fLog << setfill('-') << setw(strlen(GetDescriptor())) << "" << endl;
-    *fLog << " Files:" << endl;
+    *fLog << " Files [Tree]:" << endl;
 
     int i = 0;
@@ -765,7 +790,7 @@
     TObject *obj = NULL;
     while ((obj=Next()))
-        *fLog << " " << i++ << ") " << obj->GetName() << endl;
-
-    *fLog << " Entries: " << fNumEntries << endl;
-    *fLog << " Next Entry: " << fNumEntry << endl;
-}
+        *fLog << " " << i++ << ") " << obj->GetTitle() << " [" << obj->GetName() << "]" << endl;
+
+    *fLog << " Total Number of Entries: " << fNumEntries << endl;
+    *fLog << " Next Entry to read: " << fNumEntry << endl;
+}
Index: trunk/MagicSoft/Mars/mbase/MReadTree.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MReadTree.h	(revision 1337)
@@ -59,4 +59,5 @@
 
     TString GetFileName() const;
+    Int_t   GetFileIndex() const;
 
     virtual void   AddNotify(TObject *obj);
Index: trunk/MagicSoft/Mars/mbase/MTaskList.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MTaskList.cc	(revision 1337)
@@ -303,5 +303,5 @@
     fParList = pList;
 
-    fTasksProcess.Delete();
+    fTasksProcess.Clear();
 
     //
@@ -317,4 +317,6 @@
     while ((task=(MTask*)Next()))
     {
+        *fLog << all << task->GetName() << "... " << flush;
+
         if (CheckClassForProcess(task->IsA()))
             fTasksProcess.Add(task);
@@ -457,8 +459,8 @@
     while ( (task=(MTask*)Next()) )
     {
+        *fLog << all << task->GetName() << "... " << flush;
+
         if (!task->CallPostProcess())
             return kFALSE;
-
-        *fLog << all << task->GetName() << "... " << flush;
     }
 
Index: trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc
===================================================================
--- trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.cc	(revision 1337)
@@ -263,2 +263,21 @@
 }
 
+/*
+Bool_t MWriteAsciiFile::PreProcess(MParList *plist)
+{
+    MDataChain *chain=NULL;
+
+    TIter Next(&fList);
+    while (((MDataChain*)chain=Next()))
+        if (!chain->PreProcess(plist))
+            return kFALSE;
+
+    return MWriteFile::PreProcess(plist);
+}
+
+void MWriteAsciiFile::Add(const char *rule)
+{
+    MDataChain *chain = new MDataChain(rule);
+    fList.Add(chain);
+}
+*/
Index: trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h
===================================================================
--- trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 1336)
+++ trunk/MagicSoft/Mars/mbase/MWriteAsciiFile.h	(revision 1337)
@@ -29,5 +29,7 @@
 
     TString fNameFile;
-
+/*
+    TList fList;
+*/
     virtual void   CheckAndWrite() const;
     virtual Bool_t IsFileOpen() const;
@@ -47,4 +49,9 @@
     void AddContainer(MParContainer *cont, const char *member="", Double_t scale=1);
 
+    /*
+     Bool_t PreProcess(MParList *plist);
+     void Add(const char *rule);
+     */
+
     ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file
 };
Index: trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 1336)
+++ trunk/MagicSoft/Mars/mfilter/FilterLinkDef.h	(revision 1337)
@@ -8,4 +8,5 @@
 #pragma link C++ class MFAlpha+;
 #pragma link C++ class MFTriggerLvl1+;
+#pragma link C++ class MFParticleId+;
 #pragma link C++ class MFDataMember+;
 
Index: trunk/MagicSoft/Mars/mfilter/MFParticleId.cc
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFParticleId.cc	(revision 1337)
+++ trunk/MagicSoft/Mars/mfilter/MFParticleId.cc	(revision 1337)
@@ -0,0 +1,118 @@
+/* ======================================================================== *\
+!
+! *
+! * This file is part of MARS, the MAGIC Analysis and Reconstruction
+! * Software. It is distributed to you in the hope that it can be a useful
+! * and timesaving tool in analysing Data of imaging Cerenkov telescopes.
+! * It is distributed WITHOUT ANY WARRANTY.
+! *
+! * Permission to use, copy, modify and distribute this software and its
+! * documentation for any purpose is hereby granted without fee,
+! * provided that the above copyright notice appear in all copies and
+! * that both that copyright notice and this permission notice appear
+! * in supporting documentation. It is provided "as is" without express
+! * or implied warranty.
+! *
+!
+!
+!   Author(s): Thomas Bretz  07/2001 <mailto:tbretz@uni-sw.gwdg.de>
+!
+!   Copyright: MAGIC Software Development, 2000-2001
+!
+!
+\* ======================================================================== */
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+//   MFParticleId                                                         //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#include "MFParticleId.h"
+
+#include "MParList.h"
+#include "MLog.h"
+#include "MLogManip.h"
+
+#include "MMcEvt.hxx"
+
+ClassImp(MFParticleId);
+
+
+// --------------------------------------------------------------------------
+//
+MFParticleId::MFParticleId(const char *cname, const char type, const Int_t val,
+                           const char *name, const char *title) : fMcEvt(NULL)
+{
+    fContName = cname;
+    Init(type, val, name, title);
+}
+
+// --------------------------------------------------------------------------
+//
+MFParticleId::MFParticleId(const MMcEvt *mcevt, const char type, const Int_t val,
+                           const char *name, const char *title) : fMcEvt(mcevt)
+{
+    Init(type, val, name, title);
+}
+
+// --------------------------------------------------------------------------
+//
+void MFParticleId::Init(const char type, const Int_t val,
+                        const char *name, const char *title)
+{
+    fName  = name  ? name  : "MFParticleId";
+    fTitle = title ? title : "Filter using monte carlo particle id";
+
+    fFilterType = (type=='=' ? kEEqual : kENotEqual);
+
+    if (type!='=' && type!='!')
+        *fLog << warn << dbginf << "Warning: Neither '=' nor '!' specified... using '>'." << endl;
+
+    fValue = val;
+
+    AddToBranchList(Form("%s.fPartId", (const char*)fContName));
+}
+
+// --------------------------------------------------------------------------
+//
+Bool_t MFParticleId::IsExpressionTrue() const
+{
+    return fResult;
+}
+
+// --------------------------------------------------------------------------
+//
+Bool_t MFParticleId::PreProcess(MParList *pList)
+{
+    if (fMcEvt)
+        return kTRUE;
+
+    fMcEvt = (MMcEvt*)pList->FindObject(fContName);
+    if (fMcEvt)
+        return kTRUE;
+
+    *fLog << err << dbginf << fContName << " [MMcEvt] not found... aborting." << endl;
+    return kFALSE;
+}
+
+// --------------------------------------------------------------------------
+//
+Bool_t MFParticleId::Process()
+{
+    const Int_t id = fMcEvt->GetPartId();
+
+    switch (fFilterType)
+    {
+    case kEEqual:
+        fResult = (id == fValue);
+        return kTRUE;
+    case kENotEqual:
+        fResult = (id != fValue);
+        return kTRUE;
+    }
+
+    *fLog << err << dbginf << "Operation unknown..." << endl;
+    return kFALSE;
+}
+
Index: trunk/MagicSoft/Mars/mfilter/MFParticleId.h
===================================================================
--- trunk/MagicSoft/Mars/mfilter/MFParticleId.h	(revision 1337)
+++ trunk/MagicSoft/Mars/mfilter/MFParticleId.h	(revision 1337)
@@ -0,0 +1,45 @@
+#ifndef MARS_MFParticleId
+#define MARS_MFParticleId
+
+/////////////////////////////////////////////////////////////////////////////
+//                                                                         //
+// MFParticleId                                                           //
+//                                                                         //
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef MARS_MFilter
+#include "MFilter.h"
+#endif
+
+class MMcEvt;
+class MParList;
+
+class MFParticleId : public MFilter
+{
+private:
+    const MMcEvt *fMcEvt;
+    TString fContName;
+
+    typedef enum { kEEqual, kENotEqual } FilterType_t;
+    FilterType_t fFilterType;
+
+    Bool_t fResult;
+    Int_t  fValue;
+
+    void Init(const char type, const Int_t val,
+              const char *name, const char *title);
+
+public:
+    MFParticleId(const char *cname="MMcEvt", const char type='=', const Int_t val=0,
+                 const char *name=NULL, const char *title=NULL);
+    MFParticleId(const MMcEvt *mcevt, const char type='=', const Int_t val=0,
+                 const char *name=NULL, const char *title=NULL);
+
+    Bool_t IsExpressionTrue() const;
+    Bool_t PreProcess(MParList *pList);
+    Bool_t Process();
+
+    ClassDef(MFParticleId, 0)		// A Filter for the Level 1 Trigger
+};
+
+#endif
Index: trunk/MagicSoft/Mars/mfilter/Makefile
===================================================================
--- trunk/MagicSoft/Mars/mfilter/Makefile	(revision 1336)
+++ trunk/MagicSoft/Mars/mfilter/Makefile	(revision 1337)
@@ -34,6 +34,7 @@
 	   MF.cc \
 	   MFDataMember.cc \
-	   MFDataChain.cc \
+	   MFParticleId.cc \
 	   MFAlpha.cc
+#	   MFDataChain.cc \
 
 SRCS    = $(SRCFILES)
