1 |
// |
2 |
// C/C++ headers |
3 |
// |
4 |
#include <fstream> |
5 |
#include <string.h> |
6 |
#include <iostream> |
7 |
#include <cstring> |
8 |
#include <stdio.h> |
9 |
// |
10 |
// ROOT headers |
11 |
// |
12 |
#include <TTree.h> |
13 |
#include <TClassEdit.h> |
14 |
#include <TObject.h> |
15 |
#include <TList.h> |
16 |
#include <TArrayI.h> |
17 |
#include <TSystem.h> |
18 |
#include <TSystemDirectory.h> |
19 |
#include <TString.h> |
20 |
#include <TFile.h> |
21 |
#include <TClass.h> |
22 |
#include <TSQLServer.h> |
23 |
#include <TSQLRow.h> |
24 |
#include <TSQLResult.h> |
25 |
// |
26 |
// RunInfo header |
27 |
// |
28 |
#include <RunInfo.h> |
29 |
#include <GLTables.h> |
30 |
// |
31 |
// YODA headers |
32 |
// |
33 |
#include <PamelaRun.h> |
34 |
#include <PscuHeader.h> |
35 |
#include <PscuEvent.h> |
36 |
#include <EventHeader.h> |
37 |
#include <mcmd/McmdEvent.h> |
38 |
#include <mcmd/McmdRecord.h> |
39 |
// |
40 |
// This program headers |
41 |
// |
42 |
#include <OrbitalInfo.h> |
43 |
#include <OrbitalInfoVerl2.h> |
44 |
#include <OrbitalInfoCore.h> |
45 |
#include <InclinationInfo.h> |
46 |
|
47 |
using namespace std; |
48 |
|
49 |
// |
50 |
// CORE ROUTINE |
51 |
// |
52 |
// |
53 |
int OrbitalInfoCore(UInt_t run, TFile *file, TSQLServer *dbc, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){ |
54 |
// |
55 |
Int_t i = 0; |
56 |
// |
57 |
TString processFolder = Form("OrbitalInfoFolder_%u",run); |
58 |
// |
59 |
// Set these to true to have a very verbose output. |
60 |
// |
61 |
Bool_t debug = false; |
62 |
// |
63 |
Bool_t verbose = false; |
64 |
|
65 |
if ( OrbitalInfoargc > 0 ){ |
66 |
i = 0; |
67 |
while ( i < OrbitalInfoargc ){ |
68 |
if ( !strcmp(OrbitalInfoargv[i],"-processFolder") ) { |
69 |
if ( OrbitalInfoargc < i+1 ){ |
70 |
throw -3; |
71 |
}; |
72 |
processFolder = (TString)OrbitalInfoargv[i+1]; |
73 |
i++; |
74 |
}; |
75 |
if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) { |
76 |
verbose = true; |
77 |
debug = true; |
78 |
}; |
79 |
if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) { |
80 |
verbose = true; |
81 |
}; |
82 |
i++; |
83 |
}; |
84 |
}; |
85 |
// |
86 |
const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath())); |
87 |
// |
88 |
TTree *OrbitalInfotr = 0; |
89 |
UInt_t nevents = 0; |
90 |
UInt_t neventsm = 0; |
91 |
// |
92 |
// variables needed to reprocess data |
93 |
// |
94 |
Long64_t maxsize = 10000000000LL; |
95 |
TTree::SetMaxTreeSize(maxsize); |
96 |
// |
97 |
TString OrbitalInfoversion; |
98 |
ItoRunInfo *runinfo = 0; |
99 |
TArrayI *runlist = 0; |
100 |
TTree *OrbitalInfotrclone = 0; |
101 |
Bool_t reproc = false; |
102 |
Bool_t reprocall = false; |
103 |
UInt_t nobefrun = 0; |
104 |
UInt_t noaftrun = 0; |
105 |
UInt_t numbofrun = 0; |
106 |
stringstream ftmpname; |
107 |
TString fname; |
108 |
UInt_t totfileentries = 0; |
109 |
UInt_t idRun = 0; |
110 |
// |
111 |
// My variables. Vitaly. |
112 |
// |
113 |
// UInt_t iev = 0; |
114 |
// UInt_t j3 = 0; |
115 |
UInt_t oi = 0; |
116 |
Int_t tmpSize = 0; |
117 |
// |
118 |
// variables needed to handle error signals |
119 |
// |
120 |
Int_t code = 0; |
121 |
Int_t sgnl; |
122 |
// |
123 |
// OrbitalInfo classes |
124 |
// |
125 |
OrbitalInfo *orbitalinfo = new OrbitalInfo(); |
126 |
OrbitalInfo *orbitalinfoclone = new OrbitalInfo(); |
127 |
// |
128 |
// define variables for opening and reading level0 file |
129 |
// |
130 |
TFile *l0File = 0; |
131 |
TTree *l0tr = 0; |
132 |
TTree *l0trm = 0; |
133 |
// EM: open also header branch |
134 |
TBranch *l0head = 0; |
135 |
pamela::EventHeader *eh = 0; |
136 |
pamela::PscuHeader *ph = 0; |
137 |
pamela::McmdEvent *mcmdev = 0; |
138 |
pamela::McmdRecord *mcmdrc = 0; |
139 |
// end EM |
140 |
|
141 |
// pamela::RunHeaderEvent *reh = new pamela::RunHeaderEvent; |
142 |
// pamela::EventHeader *eH = new pamela::EventHeader; |
143 |
|
144 |
// |
145 |
// Define other basic variables |
146 |
// |
147 |
UInt_t procev = 0; |
148 |
stringstream file2; |
149 |
stringstream file3; |
150 |
stringstream qy; |
151 |
Int_t totevent = 0; |
152 |
UInt_t atime = 0; |
153 |
UInt_t re = 0; |
154 |
UInt_t ik = 0; |
155 |
|
156 |
// Position |
157 |
Float_t lon, lat, alt; |
158 |
|
159 |
// |
160 |
// IGRF stuff |
161 |
// |
162 |
float dimo = 0.0; // dipole moment (computed from dat files) |
163 |
float bnorth, beast, bdown, babs; |
164 |
float xl; // L value |
165 |
float icode; // code value for L accuracy (see fortran code) |
166 |
float bab1; // What's the difference with babs? |
167 |
float stps = 0.005; // step size for field line tracing |
168 |
float bdel = 0.01; // required accuracy |
169 |
float bequ; // equatorial b value (also called b_0) |
170 |
bool value = 0; // false if bequ is not the minimum b value |
171 |
float rr0; // equatorial radius normalized to earth radius |
172 |
|
173 |
// |
174 |
// Working filename |
175 |
// |
176 |
TString outputfile; |
177 |
stringstream name; |
178 |
name.str(""); |
179 |
name << outDir << "/"; |
180 |
// |
181 |
// temporary file and folder |
182 |
// |
183 |
TFile *tempfile = 0; |
184 |
TTree *tempOrbitalInfo = 0; |
185 |
stringstream tempname; |
186 |
stringstream OrbitalInfofolder; |
187 |
tempname.str(""); |
188 |
tempname << outDir; |
189 |
tempname << "/" << processFolder.Data(); |
190 |
OrbitalInfofolder.str(""); |
191 |
OrbitalInfofolder << tempname.str().c_str(); |
192 |
gSystem->MakeDirectory(OrbitalInfofolder.str().c_str()); |
193 |
tempname << "/OrbitalInfotree_run"; |
194 |
tempname << run << ".root"; |
195 |
// |
196 |
// DB classes |
197 |
// |
198 |
GL_ROOT *glroot = new GL_ROOT(); |
199 |
GL_TIMESYNC *dbtime = 0; |
200 |
GL_TLE *gltle = new GL_TLE(); |
201 |
// |
202 |
//Quaternions classes |
203 |
// |
204 |
Quaternions *L_QQ_Q_l_lower = new Quaternions(); |
205 |
InclinationInfo *RYPang_lower = new InclinationInfo(); |
206 |
Quaternions *L_QQ_Q_l_upper = new Quaternions(); |
207 |
InclinationInfo *RYPang_upper = new InclinationInfo(); |
208 |
|
209 |
cEci eCi; |
210 |
|
211 |
// Initialize fortran routines!!! |
212 |
Int_t ltp2 = 0; |
213 |
Int_t ltp3 = 0; |
214 |
Int_t uno = 1; |
215 |
char *niente = " "; |
216 |
GL_PARAM *glparam = new GL_PARAM(); |
217 |
GL_PARAM *glparam2 = new GL_PARAM(); |
218 |
Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table |
219 |
|
220 |
if ( parerror<0 ) { |
221 |
code = parerror; |
222 |
goto closeandexit; |
223 |
}; |
224 |
ltp2 = (Int_t)(glparam->PATH+glparam->NAME).Length(); |
225 |
if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data()); |
226 |
// |
227 |
parerror=glparam2->Query_GL_PARAM(1,302,dbc); // parameters stored in DB in GL_PRAM table |
228 |
if ( parerror<0 ) { |
229 |
code = parerror; |
230 |
goto closeandexit; |
231 |
}; |
232 |
ltp3 = (Int_t)(glparam2->PATH+glparam2->NAME).Length(); |
233 |
if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data()); |
234 |
// |
235 |
initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),<p2,(char *)(glparam2->PATH+glparam2->NAME).Data(),<p3); |
236 |
// |
237 |
// End IGRF stuff// |
238 |
// |
239 |
|
240 |
// |
241 |
// Let's start! |
242 |
// |
243 |
// As a first thing we must check what we have to do: if run = 0 we must process all events in the file has been passed |
244 |
// if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file |
245 |
// if it exists we are reprocessing data and we must delete that entries, if not we must create it. |
246 |
// |
247 |
if ( run == 0 ) reproc = true; |
248 |
// |
249 |
// |
250 |
// Output file is "outputfile" |
251 |
// |
252 |
if ( !file->IsOpen() ){ |
253 |
//printf(" OrbitalInfo - ERROR: cannot open file for writing\n"); |
254 |
throw -901; |
255 |
}; |
256 |
// |
257 |
// Retrieve GL_RUN variables from the level2 file |
258 |
// |
259 |
OrbitalInfoversion = OrbitalInfoInfo(false); // we should decide how to handle versioning system |
260 |
// |
261 |
// create an interface to RunInfo called "runinfo" |
262 |
// |
263 |
runinfo = new ItoRunInfo(file); |
264 |
// |
265 |
// open "Run" tree in level2 file, if not existing return an error (sngl != 0) |
266 |
// |
267 |
sgnl = 0; |
268 |
sgnl = runinfo->Update(run, "ORB", OrbitalInfoversion); |
269 |
//sgnl = runinfo->Read(run); |
270 |
|
271 |
if ( sgnl ){ |
272 |
//printf("OrbitalInfo - ERROR: RunInfo exited with non-zero status\n"); |
273 |
code = sgnl; |
274 |
goto closeandexit; |
275 |
} else { |
276 |
sgnl = 0; |
277 |
}; |
278 |
// |
279 |
// number of events in the file BEFORE the first event of our run |
280 |
// |
281 |
nobefrun = runinfo->GetFirstEntry(); |
282 |
// |
283 |
// total number of events in the file |
284 |
// |
285 |
totfileentries = runinfo->GetFileEntries(); |
286 |
// |
287 |
// first file entry AFTER the last event of our run |
288 |
// |
289 |
noaftrun = runinfo->GetLastEntry() + 1; |
290 |
// |
291 |
// number of run to be processed |
292 |
// |
293 |
numbofrun = runinfo->GetNoRun(); |
294 |
// |
295 |
// Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run |
296 |
// |
297 |
OrbitalInfotrclone = (TTree*)file->Get("OrbitalInfo"); |
298 |
// |
299 |
if ( !OrbitalInfotrclone ){ |
300 |
// |
301 |
// tree does not exist, we are not reprocessing |
302 |
// |
303 |
reproc = false; |
304 |
if ( run == 0 ){ |
305 |
if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n"); |
306 |
} |
307 |
if ( runinfo->IsReprocessing() && run != 0 ) { |
308 |
if (verbose) printf(" OrbitalInfo - WARNING: it seems you are not reprocessing data but OrbitalInfo\n versioning information already exists in RunInfo.\n"); |
309 |
} |
310 |
} else { |
311 |
// |
312 |
// tree exists, we are reprocessing data. Are we reprocessing a single run or all the file? |
313 |
// |
314 |
OrbitalInfotrclone->SetAutoSave(900000000000000LL); |
315 |
reproc = true; |
316 |
// |
317 |
// |
318 |
if (verbose) printf("\n Preparing the pre-processing...\n"); |
319 |
// |
320 |
if ( run == 0 ){ |
321 |
// |
322 |
// we are reprocessing all the file |
323 |
// if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately |
324 |
// |
325 |
reprocall = true; |
326 |
// |
327 |
if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n"); |
328 |
// |
329 |
} else { |
330 |
// |
331 |
// we are reprocessing a single run, we must copy to the new tree the events in the file which preceed the first event of the run |
332 |
// |
333 |
reprocall = false; |
334 |
// |
335 |
if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %u \n",run); |
336 |
// |
337 |
// copying old tree to a new file |
338 |
// |
339 |
tempfile = new TFile(tempname.str().c_str(),"RECREATE"); |
340 |
tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast"); |
341 |
tempOrbitalInfo->SetName("OrbitalInfo-old"); |
342 |
tempfile->Write(); |
343 |
tempfile->Close(); |
344 |
} |
345 |
// |
346 |
// Delete the old tree from old file and memory |
347 |
// |
348 |
OrbitalInfotrclone->Delete("all"); |
349 |
// |
350 |
if (verbose) printf(" ...done!\n"); |
351 |
// |
352 |
}; |
353 |
// |
354 |
// create mydetector tree mydect |
355 |
// |
356 |
file->cd(); |
357 |
OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data"); |
358 |
OrbitalInfotr->SetAutoSave(900000000000000LL); |
359 |
OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo); |
360 |
// |
361 |
if ( reproc && !reprocall ){ |
362 |
// |
363 |
// open new file and retrieve also tree informations |
364 |
// |
365 |
tempfile = new TFile(tempname.str().c_str(),"READ"); |
366 |
OrbitalInfotrclone = (TTree*)tempfile->Get("OrbitalInfo-old"); |
367 |
OrbitalInfotrclone->SetAutoSave(900000000000000LL); |
368 |
OrbitalInfotrclone->SetBranchAddress("OrbitalInfo",&orbitalinfoclone); |
369 |
// |
370 |
if ( nobefrun > 0 ){ |
371 |
if (verbose){ |
372 |
printf("\n Pre-processing: copying events from the old tree before the processed run\n"); |
373 |
printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run); |
374 |
printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun); |
375 |
} |
376 |
for (UInt_t j = 0; j < nobefrun; j++){ |
377 |
// |
378 |
OrbitalInfotrclone->GetEntry(j); |
379 |
// |
380 |
// copy orbitalinfoclone to mydec |
381 |
// |
382 |
orbitalinfo->Clear(); |
383 |
// |
384 |
memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone)); |
385 |
// |
386 |
// Fill entry in the new tree |
387 |
// |
388 |
OrbitalInfotr->Fill(); |
389 |
// |
390 |
}; |
391 |
if (verbose) printf(" Finished successful copying!\n"); |
392 |
}; |
393 |
}; |
394 |
// |
395 |
// Get the list of run to be processed, if only one run has to be processed the list will contain one entry only. |
396 |
// |
397 |
runlist = runinfo->GetRunList(); |
398 |
// |
399 |
// Loop over the run to be processed |
400 |
// |
401 |
|
402 |
for (UInt_t irun=0; irun < numbofrun; irun++){ |
403 |
// |
404 |
// retrieve the first run ID to be processed using the RunInfo list |
405 |
// |
406 |
|
407 |
idRun = runlist->At(irun); |
408 |
if (verbose){ |
409 |
printf("\n\n\n ####################################################################### \n"); |
410 |
printf(" PROCESSING RUN NUMBER %i \n",(int)idRun); |
411 |
printf(" ####################################################################### \n\n\n"); |
412 |
} |
413 |
// |
414 |
runinfo->ID_ROOT_L0 = 0; |
415 |
// |
416 |
// store in the runinfo class the GL_RUN variables for our run |
417 |
// |
418 |
sgnl = 0; |
419 |
sgnl = runinfo->GetRunInfo(idRun); |
420 |
if ( sgnl ){ |
421 |
if ( debug ) printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n"); |
422 |
code = sgnl; |
423 |
goto closeandexit; |
424 |
} else { |
425 |
sgnl = 0; |
426 |
}; |
427 |
// |
428 |
// now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN |
429 |
// |
430 |
if ( runinfo->ID_ROOT_L0 == 0 ){ |
431 |
if ( debug ) printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun); |
432 |
code = -5; |
433 |
goto closeandexit; |
434 |
}; |
435 |
// |
436 |
// prepare the timesync for the db |
437 |
// |
438 |
dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc); |
439 |
|
440 |
// |
441 |
// Search in the DB the path and name of the LEVEL0 file to be processed. |
442 |
// |
443 |
glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc); |
444 |
// |
445 |
ftmpname.str(""); |
446 |
ftmpname << glroot->PATH.Data() << "/"; |
447 |
ftmpname << glroot->NAME.Data(); |
448 |
fname = ftmpname.str().c_str(); |
449 |
ftmpname.str(""); |
450 |
// |
451 |
// print out informations |
452 |
// |
453 |
totevent = runinfo->NEVENTS; |
454 |
//cout<<"totevents = "<<totevent<<"\n"; |
455 |
if (verbose){ |
456 |
printf("\n LEVEL0 data file: %s \n",fname.Data()); |
457 |
printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME); |
458 |
printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME); |
459 |
printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM+1,runinfo->EV_FROM+totevent); |
460 |
}// |
461 |
// Open Level0 file |
462 |
l0File = new TFile(fname.Data()); |
463 |
if ( !l0File ) { |
464 |
if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n"); |
465 |
code = -6; |
466 |
goto closeandexit; |
467 |
}; |
468 |
l0tr = (TTree*)l0File->Get("Physics"); |
469 |
if ( !l0tr ) { |
470 |
if ( debug ) printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n"); |
471 |
l0File->Close(); |
472 |
code = -7; |
473 |
goto closeandexit; |
474 |
}; |
475 |
// EM: open header branch as well |
476 |
l0head = l0tr->GetBranch("Header"); |
477 |
if ( !l0head ) { |
478 |
if ( debug ) printf(" OrbitalInfo - ERROR: no Header branch in Level0 tree\n"); |
479 |
l0File->Close(); |
480 |
code = -8; |
481 |
goto closeandexit; |
482 |
}; |
483 |
l0tr->SetBranchAddress("Header", &eh); |
484 |
// end EM |
485 |
nevents = l0head->GetEntries(); |
486 |
// |
487 |
if ( nevents < 1 ) { |
488 |
if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n"); |
489 |
l0File->Close(); |
490 |
code = -11; |
491 |
goto closeandexit; |
492 |
}; |
493 |
// |
494 |
if ( runinfo->EV_TO > nevents-1 ) { |
495 |
if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n"); |
496 |
l0File->Close(); |
497 |
code = -12; |
498 |
goto closeandexit; |
499 |
}; |
500 |
// |
501 |
// TTree *tp = (TTree*)l0File->Get("RunHeader"); |
502 |
// tp->SetBranchAddress("Header", &eH); |
503 |
// tp->SetBranchAddress("RunHeader", &reh); |
504 |
// tp->GetEntry(0); |
505 |
// ph = eH->GetPscuHeader(); |
506 |
// ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO; |
507 |
// ULong_t ObtSync = reh->OBT_TIME_SYNC; |
508 |
// if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync); |
509 |
// |
510 |
ULong_t TimeSync = (ULong_t)dbtime->GetTimesync(); |
511 |
ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000); |
512 |
ULong_t DeltaOBT = TimeSync - ObtSync; |
513 |
|
514 |
if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync); |
515 |
|
516 |
l0trm = (TTree*)l0File->Get("Mcmd"); |
517 |
neventsm = l0trm->GetEntries(); |
518 |
// |
519 |
if (neventsm == 0){ |
520 |
if ( debug ) printf("InclinationInfo - ERROR: No quaternions in this File"); |
521 |
l0File->Close(); |
522 |
code = -13; |
523 |
goto closeandexit; |
524 |
} |
525 |
// |
526 |
|
527 |
l0trm->SetBranchAddress("Mcmd", &mcmdev); |
528 |
l0trm->SetBranchAddress("Header", &eh); |
529 |
// |
530 |
// |
531 |
// |
532 |
UInt_t mctren = 0; |
533 |
UInt_t mcreen = 0; |
534 |
UInt_t numrec = 0; |
535 |
// |
536 |
Double_t upperqtime = 0; |
537 |
Double_t lowerqtime = 0; |
538 |
|
539 |
Double_t incli = 0; |
540 |
oi = 0; |
541 |
UInt_t ooi = 0; |
542 |
// |
543 |
// init quaternions sync |
544 |
// |
545 |
Bool_t isf = true; |
546 |
Int_t fgh = 0; |
547 |
// |
548 |
// run over all the events of the run |
549 |
// |
550 |
if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n"); |
551 |
// |
552 |
for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){ |
553 |
|
554 |
// |
555 |
if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000); |
556 |
if ( debug ) printf(" %i \n",procev); |
557 |
// |
558 |
l0head->GetEntry(re); |
559 |
// |
560 |
// absolute time of this event |
561 |
// |
562 |
ph = eh->GetPscuHeader(); |
563 |
atime = dbtime->DBabsTime(ph->GetOrbitalTime()); |
564 |
// |
565 |
// paranoid check |
566 |
// |
567 |
if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME) ) { |
568 |
if (verbose) printf(" OrbitalInfo - WARNING: event at time outside the run time window, skipping it\n"); |
569 |
debug = true; |
570 |
continue; |
571 |
} |
572 |
// |
573 |
procev++; |
574 |
// |
575 |
// start processing |
576 |
// |
577 |
orbitalinfo->Clear(); |
578 |
// |
579 |
// Fill OBT, pkt_num and absTime |
580 |
// |
581 |
ph = eh->GetPscuHeader(); |
582 |
orbitalinfo->pkt_num = ph->GetCounter(); |
583 |
orbitalinfo->OBT = ph->GetOrbitalTime(); |
584 |
orbitalinfo->absTime = atime; |
585 |
// |
586 |
// Propagate the orbit from the tle time to atime, using SGP(D)4. |
587 |
// |
588 |
cCoordGeo coo; |
589 |
float jyear=0; |
590 |
// |
591 |
if(atime >= gltle->GetToTime()) { |
592 |
if ( !gltle->Query(atime, dbc) ){ |
593 |
// |
594 |
// Compute the magnetic dipole moment. |
595 |
// |
596 |
UInt_t year, month, day, hour, min, sec; |
597 |
// |
598 |
TTimeStamp t = TTimeStamp(atime, kTRUE); |
599 |
t.GetDate(kTRUE, 0, &year, &month, &day); |
600 |
t.GetTime(kTRUE, 0, &hour, &min, &sec); |
601 |
jyear = (float) year |
602 |
+ (month*31.+ (float) day)/365. |
603 |
+ (hour*3600.+min*60.+(float)sec)/(24*3600*365.); |
604 |
// |
605 |
feldcof_(&jyear, &dimo); // get dipole moment for year |
606 |
} else { |
607 |
code = -56; |
608 |
goto closeandexit; |
609 |
}; |
610 |
} |
611 |
coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle()); |
612 |
// |
613 |
cOrbit orbits(*gltle->GetTle()); |
614 |
// |
615 |
// synchronize with quaternions data |
616 |
// |
617 |
if ( isf ){ |
618 |
// |
619 |
// First event |
620 |
// |
621 |
isf = false; |
622 |
upperqtime = atime; |
623 |
lowerqtime = runinfo->RUNHEADER_TIME; |
624 |
for ( ik = 0; ik < neventsm; ik++){ |
625 |
l0trm->GetEntry(ik); |
626 |
tmpSize = mcmdev->Records->GetEntries(); |
627 |
numrec = tmpSize; |
628 |
for (Int_t j3 = 0;j3<tmpSize;j3++){ |
629 |
mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3); |
630 |
if ((int)mcmdrc->ID1 == 226){ |
631 |
L_QQ_Q_l_upper->fill(mcmdrc->McmdData); |
632 |
for (UInt_t ui = 0; ui < 6; ui++){ |
633 |
if (ui>0){ |
634 |
if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){ |
635 |
if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){ |
636 |
upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000)); |
637 |
orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi); |
638 |
RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[ui][0],L_QQ_Q_l_upper->quat[ui][1],L_QQ_Q_l_upper->quat[ui][2],L_QQ_Q_l_upper->quat[ui][3]); |
639 |
}else { |
640 |
lowerqtime = upperqtime; |
641 |
upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000)); |
642 |
orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi); |
643 |
RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[ui][0],L_QQ_Q_l_upper->quat[ui][1],L_QQ_Q_l_upper->quat[ui][2],L_QQ_Q_l_upper->quat[ui][3]); |
644 |
mcreen = j3; |
645 |
mctren = ik; |
646 |
if(fgh==0){ |
647 |
CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper); |
648 |
CopyAng(RYPang_lower,RYPang_upper); |
649 |
} |
650 |
oi=ui; |
651 |
goto closethisloop; |
652 |
} |
653 |
fgh++; |
654 |
CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper); |
655 |
CopyAng(RYPang_lower,RYPang_upper); |
656 |
} |
657 |
}else{ |
658 |
if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){ |
659 |
upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
660 |
orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi); |
661 |
RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[0][0],L_QQ_Q_l_upper->quat[0][1],L_QQ_Q_l_upper->quat[0][2],L_QQ_Q_l_upper->quat[0][3]); |
662 |
} |
663 |
else { |
664 |
lowerqtime = upperqtime; |
665 |
upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
666 |
orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi); |
667 |
RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[0][0],L_QQ_Q_l_upper->quat[0][1],L_QQ_Q_l_upper->quat[0][2],L_QQ_Q_l_upper->quat[0][3]); |
668 |
mcreen = j3; |
669 |
mctren = ik; |
670 |
if(fgh==0){ |
671 |
CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper); |
672 |
CopyAng(RYPang_lower,RYPang_upper); |
673 |
lowerqtime = atime-1; |
674 |
} |
675 |
oi=ui; |
676 |
goto closethisloop; |
677 |
//_0 = true; |
678 |
} |
679 |
fgh++; |
680 |
CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper); |
681 |
CopyAng(RYPang_lower,RYPang_upper); |
682 |
//_0 = true; |
683 |
}; |
684 |
//cin>>grib; |
685 |
}; |
686 |
}; |
687 |
}; |
688 |
}; |
689 |
}; |
690 |
closethisloop: |
691 |
// |
692 |
if ((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)){ |
693 |
// |
694 |
lowerqtime = upperqtime; |
695 |
UInt_t maxloop = 100000000; |
696 |
UInt_t mn = 0; |
697 |
bool gh=false; |
698 |
ooi=oi; |
699 |
if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime); |
700 |
while (!gh){ |
701 |
if ( mn > maxloop ){ |
702 |
if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n"); |
703 |
gh = true; |
704 |
}; |
705 |
mn++; |
706 |
if (oi<5) oi++; |
707 |
else oi=0; |
708 |
if (oi==0){ |
709 |
mcreen++; |
710 |
if (mcreen == numrec){ |
711 |
mctren++; |
712 |
mcreen = 0; |
713 |
l0trm->GetEntry(mctren); |
714 |
numrec = mcmdev->Records->GetEntries(); |
715 |
} |
716 |
CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper); |
717 |
CopyAng(RYPang_lower,RYPang_upper); |
718 |
mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen); |
719 |
if ((int)mcmdrc->ID1 == 226){ |
720 |
L_QQ_Q_l_upper->fill(mcmdrc->McmdData); |
721 |
upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
722 |
if (upperqtime<lowerqtime){ |
723 |
upperqtime=runinfo->RUNTRAILER_TIME; |
724 |
CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower); |
725 |
CopyAng(RYPang_upper,RYPang_lower); |
726 |
}else{ |
727 |
orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi); |
728 |
RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[0][0],L_QQ_Q_l_upper->quat[0][1],L_QQ_Q_l_upper->quat[0][2],L_QQ_Q_l_upper->quat[0][3]); |
729 |
} |
730 |
// re--; |
731 |
gh=true; |
732 |
} |
733 |
}else{ |
734 |
if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){ |
735 |
upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
736 |
orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi); |
737 |
RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[oi][0],L_QQ_Q_l_upper->quat[oi][1],L_QQ_Q_l_upper->quat[oi][2],L_QQ_Q_l_upper->quat[oi][3]); |
738 |
orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi); |
739 |
RYPang_lower->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[oi-1][0],L_QQ_Q_l_upper->quat[oi-1][1],L_QQ_Q_l_upper->quat[oi-1][2],L_QQ_Q_l_upper->quat[oi-1][3]); |
740 |
// re--; |
741 |
gh=true; |
742 |
}; |
743 |
}; |
744 |
}; |
745 |
if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data now we have upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime); |
746 |
}; |
747 |
// |
748 |
// Fill in quaternions and angles |
749 |
// |
750 |
if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)){ |
751 |
UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi); |
752 |
if (oi == 0){ |
753 |
if ((tut!=5)||(tut!=6)){ |
754 |
incli = (L_QQ_Q_l_upper->quat[0][0]-L_QQ_Q_l_lower->quat[ooi][0])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
755 |
orbitalinfo->q0 = incli*atime+L_QQ_Q_l_upper->quat[0][0]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
756 |
incli = (L_QQ_Q_l_upper->quat[0][1]-L_QQ_Q_l_lower->quat[ooi][1])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
757 |
orbitalinfo->q1 = incli*atime+L_QQ_Q_l_upper->quat[0][1]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
758 |
incli = (L_QQ_Q_l_upper->quat[0][2]-L_QQ_Q_l_lower->quat[ooi][2])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
759 |
orbitalinfo->q2 = incli*atime+L_QQ_Q_l_upper->quat[0][2]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
760 |
incli = (L_QQ_Q_l_upper->quat[0][3]-L_QQ_Q_l_lower->quat[ooi][3])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
761 |
orbitalinfo->q3 = incli*atime+L_QQ_Q_l_upper->quat[0][3]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
762 |
|
763 |
incli = (RYPang_upper->Tangazh-RYPang_lower->Tangazh)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
764 |
orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
765 |
incli = (RYPang_upper->Ryskanie-RYPang_lower->Ryskanie)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
766 |
orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
767 |
incli = (RYPang_upper->Kren-RYPang_lower->Kren)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000))); |
768 |
orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
769 |
} |
770 |
if (tut==6){ |
771 |
if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){ |
772 |
incli = (L_QQ_Q_l_upper->quat[0][0]-L_QQ_Q_l_lower->quat[ooi][0])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
773 |
orbitalinfo->q0 = incli*atime+L_QQ_Q_l_upper->quat[0][0]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
774 |
incli = (L_QQ_Q_l_upper->quat[0][1]-L_QQ_Q_l_lower->quat[ooi][1])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
775 |
orbitalinfo->q1 = incli*atime+L_QQ_Q_l_upper->quat[0][1]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
776 |
incli = (L_QQ_Q_l_upper->quat[0][2]-L_QQ_Q_l_lower->quat[ooi][2])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
777 |
orbitalinfo->q2 = incli*atime+L_QQ_Q_l_upper->quat[0][2]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
778 |
incli = (L_QQ_Q_l_upper->quat[0][3]-L_QQ_Q_l_lower->quat[ooi][3])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
779 |
orbitalinfo->q3 = incli*atime+L_QQ_Q_l_upper->quat[0][3]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
780 |
|
781 |
incli = (RYPang_upper->Tangazh-RYPang_lower->Tangazh)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
782 |
orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
783 |
incli = (RYPang_upper->Ryskanie-RYPang_lower->Ryskanie)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
784 |
orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
785 |
//cout<<"upper = "<<RYPang_upper->Ryskanie<<" lower = "<<RYPang_lower->Ryskanie<<" timeupper[0] = "<<L_QQ_Q_l_upper->time[0]-5500000<<" timelower["<<ooi<<"] = "<<L_QQ_Q_l_lower->time[ooi]-5500000<<" Ryscanie = "<<orbitalinfo->phi<<" incli = "<<incli<<" upper-lower = "<<RYPang_upper->Ryskanie-RYPang_lower->Ryskanie<<" Dtime = "<<dbtime->DBabsTime((UInt_t)L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)<<"-"<<dbtime->DBabsTime((UInt_t)L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000)<<" atime = "<<atime<<"\n"; |
786 |
//cin>>grib; |
787 |
incli = (RYPang_upper->Kren-RYPang_lower->Kren)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_lower->time[ooi]*1000-DeltaOBT*1000))); |
788 |
orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000)); |
789 |
} |
790 |
} |
791 |
} else { |
792 |
if((tut!=6)||(tut!=7)||(tut!=9)){ |
793 |
incli = (L_QQ_Q_l_upper->quat[oi][0]-L_QQ_Q_l_upper->quat[oi-1][0])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
794 |
orbitalinfo->q0 = incli*atime+L_QQ_Q_l_upper->quat[oi][0]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
795 |
incli = (L_QQ_Q_l_upper->quat[oi][1]-L_QQ_Q_l_upper->quat[oi-1][1])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
796 |
orbitalinfo->q1 = incli*atime+L_QQ_Q_l_upper->quat[oi][1]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
797 |
incli = (L_QQ_Q_l_upper->quat[oi][2]-L_QQ_Q_l_upper->quat[oi-1][2])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
798 |
orbitalinfo->q2 = incli*atime+L_QQ_Q_l_upper->quat[oi][2]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
799 |
incli = (L_QQ_Q_l_upper->quat[oi][3]-L_QQ_Q_l_upper->quat[oi-1][3])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
800 |
orbitalinfo->q3 = incli*atime+L_QQ_Q_l_upper->quat[oi][3]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
801 |
|
802 |
incli = (RYPang_upper->Tangazh-RYPang_lower->Tangazh)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
803 |
orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
804 |
incli = (RYPang_upper->Ryskanie-RYPang_lower->Ryskanie)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
805 |
orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
806 |
//cout<<"upper = "<<RYPang_upper->Ryskanie<<" lower = "<<RYPang_lower->Ryskanie<<" timeupper["<<oi<<"] = "<<L_QQ_Q_l_upper->time[oi]-5500000<<" timelower["<<oi-1<<"] = "<<L_QQ_Q_l_lower->time[oi-1]-5500000<<" Ryscanie = "<<orbitalinfo->phi<<" incli = "<<incli<<" upper-lower = "<<RYPang_upper->Ryskanie-RYPang_lower->Ryskanie<<" Dtime = "<<dbtime->DBabsTime((UInt_t)L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)<<"-"<<dbtime->DBabsTime((UInt_t)L_QQ_Q_l_lower->time[oi-1]*1000-DeltaOBT*1000)<<" atime = "<<atime<<"\n"; |
807 |
//cin>>grib; |
808 |
incli = (RYPang_upper->Kren-RYPang_lower->Kren)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
809 |
orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
810 |
} |
811 |
if (tut==6){ |
812 |
if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){ |
813 |
incli = (L_QQ_Q_l_upper->quat[oi][0]-L_QQ_Q_l_upper->quat[oi-1][0])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
814 |
orbitalinfo->q0 = incli*atime+L_QQ_Q_l_upper->quat[oi][0]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
815 |
incli = (L_QQ_Q_l_upper->quat[oi][1]-L_QQ_Q_l_upper->quat[oi-1][1])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
816 |
orbitalinfo->q1 = incli*atime+L_QQ_Q_l_upper->quat[oi][1]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
817 |
incli = (L_QQ_Q_l_upper->quat[oi][2]-L_QQ_Q_l_upper->quat[oi-1][2])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
818 |
orbitalinfo->q2 = incli*atime+L_QQ_Q_l_upper->quat[oi][2]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
819 |
incli = (L_QQ_Q_l_upper->quat[oi][3]-L_QQ_Q_l_upper->quat[oi-1][3])/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
820 |
orbitalinfo->q3 = incli*atime+L_QQ_Q_l_upper->quat[oi][3]-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
821 |
|
822 |
incli = (RYPang_upper->Tangazh-RYPang_lower->Tangazh)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
823 |
orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
824 |
incli = (RYPang_upper->Ryskanie-RYPang_lower->Ryskanie)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
825 |
orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
826 |
//cout<<"upper = "<<RYPang_upper->Ryskanie<<" lower = "<<RYPang_lower->Ryskanie<<" timeupper["<<oi<<"] = "<<L_QQ_Q_l_upper->time[oi]-5500000<<" timelower["<<oi-1<<"] = "<<L_QQ_Q_l_lower->time[oi-1]-5500000<<" Ryscanie = "<<orbitalinfo->phi<<" incli = "<<incli<<" upper-lower = "<<RYPang_upper->Ryskanie-RYPang_lower->Ryskanie<<" Dtime = "<<dbtime->DBabsTime((UInt_t)L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)<<"-"<<dbtime->DBabsTime((UInt_t)L_QQ_Q_l_lower->time[oi-1]*1000-DeltaOBT*1000)<<" atime = "<<atime<<"\n"; |
827 |
//cin>>grib; |
828 |
incli = (RYPang_upper->Kren-RYPang_lower->Kren)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000))); |
829 |
orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000)); |
830 |
} |
831 |
} |
832 |
} |
833 |
orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi); |
834 |
|
835 |
} else { |
836 |
orbitalinfo->mode = -1; |
837 |
}; |
838 |
|
839 |
// |
840 |
// fill orbital positions |
841 |
// |
842 |
// Build coordinates in the right range. We want to convert, |
843 |
// longitude from (0, 2*pi) to (-180deg, 180deg). Altitude is |
844 |
// in meters. |
845 |
lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon); |
846 |
lat = rad2deg(coo.m_Lat); |
847 |
alt = coo.m_Alt; |
848 |
// |
849 |
if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){ |
850 |
// |
851 |
orbitalinfo->lon = lon; |
852 |
orbitalinfo->lat = lat; |
853 |
orbitalinfo->alt = alt ; |
854 |
// |
855 |
// compute mag field components and L shell. |
856 |
// |
857 |
feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs); |
858 |
shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1); |
859 |
findb0_(&stps, &bdel, &value, &bequ, &rr0); |
860 |
// |
861 |
orbitalinfo->Bnorth = bnorth; |
862 |
orbitalinfo->Beast = beast; |
863 |
orbitalinfo->Bdown = bdown; |
864 |
orbitalinfo->Babs = babs; |
865 |
orbitalinfo->BB0 = babs/bequ; |
866 |
orbitalinfo->L = xl; |
867 |
// Set Stormer vertical cutoff using L shell. |
868 |
orbitalinfo->cutoff[0] = 14.9/(xl*xl); |
869 |
// |
870 |
}; |
871 |
// |
872 |
// Fill the class |
873 |
// |
874 |
OrbitalInfotr->Fill(); |
875 |
// |
876 |
}; // loop over the events in the run |
877 |
// |
878 |
// Here you may want to clear some variables before processing another run |
879 |
// |
880 |
delete dbtime; |
881 |
delete L_QQ_Q_l_upper; |
882 |
delete L_QQ_Q_l_lower; |
883 |
delete RYPang_upper; |
884 |
delete RYPang_lower; |
885 |
}; // process all the runs |
886 |
|
887 |
if (verbose) printf("\n Finished processing data \n"); |
888 |
// |
889 |
closeandexit: |
890 |
// |
891 |
// we have finished processing the run(s). If we processed a single run now we must copy all the events after our run from the old tree to the new one and delete the old tree. |
892 |
// |
893 |
if ( !reprocall && reproc && code >= 0 ){ |
894 |
if ( totfileentries > noaftrun ){ |
895 |
if (verbose){ |
896 |
printf("\n Post-processing: copying events from the old tree after the processed run\n"); |
897 |
printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run); |
898 |
printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries); |
899 |
} |
900 |
for (UInt_t j = noaftrun; j < totfileentries; j++ ){ |
901 |
// |
902 |
// Get entry from old tree |
903 |
// |
904 |
OrbitalInfotrclone->GetEntry(j); |
905 |
// |
906 |
// copy orbitalinfoclone to OrbitalInfo |
907 |
// |
908 |
orbitalinfo->Clear(); |
909 |
// |
910 |
memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone)); |
911 |
// |
912 |
// Fill entry in the new tree |
913 |
// |
914 |
OrbitalInfotr->Fill(); |
915 |
}; |
916 |
if (verbose) printf(" Finished successful copying!\n"); |
917 |
}; |
918 |
}; |
919 |
// |
920 |
// Close files, delete old tree(s), write and close level2 file |
921 |
// |
922 |
if ( l0File ) l0File->Close(); |
923 |
if ( tempfile ) tempfile->Close(); |
924 |
gSystem->Unlink(tempname.str().c_str()); |
925 |
// |
926 |
if ( runinfo ) runinfo->Close(); |
927 |
if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo"); |
928 |
if ( file ){ |
929 |
file->cd(); |
930 |
file->Write(); |
931 |
}; |
932 |
// |
933 |
gSystem->Unlink(OrbitalInfofolder.str().c_str()); |
934 |
// |
935 |
// the end |
936 |
// |
937 |
if (verbose) printf("\n Exiting...\n"); |
938 |
if(OrbitalInfotr)OrbitalInfotr->Delete(); |
939 |
// |
940 |
if ( orbitalinfo ) delete orbitalinfo; |
941 |
if ( orbitalinfoclone ) delete orbitalinfoclone; |
942 |
if ( glroot ) delete glroot; |
943 |
if ( runinfo ) delete runinfo; |
944 |
// |
945 |
if(code < 0) throw code; |
946 |
return(code); |
947 |
} |
948 |
|
949 |
|
950 |
// |
951 |
// Returns the cCoordGeo structure holding the geographical |
952 |
// coordinates for the event (see sgp4.h). |
953 |
// |
954 |
// atime is the abstime of the event in UTC unix time. |
955 |
// tletime is the time of the tle in UTC unix time. |
956 |
// tle is the previous and nearest tle (compared to atime). |
957 |
cCoordGeo getCoo(UInt_t atime, UInt_t tletime, cTle *tle) |
958 |
{ |
959 |
cEci eci; |
960 |
cOrbit orbit(*tle); |
961 |
orbit.getPosition((double) (atime - tletime)/60., &eci); |
962 |
|
963 |
return eci.toGeo(); |
964 |
} |
965 |
|
966 |
// function of copyng of quatrnions classes |
967 |
|
968 |
void CopyQ(Quaternions *Q1, Quaternions *Q2){ |
969 |
for(UInt_t i = 0; i < 6; i++){ |
970 |
Q1->time[i]=Q2->time[i]; |
971 |
for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j]; |
972 |
} |
973 |
return; |
974 |
} |
975 |
|
976 |
// functions of copyng InclinationInfo classes |
977 |
|
978 |
void CopyAng(InclinationInfo *A1, InclinationInfo *A2){ |
979 |
A1->Tangazh = A2->Tangazh; |
980 |
A1->Ryskanie = A2->Ryskanie; |
981 |
A1->Kren = A2->Kren; |
982 |
return; |
983 |
} |
984 |
|
985 |
UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){ |
986 |
|
987 |
UInt_t hole = 10; |
988 |
bool R10l = false; // Sign of R10 mode in lower quaternions array |
989 |
bool R10u = false; // Sign of R10 mode in upper quaternions array |
990 |
bool insm = false; // Sign that we inside quaternions array |
991 |
bool mxtml = false; // Sign of mixt mode in lower quaternions array |
992 |
bool mxtmu = false; // Sign of mixt mode in upper quaternions array |
993 |
bool npasm = false; // Sign of normall pass between R10 and non R10 or between non R10 and R10 |
994 |
UInt_t NCQl = 6; // Number of correct quaternions in lower array |
995 |
UInt_t NCQu = 6; // Number of correct quaternions in upper array |
996 |
if (f>0){ |
997 |
insm = true; |
998 |
if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false; |
999 |
if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true; |
1000 |
}else{ |
1001 |
insm = false; |
1002 |
if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true; |
1003 |
if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true; |
1004 |
if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false; |
1005 |
if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false; |
1006 |
if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){ |
1007 |
mxtml = true; |
1008 |
for(UInt_t i = 1; i < 6; i++){ |
1009 |
if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i; |
1010 |
} |
1011 |
} |
1012 |
if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){ |
1013 |
mxtmu = true; |
1014 |
for(UInt_t i = 1; i < 6; i++){ |
1015 |
if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i; |
1016 |
} |
1017 |
} |
1018 |
} |
1019 |
|
1020 |
if(((upper-lower==1.5)||(upper-lower==3.)||(upper-lower==30.)||(upper-lower==31.5)||(upper-lower==33.)||(upper-lower==181.5)||(upper-lower==210.)||(upper-lower==211.5))&&!insm) npasm = true; |
1021 |
|
1022 |
|
1023 |
if (R10u&&insm) hole=0; // best event R10 |
1024 |
if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct |
1025 |
if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10 |
1026 |
if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10 |
1027 |
if ((!npasm)&&(upper-lower<=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 4; // eliminable hole between R10 and non R10 or between non R10 and R10 |
1028 |
if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10 |
1029 |
if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10 |
1030 |
if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10 |
1031 |
if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10 |
1032 |
if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10 |
1033 |
return hole; |
1034 |
} |
1035 |
|