ScalarTemplateMatching.h
1 //-*-C++-*-
2 /***************************************************************************
3  *
4  * Copyright (C) 2003 - 2023 by Willem van Straten
5  * Licensed under the Academic Free License version 2.1
6  *
7  ***************************************************************************/
8 
9 // psrchive/More/Polarimetry/Pulsar/ScalarTemplateMatching.h
10 
11 #ifndef __Pulsar_ScalarTemplateMatching_h
12 #define __Pulsar_ScalarTemplateMatching_h
13 
14 #include "Pulsar/PhaseWeight.h"
15 #include "FTransformAgent.h"
16 #include "toa.h"
17 
18 namespace Pulsar
19 {
20  class Profile;
21  class FluctuationSpectrumStats;
22 
24 
39  class ScalarTemplateMatching : public Reference::Able
40  {
43 
46 
48  ScalarTemplateMatching* clone () const;
49 
50  public:
51 
53  static bool verbose;
54 
57 
60 
62  void set_standard (const Profile* standard);
63 
65  const Profile* get_standard () const;
66 
68  void add_observation ( const Profile* );
69 
71  void set_observation ( const Profile* );
72 
74  void delete_observations ();
75 
77  void fit (const Profile* observation);
78 
80  void solve ();
81 
83  Estimate<double> get_phase () const;
84 
86  Estimate<double> get_scale () const;
87 
89  void set_maximum_harmonic (unsigned max);
90 
92  unsigned get_maximum_harmonic () const { return maximum_harmonic; }
93 
95  void set_choose_maximum_harmonic (bool flag);
96 
99 
101  unsigned get_nharmonic () const { return n_harmonic; }
102 
104  void set_regions (const PhaseWeight& pulse, const PhaseWeight& baseline);
105 
107  void set_plan (FTransform::Plan*);
108 
110  void set_compute_reduced_chisq (bool flag) { compute_reduced_chisq = flag; }
111 
113  double get_reduced_chisq () const;
114 
115  protected:
116 
119 
121  unsigned maximum_harmonic;
122 
125 
127  unsigned n_harmonic;
128 
130 
132 
134  class Data;
135 
137  std::vector<Data> data;
138 
140  void init ();
141 
143  void model_profile ();
144 
145  Estimate<double> best_shift;
146  Estimate<double> best_scale;
147 
148  double chisq;
149  unsigned nfree;
150 
151  private:
152 
154  bool regions_set;
155 
156  };
157 
158  class ScalarTemplateMatching::Data
159  {
160  public:
161  void set_stats (FluctuationSpectrumStats*);
162  FluctuationSpectrumStats* get_stats ();
163 
164  void set_standard (const Profile*);
165  const Profile* get_standard () const;
166  const Profile* get_standard_fourier () const;
167 
168  void set_observation (const Profile*);
169  const Profile* get_observation () const;
170  const Profile* get_observation_fourier () const;
171 
173  double get_residual_variance (double scale) const;
174 
175  protected:
176 
179 
180  class ProfileData
181  {
182  public:
184  ProfileData() { variance = 0.0; }
185 
188 
191 
193  double variance;
194 
195  }; // class ProfileData
196 
197  ProfileData standard;
198  ProfileData observation;
199 
200  }; // class ScalarTemplateMatching::Data
201 
202 } // namespace Pulsar
203 
204 #endif
205 
unsigned n_harmonic
The number of harmonics in the fit.
Definition: ScalarTemplateMatching.h:132
bool compute_reduced_chisq
Compute the reduced chisq (using the expected variance of the residual profile)
Definition: ScalarTemplateMatching.h:136
void init()
Construtor helper.
Definition: ScalarTemplateMatching.C:60
Reference::To< FluctuationSpectrumStats > stats
Used to compute the variance of the off-pulse harmonics.
Definition: ScalarTemplateMatching.h:123
~ScalarTemplateMatching()
Destructor.
Definition: ScalarTemplateMatching.C:51
std::vector< Data > data
Standards and observations.
Definition: ScalarTemplateMatching.h:139
void set_standard(const Profile *standard)
Set the standard to which observations will be fit.
Definition: ScalarTemplateMatching.C:102
ScalarTemplateMatching()
Default constructor.
Definition: ScalarTemplateMatching.C:26
Stores a weight for each Profile phase bin.
Definition: PhaseWeight.h:29
Any quantity recorded as a function of pulse phase.
Definition: Profile.h:45
unsigned get_maximum_harmonic() const
Get the maximum number of harmonics to include in fit.
Definition: ScalarTemplateMatching.h:97
void delete_observations()
Delete any previously added observations.
Definition: ScalarTemplateMatching.C:158
unsigned get_nbin() const
Return the number of bins.
Definition: ProfileAmps.h:50
bool get_choose_maximum_harmonic() const
Get the maximum number of harmonics to include in fit.
Definition: ScalarTemplateMatching.h:103
Reference::To< const ProfileType > profile
The Profile from which statistics will be derived.
Definition: FluctSpectStats.h:70
bool choose_maximum_harmonic
Set true when set_standard should choose the maximum harmonic.
Definition: ScalarTemplateMatching.h:129
The original scalar template matching algorithm.
Definition: ScalarTemplateMatching.h:44
void set_regions(const PhaseWeight &pulse, const PhaseWeight &baseline)
Set the on-pulse and baseline regions.
Definition: ScalarTemplateMatching.C:95
Estimate< double > get_scale() const
Get the scale factor between the standard and the observation.
double get_reduced_chisq() const
Get the statistical goodness of fit.
Definition: ScalarTemplateMatching.C:204
void add_observation(const Profile *)
Add the specified profile to be fit to the standard/template.
void set_choose_maximum_harmonic(bool flag)
Set the maximum number of harmonics to include in fit.
Definition: ScalarTemplateMatching.C:81
void set_observation(const Profile *)
Set the only profile to be fit to the standard/template.
Definition: ScalarTemplateMatching.C:163
void set_plan(FTransform::Plan *p)
Set the fourier transform plan.
Definition: FluctSpectStats.h:65
void set_maximum_harmonic(unsigned max)
Set the maximum number of harmonics to include in fit.
Definition: ScalarTemplateMatching.C:76
void fit(const Profile *observation)
Fit the specified observation to the standard.
Definition: ScalarTemplateMatching.C:148
static bool verbose
Verbosity flag.
Definition: ScalarTemplateMatching.h:58
Computes statistics of the fluctuation spectrum (Fourier transform of pulse profile)
Definition: FluctuationSpectrumStats.h:26
void set_plan(FTransform::Plan *)
Set the fourier transform plan.
Definition: ScalarTemplateMatching.C:71
const Profile * get_standard() const
Get the standard to which observations will be fit.
Definition: ScalarTemplateMatching.C:87
void solve()
Fit all observations to the standard.
Definition: ScalarTemplateMatching.C:184
unsigned get_nharmonic() const
Get the number of harmonics to be included in fit.
Definition: ScalarTemplateMatching.h:106
Defines the PSRCHIVE library.
Definition: CalSource.h:17
void set_compute_reduced_chisq(bool flag)
When true, compute the reduced chisq; when false, assume it is unity.
Definition: ScalarTemplateMatching.h:115
Estimate< double > get_phase() const
Get the phase offset between the standard and the observation in radians.
Definition: ScalarTemplateMatching.C:210
void model_profile()
Implement the solve method using the original model_profile algorithm.
Definition: model_profile.C:106
unsigned maximum_harmonic
The maximum number of harmonics to include in the fit.
Definition: ScalarTemplateMatching.h:126

Generated using doxygen 1.8.17