Index: /trunk/MagicSoft/Mars/Changelog
===================================================================
--- /trunk/MagicSoft/Mars/Changelog	(revision 1663)
+++ /trunk/MagicSoft/Mars/Changelog	(revision 1664)
@@ -19,4 +19,27 @@
    * macros/collarea.C:
      - some simplifications
+
+   * mhist/MHMcRate.h, mhist/MHMcIntRate.h, mhist/MHEnergyTime.h,
+     mhist/MHEnergyTheta.h, mfileio/MCTReadPreProc.cc, mfileio/MChain.h,
+     mfileio/MReadMarsFile.h, mfileio/MReadTree.cc, mfileio/MWriteAsciiFile.h,
+     mfileio/MWriteRoootFile.[h,cc], manalysis/MMatrixLoop.h, 
+     manalysis/MEnergyEstimate.h, mbase/MGGroupFrame.h, mbase/MGTask.h,
+     mfilter/MFParticleId.h:
+     - updated documentation
+
+   * mfileio/MCT1ReadPreProc.cc:
+     - Changed MSrcPosCam name from Source to MSrcPosCam
+     - changed the way the MC data is filled into the MC container
+     - updated algorithm to read preproc files
+
+   * mfileio/MReadMarsFile.cc:
+     - printed a warning to the screen in case Camera=V0.5
+
+   * mfileio/structures.h:
+     - changed to version 0.6
+
+   * mmc/MMcEvt.hxx:
+     - added GetTelescopePhi
+     - added GetTelescopeTheta
 
    * mdata/MDataChain.[h,cc]:
Index: /trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/manalysis/MEnergyEstimate.h	(revision 1664)
@@ -23,5 +23,5 @@
     Bool_t Process();
 
-    ClassDef(MEnergyEstimate, 0) // Task to estimate the energy
+    ClassDef(MEnergyEstimate, 0) // Task to copy the MC energy (preliminary)
 };
 
Index: /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.h
===================================================================
--- /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/manalysis/MMatrixLoop.h	(revision 1664)
@@ -30,5 +30,5 @@
     Bool_t Process();
 
-    ClassDef(MMatrixLoop, 0)
+    ClassDef(MMatrixLoop, 0) // Task 'reading' events from a MHMatrix
 };
 
Index: /trunk/MagicSoft/Mars/mbase/MGGroupFrame.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MGGroupFrame.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mbase/MGGroupFrame.h	(revision 1664)
@@ -37,5 +37,5 @@
     virtual Bool_t ProcessMessage(Long_t msg, Long_t param1, Long_t param2);
 
-    ClassDef(MGGroupFrame, 0)
+    ClassDef(MGGroupFrame, 0) // A interface to widgets in a group frame (makes live easier)
 };
 
Index: /trunk/MagicSoft/Mars/mbase/MGTask.h
===================================================================
--- /trunk/MagicSoft/Mars/mbase/MGTask.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mbase/MGTask.h	(revision 1664)
@@ -45,5 +45,5 @@
     void CreateGui(TGCompositeFrame *f, TGLayoutHints *layout=NULL);
 
-    ClassDef(MGTask, 0)		//Abstract base class for a task
+    ClassDef(MGTask, 0) // Abstract base class for a task having a gui
 };
 
Index: /trunk/MagicSoft/Mars/mdatacheck/MGDisplayAdc.h
===================================================================
--- /trunk/MagicSoft/Mars/mdatacheck/MGDisplayAdc.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mdatacheck/MGDisplayAdc.h	(revision 1664)
@@ -44,5 +44,4 @@
                  UInt_t w=800, UInt_t h=500,
                  UInt_t options = kMainFrame|kVerticalFrame);
-
     ~MGDisplayAdc();
 
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.cc	(revision 1664)
@@ -112,20 +112,22 @@
 void MCT1ReadPreProc::AddFile(const char *txt)
 {
-    ifstream *store = fIn;
-
-    fIn = new ifstream(gSystem->ExpandPathName(txt));
-
-    if (!(*fIn))
-    {
-        *fLog << warn << "Cannot open file '" << txt << "'... ignored." << endl;
-        fIn = store;
+    const TString fname = gSystem->ExpandPathName(txt);
+
+    if (!CheckHeader(fname))
+    {
+        *fLog << warn << "WARNING - Problem reading header... ignored." << endl;
         return;
     }
 
-    fEntries += GetNumEvents();
-
-    delete fIn;
-
-    fIn = store;
+    const Int_t n = GetNumEvents(fname);
+    if (n==0)
+    {
+        *fLog << warn << "WARNING - File contains no data... ignored." << endl;
+        return;
+    }
+
+    fEntries += n;
+
+    *fLog << inf << "File " << txt << " contains " << n << " events (Total=" << fEntries << ")" << endl;
 
     fFileNames->AddLast(new TNamed(txt, ""));
@@ -390,9 +392,22 @@
            &dummy/*&outpars.eruntype*/,   &outpars.iproc_mjdate);
 
-    if (STRUCT_VERSION != structversion)
+    if (fpreprocversion<0.6)
+    {
+        *fLog << err << "Sorry only files from PreProc V0.6 and newer are supported." << endl;
+        return kFALSE;
+    }
+
+    //
+    // This is a stupid way of getting rid of numerical uncertanties when
+    // comparing floating point numbers (Argh...)
+    //
+    TString s1 = Form("%.2f", structversion);
+    TString s2 = Form("%.2f", STRUCT_VERSION);
+
+    if (s1 != s2)
     {
         *fLog << warn << "WARNING: Version of C-structures of file (V";
-        *fLog << structversion << ") not identical with current structures (V";
-        *fLog << STRUCT_VERSION << ")" << endl;
+        *fLog << s1 << ") not identical with current structures (V";
+        *fLog << s2 << ")" << endl;
     }
 
@@ -404,5 +419,5 @@
 }
 
-Bool_t MCT1ReadPreProc::ReadRunFooter()
+Int_t MCT1ReadPreProc::ReadRunFooter()
 {
     char cheadertitle[iHEADERTITLELENGTH];
@@ -420,5 +435,5 @@
     {
         fIn->seekg(-iHEADERTITLELENGTH, ios::cur);
-        return kFALSE;
+        return 0;
     }
 
@@ -444,16 +459,22 @@
      */
 
-    fNumFilterEvts += filterres.ifilter_passed_evts;
+    if (fNumEventsInRun!=(UInt_t)filterres.ifilter_passed_evts)
+    {
+        *fLog << err << "ERROR! Number of events in run (" << (UInt_t)filterres.ifilter_passed_evts;
+        *fLog << ") doesn't match number of read events (";
+        *fLog << fNumEventsInRun << ")" << endl;
+        *fLog << "       File corrupted." << endl;
+        return -1;
+    }
+
+    fNumFilterEvts += fNumEventsInRun;
     fNumRuns++;
 
-    *fLog << inf << "Read " << fNumEventsInRun << " events from run." << endl;
-
-    if (fNumEventsInRun!=(UInt_t)filterres.ifilter_passed_evts)
-    {
-        *fLog << warn << "WARNING! Number of events in run doesn't match number of read events." << endl;
-        *fLog << "         File might be corrupt." << endl;
-    }
-
-    return kTRUE;
+    *fLog << inf << "Read " << fNumEventsInRun << " events from run (Total=";
+    *fLog << fNumFilterEvts << "/" << fEntries << " [";
+    *fLog << 100*fNumFilterEvts/fEntries << "%], Runs=" << fNumRuns << ")";
+    *fLog << endl;
+
+    return 1;
 }
 
@@ -481,15 +502,6 @@
     // 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;
+    const TString name  = file->GetName();
+    const TString fname = gSystem->ExpandPathName(name);
 
     //
@@ -498,23 +510,71 @@
     fFileNames->Remove(file);
 
+    *fLog << inf << "Open file: '" << name << "'" << endl;
+
+    if (!CheckHeader(fname))
+        return kFALSE;
+
+    fIn = new ifstream(fname);
+
     *fLog << inf << "-----------------------------------------------------------------------" << endl;
 
-    *fLog << "File contains " << GetNumEvents() << " events." << endl;
-
-    // WORKAROUND for not working seekg(0) in GetNumEvents
-    fIn->close();
-    fIn->open(gSystem->ExpandPathName(name));
-
-    Bool_t rc = ReadRunHeader();
-
-    if (!rc)
+    if (!ReadRunHeader())
+    {
         *fLog << warn << "Unable to read first run header... skipping file." << endl;
-
-    return rc;
-}
-
-Int_t MCT1ReadPreProc::GetNumEvents()
-{
-    *fLog << inf << "Scanning file for size" << flush;
+        return kFALSE;
+    }
+
+    return kTRUE;
+}
+
+Bool_t MCT1ReadPreProc::CheckHeader(const TString fname) const
+{
+    ifstream fin(fname);
+    if (!fin)
+    {
+        *fLog << dbginf << err << "ERROR - Cannot open file '" << fname << "'" << endl;
+        return kFALSE;
+    }
+
+    char cheadertitle[iHEADERTITLELENGTH];
+    fin.read(cheadertitle, iHEADERTITLELENGTH);
+
+    Float_t fpreprocversion, structversion, dummy;
+
+    sscanf(cheadertitle, cTITLE_TEMPLATE,
+           &fpreprocversion, &structversion,
+           &dummy, &dummy, &dummy, &dummy);
+
+    if (fpreprocversion < 0.6)
+    {
+        *fLog << dbginf << err << "ERROR - You must use PreProc V0.6 or higher." << endl;
+        return kFALSE;
+    }
+
+    if (STRUCT_VERSION > structversion)
+    {
+        *fLog << warn << "WARNING: Version of C-structures of file (V";
+        *fLog << structversion << ") newer than current structures (V";
+        *fLog << STRUCT_VERSION << ")" << endl;
+    }
+
+    *fLog << "Current structures: " << STRUCT_VERSION << "  ";
+    *fLog << "Structures in file: " << structversion << "  ";
+    *fLog << "Used preproc version: " << fpreprocversion << endl;
+
+    return kTRUE;
+}
+
+
+Int_t MCT1ReadPreProc::GetNumEvents(const TString fname) const
+{
+    *fLog << inf << "Scanning file " << fname << " for size" << flush;
+
+    ifstream fin(fname);
+    if (!fin)
+    {
+        *fLog << dbginf << err << "ERROR - Opening file." << endl;
+        return 0;
+    }
 
     const TString m(cEND_EVENTS_TEMPLATE);
@@ -525,30 +585,31 @@
     Int_t nruns = 0;
 
-    while (!fIn->eof())
-    {
-        fIn->seekg(iHEADERTITLELENGTH, ios::cur);
-        fIn->seekg(sizeof(struct outputpars), ios::cur);
+    while (!fin.eof() && fin.peek()!=EOF)
+    {
+        fin.seekg(iHEADERTITLELENGTH, ios::cur);
+        fin.seekg(sizeof(struct outputpars), ios::cur);
 
         while (1)
         {
-            if (fIn->peek()==cEND_EVENTS_TEMPLATE[0])
+            if (fin.peek()==cEND_EVENTS_TEMPLATE[0])
             {
                 char cheadertitle[iHEADERTITLELENGTH];
-                fIn->read(cheadertitle, iHEADERTITLELENGTH);
+                fin.read(cheadertitle, iHEADERTITLELENGTH);
 
                 const TString s = cheadertitle;
                 if (s.BeginsWith(test))
                 {
-                    fIn->seekg(sizeof(struct filterresults), ios::cur);
+                    fin.seekg(sizeof(struct filterresults), ios::cur);
                     nruns++;
                     break;
                 }
 
-                fIn->seekg(-iHEADERTITLELENGTH, ios::cur);
+                fin.seekg(-iHEADERTITLELENGTH, ios::cur);
             }
 
-            fIn->seekg(sizeof(struct eventrecord), ios::cur);
-            if (fIn->eof())
+            fin.seekg(sizeof(struct eventrecord), ios::cur);
+            if (fin.eof())
                 break;
+
             nevts++;
         }
@@ -746,13 +807,20 @@
         // must be an event
         //
-        if (!ReadRunFooter())
+        switch (ReadRunFooter())
+        {
+        case -1:
+            return kFALSE;
+        case 0:
             return kTRUE;
+        }
 
         *fLog << inf << "Footer found." << endl;
+
+        const char c = fIn->peek();
 
         //
         // No after reading the footer check if we reached the end of the file
         //
-        if (fIn->eof())
+        if (fIn->eof() || c==EOF)
         {
             *fLog << "End of file." << endl;
@@ -763,5 +831,5 @@
         // If the eof isn't reached a new header must follow. Check for it.
         //
-        if (fIn->peek()!=cTITLE_TEMPLATE[0])
+        if (c!=cTITLE_TEMPLATE[0])
         {
             *fLog << inf << "Error finding new run header in file (possible EOF)... skipping rest of file." << endl;
@@ -813,4 +881,5 @@
     *fLog << "Number of Events read from file: " << fNumEvents << endl;
     *fLog << "Number of Runs read from file:   " << fNumRuns << endl;
+    *fLog << "Number of events detected first: " << fEntries << endl;
 
     if (fNumEvents!=fNumFilterEvts)
Index: /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MCT1ReadPreProc.h	(revision 1664)
@@ -42,9 +42,10 @@
     Bool_t OpenNextFile();
 
-    Int_t  GetNumEvents();
+    Int_t  GetNumEvents(const TString name) const;
+    Bool_t CheckHeader(const TString fname) const;
 
     void   ReadPedestals();
     Bool_t ReadRunHeader();
-    Bool_t ReadRunFooter();
+    Int_t  ReadRunFooter();
     Bool_t CheckFilePosition();
     void   ProcessRunHeader(const struct outputpars &outpars);
Index: /trunk/MagicSoft/Mars/mfileio/MChain.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MChain.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MChain.h	(revision 1664)
@@ -22,5 +22,5 @@
     Int_t LoadTree(Int_t entry);
 
-    ClassDef(MChain, 1)
+    ClassDef(MChain, 1) // Class derived from TChain to give access to Notify-return value
 };
 
Index: /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.cc	(revision 1664)
@@ -160,4 +160,11 @@
             *fLog << "in this case you may get less photons than you would expect." << endl;
         }
+        if (mcheader->GetCamVersion==50)
+        {
+            *fLog << warn << "Warning - You are using a file created with Camera 0.5." << endl;
+            *fLog << "In this camera version some events have undefined Impact-Values" << endl;
+            *fLog << "(MMcEvt::fImpact) Please don't use it for MC studies using the" << endl;
+            *fLog << "impact parameter." << endl;
+        }
     }
 
Index: /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MReadMarsFile.h	(revision 1664)
@@ -26,5 +26,5 @@
     Int_t AddFile(const char *fname);
 
-    ClassDef(MReadMarsFile, 1)	// Reads a tree from file(s)
+    ClassDef(MReadMarsFile, 1)	// Reads a tree from file(s) and the information from the 'RunHeader'-tree
 };
 
Index: /trunk/MagicSoft/Mars/mfileio/MReadTree.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MReadTree.cc	(revision 1664)
@@ -55,5 +55,4 @@
 #include <TFile.h>           // TFile::GetName
 #include <TSystem.h>         // gSystem->ExpandPath
-//#include <TGProgressBar.h>
 #include <TChainElement.h>
 #include <TOrdCollection.h>
Index: /trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MWriteAsciiFile.h	(revision 1664)
@@ -40,5 +40,5 @@
     void AddColumns(MParContainer *cont);
 
-    ClassDef(MWriteAsciiFile, 0) // Class to write one container to an ascii file
+    ClassDef(MWriteAsciiFile, 0) // Class to write data into an ascii file
 };
 
Index: /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.cc	(revision 1664)
@@ -131,5 +131,5 @@
     //
 
-    *fLog << inf << "Output File closed and deleted." << endl;
+    *fLog << inf << "Output File closed and object deleted." << endl;
 }
 
Index: /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/MWriteRootFile.h	(revision 1664)
@@ -95,5 +95,5 @@
     void Print(Option_t *t=NULL) const;
 
-    ClassDef(MWriteRootFile, 1)	// Class to write one container to a root file
+    ClassDef(MWriteRootFile, 1)	// Task to write data into a root file
 };
 
Index: /trunk/MagicSoft/Mars/mfileio/structures.h
===================================================================
--- /trunk/MagicSoft/Mars/mfileio/structures.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfileio/structures.h	(revision 1664)
@@ -33,5 +33,5 @@
 #define _structures_h_ "__structures_h__"
 
-#define STRUCT_VERSION 0.5
+#define STRUCT_VERSION 0.6
 
 #define iHEADERTITLELENGTH 60
Index: /trunk/MagicSoft/Mars/mfilter/MFParticleId.h
===================================================================
--- /trunk/MagicSoft/Mars/mfilter/MFParticleId.h	(revision 1663)
+++ /trunk/MagicSoft/Mars/mfilter/MFParticleId.h	(revision 1664)
@@ -42,5 +42,5 @@
     Bool_t Process();
 
-    ClassDef(MFParticleId, 1)		// A Filter for the Level 1 Trigger
+    ClassDef(MFParticleId, 1) // A Filter for the (corsika) particle Id
 };
 
