Index: trunk/psphot/src/psphotEfficiency.c
===================================================================
--- trunk/psphot/src/psphotEfficiency.c	(revision 31452)
+++ trunk/psphot/src/psphotEfficiency.c	(revision 32348)
@@ -99,5 +99,5 @@
 
 /// Generate a fake image and add it in to the existing readout
-static bool effGenerate(psImage **xSrc, psImage **ySrc, // Positions of sources
+static pmReadout *effGenerate(psImage **xSrc, psImage **ySrc, // Positions of sources
                         const pmReadout *ro,            // Readout of interest
                         const pmPSF *psf,               // Point-spread function
@@ -152,5 +152,5 @@
         psFree(xAll);
         psFree(yAll);
-        return false;
+        return NULL;
     }
     psFree(magAll);
@@ -161,7 +161,7 @@
 
     psBinaryOp(ro->image, ro->image, "+", fakeRO->image);
-    psFree(fakeRO);
-
-    return true;
+
+    // return the readout so we can subtract it later
+    return fakeRO;
 }
 
@@ -169,4 +169,7 @@
 {
     bool status = true;
+
+    fprintf (stdout, "\n");
+    psLogMsg ("psphot", PS_LOG_INFO, "--- psphot Efficiency ---");
 
     // select the appropriate recipe information
@@ -290,6 +293,6 @@
 
     psImage *xFake = NULL, *yFake = NULL; // Coordinates of sources, each bin in a row
-    if (!effGenerate(&xFake, &yFake, readout, psf, magOffsets,
-                     numSources, magLim, radius, minFlux)) {
+    pmReadout *fakeRO = effGenerate(&xFake, &yFake, readout, psf, magOffsets, numSources, magLim, radius, minFlux);
+    if (!fakeRO) {
         psError(PS_ERR_UNKNOWN, false, "Unable to generate fake sources");
         psFree(xFake);
@@ -416,4 +419,5 @@
     psFree(significance);
 
+    // psphotFitSourcesLinearReadout subtracts the model fits
     if (!psphotFitSourcesLinearReadout(recipe, readout, fakeSourcesAll, psf, true)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to perform linear fit on fake sources.");
@@ -427,4 +431,5 @@
     psf->ApTrend = NULL;
 
+    // measure the magnitudes and fluxes for the sources
     if (!psphotMagnitudesReadout(config, recipe, view, readout, fakeSourcesAll, psf)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to measure magnitudes of fake sources.");
@@ -433,4 +438,14 @@
         psf->ApTrend = apTrend; // Casting away const!
         return false;
+    }
+
+    // replace the subtracted model fits
+    for (int i = 0; i < fakeSourcesAll->n; i++) {
+	pmSource *source = fakeSourcesAll->data[i];
+
+	// replace other sources?
+	if (!(source->tmpFlags & PM_SOURCE_TMPF_SUBTRACTED)) continue;
+	
+	pmSourceAdd (source, PM_MODEL_OP_FULL, maskVal);
     }
     psFree(fakeSourcesAll);
@@ -515,4 +530,8 @@
     psFree(fakeSources);
 
+    // subtract the faked sources from the original image
+    psBinaryOp(readout->image, readout->image, "-", fakeRO->image);
+    psFree(fakeRO);
+
     pmDetEff *de = pmDetEffAlloc(magLim, numSources, numBins); // Detection efficiency
     de->magOffsets = psVectorCopy(NULL, magOffsets, PS_TYPE_F32);
@@ -529,5 +548,5 @@
     psFree(de);
 
-    psLogMsg("psphot", PS_LOG_INFO, "Detection efficiency: %lf sec\n", psTimerClear("psphot.fake"));
+    psLogMsg("psphot", PS_LOG_WARN, "Detection efficiency: %lf sec\n", psTimerClear("psphot.fake"));
 
     return true;
