/* @file  pmSourcePhotometry.h
 * @brief functions to measure source photometry
 *
 * @author EAM, IfA; GLG, MHPCC
 *
 * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
 * @date $Date: 2007-01-24 02:54:15 $
 * Copyright 2004 Maui High Performance Computing Center, University of Hawaii
 */

# ifndef PM_SOURCE_PHOTOMETRY_H
# define PM_SOURCE_PHOTOMETRY_H

/// @addtogroup Objects Object Detection / Analysis Functions
/// @{

/**
 *
 * The function returns both the magnitude of the fit, defined as -2.5log(flux),
 * where the flux is integrated under the model, theoretically from a radius of 0
 * to infinity. In practice, we integrate the model beyond 50sigma.  The aperture magnitude is
 * defined as -2.5log(flux) , where the flux is summed for all pixels which are
 * not excluded by the aperture mask. The model flux is calculated by calling the
 * model-specific function provided by pmModelFlux_GetFunction.
 *
 * XXX: must code this.
 *
 */

typedef enum {
    PM_SOURCE_PHOT_NONE   = 0x0000,
    PM_SOURCE_PHOT_GROWTH = 0x0001,
    PM_SOURCE_PHOT_APCORR = 0x0002,
    PM_SOURCE_PHOT_WEIGHT = 0x0004,
    PM_SOURCE_PHOT_INTERP = 0x0008,
} pmSourcePhotometryMode;

bool pmSourcePhotometryModel(
    float *fitMag,                      ///< integrated fit magnitude
    pmModel *model                      ///< model used for photometry
);

bool pmSourcePhotometryAper(
    float   *apMag,                     ///< aperture flux magnitude
    pmModel *model,                     ///< model used for photometry
    psImage *image,                     ///< image pixels to be used
    psImage *mask                       ///< mask of pixels to ignore
);

bool pmSourceMagnitudesInit (psMetadata *config);
bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode);
double pmSourceCrossProduct(const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum);
double pmSourceCrossWeight(const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum);
bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask);
bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight);
pmModel *pmSourceGetModel (bool *isPSF, const pmSource *source);

double pmSourceWeight(const pmSource *Mi, int term, const bool unweighted_sum);

/// @}
# endif /* PM_SOURCE_PHOTOMETRY_H */
