gastro  0.1.0
 All Classes Files Functions Variables Pages
photomfit2.h
1 // -*- C++ -*-
2 #ifndef PHOTOMFIT2_H
3 #define PHOTOMFIT2_H
4 
5 #include <map>
6 #include <assert.h>
7 #include <iostream>
8 #include <countedref.h>
9 
10 #include "refzp.h"
11 #include "ccdimage.h"
12 #include "measuredstar.h"
13 #include "fittedstar.h"
14 
15 
16 
29 class Associations;
30 
31 
32 class PhotomModel : public RefCount
33 {
34 public:
35  virtual ~PhotomModel() {}
36 
37  virtual bool isRef(CcdImage const&) const=0;
38  virtual unsigned int NScaleFactors() const=0;
39  virtual unsigned int PhotFactIndex(CcdImage const&) const=0;
40  virtual double GetPhotFact(CcdImage const&) const=0;
41  virtual std::vector<double> GetPhotFactors() const = 0;
42  virtual std::vector<double> GetPhotFactErrors() const = 0;
43 
44  virtual double GetPhotFact(unsigned int index) const=0;
45  virtual void SetPhotFact(unsigned int index, double fact, double efact)=0;
46  virtual unsigned int CcdNum(unsigned int index) const=0;
47 };
48 
49 
50 // class OneGlocalScalePerShoot
51 // class OneGlocalScalePerCcdAndShoot
52 
53 class OneGlobalScalePerCCD : public PhotomModel
54 {
55 public:
56  OneGlobalScalePerCCD(std::map<unsigned int,double>& refscales);
57  virtual ~OneGlobalScalePerCCD() {}
58 
59  virtual bool isRef(CcdImage const&) const;
60  virtual unsigned int NScaleFactors() const;
61  virtual unsigned int PhotFactIndex(CcdImage const&) const;
62  virtual double GetPhotFact(CcdImage const&) const;
63  virtual std::vector<double> GetPhotFactors() const;
64  virtual std::vector<double> GetPhotFactErrors() const;
65 
66  virtual double GetPhotFact(unsigned int index) const;
67  virtual void SetPhotFact(unsigned int index, double fact, double efact);
68  virtual unsigned int CcdNum(unsigned int index) const;
69 
70 private:
71  void init();
72  unsigned int nscfact_;
73  std::vector<unsigned int> refccds_;
74  std::map<unsigned int,double> refscales_;
75  std::vector<double> scalefactors_; // size = 36
76  std::vector<double> scalefacterrors_; // size = 36
77  std::map<unsigned int, unsigned int> ccd_; // ccd[index]
78  std::map<unsigned int, unsigned int> indexes_; // index[ccd]
79 };
80 
81 
82 
83 class PhotomFit2
84 {
85 public:
86 
88  PhotomFit2(Associations& A, PhotomModel& model);
89 
91  bool Minimize(const int MaxIter);
92 
94  void RemoveOutliers(const double NSigCut);
95 
97  CcdImageList const& GetCcdImageList() const { return ccdImageList_; }
98 
100  FittedStarList const& GetFittedStarList() const;
101 
103  double ComputeChi2();
104 
106  PhotomModel& Model() { return model_; }
107  PhotomModel const& Model() const { return model_; }
108 
110  // Get RID OF THIS. USELESS. -- or debug it
111  int NValidFittedStars() const { return nfstars_; }
112 
114  void DumpFluxScales(const std::string& pattern) const;
115 
117  void SaveResults(const std::string& pattern) const;
118 
119 private:
120  void init();
121 
123  void update_star_fluxes();
124 
126  void update_scale_factors();
127 
129  int used_fittedstars();
130 
132  template<class Op>
133  void loop_on_measurements(CcdImageList&, Op& /* , bool skip_uninitialized_stars=false */);
134 
135 
136  Associations& assoc_;
137  PhotomModel& model_;
138  FittedStarList& fittedStarList_;
139 
140  CcdImageList refCcds_;
141  CcdImageList otherCcds_;
142  CcdImageList ccdImageList_;
143 
144  unsigned int nfstars_;
145  unsigned int nfmeasurements_;
146  unsigned int nrefmeasurements_;
147  unsigned int nfluxscales_;
148 
149  double refChi2_;
150  double measuredChi2_;
151 };
152 
153 
154 #endif
155 
156 
157 
158 
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