AnitaGeomTool.h
1 
11 #ifndef ANITAGEOMTOOL_H
12 #define ANITAGEOMTOOL_H
13 
14 //Includes
15 #include <iostream>
16 #include <TObject.h>
17 #include <TMath.h>
18 #include <TVector3.h>
19 #include "AnitaConventions.h"
20 
21 #include <fstream>
22 #include <cstring>
23 #include "AnitaConventions.h"
24 
25 #include "TString.h"
26 #include "TObjArray.h"
27 #include "TObjString.h"
28 #include "TVector3.h"
29 
30 
31 
32 class UsefulAnitaEvent;
33 
34 //Are actually geometry things
35 #define R_EARTH 6.378137E6
36 #define GEOID_MAX 6.378137E6 // parameters of geoid model
37 #define GEOID_MIN 6.356752E6
38 #define C_LIGHT 299792458 //meters
39 #define FLATTENING_FACTOR (1./298.257223563)
40 
41 
43 
49 {
50  public:
51 
52  /********************************************************************************************************
53  Constructor and destructor functions
54  ********************************************************************************************************/
55  virtual ~AnitaGeomTool();
56 
57 
58  /********************************************************************************************************
59  Static member functions
60  ********************************************************************************************************/
61 
62  static AnitaGeomTool* Instance( int anita_version = 0);
63  static AnitaRing::AnitaRing_t getRingFromAnt(Int_t ant);
65  Int_t phi,
67  Int_t &surf, Int_t &chan, Int_t &ant);
68  static void getRingAntPolPhiFromSurfChan(Int_t surf, Int_t chan,
70  Int_t &ant,
72  Int_t &phi);
73  static Int_t getChanIndex(Int_t surf, Int_t chan);
75  Int_t phi,
77  static Int_t getChanIndexFromAntPol(Int_t ant,
79  static Int_t getSurfFromAnt(Int_t ant);
80  static Int_t getChanFromAntPol(Int_t ant,AnitaPol::AnitaPol_t pol);
81  static Int_t getSurfChanFromChanIndex(Int_t chanIndex, // input channel index
82  Int_t &surf,Int_t &chan);
83  static Int_t getPhiRingPolFromSurfChanTrigger(Int_t surf, Int_t chan, Int_t &phi,
85  static Int_t getSurfChanTriggerFromPhiRingPol(Int_t phi, AnitaRing::AnitaRing_t ring,
86  AnitaTrigPol::AnitaTrigPol_t pol,Int_t &surf, Int_t &chan);
87  static Int_t getPhiRingFromSurfL1Chan(Int_t surf, Int_t l1Chan, Int_t &phi, //a4 only
89  static Int_t getPhiPolFromSurfL1Chan(Int_t surf, Int_t l1Chan, Int_t &phi, //a3 only
91  static Int_t getSurfL1TriggerChanFromPhiRing(Int_t phi, AnitaRing::AnitaRing_t ring, //a4 only
92  Int_t &surf, Int_t &l1Chan);
93  static Int_t getSurfL1TriggerChanFromPhiPol(Int_t phi, AnitaPol::AnitaPol_t ring, //a3 only
94  Int_t &surf, Int_t &l1Chan);
95  static Int_t getSurfL2TriggerChanFromPhi(Int_t phi, Int_t &surf, Int_t &l2Chan);
96  static Int_t getAntPolFromSurfChan(Int_t surf, Int_t chan, Int_t &ant,
97  AnitaPol::AnitaPol_t &pol);
98  static Int_t getAzimuthPartner(Int_t rx);
99  static void getThetaPartners(Int_t rx, int& rxleft, int& rxright);
100  static void getNeighbors(Int_t rx, int& rxleft, int& rxright);
101  static Int_t getPhiSector(Int_t rx);
102  static Int_t getLayer(Int_t irx);
103  static Int_t getPhiFromAnt(Int_t ant);
104  static Int_t getAntFromPhiRing(Int_t phi, AnitaRing::AnitaRing_t ring);
105  static Int_t getAntOrientation(Int_t ant);
106  static Double_t getPhiDiff(Double_t firstPhi, Double_t secondPhi);
107 
108 
109 
110 
111  /********************************************************************************************************
112  Non-static member functions (requires initialization of class for accessing data)
113  ********************************************************************************************************/
114  Double_t getDirectionWrtNorth(Int_t phi, Double_t heading);
115 
117  void getAntXYZ(Int_t ant, Double_t &x, Double_t &y, Double_t &z,
119  Double_t getAntZ(Int_t ant, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical);
120  Double_t getAntR(Int_t ant, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical);
123  Double_t getMeanAntPairPhiRelToAftFore(Int_t firstAnt, Int_t secondAnt, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical);
125  Int_t getUpperAntNearestPhiWave(Double_t phiWave, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical);
126 
127 
128 
129  void getAntFaceXYZ(Int_t ant, Double_t &x, Double_t &y, Double_t &z);
130  Double_t getAntFaceZ(Int_t ant);
131  Double_t getAntFaceR(Int_t ant);
132  Double_t getAntFacePhiPosition(Int_t ant);
133  Double_t getAntFacePhiPositionRelToAftFore(Int_t ant);
134  Int_t getTopAntFaceNearestPhiWave(Double_t phiWave);
135  Int_t getUpperAntFaceNearestPhiWave(Double_t phiWave) { return getTopAntFaceNearestPhiWave(phiWave);}
136 
137  // Double_t phaseCentreToAntFront; //m
138 
139 
140  Double_t xAntFromDeckHorn[NUM_SEAVEYS]; //m
141  Double_t yAntFromDeckHorn[NUM_SEAVEYS]; //m
142  Double_t zAntFromDeckHorn[NUM_SEAVEYS]; //m
143  Double_t rAntFromDeckHorn[NUM_SEAVEYS]; //m
144  Double_t azCentreFromDeckHorn[NUM_SEAVEYS]; //radians
145  Double_t apertureAzFromDeckHorn[NUM_SEAVEYS]; //radians
146  Double_t apertureElFromDeckHorn[NUM_SEAVEYS]; //radians
147 
148 
149  Double_t xPhaseCentreFromDeckHorn[NUM_SEAVEYS][NUM_POLS]; //m
150  Double_t yPhaseCentreFromDeckHorn[NUM_SEAVEYS][NUM_POLS]; //m
151  Double_t zPhaseCentreFromDeckHorn[NUM_SEAVEYS][NUM_POLS]; //m
152  Double_t rPhaseCentreFromDeckHorn[NUM_SEAVEYS][NUM_POLS]; //m
153  Double_t azPhaseCentreFromDeckHorn[NUM_SEAVEYS][NUM_POLS]; //radians
154 
155 
156  Double_t xAntFromDeckBicone[NUM_BICONES]; //m
157  Double_t yAntFromDeckBicone[NUM_BICONES]; //m
158  Double_t zAntFromDeckBicone[NUM_BICONES]; //m
159 
160  Double_t xAntFromDeckDiscone[NUM_DISCONES]; //m
161  Double_t yAntFromDeckDiscone[NUM_DISCONES]; //m
162  Double_t zAntFromDeckDiscone[NUM_DISCONES]; //m
163 
164  Double_t xAnitaBoxFromDeckCorner[4];
165  Double_t yAnitaBoxFromDeckCorner[4];
166  Double_t zAnitaBoxFromDeckCorner[4];
167  Double_t xBatteryBoxFromDeckCorner[4];
168  Double_t yBatteryBoxFromDeckCorner[4];
169  Double_t zBatteryBoxFromDeckCorner[4];
170  Double_t xSipBoxFromDeckCorner[4];
171  Double_t ySipBoxFromDeckCorner[4];
172  Double_t zSipBoxFromDeckCorner[4];
173 
174  Double_t gpsPlaneFromDeck[3];
175  Double_t gpsHeadingFromDeck[3];
176  Double_t aftForeOffsetAngleDeck;
177 
178  Double_t xAntFromVerticalHorn[NUM_SEAVEYS]; //m
179  Double_t yAntFromVerticalHorn[NUM_SEAVEYS]; //m
180  Double_t zAntFromVerticalHorn[NUM_SEAVEYS]; //m
181  Double_t rAntFromVerticalHorn[NUM_SEAVEYS]; //m
182  Double_t azCentreFromVerticalHorn[NUM_SEAVEYS]; //radians
183  Double_t apertureAzFromVerticalHorn[NUM_SEAVEYS]; //radians
184  Double_t apertureElFromVerticalHorn[NUM_SEAVEYS]; //radians
185 
186  Double_t xPhaseCentreFromVerticalHorn[NUM_SEAVEYS][NUM_POLS]; //m
187  Double_t yPhaseCentreFromVerticalHorn[NUM_SEAVEYS][NUM_POLS]; //m
188  Double_t zPhaseCentreFromVerticalHorn[NUM_SEAVEYS][NUM_POLS]; //m
189  Double_t rPhaseCentreFromVerticalHorn[NUM_SEAVEYS][NUM_POLS]; //m
190  Double_t azPhaseCentreFromVerticalHorn[NUM_SEAVEYS][NUM_POLS]; //radians
191 
192 
193  Double_t xAntFromVerticalBicone[NUM_BICONES]; //m
194  Double_t yAntFromVerticalBicone[NUM_BICONES]; //m
195  Double_t zAntFromVerticalBicone[NUM_BICONES]; //m
196 
197  Double_t xAntFromVerticalDiscone[NUM_DISCONES]; //m
198  Double_t yAntFromVerticalDiscone[NUM_DISCONES]; //m
199  Double_t zAntFromVerticalDiscone[NUM_DISCONES]; //m
200 
201  Double_t xAnitaBoxFromVerticalCorner[4];
202  Double_t yAnitaBoxFromVerticalCorner[4];
203  Double_t zAnitaBoxFromVerticalCorner[4];
204  Double_t xBatteryBoxFromVerticalCorner[4];
205  Double_t yBatteryBoxFromVerticalCorner[4];
206  Double_t zBatteryBoxFromVerticalCorner[4];
207  Double_t xSipBoxFromVerticalCorner[4];
208  Double_t ySipBoxFromVerticalCorner[4];
209  Double_t zSipBoxFromVerticalCorner[4];
210 
211  Double_t gpsPlaneFromVertical[3];
212  Double_t gpsHeadingFromVertical[3];
213  Double_t aftForeOffsetAngleVertical;
214 
215  //Simon's position calib numbers
216  Double_t deltaRPhaseCentre[NUM_SEAVEYS][NUM_POLS]; //Relative to photogrammetry + ring offset
217  Double_t deltaZPhaseCentre[NUM_SEAVEYS][NUM_POLS]; //Relative to photogrammetry + ring offset
218  Double_t deltaPhiPhaseCentre[NUM_SEAVEYS][NUM_POLS]; //Relative to photogrammetry + ring offset
219  Double_t ringPhaseCentreOffset[3]; //Offset for each ring, upper lower and nadir
220 
221 
222  TVector3 fHeadingRotationAxis;
223  TVector3 fPitchRotationAxis;
224  TVector3 fRollRotationAxis;
225 
226 
227  //Kurt's ANITA-3 numbers
228  Double_t xAntFromVerticalHornPhotogrammetry[NUM_SEAVEYS]; //m
229  Double_t yAntFromVerticalHornPhotogrammetry[NUM_SEAVEYS]; //m
230  Double_t zAntFromVerticalHornPhotogrammetry[NUM_SEAVEYS]; //m
231  Double_t rAntFromVerticalHornPhotogrammetry[NUM_SEAVEYS]; //m
232  Double_t azCentreFromVerticalHornPhotogrammetry[NUM_SEAVEYS]; //radians
233  Double_t apertureAzFromVerticalHornPhotogrammetry[NUM_SEAVEYS]; //radians
234  Double_t apertureElFromVerticalHornPhotogrammetry[NUM_SEAVEYS]; //radians
235 
236  Double_t xPhaseCentreFromVerticalHornPhotogrammetry[NUM_SEAVEYS][NUM_POLS]; //m
237  Double_t yPhaseCentreFromVerticalHornPhotogrammetry[NUM_SEAVEYS][NUM_POLS]; //m
238  Double_t zPhaseCentreFromVerticalHornPhotogrammetry[NUM_SEAVEYS][NUM_POLS]; //m
239  Double_t rPhaseCentreFromVerticalHornPhotogrammetry[NUM_SEAVEYS][NUM_POLS]; //m
240  Double_t azPhaseCentreFromVerticalHornPhotogrammetry[NUM_SEAVEYS][NUM_POLS]; //radians
241  Double_t aftForeOffsetAngleVerticalPhotogrammetry; //radians
242 
243  void updateAnt(Double_t deltaR,Double_t deltaRL,Double_t deltaUD);
244  void printAntPos();
245  void addPhaseCenters();
246 
247  void usePhotogrammetryNumbers(Int_t flag) {
248  fUsePhotogrammetryNumbers=flag;
249  }
250 
251 
252  inline Double_t getGeoid(Double_t theta) {
253  Double_t c=TMath::Cos(theta);
254  return GEOID_MIN*GEOID_MAX/TMath::Sqrt(GEOID_MIN*GEOID_MIN-
255  (GEOID_MIN*GEOID_MIN-GEOID_MAX*GEOID_MAX)*c*c);
256  }
257 
258  void getCartesianCoords(Double_t lat, Double_t lon, Double_t alt, Double_t p[3]);
259  void getLatLonAltFromCartesian(Double_t p[3], Double_t &lat, Double_t &lon, Double_t &alt);
260  Double_t getDistanceToCentreOfEarth(Double_t lat);
261 
262  inline Double_t getLat(Double_t theta) {
263  return (90.-((theta*TMath::RadToDeg())));
264  }
265 
266  inline Double_t getLon(Double_t phi){
267  //Need to fix this somehow
268  Double_t phi_deg = phi*TMath::RadToDeg();
269  if (phi_deg>270)
270  phi_deg-=360;
271  return (90.-phi_deg);
272  }
273 
274  inline Double_t getThetaFromLat(Double_t lat) {
275  return (90.- lat)*TMath::DegToRad();
276  }
277 
278  inline Double_t getPhiFromLon(Double_t lon){
279  //Need to fix this somehow
280  Double_t phi_deg = 90. - lon;
281  if(phi_deg<0) phi_deg+=360;
282  return phi_deg*TMath::DegToRad();
283  }
284 
285  inline Double_t getPhi(Double_t p[3]){
286  // returns phi between 0 and 2pi.
287  Double_t pt=0;
288  Double_t phi=0;
289  pt=sqrt(p[0]*p[0]+p[1]*p[1]);
290  if (pt==0)
291  return 0.;
292  else if (pt!=0) {
293  if (p[1]/pt>1 || p[1]/pt<-1) {
294  std::cerr << "Error in getPhi. \n";
295  return 0;
296  }
297  phi=asin(p[1]/pt);
298  }
299  if (p[1]<0. && p[0]>0) phi += 2*TMath::Pi();
300  else if (phi>0 && p[0]<0.) phi = TMath::Pi() - phi;
301  else if (phi<0 && p[0]<0.) phi = -(TMath::Pi()+phi)+2*TMath::Pi();
302  return phi;
303  }
304 
305  inline Double_t getPhi(TVector3 &thePos) {
306  Double_t p[3]={thePos.X(),thePos.Y(),thePos.Z()};
307  return getPhi(p);
308  //return thePos.Theta();
309  }
310 
311  inline Double_t getTheta(Double_t p[3]) {
312  Double_t pz,pt;
313  Double_t tantheta1=0;
314  Double_t theta=0;
315 
316  pz=p[2];
317  pt=sqrt(p[0]*p[0]+p[1]*p[1]);
318  tantheta1=pt/pz;
319  theta=atan(tantheta1);
320 
321  if (pz<0)
322  theta += TMath::Pi();
323  return theta;
324  }
325 
326 
327  inline Double_t getTheta(TVector3 &thePos) {
328  Double_t p[3]={thePos.X(),thePos.Y(),thePos.Z()};
329  thePos.GetXYZ(p);
330  return getTheta(p);
331  }
332 
333  inline void getLonLat(Double_t p[3],Double_t& lon,Double_t& lat) {
334  lon=getLon(getPhi(p));
335  lat=getLat(getTheta(p));
336  }
337 
338  inline void getLonLat(TVector3 &thePos,Double_t& lon,Double_t& lat) {
339  lon=getLon(getPhi(thePos));
340  lat=getLat(getTheta(thePos));
341  }
342 
343 
344 
345  private:
346  void readAnita2Photogrammetry();
347  void readPhotogrammetry(int version);
348  void readSimonsNumbers();
349  void readPhaseCenterNumbers(int version);
350  Int_t fUsePhotogrammetryNumbers;
351  AnitaGeomTool();
352 
353 
354 };
355 
356 
357 
358 
359 #endif //ANITAGEOMTOOL_H
static Int_t getSurfL2TriggerChanFromPhi(Int_t phi, Int_t &surf, Int_t &l2Chan)
Converts phi-sector to surf and l2 trigger channel.
static Int_t getPhiRingFromSurfL1Chan(Int_t surf, Int_t l1Chan, Int_t &phi, AnitaRing::AnitaRing_t &ring)
Converts the SURF and L1 trigger channel to phi-sector and polarization.
static Int_t getLayer(Int_t irx)
get layer given antenna number
Double_t getThetaFromLat(Double_t lat)
Converts latitude to polar angle.
static void getThetaPartners(Int_t rx, int &rxleft, int &rxright)
output the antennas that are in neighbouring phi sectors (not the neighbouring antennas) ...
Int_t getTopAntNearestPhiWave(Double_t phiWave, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical)
get antenna closest to given plane wave direction
Double_t getDirectionWrtNorth(Int_t phi, Double_t heading)
Get direction that a phi sector is pointing wrt north. Also takes heading as a input.
Double_t getGeoid(Double_t theta)
Returns the geoid radiuus as a function of theta (the polar angle?)
Double_t getAntPhiPositionRelToAftFore(Int_t ant, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical)
get antenna phi position relative to ADU5 AFT-FORE line
static void getRingAntPolPhiFromSurfChan(Int_t surf, Int_t chan, AnitaRing::AnitaRing_t &ring, Int_t &ant, AnitaPol::AnitaPol_t &pol, Int_t &phi)
Convert surf-chan to ring-ant-pol-phi.
Double_t getAntZ(Int_t ant, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical)
get antenna z position
Int_t getTopAntFaceNearestPhiWave(Double_t phiWave)
get upper antenna closest to given plane wave direction
static void getNeighbors(Int_t rx, int &rxleft, int &rxright)
output the neighboring antennas
Double_t getTheta(TVector3 &thePos)
Converts cartesian coordinates to polar angle.
static Int_t getChanIndexFromAntPol(Int_t ant, AnitaPol::AnitaPol_t pol)
Convert ant-pol to logical index.
void getLonLat(Double_t p[3], Double_t &lon, Double_t &lat)
Converts cartesian coordinates to latitude and longitude.
static Int_t getAntPolFromSurfChan(Int_t surf, Int_t chan, Int_t &ant, AnitaPol::AnitaPol_t &pol)
Convert surf-chan to ant-pol.
static Int_t getSurfChanFromChanIndex(Int_t chanIndex, Int_t &surf, Int_t &chan)
Convert logical index to surf and channel.
static Int_t getChanIndexFromRingPhiPol(AnitaRing::AnitaRing_t ring, Int_t phi, AnitaPol::AnitaPol_t pol)
Convert ring-phi-pol to logical index.
static Double_t getPhiDiff(Double_t firstPhi, Double_t secondPhi)
Returns the angular difference between two phi values (in radians)
Double_t getLon(Double_t phi)
Converts a azimuthal angle to longitude.
Double_t getAntR(Int_t ant, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical)
get antenna r position
static Int_t getPhiRingPolFromSurfChanTrigger(Int_t surf, Int_t chan, Int_t &phi, AnitaRing::AnitaRing_t &ring, AnitaTrigPol::AnitaTrigPol_t &pol)
Converts the SURF and channel numbers to phi-sector, ring and polarization.
static void getSurfChanAntFromRingPhiPol(AnitaRing::AnitaRing_t ring, Int_t phi, AnitaPol::AnitaPol_t pol, Int_t &surf, Int_t &chan, Int_t &ant)
Convert ring-phi-pol to surf-chan-ant.
static Int_t getAzimuthPartner(Int_t rx)
output the antenna that points to the same place in phi as the input antenna
void getAntFaceXYZ(Int_t ant, Double_t &x, Double_t &y, Double_t &z)
get location fo antenna face in balloon cartesian coordinates
Double_t getMeanAntPairPhiRelToAftFore(Int_t firstAnt, Int_t secondAnt, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical)
The mean of the two antenna phi positions.
Double_t getAntPhiPosition(Int_t ant, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical)
get antenna phi position
void getAntXYZ(Int_t ant, Double_t &x, Double_t &y, Double_t &z, AnitaPol::AnitaPol_t pol=AnitaPol::kVertical)
get antenna cartesian coordinates (from photogrammetry)
Double_t getLat(Double_t theta)
Converts polar angle to latitude.
enum AnitaRing::EAnitaRing AnitaRing_t
Ring enumeration.
enum AnitaTrigPol::EAnitaTrigPol AnitaTrigPol_t
Polarisation enumeration.
Double_t getPhi(Double_t p[3])
Converts cartesian coordinates to azimuthal angle.
Int_t getUpperAntFaceNearestPhiWave(Double_t phiWave)
get upper antenna closest to given plane wave direction
UsefulAnitaEvent – The Calibrated Useful Anita Event object.
static Int_t getAntOrientation(Int_t ant)
Some of the antennas have their orientation reversed relative to nominal. The effect of this is to sw...
virtual ~AnitaGeomTool()
Default destructor.
static AnitaRing::AnitaRing_t getRingFromAnt(Int_t ant)
Get ring form antenna number (0-39)
static Int_t getSurfL1TriggerChanFromPhiRing(Int_t phi, AnitaRing::AnitaRing_t ring, Int_t &surf, Int_t &l1Chan)
Convert phi-sector and polarization from phi-sector and polarization.
Double_t getAntFaceR(Int_t ant)
get r position for antenna face
static Int_t getPhiPolFromSurfL1Chan(Int_t surf, Int_t l1Chan, Int_t &phi, AnitaPol::AnitaPol_t &pol)
Converts the SURF and L1 trigger channel to phi-sector and polarization.
static Int_t getPhiFromAnt(Int_t ant)
get phi from ant
static Int_t getAntFromPhiRing(Int_t phi, AnitaRing::AnitaRing_t ring)
get antenna number from phi and ring
static Int_t getSurfChanTriggerFromPhiRingPol(Int_t phi, AnitaRing::AnitaRing_t ring, AnitaTrigPol::AnitaTrigPol_t pol, Int_t &surf, Int_t &chan)
Converts the SURF and L1 trigger channel to phi-sector and polarization.
Double_t getTheta(Double_t p[3])
Converts cartesian coordinates to polar angle.
static Int_t getChanIndex(Int_t surf, Int_t chan)
Surf + channel to channel index.
Double_t getPhiFromLon(Double_t lon)
Converts longitude to azimuthal angle.
Double_t getPhi(TVector3 &thePos)
Converts cartesian coordinates to azimuthal angle.
Vertical Polarisation.
void getLonLat(TVector3 &thePos, Double_t &lon, Double_t &lat)
Converts cartesian coordinates to latitude and longitude.
Double_t getAntFacePhiPosition(Int_t ant)
get phi position for antenna face
static Int_t getPhiSector(Int_t rx)
phi sector of this antenna. rx runs from 0 to 31.
Double_t getAntFaceZ(Int_t ant)
get z position for antenna face
enum AnitaPol::EAnitaPol AnitaPol_t
Polarisation enumeration.
static AnitaGeomTool * Instance(int anita_version=0)
Instance generator. If version_number == 0, uses AnitaVersion::get();.
AnitaGeomTool – The ANITA Geometry Tool.
Definition: AnitaGeomTool.h:48
Double_t getAntFacePhiPositionRelToAftFore(Int_t ant)
get phi position relative to ADU5 AFT-FORE direction
void fillAntPositionsFromPrioritizerdConfig()
Used for evaluating ANITA-3 Prioritizerd performance.