LSST Applications g180d380827+0f66a164bb,g2079a07aa2+86d27d4dc4,g2305ad1205+7d304bc7a0,g29320951ab+500695df56,g2bbee38e9b+0e5473021a,g337abbeb29+0e5473021a,g33d1c0ed96+0e5473021a,g3a166c0a6a+0e5473021a,g3ddfee87b4+e42ea45bea,g48712c4677+36a86eeaa5,g487adcacf7+2dd8f347ac,g50ff169b8f+96c6868917,g52b1c1532d+585e252eca,g591dd9f2cf+c70619cc9d,g5a732f18d5+53520f316c,g5ea96fc03c+341ea1ce94,g64a986408d+f7cd9c7162,g858d7b2824+f7cd9c7162,g8a8a8dda67+585e252eca,g99cad8db69+469ab8c039,g9ddcbc5298+9a081db1e4,ga1e77700b3+15fc3df1f7,gb0e22166c9+60f28cb32d,gba4ed39666+c2a2e4ac27,gbb8dafda3b+c92fc63c7e,gbd866b1f37+f7cd9c7162,gc120e1dc64+02c66aa596,gc28159a63d+0e5473021a,gc3e9b769f7+b0068a2d9f,gcf0d15dbbd+e42ea45bea,gdaeeff99f8+f9a426f77a,ge6526c86ff+84383d05b3,ge79ae78c31+0e5473021a,gee10cc3b42+585e252eca,gff1a9f87cc+f7cd9c7162,w.2024.17
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