Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog	(revision 1960)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog	(revision 2046)
@@ -1,3 +1,31 @@
 ** Add changes at the beginning! **
+
+29/04/2003 A. Moralejo
+
+ph2cph.c:
+Changed determination of which mirror element is hit. Before there was a 
+problem when going to very large distances from the mirror center, sometimes
+a wrong mirror was chosen, which was actually further away from the impact 
+point than the mirror size, and therefore the photon was discarded later as
+"not hitting any mirror". Now we measure the distance on the paraboloid. The 
+new code is:
+
+  /*  calculate the mirror to be used */ 
+
+  distmirr = 1000000.0f;
+        
+  for (i=0; i<ct_NMirrors && distmirr>=ct_RMirror; ++i) {
+    distmirr2 = (float) sqrt(SQR(ct_data[i].sx - sx) +
+			     SQR(ct_data[i].sy - sy));
+
+    if (distmirr2 < distmirr) {
+      i_mirror = i;
+      distmirr  = distmirr2;
+    }
+  }
+
+geometry.c:
+Small change in calculation of ct_nax_radius (introduced fabs, but nothing 
+changes)
 
 16/04/2003 A. Moralejo
Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/geometry.c
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/geometry.c	(revision 1960)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/geometry.c	(revision 2046)
@@ -49,14 +49,16 @@
 	if (12 != fscanf(geofile, "%d %f %f %f %f %f %f %f %f %f %f %f",
 			 &ct_data[i].i,	    &ct_data[i].f,
-			 &ct_data[i].sx,	    &ct_data[i].sy,
-			 &ct_data[i].x,	    &ct_data[i].y,	&ct_data[i].z,
-			 &ct_data[i].theta,  &ct_data[i].phi,
-			 &ct_data[i].xn,	    &ct_data[i].yn,	&ct_data[i].zn))
+			 &ct_data[i].sx,    &ct_data[i].sy,
+			 &ct_data[i].x,	    &ct_data[i].y,   &ct_data[i].z,
+			 &ct_data[i].theta, &ct_data[i].phi,
+			 &ct_data[i].xn,    &ct_data[i].yn,	&ct_data[i].zn))
 	  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);
+	ct_max_radius = 
+	  (fabs(ct_data[i].sx) > ct_max_radius? fabs(ct_data[i].sx) : 
+	   ct_max_radius);
+	ct_max_radius = 
+	  (fabs(ct_data[i].sy) > ct_max_radius? fabs(ct_data[i].sy) : 
+	   ct_max_radius);
       }
 
Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c	(revision 1960)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c	(revision 2046)
@@ -142,9 +142,8 @@
 
   /*  get director cosines x,y on ground */  
-
   /*
   r[0] = 0.0;     
   r[1] = 0.0;    
-  r[2] = 1.0;    
+  r[2] = -1.0;    
   */
   /* CBC */
@@ -194,4 +193,5 @@
   applyMxV( OmegaCT, x, xCT );
   applyMxV( OmegaCT, r, rCT );        
+
 
   /* CBC */
@@ -293,5 +293,4 @@
   xcut[0] = xCT[0] + rCT[0]/rCT[2]*(xcut[2]-xCT[2]);
   xcut[1] = xCT[1] + rCT[1]/rCT[2]*(xcut[2]-xCT[2]);
-      
 
   /* CBC */
@@ -317,4 +316,5 @@
   }
 
+
   /*  calculate the mirror to be used */ 
 
@@ -322,7 +322,7 @@
         
   for (i=0; i<ct_NMirrors && distmirr>=ct_RMirror; ++i) {
-    distmirr2 = (float) sqrt(SQR(ct_data[i].x - xcut[0]) +
-		     SQR(ct_data[i].y - xcut[1]) +
-		     SQR(ct_data[i].z - xcut[2]));
+    distmirr2 = (float) sqrt(SQR(ct_data[i].sx - sx) +
+			     SQR(ct_data[i].sy - sy));
+
     if (distmirr2 < distmirr) {
       i_mirror = i;
@@ -332,5 +332,5 @@
 
   /* 
-   the mirror to use is i_mirror (calculated several lines above)
+   the mirror to use is i_mirror (calculated above)
    check whether the photon is outside the nearest (this) mirror
   */
