/[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.5 by mocchiut, Tue Sep 5 14:49:45 2006 UTC revision 1.25 by mocchiut, Sun Sep 9 18:57:29 2007 UTC
# 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>
34  #include <PscuHeader.h>  #include <PscuHeader.h>
35  #include <PscuEvent.h>  #include <PscuEvent.h>
36  #include <EventHeader.h>  #include <EventHeader.h>
37  //  #include <mcmd/McmdEvent.h>
38  // RunInfo header  #include <mcmd/McmdRecord.h>
 //  
 #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 47  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[]){  int OrbitalInfoCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){
54      //
55    Int_t i = 0;    Int_t i = 0;
56      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    //    //
61    TString processFolder = "OrbitalInfoFolder";    TString processFolder = Form("OrbitalInfoFolder_%u",run);
62    //    //
63    // Set these to true to have a very verbose output.    // Set these to true to have a very verbose output.
64    //    //
# Line 70  int OrbitalInfoCore(UInt_t run, TFile *f Line 78  int OrbitalInfoCore(UInt_t run, TFile *f
78        };        };
79        if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {        if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {
80          verbose = true;          verbose = true;
81            debug = true;
82        };        };
83        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {
84          verbose = true;          verbose = true;
# Line 82  int OrbitalInfoCore(UInt_t run, TFile *f Line 91  int OrbitalInfoCore(UInt_t run, TFile *f
91    //    //
92    TTree *OrbitalInfotr = 0;    TTree *OrbitalInfotr = 0;
93    UInt_t nevents = 0;    UInt_t nevents = 0;
94      UInt_t neventsm = 0;
95    //    //
96    // variables needed to reprocess data    // variables needed to reprocess data
97    //    //
98      Long64_t maxsize = 10000000000LL;  
99      TTree::SetMaxTreeSize(maxsize);
100      //
101    TString OrbitalInfoversion;    TString OrbitalInfoversion;
102    ItoRunInfo *runinfo = 0;    ItoRunInfo *runinfo = 0;
103    TArrayI *runlist = 0;    TArrayI *runlist = 0;
# Line 97  int OrbitalInfoCore(UInt_t run, TFile *f Line 110  int OrbitalInfoCore(UInt_t run, TFile *f
110    stringstream ftmpname;    stringstream ftmpname;
111    TString fname;    TString fname;
112    UInt_t totfileentries = 0;    UInt_t totfileentries = 0;
113    UInt_t idRun = 0;    UInt_t idRun = 0;
114      //
115      // My variables. Vitaly.
116      //
117      //  UInt_t iev = 0;
118      //  UInt_t j3 = 0;
119      UInt_t oi = 0;
120      Int_t tmpSize = 0;
121    //    //
122    // variables needed to handle error signals    // variables needed to handle error signals
123    //    //
# Line 113  int OrbitalInfoCore(UInt_t run, TFile *f Line 133  int OrbitalInfoCore(UInt_t run, TFile *f
133    //    //
134    TFile *l0File = 0;    TFile *l0File = 0;
135    TTree *l0tr = 0;    TTree *l0tr = 0;
136      TTree *l0trm = 0;
137    // EM: open also header branch    // EM: open also header branch
138    TBranch *l0head = 0;    TBranch *l0head = 0;
139    pamela::EventHeader *eh = 0;    pamela::EventHeader *eh = 0;
140    pamela::PscuHeader *ph = 0;    pamela::PscuHeader *ph = 0;
141      pamela::McmdEvent *mcmdev = 0;
142      pamela::McmdRecord *mcmdrc = 0;
143    // end EM    // end EM
144      
145      //  pamela::RunHeaderEvent *reh = new pamela::RunHeaderEvent;
146      //  pamela::EventHeader    *eH  = new pamela::EventHeader;
147      
148    //    //
149    // Define other basic variables    // Define other basic variables
150    //    //
# Line 128  int OrbitalInfoCore(UInt_t run, TFile *f Line 155  int OrbitalInfoCore(UInt_t run, TFile *f
155    Int_t totevent = 0;    Int_t totevent = 0;
156    UInt_t atime = 0;    UInt_t atime = 0;
157    UInt_t re = 0;    UInt_t re = 0;
158      UInt_t ik = 0;
159    
160      // Position
161      Float_t lon, lat, alt;
162    
163      //
164      // IGRF stuff
165      //
166      float dimo = 0.0; // dipole moment (computed from dat files)
167      float bnorth, beast, bdown, babs;
168      float xl; // L value
169      float icode; // code value for L accuracy (see fortran code)
170      float bab1; // What's  the difference with babs?
171      float stps = 0.005; // step size for field line tracing
172      float bdel = 0.01; // required accuracy
173      float bequ;  // equatorial b value (also called b_0)
174      bool value = 0; // false if bequ is not the minimum b value
175      float rr0; // equatorial radius normalized to earth radius
176    
177    //    //
178    // Working filename    // Working filename
179    //    //
# Line 142  int OrbitalInfoCore(UInt_t run, TFile *f Line 188  int OrbitalInfoCore(UInt_t run, TFile *f
188    TTree *tempOrbitalInfo = 0;    TTree *tempOrbitalInfo = 0;
189    stringstream tempname;    stringstream tempname;
190    stringstream OrbitalInfofolder;    stringstream OrbitalInfofolder;
191      Bool_t myfold = false;
192    tempname.str("");    tempname.str("");
193    tempname << outDir;    tempname << outDir;
194    tempname << "/" << processFolder.Data();    tempname << "/" << processFolder.Data();
195    OrbitalInfofolder.str("");    OrbitalInfofolder.str("");
196    OrbitalInfofolder << tempname.str().c_str();    OrbitalInfofolder << tempname.str().c_str();
   gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());  
197    tempname << "/OrbitalInfotree_run";    tempname << "/OrbitalInfotree_run";
198    tempname << run << ".root";      tempname << run << ".root";  
199    //    //
# Line 155  int OrbitalInfoCore(UInt_t run, TFile *f Line 201  int OrbitalInfoCore(UInt_t run, TFile *f
201    //    //
202    GL_ROOT *glroot = new GL_ROOT();    GL_ROOT *glroot = new GL_ROOT();
203    GL_TIMESYNC *dbtime = 0;    GL_TIMESYNC *dbtime = 0;
204      GL_TLE *gltle = new GL_TLE();
205      //
206      //Quaternions classes
207      //
208      Quaternions *L_QQ_Q_l_lower = new Quaternions();
209      InclinationInfo *RYPang_lower = new InclinationInfo();
210      Quaternions *L_QQ_Q_l_upper = new Quaternions();
211      InclinationInfo *RYPang_upper = new InclinationInfo();
212      
213      cEci eCi;
214      
215      // Initialize fortran routines!!!
216      Int_t ltp2 = 0;
217      Int_t ltp3 = 0;
218      Int_t uno = 1;
219      char *niente = " ";
220      GL_PARAM *glparam = new GL_PARAM();
221      GL_PARAM *glparam2 = new GL_PARAM();
222      Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table
223      
224      if ( parerror<0 ) {
225        code = parerror;
226        goto closeandexit;
227      };
228      ltp2 = (Int_t)(glparam->PATH+glparam->NAME).Length();
229      if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
230      //
231      parerror=glparam2->Query_GL_PARAM(1,302,dbc); // parameters stored in DB in GL_PRAM table
232      if ( parerror<0 ) {
233        code = parerror;
234        goto closeandexit;
235      };
236      ltp3 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();
237      if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
238      //
239      initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);
240      //
241      // End IGRF stuff//
242      //
243    
244    //    //
245    // Let's start!    // Let's start!
246    //    //
# Line 209  int OrbitalInfoCore(UInt_t run, TFile *f Line 295  int OrbitalInfoCore(UInt_t run, TFile *f
295    // number of run to be processed    // number of run to be processed
296    //    //
297    numbofrun = runinfo->GetNoRun();    numbofrun = runinfo->GetNoRun();
298      UInt_t totnorun = runinfo->GetRunEntries();
299    //    //
300    // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run    // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run
301    //    //
# Line 229  int OrbitalInfoCore(UInt_t run, TFile *f Line 316  int OrbitalInfoCore(UInt_t run, TFile *f
316      //      //
317      // 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?
318      //      //
319        OrbitalInfotrclone->SetAutoSave(900000000000000LL);
320      reproc = true;      reproc = true;
321      //      //
322      //      //
323      if (verbose) printf("\n Preparing the pre-processing...\n");      if (verbose) printf("\n Preparing the pre-processing...\n");
324      //      //
325      if ( run == 0 ){      if ( run == 0 || totnorun == 1 ){
326        //        //
327        // we are reprocessing all the file        // we are reprocessing all the file
328        // 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 253  int OrbitalInfoCore(UInt_t run, TFile *f Line 341  int OrbitalInfoCore(UInt_t run, TFile *f
341        //        //
342        // copying old tree to a new file        // copying old tree to a new file
343        //        //
344          gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
345          myfold = true;
346        tempfile = new TFile(tempname.str().c_str(),"RECREATE");        tempfile = new TFile(tempname.str().c_str(),"RECREATE");
347        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
348        tempOrbitalInfo->SetName("OrbitalInfo-old");        tempOrbitalInfo->SetName("OrbitalInfo-old");
# Line 272  int OrbitalInfoCore(UInt_t run, TFile *f Line 362  int OrbitalInfoCore(UInt_t run, TFile *f
362    //    //
363    file->cd();    file->cd();
364    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");
365      OrbitalInfotr->SetAutoSave(900000000000000LL);
366    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);
367    //    //
368    if ( reproc && !reprocall ){    if ( reproc && !reprocall ){
# Line 280  int OrbitalInfoCore(UInt_t run, TFile *f Line 371  int OrbitalInfoCore(UInt_t run, TFile *f
371      //      //
372      tempfile = new TFile(tempname.str().c_str(),"READ");      tempfile = new TFile(tempname.str().c_str(),"READ");
373      OrbitalInfotrclone = (TTree*)tempfile->Get("OrbitalInfo-old");      OrbitalInfotrclone = (TTree*)tempfile->Get("OrbitalInfo-old");
374        OrbitalInfotrclone->SetAutoSave(900000000000000LL);
375      OrbitalInfotrclone->SetBranchAddress("OrbitalInfo",&orbitalinfoclone);      OrbitalInfotrclone->SetBranchAddress("OrbitalInfo",&orbitalinfoclone);
376      //            //      
377      if ( nobefrun > 0 ){      if ( nobefrun > 0 ){
378        if (verbose){        if (verbose){
379        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");  
380        printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);          printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
381        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);
382        }        }
383        for (UInt_t j = 0; j < nobefrun; j++){        for (UInt_t j = 0; j < nobefrun; j++){
384          //          //
# Line 317  int OrbitalInfoCore(UInt_t run, TFile *f Line 409  int OrbitalInfoCore(UInt_t run, TFile *f
409      //      //
410      // retrieve the first run ID to be processed using the RunInfo list      // retrieve the first run ID to be processed using the RunInfo list
411      //      //
412        
413      idRun = runlist->At(irun);      idRun = runlist->At(irun);
414      if (verbose){      if (verbose){
415        printf("\n\n\n ####################################################################### \n");        printf("\n\n\n ####################################################################### \n");
# Line 349  int OrbitalInfoCore(UInt_t run, TFile *f Line 442  int OrbitalInfoCore(UInt_t run, TFile *f
442      // prepare the timesync for the db      // prepare the timesync for the db
443      //      //
444      dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);      dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
445      
446      //      //
447      // 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.
448      //      //
# Line 358  int OrbitalInfoCore(UInt_t run, TFile *f Line 452  int OrbitalInfoCore(UInt_t run, TFile *f
452      ftmpname << glroot->PATH.Data() << "/";      ftmpname << glroot->PATH.Data() << "/";
453      ftmpname << glroot->NAME.Data();      ftmpname << glroot->NAME.Data();
454      fname = ftmpname.str().c_str();      fname = ftmpname.str().c_str();
455        ftmpname.str("");
456      //      //
457      // print out informations      // print out informations
458      //      //
459      totevent = runinfo->NEVENTS;      totevent = runinfo->NEVENTS;
460        //cout<<"totevents = "<<totevent<<"\n";
461      if (verbose){      if (verbose){
462        printf("\n LEVEL0 data file: %s \n",fname.Data());        printf("\n LEVEL0 data file: %s \n",fname.Data());
463        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);
464        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
465        printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM,runinfo->EV_FROM+totevent);        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);
466      }//      }//
467      // Open Level0 file      // Open Level0 file
468      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
# Line 400  int OrbitalInfoCore(UInt_t run, TFile *f Line 496  int OrbitalInfoCore(UInt_t run, TFile *f
496        code = -11;        code = -11;
497        goto closeandexit;        goto closeandexit;
498      };      };
499      //      //
500      if ( runinfo->EV_TO > nevents-1 ) {      if ( runinfo->EV_TO > nevents-1 ) {
501        if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");        if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");
502        l0File->Close();        l0File->Close();
# Line 408  int OrbitalInfoCore(UInt_t run, TFile *f Line 504  int OrbitalInfoCore(UInt_t run, TFile *f
504        goto closeandexit;        goto closeandexit;
505      };      };
506      //      //
507    //     TTree *tp = (TTree*)l0File->Get("RunHeader");
508    //     tp->SetBranchAddress("Header", &eH);
509    //     tp->SetBranchAddress("RunHeader", &reh);
510    //     tp->GetEntry(0);
511    //     ph = eH->GetPscuHeader();
512    //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
513    //     ULong_t ObtSync = reh->OBT_TIME_SYNC;    
514    //     if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
515    //
516        ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
517        ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
518        ULong_t DeltaOBT = TimeSync - ObtSync;
519    
520        if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
521        
522        l0trm = (TTree*)l0File->Get("Mcmd");
523        neventsm = l0trm->GetEntries();
524        //    neventsm = 0;
525        //
526        if (neventsm == 0){
527          if ( debug ) printf("InclinationInfo - WARNING: No quaternions in this File");
528          //      l0File->Close();
529          code = 900;
530          //      goto closeandexit;
531        }
532        //
533        
534        l0trm->SetBranchAddress("Mcmd", &mcmdev);
535        //    l0trm->SetBranchAddress("Header", &eh);
536        //
537        //
538        //
539        UInt_t mctren = 0;    
540        UInt_t mcreen = 0;  
541        UInt_t numrec = 0;
542        //
543        Double_t upperqtime = 0;
544        Double_t lowerqtime = 0;
545        
546        Double_t incli = 0;
547        oi = 0;
548        UInt_t ooi = 0;
549        //
550        // init quaternions sync
551        //
552        Bool_t isf = true;
553        Int_t fgh = 0;
554        //
555      // run over all the events of the run      // run over all the events of the run
556      //      //
557      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");
558      //      //
559         //
560      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
561        
562        //        //
563        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
564          if ( debug ) printf(" %i \n",procev);      
565        //        //
566        l0head->GetEntry(re);        l0head->GetEntry(re);
567        //        //
568        // absolute time of this event        // absolute time of this event
569        //        //
570        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
571        atime = dbtime->DBabsTime(ph->GetOrbitalTime());          atime = dbtime->DBabsTime(ph->GetOrbitalTime());
572        //        //
573        // paranoid check        // paranoid check
574        //        //
575        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {
576          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");
577          goto jumpev;  //      debug = true;
578        };          continue;
579          }
580        //        //
581        procev++;        procev++;
582        //        //
# Line 436  int OrbitalInfoCore(UInt_t run, TFile *f Line 584  int OrbitalInfoCore(UInt_t run, TFile *f
584        //        //
585        orbitalinfo->Clear();        orbitalinfo->Clear();
586        //        //
587        // CHANGE HERE!!!!        // Fill OBT, pkt_num and absTime
588        //        //      
589        orbitalinfo->absTime = atime;        //      ph = eh->GetPscuHeader();
       // EM: add OBT and plt_num infos from the header  
       ph = eh->GetPscuHeader();  
590        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
591        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
592        // end EM        orbitalinfo->absTime = atime;
       OrbitalInfotr->Fill();  
       //      
593        //        //
594      jumpev:        // Propagate the orbit from the tle time to atime, using SGP(D)4.
       debug = false;  
595        //        //
596      };        cCoordGeo coo;
597          float jyear=0;    
598          //
599          if(atime >= gltle->GetToTime()) {
600            if ( !gltle->Query(atime, dbc) ){
601              //      
602              // Compute the magnetic dipole moment.
603              //
604              UInt_t year, month, day, hour, min, sec;
605              //
606              TTimeStamp t = TTimeStamp(atime, kTRUE);
607              t.GetDate(kTRUE, 0, &year, &month, &day);
608              t.GetTime(kTRUE, 0, &hour, &min, &sec);
609              jyear = (float) year
610                + (month*31.+ (float) day)/365.
611                + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);
612              //
613              feldcof_(&jyear, &dimo); // get dipole moment for year
614            } else {
615              code = -56;
616              goto closeandexit;
617            };
618          }
619          coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());
620          //
621          cOrbit orbits(*gltle->GetTle());
622          //
623          if ( debug ) printf(" I am Here \n");
624          //
625          // synchronize with quaternions data
626          //
627          if ( isf && neventsm>0 ){
628            if ( debug ) printf(" I am here \n");
629            //
630            // First event
631            //
632            isf = false;
633            upperqtime = atime;
634            lowerqtime = runinfo->RUNHEADER_TIME;
635            for ( ik = 0; ik < neventsm; ik++){
636              l0trm->GetEntry(ik);
637              tmpSize = mcmdev->Records->GetEntries();
638              numrec = tmpSize;
639              for (Int_t j3 = 0;j3<tmpSize;j3++){
640                mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
641                if ((int)mcmdrc->ID1 == 226){
642                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
643                  for (UInt_t ui = 0; ui < 6; ui++){
644                    if (ui>0){
645                      if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
646                        if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){
647                          upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
648                          orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
649                          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]);
650                        }else {
651                          lowerqtime = upperqtime;
652                          upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
653                          orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
654                          RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[ui][0],L_QQ_Q_l_upper->quat[ui][1],L_QQ_Q_l_upper->quat[ui][2],L_QQ_Q_l_upper->quat[ui][3]);
655                          mcreen = j3;
656                          mctren = ik;
657                          if(fgh==0){
658                            CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
659                            CopyAng(RYPang_lower,RYPang_upper);
660                          }
661                          oi=ui;
662                          goto closethisloop;
663                        }
664                        fgh++;
665                        CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
666                        CopyAng(RYPang_lower,RYPang_upper);
667                      }
668                    }else{
669                      if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){
670                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
671                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
672                        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]);
673                      }
674                      else {
675                        lowerqtime = upperqtime;
676                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
677                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
678                        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]);
679                        mcreen = j3;
680                        mctren = ik;
681                        if(fgh==0){
682                          CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
683                          CopyAng(RYPang_lower,RYPang_upper);
684                          lowerqtime = atime-1;
685                        }
686                        oi=ui;
687                        goto closethisloop;
688                        //_0 = true;
689                      }
690                      fgh++;
691                      CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
692                      CopyAng(RYPang_lower,RYPang_upper);
693                      //_0 = true;
694                    };
695                    //cin>>grib;
696                  };
697                };
698              };
699            };
700          };
701        closethisloop:
702          //
703          if ( debug ) printf(" I am There \n");
704          //
705          if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){
706            if ( debug ) printf(" I am there \n");
707            //
708            lowerqtime = upperqtime;
709            Long64_t maxloop = 100000000LL;
710            Long64_t mn = 0;
711            bool gh=false;
712            ooi=oi;
713            if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);
714            while (!gh){      
715              if ( mn > maxloop ){
716                if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");
717                gh = true;
718                neventsm = 0;
719              };
720              mn++;
721              if (oi<5) oi++;
722              else oi=0;
723              if (oi==0){
724                mcreen++;
725                if (mcreen == numrec){
726                  mctren++;
727                  mcreen = 0;
728                  l0trm->GetEntry(mctren);
729                  numrec = mcmdev->Records->GetEntries();
730                }
731                CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
732                CopyAng(RYPang_lower,RYPang_upper);
733                mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);
734                if ((int)mcmdrc->ID1 == 226){
735                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
736                  upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
737                  if (upperqtime<lowerqtime){
738                    upperqtime=runinfo->RUNTRAILER_TIME;
739                    CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);
740                    CopyAng(RYPang_upper,RYPang_lower);
741                  }else{
742                    orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
743                    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]);
744                  }
745                  //              re--;
746                  gh=true;
747                }
748              }else{
749                if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){
750                  upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
751                  orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
752                  RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[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]);
753                  orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi);
754                  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]);
755                  //              re--;
756                  gh=true;
757                };
758              };
759            };
760            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);
761          };
762          //
763          if ( debug ) printf(" I am THIS \n");
764          //
765          // Fill in quaternions and angles
766          //
767          if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)&& neventsm>0){      
768            if ( debug ) printf(" I am this \n");
769            UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
770            if (oi == 0){
771              if ((tut!=5)||(tut!=6)){
772                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)));
773                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));
774                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)));
775                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));
776                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)));
777                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));
778                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)));
779                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));
780            
781                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)));
782                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
783                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)));
784                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
785                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)));
786                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
787              }
788              if (tut==6){
789                if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
790                  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)));
791                  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));
792                  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)));
793                  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));
794                  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)));
795                  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));
796                  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)));
797                  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));
798            
799                  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)));
800                  orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
801                  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)));
802                  orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
803                  //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";
804                  //cin>>grib;
805                  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)));
806                  orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
807                }
808              }
809            } else {
810              if((tut!=6)||(tut!=7)||(tut!=9)){
811                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)));
812                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));
813                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)));
814                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));
815                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)));
816                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));
817                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)));
818                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));
819            
820                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)));
821                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
822                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)));
823                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
824                //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";
825                //cin>>grib;
826                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)));
827                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
828              }
829              if (tut==6){
830                if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
831                  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)));
832                  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));
833                  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)));
834                  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));
835                  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)));
836                  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));
837                  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)));
838                  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));
839            
840                  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)));
841                  orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
842                  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)));
843                  orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
844                  //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";
845                  //cin>>grib;
846                  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)));
847                  orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
848                }
849              }            
850            }
851            //
852            orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
853            //
854          } else {
855            if ( debug ) printf(" ops no incl! \n");
856            orbitalinfo->mode = -1;
857          };
858      
859          //
860          // fill orbital positions
861          //        
862          // Build coordinates in the right range.  We want to convert,
863          // longitude from (0, 2*pi) to (-180deg, 180deg).  Altitude is
864          // in meters.
865          lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon);
866          lat = rad2deg(coo.m_Lat);
867          alt = coo.m_Alt;
868          //
869          if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){  
870            //      
871            orbitalinfo->lon = lon;
872            orbitalinfo->lat = lat;
873            orbitalinfo->alt = alt ;
874            //
875            // compute mag field components and L shell.
876            //
877            feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);
878            shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);
879            findb0_(&stps, &bdel, &value, &bequ, &rr0);
880            //
881            orbitalinfo->Bnorth = bnorth;
882            orbitalinfo->Beast = beast;
883            orbitalinfo->Bdown = bdown;
884            orbitalinfo->Babs = babs;
885            orbitalinfo->BB0 = babs/bequ;
886            orbitalinfo->L = xl;      
887            // Set Stormer vertical cutoff using L shell.
888            orbitalinfo->cutoff[0] = 14.9/(xl*xl);
889            //
890          };      
891          //
892          // Fill the class
893          //
894          OrbitalInfotr->Fill();
895          //
896        }; // loop over the events in the run
897      //      //
898      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
899      //      //
900      delete dbtime;      delete dbtime;
901        if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
902        if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
903        if ( RYPang_upper ) delete RYPang_upper;
904        if ( RYPang_lower ) delete RYPang_lower;
905    }; // process all the runs    }; // process all the runs
906    //    
907    if (verbose) printf("\n Finished processing data \n");    if (verbose) printf("\n Finished processing data \n");
908    //    //
909   closeandexit:   closeandexit:
# Line 494  int OrbitalInfoCore(UInt_t run, TFile *f Line 941  int OrbitalInfoCore(UInt_t run, TFile *f
941    //    //
942    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
943    if ( tempfile ) tempfile->Close();                if ( tempfile ) tempfile->Close();            
944    gSystem->Unlink(tempname.str().c_str());    if ( myfold ) gSystem->Unlink(tempname.str().c_str());
945    //    //
946    if ( runinfo ) runinfo->Close();        if ( runinfo ) runinfo->Close();    
947    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
# Line 503  int OrbitalInfoCore(UInt_t run, TFile *f Line 950  int OrbitalInfoCore(UInt_t run, TFile *f
950      file->Write();      file->Write();
951    };    };
952    //    //
953    gSystem->Unlink(OrbitalInfofolder.str().c_str());    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
954    //    //
955    // the end    // the end
956    //    //
957      if ( dbc ){
958        dbc->Close();
959        delete dbc;
960      };
961    if (verbose) printf("\n Exiting...\n");    if (verbose) printf("\n Exiting...\n");
962    if(OrbitalInfotr)OrbitalInfotr->Delete();    if(OrbitalInfotr)OrbitalInfotr->Delete();
963    //    //
# Line 519  int OrbitalInfoCore(UInt_t run, TFile *f Line 970  int OrbitalInfoCore(UInt_t run, TFile *f
970    return(code);    return(code);
971  }  }
972    
973    
974    //
975    // Returns the cCoordGeo structure holding the geographical
976    // coordinates for the event (see sgp4.h).
977    //
978    // atime is the abstime of the event in UTC unix time.
979    // tletime is the time of the tle in UTC unix time.
980    // tle is the previous and nearest tle (compared to atime).
981    cCoordGeo getCoo(UInt_t atime, UInt_t tletime, cTle *tle)
982    {
983      cEci eci;
984      cOrbit orbit(*tle);
985      orbit.getPosition((double) (atime - tletime)/60., &eci);
986      
987      return eci.toGeo();
988    }
989    
990    // function of copyng of quatrnions classes
991    
992    void CopyQ(Quaternions *Q1, Quaternions *Q2){
993      for(UInt_t i = 0; i < 6; i++){
994        Q1->time[i]=Q2->time[i];
995        for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j];
996      }
997      return;
998    }
999    
1000    // functions of copyng InclinationInfo classes
1001    
1002    void CopyAng(InclinationInfo *A1, InclinationInfo *A2){
1003      A1->Tangazh = A2->Tangazh;
1004      A1->Ryskanie = A2->Ryskanie;
1005      A1->Kren = A2->Kren;
1006      return;
1007    }
1008    
1009    UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
1010      
1011      UInt_t hole = 10;
1012      bool R10l = false;     // Sign of R10 mode in lower quaternions array
1013      bool R10u = false;     // Sign of R10 mode in upper quaternions array
1014      bool insm = false;     // Sign that we inside quaternions array
1015      bool mxtml = false;    // Sign of mixt mode in lower quaternions array
1016      bool mxtmu = false;    // Sign of mixt mode in upper quaternions array
1017      bool npasm = false;     // Sign of normall pass between R10 and non R10 or between non R10 and R10
1018      UInt_t NCQl = 6;       // Number of correct quaternions in lower array
1019      UInt_t NCQu = 6;       // Number of correct quaternions in upper array
1020      if (f>0){
1021        insm = true;
1022        if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false;
1023        if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true;
1024      }else{
1025        insm = false;
1026        if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true;
1027        if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true;
1028        if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false;
1029        if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false;
1030        if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){
1031          mxtml = true;
1032          for(UInt_t i = 1; i < 6; i++){
1033            if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i;
1034          }
1035        }
1036        if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){
1037          mxtmu = true;
1038          for(UInt_t i = 1; i < 6; i++){
1039            if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i;
1040          }
1041        }
1042      }
1043      
1044      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;
1045      
1046      
1047      if (R10u&&insm) hole=0; // best event R10
1048      if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct
1049      if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10
1050      if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10
1051      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
1052      if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10
1053      if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10
1054      if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10
1055      if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10
1056      if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10
1057      return hole;
1058    }
1059    

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.25

  ViewVC Help
Powered by ViewVC 1.1.23