LSST Applications 27.0.0,g0265f82a02+469cd937ee,g02d81e74bb+21ad69e7e1,g1470d8bcf6+cbe83ee85a,g2079a07aa2+e67c6346a6,g212a7c68fe+04a9158687,g2305ad1205+94392ce272,g295015adf3+81dd352a9d,g2bbee38e9b+469cd937ee,g337abbeb29+469cd937ee,g3939d97d7f+72a9f7b576,g487adcacf7+71499e7cba,g50ff169b8f+5929b3527e,g52b1c1532d+a6fc98d2e7,g591dd9f2cf+df404f777f,g5a732f18d5+be83d3ecdb,g64a986408d+21ad69e7e1,g858d7b2824+21ad69e7e1,g8a8a8dda67+a6fc98d2e7,g99cad8db69+f62e5b0af5,g9ddcbc5298+d4bad12328,ga1e77700b3+9c366c4306,ga8c6da7877+71e4819109,gb0e22166c9+25ba2f69a1,gb6a65358fc+469cd937ee,gbb8dafda3b+69d3c0e320,gc07e1c2157+a98bf949bb,gc120e1dc64+615ec43309,gc28159a63d+469cd937ee,gcf0d15dbbd+72a9f7b576,gdaeeff99f8+a38ce5ea23,ge6526c86ff+3a7c1ac5f1,ge79ae78c31+469cd937ee,gee10cc3b42+a6fc98d2e7,gf1cff7945b+21ad69e7e1,gfbcc870c63+9a11dc8c8f
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
78 double computeDistance(const AstrometryTransform &transform) const {
79 return point2.Distance(transform.apply(point1));
80 };
81
83 double computeChi2(const AstrometryTransform &transform) const;
84
86 void setDistance(const AstrometryTransform &transform) { distance = computeDistance(transform); };
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(); }
191 void setTransform(std::shared_ptr<AstrometryTransform> transform) { _transform = std::move(transform); }
192
194 void setTransformOrder(int order);
195
199
201 void setDistance(const AstrometryTransform &transform);
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
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::ostream & operator<<(std::ostream &stream, AstrometryMapping const &mapping)
::std::list< StarMatch >::const_iterator StarMatchCIterator
Definition StarMatch.h:135
STL namespace.
T swap(T... args)
table::Key< int > order