Index: trunk/ppSim/src/ppSimPhotom.c
===================================================================
--- trunk/ppSim/src/ppSimPhotom.c	(revision 17628)
+++ trunk/ppSim/src/ppSimPhotom.c	(revision 18011)
@@ -8,18 +8,32 @@
     pmReadout *readout;
 
+    psMetadata *recipe = psMetadataLookupMetadata(&status, config->recipes, PPSIM_RECIPE); // Recipe
+
+    bool doPhotom = psMetadataLookupBool(&status, recipe, "PHOTOM"); // Density of fakes
+    if (!doPhotom) return true;
+    
     psphotModelClassInit ();
 
-    // find or define a pmFPAfile PSPHOT.INPUT
-    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PSPHOT.INPUT");
+    int blankMask = 0;		// XXX not sure what this should be set to...
+    ppSimMosaicChip(config, blankMask, view, "PPSIM.FORCE.CHIP", "PPSIM.INPUT");
+    ppSimMosaicChip(config, blankMask, view, "PPSIM.FAKE.CHIP", "PPSIM.OUTPUT");
+
+    // use PPSIM.FAKE.CHIP as the base since it is guaranteed to exist (derived from PPSIM.OUTPUT)
+    pmFPAfile *input = psMetadataLookupPtr (&status, config->files, "PPSIM.FAKE.CHIP");
     if (!status) {
-        psError(PSPHOT_ERR_CONFIG, false, "PSPHOT.INPUT I/O file is not defined");
+        psError(PSPHOT_ERR_CONFIG, false, "PPSIM.FAKE.CHIP I/O file is not defined");
         return false;
     }
 
-    // we make a new copy of the output chip to keep psphot from modifying the output image
-    // XXX is this needed for ppSim? (yes, unless we do not do photometry and make a simulated image)
-    pmChip *oldChip = pmFPAviewThisChip (view, input->src);
-    pmChip *newChip = pmFPAviewThisChip (view, input->fpa);
-    pmChipCopy (newChip, oldChip);
+    // XXX If we want to be able to write out both the positive and residual images, we will
+    // need to define an additional pmFPAfile container, and then make a copy as is done for
+    // PPIMAGE.CHIP -> PSPHOT.INPUT in ppImage.  At the moment, PPSIM.CHIP will write out the
+    // mosaicked image with the sources subtracted.
+
+    // XXX if input -> PSPHOT.INPUT, which is tied to PPSIM.CHIP with pmFPAfileDefineFromFile,
+    // then the following code creates the chip copy:
+    // pmChip *oldChip = pmFPAviewThisChip (view, input->src);
+    // pmChip *newChip = pmFPAviewThisChip (view, input->fpa);
+    // pmChipCopy (newChip, oldChip);
 
     // iterate over the cells and readout for this chip
@@ -33,8 +47,13 @@
 
             // run the actual photometry analysis
-            if (!psphotReadout (config, view)) {
+            if (!ppSimPhotomReadoutFake (config, view)) {
                 psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
                 return false;
             }
+            if (!ppSimPhotomReadoutForce (config, view)) {
+                psError(psErrorCodeLast(), false, "failure in psphotReadout for chip %d, cell %d, readout %d\n", view->chip, view->cell, view->readout);
+                return false;
+            }
+	    // ppSimDetectionLimits (config, view);
         }
     }
