Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog	(revision 1726)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog	(revision 1908)
@@ -1,3 +1,14 @@
 ** Add changes at the beginning! **
+
+4/04/2003 A. Moralejo
+
+init.h, geometry.c, ph2cph.c: 
+introduced variable ct_max_radius, the maximum distance in x or y from the 
+center to the edge of the telescope, measured on the parabolic dish. This
+is used in a fast check of whether the photon hits the disk in ph2cph.c
+
+ph2cph.c: 
+in function Lin2Curv(float x), changed the calculation of the curvilinear 
+coordinates (which before was only valid for ~17 m focus paraboloids).
 
 22/01/2003 A. Moralejo
Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/geometry.c
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/geometry.c	(revision 1726)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/geometry.c	(revision 1908)
@@ -18,4 +18,8 @@
 int	ct_NPixels;		/*  number of pixels		*/
 float	ct_PixelWidth;		/*  pixel width (cm)		*/
+float   ct_max_radius;          /* Maximum value of curvilinear
+				 * coordinates of the center of
+				 * the mirrors.
+				 */
 
 mirror *ct_data=NULL;		/*  ptr to mirror data		*/
@@ -32,4 +36,6 @@
 static void ReadMirrorTable(FILE *geofile)
 {   int i;	/*  Mirror index	*/
+
+    ct_max_radius = 0.;
 
     if ((ct_data=(mirror *)malloc(sizeof(mirror)*ct_NMirrors)) == NULL)
@@ -49,5 +55,10 @@
 	  break;
 
+	ct_max_radius = (ct_data[i].sx > ct_max_radius? ct_data[i].sx : 
+			 ct_max_radius);
+	ct_max_radius = (ct_data[i].sy > ct_max_radius? ct_data[i].sy : 
+			 ct_max_radius);
       }
+
     if (i < ct_NMirrors)
       FatalError(MIRR_FEW___FTL, i);
@@ -198,4 +209,6 @@
     fclose(geofile);
 
+    ct_max_radius += ct_RMirror;
+
     if (strlen(reflectivity_filename) == 0)
       strcpy(reflectivity_filename, REFLECTIVITY_FILE);
Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/init.h
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/init.h	(revision 1726)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/init.h	(revision 1908)
@@ -59,5 +59,8 @@
 extern int   ct_NPixels;		/*  number of pixels		*/
 extern float ct_PixelWidth;		/*  pixel width (cm)		*/
-
+extern float ct_max_radius;             /* Approximate mirror dish radius, 
+					 * used for fast rejection of photons 
+					 * not hitting the dish (in ph2cph.c).
+					 */
 
 typedef struct
Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c	(revision 1726)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c	(revision 1908)
@@ -92,4 +92,6 @@
 
   float distmirr, distmirr2;  /* distances used in MAGIC reflection routine */
+
+
   float sx, sy;
   float t1, t2;
@@ -307,6 +309,5 @@
 
   /*  is it outside the dish? */ 
-          
-  if ((fabs(sx) > 850.0) || (fabs(sy) > 850.0)) {
+  if ((fabs(sx) > ct_max_radius) || (fabs(sy) > ct_max_radius)) {
     /* 
     cout << "CONDITION 1 !" << endl << flush;
@@ -848,6 +849,11 @@
 Lin2Curv(float x)
 {
+/*
   x /= 100.f;
   return ((x + 0.000144175317185f * x * x * x)*100.f);
+*/
+
+  double k = 0.25/ct_Focal_mean;
+  return ((2*k*x*sqrt(1+4*k*k*x*x)+asinh(2*k*x))/4/k);
 }
 
