BackendEstimate.h
1//-*-C++-*-
2
3/***************************************************************************
4 *
5 * Copyright (C) 2012 by Willem van Straten
6 * Licensed under the Academic Free License version 2.1
7 *
8 ***************************************************************************/
9
10// psrchive/More/Polarimetry/Pulsar/BackendEstimate.h
11
12#ifndef __Pulsar_BackendEstimate_H
13#define __Pulsar_BackendEstimate_H
14
15#include "MEAL/Complex2.h"
16#include "MEAL/Mean.h"
17
18#include "MJD.h"
19
20using namespace std;
21
22class setMJD
23{
24 bool set;
25 MJD mjd;
26
27public:
28 setMJD () { set = false; }
29
30 operator const MJD& () const { return mjd; }
31
32 const setMJD& operator = (const MJD& _mjd)
33 { mjd = _mjd; set = true; return *this; }
34
35 friend bool operator < (const setMJD& setmjd, const MJD& mjd)
36 { return !setmjd.set || setmjd.mjd < mjd; }
37
38 friend bool operator > (const setMJD& setmjd, const MJD& mjd)
39 { return !setmjd.set || setmjd.mjd > mjd; }
40
41 friend bool operator < (const MJD& mjd, const setMJD& setmjd)
42 { return !setmjd.set || mjd < setmjd.mjd; }
43
44 friend bool operator > (const MJD& mjd, const setMJD& setmjd)
45 { return !setmjd.set || mjd > setmjd.mjd; }
46
47 friend ostream& operator << (ostream& os, const setMJD& setmjd)
48 { if (!setmjd.set) os << "unset"; else os << setmjd.mjd; return os; }
49};
50
51namespace Calibration
52{
54 class BackendEstimate : public Reference::Able
55 {
56
57 protected:
58
61
64
66 setMJD start_time;
67
69 setMJD end_time;
70
73
76
77 float weight;
78
79 public:
80
81 BackendEstimate () { weight = 0.0; }
82
84 unsigned path_index;
85
87 virtual void set_response (MEAL::Complex2* xform);
88
90 void integrate (const MEAL::Complex2* xform);
91
93 virtual void update ();
94
96 unsigned get_path_index() const { return path_index; }
97
98 void set_start_time (const MJD& epoch) { start_time = epoch; }
99 const MJD& get_start_time () const { return start_time; }
100
101 void set_end_time (const MJD& epoch) { end_time = epoch; }
102 const MJD& get_end_time () const { return end_time; }
103
105 bool spans (const MJD& epoch);
106
108 void add_observation_epoch (const MJD& epoch);
109
110 void add_weight (float amount) { weight += amount; }
111 float get_weight () const { return weight; }
112 };
113
114}
115
116#include "MEAL/ChainRule.h"
117#include "MEAL/ProductRule.h"
118
119namespace MEAL
120{
121 template<class Type, class Base>
122 Type* extract (Base* base)
123 {
124 Type* type = dynamic_cast<Type*>( base );
125 if (type)
126 return type;
127
128 MEAL::ChainRule<Base>* chain;
129 chain = dynamic_cast<MEAL::ChainRule<Base>*>( base );
130 if (chain)
131 return extract<Type> ( chain->get_model() );
132
133 MEAL::ProductRule<Base>* product;
134 product = dynamic_cast<MEAL::ProductRule<Base>*>( base );
135 if (product)
136 {
137 for (unsigned imodel=0; imodel<product->get_nmodel(); imodel++)
138 {
139 Type* type = extract<Type> ( product->get_model(imodel) );
140 if (type)
141 return type;
142 }
143 }
144
145 return 0;
146 }
147
148 template<class Base>
149 void print (std::ostream& os, Base* base, const std::string& indent = "")
150 {
151 os << indent << (void*) base << " " << base->get_name() << endl;
152
153 MEAL::ChainRule<Base>* chain;
154 chain = dynamic_cast<MEAL::ChainRule<Base>*>( base );
155 if (chain)
156 {
157 Base* model = chain->get_model();
158 print (os, model, indent + " model ");
159
160 for (unsigned i=0; i < model->get_nparam(); i++)
161 if (chain->has_constraint (i))
162 print (os, chain->get_constraint(i),
163 indent + " by[" + tostring(i) + "] ");
164
165 return;
166 }
167
168 MEAL::ProductRule<Base>* product;
169 product = dynamic_cast<MEAL::ProductRule<Base>*>( base );
170 if (product)
171 {
172 for (unsigned imodel=0; imodel<product->get_nmodel(); imodel++)
173 print (os, product->get_model(imodel), indent + " ");
174
175 return;
176 }
177
178 for (unsigned i=0; i<base->get_nparam(); i++)
179 os << indent << " " << i << " " << base->get_param (i)
180 << " " << base->get_infit(i) << endl;
181
182 }
183}
184
185#endif
186
setMJD start_time
The start of the period spanned by this backend solution.
Definition BackendEstimate.h:66
MJD min_time
The mimimum observation time.
Definition BackendEstimate.h:72
void integrate(const MEAL::Complex2 *xform)
Integrate a calibrator solution.
Definition BackendEstimate.C:72
unsigned path_index
The index of the SignalPath in which this backend is a component.
Definition BackendEstimate.h:84
setMJD end_time
The end of the period spanned by this solution.
Definition BackendEstimate.h:69
Reference::To< MEAL::Mean< MEAL::Complex2 > > mean
The mean of the backend component.
Definition BackendEstimate.h:63
Reference::To< MEAL::Complex2 > backend
The backend component.
Definition BackendEstimate.h:60
virtual void set_response(MEAL::Complex2 *xform)
Set the response that contains the backend.
Definition BackendEstimate.C:20
virtual void update()
Update the transformation with the current estimate, if possible.
Definition BackendEstimate.C:127
unsigned get_path_index() const
Return the path index.
Definition BackendEstimate.h:96
void add_observation_epoch(const MJD &epoch)
update min_time and max_time
Definition BackendEstimate.C:154
MJD max_time
The maximum observation time.
Definition BackendEstimate.h:75
bool spans(const MJD &epoch)
Return true if this estimate spans the epoch.
Definition BackendEstimate.C:143
double get_param(unsigned index) const
STL namespace.

Generated using doxygen 1.14.0