Index: trunk/ippToPsps/jython/detectionbatch.py
===================================================================
--- trunk/ippToPsps/jython/detectionbatch.py	(revision 39096)
+++ trunk/ippToPsps/jython/detectionbatch.py	(revision 39097)
@@ -372,6 +372,18 @@
         sqlLine = sqlUtility("INSERT INTO " + tableName + "(")
 
+        nInjected = int(self.getKeyInt(header, 0, 'DETEFF.NUM'))
+        detectionThreshold = self.getKeyFloat(header, "%.8f", 'DETEFF.MAGREF')
+        expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME')
+        zp      = self.getKeyFloat(header, "%.8f", 'ZPT_OBS')
+
+        zpImage = self.scratchDb.getImageZeroPoint(self.imageIDs[ota])
+
+        # XXX zp correction should come from DVO
+        detectionThreshold = detectionThreshold + zpImage + 2.5 * math.log10(expTime)
+
+
         sqlLine.group("frameID",          str(self.expID))
-        sqlLine.group("magref",           self.getKeyFloat(header,"%.8f","DETEFF.MAGREF"))
+        sqlLine.group("magref",           detectionThreshold)
+        sqlLine.group("nInjected",        nInjected)
         sql = sqlLine.make(") VALUES ( ", ")")
                       
@@ -1063,5 +1075,5 @@
         ## regex only works for -stilts import
         regex = ".*"
-    
+        
         ## for a quick test, just do the first chip:
         if self.config.test and self.config.camera == "gpc1":
Index: trunk/ippToPsps/jython/diffbatch.py
===================================================================
--- trunk/ippToPsps/jython/diffbatch.py	(revision 39096)
+++ trunk/ippToPsps/jython/diffbatch.py	(revision 39097)
@@ -507,14 +507,25 @@
         header = self.header[num]
         zpImage = self.getKeyFloat(header,"%.8f","FPA.ZP")
+        expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME')
 
         if zpImage == 0.0:
             self.logger.infoPair("CZW If this value for the zeropoint is zero, the getImageZeroPoint call is likely still broken", str(zpImage))
 
-        magref = self.getKeyFloat(header,"%.8f","DETEFF.MAGREF") + zpImage
+
+        deteffHeader = self.posFits[num].findAndReadHeader("SkyChip.deteff", self.config.test)
+        if not deteffHeader:
+            if self.config.test: self.logger.errorPair("No header found for Skychip.deteff for", filter)
+            return False
+
+        magref = self.getKeyFloat(deteffHeader,"%.8f","DETEFF.MAGREF") + zpImage + 2.5 * math.log10(expTime)
         self.logger.infoPair("Found zeropoint and set magref", str(magref))
+
+        nInjected = int(self.getKeyInt(deteffHeader, 0, 'DETEFF.NUM'))
+        
 
         sqlLine = sqlUtility("INSERT INTO " + ippTableName + "(")
         sqlLine.group("diffImageID", str(diffSkyFileID))
         sqlLine.group("magref",       magref)
+        sqlLine.group("nInjected",    nInjected)
         sql = sqlLine.make(") VALUES ( ", ")")
 
Index: trunk/ippToPsps/jython/stackbatch.py
===================================================================
--- trunk/ippToPsps/jython/stackbatch.py	(revision 39096)
+++ trunk/ippToPsps/jython/stackbatch.py	(revision 39097)
@@ -265,5 +265,11 @@
         
         # Convert detectionThreshold to appropriate magnitudes
-        detectionThreshold = self.getKeyFloat(header, "%.8f", 'DETEFF.MAGREF')
+        # Grab this from the appropriate extension.
+        deteffHeader = self.fits[filter].findAndReadHeader("SkyChip.deteff", self.config.test)
+        if not deteffHeader:
+            if self.config.test: self.logger.errorPair("No header found for Skychip.deteff for", filter)
+            return False
+
+        detectionThreshold = self.getKeyFloat(deteffHeader, "%.8f", 'DETEFF.MAGREF')
         expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME')
         zp      = self.getKeyFloat(header, "%.8f", 'ZPT_OBS')
@@ -1168,4 +1174,25 @@
 
             header = self.headerSet[filter]
+
+            # Convert detectionThreshold to appropriate magnitudes
+            # Grab this from the appropriate extension.
+            deteffHeader = self.fits[filter].findAndReadHeader("SkyChip.deteff", self.config.test)
+            if not deteffHeader:
+                if self.config.test: self.logger.errorPair("No header found for Skychip.deteff for", filter)
+                return False
+
+            detectionThreshold = self.getKeyFloat(deteffHeader, "%.8f", 'DETEFF.MAGREF')
+            expTime = self.getKeyFloat(header, "%.8f", 'EXPTIME')
+            zp      = self.getKeyFloat(header, "%.8f", 'ZPT_OBS')
+            zpErr   = self.getKeyFloat(header, "%.8f", 'ZPT_ERR')
+
+        # zp correction should comes from DVO (unless image is not in DVO)
+            zpImage = self.scratchDb.getImageZeroPoint(stackID)
+            if zpImage < 0.0:
+                zpImage = zp
+
+            detectionThreshold = detectionThreshold + zpImage + 2.5 * math.log10(expTime)
+            nInjected = int(self.getKeyInt(deteffHeader, 0, 'DETEFF.NUM'))
+
             zpImage = self.scratchDb.getImageZeroPoint(stackImageID)
             if zpImage < 0.0:
@@ -1176,4 +1203,5 @@
             sqlLine.group("stackImageID", str(stackImageID))
             sqlLine.group("magref",       magref)
+            sqlLine.group("nInjected",    nInjected)
             sql = sqlLine.make(") VALUES ( ", ")")
             
