Index: /trunk/Mars/msim/MPhotonEvent.cc
===================================================================
--- /trunk/Mars/msim/MPhotonEvent.cc	(revision 9941)
+++ /trunk/Mars/msim/MPhotonEvent.cc	(revision 9942)
@@ -452,4 +452,6 @@
 {
     const UInt_t n = GetNumPhotons();
+    if (n==0)
+        return 0;
 
     Double_t mean = 0;
@@ -463,4 +465,6 @@
 {
     const UInt_t n = GetNumPhotons();
+    if (n==0)
+        return 0;
 
     Double_t mean = 0;
@@ -471,9 +475,41 @@
 }
 
+Double_t MPhotonEvent::GetMeanT() const
+{
+    const UInt_t n = GetNumPhotons();
+    if (n==0)
+        return 0;
+
+    Double_t mean = 0;
+    for (UInt_t i=0; i<n; i++)
+        mean += operator[](i).GetTime();
+
+    return mean / n;
+}
+
+void MPhotonEvent::AddXY(Double_t x, Double_t y)
+{
+    const UInt_t n = GetNumPhotons();
+
+    for (UInt_t i=0; i<n; i++)
+    {
+        MPhotonData &p = operator[](i);
+        p.SetPosition(p.GetPosX()+x, p.GetPosY()+y);
+    }
+}
+
+void MPhotonEvent::SimWavelength(Float_t wmin, Float_t wmax)
+{
+    const UInt_t n = GetNumPhotons();
+
+    for (UInt_t i=0; i<n; i++)
+        operator[](i).SimWavelength(wmin, wmax);
+}
+
 // --------------------------------------------------------------------------
 //
 // Read the Event section from the file
 //
-Int_t MPhotonEvent::ReadCorsikaEvt(MCorsikaFormat *fInFormat, Int_t i)
+Int_t MPhotonEvent::ReadCorsikaEvt(MCorsikaFormat *fInFormat, Int_t id)
 {
     Int_t n = 0;
@@ -505,14 +541,33 @@
     // 1.06GB/ 3s   CPU
     // 1.06GB/22s   REAL
-    Bool_t readError = kFALSE;
-    Float_t * buffer;
-
-    if ( fInFormat->IsEventioFormat() )
+    Float_t *buffer = 0;
+
+    if (fInFormat->IsEventioFormat())
+    {
+        while (1)
         {
-        while (fInFormat->GetNextEvent(&buffer, readError))
-            {
-
-            const Int_t rc = Add(n).FillEventIO(buffer);
-            switch (rc)
+            const Int_t rc = fInFormat->GetNextEvent(&buffer, id);
+            if (rc==kERROR)
+                return kERROR;
+            if (rc==kFALSE)
+                break;
+
+            // Loop over number of photons in bunch
+            while (Add(n).FillEventIO(buffer))
+                n++;
+        }
+    }
+    else
+    {
+        while (1)
+        {
+            const Int_t rc1 = fInFormat->GetNextEvent(&buffer);
+            if (rc1==kERROR)
+                return kERROR;
+            if (rc1==kFALSE)
+                break;
+
+            const Int_t rc2 = Add(n).FillCorsika(buffer, id);
+            switch (rc2)
             {
             case kCONTINUE:  continue;        // No data in this bunch... skip it.
@@ -524,25 +579,6 @@
             // Increase the counter by one
             n++;
-            }
         }
-    else
-        {
-        while (fInFormat->GetNextEvent(&buffer, readError))
-            {
-
-            const Int_t rc = Add(n).FillCorsika(buffer, i);
-            switch (rc)
-            {
-            case kCONTINUE:  continue;        // No data in this bunch... skip it.
-            case kERROR:     return kERROR;   // Error occured
-            //case kFALSE:     return kFALSE;   // End of stream
-            }
-
-            // This is a photon we would like to keep later.
-            // Increase the counter by one
-            n++;
-            }
-        }
-     if (readError)      return kFALSE;
+    }
 
 /*
