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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.1.4  
changed lines
  Added in v.1.15

  ViewVC Help
Powered by ViewVC 1.1.23