lsst.jointcal  master-g9041cab851+8
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
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 
36  friend std::ostream& operator<<(std::ostream& s, Chi2Statistic const& chi2) {
37  s << "chi2/ndof : " << chi2.chi2 << '/' << chi2.ndof << '=' << chi2.chi2 / chi2.ndof;
38  return s;
39  }
40 
42  std::string __str__() {
43  std::stringstream s;
44  s << "Chi2/ndof : " << chi2 << '/' << ndof << '=' << chi2 / ndof;
45  return s.str();
46  }
47 
48  // Addentry has an ignored third argument in order to make it compatible with Chi2List.
49  void addEntry(double inc, unsigned dof, std::shared_ptr<BaseStar>) override {
50  chi2 += inc;
51  ndof += dof;
52  }
53 
55  chi2 += rhs.chi2;
56  ndof += rhs.ndof;
57  return *this;
58  }
59 };
60 
61 /*
62  * A class to accumulate chi2 contributions together with pointers to the contributors.
63  *
64  * This structure lets one compute the chi2 statistics (average and variance) and directly point back
65  * to the bad guys without relooping.
66  * The Chi2Star routine makes it compatible with AstrometryFit's
67  * accumulateStatImage and accumulateStatImageList.
68  */
69 struct Chi2Star {
70  double chi2;
71  std::shared_ptr<BaseStar> star;
72 
73  Chi2Star(double chi2, std::shared_ptr<BaseStar> star) : chi2(chi2), star(std::move(star)) {}
74  // for sorting
75  bool operator<(Chi2Star const& rhs) const { return (chi2 < rhs.chi2); }
76 
77  friend std::ostream& operator<<(std::ostream& s, Chi2Star const& chi2Star) {
78  s << "chi2: " << chi2Star.chi2 << " star: " << *(chi2Star.star) << std::endl;
79  return s;
80  }
81 };
82 
84 class Chi2List : public Chi2Accumulator, public std::vector<Chi2Star> {
85 public:
86  void addEntry(double chi2, unsigned ndof, std::shared_ptr<BaseStar> star) override {
87  this->push_back(Chi2Star(chi2, std::move(star)));
88  }
89 
91  std::pair<double, double> computeAverageAndSigma();
92 
93  friend std::ostream& operator<<(std::ostream& s, Chi2List const& chi2List);
94 };
95 
96 } // namespace jointcal
97 } // namespace lsst
98 #endif // LSST_JOINTCAL_CHI2_H
Chi2Star(double chi2, std::shared_ptr< BaseStar > star)
Definition: Chi2.h:73
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:54
void addEntry(double chi2, unsigned ndof, std::shared_ptr< BaseStar > star) override
Definition: Chi2.h:86
friend std::ostream & operator<<(std::ostream &s, Chi2List const &chi2List)
Definition: Chi2.cc:45
std::string __str__()
this routine is the one called by the python print.
Definition: Chi2.h:42
friend std::ostream & operator<<(std::ostream &s, Chi2Star const &chi2Star)
Definition: Chi2.h:77
bool operator<(Chi2Star const &rhs) const
Definition: Chi2.h:75
Structure to accumulate the chi2 contributions per each star (to help find outliers).
Definition: Chi2.h:84
virtual void addEntry(double inc, unsigned dof, std::shared_ptr< BaseStar > star)=0
std::shared_ptr< BaseStar > star
Definition: Chi2.h:71
void addEntry(double inc, unsigned dof, std::shared_ptr< BaseStar >) override
Definition: Chi2.h:49
std::pair< double, double > computeAverageAndSigma()
Compute the average and std-deviation of these chisq values.
Definition: Chi2.cc:33