/[PAMELA software]/DarthVader/OrbitalInfo/src/OrbitalInfoCore.cpp
ViewVC logotype

Annotation of /DarthVader/OrbitalInfo/src/OrbitalInfoCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.26 - (hide annotations) (download)
Thu Nov 15 15:16:26 2007 UTC (17 years, 3 months ago) by mocchiut
Branch: MAIN
CVS Tags: v5r00
Changes since 1.25: +5 -0 lines
OrbitalInfo bug in setting the time zone fixed

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

  ViewVC Help
Powered by ViewVC 1.1.23