Index: trunk/MagicSoft/Simulation/Detector/Starfield/Makefile
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/Makefile	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/Makefile	(revision 5110)
@@ -3,5 +3,5 @@
 ## Starfield Generator Makefile
 ##
-## $Id: Makefile,v 1.3 2000-09-21 10:31:36 harald Exp $
+## $Id: Makefile,v 1.4 2004-09-17 17:36:25 moralejo Exp $
 ##   
 ##################################################################
@@ -16,12 +16,14 @@
 CXX      = g++
 
+
 INCLUDES = -I${INCLUDE} \
-	   -I${INCLUDE_COR}
+	   -I${INCLUDE_COR} \
+	   -I${ROOTSYS}/include
 
 WARNINGS = -Wall
 
-CXXFLAGS =  ${WARNINGS} ${INCLUDES} -ansi
+CXXFLAGS =  ${WARNINGS} ${INCLUDES}
 
-LIBS     = -L${RANLIBDIR} -L/usr/local/lib -L/usr/lib  -lm 
+LIBS     = -L${RANLIBDIR} -L/usr/local/lib -L/usr/lib  -lm
 
 
@@ -111,64 +113,2 @@
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
-
-starfield.o: starfield.h /usr/include/stdlib.h /usr/include/standards.h
-starfield.o: /usr/include/getopt.h /usr/include/sys/types.h
-starfield.o: /usr/include/mach/machine/vm_types.h /usr/include/sys/select.h
-starfield.o: /usr/include/string.h /usr/include/strings.h /usr/include/math.h
-starfield.o: /usr/include/dirent.h /usr/include/unistd.h
-starfield.o: /usr/include/sys/access.h /usr/include/sys/seek.h
-starfield.o: convertcorsika.h photon.hxx star.hxx /usr/include/stdio.h
-starfield.o: /usr/include/va_list.h /usr/include/sys/limits.h
-starfield.o: /usr/include/sys/machine/machlimits.h
-starfield.o: /usr/include/sys/syslimits.h /usr/include/sys/machine/machtime.h
-starfield.o: /usr/include/sys/rt_limits.h parameters.h
-star.o: star.hxx /usr/include/math.h /usr/include/standards.h
-star.o: /usr/include/stdlib.h /usr/include/getopt.h /usr/include/sys/types.h
-star.o: /usr/include/mach/machine/vm_types.h /usr/include/sys/select.h
-star.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdio.h
-star.o: /usr/include/sys/seek.h /usr/include/va_list.h
-star.o: /usr/include/sys/limits.h /usr/include/sys/machine/machlimits.h
-star.o: /usr/include/sys/syslimits.h /usr/include/sys/machine/machtime.h
-star.o: /usr/include/sys/rt_limits.h
-photon.o: photon.hxx /usr/include/math.h /usr/include/standards.h
-photon.o: /usr/include/stdlib.h /usr/include/getopt.h
-photon.o: /usr/include/sys/types.h /usr/include/mach/machine/vm_types.h
-photon.o: /usr/include/sys/select.h
-convertcorsika.o: convertcorsika.h /usr/include/string.h
-convertcorsika.o: /usr/include/standards.h /usr/include/sys/types.h
-convertcorsika.o: /usr/include/mach/machine/vm_types.h
-convertcorsika.o: /usr/include/sys/select.h /usr/include/strings.h photon.hxx
-convertcorsika.o: /usr/include/math.h /usr/include/stdlib.h
-convertcorsika.o: /usr/include/getopt.h
-parameters.o: parameters.h /usr/include/stdio.h /usr/include/standards.h
-parameters.o: /usr/include/sys/seek.h /usr/include/va_list.h
-parameters.o: /usr/include/sys/types.h /usr/include/mach/machine/vm_types.h
-parameters.o: /usr/include/sys/select.h /usr/include/getopt.h
-parameters.o: /usr/include/sys/limits.h /usr/include/sys/machine/machlimits.h
-parameters.o: /usr/include/sys/syslimits.h
-parameters.o: /usr/include/sys/machine/machtime.h
-parameters.o: /usr/include/sys/rt_limits.h
-../include-CORSIKA/COREventHeader.o: ../include-CORSIKA/COREventHeader.hxx
-../include-CORSIKA/COREventHeader.o: /usr/include/stdlib.h
-../include-CORSIKA/COREventHeader.o: /usr/include/standards.h
-../include-CORSIKA/COREventHeader.o: /usr/include/getopt.h
-../include-CORSIKA/COREventHeader.o: /usr/include/sys/types.h
-../include-CORSIKA/COREventHeader.o: /usr/include/mach/machine/vm_types.h
-../include-CORSIKA/COREventHeader.o: /usr/include/sys/select.h
-../include-CORSIKA/COREventHeader.o: /usr/include/math.h
-../include-CORSIKA/CORParticle.o: ../include-CORSIKA/CORParticle.hxx
-../include-CORSIKA/CORParticle.o: /usr/include/stdlib.h
-../include-CORSIKA/CORParticle.o: /usr/include/standards.h
-../include-CORSIKA/CORParticle.o: /usr/include/getopt.h
-../include-CORSIKA/CORParticle.o: /usr/include/sys/types.h
-../include-CORSIKA/CORParticle.o: /usr/include/mach/machine/vm_types.h
-../include-CORSIKA/CORParticle.o: /usr/include/sys/select.h
-../include-CORSIKA/CORParticle.o: /usr/include/math.h
-../include-CORSIKA/CORStatfile.o: ../include-CORSIKA/CORStatfile.hxx
-../include-CORSIKA/CORStatfile.o: /usr/include/stdlib.h
-../include-CORSIKA/CORStatfile.o: /usr/include/standards.h
-../include-CORSIKA/CORStatfile.o: /usr/include/getopt.h
-../include-CORSIKA/CORStatfile.o: /usr/include/sys/types.h
-../include-CORSIKA/CORStatfile.o: /usr/include/mach/machine/vm_types.h
-../include-CORSIKA/CORStatfile.o: /usr/include/sys/select.h
-../include-CORSIKA/CORStatfile.o: /usr/include/math.h
Index: trunk/MagicSoft/Simulation/Detector/Starfield/Makefile.osf
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/Makefile.osf	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/Makefile.osf	(revision 5110)
@@ -3,5 +3,5 @@
 ## Starfield Generator Makefile
 ##
-## $Id: Makefile.osf,v 1.1 2003-01-14 13:48:38 blanch Exp $
+## $Id: Makefile.osf,v 1.2 2004-09-17 17:36:25 moralejo Exp $
 ##   
 ##################################################################
@@ -110,64 +110,2 @@
 
 # DO NOT DELETE THIS LINE -- make depend depends on it.
-
-starfield.o: starfield.h /usr/include/stdlib.h /usr/include/standards.h
-starfield.o: /usr/include/getopt.h /usr/include/sys/types.h
-starfield.o: /usr/include/mach/machine/vm_types.h /usr/include/sys/select.h
-starfield.o: /usr/include/stdio.h /usr/include/sys/seek.h
-starfield.o: /usr/include/va_list.h /usr/include/sys/limits.h
-starfield.o: /usr/include/sys/machine/machlimits.h
-starfield.o: /usr/include/sys/syslimits.h /usr/include/sys/machine/machtime.h
-starfield.o: /usr/include/sys/rt_limits.h /usr/include/string.h
-starfield.o: /usr/include/strings.h /usr/include/math.h /usr/include/dirent.h
-starfield.o: /usr/include/unistd.h /usr/include/sys/access.h convertcorsika.h
-starfield.o: photon.hxx star.hxx parameters.h
-star.o: star.hxx /usr/include/math.h /usr/include/standards.h
-star.o: /usr/include/stdlib.h /usr/include/getopt.h /usr/include/sys/types.h
-star.o: /usr/include/mach/machine/vm_types.h /usr/include/sys/select.h
-star.o: /usr/include/string.h /usr/include/strings.h /usr/include/stdio.h
-star.o: /usr/include/sys/seek.h /usr/include/va_list.h
-star.o: /usr/include/sys/limits.h /usr/include/sys/machine/machlimits.h
-star.o: /usr/include/sys/syslimits.h /usr/include/sys/machine/machtime.h
-star.o: /usr/include/sys/rt_limits.h
-photon.o: photon.hxx /usr/include/math.h /usr/include/standards.h
-photon.o: /usr/include/stdlib.h /usr/include/getopt.h
-photon.o: /usr/include/sys/types.h /usr/include/mach/machine/vm_types.h
-photon.o: /usr/include/sys/select.h
-convertcorsika.o: convertcorsika.h /usr/include/string.h
-convertcorsika.o: /usr/include/standards.h /usr/include/sys/types.h
-convertcorsika.o: /usr/include/mach/machine/vm_types.h
-convertcorsika.o: /usr/include/sys/select.h /usr/include/strings.h photon.hxx
-convertcorsika.o: /usr/include/math.h /usr/include/stdlib.h
-convertcorsika.o: /usr/include/getopt.h
-parameters.o: parameters.h /usr/include/stdio.h /usr/include/standards.h
-parameters.o: /usr/include/sys/seek.h /usr/include/va_list.h
-parameters.o: /usr/include/sys/types.h /usr/include/mach/machine/vm_types.h
-parameters.o: /usr/include/sys/select.h /usr/include/getopt.h
-parameters.o: /usr/include/sys/limits.h /usr/include/sys/machine/machlimits.h
-parameters.o: /usr/include/sys/syslimits.h
-parameters.o: /usr/include/sys/machine/machtime.h
-parameters.o: /usr/include/sys/rt_limits.h
-../include-CORSIKA/COREventHeader.o: ../include-CORSIKA/COREventHeader.hxx
-../include-CORSIKA/COREventHeader.o: /usr/include/stdlib.h
-../include-CORSIKA/COREventHeader.o: /usr/include/standards.h
-../include-CORSIKA/COREventHeader.o: /usr/include/getopt.h
-../include-CORSIKA/COREventHeader.o: /usr/include/sys/types.h
-../include-CORSIKA/COREventHeader.o: /usr/include/mach/machine/vm_types.h
-../include-CORSIKA/COREventHeader.o: /usr/include/sys/select.h
-../include-CORSIKA/COREventHeader.o: /usr/include/math.h
-../include-CORSIKA/CORParticle.o: ../include-CORSIKA/CORParticle.hxx
-../include-CORSIKA/CORParticle.o: /usr/include/stdlib.h
-../include-CORSIKA/CORParticle.o: /usr/include/standards.h
-../include-CORSIKA/CORParticle.o: /usr/include/getopt.h
-../include-CORSIKA/CORParticle.o: /usr/include/sys/types.h
-../include-CORSIKA/CORParticle.o: /usr/include/mach/machine/vm_types.h
-../include-CORSIKA/CORParticle.o: /usr/include/sys/select.h
-../include-CORSIKA/CORParticle.o: /usr/include/math.h
-../include-CORSIKA/CORStatfile.o: ../include-CORSIKA/CORStatfile.hxx
-../include-CORSIKA/CORStatfile.o: /usr/include/stdlib.h
-../include-CORSIKA/CORStatfile.o: /usr/include/standards.h
-../include-CORSIKA/CORStatfile.o: /usr/include/getopt.h
-../include-CORSIKA/CORStatfile.o: /usr/include/sys/types.h
-../include-CORSIKA/CORStatfile.o: /usr/include/mach/machine/vm_types.h
-../include-CORSIKA/CORStatfile.o: /usr/include/sys/select.h
-../include-CORSIKA/CORStatfile.o: /usr/include/math.h
Index: trunk/MagicSoft/Simulation/Detector/Starfield/convertcorsika.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/convertcorsika.cxx	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/convertcorsika.cxx	(revision 5110)
@@ -48,5 +48,6 @@
     } 
   
-  cerfile.open(cor_dir, ios::out);
+  cerfile.open(cor_dir, ios::out|ios::binary);
+
   /*if((cerfilec=fopen(cor_dir,"wb"))==NULL){
     printf("C-style::Cannot create cerenkov file.\n");
@@ -128,5 +129,5 @@
   strcat(stat_dir, stat_file);
   
-  cerfile.open (stat_dir);
+  cerfile.open (stat_dir, ios::out|ios::binary);
   
   cout<<"Writing binary statistics file "<<" "<<stat_dir<<" "<<"..."<<endl;
Index: trunk/MagicSoft/Simulation/Detector/Starfield/parameters.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/parameters.cxx	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/parameters.cxx	(revision 5110)
@@ -18,6 +18,4 @@
   float dec_arcsec;
   char dummy[160];
-
-  in->ipfx(1); // tell the io system that we are reading formatted
 
   in->getline(dummy, sizeof(dummy), '\n'); 
Index: trunk/MagicSoft/Simulation/Detector/Starfield/parameters.h
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/parameters.h	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/parameters.h	(revision 5110)
@@ -2,6 +2,6 @@
 #define _PARAMETERS_H_
 
-#include <iostream.h>
-#include <fstream.h>
+#include <iostream>
+#include <fstream>
 #include <stdio.h>
 
@@ -14,4 +14,5 @@
 #endif
 
+using namespace std;
 
 class parameters {
Index: trunk/MagicSoft/Simulation/Detector/Starfield/photon.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/photon.hxx	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/photon.hxx	(revision 5110)
@@ -9,5 +9,5 @@
 
 #include <math.h>
-#include <iostream.h>
+#include <iostream>
 #include <stdlib.h>
 
Index: trunk/MagicSoft/Simulation/Detector/Starfield/star.hxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/star.hxx	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/star.hxx	(revision 5110)
@@ -4,8 +4,8 @@
 
 #include <math.h>
-#include <string.h>
 #include <stdio.h>
-#include <iostream.h>
-#include <fstream.h>
+#include <iostream>
+#include <string>
+#include <fstream>
 #include "jcmacros.h"
 
@@ -63,5 +63,5 @@
 #endif
 
-
+using namespace std;
 
 class star{
Index: trunk/MagicSoft/Simulation/Detector/Starfield/starfield.cxx
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/starfield.cxx	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/starfield.cxx	(revision 5110)
@@ -4,4 +4,10 @@
 // (c) 2000 D. Petry 
 //
+// 15/09/2004, A. Moralejo: 
+// - Adapted to gcc 3.2 under root 3.05.07
+// - Fixed algorithm to calculate director cosines of incident photons.
+//   Former algorithm resulted in mirrored images on the camera (which we
+//   must not have after reflection on a parabollic dish).
+//
 /////////////////////////////////////////////////////////////////////////
 
@@ -9,9 +15,9 @@
 #include "starfield.h"
 
-#define PROGRAMID "$Id: starfield.cxx,v 1.3 2000-09-21 10:31:36 harald Exp $"
+#define PROGRAMID "$Id: starfield.cxx,v 1.4 2004-09-17 17:36:25 moralejo Exp $"
 
 /////////////////////////////////////////////////////////////////////////
 
-main(int argc, char **argv)
+int main(int argc, char **argv)
 {
 
@@ -32,5 +38,6 @@
   float lmin_nm[4] = {ULMIN_nm, BLMIN_nm, VLMIN_nm, RLMIN_nm}; // wave band definitions
   float lmax_nm[4] = {ULMAX_nm, BLMAX_nm, VLMAX_nm, RLMAX_nm}; 
-  float theta_rad, costheta, phi_rad, randtime, lambda_nm, xdum_m, ydum_m;
+  float theta_rad, costheta, sintheta, phi_rad, randtime, lambda_nm, xdum_m, ydum_m;
+  float cosa, cosA, sinA;
   float angdist;
 
@@ -88,5 +95,6 @@
   cout << "<Goddard Space Flight Center, Flight Dynamics Division (1998)>\n";
 
-  angdist = fmod( pars.catalog_fov_deg / cos( pars.ct_dec_rad ), 360.);
+  angdist = fmod( (float) (pars.catalog_fov_deg/cos( pars.ct_dec_rad )), 
+		  (float) 360.);
 
   if(angdist > 180.){ // too near to the pole, have to loop over all files
@@ -192,11 +200,53 @@
     }
     
-    stars[i].u = -1. * cos( stars[i].dec_rad ) * sin( stars[i].ra_rad - pars.ct_ra_rad ) / costheta; 
-
-    stars[i].v = -1. * ( sin( pars.ct_dec_rad ) * cos( stars[i].dec_rad ) * 
-		 cos( stars[i].ra_rad - pars.ct_ra_rad ) -
-		 cos( pars.ct_dec_rad ) * sin( stars[i].dec_rad )
-		 ) / costheta;
-    
+    sintheta = sqrt(1.-costheta*costheta);
+
+    //
+    // A. Moralejo, 15/09/2004  
+    // We want the director cosines of the down-going versors along the photon 
+    // incident directions. This is what the Reflector program expects (also from the 
+    // normal Corsika output). We have used simple spherical trigonometry to obtain
+    // the formulae.
+    //
+    
+    // "cosa" is the cosine of the angle "a" between the star direction and the direction
+    // defined by declination = 0  and right ascension = ct_ra. "a" is one of the sides of 
+    // a spherical triangle. It is a quantity needed for the calculations.
+
+    cosa = cos( stars[i].ra_rad - pars.ct_ra_rad ) * cos( stars[i].dec_rad );
+
+    // cosA is the angle between the great circle of constant right ascension = ct_ra  and
+    // the great circle defined by the star direction and the telescope direction. "A" would
+    // be the angle opposite to the side "a" of a spherical triangle (see above)
+
+    cosA = (cosa - costheta*cos(pars.ct_dec_rad)) / (sintheta*sin(pars.ct_dec_rad));
+
+    // We now want A to be defined in the 0 - 2pi range, so that it becomes the azimuth angle
+    // of the star in a system defined by the telescope direction. "A" will be defined between
+    // 0 and pi if sin (star_ra - ct_ra) > 0, and between pi and 2 pi otherwise.
+
+    sinA = sqrt (1.-cosA*cosA);
+    if ( sin(stars[i].ra_rad - pars.ct_ra_rad ) < 0. )
+      sinA *= -1.;
+
+    stars[i].u = -1. * sintheta * cosA;
+    stars[i].v = -1. * sintheta * sinA;
+    
+
+    // Old implementation, commented out 15/09/2004:
+    //
+    // This produced director cosines which, when fed to reflector, makes on the camera plane 
+    // a mirror-inverted image of the FOV (with respect to what one would see "by eye"). That 
+    // is NOT what we want! After reflection on the parabollic mirror, the image on the camera 
+    // is NOT mirrored, but just rotated by 180 degree. The new implementation above produces
+    // the correct FOV (tested with Reflector 0.6)
+    //
+    //    stars[i].u = -1. * cos( stars[i].dec_rad ) * sin( stars[i].ra_rad - pars.ct_ra_rad ) / costheta; 
+    //    stars[i].v = -1. * ( sin( pars.ct_dec_rad ) * cos( stars[i].dec_rad ) * 
+    //		 cos( stars[i].ra_rad - pars.ct_ra_rad ) -
+    //		 cos( pars.ct_dec_rad ) * sin( stars[i].dec_rad )
+    //		 ) / costheta;
+    
+
     // calculate the "zenith angle" theta and "azimuth" phi of the star assuming 
     // the telecope points at the zenith 
@@ -211,5 +261,5 @@
       phi_rad = 2.*PI - acos(stars[i].u);
     }
-    
+
     // calculate number of photons
     
@@ -289,5 +339,5 @@
 
   convertcorsika( 
-		 ((int)pars.ct_ra_h*10)*1000 + (int)(abs(pars.ct_dec_deg)*10), // the file id
+		 ((int)pars.ct_ra_h*10)*1000 + (int)(fabs(pars.ct_dec_deg)*10), // the file id
 		 totalphotinside, photons, pars.integtime_s, pars.verbose, pars.output_file);
 
Index: trunk/MagicSoft/Simulation/Detector/Starfield/starfield.h
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/starfield.h	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/starfield.h	(revision 5110)
@@ -4,9 +4,8 @@
 #define _STARFIELD_H_
 
-#include <iostream.h>
-#include <fstream.h>
+#include <iostream>
+#include <fstream>
 #include <stdlib.h>
 #include <stdio.h>
-#include <string.h>
 #include <math.h>
 #include <sys/types.h>
Index: trunk/MagicSoft/Simulation/Detector/Starfield/starfield.par
===================================================================
--- trunk/MagicSoft/Simulation/Detector/Starfield/starfield.par	(revision 5109)
+++ trunk/MagicSoft/Simulation/Detector/Starfield/starfield.par	(revision 5110)
@@ -9,5 +9,5 @@
 10.0
 Path inside which the star catalog data can be found:
-/usr/users/magicsol/blanch/Data
+/home/magic/MagicProgs/Simulation/Detector/Starfield/Data
 Verbosity level (0 = not verbose, 1 = verbose, 2 = very verbose, 3 = very very ...):
 0
