-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateIceMCgpsA4.cxx
212 lines (176 loc) · 6.35 KB
/
createIceMCgpsA4.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#include "AnitaConventions.h"
#include "AnitaGeomTool.h"
#include "UsefulAnitaEvent.h"
#include "RawAnitaEvent.h"
#include "Adu5Pat.h"
#include "TimedAnitaHeader.h"
#include "PrettyAnitaHk.h"
#include "ProgressBar.h"
#include "TFile.h"
#include "TTree.h"
#include "TChain.h"
#include "TCanvas.h"
#include "TGraph.h"
#include "TH2.h"
#include "TColor.h"
#include "TMath.h"
#include "TStyle.h"
#include "TSystem.h"
#include <iostream>
#include <fstream>
using namespace Acclaim;
using namespace std;
void getCartesianCoords(Double_t lat, Double_t lon, Double_t alt, Double_t p[3]);
int main(int argc, char *argv[]){
if(!(argc==3 || argc==2)){
std::cerr << "Usage 1: " << argv[0] << " [run]" << std::endl;
std::cerr << "Usage 2: " << argv[0] << " [firstRun] [lastRun]" << std::endl;
return 1;
}
std::cout << argv[0] << "\t" << argv[1];
if(argc==3){std::cout << "\t" << argv[2];}
std::cout << std::endl;
const Int_t firstRun = atoi(argv[1]);
const Int_t lastRun = argc==3 ? atoi(argv[2]) : firstRun;
cout << "first run is " << firstRun << endl;
cout << "last run is " << lastRun << endl;
AnitaVersion::set(4);
FileStat_t staty;
char gpsName[FILENAME_MAX];
Adu5Pat *pat = 0;
TChain *gpsChain = new TChain("adu5PatTree");
for (int run=firstRun;run<lastRun+1; run++){
sprintf(gpsName,"/Users/oindreebanerjee/OneDrive/flight1617/timedGps/timedGpsEvent%d.root",run);
cout << gpsName << endl;
if(gSystem->GetPathInfo(gpsName,staty)) {
continue;
}
gpsChain->Add(gpsName);
}
gpsChain->SetBranchAddress("pat", &pat);
gpsChain->BuildIndex("realTime");
UInt_t numEntries=gpsChain->GetEntries();
cout << "There are " << numEntries << " in total "<< endl;
const int granularity = 60;
cout << "The chosen granularity is : " << granularity << " seconds" << endl;
gpsChain->GetEntry(0);
double firstTS = pat->realTime;
gpsChain->GetEntry(numEntries-1);
double lastTS = pat->realTime;
time_t tt = firstTS;
struct tm *tm = localtime(&tt);
char date[30];
strftime(date, sizeof(date), "%Y-%m-%d, %H:%M", tm);
char today[30];
strftime(today, sizeof(today), "%Y-%b-%d", tm);
cout << "Events starting from : " << date << endl;
tt = lastTS;
tm = localtime(&tt);
strftime(date, sizeof(date), "%Y-%m-%d, %H:%M", tm);
cout << "And finishing on : " << date << endl;
UInt_t realTime = firstTS;
Float_t pitch, roll;
Float_t heading, latitude, longitude, altitude;
TTree* tree = new TTree();
tree->Branch("heading", &heading, "heading/F" );
tree->Branch("latitude", &latitude, "latitude/F" );
tree->Branch("longitude", &longitude, "longitude/F" );
tree->Branch("altitude", &altitude, "altitude/F" );
tree->Branch("realTime", &realTime, "realTime/I" );
tree->Branch("pitch", &pitch, "pitch/F" );
tree->Branch("roll", &roll, "roll/F" );
// int count = 0;
// TH2D *htemp = new TH2D("htemp", "", 1000, -2e3, +2e3, 1000, -2e3, +2e3);
UInt_t realTime_old = firstTS;
// Bad periods in different flights
int num_bad = 4; //ANITA-4
//int num_bad = 1; //ANITA-3
// ANITA-3 had the following bad time period
// Skip from 1420749855 to 1420751715
//Int_t badPeriodStart = 1420749800;
//Int_t badPeriodEnd = 1420751715;
// ANITA-4 had four bad time periods, these were in runs 183, 293, 311, 367 --> oindree
Int_t badPeriodStart[num_bad];
Int_t badPeriodEnd[num_bad];
badPeriodStart[0] = 1481680783;
badPeriodStart[1] = 1482474256;
badPeriodStart[2] = 1482605592;
badPeriodStart[3] = 1483003713;
badPeriodEnd[0] = badPeriodStart[0] + 913;
badPeriodEnd[1] = badPeriodStart[1] + 44256;
badPeriodEnd[2] = badPeriodStart[2] + 224;
badPeriodEnd[3] = badPeriodStart[3] + 850;
ProgressBar p((lastTS-firstTS)/granularity);
//for (unsigned int entry=0;entry<numEntries;entry++){
while(realTime_old<=lastTS){
if (realTime_old > badPeriodStart[3])
{
break;
}
for (int ibad = 0; ibad < num_bad-1; ibad++)
{
while (realTime_old>=badPeriodStart[ibad] && realTime_old<=badPeriodEnd[ibad])
{
realTime_old=realTime_old+granularity;
}
}
int index = gpsChain->GetEntryNumberWithIndex(realTime_old);
p++;
if (index>0){
gpsChain->GetEntry(index);
} else {
index = gpsChain->GetEntryNumberWithBestIndex(realTime_old);
gpsChain->GetEntry(index);
while (TMath::Abs((int)pat->realTime-(int)realTime_old)>70 || pat->realTime<realTime_old){
cout << pat->realTime << " " << realTime_old << endl;
realTime_old=realTime_old+granularity;
index = gpsChain->GetEntryNumberWithBestIndex(realTime_old);
gpsChain->GetEntry(index);
}
}
// gpsChain->GetEntry(entry);
// realTime = pat->realTime;
// if (realTime-realTime_old<granularity) continue;
// // cout << realTime << endl;
// // int temp = int(realTime-firstTS);
// // if ( (temp%granularity)==0){
// while (pat->heading<0 || isnan(pat->heading)){
// entry++;
// gpsChain->GetEntry(entry);
// p++;
// }
realTime = pat->realTime;
heading = pat->heading;
latitude = pat->latitude;
longitude = pat->longitude;
altitude = pat->altitude;
pitch = pat->pitch;
roll = pat->roll;
realTime_old = realTime+granularity;
tree->Fill();
// double pos[3];
// getCartesianCoords(latitude, longitude, altitude, pos);
// htemp->Fill(pos[0], pos[1]);
// cout << pos[0] << " " << pos[1] << endl;
// count ++;
}
cout << "Saving" << endl;
TFile *output = new TFile ("anita4gps_pitchroll.root", "recreate");
tree->Write("adu5PatTree");
cout << "Saved" << endl;
output->Close();
return 0;
}
void getCartesianCoords(Double_t lat, Double_t lon, Double_t alt, Double_t p[3])
{
if(lat<0) lat*=-1;
//Note that x and y are switched to conform with previous standards
lat*=TMath::DegToRad();
lon*=TMath::DegToRad();
//calculate x,y,z coordinates
Double_t C2=pow(cos(lat)*cos(lat)+(1-FLATTENING_FACTOR)*(1-FLATTENING_FACTOR)*sin(lat)*sin(lat),-0.5);
Double_t Q2=(1-FLATTENING_FACTOR)*(1-FLATTENING_FACTOR)*C2;
p[1]=(R_EARTH*C2+alt)*TMath::Cos(lat)*TMath::Cos(lon)/1000;
p[0]=(R_EARTH*C2+alt)*TMath::Cos(lat)*TMath::Sin(lon)/1000;
p[2]=(R_EARTH*Q2+alt)*TMath::Sin(lat)/1000;
}