Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREvent.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREvent.cxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREvent.cxx	(revision 294)
@@ -0,0 +1,13 @@
+/////////////////////////////////////////////////////////////////
+//
+// COREvent
+//
+//  Created: Tue Apr 28 16:14:05 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for Event-classes
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+#include "COREvent.hxx"
+
Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREvent.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREvent.hxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREvent.hxx	(revision 294)
@@ -0,0 +1,74 @@
+/////////////////////////////////////////////////////////////////
+//
+// COREvent
+//
+//  Created: Tue Apr 28 16:14:05 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for Event-classes
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+#ifndef COREvent_Class
+#define COREvent_Class
+
+#ifdef __ROOT__
+#include "TROOT.h"
+#include "TObject.h"
+#else // not __ROOT__
+#include "Rtypes.h"
+#endif
+
+#include "COREventHeader.hxx"
+
+class COREvent {
+
+public:
+  Int_t           NCphotons;
+  Float_t         TimeBegin;
+  Float_t         TimeEnd;
+  COREventHeader  EvtHdr;
+  UInt_t          Flag;
+
+public:
+  COREvent(void) {} // default constructor
+  virtual ~COREvent(void) {} // default destructor
+
+  // set number of Cphotons for this event
+  inline void SetNCphotons( Int_t n ) { NCphotons = n; }
+
+  // set flag with a number
+  inline void SetFlag( UInt_t f ) { Flag = f; }
+
+  // toggle flag bit number b
+  inline void ToggleFlagBit( UInt_t b ) { }
+
+  // get number of Cherenkov photons
+  inline Int_t GetNCphotons() const { return NCphotons; }
+
+  // get EventHeader pointer
+  inline COREventHeader *GetHeader() { return &EvtHdr; }
+
+  // Get flag value
+  inline UInt_t GetFlag() const { return Flag; }
+
+  // get status of flag bit number b
+  inline UInt_t GetFlagBit( UInt_t b ) { return ( Flag && 1 << (b-1) ); }
+
+  // set times for this event (first and last Cherenkov photons)
+  void SetTimes( Float_t t1, Float_t t2 ) {
+	TimeBegin = t1;
+	TimeEnd = t2;
+  }
+
+  // get times of this event (first and last Cherenkov photons)
+  Float_t GetTimes(Float_t *t1, Float_t *t2) const { 
+	*t1 = TimeBegin;
+	*t2 = TimeEnd;
+	return (TimeEnd - TimeBegin); 
+  }
+
+};
+
+#endif  // not defined COREvent_Class
+
Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREventHeader.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREventHeader.cxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREventHeader.cxx	(revision 294)
@@ -0,0 +1,105 @@
+/////////////////////////////////////////////////////////////////
+//
+// COREventHeader
+//
+//  Created: Tue Apr 28 16:27:14 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for EventHeader-classes
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+// @T \newpage
+
+// @section Source code of {\tt COREventHeader.cxx}
+
+// @subsection Class {\em COREventHeader}: Implementation
+
+// @code
+
+#include "COREventHeader.hxx"
+
+void 
+COREventHeader::print(void) {
+
+  cout << "  EVTH           :" << (char*)EVTH << endl;
+  cout << "  EvtNumber      :" << EvtNumber << endl;
+  cout << "  PrimaryID      :" << PrimaryID << endl;
+  cout << "  Etotal         :" << Etotal    << endl;
+  cout << "  Thick0         :" << Thick0    << endl;
+  cout << "  FirstTarget    :" << FirstTarget << endl;
+  cout << "  zFirstInt      :" << zFirstInt << endl;
+  cout << "  p[3]           :" << p[0] << ' ' << p[1] << ' ' << p[2] << endl;
+  cout << "  Theta          :" << Theta  << endl;
+  cout << "  Phi            :" << Phi  << endl;
+                                
+  cout << "  NumRndSeq      :" << NumRndSeq << endl;
+                                
+  cout << "  RunNumber      :" << RunNumber << endl;
+  cout << "  DateRun        :" << DateRun << endl;
+  cout << "  VersionPGM     :" << VersionPGM << endl;
+                                
+  cout << "  NumObsLev      :" << NumObsLev << endl;
+  cout << "  HeightLev[0]   :" << HeightLev[0]  << endl;
+                                
+  cout << "  SlopeSpec      :" << SlopeSpec << endl;
+  cout << "  ELowLim        :" << ELowLim    << endl;
+  cout << "  EUppLim        :" << EUppLim    << endl;
+                                
+  cout << "  Ecutoffh       :" << Ecutoffh   << endl;
+  cout << "  Ecutoffm       :" << Ecutoffm   << endl;
+  cout << "  Ecutoffe       :" << Ecutoffe   << endl;
+  cout << "  Ecutoffg       :" << Ecutoffg   << endl;
+                                
+  cout << "  NFLAIN         :" << NFLAIN << endl;
+  cout << "  NFLDIF         :" << NFLDIF << endl;
+  cout << "  NFLPI0         :" << NFLPI0 << endl;
+  cout << "  NFLPIF         :" << NFLPIF << endl;
+  cout << "  NFLCHE         :" << NFLCHE << endl;
+  cout << "  NFRAGM         :" << NFRAGM  << endl;
+                                
+  cout << "  Bx             :" << Bx << endl;
+  cout << "  By             :" << By << endl;
+                                
+  cout << "  EGS4yn         :" << EGS4yn << endl;
+  cout << "  NKGyn          :" << NKGyn << endl;
+  cout << "  GHEISHAyn      :" << GHEISHAyn << endl;
+  cout << "  VENUSyn        :" << VENUSyn << endl;
+  cout << "  CERENKOVyn     :" << CERENKOVyn << endl;
+  cout << "  NEUTRINOyn     :" << NEUTRINOyn << endl;
+  cout << "  HORIZONTyn     :" << HORIZONTyn << endl;
+  cout << "  COMPUTER       :" << COMPUTER << endl;
+                                
+  cout << "  ThetaMin       :" << ThetaMin << endl;
+  cout << "  ThetaMax       :" << ThetaMax << endl;
+  cout << "  PhiMin         :" << PhiMin << endl;
+  cout << "  PhiMax         :" << PhiMax << endl;
+                                
+  cout << "  CBunchSize     :" << CBunchSize << endl;
+  cout << "  CDetInX        :" << CDetInX << endl;
+  cout << "  CDetInY        :" << CDetInY << endl;
+  cout << "  CSpacInX       :" << CSpacInX << endl;
+  cout << "  CSpacInY       :" << CSpacInY << endl;
+  cout << "  CLenInX        :" << CLenInX << endl;
+  cout << "  CLenInY        :" << CLenInY << endl;
+  cout << "  COutput        :" << COutput << endl;
+                                
+  cout << "  AngleNorthX    :" << AngleNorthX << endl;
+  cout << "  MuonInfo       :" << MuonInfo << endl;
+                                
+  cout << "  StepLength     :" << StepLength << endl;
+  cout << "  CWaveLower     :" << CWaveLower        << endl;
+  cout << "  CWaveUpper     :" << CWaveUpper        << endl;
+  cout << "  Multipl        :" << Multipl        << endl;
+  cout << "  CorePos{1}     :" 
+       << '(' << CorePos[0][0] 
+       << ',' << CorePos[1][0] << ") m" << endl;
+                                
+  cout << "  SpinTheta      :" << SpinTheta  << endl;
+  cout << "  SpinPhi        :" << SpinPhi    << endl;
+
+  cout << flush;
+}
+
+// @endcode << endl;
+
Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREventHeader.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREventHeader.hxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/COREventHeader.hxx	(revision 294)
@@ -0,0 +1,245 @@
+/////////////////////////////////////////////////////////////////
+//
+// COREventHeader
+//
+//  Created: Tue Apr 28 16:27:14 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for EventHeader-classes
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+// @T \newpage
+
+// @section Source code of {\tt COREventHeader.hxx}
+
+/* @text
+This section shows the include file {\tt COREventHeader.hxx}
+@endtext */
+
+#ifndef COREventHeader_Class
+#define COREventHeader_Class
+
+// @subsection Include files
+
+// @code
+#ifdef __ROOT__
+#include "TROOT.h"
+#include "TObject.h"
+#else // not __ROOT__
+#include "Rtypes.h"
+#endif
+
+#include <iostream.h>
+#include <iomanip.h>
+#include <fstream.h>
+#include <stdlib.h>
+#include <math.h>
+// @endcode
+
+// @subsection Class {\em COREventHeader}: Definition
+
+// @code
+class COREventHeader {
+
+public:
+  char         EVTH[4];
+  Float_t      EvtNumber;
+  Float_t      PrimaryID;
+  Float_t      Etotal;   
+  Float_t      Thick0;   
+  Float_t      FirstTarget;
+  Float_t      zFirstInt;
+  Float_t      p[3];     
+  Float_t      Theta; 
+  Float_t      Phi; 
+
+  Float_t      NumRndSeq;
+  Float_t      RndData[10][3];
+  
+  Float_t      RunNumber;
+  Float_t      DateRun;
+  Float_t      VersionPGM;
+
+  Float_t      NumObsLev;
+  Float_t      HeightLev[10]; 
+
+  Float_t      SlopeSpec;
+  Float_t      ELowLim;   
+  Float_t      EUppLim;   
+
+  Float_t      Ecutoffh;  
+  Float_t      Ecutoffm;  
+  Float_t      Ecutoffe;  
+  Float_t      Ecutoffg;  
+
+  Float_t      NFLAIN;
+  Float_t      NFLDIF;
+  Float_t      NFLPI0;
+  Float_t      NFLPIF;
+  Float_t      NFLCHE;
+  Float_t      NFRAGM; 
+ 
+  Float_t      Bx;
+  Float_t      By;
+  
+  Float_t      EGS4yn;
+  Float_t      NKGyn;
+  Float_t      GHEISHAyn;
+  Float_t      VENUSyn;
+  Float_t      CERENKOVyn;
+  Float_t      NEUTRINOyn;
+  Float_t      HORIZONTyn;
+  Float_t      COMPUTER;
+
+  Float_t      ThetaMin;
+  Float_t      ThetaMax;
+  Float_t      PhiMin;
+  Float_t      PhiMax;
+
+  Float_t      CBunchSize;
+  Float_t      CDetInX,CDetInY;
+  Float_t      CSpacInX,CSpacInY;
+  Float_t      CLenInX,CLenInY;
+  Float_t      COutput;
+
+  Float_t      AngleNorthX;
+  Float_t      MuonInfo;
+
+  Float_t      StepLength;
+  Float_t      CWaveLower;       
+  Float_t      CWaveUpper;       
+  Float_t      Multipl;       
+  Float_t      CorePos[2][20];   
+
+  Float_t      dmmy1; 
+  Float_t      SpinTheta; 
+  Float_t      SpinPhi;   
+  Float_t      dmmy2[132]; 
+
+public:
+  COREventHeader(void) {}  // default constructor
+
+  virtual ~COREventHeader(void) {}  // default destructor
+  
+  // reads EventHeader from binary input stream
+  Int_t read ( ifstream &is ) {
+    is.read ( (char *)this, sizeof( float ) * 273 ); 
+    return is.gcount();
+  }
+
+  // writes EventHeader to binary output stream
+  Int_t write ( ofstream &os ) {
+    os.write ( (char *)this, sizeof( float ) * 273 ); 
+    return 0;
+  }
+  
+  // get information about the EventHeader
+
+  // print-out of the EVTH
+  void print(void);
+  
+  // get the primary type (GEANT code)
+  inline Float_t get_primary ( void ) { return ( PrimaryID ); }
+
+  // get the total primary energy
+  inline Float_t get_energy ( void ) { return ( Etotal ); }
+  
+  // get the initial zenith angle
+  inline Float_t get_theta ( void ) { return ( Theta ); }
+
+  // get the initial phi angle
+  inline Float_t get_phi ( void ) { return ( Phi ); }
+
+  // get the particle xi angle
+  inline Float_t get_xi ( void ) { return ( SpinTheta ); }
+
+  // get the particle spin-theta angle
+  inline Float_t get_stheta ( void ) { return ( SpinTheta ); }
+
+  // get the particle spin-phi angle
+  inline Float_t get_sphi ( void ) { return ( SpinPhi ); }
+
+  // get the particle real angles of the particle
+  void get_real_direct ( Float_t *theta, Float_t *phi ) { 
+    *theta = acos(cos(Theta)*cos(SpinTheta)+
+                  sin(Theta)*sin(SpinTheta)*cos(fabs(SpinPhi)));
+    *phi = asin(sin(SpinTheta)*sin(fabs(SpinPhi))/sin(*theta));
+    if (SpinPhi<0.0)
+      *phi = Phi - *phi;
+    else
+      *phi = Phi + *phi;
+  }
+
+  // get the spectrum slope
+  inline Float_t get_slope ( void ) { return ( SlopeSpec ); }
+
+  // get the energy range of this run
+  inline void get_energy_range ( Float_t *elow, Float_t *eup ) { 
+    *elow = ELowLim;   
+    *eup = EUppLim;
+  }
+
+  // get the core position
+  inline Float_t get_core ( Float_t *x, Float_t *y, Int_t ncore = 0 ) {
+    *x = CorePos[0][ncore];
+    *y = CorePos[1][ncore];
+    return ( (Float_t) sqrt ( (*x)*(*x) + (*y)*(*y) ) );
+  }
+
+  // get the core position
+  inline Float_t get_core ( Int_t ncore = 0 ) {
+    return ( (Float_t) sqrt ( ((CorePos[0][ncore])*(CorePos[0][ncore]))+
+                              ((CorePos[1][ncore])*(CorePos[1][ncore])) ) );
+  }
+
+  // show the seeds in the console
+  inline void print_seeds ( void ) {
+    Int_t i;
+    cout << "Seeds status at the beginning of this shower:" 
+         << setiosflags(ios::left) << setw(10) << endl;
+    for (i=0; i<NumRndSeq; ++i) {
+      cout << "SEED       " 
+           << RndData[i][0]
+           << RndData[i][1]
+           << RndData[i][2] << endl;
+    }
+    cout << resetiosflags(ios::left);
+  }
+
+  // fill essential information
+  inline void fill ( Float_t theEvtNumber,
+             Float_t thePrimaryID,
+             Float_t theEtotal,   
+             Float_t theFirstTarget,
+             Float_t thezFirstInt,
+             Float_t thepx, 
+             Float_t thepy, 
+             Float_t thepz, 
+             Float_t theTheta, 
+             Float_t thePhi,
+             Float_t theX, 
+             Float_t theY) {
+             
+    strcpy(EVTH,"EVTH");
+    EvtNumber = theEvtNumber; 
+    PrimaryID = thePrimaryID;
+    Etotal    = theEtotal;
+    FirstTarget = theFirstTarget;
+    zFirstInt = thezFirstInt;
+    p[0] = thepx;      
+    p[1] = thepy;      
+    p[2] = thepz;      
+    Theta = theTheta;   
+    Phi = thePhi;      
+    Thick0 = 0.0;        
+    CorePos[0][0] = theX;
+    CorePos[1][0] = theY;
+
+    return; 
+  }
+
+};
+// @endcode
+
+#endif  // not defined COREventHeader_Class
Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORParticle.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORParticle.cxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORParticle.cxx	(revision 294)
@@ -0,0 +1,22 @@
+/////////////////////////////////////////////////////////////////
+//
+// CORParticle
+//
+//  Created: Tue Apr 28 16:43:30 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for Particles/Cherenkov photons
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+// @T \newpage
+
+// @section Source code of {\tt CORParticle.cxx}
+
+// @subsection Class {\em CORParticle}: Implementation
+
+// @code
+
+#include "CORParticle.hxx"
+
+// @endcode
Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORParticle.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORParticle.hxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORParticle.hxx	(revision 294)
@@ -0,0 +1,123 @@
+/////////////////////////////////////////////////////////////////
+//
+// CORParticle
+//
+//  Created: Tue Apr 28 16:43:30 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for Particles/Cherenkov photons
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+// @T \newpage
+
+// @section Source code of {\tt CORParticle.hxx}
+
+/* @text
+This section shows the include file {\tt CORParticle.hxx}
+@endtext */
+
+#ifndef CORParticle_Class
+#define CORParticle_Class
+
+// @subsection Include files
+
+// @code
+#ifdef __ROOT__
+#include "TROOT.h"
+#include "TObject.h"
+#else // not __ROOT__
+#include "Rtypes.h"
+#endif
+
+#include <iostream.h>
+#include <iomanip.h>
+#include <fstream.h>
+#include <stdlib.h>
+#include <math.h>
+// @endcode
+
+// @subsection Class {\em CORParticle}: Definition
+
+// @code
+class CORParticle {
+
+public:
+  Float_t     w;                // wavelength/type of particle [nm/-]
+  Float_t     x, y;             // position [cm]
+  Float_t     u, v;             // director cosines 
+  Float_t     t;                // time since first interaction [ns]
+  Float_t     h;                // height [cm]
+
+public:
+  CORParticle() {} // default constructor
+
+  // overloaded constructor
+  CORParticle( ifstream &is ) { CORParticle::read( is ); }
+
+  // overloaded constructor
+  CORParticle(Float_t thew, Float_t thex, Float_t they, 
+          Float_t theu, Float_t thev, Float_t thet, Float_t theh) 
+    {
+      w = thew;
+      x = thex;
+      y = they;
+      u = theu;
+      v = thev;
+      t = thet;
+      h = theh;
+    }
+
+  virtual ~CORParticle() {} // default destructor
+
+  // reads photon from binary input stream
+  Int_t read ( ifstream &is ) {
+    int n;
+    is.read ( (char *)this, 7 * sizeof( Float_t ) );   // 
+    return is.gcount();
+  }
+
+  // writes photon to binary output stream
+  Int_t write ( ofstream &os ) {
+    os.write ( (char *)this, 7 * sizeof( Float_t ) );
+    return 0;
+  }
+
+  // fill information
+  inline void fill(Float_t thew, Float_t thex, Float_t they, 
+		   Float_t theu, Float_t thev, Float_t thet, Float_t theh) 
+    {
+      w = thew;
+      x = thex;
+      y = they;
+      u = theu;
+      v = thev;
+      t = thet;
+      h = theh;
+    }
+
+  // get information about the photon
+  inline Float_t get_wl( void ) { 
+    return ( (w>1.0) ? 
+             w - 1000.*((int)floor(w/1000.)) :
+             0.0 ); 
+  }
+  inline Float_t get_id( void ) { return ( w ); }
+  inline Int_t get_particle( void ) { 
+    return ( (int)floor(w/1000.) );
+  }
+  inline Float_t get_x( void ) { return ( x ); }
+  inline Float_t get_y( void ) { return ( y ); }
+  inline Float_t get_u( void ) { return ( u ); }
+  inline Float_t get_v( void ) { return ( v ); }
+  inline Float_t get_h( void ) { return ( h ); }
+  inline Float_t get_t( void ) { return ( t ); }
+                  
+  inline Float_t get_r( void ) { return ( sqrt( x*x + y*y ) ); }
+  inline Float_t get_w( void ) { return ( sqrt( 1.0 - u*u - v*v ) ); }
+};
+
+// @endcode 
+
+#endif  // not defined CORParticle_Class
+
Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORStatfile.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORStatfile.cxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORStatfile.cxx	(revision 294)
@@ -0,0 +1,266 @@
+/////////////////////////////////////////////////////////////////
+//
+// CORStatfile
+//
+//  Created: Tue Apr 28 16:14:05 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for Event-classes
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+// @T \newpage
+
+// @section Source code of {\tt CORStatfile.cxx}
+
+// @subsection Class {\em CORStatfile}: Implementation
+
+// @code
+
+#include "CORStatfile.hxx"
+
+CORStatfile::CORStatfile () 
+{
+  init ( 79 );  // assumes thstep = 10 g/cm2    (790/10 = 79)
+}
+
+CORStatfile::CORStatfile ( Int_t n )
+{
+  init ( n );
+}
+
+void
+CORStatfile::init ( Int_t n ) 
+{
+  Int_t i, k;
+
+  nstep = n;
+
+  evth   = new Float_t[MAXBUF]; 	  // event header
+  evte   = new Float_t[MAXBUF]; 	  // event end
+  
+  nproto = new Int_t[nstep];
+  nprotb = new Int_t[nstep];
+  nneutr = new Int_t[nstep];
+  nneutb = new Int_t[nstep];
+  nphoto = new Int_t[nstep];
+  nelect = new Int_t[nstep];
+  nposit = new Int_t[nstep];
+  nnu    = new Int_t[nstep];
+  nmum   = new Int_t[nstep];
+  nmup   = new Int_t[nstep];
+  npi0   = new Int_t[nstep];
+  npim   = new Int_t[nstep];
+  npip   = new Int_t[nstep];
+  nk0l   = new Int_t[nstep];
+  nk0s   = new Int_t[nstep];
+  nkmi   = new Int_t[nstep];
+  nkpl   = new Int_t[nstep];
+  nhyp   = new Int_t[nstep];
+  ndeut  = new Int_t[nstep];
+  ntrit  = new Int_t[nstep];
+  nalpha = new Int_t[nstep];
+  nother = new Int_t[nstep];
+
+  plong = new Float_t * [9];
+  aplong = new Float_t * [9];
+
+  for ( i=0; i<9; i++ ) {
+	plong[i] = new Float_t[NPLONG];
+	aplong[i] = new Float_t[NPLONG];
+  }
+	
+  for ( i=0; i<9; i++ )
+	for ( k=0; k<NPLONG; k++ )
+	  plong[i][k] = aplong[i][k] = 0.;
+
+  opened = 0;
+  bunch = 1.0;
+}
+
+CORStatfile::~CORStatfile () 
+{
+  Int_t i;
+
+  for ( i=0; i<9; i++ ) {
+	delete [] plong[i];
+	delete [] aplong[i];
+	plong[i] = aplong[i] = NULL;
+  }
+
+  delete [] plong;
+  delete [] aplong;
+  plong = aplong = NULL;
+
+  delete [] evth;
+  delete [] evte;
+  evth = evte = NULL;
+  
+  delete [] nproto;
+  delete [] nprotb;
+  delete [] nneutr;
+  delete [] nneutb;
+  delete [] nphoto;
+  delete [] nelect;
+  delete [] nposit;
+  delete [] nnu;
+  delete [] nmum;
+  delete [] nmup;
+  delete [] npi0;
+  delete [] npim;
+  delete [] npip;
+  delete [] nk0l;
+  delete [] nk0s;
+  delete [] nkmi;
+  delete [] nkpl;
+  delete [] nhyp;
+  delete [] ndeut;
+  delete [] ntrit;
+  delete [] nalpha;
+  delete [] nother;
+
+  nproto = nprotb = nneutr = nneutb = 
+	nphoto = nelect = nposit = nnu =   
+	nmum = nmup = npi0 = npim = npip = 
+	nk0l = nk0s = nkmi = nkpl = nhyp = 
+	ndeut = ntrit = nalpha = nother = NULL;
+
+}
+
+Int_t 
+CORStatfile::openfile ( char *fname )
+{
+  if ( input_file != NULL )
+	input_file.close();
+  input_file.open( fname );
+  opened = 1;
+  return ( ! input_file.bad() );
+}
+
+void
+CORStatfile::closefile ( void )
+{
+  input_file.close();
+  opened = 0;
+}
+
+void
+CORStatfile::read()
+{
+  Int_t i, k;
+  Float_t f;
+
+  input_file.read ( (char *)evth, sizeof (Float_t) * MAXBUF );
+  input_file.read ( (char *)evte, sizeof (Float_t) * MAXBUF );
+  input_file.read ( (char *)&timefirst, sizeof (Float_t) );
+  input_file.read ( (char *)&timelast, sizeof (Float_t) );
+
+  for (i = 0; i < 10; i++) {
+
+      input_file.read ( (char *)(nproto + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nprotb + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nneutr + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nneutb + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nphoto + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nelect + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nposit + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nnu + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nmum + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nmup + i), sizeof (Int_t) );
+      input_file.read ( (char *)(npi0 + i), sizeof (Int_t) );
+      input_file.read ( (char *)(npim + i), sizeof (Int_t) );
+      input_file.read ( (char *)(npip + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nk0l + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nk0s + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nkmi + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nkpl + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nhyp + i), sizeof (Int_t) );
+      input_file.read ( (char *)(ndeut + i), sizeof (Int_t) );
+      input_file.read ( (char *)(ntrit + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nalpha + i), sizeof (Int_t) );
+      input_file.read ( (char *)(nother + i), sizeof (Int_t) );
+
+  }
+
+  input_file.read ( (char *)&ifinnu, sizeof (Int_t) );
+  input_file.read ( (char *)&ifinpi, sizeof (Int_t) );
+  input_file.read ( (char *)&ifinet, sizeof (Int_t) );
+  input_file.read ( (char *)&ifinka, sizeof (Int_t) );
+  input_file.read ( (char *)&ifinhy, sizeof (Int_t) );
+  input_file.read ( (char *)&cerele, sizeof (Int_t) );
+  input_file.read ( (char *)&cerhad, sizeof (Int_t) );
+
+  input_file.read ( (char *)&lpct1, sizeof (Int_t) );
+  input_file.read ( (char *)&nstep, sizeof (Int_t) );
+  input_file.read ( (char *)&thstep, sizeof (Float_t) );
+
+  for (k = 0; k < 9; k++)
+	for (i = 0; i < nstep; i++) {
+	  input_file.read ( (char *)&f, sizeof (Float_t) );
+	  plong[k][i] = f;
+	}
+
+  for (k = 0; k < 9; k++)
+	for (i = 0; i < nstep; i++)
+	  aplong[k][i] += plong[k][i] * bunch;
+  
+}
+
+void
+CORStatfile::write(ofstream &output_file)
+{
+  Int_t i, k;
+  Float_t f = 0.;
+
+  output_file.write ( (char *)evth, sizeof (Float_t) * MAXBUF );
+  output_file.write ( (char *)evte, sizeof (Float_t) * MAXBUF );
+  output_file.write ( (char *)&timefirst, sizeof (Float_t) );
+  output_file.write ( (char *)&timelast, sizeof (Float_t) );
+
+  for (i = 0; i < 10; i++) {
+
+      output_file.write ( (char *)(nproto + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nprotb + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nneutr + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nneutb + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nphoto + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nelect + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nposit + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nnu + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nmum + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nmup + i), sizeof (Int_t) );
+      output_file.write ( (char *)(npi0 + i), sizeof (Int_t) );
+      output_file.write ( (char *)(npim + i), sizeof (Int_t) );
+      output_file.write ( (char *)(npip + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nk0l + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nk0s + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nkmi + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nkpl + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nhyp + i), sizeof (Int_t) );
+      output_file.write ( (char *)(ndeut + i), sizeof (Int_t) );
+      output_file.write ( (char *)(ntrit + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nalpha + i), sizeof (Int_t) );
+      output_file.write ( (char *)(nother + i), sizeof (Int_t) );
+
+  }
+
+  output_file.write ( (char *)&ifinnu, sizeof (Int_t) );
+  output_file.write ( (char *)&ifinpi, sizeof (Int_t) );
+  output_file.write ( (char *)&ifinet, sizeof (Int_t) );
+  output_file.write ( (char *)&ifinka, sizeof (Int_t) );
+  output_file.write ( (char *)&ifinhy, sizeof (Int_t) );
+  output_file.write ( (char *)&cerele, sizeof (Int_t) );
+  output_file.write ( (char *)&cerhad, sizeof (Int_t) );
+
+  output_file.write ( (char *)&lpct1, sizeof (Int_t) );
+  output_file.write ( (char *)&nstep, sizeof (Int_t) );
+  output_file.write ( (char *)&thstep, sizeof (Float_t) );
+
+  for (k = 0; k < 9; k++)
+    for (i = 0; i < nstep; i++) {
+      output_file.write ( (char *)&f, sizeof (Float_t) );
+    }
+  
+}
+
+// @endcode
Index: trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORStatfile.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORStatfile.hxx	(revision 294)
+++ trunk/MagicSoft/Simulation/Detector/include-CORSIKA/CORStatfile.hxx	(revision 294)
@@ -0,0 +1,105 @@
+/////////////////////////////////////////////////////////////////
+//
+// CORStatfile
+//
+//  Created: Tue Apr 28 16:14:05 1998
+//  Author:  Jose Carlos Gonzales
+//  Purpose: Base class for Statfiles
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+// @T \newpage
+
+// @section Source code of {\tt CORStatfile.hxx}
+
+/* @text
+This section shows the include file {\tt CORStatfile.hxx}
+@endtext */
+
+#ifndef CORStatfile_Class
+#define CORStatfile_Class
+
+// @subsection Include files
+
+// @code
+#ifdef __ROOT__
+#include "TROOT.h"
+#include "TObject.h"
+#else // not __ROOT__
+#include "Rtypes.h"
+#endif
+
+#include <iostream.h>
+#include <fstream.h>
+#include <stdlib.h>
+#include <math.h>
+
+#define MAXBUF 273  /* 39*7 */
+#define NSUBBL 21
+#define NPLONG 1041
+// @endcode
+
+// @subsection Class {\em CORStatfile}: Definition
+
+// @code
+class CORStatfile {
+  
+public:
+  Int_t steps;          // steps in the longitudinal distribution
+  Float_t *evth;          // event header
+  Float_t *evte;          // event end
+  Int_t *nproto;          // number of protons
+  Int_t *nprotb;          // number of anti-protons
+  Int_t *nneutr;          // number of neutrons
+  Int_t *nneutb;          // number of 
+  Int_t *nphoto;          // number of 
+  Int_t *nelect;          // number of 
+  Int_t *nposit;          // number of 
+  Int_t *nnu;         // number of 
+  Int_t *nmum;        // number of 
+  Int_t *nmup;        // number of 
+  Int_t *npi0;        // number of 
+  Int_t *npim;        // number of 
+  Int_t *npip;        // number of 
+  Int_t *nk0l;        // number of 
+  Int_t *nk0s;        // number of 
+  Int_t *nkmi;        // number of 
+  Int_t *nkpl;        // number of 
+  Int_t *nhyp;        // number of 
+  Int_t *ndeut;         // number of 
+  Int_t *ntrit;         // number of 
+  Int_t *nalpha;          // number of 
+  Int_t *nother;          // number of 
+  Int_t ifinnu, ifinpi, ifinet, ifinka, ifinhy, cerele, cerhad;
+  Int_t lpct1, nstep;
+  Float_t thstep;
+  Float_t **plong, **aplong;
+  Float_t bunch;
+  Float_t timefirst, timelast;
+  ifstream input_file;
+  Int_t opened;
+
+protected:
+  void init( Int_t n );
+
+public:
+  CORStatfile ( void );   // constructor
+  CORStatfile ( Int_t n );   // overloaded constructor
+  ~CORStatfile ( void );  // destructor
+  // copy constructor defaults
+
+  inline void set_bunch ( Float_t b ) { bunch = b; };
+  void read ();    // reads data from input file
+  void write(ofstream &output_file);  // writes data to given output file
+  Int_t openfile ( char *fname ); // sets and opens new sta* file
+  void closefile (); // sets and opens new sta* file
+  inline Float_t get_tfirst() { return ( timefirst ); }
+  inline Float_t get_tlast() { return ( timelast ); }
+  
+};
+
+// @endcode
+
+#endif // not defined CORStatfile_Class
+
