/[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.10 by mocchiut, Wed Jan 24 13:16:26 2007 UTC revision 1.28 by mocchiut, Thu Sep 4 15:46:18 2008 UTC
# Line 34  Line 34 
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    #include <mcmd/McmdRecord.h>
39  //  //
40  // This program headers  // This program headers
41  //  //
42  #include <OrbitalInfo.h>  #include <OrbitalInfo.h>
43  #include <OrbitalInfoVerl2.h>  #include <OrbitalInfoVerl2.h>
44  #include <OrbitalInfoCore.h>  #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      //
 //   // Temporary check to use igrf routines.  We need dat files in the  
 //   // current directory.  
 //   fstream igrfdat1("igrf05.dat");  
 //   fstream igrfdat2("igrf05s.dat");  
 //   if( (!igrfdat1) && (!igrfdat2)) {  
 //     cerr<<"\n**************************************\n"  
 //      <<"igrf05.dat or igrf05s.dat not in the current directory.  Exiting.\n"  
 //      <<"**************************************\n";  
 //     exit(EXIT_FAILURE);  
 //   }  
 //   igrfdat1.close();  
 //   igrfdat2.close();  
 //   // end of temporary code  
 //   //  
   
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      stringstream myquery;
62      myquery.str("");
63      myquery << "SET time_zone='+0:00'";
64      dbc->Query(myquery.str().c_str());
65    //    //
66    TString processFolder = "OrbitalInfoFolder";    TString processFolder = Form("OrbitalInfoFolder_%u",run);
67    //    //
68    // Set these to true to have a very verbose output.    // Set these to true to have a very verbose output.
69    //    //
# Line 86  int OrbitalInfoCore(UInt_t run, TFile *f Line 83  int OrbitalInfoCore(UInt_t run, TFile *f
83        };        };
84        if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {        if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {
85          verbose = true;          verbose = true;
86            debug = true;
87        };        };
88        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {
89          verbose = true;          verbose = true;
# Line 98  int OrbitalInfoCore(UInt_t run, TFile *f Line 96  int OrbitalInfoCore(UInt_t run, TFile *f
96    //    //
97    TTree *OrbitalInfotr = 0;    TTree *OrbitalInfotr = 0;
98    UInt_t nevents = 0;    UInt_t nevents = 0;
99      UInt_t neventsm = 0;
100    //    //
101    // variables needed to reprocess data    // variables needed to reprocess data
102    //    //
# Line 116  int OrbitalInfoCore(UInt_t run, TFile *f Line 115  int OrbitalInfoCore(UInt_t run, TFile *f
115    stringstream ftmpname;    stringstream ftmpname;
116    TString fname;    TString fname;
117    UInt_t totfileentries = 0;    UInt_t totfileentries = 0;
118    UInt_t idRun = 0;    UInt_t idRun = 0;
119      //
120      // My variables. Vitaly.
121      //
122      //  UInt_t iev = 0;
123      //  UInt_t j3 = 0;
124      UInt_t oi = 0;
125      Int_t tmpSize = 0;
126    //    //
127    // variables needed to handle error signals    // variables needed to handle error signals
128    //    //
# Line 132  int OrbitalInfoCore(UInt_t run, TFile *f Line 138  int OrbitalInfoCore(UInt_t run, TFile *f
138    //    //
139    TFile *l0File = 0;    TFile *l0File = 0;
140    TTree *l0tr = 0;    TTree *l0tr = 0;
141      TTree *l0trm = 0;
142    // EM: open also header branch    // EM: open also header branch
143    TBranch *l0head = 0;    TBranch *l0head = 0;
144    pamela::EventHeader *eh = 0;    pamela::EventHeader *eh = 0;
145    pamela::PscuHeader *ph = 0;    pamela::PscuHeader *ph = 0;
146      pamela::McmdEvent *mcmdev = 0;
147      pamela::McmdRecord *mcmdrc = 0;
148    // end EM    // end EM
149      
150      //  pamela::RunHeaderEvent *reh = new pamela::RunHeaderEvent;
151      //  pamela::EventHeader    *eH  = new pamela::EventHeader;
152      
153    //    //
154    // Define other basic variables    // Define other basic variables
155    //    //
# Line 147  int OrbitalInfoCore(UInt_t run, TFile *f Line 160  int OrbitalInfoCore(UInt_t run, TFile *f
160    Int_t totevent = 0;    Int_t totevent = 0;
161    UInt_t atime = 0;    UInt_t atime = 0;
162    UInt_t re = 0;    UInt_t re = 0;
163      UInt_t ik = 0;
164    
165    // Position    // Position
166    Float_t lon, lat, alt;    Float_t lon, lat, alt;
# Line 179  int OrbitalInfoCore(UInt_t run, TFile *f Line 193  int OrbitalInfoCore(UInt_t run, TFile *f
193    TTree *tempOrbitalInfo = 0;    TTree *tempOrbitalInfo = 0;
194    stringstream tempname;    stringstream tempname;
195    stringstream OrbitalInfofolder;    stringstream OrbitalInfofolder;
196      Bool_t myfold = false;
197    tempname.str("");    tempname.str("");
198    tempname << outDir;    tempname << outDir;
199    tempname << "/" << processFolder.Data();    tempname << "/" << processFolder.Data();
200    OrbitalInfofolder.str("");    OrbitalInfofolder.str("");
201    OrbitalInfofolder << tempname.str().c_str();    OrbitalInfofolder << tempname.str().c_str();
   gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());  
202    tempname << "/OrbitalInfotree_run";    tempname << "/OrbitalInfotree_run";
203    tempname << run << ".root";      tempname << run << ".root";  
204    //    //
# Line 193  int OrbitalInfoCore(UInt_t run, TFile *f Line 207  int OrbitalInfoCore(UInt_t run, TFile *f
207    GL_ROOT *glroot = new GL_ROOT();    GL_ROOT *glroot = new GL_ROOT();
208    GL_TIMESYNC *dbtime = 0;    GL_TIMESYNC *dbtime = 0;
209    GL_TLE *gltle = new GL_TLE();    GL_TLE *gltle = new GL_TLE();
210      //
211      //Quaternions classes
212      //
213      Quaternions *L_QQ_Q_l_lower = new Quaternions();
214      InclinationInfo *RYPang_lower = new InclinationInfo();
215      Quaternions *L_QQ_Q_l_upper = new Quaternions();
216      InclinationInfo *RYPang_upper = new InclinationInfo();
217      
218      cEci eCi;
219      
220    // Initialize fortran routines!!!    // Initialize fortran routines!!!
221    Int_t ltp2 = 0;    Int_t ltp2 = 0;
222    Int_t ltp3 = 0;    Int_t ltp3 = 0;
# Line 201  int OrbitalInfoCore(UInt_t run, TFile *f Line 225  int OrbitalInfoCore(UInt_t run, TFile *f
225    GL_PARAM *glparam = new GL_PARAM();    GL_PARAM *glparam = new GL_PARAM();
226    GL_PARAM *glparam2 = new GL_PARAM();    GL_PARAM *glparam2 = new GL_PARAM();
227    Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table    Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table
228      
229    if ( parerror<0 ) {    if ( parerror<0 ) {
230      code = parerror;      code = parerror;
231      goto closeandexit;      goto closeandexit;
# Line 217  int OrbitalInfoCore(UInt_t run, TFile *f Line 242  int OrbitalInfoCore(UInt_t run, TFile *f
242    if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());    if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
243    //    //
244    initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);    initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);
   
245    //    //
246    // End IGRF stuff//    // End IGRF stuff//
247    //    //
# Line 276  int OrbitalInfoCore(UInt_t run, TFile *f Line 300  int OrbitalInfoCore(UInt_t run, TFile *f
300    // number of run to be processed    // number of run to be processed
301    //    //
302    numbofrun = runinfo->GetNoRun();    numbofrun = runinfo->GetNoRun();
303      UInt_t totnorun = runinfo->GetRunEntries();
304    //    //
305    // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run    // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run
306    //    //
# Line 302  int OrbitalInfoCore(UInt_t run, TFile *f Line 327  int OrbitalInfoCore(UInt_t run, TFile *f
327      //      //
328      if (verbose) printf("\n Preparing the pre-processing...\n");      if (verbose) printf("\n Preparing the pre-processing...\n");
329      //      //
330      if ( run == 0 ){      if ( run == 0 || totnorun == 1 ){
331        //        //
332        // we are reprocessing all the file        // we are reprocessing all the file
333        // if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately        // 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 321  int OrbitalInfoCore(UInt_t run, TFile *f Line 346  int OrbitalInfoCore(UInt_t run, TFile *f
346        //        //
347        // copying old tree to a new file        // copying old tree to a new file
348        //        //
349          gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
350          myfold = true;
351        tempfile = new TFile(tempname.str().c_str(),"RECREATE");        tempfile = new TFile(tempname.str().c_str(),"RECREATE");
352        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
353        tempOrbitalInfo->SetName("OrbitalInfo-old");        tempOrbitalInfo->SetName("OrbitalInfo-old");
# Line 387  int OrbitalInfoCore(UInt_t run, TFile *f Line 414  int OrbitalInfoCore(UInt_t run, TFile *f
414      //      //
415      // retrieve the first run ID to be processed using the RunInfo list      // retrieve the first run ID to be processed using the RunInfo list
416      //      //
417        
418      idRun = runlist->At(irun);      idRun = runlist->At(irun);
419      if (verbose){      if (verbose){
420        printf("\n\n\n ####################################################################### \n");        printf("\n\n\n ####################################################################### \n");
# Line 419  int OrbitalInfoCore(UInt_t run, TFile *f Line 447  int OrbitalInfoCore(UInt_t run, TFile *f
447      // prepare the timesync for the db      // prepare the timesync for the db
448      //      //
449      dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);      dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
450      
451      //      //
452      // 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.
453      //      //
# Line 428  int OrbitalInfoCore(UInt_t run, TFile *f Line 457  int OrbitalInfoCore(UInt_t run, TFile *f
457      ftmpname << glroot->PATH.Data() << "/";      ftmpname << glroot->PATH.Data() << "/";
458      ftmpname << glroot->NAME.Data();      ftmpname << glroot->NAME.Data();
459      fname = ftmpname.str().c_str();      fname = ftmpname.str().c_str();
460        ftmpname.str("");
461      //      //
462      // print out informations      // print out informations
463      //      //
464      totevent = runinfo->NEVENTS;      totevent = runinfo->NEVENTS;
465        //cout<<"totevents = "<<totevent<<"\n";
466      if (verbose){      if (verbose){
467        printf("\n LEVEL0 data file: %s \n",fname.Data());        printf("\n LEVEL0 data file: %s \n",fname.Data());
468        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);
469        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
470        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);
471      }//      }//
472        //
473        //    if ( !totevent ) goto closeandexit;
474      // Open Level0 file      // Open Level0 file
475      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
476      if ( !l0File ) {      if ( !l0File ) {
# Line 464  int OrbitalInfoCore(UInt_t run, TFile *f Line 497  int OrbitalInfoCore(UInt_t run, TFile *f
497      // end EM      // end EM
498      nevents = l0head->GetEntries();      nevents = l0head->GetEntries();
499      //      //
500      if ( nevents < 1 ) {      if ( nevents < 1 && totevent ) {
501        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
502        l0File->Close();        l0File->Close();
503        code = -11;        code = -11;
504        goto closeandexit;        goto closeandexit;
505      };      };
506      //      //
507      if ( runinfo->EV_TO > nevents-1 ) {      if ( runinfo->EV_TO > nevents-1 && totevent ) {
508        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");
509        l0File->Close();        l0File->Close();
510        code = -12;        code = -12;
511        goto closeandexit;        goto closeandexit;
512      };      };
513      //      //
514    //     TTree *tp = (TTree*)l0File->Get("RunHeader");
515    //     tp->SetBranchAddress("Header", &eH);
516    //     tp->SetBranchAddress("RunHeader", &reh);
517    //     tp->GetEntry(0);
518    //     ph = eH->GetPscuHeader();
519    //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
520    //     ULong_t ObtSync = reh->OBT_TIME_SYNC;    
521    //     if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
522    //
523        ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
524        ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
525        ULong_t DeltaOBT = TimeSync - ObtSync;
526    
527        if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
528        
529        l0trm = (TTree*)l0File->Get("Mcmd");
530        neventsm = l0trm->GetEntries();
531        //    neventsm = 0;
532        //
533        if (neventsm == 0){
534          if ( debug ) printf("InclinationInfo - WARNING: No quaternions in this File");
535          //      l0File->Close();
536          code = 900;
537          //      goto closeandexit;
538        }
539        //
540        
541        l0trm->SetBranchAddress("Mcmd", &mcmdev);
542        //    l0trm->SetBranchAddress("Header", &eh);
543        //
544        //
545        //
546        UInt_t mctren = 0;    
547        UInt_t mcreen = 0;  
548        UInt_t numrec = 0;
549        //
550        Double_t upperqtime = 0;
551        Double_t lowerqtime = 0;
552        
553        Double_t incli = 0;
554        oi = 0;
555        UInt_t ooi = 0;
556        //
557        // init quaternions sync
558        //
559        Bool_t isf = true;
560        Int_t fgh = 0;
561        //
562      // run over all the events of the run      // run over all the events of the run
563      //      //
564      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");
565      //      //
566         //
567      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
568        
569        //        //
570        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
571          if ( debug ) printf(" %i \n",procev);      
572        //        //
573        l0head->GetEntry(re);        l0head->GetEntry(re);
574        //        //
575        // absolute time of this event        // absolute time of this event
576        //        //
577        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
578        atime = dbtime->DBabsTime(ph->GetOrbitalTime());          atime = dbtime->DBabsTime(ph->GetOrbitalTime());
579        //        //
580        // paranoid check        // paranoid check
581        //        //
582        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {
583          if (verbose) printf(" OrbitalInfo - WARNING: event at time outside the run time window, skipping it\n");          if (verbose) printf(" OrbitalInfo - WARNING: event at time outside the run time window, skipping it\n");
584          debug = true;  //      debug = true;
585          continue;          continue;
586        }        }
587        //        //
# Line 507  int OrbitalInfoCore(UInt_t run, TFile *f Line 591  int OrbitalInfoCore(UInt_t run, TFile *f
591        //        //
592        orbitalinfo->Clear();        orbitalinfo->Clear();
593        //        //
594        // CHANGE HERE!!!!        // Fill OBT, pkt_num and absTime
595        //        //      
596        orbitalinfo->absTime = atime;        //      ph = eh->GetPscuHeader();
       // EM: add OBT and plt_num infos from the header  
       ph = eh->GetPscuHeader();  
597        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
598        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
599          orbitalinfo->absTime = atime;
600        // If the absolute time of the event overpass the time of the        //
601        // tle, get a new tle.  GL_TLE::GetToTime() default to zero.        // Propagate the orbit from the tle time to atime, using SGP(D)4.
602          //
603          cCoordGeo coo;
604          float jyear=0;    
605        //        //
       // I also use this condition to compute the dipole moment dimo.  
       // It's really redundant to compute it so often because  
       // probably it will not change at all.  But the overhead is  
       // minimum.  
       float jyear=0;  
   
606        if(atime >= gltle->GetToTime()) {        if(atime >= gltle->GetToTime()) {
607          if ( !gltle->Query(atime, dbc) ){          if ( !gltle->Query(atime, dbc) ){
608                        //      
609            // Compute the magnetic dipole moment.            // Compute the magnetic dipole moment.
610              //
611            UInt_t year, month, day, hour, min, sec;            UInt_t year, month, day, hour, min, sec;
612                        //
613            TTimeStamp t = TTimeStamp(atime, kTRUE);            TTimeStamp t = TTimeStamp(atime, kTRUE);
614            t.GetDate(kTRUE, 0, &year, &month, &day);            t.GetDate(kTRUE, 0, &year, &month, &day);
615            t.GetTime(kTRUE, 0, &hour, &min, &sec);            t.GetTime(kTRUE, 0, &hour, &min, &sec);
616            jyear = (float) year            jyear = (float) year
617              + (month*31.+ (float) day)/365.              + (month*31.+ (float) day)/365.
618              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);
619                        //
620            feldcof_(&jyear, &dimo); // get dipole moment for year            feldcof_(&jyear, &dimo); // get dipole moment for year
621          } else {          } else {
622            code = -56;            code = -56;
623            goto closeandexit;            goto closeandexit;
624          };          };
625        }        }
626          coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());
627        // Propagate the orbit from the tle time to atime, using SGP(D)4.        //
628        cCoordGeo coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());        cOrbit orbits(*gltle->GetTle());
629          //
630          if ( debug ) printf(" I am Here \n");
631          //
632          // synchronize with quaternions data
633          //
634          if ( isf && neventsm>0 ){
635            if ( debug ) printf(" I am here \n");
636            //
637            // First event
638            //
639            isf = false;
640            upperqtime = atime;
641            lowerqtime = runinfo->RUNHEADER_TIME;
642            for ( ik = 0; ik < neventsm; ik++){
643              l0trm->GetEntry(ik);
644              tmpSize = mcmdev->Records->GetEntries();
645              numrec = tmpSize;
646              for (Int_t j3 = 0;j3<tmpSize;j3++){
647                mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
648                if ((int)mcmdrc->ID1 == 226){
649                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
650                  for (UInt_t ui = 0; ui < 6; ui++){
651                    if (ui>0){
652                      if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
653                        if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){
654                          upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
655                          orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
656                          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]);
657                        }else {
658                          lowerqtime = upperqtime;
659                          upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
660                          orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
661                          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]);
662                          mcreen = j3;
663                          mctren = ik;
664                          if(fgh==0){
665                            CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
666                            CopyAng(RYPang_lower,RYPang_upper);
667                          }
668                          oi=ui;
669                          goto closethisloop;
670                        }
671                        fgh++;
672                        CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
673                        CopyAng(RYPang_lower,RYPang_upper);
674                      }
675                    }else{
676                      if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){
677                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
678                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
679                        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]);
680                      }
681                      else {
682                        lowerqtime = upperqtime;
683                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
684                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
685                        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]);
686                        mcreen = j3;
687                        mctren = ik;
688                        if(fgh==0){
689                          CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
690                          CopyAng(RYPang_lower,RYPang_upper);
691                          lowerqtime = atime-1;
692                        }
693                        oi=ui;
694                        goto closethisloop;
695                        //_0 = true;
696                      }
697                      fgh++;
698                      CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
699                      CopyAng(RYPang_lower,RYPang_upper);
700                      //_0 = true;
701                    };
702                    //cin>>grib;
703                  };
704                };
705              };
706            };
707          };
708        closethisloop:
709          //
710          if ( debug ) printf(" I am There \n");
711          //
712          if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){
713            if ( debug ) printf(" I am there \n");
714            //
715            lowerqtime = upperqtime;
716            Long64_t maxloop = 100000000LL;
717            Long64_t mn = 0;
718            bool gh=false;
719            ooi=oi;
720            if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);
721            while (!gh){      
722              if ( mn > maxloop ){
723                if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");
724                gh = true;
725                neventsm = 0;
726              };
727              mn++;
728              if (oi<5) oi++;
729              else oi=0;
730              if (oi==0){
731                mcreen++;
732                if (mcreen == numrec){
733                  mctren++;
734                  mcreen = 0;
735                  l0trm->GetEntry(mctren);
736                  numrec = mcmdev->Records->GetEntries();
737                }
738                CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
739                CopyAng(RYPang_lower,RYPang_upper);
740                mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);
741                if ((int)mcmdrc->ID1 == 226){
742                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
743                  upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
744                  if (upperqtime<lowerqtime){
745                    upperqtime=runinfo->RUNTRAILER_TIME;
746                    CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);
747                    CopyAng(RYPang_upper,RYPang_lower);
748                  }else{
749                    orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
750                    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]);
751                  }
752                  //              re--;
753                  gh=true;
754                }
755              }else{
756                if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){
757                  upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
758                  orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
759                  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]);
760                  orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi);
761                  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]);
762                  //              re--;
763                  gh=true;
764                };
765              };
766            };
767            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);
768          };
769          //
770          if ( debug ) printf(" I am THIS \n");
771          //
772          // Fill in quaternions and angles
773          //
774          if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)&& neventsm>0){      
775            if ( debug ) printf(" I am this \n");
776            UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
777            if (oi == 0){
778              if ((tut!=5)||(tut!=6)){
779                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)));
780                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));
781                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)));
782                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));
783                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)));
784                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));
785                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)));
786                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));
787            
788                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)));
789                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
790                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)));
791                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
792                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)));
793                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
794              }
795              if (tut==6){
796                if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
797                  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)));
798                  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));
799                  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)));
800                  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));
801                  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)));
802                  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));
803                  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)));
804                  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));
805            
806                  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)));
807                  orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
808                  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)));
809                  orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
810                  //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";
811                  //cin>>grib;
812                  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)));
813                  orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
814                }
815              }
816            } else {
817              if((tut!=6)||(tut!=7)||(tut!=9)){
818                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)));
819                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));
820                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)));
821                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));
822                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)));
823                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));
824                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)));
825                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));
826            
827                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)));
828                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
829                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)));
830                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
831                //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";
832                //cin>>grib;
833                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)));
834                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
835              }
836              if (tut==6){
837                if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
838                  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)));
839                  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));
840                  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)));
841                  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));
842                  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)));
843                  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));
844                  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)));
845                  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));
846            
847                  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)));
848                  orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
849                  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)));
850                  orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
851                  //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";
852                  //cin>>grib;
853                  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)));
854                  orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
855                }
856              }            
857            }
858            //
859            orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
860            //
861          } else {
862            if ( debug ) printf(" ops no incl! \n");
863            orbitalinfo->mode = -1;
864          };
865      
866          //
867          // fill orbital positions
868          //        
869        // Build coordinates in the right range.  We want to convert,        // Build coordinates in the right range.  We want to convert,
870        // longitude from (0, 2*pi) to (-180deg, 180deg).  Altitude is        // longitude from (0, 2*pi) to (-180deg, 180deg).  Altitude is
871        // in meters.        // in meters.
872        lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon);        lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon);
873        lat = rad2deg(coo.m_Lat);        lat = rad2deg(coo.m_Lat);
874        alt = coo.m_Alt;        alt = coo.m_Alt;
875          //
   
       //      if((lon>180) || (lon<-180) || (lat>90) || (lat<-90) || (alt<0))  
       //        continue;  
876        if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){          if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){  
877            //      
878          orbitalinfo->lon = lon;          orbitalinfo->lon = lon;
879          orbitalinfo->lat = lat;          orbitalinfo->lat = lat;
880          orbitalinfo->alt = alt ;          orbitalinfo->alt = alt ;
881                    //
882          // compute mag field components and L shell.          // compute mag field components and L shell.
883            //
884          feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);          feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);
885          shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);          shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);
886          findb0_(&stps, &bdel, &value, &bequ, &rr0);          findb0_(&stps, &bdel, &value, &bequ, &rr0);
887                    //
888          orbitalinfo->Bnorth = bnorth;          orbitalinfo->Bnorth = bnorth;
889          orbitalinfo->Beast = beast;          orbitalinfo->Beast = beast;
890          orbitalinfo->Bdown = bdown;          orbitalinfo->Bdown = bdown;
891          orbitalinfo->Babs = babs;          orbitalinfo->Babs = babs;
892          orbitalinfo->BB0 = babs/bequ;          orbitalinfo->BB0 = babs/bequ;
893          orbitalinfo->L = xl;          orbitalinfo->L = xl;      
           
894          // Set Stormer vertical cutoff using L shell.          // Set Stormer vertical cutoff using L shell.
895          orbitalinfo->cutoff[0] = 14.9/(xl*xl);          orbitalinfo->cutoff[0] = 14.9/(xl*xl);
896        };          //
897                };      
898        // end EM        //
899          // Fill the class
900          //
901        OrbitalInfotr->Fill();        OrbitalInfotr->Fill();
902      }        //
903            }; // loop over the events in the run
904      //      //
905      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
906      //      //
907      delete dbtime;      delete dbtime;
908        if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
909        if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
910        if ( RYPang_upper ) delete RYPang_upper;
911        if ( RYPang_lower ) delete RYPang_lower;
912    }; // process all the runs    }; // process all the runs
913    //    
914    if (verbose) printf("\n Finished processing data \n");    if (verbose) printf("\n Finished processing data \n");
915    //    //
916   closeandexit:   closeandexit:
# Line 626  int OrbitalInfoCore(UInt_t run, TFile *f Line 948  int OrbitalInfoCore(UInt_t run, TFile *f
948    //    //
949    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
950    if ( tempfile ) tempfile->Close();                if ( tempfile ) tempfile->Close();            
951    gSystem->Unlink(tempname.str().c_str());    if ( myfold ) gSystem->Unlink(tempname.str().c_str());
952    //    //
953    if ( runinfo ) runinfo->Close();        if ( runinfo ) runinfo->Close();    
954    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
# Line 635  int OrbitalInfoCore(UInt_t run, TFile *f Line 957  int OrbitalInfoCore(UInt_t run, TFile *f
957      file->Write();      file->Write();
958    };    };
959    //    //
960    gSystem->Unlink(OrbitalInfofolder.str().c_str());    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
961    //    //
962    // the end    // the end
963    //    //
964      if ( dbc ){
965        dbc->Close();
966        delete dbc;
967      };
968    if (verbose) printf("\n Exiting...\n");    if (verbose) printf("\n Exiting...\n");
969    if(OrbitalInfotr)OrbitalInfotr->Delete();    if(OrbitalInfotr)OrbitalInfotr->Delete();
970    //    //
# Line 663  cCoordGeo getCoo(UInt_t atime, UInt_t tl Line 989  cCoordGeo getCoo(UInt_t atime, UInt_t tl
989  {  {
990    cEci eci;    cEci eci;
991    cOrbit orbit(*tle);    cOrbit orbit(*tle);
     
992    orbit.getPosition((double) (atime - tletime)/60., &eci);    orbit.getPosition((double) (atime - tletime)/60., &eci);
993        
994    return eci.toGeo();    return eci.toGeo();
995  }  }
996    
997    // function of copyng of quatrnions classes
998    
999    void CopyQ(Quaternions *Q1, Quaternions *Q2){
1000      for(UInt_t i = 0; i < 6; i++){
1001        Q1->time[i]=Q2->time[i];
1002        for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j];
1003      }
1004      return;
1005    }
1006    
1007    // functions of copyng InclinationInfo classes
1008    
1009    void CopyAng(InclinationInfo *A1, InclinationInfo *A2){
1010      A1->Tangazh = A2->Tangazh;
1011      A1->Ryskanie = A2->Ryskanie;
1012      A1->Kren = A2->Kren;
1013      return;
1014    }
1015    
1016    UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
1017      
1018      UInt_t hole = 10;
1019      bool R10l = false;     // Sign of R10 mode in lower quaternions array
1020      bool R10u = false;     // Sign of R10 mode in upper quaternions array
1021      bool insm = false;     // Sign that we inside quaternions array
1022      bool mxtml = false;    // Sign of mixt mode in lower quaternions array
1023      bool mxtmu = false;    // Sign of mixt mode in upper quaternions array
1024      bool npasm = false;     // Sign of normall pass between R10 and non R10 or between non R10 and R10
1025      UInt_t NCQl = 6;       // Number of correct quaternions in lower array
1026      UInt_t NCQu = 6;       // Number of correct quaternions in upper array
1027      if (f>0){
1028        insm = true;
1029        if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false;
1030        if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true;
1031      }else{
1032        insm = false;
1033        if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true;
1034        if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true;
1035        if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false;
1036        if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false;
1037        if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){
1038          mxtml = true;
1039          for(UInt_t i = 1; i < 6; i++){
1040            if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i;
1041          }
1042        }
1043        if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){
1044          mxtmu = true;
1045          for(UInt_t i = 1; i < 6; i++){
1046            if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i;
1047          }
1048        }
1049      }
1050      
1051      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;
1052      
1053      
1054      if (R10u&&insm) hole=0; // best event R10
1055      if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct
1056      if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10
1057      if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10
1058      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
1059      if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10
1060      if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10
1061      if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10
1062      if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10
1063      if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10
1064      return hole;
1065    }
1066    

Legend:
Removed from v.1.10  
changed lines
  Added in v.1.28

  ViewVC Help
Powered by ViewVC 1.1.23