ComplexRVMFit.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2009 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/Polarimetry/Pulsar/ComplexRVMFit.h
10 
11 #ifndef __Pulsar_ComplexRVMFit_h
12 #define __Pulsar_ComplexRVMFit_h
13 
14 #include "MEAL/Axis.h"
15 #include "Estimate.h"
16 
17 #include <complex>
18 
19 // forward declarations
20 namespace MEAL
21 {
22  class ComplexRVM;
23  class OrthoRVM;
24  class RotatingVectorModel;
25 }
26 
27 typedef std::pair<double,double> range;
28 
29 namespace Pulsar
30 {
31  class PolnProfile;
32 
35  {
36 
37  public:
38 
40  static bool verbose;
41 
43  ComplexRVMFit ();
44 
46  double get_gate_duty_cycle() const { return gate; }
47 
49  virtual void set_gate_duty_cycle (double turns) { gate = turns; }
50 
52 
53  void add_opm (const range& radians);
54 
56  bool is_opm (double phase_in_radians) const;
57 
59 
60  void add_include (const range& radians);
61 
63  bool is_included (double phase_in_radians) const;
64 
66 
67  void add_exclude (const range& radians);
68 
70  bool is_excluded (double phase_in_radians) const;
71 
73  void set_observation (const PolnProfile*);
75  const PolnProfile* get_observation () const;
76 
78  void set_threshold (float sigma);
80  float get_threshold () const;
81 
83  void set_guess_smooth (unsigned phase_bins);
85  unsigned get_guess_smooth () const;
86 
89 
91  void solve ();
92 
93  void set_chisq_map (bool flag) { chisq_map = flag; }
94 
95  void set_range_alpha (const range& r) { range_alpha = r; }
96  void set_range_zeta (const range& r) { range_zeta = r; }
97  void set_range_beta (const range& r) { range_beta = r; }
98 
99  void search_2D (unsigned nalpha, unsigned nzeta);
100  void search_1D (unsigned nzeta);
101 
103  double evaluate (double phi_radians);
104 
105  float get_chisq () const { return chisq; }
106  unsigned get_nfree () const { return nfree; }
107 
108  // get the post-fit residuals of Stokes Q and U
109  void get_residuals (std::vector<double>& phases,
110  std::vector< std::complex< Estimate<double> > >& res);
111 
112  // get the post-fit residuals of position angle
113  void get_psi_residuals (std::vector<double>& phases,
114  std::vector< Estimate<double> >& res);
115 
116  protected:
117 
118  // fraction of pulse period stored in pulse profile
119  double gate;
120 
121  void check_parameters ();
122 
123  void init (MEAL::RotatingVectorModel*);
124  void init (MEAL::OrthoRVM*);
125 
126  void check_parameters (MEAL::RotatingVectorModel*);
127 
130 
131  float threshold;
132 
133  // ranges of pulse longitude to include in model
134  std::vector<range> range_include;
135  // ranges of pulse longitude to exclude from model
136  std::vector<range> range_exclude;
137 
138  MEAL::Axis<unsigned> state;
139  std::vector< MEAL::Axis<unsigned>::Value > data_x;
140  std::vector< std::complex< Estimate<double> > > data_y;
141 
142  // orthogonally polarized mode phase ranges
143  std::vector<range> opm;
144 
145  range range_alpha;
146  range range_beta;
147  range range_zeta;
148 
149  // length of the first guess ellipse along the sin(alpha) axis
150  float guess_alpha;
151  // length of the first guess ellipse along the sin(beta) axis
152  float guess_beta;
153 
154  // number of phase bins in smoothing window used to stabilize first guess
155  unsigned guess_smooth;
156 
157  private:
158 
159  // used by set_observation method to find the maximum in delpsi/delphi
160  void find_delpsi_delphi_max ();
161 
162  // set L of each bin to least-squares best fit
163  void renormalize();
164 
165  std::vector< std::complex< Estimate<double> > > linear;
166  double delpsi_delphi;
167 
168  float peak_phase;
169  float peak_pa;
170 
171  float chisq;
172  unsigned nfree;
173  bool chisq_map;
174 
175  double max_L;
176 
177  bool auto_detect_opm;
178  };
179 }
180 
181 #endif
182 
std::complex< double > evaluate(std::vector< std::complex< double > > *grad=0) const
void use_impact(bool flag=true)
void add_opm(const range &radians)
Add a range of pulse phase containing an orthogonally polarized mode.
Definition: ComplexRVMFit.C:375
unsigned get_nstate() const
Signal::State get_state() const
Get the State of the poln profile.
Definition: PolnProfile.h:94
void set_observation(const PolnProfile *)
Set the data to which model will be fit.
Definition: ComplexRVMFit.C:143
void set_guess_smooth(unsigned phase_bins)
Set the smoothing window used to stabilize first guess.
Definition: ComplexRVMFit.C:62
void solve()
Fit data to the model.
Definition: ComplexRVMFit.C:467
const ScalarMath tan(const ScalarMath &x)
void add_exclude(const range &radians)
Add a range of pulse phase to be excluded from constraints.
Definition: ComplexRVMFit.C:395
void set_line_of_sight(double radians)
Reference::To< ScalarParameter > magnetic_meridian
const ScalarMath atan(const ScalarMath &x)
bool is_opm(double phase_in_radians) const
Return true if pulse phase falls within an OPM range.
Definition: ComplexRVMFit.C:380
Stores a weight for each Profile phase bin.
Definition: PhaseWeight.h:29
void set_state(unsigned i)
const ScalarMath sin(const ScalarMath &x)
Reference::To< ScalarParameter > reference_position_angle
unsigned get_guess_smooth() const
Get the smoothing window used to stabilize first guess.
Definition: ComplexRVMFit.C:67
Reference::To< ScalarParameter > magnetic_axis
double get_gate_duty_cycle() const
Get the fraction of the pulse period modelled (in turns)
Definition: ComplexRVMFit.h:46
Reference::To< ScalarParameter > kappa
void set_threshold(float sigma)
Set the threshold below which data are ignored.
Definition: ComplexRVMFit.C:52
ComplexRVMFit()
Default constructor.
Definition: ComplexRVMFit.C:35
const PolnProfile * get_observation() const
Get the data to which model will be fit.
Definition: ComplexRVMFit.C:406
Reference::To< ScalarParameter > line_of_sight
static bool verbose
static bool verbose
Verbosity flag.
Definition: ComplexRVMFit.h:40
void set_linear(unsigned i, const Estimate< double > &L)
Reference::To< ScalarParameter > impact
MEAL::ComplexRVM * get_model()
Get the model to be fit to the data.
Definition: ComplexRVMFit.C:416
Polarimetric pulse profile transformations and derivations.
Definition: PolnProfile.h:34
T get_value() const
void set_gains_infit(bool flag=true)
double evaluate(double phi_radians)
Evaluate the model at the specified pulse longitude (in radians)
Definition: ComplexRVMFit.C:698
Fit rotating vector model to Stokes Q and U profiles.
Definition: ComplexRVMFit.h:34
virtual void set_gate_duty_cycle(double turns)
Set the fraction of the pulse period modelled (in turns)
Definition: ComplexRVMFit.h:49
void add_include(const range &radians)
Add a range of pulse phase to be included as constraints.
Definition: ComplexRVMFit.C:385
bool is_excluded(double phase_in_radians) const
Return true if pulse phase falls within an excluded range.
Definition: ComplexRVMFit.C:400
Estimate< double > get_linear(unsigned i) const
float get_threshold() const
Get the threshold below which data are ignored.
Definition: ComplexRVMFit.C:57
const std::string get_message() const
Defines the PSRCHIVE library.
Definition: CalSource.h:17
const ScalarMath atan2(const ScalarMath &y, const ScalarMath &x)
bool is_included(double phase_in_radians) const
Return true if pulse phase falls within an included range.
Definition: ComplexRVMFit.C:390
double get_phase(unsigned i) const
Reference::To< ScalarParameter > lambda

Generated using doxygen 1.8.17