Index: trunk/doc/release.2015/ps1.analysis/analysis.tex
===================================================================
--- trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 40591)
+++ trunk/doc/release.2015/ps1.analysis/analysis.tex	(revision 40592)
@@ -623,5 +623,5 @@
 \label{sec:peaks}
 
-\note{add a ref to the Kaiser paper}
+%% is there a ref I can use for the optimal detection? see SDSS docs?
 
 The sources are initially detected by finding the location of local
@@ -1276,4 +1276,5 @@
 
 \subsubsection{Radial Profile Wings}
+\label{sec:radial.profile}
 
 We attempt to measure the radial profile of sources in order to find
@@ -1335,5 +1336,5 @@
 neighbors.
 
-\note{give a test example}
+% \note{give a test example}
 
 \subsubsection{Source Size Assessment}
@@ -1379,6 +1380,4 @@
 
 \subsubsection{Full PSF Model Fitting}
-
-% \note{review the discussion below}
 
 % gaussSigma = MOMENTS_GAUSS_SIGMA from recipe (initially)
@@ -1609,6 +1608,5 @@
 %% In order for a source to be included in the extended source
 %% analysis, it much have been detected in the 'bright source' analysis
-%% step ($S/N > 20$, Section~\ref{sec:xxxx}).  \note{is this restriction
-%% more or less severe than the mag limits?}  
+%% step ($S/N > 20$, Section~\ref{sec:xxxx}).  
 
 The extended source analysis is not applied to all object which may be
@@ -1800,7 +1798,5 @@
   in][regarding the masking of saturated pixels]{waters2017}.  
 
-% \note{need a discussion of the detector saturation behavior
-
-% \note{more detail below?}  
+% \note{need a discussion of the detector saturation behavior?}
 
 Before the non-linear fitting may be performed, it is necessary to
@@ -1899,5 +1895,5 @@
 using an FFT-based convolution.
 
-\note{examples?  show timing comparisons?}
+% \note{examples?  show timing comparisons?}
 
 For the Exponential and DeVaucouleur fits, all parameters are fitted
@@ -1978,36 +1974,41 @@
 minimize the impact of the stack image quality variations.
 
-In \code{psphotStack}, the stack analysis version of \code{psphot}, the 5 filter
-images are processed together.  After the PSF models have been fitted
-and a best set of galaxy models have been determined, three sets of
-radial apertures are measured.  In the first set, the fluxes in the
-radial apertures are measured using the raw stack images.  The centers
-of the apertures for each source across the 5 filters are fixed so
-that the pixels represent the equivalent portions of the same galaxy
-for all 5 filters.  In this analysis, the best model for each source
-is subtracted from the image pixels for all sources excluding the
-source in consideration.  The 'best model' is determined based on the
-minimum $\chi^2$ value for the model fits.
+In \code{psphotStack}, the stack analysis version of \code{psphot},
+the 5 filter images are processed together.  After the PSF models have
+been fitted and a best set of galaxy models have been determined,
+three sets of fixed circular apertures are measured.  In the first
+set, the fluxes in the apertures are measured using the raw stack
+images.  The centers of the apertures for each source across the 5
+filters are fixed so that the pixels represent the equivalent portions
+of the same galaxy for all 5 filters.  In this analysis, the best
+model for each source is subtracted from the image pixels for all
+sources excluding the source in consideration.  The 'best model' is
+determined based on the minimum $\chi^2$ value for the model fits.
+
+In addition to the raw fixed circular apertures, the stack images are
+each convolved with a circular Gaussian with $\sigma$ chosen to yield
+an image with a typical FWHM of 6 pixels (1.5\arcsec).  The full set
+of circular apertures are again measured on these convolved images.
+Again, the best source models are subtracted from the image for
+sources not being measured.  This subtraction includes the convolution
+to smooth the model to the effective FWHM of the convolved image.  The
+entire procedure is then repeated with a target FWHM of 8 pixels
+(2\arcsec).
 
 For the PV3 analysis of the $3\pi$ survey data, the fluxes are
-measured for a set of 9 circular apertures with sizes chosen to match
-the similar circular apertures measured by the SDSS analysis.   are measured 
+measured for a set of up to 9 circular apertures with sizes chosen to
+match the similar circular apertures measured by the SDSS analysis.
+These apertures have radii of (4.16, 7.04, 12.0, 18.56, 29.76, 45.68,
+72.80, 112.80, 176.88) pixels = (1.04, 1.76, 3.00, 4.64, 7.44, 11.42,
+18.20, 28.20, 44.22) arcseconds.  If the object is too faint, the
+larger apertures will be largely noise and the computation is
+wasteful.  We only calculate the circular apertures out to the second
+aperture larger than the ``sky radius'' (defined in
+Section~\label{sec:radial.profile}), but we calculate photometry for
+at least the smallest 4 apertures.
 
 % at least out to aperture # RADIAL_AP_MIN (= 4), but no further than
 % the aperture with radius > skyRadius
 % last bin is first with inner radius >= skyRadius
-
-% \note{more discussion of the selection of the best model}.  
-
-In addition to the raw radial apertures, the stack images are each
-convolved with a circular Gaussian with $\sigma$ chosen to yield an
-image with a typical FWHM of 6\arcsec.  The full set of radial
-apertures are again measured on these convolved images.  Again, the
-best source models are subtracted from the image for sources not being
-measured.  This subtraction includes the convolution to smooth the
-model to the effective FWHM of the convolved image.  The entire
-procedure is then repeated with a target FWHM of 8\arcsec.  
-
-% \note{is the first convolution done with the Alard-Lupton technique?}
 
 \subsection{Aperture Correction and Total Aperture Fluxes}
@@ -2186,5 +2187,5 @@
 \end{table*}
 
-\subsection{Output Formats}
+% \subsection{Output Formats}
 
 \section{Forced Photometry Modes}
@@ -2370,5 +2371,5 @@
 types of sources.  This model is fitted in the same portion of the
 code which performs the unconvolved galaxy model analysis.
-\note{describe the trailed analytical model}.
+% \note{describe the trailed analytical model}.
 
 In some cases, the stars in the two images may be somewhat offset.
@@ -2381,10 +2382,50 @@
 negative images will have stellar profiles, but they will be offset
 and will not subtract well.  The two components may not have the same
-amplitude.  In theory, a PSF-dipole model could be used to fit these types of
-sources, with free parameters of the two centroids and the two
-fluxes.  In practice in \ippprog{psphot}, we use a number of non-parametric
-pixel-level statistics in an attempt to detect these cases.  
-
-\note{list the parameters}
+amplitude.  In theory, a PSF-dipole model could be used to fit these
+types of sources, with free parameters of the two centroids and the
+two fluxes.  In practice in \ippprog{psphot}, we use a number of
+non-parametric pixel-level statistics in an attempt to detect these
+cases.
+
+For the difference images, we measure the following quantities for
+each of the detections, using only pixels within the photometry
+aperture.  First, we count the number of masked pixels (\code{nMask}),
+the number of pixels with positive flux (\code{nGood}), and the number
+of pixels with negative flux (\code{nBad}).  We also add the total
+flux in positive pixels (\code{fGood}) and total absolute value of the
+flux in negative pixels (\code{fBad}).  Using these values, We report
+the following quantities:
+\begin{itemize}
+\item \code{nGood}
+\item \code{fRatio} = \code{fGood} / (\code{fGood} + \code{fBad})
+\item \code{nRatioBad} = \code{nGood} / (\code{nGood} + \code{nBad})
+\item \code{nRatioMask} = \code{nGood} / (\code{nGood} + \code{nMask})
+\item \code{nRatioAll} = \code{nGood} / (\code{nGood} + \code{nMask} + \code{nBad})
+\end{itemize}
+
+We also attempt to place the difference image detections in the
+context of the input images, both the positive (subtrahend) and
+negative (minuend) images.  We identify the closest source in both the
+postive and negative images to the detection in the difference image,
+out to a maximum of \code{INPUT.MATCH.RADIUS} (= 50 pixels), but only
+if the source in those images has a signal-to-noise greater than
+\code{INPUT.MATCH.MIN.SN} (= 10).  If there is a close neighbor in the
+positive image, and the difference in the magnitudes of the source in
+that image and the source in the difference image is less than 5
+$\sigma$, then the bit \code{PM_SOURCE_MODE2_DIFF_SELF_MATCH =
+  0x00000800} is raised in \code{mask2} as these two detections are
+likely the same flux (\ie, detection of an isolated source).  
+
+If the difference image detection is matched to a nearby source in the
+positive image, then the signal-to-noise of the neighbor is saved as
+\code{DIFF_SN_P} and the distance in pixels between the difference
+detection and positive detection is saved as \code{DIFF_R_P}.
+Similarly, for a neighbor in the negative image, these values are
+saved as \code{DIFF_SN_M} and \code{DIFF_R_M}.  Additional
+\code{mask2} bits are also raised: if the difference detection is only
+associated with one of the two input images, then the bit
+\code{PM_SOURCE_MODE2_DIFF_WITH_SINGLE = 0x00000001} is raised, while
+a difference detection which has a match in both input images has
+\code{PM_SOURCE_MODE2_DIFF_WITH_DOUBLE = 0x00000002} raised. 
 
 Comets appear in the difference images as a non-PSF sources.  Their
@@ -2436,10 +2477,4 @@
 \end{document}
 
-\subsection{Output Options}
-
-% \note{need to discuss tests}
-
-% \note{need to discuss failings and holes}
-
 \begin{verbatim}
 Configuration variables affecting the peak detection process:
