Index: trunk/Mars/msim/MPhotonData.cc
===================================================================
--- trunk/Mars/msim/MPhotonData.cc	(revision 9936)
+++ trunk/Mars/msim/MPhotonData.cc	(revision 9937)
@@ -16,8 +16,8 @@
 !
 !
-!   Author(s): Thomas Bretz, 12/2000 <mailto:tbretz@astro.uni-wuerzburg.de>
+!   Author(s): Thomas Bretz, 12/2000 <mailto:thomas.bretz@epfl.ch>
 !   Author(s): Qi Zhe,       06/2007 <mailto:qizhe@astro.uni-wuerzburg.de>
 !
-!   Copyright: CheObs Software Development, 2000-2009
+!   Copyright: CheObs Software Development, 2000-2010
 !
 !
@@ -34,5 +34,9 @@
 //   Version 1:
 //   ----------
-//    - First implementation
+//    * First implementation
+//
+//   Version 2:
+//   ----------
+//    - fNumPhotons
 //
 /////////////////////////////////////////////////////////////////////////////
@@ -57,5 +61,5 @@
 MPhotonData::MPhotonData(/*const char *name, const char *title*/)
     : fPosX(0), fPosY(0), fCosU(0), fCosV(0), fTime(0), fWavelength(0),
-    fNumPhotons(1), fProductionHeight(0), fPrimary(MMcEvtBasic::kUNDEFINED),
+    /*fNumPhotons(1),*/ fProductionHeight(0), fPrimary(MMcEvtBasic::kUNDEFINED),
     fTag(-1), fWeight(1)
 {
@@ -82,5 +86,5 @@
     MPhotonData &d = static_cast<MPhotonData&>(obj);
 
-    d.fNumPhotons       = fNumPhotons;
+//    d.fNumPhotons       = fNumPhotons;
     d.fPosX             = fPosX;
     d.fPosY             = fPosY;
@@ -185,5 +189,5 @@
 
     fPrimary    = MMcEvtBasic::kUNDEFINED;
-    fNumPhotons =  1;
+//    fNumPhotons =  1;
     fTag        = -1;
     fWeight     =  1;
@@ -201,8 +205,14 @@
 // system intpo our own.
 //
-Int_t MPhotonData::FillCorsika(Float_t f[7])
+Int_t MPhotonData::FillCorsika(Float_t f[7], Int_t i)
 {
     const UInt_t n = TMath::Nint(f[0]);
     if (n==0)
+        // FIXME: Do we need to decode the rest anyway?
+        return kCONTINUE;
+
+    // Check reuse
+    const Int_t reuse = (n/1000)%100; // Force this to be 1!
+    if (reuse!=i)
         return kCONTINUE;
 
@@ -210,13 +220,4 @@
     fWavelength = n%1000;
     fPrimary    = MMcEvtBasic::ParticleId_t(n/100000);
-    fNumPhotons = (n/1000)%100; // Force this to be 1!
-
-    if (fNumPhotons!=1)
-    {
-        // FIXME: Could be done in MPhotonEvent::ReadCorsikaEvent
-        gLog << err << "ERROR - MPhotonData::FillCorsika: fNumPhotons not 1, but " << fNumPhotons << endl;
-        gLog << "        This is not yet supported." << endl;
-        return kERROR;
-    }
 
     // x=north, y=west
@@ -254,4 +255,10 @@
 Int_t MPhotonData::FillEventIO(Float_t f[8])
 {
+    if (TMath::Nint(f[6])!=1)
+    {
+        gLog << err << "ERROR - Bunch sizes != 1 are not supported." << endl;
+        return kFALSE;
+    }
+
     fPosX             =  f[1];              // xpos relative to telescope [cm]
     fPosY             = -f[0];              // ypos relative to telescope [cm]
@@ -260,7 +267,6 @@
     fTime             =  f[4];              // a relative arival time [ns]
     fProductionHeight =  f[5];              // altitude of emission [cm]
-    fNumPhotons       =  TMath::Nint(f[6]); // photons in this bunch
+//    fNumPhotons       =  TMath::Nint(f[6]); // photons in this bunch
     fWavelength       =  TMath::Nint(f[7]); // so far always zeor = unspec. [nm]
-
 
     // Now reset all data members which are not in the stream
@@ -271,5 +277,5 @@
     return kTRUE;
 }
-
+/*
 // --------------------------------------------------------------------------
 //
@@ -299,4 +305,5 @@
     return rc==kTRUE ? !fin.eof() : rc;
 }
+*/
 
 // --------------------------------------------------------------------------
@@ -308,5 +315,6 @@
 {
     gLog << inf << endl;
-    gLog << "Num Photons:      " << fNumPhotons << " from " << MMcEvtBasic::GetParticleName(fPrimary) << endl;
+//    gLog << "Num Photons:      " << fNumPhotons << " from " << MMcEvtBasic::GetParticleName(fPrimary) << endl;
+    gLog << "Origin:           " << MMcEvtBasic::GetParticleName(fPrimary) << endl;
     gLog << "Wavelength:       " << fWavelength << "nm" << endl;
     gLog << "Pos X/Y  Cos U/V: " << fPosX << "/" << fPosY << "   " << fCosU << "/" << fCosV << endl;
Index: trunk/Mars/msim/MPhotonData.h
===================================================================
--- trunk/Mars/msim/MPhotonData.h	(revision 9936)
+++ trunk/Mars/msim/MPhotonData.h	(revision 9937)
@@ -37,15 +37,8 @@
 
     Float_t fTime;                       // [ns] Time since first interaction or entrance into atmosphere
-    // 17M
     UShort_t fWavelength;                // [nm] Wavelength
-    // 19M
-    UInt_t   fNumPhotons;                // Number of cherenkov photons ins bunch
+//    UInt_t   fNumPhotons;                // Number of cherenkov photons ins bunch
     Float_t  fProductionHeight;          // [cm] Height of bunch production
     MMcEvtBasic::ParticleId_t fPrimary;  // Type of emitting particle
-    // 22M
-    // gzip
-    // 25M
-    // raw
-    // 32M
 
     Int_t   fTag;    //! A tag for external use
@@ -129,12 +122,12 @@
 
     // I/O
-    Int_t ReadCorsikaEvt(istream &fin);
-    Int_t ReadRflEvt(istream &fin);
+    //Int_t ReadCorsikaEvt(istream &fin);
+    //Int_t ReadRflEvt(istream &fin);
 
-    Int_t FillCorsika(Float_t f[7]);
+    Int_t FillCorsika(Float_t f[7], Int_t i);
     Int_t FillEventIO(Float_t f[7]);
     Int_t FillRfl(Float_t f[8]);
 
-    ClassDef(MPhotonData, 1) //Container to store a cherenkov photon bunch from a CORSUKA file
+    ClassDef(MPhotonData, 2) //Container to store a cherenkov photon bunch from a CORSUKA file
 };
 
Index: trunk/Mars/msim/MPhotonEvent.cc
===================================================================
--- trunk/Mars/msim/MPhotonEvent.cc	(revision 9936)
+++ trunk/Mars/msim/MPhotonEvent.cc	(revision 9937)
@@ -449,9 +449,31 @@
 }
 
+Double_t MPhotonEvent::GetMeanX() const
+{
+    const UInt_t n = GetNumPhotons();
+
+    Double_t mean = 0;
+    for (UInt_t i=0; i<n; i++)
+        mean += operator[](i).GetPosX();
+
+    return mean / n;
+}
+
+Double_t MPhotonEvent::GetMeanY() const
+{
+    const UInt_t n = GetNumPhotons();
+
+    Double_t mean = 0;
+    for (UInt_t i=0; i<n; i++)
+        mean += operator[](i).GetPosY();
+
+    return mean / n;
+}
+
 // --------------------------------------------------------------------------
 //
 // Read the Event section from the file
 //
-Int_t MPhotonEvent::ReadCorsikaEvt(MCorsikaFormat * fInFormat)
+Int_t MPhotonEvent::ReadCorsikaEvt(MCorsikaFormat *fInFormat, Int_t i)
 {
     Int_t n = 0;
@@ -509,5 +531,5 @@
             {
 
-            const Int_t rc = Add(n).FillCorsika(buffer);
+            const Int_t rc = Add(n).FillCorsika(buffer, i);
             switch (rc)
             {
@@ -577,5 +599,5 @@
 }
 
-Int_t MPhotonEvent::ReadCorsikaEvt(istream &fin)
+Int_t MPhotonEvent::ReadCorsikaEvt(istream &fin, Int_t i)
 {
     Int_t n = 0;
@@ -635,5 +657,5 @@
             // Get/Add the n-th entry from the array and
             // fill it with the current 7 floats
-            const Int_t rc = Add(n).FillCorsika(ptr);
+            const Int_t rc = Add(n).FillCorsika(ptr, i);
             ptr += 7;
 
@@ -707,6 +729,6 @@
 
 // --------------------------------------------------------------------------
-//
-Int_t MPhotonEvent::ReadRflEvt(std::istream &fin)
+/*
+Int_t MPhotonEvent::ReadRflEvt(std::istream &fin, Int_t i)
 {
     Int_t n = 0;
@@ -735,5 +757,5 @@
         // Now we read a single cherenkov bunch
         //const Int_t rc = static_cast<MPhotonData*>(o)->ReadRflEvt(fin);
-        const Int_t rc = Add(n).ReadRflEvt(fin);
+        const Int_t rc = Add(n).ReadRflEvt(fin, i);
 
         // Evaluate result from reading event
@@ -754,8 +776,8 @@
     SetReadyToSave();
 
-    //*fLog << all << "Number of photon bunches: " << fData.GetEntriesFast() << endl;
+    // *fLog << all << "Number of photon bunches: " << fData.GetEntriesFast() << endl;
     return kTRUE;
 }
-
+*/
 // --------------------------------------------------------------------------
 //
Index: trunk/Mars/msim/MPhotonEvent.h
===================================================================
--- trunk/Mars/msim/MPhotonEvent.h	(revision 9936)
+++ trunk/Mars/msim/MPhotonEvent.h	(revision 9937)
@@ -37,4 +37,7 @@
     Double_t GetTimeMedianDev() const;
 
+    Double_t GetMeanX() const;
+    Double_t GetMeanY() const;
+
     TClonesArray &GetArray() { return fData; }
     const TClonesArray &GetArray() const { return fData; }
@@ -53,7 +56,7 @@
 
     // I/O
-    Int_t ReadCorsikaEvt(MCorsikaFormat * fInFormat);
-    Int_t ReadCorsikaEvt(istream &fin);
-    Int_t ReadRflEvt(istream &fin);
+    Int_t ReadCorsikaEvt(MCorsikaFormat *fInFormat, Int_t i);
+    Int_t ReadCorsikaEvt(istream &fin, Int_t i);
+    //Int_t ReadRflEvt(istream &fin, Int_t i);
 
     // TObject
Index: trunk/Mars/msim/MSimMMCS.cc
===================================================================
--- trunk/Mars/msim/MSimMMCS.cc	(revision 9936)
+++ trunk/Mars/msim/MSimMMCS.cc	(revision 9937)
@@ -131,5 +131,5 @@
 
     // FIXME: Is there a way to write them as LAST entry in the file?
-    fMcRunHeader->SetNumSimulatedShowers(fRunHeader->GetNumEvents());
+    fMcRunHeader->SetNumSimulatedShowers(fRunHeader->GetNumEvents()*fRunHeader->GetNumReuse());
     fMcRunHeader->SetCorsikaVersion(TMath::Nint(fRunHeader->GetProgramVersion()*100));
 
@@ -211,4 +211,5 @@
 
     fMcEvt->SetEvtNumber(fEvtHeader->GetEvtNumber());
+    fMcEvt->SetEventReuse(fEvtHeader->GetNumReuse());
     fMcEvt->SetPhotElfromShower(0);
 
