41static double sq(
double x) {
return x *
x; }
49 double det = vxx * vyy - vxy * vxy;
62 stream <<
" number of elements " << starMatchList.
size() <<
std::endl;
68 const AstrometryTransform &transform) {
71 for (
auto const &it : starMatchList)
result[
count++] = it.computeChi2(transform);
75static unsigned chi2_cleanup(StarMatchList &starMatchList,
const double chi2Cut,
76 const AstrometryTransform &transform) {
77 unsigned erased = starMatchList.removeAmbiguities(transform);
78 for (
auto smi = starMatchList.begin(); smi != starMatchList.end();) {
79 if (smi->chi2 > chi2Cut) {
80 smi = starMatchList.erase(smi);
102 _chi2 = _transform->fit(*
this);
112 if (_chi2 <= 0)
return;
113 unsigned npair = int(
size());
114 if (npair == 0)
break;
119 for (
auto &starMatch : *
this)
120 chi2_array[
count++] = starMatch.chi2 = starMatch.computeChi2(*_transform);
123 double median = (npair & 1) ? chi2_array[npair / 2]
124 : (chi2_array[npair / 2 - 1] + chi2_array[npair / 2]) * 0.5;
127 cut = sq(nSigmas) * median;
128 nremoved = chi2_cleanup(*
this, cut, *_transform);
135 int deno = (2. *
size() - _transform->getNpar());
136 return (deno > 0) ?
sqrt(_dist2 / deno) : -1;
140 for (
auto &smi : *
this) smi.setDistance(
transform);
144 if (!which)
return 0;
146 int initial_count =
size();
155 return (initial_count -
size());
160 setTransform(std::make_shared<AstrometryTransformLinearShift>());
162 setTransform(std::make_shared<AstrometryTransformLinear>());
173 if (!_transform)
return nullptr;
175 auto old_transform = _transform->clone();
176 double old_chi2 = _chi2;
181 auto inverted_transform = _transform->clone();
186 return inverted_transform;
198 for (
auto &starMatch : *
this) {
206 for (
auto const &starMatch : *
this) {
207 if (starMatch.computeDistance(identity) < mindist) n++;
219 for (
auto const &starMatch : *
this) {
229 stream <<
" ================================================================" <<
std::endl
234 <<
" ================================================================" <<
std::endl;
239 for (
auto const &starMatch : starMatchList)
240 dist2 +=
transform.apply(starMatch.point1).computeDist2(starMatch.point2);
245 auto chi2s(chi2_array(starMatchList,
transform));
247 for (
auto const &c : chi2s) chi2 += c;
A Point with uncertainties.
A hanger for star associations.
double computeChi2(const AstrometryTransform &transform) const
returns the chi2 (using errors in the FatPoint's)
std::unique_ptr< AstrometryTransform > inverseTransform()
returns the inverse transform (swap, fit(refineTransform) , and swap).
void setDistance(const AstrometryTransform &transform)
Sets the distance (residual) field of all std::list elements. Mandatory before sorting on distances.
void printTransform(std::ostream &stream=std::cout) const
print the matching transformation quality (transform, chi2, residual)
void swap()
swaps elements 1 and 2 of each starmatch in std::list.
double getChi2() const
access to the chi2 of the last call to refineTransform.
int getTransformOrder() const
returns the order of the used transform
void setTransform(const AstrometryTransform *transform)
sets a transform between the 2 std::lists and deletes the previous or default one....
int recoveredNumber(double mindist) const
count the number of elements for which distance is < mindist
void setTransformOrder(int order)
set transform according to the given order.
double computeResidual() const
returns the average 1d Residual (last call to refineTransform)
unsigned removeAmbiguities(const AstrometryTransform &transform, int which=3)
cleans up the std::list of pairs for pairs that share one of their stars, keeping the closest one.
void cutTail(int nKeep)
deletes the tail of the match std::list
void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform, const AstrometryTransform *posteriorTransform=nullptr) const
enables to get a transformed StarMatchList.
void refineTransform(double nSigmas)
removes pairs beyond nSigmas in distance (where the sigma scale is set by the fit) and iterates until...
StarMatch erase(StarMatch ... args)
bool compareStar1(const StarMatch &one, const StarMatch &two)
bool sameStar2(const StarMatch &one, const StarMatch &two)
bool sameStar1(const StarMatch &one, const StarMatch &two)
bool compareStar2(const StarMatch &one, const StarMatch &two)
double computeDist2(const StarMatchList &S, const AstrometryTransform &transform)
sum of distance squared
double computeChi2(const StarMatchList &L, const AstrometryTransform &transform)
the actual chi2
std::ostream & operator<<(std::ostream &stream, AstrometryMapping const &mapping)
StarMatch unique(StarMatch ... args)