Index: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSource.h
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSource.h	(revision 33043)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSource.h	(revision 33044)
@@ -72,4 +72,5 @@
     psImage *pixels;                    ///< Rectangular region including object pixels.
     psImage *variance;			///< Image variance.
+    psImage *modelVar;			///< variance based on current models
     psImage *maskObj;                   ///< unique mask for this object which marks included pixels associated with objects.
     psImage *maskView;                  ///< view into global image mask for this object region
Index: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c	(revision 33043)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.c	(revision 33044)
@@ -900,5 +900,5 @@
 }
 
-double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
+double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
@@ -907,8 +907,19 @@
     const psImage *Pi = Mi->modelFlux;
     assert (Pi != NULL);
-    const psImage *Wi = Mi->variance;
-    if (!unweighted_sum) {
-        assert (Wi != NULL);
-    }
+
+    const psImage *Wi = NULL;
+    switch (fitVarMode) {
+      case PM_SOURCE_PHOTFIT_CONST:
+	break;
+      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	Wi = Mi->variance;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_MODEL_VAR:
+	Wi = Mi->modelVar;
+        psAssert (Wi, "programming error");
+	break;
+    }	
+
     const psImage *Ti = Mi->maskObj;
     assert (Ti != NULL);
@@ -916,10 +927,8 @@
     for (int yi = 0; yi < Pi->numRows; yi++) {
         for (int xi = 0; xi < Pi->numCols; xi++) {
-            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal)
-                continue;
-            if (!unweighted_sum) {
+            if (Ti->data.PS_TYPE_IMAGE_MASK_DATA[yi][xi] & maskVal) continue;
+            if (fitVarMode != PM_SOURCE_PHOTFIT_CONST) {
                 wt = covarFactor * Wi->data.F32[yi][xi];
-                if (wt == 0)
-                    continue;
+                if (wt == 0) continue;
             }
 
@@ -948,5 +957,5 @@
 }
 
-double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
+double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
@@ -963,8 +972,17 @@
     assert (Pj != NULL);
 
-    const psImage *Wi = Mi->variance;
-    if (!unweighted_sum) {
-        assert (Wi != NULL);
-    }
+    const psImage *Wi = NULL;
+    switch (fitVarMode) {
+      case PM_SOURCE_PHOTFIT_CONST:
+	break;
+      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	Wi = Mi->variance;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_MODEL_VAR:
+	Wi = Mi->modelVar;
+        psAssert (Wi, "programming error");
+	break;
+    }	
 
     const psImage *Ti = Mi->maskObj;
@@ -996,13 +1014,18 @@
                 continue;
 
-            // XXX skip the nonsense weight pixels?
-            if (unweighted_sum) {
-                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
-            } else {
+	    float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
+	    switch (fitVarMode) {
+	      case PM_SOURCE_PHOTFIT_CONST:
+		wt = 1.0;
+		break;
+	      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	      case PM_SOURCE_PHOTFIT_MODEL_VAR:
                 wt = covarFactor * Wi->data.F32[yi][xi];
-                if (wt > 0) {
-                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
-                }
-            }
+		break;
+	    }
+            // skip pixels with nonsense weight values
+	    if (wt <= 0) continue;
+
+	    flux += value / wt;
         }
     }
@@ -1010,5 +1033,5 @@
 }
 
-double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal)
+double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal)
 {
     PS_ASSERT_PTR_NON_NULL(Mi, NAN);
@@ -1025,8 +1048,17 @@
     assert (Pj != NULL);
 
-    const psImage *Wi = Mi->variance;
-    if (!unweighted_sum) {
-        assert (Wi != NULL);
-    }
+    const psImage *Wi = NULL;
+    switch (fitVarMode) {
+      case PM_SOURCE_PHOTFIT_CONST:
+	break;
+      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	Wi = Mi->variance;
+        psAssert (Wi, "programming error");
+	break;
+      case PM_SOURCE_PHOTFIT_MODEL_VAR:
+	Wi = Mi->modelVar;
+        psAssert (Wi, "programming error");
+	break;
+    }	
 
     const psImage *Ti = Mi->maskObj;
@@ -1058,13 +1090,19 @@
                 continue;
 
-            // XXX skip the nonsense weight pixels?
-            if (unweighted_sum) {
-                flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
-            } else {
+	    float value = (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]);
+	    switch (fitVarMode) {
+	      case PM_SOURCE_PHOTFIT_CONST:
+		wt = 1.0;
+		break;
+	      case PM_SOURCE_PHOTFIT_IMAGE_VAR:
+	      case PM_SOURCE_PHOTFIT_MODEL_VAR:
                 wt = covarFactor * Wi->data.F32[yi][xi];
-                if (wt > 0) {
-                    flux += (Pi->data.F32[yi][xi] * Pj->data.F32[yj][xj]) / wt;
-                }
-            }
+		break;
+	    }
+            // skip pixels with nonsense weight values
+	    if (wt <= 0) continue;
+
+	    flux += value / wt;
+
         }
     }
Index: /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.h
===================================================================
--- /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.h	(revision 33043)
+++ /branches/eam_branches/ipp-20111122/psModules/src/objects/pmSourcePhotometry.h	(revision 33044)
@@ -38,4 +38,10 @@
 } pmSourcePhotometryMode;
 
+typedef enum {
+    PM_SOURCE_PHOTFIT_CONST,
+    PM_SOURCE_PHOTFIT_IMAGE_VAR,
+    PM_SOURCE_PHOTFIT_MODEL_VAR,
+} pmSourceFitVarMode;
+
 bool pmSourcePhotometryModel(
     float *fitMag,                      ///< integrated fit magnitude
@@ -75,7 +81,7 @@
 bool pmSourceMeasureDiffStats (pmSource *source, psImageMaskType maskVal, psImageMaskType markVal);
 
-double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
-double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
-double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum, const float covarFactor, psImageMaskType maskVal);
+double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
+double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
+double pmSourceModelWeight(const pmSource *Mi, int term, const pmSourceFitVarMode fitVarMode, const float covarFactor, psImageMaskType maskVal);
 
 bool pmSourceNeighborFlags (pmSource *source);
