lsst.jointcal  14.0-14-g932474c+5
Chi2.h
Go to the documentation of this file.
1 // -*- LSST-C++ -*-
2 #ifndef LSST_JOINTCAL_CHI2_H
3 #define LSST_JOINTCAL_CHI2_H
4 
5 #include <string>
6 #include <iostream>
7 #include <sstream>
8 #include <utility>
9 #include <vector>
10 
11 #include "lsst/jointcal/BaseStar.h"
12 
13 namespace lsst {
14 namespace jointcal {
15 
22 public:
23  virtual void addEntry(double inc, unsigned dof, std::shared_ptr<BaseStar> star) = 0;
24 
25  virtual ~Chi2Accumulator(){};
26 };
27 
30 public:
31  double chi2;
32  unsigned ndof;
33 
34  Chi2Statistic() : chi2(0), ndof(0){};
35 
37  s << "chi2/ndof : " << chi2.chi2 << '/' << chi2.ndof << '=' << chi2.chi2 / chi2.ndof;
38  return s;
39  }
40 
41  // Addentry has an ignored third argument in order to make it compatible with Chi2List.
42  void addEntry(double inc, unsigned dof, std::shared_ptr<BaseStar>) override {
43  chi2 += inc;
44  ndof += dof;
45  }
46 
48  chi2 += rhs.chi2;
49  ndof += rhs.ndof;
50  return *this;
51  }
52 };
53 
54 /*
55  * A class to accumulate chi2 contributions together with pointers to the contributors.
56  *
57  * This structure lets one compute the chi2 statistics (average and variance) and directly point back
58  * to the bad guys without relooping.
59  * The Chi2Star routine makes it compatible with AstrometryFit's
60  * accumulateStatImage and accumulateStatImageList.
61  */
62 struct Chi2Star {
63  double chi2;
65 
66  Chi2Star(double chi2, std::shared_ptr<BaseStar> star) : chi2(chi2), star(std::move(star)) {}
67  // for sorting
68  bool operator<(Chi2Star const& rhs) const { return (chi2 < rhs.chi2); }
69 
70  friend std::ostream& operator<<(std::ostream& s, Chi2Star const& chi2Star) {
71  s << "chi2: " << chi2Star.chi2 << " star: " << *(chi2Star.star) << std::endl;
72  return s;
73  }
74 };
75 
77 class Chi2List : public Chi2Accumulator, public std::vector<Chi2Star> {
78 public:
79  void addEntry(double chi2, unsigned ndof, std::shared_ptr<BaseStar> star) override {
80  push_back(Chi2Star(chi2, std::move(star)));
81  }
82 
84  std::pair<double, double> computeAverageAndSigma();
85 
86  friend std::ostream& operator<<(std::ostream& s, Chi2List const& chi2List);
87 };
88 
89 } // namespace jointcal
90 } // namespace lsst
91 #endif // LSST_JOINTCAL_CHI2_H
Chi2Star(double chi2, std::shared_ptr< BaseStar > star)
Definition: Chi2.h:66
Simple structure to accumulate chi2 and ndof.
Definition: Chi2.h:29
friend std::ostream & operator<<(std::ostream &s, Chi2Statistic const &chi2)
Definition: Chi2.h:36
Base class for Chi2Statistic and Chi2List, to allow addEntry inside Fitter for either class...
Definition: Chi2.h:21
Chi2Statistic & operator+=(Chi2Statistic const &rhs)
Definition: Chi2.h:47
void addEntry(double chi2, unsigned ndof, std::shared_ptr< BaseStar > star) override
Definition: Chi2.h:79
T endl(T... args)
STL namespace.
std::ostream & operator<<(std::ostream &stream, const Gtransfo &gtransfo)
allows &#39;stream << Transfo;&#39; (by calling gtransfo.dump(stream)).
Definition: Gtransfo.cc:193
friend std::ostream & operator<<(std::ostream &s, Chi2Star const &chi2Star)
Definition: Chi2.h:70
Structure to accumulate the chi2 contributions per each star (to help find outliers).
Definition: Chi2.h:77
virtual void addEntry(double inc, unsigned dof, std::shared_ptr< BaseStar > star)=0
Class for a simple mapping implementing a generic Gtransfo.
std::shared_ptr< BaseStar > star
Definition: Chi2.h:64
T move(T... args)
void addEntry(double inc, unsigned dof, std::shared_ptr< BaseStar >) override
Definition: Chi2.h:42
STL class.
bool operator<(Chi2Star const &rhs) const
Definition: Chi2.h:68
STL class.