Index: trunk/MagicSoft/Mars/Changelog
===================================================================
--- trunk/MagicSoft/Mars/Changelog	(revision 715)
+++ trunk/MagicSoft/Mars/Changelog	(revision 716)
@@ -2,4 +2,16 @@
 
  2000/04/02: Thomas Bretz
+ 
+   * mraw/MRawEvtHeader.h, mraw/MRawFileWrite.cc:
+     - added constants (kTT*) for trigger type
+   
+   * manalysis/MImgCleanStd.[h,cc]:
+     - added changeable cleaning levels
+ 
+   * manalysis/MHillas.cc:
+     - added some more sanity checks to the calculation
+     
+   * manalysis/MCT1ReadAscii.[h,cc]:
+     - added some kind of chain feature (AddFile) to process more than one file
  
    * mgui/MGeomPix.[h,c]:
Index: trunk/MagicSoft/Mars/Makefile.conf.general
===================================================================
--- trunk/MagicSoft/Mars/Makefile.conf.general	(revision 715)
+++ trunk/MagicSoft/Mars/Makefile.conf.general	(revision 716)
@@ -3,4 +3,5 @@
 #
 
+ROOTVER    =  `root-config --version`
 ROOTLIBS   =  `root-config --libs`
 ROOTGLIBS  =  `root-config --glibs`
@@ -11,5 +12,5 @@
 #
 
-DEFINES	  = -D__MARS__
+DEFINES	  = -D__MARS__ -DROOTVER=\"$(ROOTVER)\"
 
 CXXFLAGS  = $(ROOTCFLAGS) $(INCLUDES) $(OPTIM) $(DEBUG) $(DEFINES)
Index: trunk/MagicSoft/Mars/macros/CT1Hillas.C
===================================================================
--- trunk/MagicSoft/Mars/macros/CT1Hillas.C	(revision 715)
+++ trunk/MagicSoft/Mars/macros/CT1Hillas.C	(revision 716)
@@ -40,5 +40,8 @@
     //  4) fill the hillas into the histograms
     //
-    MCT1ReadAscii read("CT1_97_on1.dat") ;
+    MCT1ReadAscii read;
+    read.AddFile("CT1_99_off1.dat");
+    read.AddFile("CT1_99_off2.dat");
+
     MImgCleanStd  clean;
     MHillasCalc   hcalc;
Index: trunk/MagicSoft/Mars/macros/readCT1.C
===================================================================
--- trunk/MagicSoft/Mars/macros/readCT1.C	(revision 715)
+++ trunk/MagicSoft/Mars/macros/readCT1.C	(revision 716)
@@ -42,5 +42,10 @@
 
         clean.Process();
-        hcalc.Process();
+
+        if (hcalc.Process()==kCONTINUE)
+        {
+            cout << "skipped." << endl;
+            continue;
+        }
 
         hillas.Print();
Index: trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc	(revision 715)
+++ trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.cc	(revision 716)
@@ -9,4 +9,6 @@
 #include <fstream.h>
 
+#include <TArrayC.h>
+
 #include "MLog.h"
 #include "MLogManip.h"
@@ -28,5 +30,75 @@
     // remember file name for opening the file in the preprocessor
     //
-    fFileName = fname;
+    fFileNames = new TArrayC;
+    if (fname)
+        AddFile(fname);
+}
+
+MCT1ReadAscii::~MCT1ReadAscii()
+{
+    delete fFileNames;
+    if (fIn)
+        delete fIn;
+}
+
+void MCT1ReadAscii::AddFile(const char *txt)
+{
+    //
+    // Add this file as the last entry in the chain
+    //
+    const int   sz  = fFileNames->GetSize();
+    const int   tsz = strlen(txt)+1;
+
+    fFileNames->Set(sz+tsz);
+
+    memcpy(fFileNames->GetArray()+sz, txt, tsz);
+}
+
+Bool_t MCT1ReadAscii::OpenNextFile()
+{
+    //
+    // open the input stream and check if it is really open (file exists?)
+    //
+    if (fIn)
+        delete fIn;
+    fIn = NULL;
+
+    const int arrsz = fFileNames->GetSize();
+
+    if (arrsz<1)
+        return kFALSE;
+
+    //
+    // open the file which is the first one in the chain
+    //
+    const char *name = fFileNames->GetArray();
+
+    fIn = new ifstream(name);
+    if (!(*fIn))
+    {
+        *fLog << dbginf << "Cannot open file '" << name << "'" << endl;
+        return kFALSE;
+    }
+
+    //
+    // remove the first entry from the chain
+    //
+    *fLog << "Open file: '" << name << "'" << endl;
+
+    //
+    // create the new char array containing the filenames to process
+    //
+    const int sz  = strlen(name)+1;
+
+    char *dummy = new char[arrsz-sz];
+    memcpy(dummy, name+sz, arrsz-sz);
+
+    //
+    // dummy will be deleted by the destructor of fFileNames
+    //
+    fFileNames->Adopt(arrsz-sz, dummy);
+
+    return kTRUE;
+
 }
 
@@ -38,12 +110,8 @@
 
     //
-    // open the input stream and check if it is really open (file exists?)
-    //
-    fIn = new ifstream(fFileName);
-    if (!(*fIn))
-    {
-        *fLog << dbginf << "Cannot open file." << endl;
-        return kFALSE;
-    }
+    // Try to open at least one (the first) file
+    //
+    if (!OpenNextFile())
+        return kFALSE;
 
     //
@@ -141,8 +209,9 @@
 
     //
-    // check if we are done
+    // 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 (fIn->eof())
-        return kFALSE;
+        return OpenNextFile() ? kCONTINUE : kFALSE;
 
     //
@@ -163,12 +232,2 @@
 }
 
-Bool_t MCT1ReadAscii::PostProcess()
-{
-    //
-    // close and delete the input stream
-    //
-    delete fIn;
-
-    return kTRUE;
-}
-
Index: trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.h	(revision 715)
+++ trunk/MagicSoft/Mars/manalysis/MCT1ReadAscii.h	(revision 716)
@@ -6,4 +6,5 @@
 #endif
 
+class TArrayC;
 class MCerPhotEvt;
 class MPedestalCam;
@@ -12,8 +13,11 @@
 {
 private:
-    TString       fFileName;    //! the file name of the string
-    ifstream     *fIn;          //! the inputfile
-    MCerPhotEvt  *fNphot;       //! the data container for all data.
-    MPedestalCam *fPedest;      //! ct1 pedestals
+    TString       fFileName;    // the file name of the string
+    ifstream     *fIn;          // the inputfile
+    MCerPhotEvt  *fNphot;       // the data container for all data.
+    MPedestalCam *fPedest;      // ct1 pedestals
+    TArrayC      *fFileNames;   // Array which stores the \0-terminated filenames
+
+    Bool_t OpenNextFile();
 
     void ReadPedestals();
@@ -21,11 +25,14 @@
 
 public:
-    MCT1ReadAscii(const char *filename,
+    MCT1ReadAscii(const char *filename=NULL,
                   const char *name=NULL,
                   const char *title=NULL);
 
+    ~MCT1ReadAscii();
+
+    void AddFile(const char *fname);
+
     Bool_t PreProcess(MParList *pList);
     Bool_t Process();
-    Bool_t PostProcess();
 
     ClassDef(MCT1ReadAscii, 0)	// Reads the CT1 data file
Index: trunk/MagicSoft/Mars/manalysis/MHillas.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 715)
+++ trunk/MagicSoft/Mars/manalysis/MHillas.cc	(revision 716)
@@ -99,4 +99,9 @@
 Bool_t MHillas::Calc(MGeomCam &geom, MCerPhotEvt &evt)
 {
+    //
+    // Calculate the Hillas parameters from a cerenkov photon event
+    // (The calcualtion is some kind of two dimentional statistics)
+    //
+
     const UInt_t nevt = evt.GetNumPixels();
 
@@ -104,5 +109,5 @@
     // sanity check
     //
-    if (nevt<2)
+    if (nevt <= 2)
         return kFALSE;
 
@@ -115,4 +120,8 @@
     fSize = 0;
 
+    //
+    // FIXME! npix should be retrieved from MCerPhotEvt
+    //
+    UShort_t npix=0;
     for (UInt_t i=0; i<nevt; i++)
     {
@@ -129,5 +138,13 @@
         xmean += nphot * gpix.GetX(); // [mm]
         ymean += nphot * gpix.GetY(); // [mm]
+
+        npix++;
     }
+
+    //
+    // sanity check
+    //
+    if (fSize==0 || npix<=2)
+        return kFALSE;
 
     xmean /= fSize; // [mm]
Index: trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 715)
+++ trunk/MagicSoft/Mars/manalysis/MImgCleanStd.cc	(revision 716)
@@ -11,5 +11,7 @@
 ClassImp(MImgCleanStd)
 
-MImgCleanStd::MImgCleanStd(const char *name, const char *title)
+MImgCleanStd::MImgCleanStd(const Float_t lvl1, const Float_t lvl2,
+                           const char *name, const char *title)
+    : fCleanLvl1(lvl1), fCleanLvl2(lvl2)
 {
     //
@@ -18,12 +20,13 @@
   
     *fName  = name  ? name  : "MImgCleanStd";
-    *fTitle = name  ? name  : "Task which does a standard image cleaning";
-}
-
-void MImgCleanStd::CleanLevel1()
+    *fTitle = title ? title : "Task which does a standard image cleaning";
+}
+
+void MImgCleanStd::CleanStep1()
 {
     //
     //  This method looks for all pixels with an entry (photons)
     //  that is three times bigger than the noise of the pixel
+    //  (std: 3 sigma, clean level 1)
     //
 
@@ -41,10 +44,10 @@
         const Float_t noise = pix.GetErrorPhot();
 
-        if (entry < 3 * noise )
+        if (entry < fCleanLvl1 * noise )
             pix.SetPixelUnused();
     }
 }
 
-void MImgCleanStd::CleanLevel2()
+void MImgCleanStd::CleanStep2()
 {
     //
@@ -113,10 +116,10 @@
 } 
 
-void MImgCleanStd::CleanLevel3()
+void MImgCleanStd::CleanStep3()
 {
     //
     //   Look for the boundary pixels around the core pixels
-    //   if a pixel has more than 2.5 sigma, and a core neigbor
-    //   it is declared as used.
+    //   if a pixel has more than 2.5 (clean level 2) sigma, and
+    //   a core neigbor it is declared as used.
     //
     const Int_t entries = fEvt->GetNumPixels();
@@ -141,5 +144,5 @@
         const Float_t noise = pix.GetErrorPhot();
 
-        if (entry <= 2.5 * noise )
+        if (entry <= fCleanLvl2 * noise )
             continue;
 
@@ -198,7 +201,7 @@
 Bool_t MImgCleanStd::Process()
 {
-    CleanLevel1();
-    CleanLevel2();
-    CleanLevel3();
+    CleanStep1();
+    CleanStep2();
+    CleanStep3();
 
     return kTRUE;
Index: trunk/MagicSoft/Mars/manalysis/MImgCleanStd.h
===================================================================
--- trunk/MagicSoft/Mars/manalysis/MImgCleanStd.h	(revision 715)
+++ trunk/MagicSoft/Mars/manalysis/MImgCleanStd.h	(revision 716)
@@ -18,10 +18,14 @@
     MCerPhotEvt *fEvt;
 
+    Float_t fCleanLvl1;
+    Float_t fCleanLvl2;
+
 public:
-    MImgCleanStd(const char *name=NULL, const char *title=NULL) ;
+    MImgCleanStd(const Float_t lvl1=3.0, const Float_t lvl2=2.5,
+                 const char *name=NULL, const char *title=NULL);
 
-    void CleanLevel1();
-    void CleanLevel2();
-    void CleanLevel3();
+    void CleanStep1();
+    void CleanStep2();
+    void CleanStep3();
 
     Bool_t PreProcess (MParList *pList);
Index: trunk/MagicSoft/Mars/merpp.cc
===================================================================
--- trunk/MagicSoft/Mars/merpp.cc	(revision 715)
+++ trunk/MagicSoft/Mars/merpp.cc	(revision 716)
@@ -37,4 +37,5 @@
     gLog << "      MARS Merging and Preprocessing Program" << endl ;
     gLog << "            Compiled on <" << __DATE__ << ">" << endl ;
+    gLog << "               Using ROOT v" << ROOTVER << endl ;
     gLog << "==================================================" << endl ;
     gLog << endl;
Index: trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 715)
+++ trunk/MagicSoft/Mars/mraw/MRawEvtHeader.h	(revision 716)
@@ -10,4 +10,13 @@
 class MArrayB;
 class MRawRunHeader;
+
+//
+// Trigger Typed (TT)
+//
+enum {
+    kTTEvent       = 0,
+    kTTPedestal    = 1,
+    kTTCalibration = 2
+};
 
 class MRawEvtHeader : public MParContainer
@@ -27,5 +36,5 @@
 
     //
-    // Informations only needed to read the raw file
+    // Informations only needed to read the raw file correctly
     //
     UShort_t fTrigType;        //! Trigger Type of this event
Index: trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc
===================================================================
--- trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 715)
+++ trunk/MagicSoft/Mars/mraw/MRawFileWrite.cc	(revision 716)
@@ -15,4 +15,6 @@
 
 #include "MLog.h"
+#include "MLogManip.h"
+
 #include "MParList.h"
 #include "MRawRunHeader.h"
@@ -142,16 +144,21 @@
     switch (type)
     {
-    case 0:
+    case kTTEvent:
         fTData->Fill();
-        break;
-    case 1:
+        return kTRUE;
+
+    case kTTPedestal:
         fTPedestal->Fill();
-        break;
-    case 2:
+        return kTRUE;
+
+    case kTTCalibration:
         fTCalibration->Fill();
-        break;
+        return kTRUE;
     }
 
-    return kTRUE;
+    *fLog << dbginf << "Got wrong number for the trigger type: " << type;
+    *fLog << "  - skipping" << endl;
+
+    return kCONTINUE;
 }
 
