Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog	(revision 2047)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/Changelog	(revision 2051)
@@ -1,3 +1,22 @@
 ** Add changes at the beginning! **
+
+30/04/2003 A. Moralejo
+
+ph2cph.c: Found out that the fix from yesterday, although it "patched" the 
+loss of photons, did not remove the real cause for it. Actually in the 
+determination of the intersection of the photon with the paraboloid there
+was an overflow which resulted in nonsense coordinates beyond 10 m from 
+the mirror dish center. It has been fixed fixed by changing the following 
+cut:
+
+  if ( fabs(a) < 1.e-3 ) {
+    xcut[2] = -c / b
+  }
+
+which was formerly < 1.e-6.
+
+I also noticed that the problem from yesterday was not so serious: it only 
+removed a significant amount of the photons nearly paralel to the telescope
+axis, but globally, over a cer file there is no big difference.
 
 29/04/2003 A. Moralejo
Index: trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c
===================================================================
--- trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c	(revision 2047)
+++ trunk/MagicSoft/Simulation/Detector/ReflectorII/ph2cph.c	(revision 2051)
@@ -78,5 +78,5 @@
   float phi;                  /* angle between photon and camera plane */ 
 
-  float a, b, c, t;           /* intermediate variables */ 
+  float a, b, c, t, t1, t2;   /* intermediate variables */ 
 
   float d;                    /* minimum distance trajectory-mirror center */ 
@@ -95,5 +95,4 @@
 
   float sx, sy;
-  float t1, t2;
   float dummy = 0.;
 
@@ -193,5 +192,4 @@
   applyMxV( OmegaCT, x, xCT );
   applyMxV( OmegaCT, r, rCT );        
-
 
   /* CBC */
@@ -240,5 +238,5 @@
  
   /*  the z coordinate is calculated */
- 
+
   a = - SQR(rCT[0]) - SQR(rCT[1]);
 
@@ -257,10 +255,20 @@
     - SQR(rCT[0])*SQR(xCT[2]) - SQR(rCT[1])*SQR(xCT[2]);
 
-
-  if ( fabs(a) < 1.e-6 ) {
-
-    /*  only one value */ 
-
-    xcut[2] = -c / b;
+  /* Alternative calculation (AM), same result:
+   *
+   * a = SQR(rCT[0])+SQR(rCT[1]);
+   * b = 2*xCT[0]*rCT[0]+2*xCT[1]*rCT[1]-4*ct_Focal_mean*rCT[2];
+   * c = -4*ct_Focal_mean*xCT[2]+SQR(xCT[0])+SQR(xCT[1]);
+   */
+
+  if ( fabs(a) < 1.e-3 ) {   /* Changed old cut value 1e-6 AM, 04/2003 */
+    xcut[2] = -c / b;         // Only one solution
+
+      /*
+       * Alternative calculation:
+       *  if (a < 1.e-3 )
+       *  {
+       *     xcut[2] = xCT[2] - c/b*rCT[2];
+       */
 
   } else {
@@ -281,7 +289,12 @@
 
     /*  z must be the minimum of t1 and t2 */ 
-          
+
     xcut[2] = (t1 < t2) ? t1 : t2;
 
+    /*
+     * Alternative calculation:
+     *
+     * xcut[2] = (t1 < t2) ? xCT[2]+t1*rCT[2] : xCT[2]+t2*rCT[2];  
+     */
   }
     
@@ -315,5 +328,4 @@
     return 2;
   }
-
 
   /*  calculate the mirror to be used */ 
