/[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.23 - (hide annotations) (download)
Thu Sep 6 12:49:30 2007 UTC (17 years, 5 months ago) by mocchiut
Branch: MAIN
Changes since 1.22: +5 -3 lines
Small improvements of *Core routines, added simulation identification feature in CaloCore

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

  ViewVC Help
Powered by ViewVC 1.1.23