42 static double sq(
double x) {
return x *
x; }
50 double det = vxx * vyy - vxy * vxy;
63 stream <<
" number of elements " << starMatchList.
size() <<
std::endl;
69 unsigned s = starMatchList.
size();
72 for (
auto const &it : starMatchList) res[count++] = it.computeChi2(gtransfo);
76 static unsigned chi2_cleanup(
StarMatchList &starMatchList,
const double chi2Cut,
const Gtransfo >ransfo) {
78 for (
auto smi = starMatchList.
begin(); smi != starMatchList.
end();) {
79 if (smi->chi2 > chi2Cut) {
80 smi = starMatchList.
erase(smi);
102 _chi2 = _transfo->fit(*
this);
112 if (_chi2 <= 0)
return;
113 unsigned npair = int(size());
114 if (npair == 0)
break;
119 for (
auto &starMatch : *
this) chi2_array[count++] = starMatch.chi2 = starMatch.computeChi2(*_transfo);
122 double median = (npair & 1) ? chi2_array[npair / 2]
123 : (chi2_array[npair / 2 - 1] + chi2_array[npair / 2]) * 0.5;
126 cut = sq(nSigmas) * median;
127 nremoved = chi2_cleanup(*
this, cut, *_transfo);
134 int deno = (2. * size() - _transfo->getNpar());
135 return (deno > 0) ?
sqrt(_dist2 / deno) : -1;
139 for (
auto &smi : *
this) smi.setDistance(gtransfo);
143 if (!which)
return 0;
145 int initial_count = size();
154 return (initial_count - size());
159 setTransfo(std::make_shared<GtransfoLinShift>());
161 setTransfo(std::make_shared<GtransfoLin>());
172 if (!_transfo)
return nullptr;
174 auto old_transfo = _transfo->clone();
175 double old_chi2 = _chi2;
178 setTransfoOrder(_order);
180 auto inverted_transfo = _transfo->clone();
181 setTransfo(old_transfo.get());
185 return inverted_transfo;
191 for (si =
begin(); si !=
end() && count < nKeep; ++count, ++si)
197 for (
auto &starMatch : *
this) {
205 for (
auto const &starMatch : *
this) {
206 if (starMatch.computeDistance(identity) < mindist) n++;
212 const Gtransfo *posteriorTransfo)
const {
215 const Gtransfo &T1 = (priorTransfo) ? *priorTransfo :
id;
216 const Gtransfo &T2 = (posteriorTransfo) ? *posteriorTransfo :
id;
218 for (
auto const &starMatch : *
this) {
228 stream <<
" ================================================================" <<
std::endl 229 <<
" Transformation between lists of order " << getTransfoOrder() <<
std::endl 231 <<
" Chi2 = " << getChi2() <<
" Residual = " << computeResidual() <<
std::endl 232 <<
" Number in the list = " << size() <<
std::endl 233 <<
" ================================================================" <<
std::endl;
238 for (
auto const &starMatch : starMatchList)
239 dist2 += gtransfo.
apply(starMatch.point1).computeDist2(starMatch.point2);
244 unsigned s = starMatchList.
size();
247 for (
unsigned k = 0; k < s; ++k) chi2 += chi2s[k];
implements the linear transformations (6 real coefficients).
A hanger for star associations.
void setDistance(const Gtransfo >ransfo)
Sets the distance (residual) field of all std::list elements. Mandatory before sorting on distances...
double computeChi2(const Gtransfo >ransfo) const
returns the chi2 (using errors in the FatPoint's)
void setTransfoOrder(int order)
set transfo according to the given order.
std::unique_ptr< Gtransfo > inverseTransfo()
returns the inverse transfo (swap, fit(refineTransfo) , and swap).
Polynomial transformation class.
int recoveredNumber(double mindist) const
count the number of elements for which distance is < mindist
A Point with uncertainties.
void setDistance(const Gtransfo >ransfo)
to be used before sorting on distances.
Class for a simple mapping implementing a generic Gtransfo.
void dumpTransfo(std::ostream &stream=std::cout) const
print the matching transformation quality (transfo, chi2, residual)
friend bool sameStar2(const StarMatch &one, const StarMatch &two)
unsigned removeAmbiguities(const Gtransfo >ransfo, int which=3)
cleans up the std::list of pairs for pairs that share one of their stars, keeping the closest one...
friend bool sameStar1(const StarMatch &one, const StarMatch &two)
double computeResidual() const
returns the average 1d Residual (last call to refineTransfo)
virtual void transformPosAndErrors(const FatPoint &in, FatPoint &out) const
friend bool compareStar2(const StarMatch &one, const StarMatch &two)
A do-nothing transformation. It anyway has dummy routines to mimick a Gtransfo.
void refineTransfo(double nSigmas)
removes pairs beyond nSigmas in distance (where the sigma scale is set by the fit) and iterates until...
friend std::ostream & operator<<(std::ostream &stream, const StarMatch &Match)
double computeDist2(const StarMatchList &S, const Gtransfo >ransfo)
sum of distance squared
a virtual (interface) class for geometric transformations.
friend bool compareStar1(const StarMatch &one, const StarMatch &two)
void swap()
swaps elements 1 and 2 of each starmatch in std::list.
void applyTransfo(StarMatchList &transformed, const Gtransfo *priorTransfo, const Gtransfo *posteriorTransfo=nullptr) const
enables to get a transformed StarMatchList.
void cutTail(int nKeep)
deletes the tail of the match std::list
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0