icemc
ray.hh
Go to the documentation of this file.
1 #ifndef RAY_H_
2 #define RAY_H_
3 
5 //class Ray:
7 class Vector;
8 class IceModel;
9 class Settings;
10 class Anita;
11 class Position;
12 class Signal;
13 
14 #include <iostream>
15 #include <cmath>
16 
17 
18 using std::cout;
20 class Ray {
21 
22 private:
23 
24 protected:
25 
26 
27 
28 public:
29  Ray();
30  void Initialize();
31 
32  Vector n_exit2bn[5]; // normal vector in direction of exit point to balloon - 5 iterations, 3 directions for each
33  Vector nsurf_rfexit; // normal of the surface at the place where the rf leaves
35  Vector nrf_iceside[5]; // direction of rf [tries][3d]
36 
40 
42  Position rfexit[5]; // position where the rf exits the ice- 5 iterations, 3 dimensions each
43 
44 
45  double sum_slopeyness; // for summing the average slopeyness
46  //double sum_slopeyness=0; // for summing the average slopeyness
48 
50 
51  int GetRayIceSide(const Vector &n_exit2bn,
52  const Vector &nsurf_rfexit,
53  double nexit,
54  double nenter,
55  Vector &nrf2_iceside);
56 
57  int TraceRay(Settings *settings1,Anita *anita1,int whichiteration,double n_depth);
58 
59 
60  int GetSurfaceNormal(Settings *settings1,IceModel *antarctica,Vector posnu,double &slopeyangle,int whichtry);
61 
62  int RandomizeSurface(Settings *settings1,Position rfexit_temp,Vector posnu,IceModel *antarctica,double &slopeyangle,int whichtry);
63 
64 
65  void GetRFExit(Settings *settings1,Anita *anita1,int whichray,Position posnu,Position posnu_down,Position r_bn,Position r_boresights[Anita::NLAYERS_MAX][Anita::NPHI_MAX],int whichtry,IceModel *antarctica);
66 
67  // void WhereDoesItLeave(const Position &posnu,
68  // const Vector &nnu,Position &r_out);
69 
70  // static void WhereDoesItLeave(const Position &posnu,
71  // const Vector &nnu,Position &r_out);
72 
73  static int WhereDoesItLeave(const Position &posnu, const Vector &ntemp,IceModel *antarctica, Position &r_out) {
74  double distance=0;
75  double posnu_length=posnu.Mag(); // distance from center of earth to interaction
76  double lon,lat;//,lon_old,lat_old; //latitude, longitude indices for 1st and 2nd iteration
77  lon = posnu.Lon(); // what latitude, longitude does interaction occur at
78  lat = posnu.Lat();
79  // lon_old=lon; // save this longitude and latitude so we can refer to it later
80  // lat_old=lat;
81 
82  // use law of cosines to get distance from interaction to exit point for the ray
83  // need to solve for that distance using the quadratic formula
84 
85  // angle between posnu and ntemp vector for law of cosines.
86  double costheta=-1*(posnu*ntemp)/posnu_length;
87 
88  // a,b,c for quadratic formula, needed to solve for
89  double a=1;
90  double b=-1*2*posnu_length*costheta;
91  double c=posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2);
92 
93  if (b*b-4*a*c<0.) {
94  return 0;
95  }
96 
97  // use the "+" solution because the other one is where the ray is headed downward toward the rock
98  distance=(-1*b+sqrt(b*b-4*a*c))/2;
99 
100  // now here is the exit point for the ray
101  r_out = posnu + distance*ntemp;
102 
103  lon = r_out.Lon(); // latitude and longitude of exit point
104  lat = r_out.Lat();
105 
106  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
107  // sometimes though the new surface is lower than the one over posnu which causes a problem.
108  if (b*b-4*a*c<0.) {
109  //cout << "inu is " << inu << "\n";
110  // try halving the distance
111  distance=distance/2.;
112  //cout << "bad. distance 1/2 is " << distance << "\n";
113  r_out = posnu + distance*ntemp;
114  lon = r_out.Lon(); // latitude and longitude of exit point
115  lat = r_out.Lat();
116  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
117  if (b*b-4*a*c<0.) { // if we still have the problem back up more
118  distance=distance/2.; // now we are at 1/4 the distance
119  //cout << "bad. distance 1/4 is " << distance << "\n";
120  r_out = posnu + distance*ntemp;
121  lon = r_out.Lon(); // latitude and longitude of exit point
122  lat = r_out.Lat();
123  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
124  if (b*b-4*a*c<0.) { // the problem is less then 1/4 of the way in
125  distance=distance/2.; // now we are at 1/8 the distance
126  //cout << "bad. distance 1/8 is " << distance << "\n";
127  r_out = posnu + distance*ntemp;
128  lon = r_out.Lon(); // latitude and longitude of exit point
129  lat = r_out.Lat();
130  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
131  if (b*b-4*a*c<0.) {
132  // still have the problem so just make the distance 0
133  distance=0.; // now we are at 1/8 the distance
134  //cout << "bad. distance is " << distance << "\n";
135  lon = posnu.Lon(); // latitude and longitude of exit point
136  lat = posnu.Lat();
137  r_out=antarctica->Surface(lon,lat)/posnu.Mag()*posnu;
138  }
139  } // now we are at 1/8 the distance
140  else {// if this surface is ok problem is between 1/4 and 1/2
141  distance=distance*1.5; // now we are at 3/8 the distance
142  // cout << "good. distance 3/8 is " << distance << "\n";
143  r_out = posnu + distance*ntemp;
144  lon = r_out.Lon(); // latitude and longitude of exit point
145  lat = r_out.Lat();
146  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
147  if (b*b-4.*a*c<0.) {
148  distance=distance*2./3.; // go back to 1/4
149  r_out = posnu + distance*ntemp;
150  lon = r_out.Lon(); // latitude and longitude of exit point
151  lat = r_out.Lat();
152  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
153  //cout << "good at distance 1/4 is " << distance << "\n";
154  }
155  } // now we are at 3/8 the distance
156 
157 
158  } // now we are at 1/4 the distance
159  else { // if this surface at 1/2 distance is ok see if we can go a little further
160  distance=distance*1.5; // now we are at 3/4 the distance
161  //cout << "good. distance 3/4 is " << distance << "\n";
162  r_out = posnu + distance*ntemp;
163  lon = r_out.Lon(); // latitude and longitude of exit point
164  lat = r_out.Lat();
165  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
166  if (b*b-4*a*c<0.) { // the problem is between 1/2 and 3/4 of the way in
167  distance=distance*5./6.; // now we are at 5/8 the distance
168  //cout << "bad. distance 5/8 is " << distance << "\n";
169  r_out = posnu + distance*ntemp;
170  lon = r_out.Lon(); // latitude and longitude of exit point
171  lat = r_out.Lat();
172  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
173  if (b*b-4*a*c<0.) {
174  distance=distance*4./5.;
175  r_out = posnu + distance*ntemp;
176  lon = r_out.Lon(); // latitude and longitude of exit point
177  lat = r_out.Lat();
178  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
179  //cout << "good at distance 3/4 is " << distance << "\n";
180  }
181  } // now we are at 1/8 the distance
182  else {// if this surface is ok problem is between 1/4 and 1/2
183  distance=distance*7./6.; // now we are at 7/8 the distance
184  //cout << "good. distance 7/8 is " << distance << "\n";
185  r_out = posnu + distance*ntemp;
186  lon = r_out.Lon(); // latitude and longitude of exit point
187  lat = r_out.Lat();
188  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
189  if (b*b-4*a*c<0) {
190  // now found the problem so go back to 3/4 distance
191  distance=distance*6./7.;
192  //cout << "good at distance 3/4 is " << distance << "\n";
193  r_out = posnu + distance*ntemp;
194  lon = r_out.Lon(); // latitude and longitude of exit point
195  lat = r_out.Lat();
196  c = posnu_length*posnu_length - pow(antarctica->Surface(lon,lat),2); // redo the law of cosines
197  }
198  } // now we are at 3/8 the distance
199  } // now we are at 3/4 distance
200  } // if exit point we initially found was not ok
201  else {
202  distance=(-1*b+sqrt(b*b-4*a*c))/2; // and quadratic formula
203  r_out = posnu + distance*ntemp;
204  }
205  return 1;
206  }
207 
208 
209 
213 }; //class Ray
214 
215 
216 #endif
Vector nrf_iceside_eachboresight[5][Anita::NLAYERS_MAX][Anita::NPHI_MAX]
Definition: ray.hh:37
double Lat() const
Returns latitude, where the +z direction is at 0 latitude.
Definition: position.cc:47
void PrintAnglesofIncidence()
Definition: ray.cc:27
This class represents a three-vector. Operators are overloaded to provide for the familiar operations...
Definition: vector.hh:27
int whichray
Definition: icemc.cc:162
Vector nsurf_rfexit
Definition: ray.hh:33
Vector nsurf_rfexit_db
Definition: ray.hh:34
Position rfexit[5]
Definition: ray.hh:42
Ice thicknesses and water depth.
Definition: icemodel.hh:88
void GetRFExit(Settings *settings1, Anita *anita1, int whichray, Position posnu, Position posnu_down, Position r_bn, Position r_boresights[Anita::NLAYERS_MAX][Anita::NPHI_MAX], int whichtry, IceModel *antarctica)
Definition: ray.cc:54
double Surface(double lon, double lat)
Definition: icemodel.cc:1053
int TraceRay(Settings *settings1, Anita *anita1, int whichiteration, double n_depth)
Definition: ray.cc:197
This class is a 3-vector that represents a position on the Earth&#39;s surface.
Definition: position.hh:26
Vector yaxis
Definition: ray.hh:211
Ray()
Definition: ray.cc:18
double slopeyy
Definition: ray.hh:47
static const int NPHI_MAX
max number of antennas around in phi (in smex, 16)
Definition: anita.hh:61
Position rfexit_eachboresight[5][Anita::NLAYERS_MAX][Anita::NPHI_MAX]
Definition: ray.hh:39
int GetSurfaceNormal(Settings *settings1, IceModel *antarctica, Vector posnu, double &slopeyangle, int whichtry)
Definition: ray.cc:176
Ray tracing.
Definition: ray.hh:20
Reads in and stores input settings for the run.
Definition: Settings.h:35
Vector n_exit2bn[5]
Definition: ray.hh:32
double slopeyx
Definition: ray.hh:47
static const int NLAYERS_MAX
max number of layers (in smex design, it&#39;s 4)
Definition: anita.hh:59
int RandomizeSurface(Settings *settings1, Position rfexit_temp, Vector posnu, IceModel *antarctica, double &slopeyangle, int whichtry)
Definition: ray.cc:108
double slopeyz
Definition: ray.hh:47
void Initialize()
Definition: ray.cc:32
Position rfexit_db[5]
Definition: ray.hh:41
double Lon() const
Returns longitude.
Definition: position.cc:51
int GetRayIceSide(const Vector &n_exit2bn, const Vector &nsurf_rfexit, double nexit, double nenter, Vector &nrf2_iceside)
Definition: ray.cc:297
Vector nrf_iceside[5]
Definition: ray.hh:35
Contains everything about positions within payload and signals it sees for each event, in both the trigger and signal paths.
Definition: anita.hh:32
Vector zaxis
Definition: ray.hh:212
static int WhereDoesItLeave(const Position &posnu, const Vector &ntemp, IceModel *antarctica, Position &r_out)
Definition: ray.hh:73
Vector xaxis
Definition: ray.hh:210
Vector n_exit2bn_eachboresight[5][Anita::NLAYERS_MAX][Anita::NPHI_MAX]
Definition: ray.hh:38
double Mag() const
Definition: vector.cc:65
double sum_slopeyness
Definition: ray.hh:45
Radiation from interaction.
Definition: signal.hh:13