sample.h
1//-*-C++-*-
2/***************************************************************************
3 *
4 * Copyright (C) 2016 by Willem van Straten
5 * Licensed under the Academic Free License version 2.1
6 *
7 ***************************************************************************/
8
9// epsic/src/sample.h
10
11#ifndef __epsic_sample_h
12#define __epsic_sample_h
13
14#include "mode.h"
15
16#include <cstdlib>
17#include <vector>
18
19namespace epsic
20{
21
22 /***************************************************************************
23 *
24 * a Stokes sample
25 *
26 ***************************************************************************/
27
28 class sample
29 {
30 public:
31
32 unsigned sample_size;
33
34 sample() { sample_size = 1; }
35
36 virtual ~sample () {}
37
38 virtual Stokes<double> get_Stokes () = 0;
39 virtual Vector<4, double> get_mean () = 0;
40 virtual Matrix<4,4, double> get_covariance () = 0;
41 virtual Matrix<4,4, double> get_crosscovariance (unsigned ilag) = 0;
42
43 Matrix<4,4, double> get_covariance (mode* s, unsigned sample_size);
44
45 Matrix<4,4, double> get_crosscovariance (mode* s, unsigned at_lag,
46 unsigned sample_size);
47 };
48
49 /***************************************************************************
50 *
51 * a single source of electromagnetic radiation
52 *
53 ***************************************************************************/
54
55 class single : public sample
56 {
57 public:
58 mode* source;
59
60 single (mode* s) { source = s; }
61
62 ~single () { delete source; }
63
64 virtual Stokes<double> get_Stokes_instance ()
65 {
66 Spinor<double> e = source->get_field();
67 Vector<4, double> tmp;
68 compute_stokes (tmp, e);
69 return tmp;
70 }
71
72 Stokes<double> get_Stokes ()
73 {
74 Stokes<double> result;
75 for (unsigned i=0; i<sample_size; i++)
76 result += get_Stokes_instance();
77 result /= sample_size;
78 return result;
79 }
80
81 Vector<4, double> get_mean ()
82 {
83 return source->get_mean();
84 }
85
86 Matrix<4,4, double> get_covariance ()
87 {
88 return sample::get_covariance (source, sample_size);
89 }
90
91 Matrix<4,4, double> get_crosscovariance (unsigned ilag)
92 {
93 return sample::get_crosscovariance (source, ilag, sample_size);
94 }
95
96 };
97
98
99 /***************************************************************************
100 *
101 * a combination of two sources of electromagnetic radiation
102 *
103 ***************************************************************************/
104
105 class combination : public sample
106 {
107 protected:
108 double intensity_covariance;
109
110 public:
111 mode* A;
112 mode* B;
113
114 combination () { A = new mode; B = new mode; intensity_covariance = 0; }
115
116 virtual void set_normal (BoxMuller* n)
117 { A->set_normal(n); B->set_normal(n); }
118
120 void set_intensity_covariance (double covar) { intensity_covariance = covar; }
121
122 Matrix<4,4, double> get_crosscovariance (unsigned ilag)
123 {
124 if (ilag == 0)
125 return get_covariance();
126
127 return sample::get_crosscovariance (A, ilag, sample_size)
128 + sample::get_crosscovariance (B, ilag, sample_size);
129 }
130 };
131
132 /***************************************************************************
133 *
134 * a superposition of two sources of electromagnetic radiation
135 *
136 ***************************************************************************/
137
138 class superposed : public combination
139 {
140 Stokes<double> get_Stokes ();
141 Vector<4, double> get_mean ();
142 Matrix<4,4, double> get_covariance ();
143 };
144
145 /***************************************************************************
146 *
147 * a composition of two sources of electromagnetic radiation
148 *
149 ***************************************************************************/
150
151 class composite : public combination
152 {
153 double A_fraction;
154
155 public:
156
157 composite (double fraction) { A_fraction = fraction; }
158
159 Stokes<double> get_Stokes ();
160 Vector<4, double> get_mean ();
161 Matrix<4,4, double> get_covariance ();
162 };
163
164 /***************************************************************************
165 *
166 * a disjoint combination of two sources of electromagnetic radiation
167 *
168 ***************************************************************************/
169
170 class disjoint : public combination
171 {
172 double A_fraction;
173
174 public:
175
176 disjoint (double fraction) { A_fraction = fraction; }
177
178 Stokes<double> get_Stokes ();
179 Vector<4, double> get_mean ();
180 Matrix<4,4, double> get_covariance ();
181 Matrix<4,4, double> get_crosscovariance (unsigned ilag);
182 };
183
184
185 /***************************************************************************
186 *
187 * a post-detection boxcar-smoothed source of electromagnetic radiation
188 *
189 ***************************************************************************/
190
191 class boxcar_sample : public single
192 {
193 std::vector< Stokes<double> > instances;
194 unsigned smooth;
195 unsigned current;
196
197 void setup()
198 {
199 current = 0;
200 instances.resize (smooth);
201 for (unsigned i=1; i<smooth; i++)
202 instances[i] = single::get_Stokes_instance();
203 }
204
205 public:
206
207 boxcar_sample (mode* s, unsigned n) : single(s) { smooth = n; }
208
209 Stokes<double> get_Stokes_instance ()
210 {
211 if (instances.size() < smooth)
212 setup ();
213
214 instances[current] = single::get_Stokes_instance();
215 current = (current + 1) % smooth;
216
217 Stokes<double> result;
218 for (unsigned i=0; i<smooth; i++)
219 result += instances[i];
220
221 result /= smooth;
222 return result;
223 }
224 };
225
226
227 class coherent : public combination
228 {
229 Spinor<double> a;
230 Spinor<double> b;
231
232 field_transformer* a_xform;
233 field_transformer* b_xform;
234
235 mode* coupling;
236 double coherence;
237
238 bool built;
239 void build();
240
241
242 public:
243
244 coherent (double coherence);
245 void set_normal (BoxMuller*);
246
247 Stokes<double> get_Stokes ();
248 Vector<4, double> get_mean ();
249 Matrix<4,4, double> get_covariance ();
250
251 };
252
253} // namespace epsic
254
255#endif // ! defined __epsic_sample_h

Generated using doxygen 1.14.0