/* @file  pmSourcePhotometry.h
 * @brief functions to measure source photometry
 *
 * @author EAM, IfA; GLG, MHPCC
 *
 * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
 * @date $Date: 2008-07-15 20:25:00 $
 * 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
    psMaskType maskVal                  ///< Value to mask
);

bool pmSourceMagnitudesInit (psMetadata *config);
bool pmSourceMagnitudes (pmSource *source, pmPSF *psf, pmSourcePhotometryMode mode, psMaskType maskVal);
bool pmSourcePixelWeight (float *pixWeight, pmModel *model, psImage *image, psImage *mask, psMaskType maskVal);
bool pmSourceChisq (pmModel *model, psImage *image, psImage *mask, psImage *weight, psMaskType maskVal);


double pmSourceDataDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum);
double pmSourceModelDotModel (const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum);
double pmSourceModelWeight(const pmSource *Mi, int term, const bool unweighted_sum);

// retire these:
// double pmSourceCrossProduct(const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum);
// double pmSourceCrossWeight(const pmSource *Mi, const pmSource *Mj, const bool unweighted_sum);
// double pmSourceWeight(const pmSource *Mi, int term, const bool unweighted_sum);

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