LSST Applications g063fba187b+cac8b7c890,g0f08755f38+6aee506743,g1653933729+a8ce1bb630,g168dd56ebc+a8ce1bb630,g1a2382251a+b4475c5878,g1dcb35cd9c+8f9bc1652e,g20f6ffc8e0+6aee506743,g217e2c1bcf+73dee94bd0,g28da252d5a+1f19c529b9,g2bbee38e9b+3f2625acfc,g2bc492864f+3f2625acfc,g3156d2b45e+6e55a43351,g32e5bea42b+1bb94961c2,g347aa1857d+3f2625acfc,g35bb328faa+a8ce1bb630,g3a166c0a6a+3f2625acfc,g3e281a1b8c+c5dd892a6c,g3e8969e208+a8ce1bb630,g414038480c+5927e1bc1e,g41af890bb2+8a9e676b2a,g7af13505b9+809c143d88,g80478fca09+6ef8b1810f,g82479be7b0+f568feb641,g858d7b2824+6aee506743,g89c8672015+f4add4ffd5,g9125e01d80+a8ce1bb630,ga5288a1d22+2903d499ea,gb58c049af0+d64f4d3760,gc28159a63d+3f2625acfc,gcab2d0539d+b12535109e,gcf0d15dbbd+46a3f46ba9,gda6a2b7d83+46a3f46ba9,gdaeeff99f8+1711a396fd,ge79ae78c31+3f2625acfc,gef2f8181fd+0a71e47438,gf0baf85859+c1f95f4921,gfa517265be+6aee506743,gfa999e8aa5+17cd334064,w.2024.51
LSST Data Management Base Package
Loading...
Searching...
No Matches
StarMatch.h
Go to the documentation of this file.
1// -*- LSST-C++ -*-
2/*
3 * This file is part of jointcal.
4 *
5 * Developed for the LSST Data Management System.
6 * This product includes software developed by the LSST Project
7 * (https://www.lsst.org).
8 * See the COPYRIGHT file at the top-level directory of this distribution
9 * for details of code ownership.
10 *
11 * This program is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation, either version 3 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <https://www.gnu.org/licenses/>.
23 */
24
25#ifndef LSST_JOINTCAL_STAR_MATCH_H
26#define LSST_JOINTCAL_STAR_MATCH_H
27
28#include <algorithm> // for swap
29#include <iostream>
30#include <iterator> // for std::ostream_iterator
31#include <list>
32#include <string>
33#include <utility>
34
35#include "lsst/jointcal/Point.h"
36#include "lsst/jointcal/BaseStar.h" // class definition used in inlined functions
37#include "lsst/jointcal/AstrometryTransform.h" // inlined function calls AstrometryTransform::apply()
38
39namespace lsst {
40namespace jointcal {
41
53
55class StarMatch {
56 friend class StarMatchList;
57
58public:
59 /* if one sets that private, then fitting routines will be a nightmare. we could set all the Transform
60 * classes friend... */
64 double distance{};
65 double chi2{};
66
68
73
74 // the next one would require that StarMatch knows BaseStar which is not mandatory for StarMatch to work
75 // StarMatch(BaseStar *star1, BaseStar *star2) : point1(*star1), point2(*star2), s1(star1), s2(star2) {};
76
79 return point2.Distance(transform.apply(point1));
80 };
81
83 double computeChi2(const AstrometryTransform &transform) const;
84
88 double getDistance() const { return distance; }
89
90 void swap() {
92 std::swap(s1, s2);
93 }
94
95 /* comparison that ensures that after a sort, duplicates are next one another */
96 explicit StarMatch() = default;;
97
98 friend std::ostream &operator<<(std::ostream &stream, const StarMatch &Match);
99
100 ~StarMatch() = default;
101
102private:
103 // bool operator < (const StarMatch & other) const { return (s1 > other.s1) ? s1 > other.s1 : s2 >
104 // other.s2;}
105
106 /* for unique to remove duplicates */
107 bool operator==(const StarMatch &other) const { return (s1 == other.s1 && s2 == other.s2); };
108 bool operator!=(const StarMatch &other) const { return (s1 != other.s1 || s2 != other.s2); };
109
110 friend bool compareStar1(const StarMatch &one, const StarMatch &two);
111 friend bool sameStar1(const StarMatch &one, const StarMatch &two);
112 friend bool compareStar2(const StarMatch &one, const StarMatch &two);
113 friend bool sameStar2(const StarMatch &one, const StarMatch &two);
114};
115
116inline bool compareStar1(const StarMatch &one, const StarMatch &two) {
117 return ((one.s1 == two.s1) ? (one.distance < two.distance) : (&(*one.s1) > &(*two.s1)));
118}
119
120inline bool sameStar1(const StarMatch &one, const StarMatch &two) { return (one.s1 == two.s1); }
121
122inline bool compareStar2(const StarMatch &one, const StarMatch &two) {
123 return ((one.s2 == two.s2) ? (one.distance < two.distance) : (&(*one.s2) > &(*two.s2)));
124}
125
126inline bool sameStar2(const StarMatch &one, const StarMatch &two) { return (one.s2 == two.s2); }
127
128/* =================================== StarMatchList
129 * ============================================================ */
130
131std::ostream &operator<<(std::ostream &stream, const StarMatch &match);
132
133//#ifdef TO_BE_FIXED
134using StarMatchIterator = ::std::list<StarMatch>::iterator;
135using StarMatchCIterator = ::std::list<StarMatch>::const_iterator;
136//#endif
137
139
148std::ostream &operator<<(std::ostream &stream, const StarMatchList &starMatchList);
149
150class StarMatchList : public std::list<StarMatch> {
151public:
152 void refineTransform(double nSigmas);
153
156 void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform,
157 const AstrometryTransform *posteriorTransform = nullptr) const;
158
159 /* constructor */
160 StarMatchList() : _order(0), _chi2(0){};
161
163
166
168 double getDist2() const { return _dist2; }
169
171 double getChi2() const { return _chi2; }
172
174 int getTransformOrder() const { return _order; }
175
177 void swap();
178
180 double computeResidual() const;
181
185 unsigned removeAmbiguities(const AstrometryTransform &transform, int which = 3);
186
188 void setTransform(const AstrometryTransform *transform) { _transform = transform->clone(); }
190 void setTransform(const AstrometryTransform &transform) { _transform = transform.clone(); }
192
194 void setTransformOrder(int order);
195
199
202
204 void cutTail(int nKeep);
205
207 int recoveredNumber(double mindist) const;
208
210 void printTransform(std::ostream &stream = std::cout) const;
211
212 ~StarMatchList() = default;
213 StarMatchList(const StarMatchList &) = delete; // copies not properly handled
214 void operator=(const StarMatchList &) = delete;
215
216private:
217 int _order;
218 double _chi2;
219 double _dist2{};
221};
222
224double computeDist2(const StarMatchList &S, const AstrometryTransform &transform);
225
227double computeChi2(const StarMatchList &L, const AstrometryTransform &transform);
228} // namespace jointcal
229} // namespace lsst
230
231#endif // LSST_JOINTCAL_STAR_MATCH_H
table::Key< int > transform
a virtual (interface) class for geometric transformations.
A Point with uncertainties.
Definition FatPoint.h:34
double Distance(const Point &other) const
Definition Point.h:51
A hanger for star associations.
Definition StarMatch.h:55
double computeChi2(const AstrometryTransform &transform) const
returns the chi2 (using errors in the FatPoint's)
Definition StarMatch.cc:43
std::shared_ptr< const BaseStar > s1
Definition StarMatch.h:63
std::shared_ptr< const BaseStar > s2
Definition StarMatch.h:63
StarMatch(FatPoint point1, FatPoint point2, std::shared_ptr< const BaseStar > star1, std::shared_ptr< const BaseStar > star2)
constructor.
Definition StarMatch.h:70
friend std::ostream & operator<<(std::ostream &stream, const StarMatch &Match)
Definition StarMatch.cc:55
void setDistance(const AstrometryTransform &transform)
to be used before sorting on distances.
Definition StarMatch.h:86
friend bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:126
double computeDistance(const AstrometryTransform &transform) const
returns the distance from transform(point1) to point2.
Definition StarMatch.h:78
double getDistance() const
returns the value computed by the above one.
Definition StarMatch.h:88
friend bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:122
FatPoint point2
2 points
Definition StarMatch.h:61
friend bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:120
friend bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:116
void operator=(const StarMatchList &)=delete
std::unique_ptr< AstrometryTransform > inverseTransform()
returns the inverse transform (swap, fit(refineTransform) , and swap).
Definition StarMatch.cc:172
void setDistance(const AstrometryTransform &transform)
Sets the distance (residual) field of all std::list elements. Mandatory before sorting on distances.
Definition StarMatch.cc:139
void setTransform(const AstrometryTransform &transform)
Definition StarMatch.h:190
void printTransform(std::ostream &stream=std::cout) const
print the matching transformation quality (transform, chi2, residual)
Definition StarMatch.cc:228
void swap()
swaps elements 1 and 2 of each starmatch in std::list.
Definition StarMatch.cc:197
double getChi2() const
access to the chi2 of the last call to refineTransform.
Definition StarMatch.h:171
void setTransform(std::shared_ptr< AstrometryTransform > transform)
Definition StarMatch.h:191
int getTransformOrder() const
returns the order of the used transform
Definition StarMatch.h:174
std::shared_ptr< const AstrometryTransform > getTransform() const
carries out a fit with outlier rejection
Definition StarMatch.h:165
StarMatchList(const StarMatchList &)=delete
void setTransform(const AstrometryTransform *transform)
sets a transform between the 2 std::lists and deletes the previous or default one....
Definition StarMatch.h:188
int recoveredNumber(double mindist) const
count the number of elements for which distance is < mindist
Definition StarMatch.cc:203
void setTransformOrder(int order)
set transform according to the given order.
Definition StarMatch.cc:158
double computeResidual() const
returns the average 1d Residual (last call to refineTransform)
Definition StarMatch.cc:134
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.
Definition StarMatch.cc:143
double getDist2() const
access to the sum of squared residuals of the last call to refineTransform.
Definition StarMatch.h:168
void cutTail(int nKeep)
deletes the tail of the match std::list
Definition StarMatch.cc:189
void applyTransform(StarMatchList &transformed, const AstrometryTransform *priorTransform, const AstrometryTransform *posteriorTransform=nullptr) const
enables to get a transformed StarMatchList.
Definition StarMatch.cc:212
void refineTransform(double nSigmas)
removes pairs beyond nSigmas in distance (where the sigma scale is set by the fit) and iterates until...
Definition StarMatch.cc:92
T move(T... args)
bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:116
bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:126
bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:120
bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition StarMatch.h:122
double computeDist2(const StarMatchList &S, const AstrometryTransform &transform)
sum of distance squared
Definition StarMatch.cc:237
double computeChi2(const StarMatchList &L, const AstrometryTransform &transform)
the actual chi2
Definition StarMatch.cc:244
::std::list< StarMatch >::iterator StarMatchIterator
Definition StarMatch.h:134
::std::list< StarMatch >::const_iterator StarMatchCIterator
Definition StarMatch.h:135
STL namespace.
basic_ostream< char, traits > & operator<<(basic_ostream< char, traits > &, const char *)
T swap(T... args)
table::Key< int > order