32# include "Minuit2/FCNBase.h"
33# include "Minuit2/FunctionMinimum.h"
34# include "Minuit2/MnMigrad.h"
35# include "Minuit2/MnMinos.h"
36# include "Minuit2/MnPrint.h"
47#include "ndarray/eigen.h"
55namespace lsst {
namespace ip {
namespace diffim {
58meas::base::FlagDefinitionList dipoleFluxFlagDefinitions;
61meas::base::FlagDefinition
const DipoleFluxAlgorithm::FAILURE = dipoleFluxFlagDefinitions.addFailureFlag(
"general failure flag, set if anything went wrong");
62meas::base::FlagDefinition
const DipoleFluxAlgorithm::POS_FLAG = dipoleFluxFlagDefinitions.add(
"pos_flag",
"failure flag for positive, set if anything went wrong");
63meas::base::FlagDefinition
const DipoleFluxAlgorithm::NEG_FLAG = dipoleFluxFlagDefinitions.add(
"neg_flag",
"failure flag for negative, set if anything went wrong");
66 return dipoleFluxFlagDefinitions;
78 return dipoleCentroidFlagDefinitions;
101 _psfDipoleFlux(psfDipoleFlux),
105 double Up()
const {
return _errorDef; }
121 if ((negFlux > 0.0) || (posFlux < 0.0)) {
126 posCenterX, posCenterY, posFlux);
127 double chi2 =
fit.first;
128 int nPix =
fit.second;
129 if (nPix > _maxPix) {
151 double negCenterX,
double negCenterY,
double negFlux,
152 double posCenterX,
double posCenterY,
double posFlux
171 footprint->getBBox());
187 negModelSubim += negSubim;
198 posModelSubim += posSubim;
203 residuals += posModel;
205 residuals *= residuals;
223 (boost::format(
"No footprint for source %d") % source.getId()).str());
228 if (peakCatalog.
size() == 0) {
230 (boost::format(
"No peak for source %d") % source.getId()).str());
232 else if (peakCatalog.
size() == 1) {
244 ROOT::Minuit2::MnUserParameters fitPar;
261 ROOT::Minuit2::MnMigrad migrad(minimizerFunc, fitPar);
266 ROOT::Minuit2::FunctionMinimum
min = migrad(_ctrl.
maxFnCalls);
268 float minChi2 =
min.Fval();
285 double evalChi2 =
fit.first;
286 int nPix =
fit.second;
298 source.set(_chi2dofKey, evalChi2 / (nPix - minimizerFunc.
getNpar()));
299 source.set(_negCentroid.
getX(), minNegCentroid->getX());
300 source.set(_negCentroid.
getY(), minNegCentroid->getY());
301 source.set(_posCentroid.
getX(), minPosCentroid->getX());
302 source.set(_posCentroid.
getY(), minPosCentroid->getY());
303 source.set(_avgCentroid.
getX(), 0.5*(minNegCentroid->getX() + minPosCentroid->getX()));
304 source.set(_avgCentroid.
getY(), 0.5*(minNegCentroid->getY() + minPosCentroid->getY()));
#define LSST_EXCEPT(type,...)
Create an exception with a given type.
Record class that represents a peak in a Footprint.
float getPeakValue() const
A class to contain the data, WCS, and other information needed to describe an image of the sky.
lsst::geom::Box2I getBBox(ImageOrigin origin=PARENT) const
A class to represent a 2-dimensional array of pixels.
A class to manipulate images, masks, and variance as a single object.
A class to evaluate image statistics.
size_type size() const
Return the number of elements in the catalog.
reference back() const
Return the last record.
reference front() const
Return the first record.
T Value
The data type for get and set.
Record class that contains measurements made on a single exposure.
An integer coordinate rectangle.
int getMinY() const noexcept
int getMinX() const noexcept
int getMaxX() const noexcept
int getMaxY() const noexcept
static meas::base::FlagDefinition const FAILURE
static meas::base::FlagDefinition const POS_FLAG
static meas::base::FlagDefinition const NEG_FLAG
static meas::base::FlagDefinitionList const & getFlagDefinitions()
static meas::base::FlagDefinitionList const & getFlagDefinitions()
ResultKey const & getPositiveKeys() const
Return the standard flux keys registered by this algorithm.
static meas::base::FlagDefinition const POS_FLAG
static meas::base::FlagDefinition const NEG_FLAG
ResultKey const & getNegativeKeys() const
meas::base::FlagHandler _flagHandler
static meas::base::FlagDefinition const FAILURE
Class to minimize PsfDipoleFlux; this is the object that Minuit minimizes.
void setMaxPix(int maxPix)
void setErrorDef(double def)
virtual double operator()(std::vector< double > const ¶ms) const
MinimizeDipoleChi2(PsfDipoleFlux const &psfDipoleFlux, afw::table::SourceRecord &source, afw::image::Exposure< float > const &exposure)
float stepSizeCoord
"Default initial step size for coordinates in non-linear fitter" ;
double errorDef
"How many sigma the error bars of the non-linear fitter represent" ;
float stepSizeFlux
"Default initial step size for flux in non-linear fitter" ;
int maxFnCalls
"Maximum function calls for non-linear fitter; 0 = unlimited" ;
Implementation of Psf dipole flux.
std::pair< double, int > chi2(afw::table::SourceRecord &source, afw::image::Exposure< float > const &exposure, double negCenterX, double negCenterY, double negFlux, double posCenterX, double poCenterY, double posFlux) const
void measure(afw::table::SourceRecord &measRecord, afw::image::Exposure< float > const &exposure) const
Called to measure a single child source in an image.
void fail(afw::table::SourceRecord &measRecord, meas::base::MeasurementError *error=NULL) const
Handle an exception thrown by the current algorithm by setting flags in the given record.
afw::table::Key< CentroidElement > getX() const
Return a Key for the x coordinate.
afw::table::Key< CentroidElement > getY() const
Return a Key for the y coordinate.
vector-type utility class to build a collection of FlagDefinitions
void handleFailure(afw::table::BaseRecord &record, MeasurementError const *error=nullptr) const
Handle an expected or unexpected Exception thrown by a measurement algorithm.
Exception to be thrown when a measurement algorithm experiences a known failure mode.
Reports errors that are due to events beyond the control of the program.
afw::table::CatalogT< PeakRecord > PeakCatalog
Statistics makeStatistics(lsst::afw::image::Image< Pixel > const &img, lsst::afw::image::Mask< image::MaskPixel > const &msk, int const flags, StatisticsControl const &sctrl=StatisticsControl())
Handle a watered-down front-end to the constructor (no variance)
@ SUM
find sum of pixels in the image
@ NPOINT
number of sample points
Simple class used to define and document flags The name and doc constitute the identity of the FlagDe...