Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 1672)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.cxx	(revision 1674)
@@ -21,7 +21,7 @@
 //
 // $RCSfile: camera.cxx,v $
-// $Revision: 1.46 $
+// $Revision: 1.47 $
 // $Author: blanch $ 
-// $Date: 2002-11-08 17:51:00 $
+// $Date: 2002-12-10 17:19:31 $
 //
 ////////////////////////////////////////////////////////////////////////
@@ -408,4 +408,5 @@
 
   char flag[SIZE_OF_FLAGS + 1];  //@< flags in the .rfl file
+  char flag_new[4];              //@< New flag for the run header in the .rfl file
 
   int reflector_file_version;  //@< vrsion of he reflector file
@@ -1218,6 +1219,4 @@
     if(!isA( flag, FLAG_START_OF_RUN )){
 
-      //  We exit
-      //error( SIGNATURE, "Expected start of run flag, but found: %s\n", flag );
       //  We break the main loop
       cout<<"Warning: Expected start of run flag, but found:"<<flag<<endl;
@@ -1227,4 +1226,18 @@
     else { // found start of run
 
+      fread( flag_new, 4, 1, inputfile );
+
+      if(!isA( flag_new, FLAG_START_OF_HEADER)){
+
+	//  We break the main loop
+	cout<<"Warning: Expected start of run header flag, but found:"<<flag<<endl;
+	cout<<"         We break the main loop"<<endl;
+	break;      
+      }
+
+      Float_t flag_temp[SIZE_OF_MCRUNHEADER];
+      
+      fread( flag_temp, (SIZE_OF_MCRUNHEADER)*sizeof(float), 1, inputfile );
+
       nshow=0;
 
@@ -1232,4 +1245,14 @@
 
       while( isA( flag, FLAG_START_OF_EVENT   )){ // while there is a next event
+	fread( flag_new, 4, 1, inputfile );
+
+	if(!isA( flag_new, FLAG_EVENT_HEADER)){
+
+	//  We break while events loop
+	  cout<<"Warning: Expected start of event header flag, but found:"<<flag<<endl;
+	  cout<<"         We break the while events loop"<<endl;
+	  break;      
+	}
+
 	//
 	// Clear Trigger and Fadc
@@ -1279,5 +1302,5 @@
 	
 	// read the direction of the incoming shower
-	
+
 	if (reflector_file_version<6){
 	  thetashw = mcevth.get_theta();
@@ -1758,5 +1781,72 @@
 	    
 	    if (Write_McEvt){
-		}
+	      Float_t ftime, ltime;
+	      if (reflector_file_version<6){
+		mcevth.get_times(&ftime, &ltime);
+		McEvt->Fill( -1.0, 
+			     (UShort_t) mcevth.get_primary() , 
+			     mcevth.get_energy(),
+			     -1.0,
+			     -1.0,
+			     -1.0, 
+			     mcevth.get_theta(), 
+			     mcevth.get_phi(), 
+			     mcevth.get_core(),
+			     mcevth.get_coreX(),
+			     mcevth.get_coreY(),
+			     impactD,
+			     mcevth_2.get_theta_CT(),
+			     mcevth_2.get_phi_CT(),
+			     ftime,
+			     ltime,
+			     0,
+			     0,
+			     0,
+			     0,
+			     0,
+			     0,
+			     0,
+			     (UInt_t)mcevth.get_CORSIKA(), 
+			     (UInt_t)mcevth.get_AtmAbs(), 
+			     (UInt_t)mcevth.get_MirrAbs()+mcevth.get_OutOfMirr()+mcevth.get_BlackSpot(), 
+			     (UInt_t) ncph, 
+			     (UInt_t) inumphe,
+			     (UInt_t) inumphensb+inumphe);
+	      }
+	      else{
+		Float_t Nmax, t0, tmax, a, b, c, chi2;
+		mcevth.get_times(&ftime, &ltime);
+		chi2=mcevth_2.get_NKGfit(&Nmax, &t0, &tmax, &a, &b, &c);
+		McEvt->Fill( mcevth_2.get_evt_number(),
+			     (UShort_t) mcevth_2.get_primary() , 
+			     mcevth_2.get_energy(),
+			     mcevth_2.get_thick0(),
+			     mcevth_2.get_first_target(),
+			     mcevth_2.get_z_first_int(),
+			     mcevth_2.get_theta(), 
+			     mcevth_2.get_phi(), 
+			     mcevth_2.get_core(),
+			     mcevth_2.get_coreX(),
+			     mcevth_2.get_coreY(),
+			     impactD,
+			     mcevth_2.get_theta_CT(),
+			     mcevth_2.get_phi_CT(),
+			     ftime,
+			     ltime,
+			     Nmax,
+			     t0,
+			     tmax,
+			     a,
+			     b,
+			     c,
+			     chi2,
+			     (UInt_t)mcevth_2.get_CORSIKA(), 
+			     (UInt_t)mcevth_2.get_AtmAbs(), 
+			     (UInt_t)mcevth_2.get_MirrAbs()+mcevth_2.get_OutOfMirr()+mcevth_2.get_BlackSpot(), 
+			     (UInt_t) ncph, 
+			     (UInt_t) inumphe,
+			     (UInt_t) inumphensb+inumphe);
+	      }
+	    }
 	    //   We don not count photons out of the camera.	
 	    
@@ -1833,4 +1923,5 @@
       if( !isA( flag, FLAG_END_OF_RUN   )){
 	error( SIGNATURE, "Expected end of run flag, but found: %s\n", flag );
+	break;
       }
       else { // found end of run
@@ -1843,5 +1934,7 @@
 	  log(SIGNATURE, "End of file . . .\n");
 	  still_in_loop  = FALSE;
-  
+	  log(SIGNATURE, "Reading ASCII files at the end of the reflector file.  . .\n");
+	  read_ascii(inputfile);
+	  break;
 	  if ((! Data_From_STDIN) && ( !feof(inputfile) )){
 	    
@@ -1850,5 +1943,8 @@
 
 	    if((reflector_file_version=check_reflector_file( inputfile ))==FALSE){
-	      exit(1);
+	      // exit(1);
+	      log(SIGNATURE, "Next file is not recognised as a reflector file.\n");
+	      log(SIGNATURE, "Stopping ...\n");
+	      break;
 	    }
 	    
@@ -1916,5 +2012,5 @@
 		    mcevth.get_CWaveUpper(),
 		    mcevth.get_slope(),
-		    mcevth.get_NumObsLev(),
+		    1,
 		    heights,
 		    corsika,
@@ -1922,5 +2018,5 @@
 		    (UInt_t)(VERSION*100),
 		    0);
-  
+
   //  Fill the Header Tree with the current leaves of each branch
   HeaderTree.Fill() ;
@@ -2725,4 +2821,19 @@
 //!@}
 
+//!-----------------------------------------------------------
+// @name read_ascii  
+//                          
+// @desc read ascii configuration files used by the reflector
+//
+// @date tue dec 10 17:14:10 CET 2002
+//------------------------------------------------------------
+// @function
+
+//!@{
+void 
+read_ascii(FILE *sp)
+{
+  cout<<"To be implemented..."<<endl;
+}
 
 //!-----------------------------------------------------------
@@ -3684,4 +3795,7 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.46  2002/11/08 17:51:00  blanch
+// *** empty log message ***
+//
 // Revision 1.45  2002/10/29 17:15:27  blanch
 // Reading several reflector versions.
@@ -3823,4 +3937,7 @@
 //
 // $Log: not supported by cvs2svn $
+// Revision 1.46  2002/11/08 17:51:00  blanch
+// *** empty log message ***
+//
 // Revision 1.45  2002/10/29 17:15:27  blanch
 // Reading several reflector versions.
Index: trunk/MagicSoft/Simulation/Detector/Camera/camera.h
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Camera/camera.h	(revision 1672)
+++ trunk/MagicSoft/Simulation/Detector/Camera/camera.h	(revision 1674)
@@ -19,7 +19,7 @@
 //=
 //= $RCSfile: camera.h,v $
-//= $Revision: 1.12 $
+//= $Revision: 1.13 $
 //= $Author: blanch $ 
-//= $Date: 2002-10-29 17:16:28 $
+//= $Date: 2002-12-10 17:20:32 $
 //=
 //=//////////////////////////////////////////////////////////////////////
@@ -62,4 +62,5 @@
 #include "moments.h"
 
+#include "MCRunHeader.hxx"
 #include "MCEventHeader.hxx"
 #include "MCEventHeader_2.hxx"
@@ -281,4 +282,6 @@
 void read_QE(void);
 void read_WC(void);
+void read_ascii( FILE *sp // the input file
+		 );
 int pixels_are_neig(int pix1, int pix2);
 int bpoint_is_in_pix(double dx, double dy, int ipixnum, 
@@ -330,4 +333,7 @@
 /*
  *$Log: not supported by cvs2svn $
+ *Revision 1.12  2002/10/29 17:16:28  blanch
+ *Header file for camera.cxx version 1.45
+ *
  *Revision 1.11  2002/10/18 16:53:30  blanch
  *Modification to read several reflector version files.
Index: trunk/MagicSoft/Simulation/Detector/include-MC/MCCphoton.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MC/MCCphoton.hxx	(revision 1672)
+++ trunk/MagicSoft/Simulation/Detector/include-MC/MCCphoton.hxx	(revision 1674)
@@ -43,5 +43,7 @@
 
 const char FLAG_START_OF_RUN[]   = "\nSTART---RUN\n";
+const char FLAG_START_OF_HEADER[]   = "RUNH";
 const char FLAG_START_OF_EVENT[] = "\nSTART-EVENT\n";
+const char FLAG_EVENT_HEADER[]   = "EVTH";
 const char FLAG_END_OF_EVENT[] =   "\nEND---EVENT\n";
 const char FLAG_END_OF_RUN[] =     "\nEND-----RUN\n";
@@ -50,4 +52,5 @@
 
 #define SIZE_OF_FLAGS  13
+#define SIZE_OF_HEADER    8       /* floats */
 #define SIZE_OF_MCCPHOTON    8   /* floats */
 
Index: trunk/MagicSoft/Simulation/Detector/include-MC/MCEventHeader_2.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MC/MCEventHeader_2.hxx	(revision 1672)
+++ trunk/MagicSoft/Simulation/Detector/include-MC/MCEventHeader_2.hxx	(revision 1674)
@@ -39,5 +39,5 @@
 #include "COREventHeader.hxx"
 
-#define SIZE_OF_MCEVENTHEADER_2    178   /* floats */
+#define SIZE_OF_MCEVENTHEADER_2    181   /* floats */
 
 // @endcode
Index: trunk/MagicSoft/Simulation/Detector/include-MC/MCRunHeader.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MC/MCRunHeader.cxx	(revision 1674)
+++ trunk/MagicSoft/Simulation/Detector/include-MC/MCRunHeader.cxx	(revision 1674)
@@ -0,0 +1,22 @@
+/////////////////////////////////////////////////////////////////
+//
+// MCRunHeader
+//
+//  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 MCRunHeader.cxx}
+
+// @subsection Class {\em MCRunHeader}: Implementation
+
+// @code
+
+#include "MCRunHeader.hxx"
+
+// @endcode
Index: trunk/MagicSoft/Simulation/Detector/include-MC/MCRunHeader.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/include-MC/MCRunHeader.hxx	(revision 1674)
+++ trunk/MagicSoft/Simulation/Detector/include-MC/MCRunHeader.hxx	(revision 1674)
@@ -0,0 +1,104 @@
+/////////////////////////////////////////////////////////////////
+//
+// MCRunHeader
+//
+//  Created: Wed Oct 30 17:43:14 2002
+//  Author:  Oscar Blanch Bigas
+//  Purpose: Base class for RunHeader-classes
+//  Notes:   
+//
+/////////////////////////////////////////////////////////////////
+
+// @T \newpage
+
+// @section Source code of {\tt MCRunHeader.hxx}
+
+/* @text
+This section shows the include file {\tt MCRunHeader.hxx}
+@endtext */
+
+#ifndef MCRunHeader_Class
+#define MCRunHeader_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>
+
+#define SIZE_OF_MCRUNHEADER    272   /* floats */
+
+// @endcode
+
+// @subsection Class {\em MCRunHeader}: Definition
+
+// @code
+class MCRunHeader {
+
+protected:
+    Float_t RunNumber;
+    Float_t date;
+    Float_t Corsika_version;
+    Float_t NumObsLev;
+    Float_t HeightLev[10];
+    Float_t SlopeSpec;  /* Slope of primaries' energy spectrum */
+    Float_t ELowLim;
+    Float_t EUppLim;    /* Limits of energy range for generation */
+    Float_t EGS4_flag;
+    Float_t NKG_flag;
+    Float_t Ecutoffh;
+    Float_t Ecutoffm;
+    Float_t Ecutoffe;
+    Float_t Ecutoffg;
+    /* Physical constants and interaction flags (see CORSIKA manual): */
+    Float_t C[50];
+    Float_t dummy1[20]; /* not used */
+    Float_t CKA[40];
+    Float_t CETA[5];
+    Float_t CSTRBA[11];
+    Float_t dummy2[104]; /* not used */
+    Float_t AATM[5];
+    Float_t BATM[5];
+    Float_t CATM[5];
+    Float_t NFL[4];
+
+public:
+  MCRunHeader(void) {}  // default constructor
+
+  virtual ~MCRunHeader(void) {}  // default destructor
+  
+  // reads EventHeader from binary input stream
+  Int_t read ( ifstream &is ) {
+    is.read ( (char *)this, mysize() ); 
+    return is.gcount();
+  }
+
+  // writes EventHeader to binary output stream
+  Int_t write ( ofstream &os ) {
+    os.write ( (char *)this, mysize() ); 
+    return 0;
+  }
+  
+  inline int mysize(void) 
+    { return ( sizeof( float ) * SIZE_OF_MCRUNHEADER ); }
+
+  inline void print ( void ) {
+    float *ptr = (float *)this;
+    for(int i=0; i<SIZE_OF_MCRUNHEADER; ++i,++ptr)
+      cerr << i << ':' << *ptr << '\n';
+  }
+
+};
+// @endcode
+
+#endif  // not defined MCRunHeader_Class
