/[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.37 - (hide annotations) (download)
Fri Dec 19 14:00:08 2008 UTC (16 years, 2 months ago) by mocchiut
Branch: MAIN
Changes since 1.36: +97 -8 lines
New OrbitalInfoCore, now take more files for inclination Mcmds (should fix some holes)

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 mocchiut 1.30 //
74 mocchiut 1.31 Bool_t standalone = false;
75 mocchiut 1.30 //
76 mocchiut 1.1 if ( OrbitalInfoargc > 0 ){
77     i = 0;
78     while ( i < OrbitalInfoargc ){
79     if ( !strcmp(OrbitalInfoargv[i],"-processFolder") ) {
80     if ( OrbitalInfoargc < i+1 ){
81     throw -3;
82     };
83     processFolder = (TString)OrbitalInfoargv[i+1];
84     i++;
85     };
86     if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {
87     verbose = true;
88 mocchiut 1.15 debug = true;
89 mocchiut 1.1 };
90     if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {
91     verbose = true;
92     };
93 mocchiut 1.30 if ( (!strcmp(OrbitalInfoargv[i],"--standalone")) ) {
94     standalone = true;
95     };
96     if ( (!strcmp(OrbitalInfoargv[i],"--calculate-pitch")) ) {
97     standalone = false;
98     };
99 mocchiut 1.1 i++;
100     };
101     };
102     //
103     const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath()));
104     //
105     TTree *OrbitalInfotr = 0;
106 mocchiut 1.5 UInt_t nevents = 0;
107 mocchiut 1.15 UInt_t neventsm = 0;
108 mocchiut 1.1 //
109     // variables needed to reprocess data
110     //
111 mocchiut 1.6 Long64_t maxsize = 10000000000LL;
112     TTree::SetMaxTreeSize(maxsize);
113     //
114 mocchiut 1.1 TString OrbitalInfoversion;
115     ItoRunInfo *runinfo = 0;
116 mocchiut 1.5 TArrayI *runlist = 0;
117 mocchiut 1.1 TTree *OrbitalInfotrclone = 0;
118     Bool_t reproc = false;
119     Bool_t reprocall = false;
120     UInt_t nobefrun = 0;
121     UInt_t noaftrun = 0;
122     UInt_t numbofrun = 0;
123     stringstream ftmpname;
124     TString fname;
125 mocchiut 1.5 UInt_t totfileentries = 0;
126 mocchiut 1.15 UInt_t idRun = 0;
127     //
128     // My variables. Vitaly.
129     //
130     // UInt_t iev = 0;
131     // UInt_t j3 = 0;
132     UInt_t oi = 0;
133     Int_t tmpSize = 0;
134 mocchiut 1.1 //
135     // variables needed to handle error signals
136     //
137     Int_t code = 0;
138     Int_t sgnl;
139     //
140     // OrbitalInfo classes
141     //
142     OrbitalInfo *orbitalinfo = new OrbitalInfo();
143     OrbitalInfo *orbitalinfoclone = new OrbitalInfo();
144     //
145     // define variables for opening and reading level0 file
146     //
147     TFile *l0File = 0;
148     TTree *l0tr = 0;
149 mocchiut 1.37 // TTree *l0trm = 0;
150     TChain *ch = 0;
151 mocchiut 1.2 // EM: open also header branch
152     TBranch *l0head = 0;
153     pamela::EventHeader *eh = 0;
154     pamela::PscuHeader *ph = 0;
155 mocchiut 1.15 pamela::McmdEvent *mcmdev = 0;
156     pamela::McmdRecord *mcmdrc = 0;
157 mocchiut 1.2 // end EM
158 mocchiut 1.15
159     // pamela::RunHeaderEvent *reh = new pamela::RunHeaderEvent;
160     // pamela::EventHeader *eH = new pamela::EventHeader;
161    
162 mocchiut 1.1 //
163     // Define other basic variables
164     //
165     UInt_t procev = 0;
166     stringstream file2;
167     stringstream file3;
168     stringstream qy;
169     Int_t totevent = 0;
170 mocchiut 1.5 UInt_t atime = 0;
171     UInt_t re = 0;
172 mocchiut 1.15 UInt_t ik = 0;
173 mocchiut 1.7
174     // Position
175     Float_t lon, lat, alt;
176    
177     //
178     // IGRF stuff
179     //
180     float dimo = 0.0; // dipole moment (computed from dat files)
181     float bnorth, beast, bdown, babs;
182     float xl; // L value
183     float icode; // code value for L accuracy (see fortran code)
184     float bab1; // What's the difference with babs?
185     float stps = 0.005; // step size for field line tracing
186     float bdel = 0.01; // required accuracy
187     float bequ; // equatorial b value (also called b_0)
188     bool value = 0; // false if bequ is not the minimum b value
189     float rr0; // equatorial radius normalized to earth radius
190    
191 mocchiut 1.1 //
192     // Working filename
193     //
194     TString outputfile;
195     stringstream name;
196     name.str("");
197     name << outDir << "/";
198     //
199     // temporary file and folder
200     //
201     TFile *tempfile = 0;
202     TTree *tempOrbitalInfo = 0;
203     stringstream tempname;
204     stringstream OrbitalInfofolder;
205 mocchiut 1.23 Bool_t myfold = false;
206 mocchiut 1.1 tempname.str("");
207     tempname << outDir;
208     tempname << "/" << processFolder.Data();
209     OrbitalInfofolder.str("");
210     OrbitalInfofolder << tempname.str().c_str();
211     tempname << "/OrbitalInfotree_run";
212     tempname << run << ".root";
213     //
214     // DB classes
215     //
216     GL_ROOT *glroot = new GL_ROOT();
217 mocchiut 1.5 GL_TIMESYNC *dbtime = 0;
218 mocchiut 1.7 GL_TLE *gltle = new GL_TLE();
219 mocchiut 1.15 //
220     //Quaternions classes
221     //
222     Quaternions *L_QQ_Q_l_lower = new Quaternions();
223     InclinationInfo *RYPang_lower = new InclinationInfo();
224     Quaternions *L_QQ_Q_l_upper = new Quaternions();
225     InclinationInfo *RYPang_upper = new InclinationInfo();
226    
227     cEci eCi;
228    
229 mocchiut 1.7 // Initialize fortran routines!!!
230     Int_t ltp2 = 0;
231     Int_t ltp3 = 0;
232     Int_t uno = 1;
233     char *niente = " ";
234     GL_PARAM *glparam = new GL_PARAM();
235 mocchiut 1.10 GL_PARAM *glparam2 = new GL_PARAM();
236 mocchiut 1.7 Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table
237 mocchiut 1.30 //
238     // Orientation variables
239     //
240     UInt_t evfrom = 0;
241     UInt_t jumped = 0;
242     Int_t itr = -1;
243     Double_t A1;
244     Double_t A2;
245     Double_t A3;
246     Double_t Px = 0;
247     Double_t Py = 0;
248     Double_t Pz = 0;
249     TTree *ttof = 0;
250     ToFLevel2 *tof = new ToFLevel2();
251     OrientationInfo *PO = new OrientationInfo();
252     Int_t nz = 6;
253     Float_t zin[6];
254     Int_t nevtofl2 = 0;
255     //
256 mocchiut 1.7 if ( parerror<0 ) {
257     code = parerror;
258     goto closeandexit;
259     };
260     ltp2 = (Int_t)(glparam->PATH+glparam->NAME).Length();
261     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
262     //
263     parerror=glparam2->Query_GL_PARAM(1,302,dbc); // parameters stored in DB in GL_PRAM table
264     if ( parerror<0 ) {
265     code = parerror;
266     goto closeandexit;
267     };
268     ltp3 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();
269     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
270     //
271     initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);
272     //
273     // End IGRF stuff//
274     //
275 mocchiut 1.30 for (Int_t ip=0;ip<nz;ip++){
276     zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
277     };
278     //
279     if ( !standalone ){
280     //
281     // Does it contain the Tracker tree?
282     //
283     ttof = (TTree*)file->Get("ToF");
284     if ( !ttof ) {
285     if ( verbose ) printf(" OrbitalInfo - ERROR: no tof tree\n");
286     code = -900;
287     goto closeandexit;
288     };
289     ttof->SetBranchAddress("ToFLevel2",&tof);
290     nevtofl2 = ttof->GetEntries();
291     };
292 mocchiut 1.1 //
293     // Let's start!
294     //
295     // 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
296     // if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file
297     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
298     //
299 mocchiut 1.5 if ( run == 0 ) reproc = true;
300 mocchiut 1.1 //
301     //
302     // Output file is "outputfile"
303     //
304     if ( !file->IsOpen() ){
305     //printf(" OrbitalInfo - ERROR: cannot open file for writing\n");
306     throw -901;
307     };
308     //
309     // Retrieve GL_RUN variables from the level2 file
310     //
311     OrbitalInfoversion = OrbitalInfoInfo(false); // we should decide how to handle versioning system
312     //
313     // create an interface to RunInfo called "runinfo"
314     //
315     runinfo = new ItoRunInfo(file);
316     //
317     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
318     //
319     sgnl = 0;
320     sgnl = runinfo->Update(run, "ORB", OrbitalInfoversion);
321     //sgnl = runinfo->Read(run);
322    
323     if ( sgnl ){
324     //printf("OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");
325     code = sgnl;
326     goto closeandexit;
327     } else {
328     sgnl = 0;
329     };
330     //
331     // number of events in the file BEFORE the first event of our run
332     //
333     nobefrun = runinfo->GetFirstEntry();
334     //
335     // total number of events in the file
336     //
337     totfileentries = runinfo->GetFileEntries();
338     //
339     // first file entry AFTER the last event of our run
340     //
341     noaftrun = runinfo->GetLastEntry() + 1;
342     //
343     // number of run to be processed
344     //
345     numbofrun = runinfo->GetNoRun();
346 mocchiut 1.22 UInt_t totnorun = runinfo->GetRunEntries();
347 mocchiut 1.1 //
348     // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run
349     //
350     OrbitalInfotrclone = (TTree*)file->Get("OrbitalInfo");
351     //
352     if ( !OrbitalInfotrclone ){
353     //
354     // tree does not exist, we are not reprocessing
355     //
356     reproc = false;
357 mocchiut 1.5 if ( run == 0 ){
358 mocchiut 1.1 if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n");
359     }
360 mocchiut 1.5 if ( runinfo->IsReprocessing() && run != 0 ) {
361 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");
362     }
363     } else {
364     //
365     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
366     //
367 mocchiut 1.6 OrbitalInfotrclone->SetAutoSave(900000000000000LL);
368 mocchiut 1.1 reproc = true;
369     //
370     //
371     if (verbose) printf("\n Preparing the pre-processing...\n");
372     //
373 mocchiut 1.22 if ( run == 0 || totnorun == 1 ){
374 mocchiut 1.1 //
375     // we are reprocessing all the file
376     // 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
377     //
378     reprocall = true;
379     //
380     if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n");
381     //
382     } else {
383     //
384     // 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
385     //
386     reprocall = false;
387     //
388 mocchiut 1.5 if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %u \n",run);
389 mocchiut 1.1 //
390     // copying old tree to a new file
391     //
392 mocchiut 1.23 gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
393     myfold = true;
394 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
395     tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
396     tempOrbitalInfo->SetName("OrbitalInfo-old");
397     tempfile->Write();
398     tempfile->Close();
399     }
400     //
401     // Delete the old tree from old file and memory
402     //
403     OrbitalInfotrclone->Delete("all");
404     //
405     if (verbose) printf(" ...done!\n");
406     //
407     };
408     //
409     // create mydetector tree mydect
410     //
411     file->cd();
412     OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");
413 mocchiut 1.6 OrbitalInfotr->SetAutoSave(900000000000000LL);
414 mocchiut 1.30 orbitalinfo->Set();//ELENA **TEMPORANEO?**
415 mocchiut 1.1 OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);
416     //
417     if ( reproc && !reprocall ){
418     //
419     // open new file and retrieve also tree informations
420     //
421     tempfile = new TFile(tempname.str().c_str(),"READ");
422     OrbitalInfotrclone = (TTree*)tempfile->Get("OrbitalInfo-old");
423 mocchiut 1.6 OrbitalInfotrclone->SetAutoSave(900000000000000LL);
424 mocchiut 1.1 OrbitalInfotrclone->SetBranchAddress("OrbitalInfo",&orbitalinfoclone);
425     //
426     if ( nobefrun > 0 ){
427     if (verbose){
428 mocchiut 1.7 printf("\n Pre-processing: copying events from the old tree before the processed run\n");
429     printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
430     printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
431 mocchiut 1.1 }
432     for (UInt_t j = 0; j < nobefrun; j++){
433     //
434     OrbitalInfotrclone->GetEntry(j);
435     //
436     // copy orbitalinfoclone to mydec
437     //
438 mocchiut 1.3 orbitalinfo->Clear();
439 mocchiut 1.5 //
440 mocchiut 1.1 memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
441     //
442     // Fill entry in the new tree
443     //
444     OrbitalInfotr->Fill();
445     //
446     };
447     if (verbose) printf(" Finished successful copying!\n");
448     };
449     };
450     //
451     // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
452     //
453     runlist = runinfo->GetRunList();
454     //
455     // Loop over the run to be processed
456     //
457     for (UInt_t irun=0; irun < numbofrun; irun++){
458     //
459     // retrieve the first run ID to be processed using the RunInfo list
460     //
461 mocchiut 1.15
462 mocchiut 1.1 idRun = runlist->At(irun);
463     if (verbose){
464     printf("\n\n\n ####################################################################### \n");
465     printf(" PROCESSING RUN NUMBER %i \n",(int)idRun);
466     printf(" ####################################################################### \n\n\n");
467     }
468     //
469 mocchiut 1.5 runinfo->ID_ROOT_L0 = 0;
470 mocchiut 1.1 //
471     // store in the runinfo class the GL_RUN variables for our run
472     //
473     sgnl = 0;
474     sgnl = runinfo->GetRunInfo(idRun);
475     if ( sgnl ){
476 mocchiut 1.5 if ( debug ) printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");
477 mocchiut 1.1 code = sgnl;
478     goto closeandexit;
479     } else {
480     sgnl = 0;
481     };
482     //
483     // now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN
484     //
485 mocchiut 1.5 if ( runinfo->ID_ROOT_L0 == 0 ){
486     if ( debug ) printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
487 mocchiut 1.1 code = -5;
488     goto closeandexit;
489     };
490     //
491 mocchiut 1.5 // prepare the timesync for the db
492     //
493     dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
494 mocchiut 1.15
495 mocchiut 1.5 //
496 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
497     //
498 mocchiut 1.5 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
499 mocchiut 1.1 //
500     ftmpname.str("");
501     ftmpname << glroot->PATH.Data() << "/";
502     ftmpname << glroot->NAME.Data();
503     fname = ftmpname.str().c_str();
504 mocchiut 1.15 ftmpname.str("");
505 mocchiut 1.1 //
506     // print out informations
507     //
508 mocchiut 1.5 totevent = runinfo->NEVENTS;
509 mocchiut 1.30 evfrom = runinfo->EV_FROM;
510 mocchiut 1.15 //cout<<"totevents = "<<totevent<<"\n";
511 mocchiut 1.1 if (verbose){
512     printf("\n LEVEL0 data file: %s \n",fname.Data());
513 mocchiut 1.5 printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
514     printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
515 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);
516 mocchiut 1.1 }//
517 mocchiut 1.27 //
518 mocchiut 1.28 // if ( !totevent ) goto closeandexit;
519 mocchiut 1.1 // Open Level0 file
520     l0File = new TFile(fname.Data());
521     if ( !l0File ) {
522 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");
523 mocchiut 1.1 code = -6;
524     goto closeandexit;
525     };
526     l0tr = (TTree*)l0File->Get("Physics");
527     if ( !l0tr ) {
528 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n");
529 mocchiut 1.1 l0File->Close();
530     code = -7;
531     goto closeandexit;
532     };
533 mocchiut 1.2 // EM: open header branch as well
534     l0head = l0tr->GetBranch("Header");
535     if ( !l0head ) {
536 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Header branch in Level0 tree\n");
537 mocchiut 1.2 l0File->Close();
538     code = -8;
539     goto closeandexit;
540     };
541     l0tr->SetBranchAddress("Header", &eh);
542     // end EM
543 mocchiut 1.5 nevents = l0head->GetEntries();
544 mocchiut 1.1 //
545 mocchiut 1.28 if ( nevents < 1 && totevent ) {
546 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
547 mocchiut 1.1 l0File->Close();
548     code = -11;
549     goto closeandexit;
550     };
551 mocchiut 1.20 //
552 mocchiut 1.28 if ( runinfo->EV_TO > nevents-1 && totevent ) {
553 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");
554 mocchiut 1.1 l0File->Close();
555     code = -12;
556     goto closeandexit;
557     };
558     //
559 mocchiut 1.15 // TTree *tp = (TTree*)l0File->Get("RunHeader");
560     // tp->SetBranchAddress("Header", &eH);
561     // tp->SetBranchAddress("RunHeader", &reh);
562     // tp->GetEntry(0);
563     // ph = eH->GetPscuHeader();
564     // ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
565     // ULong_t ObtSync = reh->OBT_TIME_SYNC;
566     // if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
567     //
568     ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
569     ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
570     ULong_t DeltaOBT = TimeSync - ObtSync;
571    
572     if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
573 mocchiut 1.37 //
574     // Read MCMDs from up to 11 files, 5 before and 5 after the present one in order to have some kind of inclination information
575     //
576     ch = new TChain("Mcmd","Mcmd");
577     //
578     // look in the DB to find the closest files to this run
579     //
580     TSQLResult *pResult = 0;
581     TSQLRow *Row = 0;
582     stringstream myquery;
583     UInt_t l0fid[10];
584     Int_t i = 0;
585     memset(l0fid,0,10*sizeof(Int_t));
586     //
587     myquery.str("");
588     myquery << "select ID_ROOT_L0 from GL_RUN where RUNHEADER_TIME<=" << runinfo->RUNHEADER_TIME << " group by ID_ROOT_L0 order by RUNHEADER_TIME desc limit 5;";
589     //
590     pResult = dbc->Query(myquery.str().c_str());
591     //
592     i = 9;
593     if( pResult ){
594     //
595     Row = pResult->Next();
596     //
597     while ( Row ){
598     //
599     // store infos and exit
600     //
601     l0fid[i] = (UInt_t)atoll(Row->GetField(0));
602     i--;
603     Row = pResult->Next();
604     //
605     };
606     pResult->Delete();
607     };
608     //
609     myquery.str("");
610     myquery << "select ID_ROOT_L0 from GL_RUN where RUNHEADER_TIME>" << runinfo->RUNHEADER_TIME << " group by ID_ROOT_L0 order by RUNHEADER_TIME asc limit 5;";
611     //
612     pResult = dbc->Query(myquery.str().c_str());
613     //
614     i = 0;
615     if( pResult ){
616     //
617     Row = pResult->Next();
618     //
619     while ( Row ){
620     //
621     // store infos and exit
622     //
623     l0fid[i] = (UInt_t)atoll(Row->GetField(0));
624     i++;
625     Row = pResult->Next();
626     //
627     };
628     pResult->Delete();
629     };
630     //
631     i = 0;
632     UInt_t previd = 0;
633     while ( i < 10 ){
634     if ( l0fid[i] && previd != l0fid[i] ){
635     previd = l0fid[i];
636     myquery.str("");
637     myquery << "select PATH,NAME from GL_ROOT where ID=" << l0fid[i] << " ;";
638     //
639     pResult = dbc->Query(myquery.str().c_str());
640     //
641     if( pResult ){
642     //
643     Row = pResult->Next();
644     //
645     if ( debug ) printf(" Using inclination informations from file: %s \n",(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1)).Data());
646     ch->Add(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1));
647     //
648     pResult->Delete();
649     };
650     };
651     i++;
652     };
653     //
654     // l0trm = (TTree*)l0File->Get("Mcmd");
655     // ch->ls();
656     ch->SetBranchAddress("Mcmd",&mcmdev);
657     // printf(" entries %llu \n", ch->GetEntries());
658     // l0trm = ch->GetTree();
659     // neventsm = l0trm->GetEntries();
660     neventsm = ch->GetEntries();
661     if ( debug ) printf(" entries %u \n", neventsm);
662 mocchiut 1.18 // neventsm = 0;
663 mocchiut 1.15 //
664     if (neventsm == 0){
665 mocchiut 1.18 if ( debug ) printf("InclinationInfo - WARNING: No quaternions in this File");
666     // l0File->Close();
667     code = 900;
668     // goto closeandexit;
669 mocchiut 1.15 }
670     //
671    
672 mocchiut 1.37 // l0trm->SetBranchAddress("Mcmd", &mcmdev);
673 mocchiut 1.18 // l0trm->SetBranchAddress("Header", &eh);
674 mocchiut 1.15 //
675     //
676     //
677     UInt_t mctren = 0;
678     UInt_t mcreen = 0;
679     UInt_t numrec = 0;
680     //
681     Double_t upperqtime = 0;
682     Double_t lowerqtime = 0;
683    
684     Double_t incli = 0;
685     oi = 0;
686     UInt_t ooi = 0;
687     //
688     // init quaternions sync
689     //
690     Bool_t isf = true;
691     Int_t fgh = 0;
692     //
693 mocchiut 1.1 // run over all the events of the run
694     //
695     if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n");
696     //
697 mocchiut 1.25 //
698 mocchiut 1.5 for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
699 mocchiut 1.15
700 mocchiut 1.1 //
701 mocchiut 1.5 if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
702 mocchiut 1.15 if ( debug ) printf(" %i \n",procev);
703 mocchiut 1.1 //
704 mocchiut 1.5 l0head->GetEntry(re);
705 mocchiut 1.1 //
706     // absolute time of this event
707     //
708 mocchiut 1.5 ph = eh->GetPscuHeader();
709 mocchiut 1.15 atime = dbtime->DBabsTime(ph->GetOrbitalTime());
710 mocchiut 1.1 //
711     // paranoid check
712     //
713 mocchiut 1.34 if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1)) ) {
714 mocchiut 1.1 if (verbose) printf(" OrbitalInfo - WARNING: event at time outside the run time window, skipping it\n");
715 mocchiut 1.30 jumped++;
716 mocchiut 1.19 // debug = true;
717 mocchiut 1.7 continue;
718     }
719 mocchiut 1.30
720     //
721     // retrieve tof informations
722     //
723     if ( !reprocall ){
724     itr = nobefrun + (re - evfrom - jumped);
725     //itr = re-(46438+200241);
726     } else {
727     itr = runinfo->GetFirstEntry() + (re - evfrom - jumped);
728     };
729     //
730     if ( !standalone ){
731     if ( itr > nevtofl2 ){
732     if ( verbose ) printf(" OrbitalInfo - ERROR: no tof events with entry = %i in Level2 file\n",itr);
733     if ( debug ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
734     l0File->Close();
735     code = -901;
736     goto closeandexit;
737     };
738     //
739     tof->Clear();
740     //
741     ttof->GetEntry(itr);
742     //
743     };
744 mocchiut 1.1 //
745     procev++;
746     //
747     // start processing
748     //
749 mocchiut 1.3 orbitalinfo->Clear();
750 mocchiut 1.5 //
751 mocchiut 1.30 OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
752     if( !(orbitalinfo->OrbitalInfoTrk) ) orbitalinfo->OrbitalInfoTrk = new TClonesArray("OrbitalInfoTrkVar",2);
753     TClonesArray &tor = *orbitalinfo->OrbitalInfoTrk;
754     //
755 mocchiut 1.15 // Fill OBT, pkt_num and absTime
756     //
757 mocchiut 1.2 orbitalinfo->pkt_num = ph->GetCounter();
758     orbitalinfo->OBT = ph->GetOrbitalTime();
759 mocchiut 1.15 orbitalinfo->absTime = atime;
760     //
761     // Propagate the orbit from the tle time to atime, using SGP(D)4.
762     //
763     cCoordGeo coo;
764     float jyear=0;
765 mocchiut 1.7 //
766     if(atime >= gltle->GetToTime()) {
767 mocchiut 1.9 if ( !gltle->Query(atime, dbc) ){
768 mocchiut 1.15 //
769 mocchiut 1.9 // Compute the magnetic dipole moment.
770 mocchiut 1.15 //
771 mocchiut 1.9 UInt_t year, month, day, hour, min, sec;
772 mocchiut 1.15 //
773 mocchiut 1.9 TTimeStamp t = TTimeStamp(atime, kTRUE);
774     t.GetDate(kTRUE, 0, &year, &month, &day);
775     t.GetTime(kTRUE, 0, &hour, &min, &sec);
776     jyear = (float) year
777     + (month*31.+ (float) day)/365.
778     + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);
779 mocchiut 1.15 //
780 mocchiut 1.9 feldcof_(&jyear, &dimo); // get dipole moment for year
781     } else {
782     code = -56;
783     goto closeandexit;
784     };
785 mocchiut 1.7 }
786 mocchiut 1.15 coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());
787     //
788     cOrbit orbits(*gltle->GetTle());
789     //
790 mocchiut 1.18 if ( debug ) printf(" I am Here \n");
791     //
792 mocchiut 1.15 // synchronize with quaternions data
793     //
794 mocchiut 1.18 if ( isf && neventsm>0 ){
795     if ( debug ) printf(" I am here \n");
796 mocchiut 1.15 //
797     // First event
798     //
799     isf = false;
800     upperqtime = atime;
801     lowerqtime = runinfo->RUNHEADER_TIME;
802     for ( ik = 0; ik < neventsm; ik++){
803 mocchiut 1.37 // l0trm->GetEntry(ik);
804     ch->GetEntry(ik);
805 mocchiut 1.15 tmpSize = mcmdev->Records->GetEntries();
806     numrec = tmpSize;
807     for (Int_t j3 = 0;j3<tmpSize;j3++){
808 mocchiut 1.37 if ( debug ) printf(" ik %i j3 %i eh eh eh \n",ik,j3);
809 mocchiut 1.15 mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
810     if ((int)mcmdrc->ID1 == 226){
811     L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
812     for (UInt_t ui = 0; ui < 6; ui++){
813     if (ui>0){
814     if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
815     if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){
816     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
817     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
818     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]);
819     }else {
820     lowerqtime = upperqtime;
821     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
822     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
823     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]);
824     mcreen = j3;
825     mctren = ik;
826     if(fgh==0){
827     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
828     CopyAng(RYPang_lower,RYPang_upper);
829     }
830     oi=ui;
831     goto closethisloop;
832     }
833     fgh++;
834     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
835     CopyAng(RYPang_lower,RYPang_upper);
836     }
837     }else{
838     if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){
839     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
840     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
841     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]);
842     }
843     else {
844     lowerqtime = upperqtime;
845     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
846     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
847     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]);
848     mcreen = j3;
849     mctren = ik;
850     if(fgh==0){
851     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
852     CopyAng(RYPang_lower,RYPang_upper);
853     lowerqtime = atime-1;
854     }
855     oi=ui;
856     goto closethisloop;
857     //_0 = true;
858     }
859     fgh++;
860     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
861     CopyAng(RYPang_lower,RYPang_upper);
862     //_0 = true;
863     };
864     //cin>>grib;
865     };
866     };
867     };
868     };
869     };
870     closethisloop:
871     //
872 mocchiut 1.18 if ( debug ) printf(" I am There \n");
873     //
874     if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){
875     if ( debug ) printf(" I am there \n");
876 mocchiut 1.15 //
877     lowerqtime = upperqtime;
878 mocchiut 1.21 Long64_t maxloop = 100000000LL;
879     Long64_t mn = 0;
880 mocchiut 1.15 bool gh=false;
881     ooi=oi;
882     if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);
883     while (!gh){
884     if ( mn > maxloop ){
885     if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");
886     gh = true;
887 mocchiut 1.21 neventsm = 0;
888 mocchiut 1.15 };
889     mn++;
890     if (oi<5) oi++;
891     else oi=0;
892 mocchiut 1.29 if (oi==0 && numrec > 0){
893     if ( debug ) printf(" mumble \n");
894 mocchiut 1.15 mcreen++;
895     if (mcreen == numrec){
896     mctren++;
897     mcreen = 0;
898 mocchiut 1.37 // l0trm->GetEntry(mctren);
899     ch->GetEntry(mctren);
900 mocchiut 1.15 numrec = mcmdev->Records->GetEntries();
901     }
902     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
903     CopyAng(RYPang_lower,RYPang_upper);
904     mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);
905     if ((int)mcmdrc->ID1 == 226){
906     L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
907     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
908     if (upperqtime<lowerqtime){
909     upperqtime=runinfo->RUNTRAILER_TIME;
910     CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);
911     CopyAng(RYPang_upper,RYPang_lower);
912     }else{
913     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
914     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]);
915     }
916     // re--;
917     gh=true;
918     }
919     }else{
920     if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){
921     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
922     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
923     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]);
924     orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi);
925     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]);
926     // re--;
927     gh=true;
928     };
929     };
930     };
931     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);
932     };
933     //
934 mocchiut 1.18 if ( debug ) printf(" I am THIS \n");
935     //
936 mocchiut 1.15 // Fill in quaternions and angles
937     //
938 mocchiut 1.18 if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)&& neventsm>0){
939     if ( debug ) printf(" I am this \n");
940 mocchiut 1.15 UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
941     if (oi == 0){
942     if ((tut!=5)||(tut!=6)){
943     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)));
944     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));
945     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)));
946     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));
947     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)));
948     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));
949     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)));
950     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));
951    
952     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)));
953     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
954     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)));
955     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
956     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)));
957     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
958     }
959     if (tut==6){
960     if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
961     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)));
962     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));
963     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)));
964     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));
965     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)));
966     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));
967     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)));
968     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));
969    
970     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)));
971     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
972     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)));
973     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
974     //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";
975     //cin>>grib;
976     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)));
977     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
978     }
979     }
980     } else {
981     if((tut!=6)||(tut!=7)||(tut!=9)){
982     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)));
983     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));
984     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)));
985     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));
986     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)));
987     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));
988     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)));
989     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));
990    
991     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)));
992     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
993     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)));
994     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
995     //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";
996     //cin>>grib;
997     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)));
998     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
999     }
1000     if (tut==6){
1001     if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
1002     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)));
1003     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));
1004     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)));
1005     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));
1006     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)));
1007     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));
1008     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)));
1009     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));
1010    
1011     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)));
1012     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1013     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)));
1014     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1015     //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";
1016     //cin>>grib;
1017     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)));
1018     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1019     }
1020     }
1021     }
1022 mocchiut 1.18 //
1023 mocchiut 1.15 orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
1024 mocchiut 1.18 //
1025 mocchiut 1.15 } else {
1026 mocchiut 1.18 if ( debug ) printf(" ops no incl! \n");
1027 mocchiut 1.30 orbitalinfo->mode = 10;
1028     };
1029     //
1030     // ops no inclination information
1031     //
1032     if ( orbitalinfo->q0< -999 || orbitalinfo->q1 < -999 || orbitalinfo->q2 < -999 || orbitalinfo->q3 < -999 || orbitalinfo->q0 != orbitalinfo->q0 || orbitalinfo->q1 != orbitalinfo->q1 || orbitalinfo->q2 != orbitalinfo->q2 || orbitalinfo->q3 != orbitalinfo->q3 ){
1033     orbitalinfo->mode = 10;
1034     orbitalinfo->q0 = -1000.;
1035     orbitalinfo->q1 = -1000.;
1036     orbitalinfo->q2 = -1000.;
1037     orbitalinfo->q3 = -1000.;
1038     orbitalinfo->etha = -1000.;
1039     orbitalinfo->phi = -1000.;
1040     orbitalinfo->theta = -1000.;
1041 mocchiut 1.15 };
1042 mocchiut 1.30 //
1043     // #########################################################################################################################
1044 mocchiut 1.15 //
1045     // fill orbital positions
1046     //
1047 mocchiut 1.7 // Build coordinates in the right range. We want to convert,
1048     // longitude from (0, 2*pi) to (-180deg, 180deg). Altitude is
1049     // in meters.
1050     lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon);
1051     lat = rad2deg(coo.m_Lat);
1052     alt = coo.m_Alt;
1053 mocchiut 1.15 //
1054 mocchiut 1.7 if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){
1055 mocchiut 1.15 //
1056 mocchiut 1.7 orbitalinfo->lon = lon;
1057     orbitalinfo->lat = lat;
1058     orbitalinfo->alt = alt ;
1059 mocchiut 1.15 //
1060 mocchiut 1.7 // compute mag field components and L shell.
1061 mocchiut 1.15 //
1062 mocchiut 1.7 feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);
1063     shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);
1064     findb0_(&stps, &bdel, &value, &bequ, &rr0);
1065 mocchiut 1.15 //
1066 mocchiut 1.7 orbitalinfo->Bnorth = bnorth;
1067     orbitalinfo->Beast = beast;
1068     orbitalinfo->Bdown = bdown;
1069     orbitalinfo->Babs = babs;
1070     orbitalinfo->BB0 = babs/bequ;
1071 mocchiut 1.15 orbitalinfo->L = xl;
1072 mocchiut 1.7 // Set Stormer vertical cutoff using L shell.
1073 mocchiut 1.33 orbitalinfo->cutoffsvl = 14.9/(xl*xl);
1074 mocchiut 1.15 //
1075     };
1076 pamelaprod 1.11 //
1077 mocchiut 1.30 // pitch angles
1078     //
1079     if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){
1080     //
1081     Float_t Bx = -orbitalinfo->Bdown; //don't need for PamExp ExpOnly for all geography areas
1082     Float_t By = orbitalinfo->Beast; //don't need for PamExp ExpOnly for all geography areas
1083     Float_t Bz = orbitalinfo->Bnorth; //don't need for PamExp ExpOnly for all geography areas
1084     //
1085     TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);
1086     TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);
1087     TMatrixD Iij = PO->ColPermutation(Dij);
1088     //
1089 mocchiut 1.33 orbitalinfo->Iij.ResizeTo(Iij);
1090     orbitalinfo->Iij = Iij;
1091     //
1092 mocchiut 1.30 A1 = Iij(0,2);
1093     A2 = Iij(1,2);
1094     A3 = Iij(2,2);
1095     //
1096 mocchiut 1.33 // orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3); // Angle between zenit and Pamela's main axiz
1097     // orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz); // Angle between Pamela's main axiz and B
1098 mocchiut 1.30 //
1099     if ( !standalone && tof->ntrk() > 0 ){
1100     //
1101     Int_t nn = 0;
1102     for(Int_t nt=0; nt < tof->ntrk(); nt++){
1103     //
1104     ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1105     Double_t E11x = ptt->xtr_tof[0]; // tr->x[0];
1106     Double_t E11y = ptt->ytr_tof[0]; //tr->y[0];
1107     Double_t E11z = zin[0];
1108     Double_t E22x = ptt->xtr_tof[3];//tr->x[3];
1109     Double_t E22y = ptt->ytr_tof[3];//tr->y[3];
1110     Double_t E22z = zin[3];
1111 mocchiut 1.32 if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1 ){
1112 mocchiut 1.30 Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1113     Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1114     if(E22x-E11x>=0 && E22y-E11y <0) MyAzim = 360. - MyAzim;
1115     if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1116     if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1117     if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1118     Px = (E22x-E11x)/norm;
1119     Py = (E22y-E11y)/norm;
1120     Pz = (E22z-E11z)/norm;
1121     //
1122 mocchiut 1.33 t_orb->trkseqno = ptt->trkseqno;
1123     //
1124     TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);
1125     t_orb->Eij.ResizeTo(Eij);
1126     t_orb->Eij = Eij;
1127     //
1128     TMatrixD Sij = PO->PamelatoGEO(Fij,Px,Py,Pz);
1129     t_orb->Sij.ResizeTo(Sij);
1130     t_orb->Sij = Sij;
1131 mocchiut 1.30 //
1132     t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);
1133 mocchiut 1.33 //
1134     //
1135     Double_t omega = PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),cos(orbitalinfo->lon+TMath::Pi()/2)-sin(orbitalinfo->lon+TMath::Pi()/2),cos(orbitalinfo->lon+TMath::Pi()/2)+sin(orbitalinfo->lon+TMath::Pi()/2),1);
1136     //
1137     t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1138     //
1139 mocchiut 1.36 if ( t_orb->pitch != t_orb->pitch ) t_orb->pitch = -1000.;
1140     if ( t_orb->cutoff != t_orb->cutoff ) t_orb->cutoff = -1000.;
1141     //
1142 mocchiut 1.33 if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1143 mocchiut 1.30 //
1144     new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1145     nn++;
1146     //
1147     t_orb->Clear();
1148     //
1149     };
1150     //
1151     };
1152     } else {
1153     if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());
1154     };
1155     //
1156 mocchiut 1.35 } else {
1157     if ( !standalone && tof->ntrk() > 0 ){
1158     //
1159     Int_t nn = 0;
1160     for(Int_t nt=0; nt < tof->ntrk(); nt++){
1161     //
1162     ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1163     if ( ptt->trkseqno != -1 ){
1164     //
1165     t_orb->trkseqno = ptt->trkseqno;
1166     //
1167     t_orb->Eij = 0;
1168     //
1169     t_orb->Sij = 0;
1170     //
1171     t_orb->pitch = -1000.;
1172     //
1173     t_orb->cutoff = -1000.;
1174     //
1175     new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1176     nn++;
1177     //
1178     t_orb->Clear();
1179     //
1180     };
1181     //
1182     };
1183     };
1184 mocchiut 1.30 };
1185     //
1186 mocchiut 1.15 // Fill the class
1187 pamelaprod 1.11 //
1188 mocchiut 1.1 OrbitalInfotr->Fill();
1189 mocchiut 1.15 //
1190 mocchiut 1.30 delete t_orb;
1191     //
1192 mocchiut 1.15 }; // loop over the events in the run
1193 mocchiut 1.1 //
1194     // Here you may want to clear some variables before processing another run
1195     //
1196 mocchiut 1.5 delete dbtime;
1197 mocchiut 1.18 if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1198     if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
1199     if ( RYPang_upper ) delete RYPang_upper;
1200     if ( RYPang_lower ) delete RYPang_lower;
1201 mocchiut 1.1 }; // process all the runs
1202 mocchiut 1.15
1203 mocchiut 1.1 if (verbose) printf("\n Finished processing data \n");
1204     //
1205     closeandexit:
1206     //
1207     // 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.
1208     //
1209     if ( !reprocall && reproc && code >= 0 ){
1210     if ( totfileentries > noaftrun ){
1211     if (verbose){
1212     printf("\n Post-processing: copying events from the old tree after the processed run\n");
1213     printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
1214     printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
1215     }
1216     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1217     //
1218     // Get entry from old tree
1219     //
1220     OrbitalInfotrclone->GetEntry(j);
1221     //
1222     // copy orbitalinfoclone to OrbitalInfo
1223     //
1224 mocchiut 1.3 orbitalinfo->Clear();
1225 mocchiut 1.5 //
1226 mocchiut 1.1 memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
1227     //
1228     // Fill entry in the new tree
1229     //
1230     OrbitalInfotr->Fill();
1231     };
1232     if (verbose) printf(" Finished successful copying!\n");
1233     };
1234     };
1235     //
1236     // Close files, delete old tree(s), write and close level2 file
1237     //
1238     if ( l0File ) l0File->Close();
1239     if ( tempfile ) tempfile->Close();
1240 mocchiut 1.23 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1241 mocchiut 1.5 //
1242 mocchiut 1.1 if ( runinfo ) runinfo->Close();
1243     if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");
1244 mocchiut 1.30 if ( tof ) tof->Delete();
1245     if ( ttof ) ttof->Delete();
1246     //
1247 mocchiut 1.1 if ( file ){
1248     file->cd();
1249     file->Write();
1250     };
1251     //
1252 mocchiut 1.23 if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1253 mocchiut 1.1 //
1254     // the end
1255     //
1256 mocchiut 1.25 if ( dbc ){
1257     dbc->Close();
1258     delete dbc;
1259     };
1260 mocchiut 1.1 if (verbose) printf("\n Exiting...\n");
1261     if(OrbitalInfotr)OrbitalInfotr->Delete();
1262 mocchiut 1.4 //
1263 mocchiut 1.30 if ( PO ) delete PO;
1264 mocchiut 1.4 if ( orbitalinfo ) delete orbitalinfo;
1265     if ( orbitalinfoclone ) delete orbitalinfoclone;
1266     if ( glroot ) delete glroot;
1267     if ( runinfo ) delete runinfo;
1268     //
1269 mocchiut 1.1 if(code < 0) throw code;
1270     return(code);
1271     }
1272    
1273 mocchiut 1.7
1274     //
1275     // Returns the cCoordGeo structure holding the geographical
1276     // coordinates for the event (see sgp4.h).
1277     //
1278     // atime is the abstime of the event in UTC unix time.
1279     // tletime is the time of the tle in UTC unix time.
1280     // tle is the previous and nearest tle (compared to atime).
1281     cCoordGeo getCoo(UInt_t atime, UInt_t tletime, cTle *tle)
1282     {
1283     cEci eci;
1284     cOrbit orbit(*tle);
1285     orbit.getPosition((double) (atime - tletime)/60., &eci);
1286    
1287     return eci.toGeo();
1288     }
1289 mocchiut 1.15
1290     // function of copyng of quatrnions classes
1291    
1292     void CopyQ(Quaternions *Q1, Quaternions *Q2){
1293     for(UInt_t i = 0; i < 6; i++){
1294     Q1->time[i]=Q2->time[i];
1295     for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j];
1296     }
1297     return;
1298     }
1299    
1300     // functions of copyng InclinationInfo classes
1301    
1302     void CopyAng(InclinationInfo *A1, InclinationInfo *A2){
1303     A1->Tangazh = A2->Tangazh;
1304     A1->Ryskanie = A2->Ryskanie;
1305     A1->Kren = A2->Kren;
1306     return;
1307     }
1308    
1309     UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
1310    
1311     UInt_t hole = 10;
1312     bool R10l = false; // Sign of R10 mode in lower quaternions array
1313     bool R10u = false; // Sign of R10 mode in upper quaternions array
1314     bool insm = false; // Sign that we inside quaternions array
1315     bool mxtml = false; // Sign of mixt mode in lower quaternions array
1316     bool mxtmu = false; // Sign of mixt mode in upper quaternions array
1317     bool npasm = false; // Sign of normall pass between R10 and non R10 or between non R10 and R10
1318     UInt_t NCQl = 6; // Number of correct quaternions in lower array
1319     UInt_t NCQu = 6; // Number of correct quaternions in upper array
1320     if (f>0){
1321     insm = true;
1322     if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false;
1323     if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true;
1324     }else{
1325     insm = false;
1326     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true;
1327     if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true;
1328     if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false;
1329     if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false;
1330     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){
1331     mxtml = true;
1332     for(UInt_t i = 1; i < 6; i++){
1333     if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i;
1334     }
1335     }
1336     if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){
1337     mxtmu = true;
1338     for(UInt_t i = 1; i < 6; i++){
1339     if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i;
1340     }
1341     }
1342     }
1343    
1344     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;
1345    
1346    
1347     if (R10u&&insm) hole=0; // best event R10
1348     if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct
1349     if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10
1350     if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10
1351     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
1352     if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10
1353     if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10
1354     if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10
1355     if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10
1356     if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10
1357     return hole;
1358     }
1359    

  ViewVC Help
Powered by ViewVC 1.1.23