gastro  0.1.0
All Classes Files Functions Variables Pages
smoothmodelfitter.h
1 // -*- C++ -*-
2 //
3 //
4 #ifndef SMOOTHMODELFITTER_H
5 #define SMOOTHMODELFITTER_H
6 
7 
8 #include <time.h>
9 #include <math.h>
10 
11 #include "ccdimage.h"
12 #include "measuredstar.h"
13 
14 class Associations;
15 class Vect;
16 
17 
18 // 2d polynomial
19 class Poly2
20 {
21 public:
23  Poly2(const double XMin, const double YMin,
24  const double XMax, const double YMax,
25  const int Deg);
26 
28  void Monomials(const double &X, const double &Y, Vect &M) const;
29 
31  bool Compute(const double X, const double Y, Vect const& coeffs, double& val) const;
32 
34  // void SetCoeffs(const Vect &Coeffs);
35 
36 
38  unsigned NTerms() const { return nterms_;}
39 
41  bool Read(std::istream &S);
42  void Write(std::ostream &S) const;
43 
45  void DecreaseDegree();
46 
47 private:
48  double ax_, bx_;
49  double ay_, by_;
50  int deg_;
51  unsigned nterms_;
52  Vect coeffs_;
53 };
54 
55 
56 class SmoothModelFitter
57 {
58 public:
59  SmoothModelFitter(Associations& assoc, unsigned int deg);
60 
61  ~SmoothModelFitter() { }
62 
64  template<class Op>
65  void LoopOnMeasurements(Op& op) const;
66 
68  bool Minimize(unsigned int maxiter);
69 
71  void RemoveOutliers(double nsig);
72 
74  double GetChi2() const;
75 
77  int GetNMeas() const;
78 
80  int GetNDoF() const;
81 
83  int GetNPar() const { return npar_; }
84 
86  static bool Value(MeasuredStar& m, Vect const& pars, double& value, int deg);
87 
89  void DumpNTuples(std::string const& output_dir) const;
90 
92  void DumpParNTuple(std::string const& ntname) const;
93 
95  void DumpMeasuredStarNTuple(std::string const& ntname) const;
96 
98  void DumpFittedStarNTuple(std::string const& ntname) const;
99 
100 private:
101  unsigned int deg_;
102  Associations& assoc_;
103  CcdImageList& imstd::list_;
104  FittedStarList& fittedstarstd::list_;
105  int npar_;
106 
107  Poly2 corrs_;
108  Vect calibpars_;
109 
110  mutable double chi2_;
111  mutable int nmeas_;
112  mutable int ndof_;
113  mutable bool cleanChi2_;
114 
115  void update_star_fluxes_();
116  void update_calib_pars_();
117 };
118 
119 
120 
121 template<class Op>
122 void SmoothModelFitter::LoopOnMeasurements(Op& op) const
123 {
124  CcdImageIterator imI;
125  MeasuredStarIterator stI;
126 
127  for(imI=imstd::list_.begin();imI!=imstd::list_.end();imI++)
128  {
129  CcdImage& ccdImage = **imI;
130  MeasuredStarList& catalog = ccdImage.CatalogForFit();
131  for(stI=catalog.begin();stI!=catalog.end();stI++)
132  {
133  MeasuredStar& m = **stI;
134  if( !m.IsValid() ) continue;
135  FittedStar* f = m.GetFittedStar();
136  if(!f) continue;
137  op(m);
138  }
139  }
140 
141  op.Finalize();
142 }
143 
144 
145 
146 
147 #endif
148 
149 
A list of FittedStar s. Such a list is typically constructed by Associations.
Definition: fittedstar.h:158
The class that implements the relations between MeasuredStar and FittedStar.
Definition: associations.h:17
handler of an actual image from a single CCD
Definition: ccdimage.h:21
The objects which have been measured several times. The MeasuredStar s measuring the same object in d...
Definition: fittedstar.h:37
bool IsValid() const
Fits may use that to discard outliers.
Definition: measuredstar.h:83
objects measured on actual images. Coordinates and uncertainties are expressed in pixel image frame...
Definition: measuredstar.h:21
A list of MeasuredStar. They are usually filled in Associations::AddImage.
Definition: measuredstar.h:105