Index: /branches/eam_rel9_p0/psModules/src/objects/pmPSFtry.c
===================================================================
--- /branches/eam_rel9_p0/psModules/src/objects/pmPSFtry.c	(revision 5984)
+++ /branches/eam_rel9_p0/psModules/src/objects/pmPSFtry.c	(revision 5985)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  @version $Revision: 1.3.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-01-10 04:46:03 $
+ *  @version $Revision: 1.3.4.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-01-14 07:02:53 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -192,13 +192,13 @@
     //   we use an outlier rejection to avoid this bias
 
-    // rflux = ten(0.4*fitMag);
-    psVector *rflux = psVectorAlloc (psfTry->sources->n, PS_TYPE_F64);
+    // r2rflux = radius^2 * ten(0.4*fitMag);
+    psVector *r2rflux = psVectorAlloc (psfTry->sources->n, PS_TYPE_F64);
     for (int i = 0; i < psfTry->sources->n; i++) {
         if (psfTry->mask->data.U8[i] & PSFTRY_MASK_ALL)
             continue;
-        rflux->data.F64[i] = pow(10.0, 0.4*psfTry->fitMag->data.F64[i]);
-    }
-
-    // use 3hi/1lo sigma clipping on the rflux vs metric fit
+        r2rflux->data.F64[i] = PS_SQR(RADIUS) * pow(10.0, 0.4*psfTry->fitMag->data.F64[i]);
+    }
+
+    // use 3hi/1lo sigma clipping on the r2rflux vs metric fit
     psStats *stats = psStatsAlloc (PS_STAT_SAMPLE_MEDIAN | PS_STAT_SAMPLE_STDEV);
     stats->min = 1.0;
@@ -206,18 +206,19 @@
     stats->clipIter = 3;
 
-    // fit ApResid only to rflux, ignore x,y variations for now
-    // linear clipped fit of ApResid to rflux
+    // fit ApTrend only to r2rflux, ignore x,y,flux variations for now
+    // linear clipped fit of ApResid to r2rflux
     psPolynomial1D *poly = psPolynomial1DAlloc (1, PS_POLYNOMIAL_ORD);
-    poly = psVectorClipFitPolynomial1D (poly, stats, psfTry->mask, PSFTRY_MASK_ALL, psfTry->metric, NULL, rflux);
+    poly = psVectorClipFitPolynomial1D (poly, stats, psfTry->mask, PSFTRY_MASK_ALL, psfTry->metric, NULL, r2rflux);
     psLogMsg ("pmPSFtryMetric", 4, "fit stats: %f +/- %f\n", stats->sampleMedian, stats->sampleStdev);
 
-    psfTry->psf->ApTrend->coeff[0][0][0] = poly->coeff[0];
-    psfTry->psf->ApTrend->coeff[0][0][1] = 0;
-
-    psfTry->psf->skyBias  = poly->coeff[1] / (M_PI * PS_SQR(RADIUS));
+    pmPSF_MaskApTrend (psfTry->psf, PM_PSF_SKYBIAS);
+    psfTry->psf->ApTrend->coeff[0][0][0][0] = poly->coeff[0];
+    psfTry->psf->ApTrend->coeff[0][0][1][0] = 0;
+
+    psfTry->psf->skyBias  = poly->coeff[1];
     psfTry->psf->ApResid  = poly->coeff[0];
     psfTry->psf->dApResid = stats->sampleStdev;
 
-    psFree (rflux);
+    psFree (r2rflux);
     psFree (poly);
     psFree (stats);
