/[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.29 - (hide annotations) (download)
Thu Sep 25 12:28:08 2008 UTC (16 years, 5 months ago) by mocchiut
Branch: MAIN
Changes since 1.28: +3 -1 lines
OrbitalInfo crashing on some runs, 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 mocchiut 1.27 //
473 mocchiut 1.28 // if ( !totevent ) goto closeandexit;
474 mocchiut 1.1 // Open Level0 file
475     l0File = new TFile(fname.Data());
476     if ( !l0File ) {
477 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");
478 mocchiut 1.1 code = -6;
479     goto closeandexit;
480     };
481     l0tr = (TTree*)l0File->Get("Physics");
482     if ( !l0tr ) {
483 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n");
484 mocchiut 1.1 l0File->Close();
485     code = -7;
486     goto closeandexit;
487     };
488 mocchiut 1.2 // EM: open header branch as well
489     l0head = l0tr->GetBranch("Header");
490     if ( !l0head ) {
491 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Header branch in Level0 tree\n");
492 mocchiut 1.2 l0File->Close();
493     code = -8;
494     goto closeandexit;
495     };
496     l0tr->SetBranchAddress("Header", &eh);
497     // end EM
498 mocchiut 1.5 nevents = l0head->GetEntries();
499 mocchiut 1.1 //
500 mocchiut 1.28 if ( nevents < 1 && totevent ) {
501 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
502 mocchiut 1.1 l0File->Close();
503     code = -11;
504     goto closeandexit;
505     };
506 mocchiut 1.20 //
507 mocchiut 1.28 if ( runinfo->EV_TO > nevents-1 && totevent ) {
508 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");
509 mocchiut 1.1 l0File->Close();
510     code = -12;
511     goto closeandexit;
512     };
513     //
514 mocchiut 1.15 // TTree *tp = (TTree*)l0File->Get("RunHeader");
515     // tp->SetBranchAddress("Header", &eH);
516     // tp->SetBranchAddress("RunHeader", &reh);
517     // tp->GetEntry(0);
518     // ph = eH->GetPscuHeader();
519     // ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
520     // ULong_t ObtSync = reh->OBT_TIME_SYNC;
521     // if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
522     //
523     ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
524     ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
525     ULong_t DeltaOBT = TimeSync - ObtSync;
526    
527     if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
528    
529     l0trm = (TTree*)l0File->Get("Mcmd");
530     neventsm = l0trm->GetEntries();
531 mocchiut 1.18 // neventsm = 0;
532 mocchiut 1.15 //
533     if (neventsm == 0){
534 mocchiut 1.18 if ( debug ) printf("InclinationInfo - WARNING: No quaternions in this File");
535     // l0File->Close();
536     code = 900;
537     // goto closeandexit;
538 mocchiut 1.15 }
539     //
540    
541     l0trm->SetBranchAddress("Mcmd", &mcmdev);
542 mocchiut 1.18 // l0trm->SetBranchAddress("Header", &eh);
543 mocchiut 1.15 //
544     //
545     //
546     UInt_t mctren = 0;
547     UInt_t mcreen = 0;
548     UInt_t numrec = 0;
549     //
550     Double_t upperqtime = 0;
551     Double_t lowerqtime = 0;
552    
553     Double_t incli = 0;
554     oi = 0;
555     UInt_t ooi = 0;
556     //
557     // init quaternions sync
558     //
559     Bool_t isf = true;
560     Int_t fgh = 0;
561     //
562 mocchiut 1.1 // run over all the events of the run
563     //
564     if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n");
565     //
566 mocchiut 1.25 //
567 mocchiut 1.5 for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
568 mocchiut 1.15
569 mocchiut 1.1 //
570 mocchiut 1.5 if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
571 mocchiut 1.15 if ( debug ) printf(" %i \n",procev);
572 mocchiut 1.1 //
573 mocchiut 1.5 l0head->GetEntry(re);
574 mocchiut 1.1 //
575     // absolute time of this event
576     //
577 mocchiut 1.5 ph = eh->GetPscuHeader();
578 mocchiut 1.15 atime = dbtime->DBabsTime(ph->GetOrbitalTime());
579 mocchiut 1.1 //
580     // paranoid check
581     //
582     if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME) ) {
583     if (verbose) printf(" OrbitalInfo - WARNING: event at time outside the run time window, skipping it\n");
584 mocchiut 1.19 // debug = true;
585 mocchiut 1.7 continue;
586     }
587 mocchiut 1.1 //
588     procev++;
589     //
590     // start processing
591     //
592 mocchiut 1.3 orbitalinfo->Clear();
593 mocchiut 1.5 //
594 mocchiut 1.15 // Fill OBT, pkt_num and absTime
595     //
596 mocchiut 1.18 // ph = eh->GetPscuHeader();
597 mocchiut 1.2 orbitalinfo->pkt_num = ph->GetCounter();
598     orbitalinfo->OBT = ph->GetOrbitalTime();
599 mocchiut 1.15 orbitalinfo->absTime = atime;
600     //
601     // Propagate the orbit from the tle time to atime, using SGP(D)4.
602     //
603     cCoordGeo coo;
604     float jyear=0;
605 mocchiut 1.7 //
606     if(atime >= gltle->GetToTime()) {
607 mocchiut 1.9 if ( !gltle->Query(atime, dbc) ){
608 mocchiut 1.15 //
609 mocchiut 1.9 // Compute the magnetic dipole moment.
610 mocchiut 1.15 //
611 mocchiut 1.9 UInt_t year, month, day, hour, min, sec;
612 mocchiut 1.15 //
613 mocchiut 1.9 TTimeStamp t = TTimeStamp(atime, kTRUE);
614     t.GetDate(kTRUE, 0, &year, &month, &day);
615     t.GetTime(kTRUE, 0, &hour, &min, &sec);
616     jyear = (float) year
617     + (month*31.+ (float) day)/365.
618     + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);
619 mocchiut 1.15 //
620 mocchiut 1.9 feldcof_(&jyear, &dimo); // get dipole moment for year
621     } else {
622     code = -56;
623     goto closeandexit;
624     };
625 mocchiut 1.7 }
626 mocchiut 1.15 coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());
627     //
628     cOrbit orbits(*gltle->GetTle());
629     //
630 mocchiut 1.18 if ( debug ) printf(" I am Here \n");
631     //
632 mocchiut 1.15 // synchronize with quaternions data
633     //
634 mocchiut 1.18 if ( isf && neventsm>0 ){
635     if ( debug ) printf(" I am here \n");
636 mocchiut 1.15 //
637     // First event
638     //
639     isf = false;
640     upperqtime = atime;
641     lowerqtime = runinfo->RUNHEADER_TIME;
642     for ( ik = 0; ik < neventsm; ik++){
643     l0trm->GetEntry(ik);
644     tmpSize = mcmdev->Records->GetEntries();
645     numrec = tmpSize;
646     for (Int_t j3 = 0;j3<tmpSize;j3++){
647 mocchiut 1.29 if ( debug ) printf(" eh eh eh \n");
648 mocchiut 1.15 mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
649     if ((int)mcmdrc->ID1 == 226){
650     L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
651     for (UInt_t ui = 0; ui < 6; ui++){
652     if (ui>0){
653     if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
654     if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){
655     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
656     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
657     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]);
658     }else {
659     lowerqtime = upperqtime;
660     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
661     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
662     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]);
663     mcreen = j3;
664     mctren = ik;
665     if(fgh==0){
666     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
667     CopyAng(RYPang_lower,RYPang_upper);
668     }
669     oi=ui;
670     goto closethisloop;
671     }
672     fgh++;
673     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
674     CopyAng(RYPang_lower,RYPang_upper);
675     }
676     }else{
677     if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){
678     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
679     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
680     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]);
681     }
682     else {
683     lowerqtime = upperqtime;
684     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
685     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
686     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]);
687     mcreen = j3;
688     mctren = ik;
689     if(fgh==0){
690     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
691     CopyAng(RYPang_lower,RYPang_upper);
692     lowerqtime = atime-1;
693     }
694     oi=ui;
695     goto closethisloop;
696     //_0 = true;
697     }
698     fgh++;
699     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
700     CopyAng(RYPang_lower,RYPang_upper);
701     //_0 = true;
702     };
703     //cin>>grib;
704     };
705     };
706     };
707     };
708     };
709     closethisloop:
710     //
711 mocchiut 1.18 if ( debug ) printf(" I am There \n");
712     //
713     if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){
714     if ( debug ) printf(" I am there \n");
715 mocchiut 1.15 //
716     lowerqtime = upperqtime;
717 mocchiut 1.21 Long64_t maxloop = 100000000LL;
718     Long64_t mn = 0;
719 mocchiut 1.15 bool gh=false;
720     ooi=oi;
721     if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);
722     while (!gh){
723     if ( mn > maxloop ){
724     if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");
725     gh = true;
726 mocchiut 1.21 neventsm = 0;
727 mocchiut 1.15 };
728     mn++;
729     if (oi<5) oi++;
730     else oi=0;
731 mocchiut 1.29 if (oi==0 && numrec > 0){
732     if ( debug ) printf(" mumble \n");
733 mocchiut 1.15 mcreen++;
734     if (mcreen == numrec){
735     mctren++;
736     mcreen = 0;
737     l0trm->GetEntry(mctren);
738     numrec = mcmdev->Records->GetEntries();
739     }
740     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
741     CopyAng(RYPang_lower,RYPang_upper);
742     mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);
743     if ((int)mcmdrc->ID1 == 226){
744     L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
745     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
746     if (upperqtime<lowerqtime){
747     upperqtime=runinfo->RUNTRAILER_TIME;
748     CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);
749     CopyAng(RYPang_upper,RYPang_lower);
750     }else{
751     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
752     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]);
753     }
754     // re--;
755     gh=true;
756     }
757     }else{
758     if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){
759     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
760     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
761     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]);
762     orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi);
763     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]);
764     // re--;
765     gh=true;
766     };
767     };
768     };
769     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);
770     };
771     //
772 mocchiut 1.18 if ( debug ) printf(" I am THIS \n");
773     //
774 mocchiut 1.15 // Fill in quaternions and angles
775     //
776 mocchiut 1.18 if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)&& neventsm>0){
777     if ( debug ) printf(" I am this \n");
778 mocchiut 1.15 UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
779     if (oi == 0){
780     if ((tut!=5)||(tut!=6)){
781     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)));
782     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));
783     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)));
784     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));
785     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)));
786     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));
787     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)));
788     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));
789    
790     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)));
791     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
792     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)));
793     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
794     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)));
795     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
796     }
797     if (tut==6){
798     if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
799     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)));
800     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));
801     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)));
802     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));
803     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)));
804     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));
805     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)));
806     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));
807    
808     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)));
809     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
810     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)));
811     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
812     //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";
813     //cin>>grib;
814     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)));
815     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
816     }
817     }
818     } else {
819     if((tut!=6)||(tut!=7)||(tut!=9)){
820     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)));
821     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));
822     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)));
823     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));
824     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)));
825     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));
826     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)));
827     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));
828    
829     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)));
830     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
831     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)));
832     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
833     //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";
834     //cin>>grib;
835     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)));
836     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
837     }
838     if (tut==6){
839     if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
840     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)));
841     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));
842     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)));
843     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));
844     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)));
845     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));
846     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)));
847     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));
848    
849     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)));
850     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
851     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)));
852     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
853     //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";
854     //cin>>grib;
855     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)));
856     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
857     }
858     }
859     }
860 mocchiut 1.18 //
861 mocchiut 1.15 orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
862 mocchiut 1.18 //
863 mocchiut 1.15 } else {
864 mocchiut 1.18 if ( debug ) printf(" ops no incl! \n");
865 mocchiut 1.15 orbitalinfo->mode = -1;
866     };
867    
868     //
869     // fill orbital positions
870     //
871 mocchiut 1.7 // Build coordinates in the right range. We want to convert,
872     // longitude from (0, 2*pi) to (-180deg, 180deg). Altitude is
873     // in meters.
874     lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon);
875     lat = rad2deg(coo.m_Lat);
876     alt = coo.m_Alt;
877 mocchiut 1.15 //
878 mocchiut 1.7 if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){
879 mocchiut 1.15 //
880 mocchiut 1.7 orbitalinfo->lon = lon;
881     orbitalinfo->lat = lat;
882     orbitalinfo->alt = alt ;
883 mocchiut 1.15 //
884 mocchiut 1.7 // compute mag field components and L shell.
885 mocchiut 1.15 //
886 mocchiut 1.7 feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);
887     shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);
888     findb0_(&stps, &bdel, &value, &bequ, &rr0);
889 mocchiut 1.15 //
890 mocchiut 1.7 orbitalinfo->Bnorth = bnorth;
891     orbitalinfo->Beast = beast;
892     orbitalinfo->Bdown = bdown;
893     orbitalinfo->Babs = babs;
894     orbitalinfo->BB0 = babs/bequ;
895 mocchiut 1.15 orbitalinfo->L = xl;
896 mocchiut 1.7 // Set Stormer vertical cutoff using L shell.
897     orbitalinfo->cutoff[0] = 14.9/(xl*xl);
898 mocchiut 1.15 //
899     };
900 pamelaprod 1.11 //
901 mocchiut 1.15 // Fill the class
902 pamelaprod 1.11 //
903 mocchiut 1.1 OrbitalInfotr->Fill();
904 mocchiut 1.15 //
905     }; // loop over the events in the run
906 mocchiut 1.1 //
907     // Here you may want to clear some variables before processing another run
908     //
909 mocchiut 1.5 delete dbtime;
910 mocchiut 1.18 if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
911     if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
912     if ( RYPang_upper ) delete RYPang_upper;
913     if ( RYPang_lower ) delete RYPang_lower;
914 mocchiut 1.1 }; // process all the runs
915 mocchiut 1.15
916 mocchiut 1.1 if (verbose) printf("\n Finished processing data \n");
917     //
918     closeandexit:
919     //
920     // 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.
921     //
922     if ( !reprocall && reproc && code >= 0 ){
923     if ( totfileentries > noaftrun ){
924     if (verbose){
925     printf("\n Post-processing: copying events from the old tree after the processed run\n");
926     printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
927     printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
928     }
929     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
930     //
931     // Get entry from old tree
932     //
933     OrbitalInfotrclone->GetEntry(j);
934     //
935     // copy orbitalinfoclone to OrbitalInfo
936     //
937 mocchiut 1.3 orbitalinfo->Clear();
938 mocchiut 1.5 //
939 mocchiut 1.1 memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
940     //
941     // Fill entry in the new tree
942     //
943     OrbitalInfotr->Fill();
944     };
945     if (verbose) printf(" Finished successful copying!\n");
946     };
947     };
948     //
949     // Close files, delete old tree(s), write and close level2 file
950     //
951     if ( l0File ) l0File->Close();
952     if ( tempfile ) tempfile->Close();
953 mocchiut 1.23 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
954 mocchiut 1.5 //
955 mocchiut 1.1 if ( runinfo ) runinfo->Close();
956     if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");
957     if ( file ){
958     file->cd();
959     file->Write();
960     };
961     //
962 mocchiut 1.23 if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
963 mocchiut 1.1 //
964     // the end
965     //
966 mocchiut 1.25 if ( dbc ){
967     dbc->Close();
968     delete dbc;
969     };
970 mocchiut 1.1 if (verbose) printf("\n Exiting...\n");
971     if(OrbitalInfotr)OrbitalInfotr->Delete();
972 mocchiut 1.4 //
973     if ( orbitalinfo ) delete orbitalinfo;
974     if ( orbitalinfoclone ) delete orbitalinfoclone;
975     if ( glroot ) delete glroot;
976     if ( runinfo ) delete runinfo;
977     //
978 mocchiut 1.1 if(code < 0) throw code;
979     return(code);
980     }
981    
982 mocchiut 1.7
983     //
984     // Returns the cCoordGeo structure holding the geographical
985     // coordinates for the event (see sgp4.h).
986     //
987     // atime is the abstime of the event in UTC unix time.
988     // tletime is the time of the tle in UTC unix time.
989     // tle is the previous and nearest tle (compared to atime).
990     cCoordGeo getCoo(UInt_t atime, UInt_t tletime, cTle *tle)
991     {
992     cEci eci;
993     cOrbit orbit(*tle);
994     orbit.getPosition((double) (atime - tletime)/60., &eci);
995    
996     return eci.toGeo();
997     }
998 mocchiut 1.15
999     // function of copyng of quatrnions classes
1000    
1001     void CopyQ(Quaternions *Q1, Quaternions *Q2){
1002     for(UInt_t i = 0; i < 6; i++){
1003     Q1->time[i]=Q2->time[i];
1004     for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j];
1005     }
1006     return;
1007     }
1008    
1009     // functions of copyng InclinationInfo classes
1010    
1011     void CopyAng(InclinationInfo *A1, InclinationInfo *A2){
1012     A1->Tangazh = A2->Tangazh;
1013     A1->Ryskanie = A2->Ryskanie;
1014     A1->Kren = A2->Kren;
1015     return;
1016     }
1017    
1018     UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
1019    
1020     UInt_t hole = 10;
1021     bool R10l = false; // Sign of R10 mode in lower quaternions array
1022     bool R10u = false; // Sign of R10 mode in upper quaternions array
1023     bool insm = false; // Sign that we inside quaternions array
1024     bool mxtml = false; // Sign of mixt mode in lower quaternions array
1025     bool mxtmu = false; // Sign of mixt mode in upper quaternions array
1026     bool npasm = false; // Sign of normall pass between R10 and non R10 or between non R10 and R10
1027     UInt_t NCQl = 6; // Number of correct quaternions in lower array
1028     UInt_t NCQu = 6; // Number of correct quaternions in upper array
1029     if (f>0){
1030     insm = true;
1031     if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false;
1032     if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true;
1033     }else{
1034     insm = false;
1035     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true;
1036     if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true;
1037     if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false;
1038     if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false;
1039     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){
1040     mxtml = true;
1041     for(UInt_t i = 1; i < 6; i++){
1042     if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i;
1043     }
1044     }
1045     if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){
1046     mxtmu = true;
1047     for(UInt_t i = 1; i < 6; i++){
1048     if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i;
1049     }
1050     }
1051     }
1052    
1053     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;
1054    
1055    
1056     if (R10u&&insm) hole=0; // best event R10
1057     if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct
1058     if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10
1059     if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10
1060     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
1061     if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10
1062     if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10
1063     if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10
1064     if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10
1065     if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10
1066     return hole;
1067     }
1068    

  ViewVC Help
Powered by ViewVC 1.1.23