CalibratedSSHk.cxx
1 
9 #include "CalibratedSSHk.h"
10 #include "RawSSHk.h"
11 #include <iostream>
12 #include <fstream>
13 #include <cstring>
14 
15 #include <TMath.h>
16 
17 ClassImp(CalibratedSSHk);
18 
19 namespace SSConsts {
20 //Calibration constants, may need to be updated
21 float calSlope[40]=
22  {1,1,100,1,1,1,1,1,1,1,1,100,1,1,1,100,100,100,100,100,1,1,1,1,100,1,1,1,100,1,1,1,1,1,1,100,100,100,100,100};
23 
24 float calIntercept[40]=
25  {0,0,-273.15,0,0,0,0,0,0,0,0,-273.15,0,0,0,-273.15,-273.15,-273.15,-273.15,-273.15,0,0,0,0,-273.15,0,0,0,-273.15,0,0,0,0,0,0,-273.15,-273.15,-273.15,-273.15,-273.15};
26 
27 int calScheme[40]=
28  {0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,1,1,1,1,1,0,0,0,0,1,0,0,0,1,0,0,0,0,0,0,1,1,1,1,1};
29 
30 
31 //Sunsensor Stuff
32 //int ssYVals[4][2]={{0,20},{22,3},{26,7},{9,29}};
33 //int ssXVals[4][2]={{1,21},{23,4},{27,8},{10,30}};
34 
35 //int sunsensorChans[20]={0,1,20,21,2,22,23,3,4,24,26,27,7,8,28,9,10,29,30,11};
36 int ssXInds[4][2]={{20,0},{3,22},{7,26},{29,9}};
37 int ssYInds[4][2]={{21,1},{4,23},{8,27},{30,10}};
38 int ssTemp[4]={2,24,28,11};
39 
40 
41 
42 //Sunsensor Stuff
43 float ssOffset[4][2]={{0.08,-0.1572},{-0.32940,-0.17477},
44  {0.05541,-0.08458},{-0.23773,-0.50356}};
45 float ssGain[4][2]={{5.0288,5.0},{4.8515,5.0},{5.0599,5.0},{5.0288,5.0}};
46 float ssSep[4]={3.704391,3.618574,3.512025,3.554451};
47 float ssAzRel[4]={0,-90,+180,90};
48 float ssGammaFactor[4]={0.4,0.2,0.3,0.5};
49 const float globalGamma=67;
50 }
51 
52 using namespace SSConsts;
53 
55 {
56  //Default Constructor
57 }
58 
60  //Default Destructor
61 }
62 
63 
65 {
66  run=hkPtr->run;
67  realTime=hkPtr->realTime;
68  payloadTime=hkPtr->payloadTime;
69  payloadTimeUs=hkPtr->payloadTimeUs;
70 
71  //Now calibrate voltage
72  for(int chan=0;chan<40;chan++) {
73  float avz= 2048;
74  float cal = 4055;
75  if(avzPtr)
76  avz = float((avzPtr->acromagData[chan])>>4);
77  if(calPtr)
78  cal = float((calPtr->acromagData[chan])>>4);
79  float slope=4.9/(cal-avz);
80  float intercept=-1*slope*avz;
81  voltage[chan]=slope*float((hkPtr->acromagData[chan])>>4)+intercept;
82 
83  // std::cout << board << "\t" << chan << "\t" << slope << "\t" << intercept << "\t" << hkPtr->acromagData[chan] << "\t" << voltage[chan] << std::endl;
84  }
85 
86 
87  //Now convert voltage to 'useful' quantity
88  for(int chan=0;chan<40;chan++) {
89  switch(calScheme[chan]) {
90  case 0:
91  //Do nothing
92  useful[chan]=voltage[chan];
93  break;
94  case 1:
95  //y = mx +c
96  useful[chan]=(calSlope[chan]*voltage[chan])+calIntercept[chan];
97  break;
98  default:
99  useful[chan]=voltage[chan];
100  break;
101  }
102  }
103 
104 }
105 
106 
107 const char *CalibratedSSHk::getName(int ssInd)
108 {
109  switch(ssInd) {
110  case 0: return "SS-2";
111  case 1: return "SS-4";
112  case 2: return "SS-6";
113  case 3: return "SS-8";
114  default:
115  return "n/c";
116  }
117 }
118 
119 
120 void CalibratedSSHk::getSSMagnitude(int ssInd, Float_t *magnitude, Float_t *magX, Float_t *magY) {
121  if(ssInd<0 || ssInd>4) return;
122 
123  *magnitude=
124  TMath::Abs(this->useful[ssXInds[ssInd][0]])+
125  TMath::Abs(this->useful[ssXInds[ssInd][1]])+
126  TMath::Abs(this->useful[ssYInds[ssInd][0]])+
127  TMath::Abs(this->useful[ssYInds[ssInd][1]]);
128 
129  *magX=TMath::Abs(this->useful[ssXInds[ssInd][0]]+this->useful[ssXInds[ssInd][1]]);
130  *magY=TMath::Abs(this->useful[ssYInds[ssInd][0]]+this->useful[ssYInds[ssInd][1]]);
131 }
132 
133 
134 Float_t CalibratedSSHk::getSSTemp(int ssInd)
135 {
136  if(ssInd<0 || ssInd>4) return -1;
137  return this->useful[ssTemp[ssInd]];
138 }
139 
140 
141 Int_t CalibratedSSHk::getSSXRatio(int ssInd, Float_t *xRatio)
142 {
143  *xRatio=(this->useful[ssXInds[ssInd][1]]-this->useful[ssXInds[ssInd][0]]);
144  Float_t xDenom=(this->useful[ssXInds[ssInd][1]]+this->useful[ssXInds[ssInd][0]]);
145  if(TMath::Abs(xDenom)>0.1*TMath::Abs(*xRatio)) {
146  (*xRatio)/=xDenom;
147  return 1;
148  }
149  else {
150  *xRatio=0;
151  }
152  return 0;
153 }
154 
155 Int_t CalibratedSSHk::getSSYRatio(int ssInd, Float_t *yRatio)
156 {
157 
158  *yRatio=(this->useful[ssYInds[ssInd][1]]-this->useful[ssYInds[ssInd][0]]);
159  Float_t yDenom=(this->useful[ssYInds[ssInd][1]]+this->useful[ssYInds[ssInd][0]]);
160  if(TMath::Abs(yDenom)>0.1*TMath::Abs(*yRatio)) {
161  (*yRatio)/=yDenom;
162  return 1;
163  }
164  else {
165  *yRatio=0;
166  }
167  return 0;
168 }
169 
170 
171 Float_t CalibratedSSHk::getSSAzimuth(int ssInd)
172 {
173  Float_t azimuth,elevation,relAzimuth;
174  Float_t pos[3];
175  getFancySS(ssInd,pos,&azimuth,&elevation,&relAzimuth);
176  return azimuth;
177 }
178 
179 
180 Float_t CalibratedSSHk::getSSAzimuthAdu5(int ssInd)
181 {
182  Float_t azimuth,elevation,relAzimuth;
183  Float_t pos[3];
184  getFancySS(ssInd,pos,&azimuth,&elevation,&relAzimuth);
185  return relAzimuth;
186 }
187 
188 Float_t CalibratedSSHk::getSSElevation(int ssInd)
189 {
190 
191  Float_t azimuth,elevation,relAzimuth;
192  Float_t pos[3];
193  getFancySS(ssInd,pos,&azimuth,&elevation,&relAzimuth);
194  return elevation;
195 
196 }
197 
198 
199 
200 
201 Int_t CalibratedSSHk::getFancySS(int ssInd, Float_t pos[3], Float_t *azimuth,
202  Float_t *elevation, Float_t *relAzimuth) {
203 
204  //Currently 0 & 1 are broken
205  if(ssInd<=1 || ssInd>=4) return 0;
206 
207 
208  Float_t magnitude=0,magX=0,magY=0;
209  this->getSSMagnitude(ssInd,&magnitude,&magX,&magY);
210 
211  Float_t xRatio=0;
212  Float_t x0=0;
213  if(this->getSSXRatio(ssInd,&xRatio)) {
214  x0=xRatio;
215  x0*=ssGain[ssInd][0];
216  x0-=ssOffset[ssInd][0];
217  }
218 
219  Float_t y0=0;
220  Float_t yRatio=0;
221  if(this->getSSYRatio(ssInd,&yRatio)) {
222  y0=-1*yRatio;
223  y0*=ssGain[ssInd][1];
224  y0-=ssOffset[ssInd][1];
225  }
226 
227 
228  int goodVals=1;
229  if(magX<0.5) {
230  goodVals=0;
231  xRatio=0;
232  x0=-1*ssOffset[ssInd][0];
233  }
234 
235  if(magY<0.5) {
236  goodVals=0;
237  yRatio=0;
238  y0=-1*ssOffset[ssInd][1];
239  }
240 
241  Float_t gamma=(globalGamma-ssGammaFactor[ssInd])*TMath::DegToRad();
242  pos[0]=(-1*x0*TMath::Cos(gamma))-(TMath::Sin(gamma)*ssSep[ssInd]);
243  pos[1]=-1*y0;
244  pos[2]=ssSep[ssInd]*TMath::Cos(gamma)-x0*TMath::Sin(gamma);
245 
246  *azimuth=TMath::ATan2(pos[1],-1*pos[0])*TMath::RadToDeg();
247  Float_t posXY2=TMath::Sqrt(pos[0]*pos[0] + pos[1]*pos[1]);
248  *elevation=TMath::ATan2(pos[2],posXY2)*TMath::RadToDeg();
249  *relAzimuth=(*azimuth)+ssAzRel[ssInd];
250  if((*relAzimuth)<0) (*relAzimuth)+=360;
251 
252  return goodVals;
253 }
254 
255 
256 
257 Float_t CalibratedSSHk::getRawSunsensor(int ssInd, int type)
258 {
259  if((ssInd>=0 && ssInd<4) && (type>=0 && type<5)) {
260  switch(type) {
261  case 0:
262  return useful[ssXInds[ssInd][0]%40];
263  case 1:
264  return useful[ssXInds[ssInd][1]%40];
265  case 2:
266  return useful[ssYInds[ssInd][0]%40];
267  case 3:
268  return useful[ssYInds[ssInd][1]%40];
269  case 4:
270  return useful[ssTemp[ssInd]%40];
271  default:
272  return -1;
273 
274  }
275  }
276  return -1;
277 
278 }
UShort_t acromagData[40]
The array of ADC values.
Definition: RawSSHk.h:37
Int_t getSSYRatio(int ssInd, Float_t *yRatio)
Get sunsensor y-ratio.
Float_t getSSTemp(int ssInd)
Get sunsensor temperature.
RawSSHk – The Raw ANITA Housekeeping.
Definition: RawSSHk.h:23
CalibratedSSHk – The calibrated housekeeping data.
Int_t getFancySS(int ssInd, Float_t pos[3], Float_t *azimuth, Float_t *elevation, Float_t *relAzimuth)
Convert sunsensor data to elevation and azimuth.
UInt_t payloadTime
Time in unixTime.
Definition: RawSSHk.h:33
Int_t getSSXRatio(int ssInd, Float_t *xRatio)
Get sunsensor x-ratio.
UInt_t realTime
Time in unixTime.
Definition: RawSSHk.h:32
void getSSMagnitude(int ssInd, Float_t *magnitude, Float_t *magX, Float_t *magY)
Get sunsensor magnitude.
Int_t run
Run number, assigned offline.
Definition: RawSSHk.h:31
CalibratedSSHk()
Default constructor.
Float_t getRawSunsensor(int ssInd, int type)
Returns raw sunsensor stuff, here type goes x1,x2,y1,y2,T.
~CalibratedSSHk()
Default destructor.
UInt_t payloadTimeUs
Subsecond timing.
Definition: RawSSHk.h:34