TrigCache.h
1 #ifndef _UCORRELATOR_TRIGCACHE_H
2 #define _UCORRELATOR_TRIGCACHE_H
3 
4 #include "AntennaPositions.h"
5 #include <cmath>
6 
7 #ifndef DEG2RAD
8 #define DEG2RAD (M_PI / 180.)
9 #endif
10 
11 namespace UCorrelator
12 {
13 
18  struct TrigCache
19  {
20  TrigCache(int n_phi, double dphi, double phi_start, int ntheta, double dtheta, double theta_start, const AntennaPositions * aps, bool use_bin_center= false, int nant2use = 0, const int * ants = 0)
21  : nphi(n_phi) ,ap(aps)
22  {
23 
24  phi = new double[nphi];
25  int num_ants = nant2use == 0 ? NUM_SEAVEYS : nant2use;
26  cos_phi = new double[nphi * NUM_SEAVEYS * 2]; //allocate enough space even if unused... the non-wanted ants will be full of junk
27  theta = new double[ntheta];
28  tan_theta = new double[ntheta];
29  cos_theta = new double[ntheta];
30 
31  for (int i = 0; i < nphi; i++)
32  {
33  double current_phi = phi_start + dphi * i;
34  if (use_bin_center) current_phi += 0.5 * dphi;
35 
36  phi[i] = current_phi;
37  for (int j = 0; j < num_ants; j++)
38  {
39  int ant = nant2use ? ants[j] : j;
40  cos_phi[2 * (i + ant * nphi)] = cos( DEG2RAD * ( current_phi - ap->phiAnt[0][ant] ));
41  cos_phi[2 * (i + ant * nphi) + 1] = cos( DEG2RAD * ( current_phi - ap->phiAnt[1][ant] ));
42  }
43  }
44 
45  for (int i = 0; i < ntheta; i++)
46  {
47  double current_theta = theta_start + dtheta * i;
48  if (use_bin_center) current_theta += 0.5 * dphi;
49  theta[i] = -current_theta; //lol
50  cos_theta[i] = cos(theta[i] * DEG2RAD); //naturally, we reverse the sign...
51  tan_theta[i] = tan(theta[i] * DEG2RAD); //naturally, we reverse the sign...
52  }
53 
54 
55  };
56 
57 
58  ~TrigCache()
59  {
60 
61  delete [] phi;
62  delete [] cos_phi;
63  delete [] theta;
64  delete [] cos_theta;
65  delete [] tan_theta;
66 
67  }
68 
69 
70  int nphi;
71 
72  double * phi; //degrees!
73  double * cos_phi;
74  //lookup since depends on antenna / polarization
75  // but caerful, if you restricted antennas and ask for one you didn't want, you get junk!
76  double cosPhi(int phibin, int ant, int pol) { return cos_phi[ 2 * (phibin + ant * nphi) + pol]; }
77  double * theta; //degrees!
78  double * cos_theta;
79  double * tan_theta;
80 
81  const AntennaPositions * ap;
82 
83  };
84 
85 
86 
87 }
88 
89 
90 #endif
double phiAnt[2][NUM_SEAVEYS]