Index: trunk/Mars/msimreflector/MFresnelLens.cc
===================================================================
--- trunk/Mars/msimreflector/MFresnelLens.cc	(revision 19645)
+++ trunk/Mars/msimreflector/MFresnelLens.cc	(revision 19646)
@@ -244,5 +244,5 @@
 
         if (z<-fH)
-            gLog << warn << "Groove " << i << " deeper (" << z << ") than thickness of lens material (" << fH << ")." << endl;
+            *fLog << warn << "Groove " << i << " deeper (" << z << ") than thickness of lens material (" << fH << ")." << endl;
     }
 
@@ -292,5 +292,5 @@
         if (trans>1)
         {
-            gLog << err << "Transmission larger than 1." << endl;
+            *fLog << err << "Transmission larger than 1." << endl;
             return -1;
         }
@@ -310,5 +310,5 @@
             if (trans>1)
             {
-                gLog << warn << "Transmission at " << lambda << "nm (" << trans << ") after Fresnel correction larger than 1." << endl;
+                *fLog << warn << "Transmission at " << lambda << "nm (" << trans << ") after Fresnel correction larger than 1." << endl;
                 trans = 1;
             }
@@ -377,6 +377,12 @@
     // from the entrance of the lens => FIXME: To be checked
     const double rn = n1/n0;
-    const double c = (rn - 1) * (F + d/rn); // FIXME
+    const double c = (rn - 1) * (F + d/rn); // FIXME: try and error with a large d
     return -atan(r/c);
+
+    // F = 50.21
+    //       d= 10        d=20
+    // -:    47           43.7
+    // 0:    53.5         57.0
+    // +:    60.3         70.3
 }
 
@@ -693,5 +699,8 @@
         const int step = outgoing ^ !first ? 1 : -1;
         const int end  = outgoing ^ !first ? fGrooves.size() : 1;
-        const int beg  = j==0 ? ix : ix+(step);
+        const int beg  = j==0 ? ix : ix+step;
+
+        if (step==-1 && ix==1) // can not count downwards from here
+            continue;
 
         for (int i=beg; i!=end; i+=step)
@@ -1377,5 +1386,5 @@
         (lambda<fAbsorptionLength.GetXmin() || lambda>fAbsorptionLength.GetXmax()))
         {
-            gLog << err << "Wavelength " << lambda << "nm out of absorption range [" << fAbsorptionLength.GetXmin() << "nm;" << fAbsorptionLength.GetXmax() << "nm]" << endl;
+            *fLog << err << "Wavelength " << lambda << "nm out of absorption range [" << fAbsorptionLength.GetXmin() << "nm;" << fAbsorptionLength.GetXmax() << "nm]" << endl;
             return -1;
         }
@@ -1444,5 +1453,8 @@
         // from the entrance of the lens => FIXME: To be checked
         // (Propagating to F means not propagating a distance of F-H from the exit)
-        p.fVectorPart.SetZ(fH/2);
+        //p.fVectorPart.SetZ(fH-fH/2/fN);//fH/2); Found by try-and-error
+
+        // We are already at -H, adding F and setting Z=0 means going to -(F+H)
+        p.fVectorPart.SetZ(0);//fH/2); Found by try-and-error
 
         return cnt>=fMinHits && (fMaxHits==0 || cnt<=fMaxHits) ? cnt : -1;;
@@ -1488,5 +1500,5 @@
         (lambda<fAbsorptionLength.GetXmin() || lambda>fAbsorptionLength.GetXmax()))
         {
-            gLog << err << "Wavelength " << lambda << "nm out of absorption range [" << fAbsorptionLength.GetXmin() << "nm;" << fAbsorptionLength.GetXmax() << "nm]" << endl;
+            *fLog << err << "Wavelength " << lambda << "nm out of absorption range [" << fAbsorptionLength.GetXmin() << "nm;" << fAbsorptionLength.GetXmax() << "nm]" << endl;
             return -1;
         }
@@ -1558,5 +1570,5 @@
     {
         if (verbose)
-            gLog << all << e.id() << ": " << e.what() << endl;
+            *fLog << all << e.id() << ": " << e.what() << endl;
 
         // Hit point at bottom surface beyond allowed range
