lsst.jointcal  master-ga8493ae4fe+5
StarMatch.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 #ifndef LSST_JOINTCAL_STAR_MATCH_H
3 #define LSST_JOINTCAL_STAR_MATCH_H
4 
5 #include <iostream>
6 #include <iterator> // for std::ostream_iterator
7 #include <algorithm> // for swap
8 #include <string>
9 #include <list>
10 
11 #include "lsst/jointcal/Point.h"
12 #include "lsst/jointcal/BaseStar.h" // class definition used in inlined functions
13 #include "lsst/jointcal/Gtransfo.h" // inlined function calls Gtransfo::apply()
14 
15 namespace lsst {
16 namespace jointcal {
17 
29 
31 class StarMatch {
32  friend class StarMatchList;
33 
34 public:
35  /* if one sets that private, then fitting routines will be a nightmare. we could set all the Transfo
36  * classes friend... */
38  std::shared_ptr<const BaseStar> s1, s2;
40  double distance;
41  double chi2;
42 
43 public:
45 
47  StarMatch(const FatPoint &point1, const FatPoint &point2, std::shared_ptr<const BaseStar> star1,
48  std::shared_ptr<const BaseStar> star2)
49  : point1(point1), point2(point2), s1(std::move(star1)), s2(std::move(star2)), distance(0.){};
50 
51  // the next one would require that StarMatch knows BaseStar which is not mandatory for StarMatch to work
52  // StarMatch(BaseStar *star1, BaseStar *star2) : point1(*star1), point2(*star2), s1(star1), s2(star2) {};
53 
55  double computeDistance(const Gtransfo &gtransfo) const {
56  return point2.Distance(gtransfo.apply(point1));
57  };
58 
60  double computeChi2(const Gtransfo &gtransfo) const;
61 
63  void setDistance(const Gtransfo &gtransfo) { distance = computeDistance(gtransfo); };
65  double getDistance() const { return distance; }
66 
67  void swap() {
68  std::swap(point1, point2);
69  std::swap(s1, s2);
70  }
71 
72  /* comparison that ensures that after a sort, duplicates are next one another */
73  explicit StarMatch(){};
74 
75  friend std::ostream &operator<<(std::ostream &stream, const StarMatch &Match);
76 
78 
79 private:
80  // bool operator < (const StarMatch & other) const { return (s1 > other.s1) ? s1 > other.s1 : s2 >
81  // other.s2;}
82 
83  /* for unique to remove duplicates */
84  bool operator==(const StarMatch &other) const { return (s1 == other.s1 && s2 == other.s2); };
85  bool operator!=(const StarMatch &other) const { return (s1 != other.s1 || s2 != other.s2); };
86 
87  friend bool compareStar1(const StarMatch &one, const StarMatch &two);
88  friend bool sameStar1(const StarMatch &one, const StarMatch &two);
89  friend bool compareStar2(const StarMatch &one, const StarMatch &two);
90  friend bool sameStar2(const StarMatch &one, const StarMatch &two);
91 };
92 
93 inline bool compareStar1(const StarMatch &one, const StarMatch &two) {
94  return ((one.s1 == two.s1) ? (one.distance < two.distance) : (&(*one.s1) > &(*two.s1)));
95 }
96 
97 inline bool sameStar1(const StarMatch &one, const StarMatch &two) { return (one.s1 == two.s1); }
98 
99 inline bool compareStar2(const StarMatch &one, const StarMatch &two) {
100  return ((one.s2 == two.s2) ? (one.distance < two.distance) : (&(*one.s2) > &(*two.s2)));
101 }
102 
103 inline bool sameStar2(const StarMatch &one, const StarMatch &two) { return (one.s2 == two.s2); }
104 
105 /* =================================== StarMatchList
106  * ============================================================ */
107 
108 std::ostream &operator<<(std::ostream &stream, const StarMatch &match);
109 
110 //#ifdef TO_BE_FIXED
111 typedef ::std::list<StarMatch>::iterator StarMatchIterator;
112 typedef ::std::list<StarMatch>::const_iterator StarMatchCIterator;
113 //#endif
114 
116 
125 std::ostream &operator<<(std::ostream &stream, const StarMatchList &starMatchList);
126 
127 class StarMatchList : public std::list<StarMatch> {
128 private:
129  int _order;
130  double _chi2;
131  double _dist2;
132  std::shared_ptr<Gtransfo> _transfo;
133 
134 public:
135  void refineTransfo(double nSigmas);
136 
139  void applyTransfo(StarMatchList &transformed, const Gtransfo *priorTransfo,
140  const Gtransfo *posteriorTransfo = nullptr) const;
141 
142  /* constructor */
143  StarMatchList() : _order(0), _chi2(0){};
144 
146 
148  std::shared_ptr<const Gtransfo> getTransfo() const { return _transfo; }
149 
151  double getDist2() const { return _dist2; }
152 
154  double getChi2() const { return _chi2; }
155 
157  int getTransfoOrder() const { return _order; }
158 
160  void swap();
161 
163  double computeResidual() const;
164 
168  unsigned removeAmbiguities(const Gtransfo &gtransfo, int which = 3);
169 
171  void setTransfo(const Gtransfo *gtransfo) { _transfo = gtransfo->clone(); }
173  void setTransfo(const Gtransfo &gtransfo) { _transfo = gtransfo.clone(); }
174  void setTransfo(std::shared_ptr<Gtransfo> gtransfo) { _transfo = std::move(gtransfo); }
175 
177  void setTransfoOrder(int order);
178 
181  std::unique_ptr<Gtransfo> inverseTransfo();
182 
184  void setDistance(const Gtransfo &gtransfo);
185 
187  void cutTail(int nKeep);
188 
190  int recoveredNumber(double mindist) const;
191 
193  void dumpTransfo(std::ostream &stream = std::cout) const;
194 
195  ~StarMatchList(){/* should delete the transfo.... or use counted refs*/};
196 
197 private:
198  StarMatchList(const StarMatchList &); // copies nor properly handled
199  void operator=(const StarMatchList &);
200 };
201 
203 double computeDist2(const StarMatchList &S, const Gtransfo &gtransfo);
204 
206 double computeChi2(const StarMatchList &L, const Gtransfo &gtransfo);
207 } // namespace jointcal
208 } // namespace lsst
209 
210 #endif // LSST_JOINTCAL_STAR_MATCH_H
A hanger for star associations.
Definition: StarMatch.h:31
friend class StarMatchList
Definition: StarMatch.h:32
FatPoint point2
2 points
Definition: StarMatch.h:37
double computeChi2(const Gtransfo &gtransfo) const
returns the chi2 (using errors in the FatPoint&#39;s)
Definition: StarMatch.cc:20
void setTransfo(std::shared_ptr< Gtransfo > gtransfo)
Definition: StarMatch.h:174
STL namespace.
double computeDistance(const Gtransfo &gtransfo) const
returns the distance from gtransfo(point1) to point2.
Definition: StarMatch.h:55
double Distance(const Point &other) const
Definition: Point.h:27
A Point with uncertainties.
Definition: FatPoint.h:11
void setDistance(const Gtransfo &gtransfo)
to be used before sorting on distances.
Definition: StarMatch.h:63
double getDist2() const
access to the sum of squared residuals of the last call to refineTransfo.
Definition: StarMatch.h:151
double getChi2() const
access to the chi2 of the last call to refineTransfo.
Definition: StarMatch.h:154
std::shared_ptr< const Gtransfo > getTransfo() const
carries out a fit with outlier rejection
Definition: StarMatch.h:148
Class for a simple mapping implementing a generic Gtransfo.
Definition: Associations.h:24
int getTransfoOrder() const
returns the order of the used transfo
Definition: StarMatch.h:157
::std::list< StarMatch >::const_iterator StarMatchCIterator
Definition: StarMatch.h:112
friend bool sameStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:103
StarMatch(const FatPoint &point1, const FatPoint &point2, std::shared_ptr< const BaseStar > star1, std::shared_ptr< const BaseStar > star2)
constructor.
Definition: StarMatch.h:47
friend bool sameStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:97
::std::list< StarMatch >::iterator StarMatchIterator
Definition: StarMatch.h:111
friend bool compareStar2(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:99
void setTransfo(const Gtransfo *gtransfo)
sets a transfo between the 2 std::lists and deletes the previous or default one. No fit...
Definition: StarMatch.h:171
friend std::ostream & operator<<(std::ostream &stream, const StarMatch &Match)
Definition: StarMatch.cc:32
double computeDist2(const StarMatchList &S, const Gtransfo &gtransfo)
sum of distance squared
Definition: StarMatch.cc:212
a virtual (interface) class for geometric transformations.
Definition: Gtransfo.h:37
std::shared_ptr< const BaseStar > s2
Definition: StarMatch.h:39
std::shared_ptr< const BaseStar > s1
Definition: StarMatch.h:39
Frame applyTransfo(const Frame &inputframe, const Gtransfo &gtransfo, const WhichTransformed which)
Transform a Frame through a Transfo.
Definition: AstroUtils.cc:15
friend bool compareStar1(const StarMatch &one, const StarMatch &two)
Definition: StarMatch.h:93
void setTransfo(const Gtransfo &gtransfo)
Definition: StarMatch.h:173
virtual std::unique_ptr< Gtransfo > clone() const =0
returns a copy (allocated by new) of the transformation.
virtual void apply(const double xIn, const double yIn, double &xOut, double &yOut) const =0
double getDistance() const
returns the value computed by the above one.
Definition: StarMatch.h:65