/[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.41 by pam-fi, Thu Aug 6 15:00:43 2009 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    
48  using namespace std;  using namespace std;
49    
# Line 47  using namespace std; Line 51  using namespace std;
51  // CORE ROUTINE  // CORE ROUTINE
52  //  //
53  //  //
54  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[]){
55      //
 //   // 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  
 //   //  
   
56    Int_t i = 0;    Int_t i = 0;
57      TString host = glt->CGetHost();
58      TString user = glt->CGetUser();
59      TString psw = glt->CGetPsw();
60      TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
61      //
62      stringstream myquery;
63      myquery.str("");
64      myquery << "SET time_zone='+0:00'";
65      dbc->Query(myquery.str().c_str());
66    //    //
67    TString processFolder = "OrbitalInfoFolder";    TString processFolder = Form("OrbitalInfoFolder_%u",run);
68    //    //
69    // Set these to true to have a very verbose output.    // Set these to true to have a very verbose output.
70    //    //
71    Bool_t debug = false;    Bool_t debug = false;
72    //    //
73    Bool_t verbose = false;    Bool_t verbose = false;
74      //
75      Bool_t standalone = false;
76      //
77    if ( OrbitalInfoargc > 0 ){    if ( OrbitalInfoargc > 0 ){
78      i = 0;      i = 0;
79      while ( i < OrbitalInfoargc ){      while ( i < OrbitalInfoargc ){
# Line 86  int OrbitalInfoCore(UInt_t run, TFile *f Line 86  int OrbitalInfoCore(UInt_t run, TFile *f
86        };        };
87        if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {        if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {
88          verbose = true;          verbose = true;
89            debug = true;
90        };        };
91        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {
92          verbose = true;          verbose = true;
93        };        };
94          if ( (!strcmp(OrbitalInfoargv[i],"--standalone")) ) {
95            standalone = true;
96          };
97          if ( (!strcmp(OrbitalInfoargv[i],"--calculate-pitch")) ) {
98            standalone = false;
99          };
100        i++;        i++;
101      };      };
102    };    };
# Line 98  int OrbitalInfoCore(UInt_t run, TFile *f Line 105  int OrbitalInfoCore(UInt_t run, TFile *f
105    //    //
106    TTree *OrbitalInfotr = 0;    TTree *OrbitalInfotr = 0;
107    UInt_t nevents = 0;    UInt_t nevents = 0;
108      UInt_t neventsm = 0;
109    //    //
110    // variables needed to reprocess data    // variables needed to reprocess data
111    //    //
# Line 116  int OrbitalInfoCore(UInt_t run, TFile *f Line 124  int OrbitalInfoCore(UInt_t run, TFile *f
124    stringstream ftmpname;    stringstream ftmpname;
125    TString fname;    TString fname;
126    UInt_t totfileentries = 0;    UInt_t totfileentries = 0;
127    UInt_t idRun = 0;    UInt_t idRun = 0;
128      //
129      // My variables. Vitaly.
130      //
131      //  UInt_t iev = 0;
132      //  UInt_t j3 = 0;
133      UInt_t oi = 0;
134      Int_t tmpSize = 0;
135    //    //
136    // variables needed to handle error signals    // variables needed to handle error signals
137    //    //
# Line 132  int OrbitalInfoCore(UInt_t run, TFile *f Line 147  int OrbitalInfoCore(UInt_t run, TFile *f
147    //    //
148    TFile *l0File = 0;    TFile *l0File = 0;
149    TTree *l0tr = 0;    TTree *l0tr = 0;
150      //  TTree *l0trm = 0;
151      TChain *ch = 0;
152    // EM: open also header branch    // EM: open also header branch
153    TBranch *l0head = 0;    TBranch *l0head = 0;
154    pamela::EventHeader *eh = 0;    pamela::EventHeader *eh = 0;
155    pamela::PscuHeader *ph = 0;    pamela::PscuHeader *ph = 0;
156      pamela::McmdEvent *mcmdev = 0;
157      pamela::McmdRecord *mcmdrc = 0;
158    // end EM    // end EM
159      
160      //  pamela::RunHeaderEvent *reh = new pamela::RunHeaderEvent;
161      //  pamela::EventHeader    *eH  = new pamela::EventHeader;
162      
163    //    //
164    // Define other basic variables    // Define other basic variables
165    //    //
# Line 147  int OrbitalInfoCore(UInt_t run, TFile *f Line 170  int OrbitalInfoCore(UInt_t run, TFile *f
170    Int_t totevent = 0;    Int_t totevent = 0;
171    UInt_t atime = 0;    UInt_t atime = 0;
172    UInt_t re = 0;    UInt_t re = 0;
173      UInt_t ik = 0;
174    
175    // Position    // Position
176    Float_t lon, lat, alt;    Float_t lon, lat, alt;
# Line 154  int OrbitalInfoCore(UInt_t run, TFile *f Line 178  int OrbitalInfoCore(UInt_t run, TFile *f
178    //    //
179    // IGRF stuff    // IGRF stuff
180    //    //
181    float dimo = 0.0; // dipole moment (computed from dat files)    Float_t dimo = 0.0; // dipole moment (computed from dat files)
182    float bnorth, beast, bdown, babs;    Float_t bnorth, beast, bdown, babs;
183    float xl; // L value    Float_t xl; // L value
184    float icode; // code value for L accuracy (see fortran code)    Float_t icode; // code value for L accuracy (see fortran code)
185    float bab1; // What's  the difference with babs?    Float_t bab1; // What's  the difference with babs?
186    float stps = 0.005; // step size for field line tracing    Float_t stps = 0.005; // step size for field line tracing
187    float bdel = 0.01; // required accuracy    Float_t bdel = 0.01; // required accuracy
188    float bequ;  // equatorial b value (also called b_0)    Float_t bequ;  // equatorial b value (also called b_0)
189    bool value = 0; // false if bequ is not the minimum b value    Bool_t value = 0; // false if bequ is not the minimum b value
190    float rr0; // equatorial radius normalized to earth radius    Float_t rr0; // equatorial radius normalized to earth radius
191    
192    //    //
193    // Working filename    // Working filename
# Line 179  int OrbitalInfoCore(UInt_t run, TFile *f Line 203  int OrbitalInfoCore(UInt_t run, TFile *f
203    TTree *tempOrbitalInfo = 0;    TTree *tempOrbitalInfo = 0;
204    stringstream tempname;    stringstream tempname;
205    stringstream OrbitalInfofolder;    stringstream OrbitalInfofolder;
206      Bool_t myfold = false;
207    tempname.str("");    tempname.str("");
208    tempname << outDir;    tempname << outDir;
209    tempname << "/" << processFolder.Data();    tempname << "/" << processFolder.Data();
210    OrbitalInfofolder.str("");    OrbitalInfofolder.str("");
211    OrbitalInfofolder << tempname.str().c_str();    OrbitalInfofolder << tempname.str().c_str();
   gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());  
212    tempname << "/OrbitalInfotree_run";    tempname << "/OrbitalInfotree_run";
213    tempname << run << ".root";      tempname << run << ".root";  
214      UInt_t totnorun = 0;
215    //    //
216    // DB classes    // DB classes
217    //    //
218    GL_ROOT *glroot = new GL_ROOT();    GL_ROOT *glroot = new GL_ROOT();
219    GL_TIMESYNC *dbtime = 0;    GL_TIMESYNC *dbtime = 0;
220    GL_TLE *gltle = new GL_TLE();    GL_TLE *gltle = new GL_TLE();
221      //
222      //Quaternions classes
223      //
224      Quaternions *L_QQ_Q_l_lower = new Quaternions();
225      InclinationInfo *RYPang_lower = new InclinationInfo();
226      Quaternions *L_QQ_Q_l_upper = new Quaternions();
227      InclinationInfo *RYPang_upper = new InclinationInfo();
228      
229      cEci eCi;
230      
231    // Initialize fortran routines!!!    // Initialize fortran routines!!!
232    Int_t ltp2 = 0;    Int_t ltp2 = 0;
233    Int_t ltp3 = 0;    Int_t ltp3 = 0;
234    Int_t uno = 1;    Int_t uno = 1;
235    char *niente = " ";    const char *niente = " ";
236    GL_PARAM *glparam = new GL_PARAM();    GL_PARAM *glparam = new GL_PARAM();
237    GL_PARAM *glparam2 = new GL_PARAM();    GL_PARAM *glparam2 = new GL_PARAM();
238    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
239      //
240      // Orientation variables
241      //
242      UInt_t evfrom = 0;
243      UInt_t jumped = 0;
244      Int_t itr = -1;    
245      Double_t A1;
246      Double_t A2;
247      Double_t A3;
248      Double_t Px = 0;
249      Double_t Py = 0;      
250      Double_t Pz = 0;  
251      TTree *ttof = 0;
252      ToFLevel2 *tof = new ToFLevel2();
253      OrientationInfo *PO = new OrientationInfo();
254      Int_t nz = 6;
255      Float_t zin[6];
256      Int_t nevtofl2 = 0;
257      //  
258    if ( parerror<0 ) {    if ( parerror<0 ) {
259      code = parerror;      code = parerror;
260      goto closeandexit;      goto closeandexit;
# Line 217  int OrbitalInfoCore(UInt_t run, TFile *f Line 271  int OrbitalInfoCore(UInt_t run, TFile *f
271    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());
272    //    //
273    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);
   
274    //    //
275    // End IGRF stuff//    // End IGRF stuff//
276    //    //
277      for (Int_t ip=0;ip<nz;ip++){
278        zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
279      };
280      //
281      if ( !standalone ){
282        //
283        // Does it contain the Tracker tree?
284        //
285        ttof = (TTree*)file->Get("ToF");
286        if ( !ttof ) {
287          if ( verbose ) printf(" OrbitalInfo - ERROR: no tof tree\n");
288          code = -900;
289          goto closeandexit;
290        };
291        ttof->SetBranchAddress("ToFLevel2",&tof);  
292        nevtofl2 = ttof->GetEntries();
293      };
294    //    //
295    // Let's start!    // Let's start!
296    //    //
# Line 276  int OrbitalInfoCore(UInt_t run, TFile *f Line 345  int OrbitalInfoCore(UInt_t run, TFile *f
345    // number of run to be processed    // number of run to be processed
346    //    //
347    numbofrun = runinfo->GetNoRun();    numbofrun = runinfo->GetNoRun();
348      totnorun = runinfo->GetRunEntries();
349    //    //
350    // 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
351    //    //
# Line 302  int OrbitalInfoCore(UInt_t run, TFile *f Line 372  int OrbitalInfoCore(UInt_t run, TFile *f
372      //      //
373      if (verbose) printf("\n Preparing the pre-processing...\n");      if (verbose) printf("\n Preparing the pre-processing...\n");
374      //      //
375      if ( run == 0 ){      if ( run == 0 || totnorun == 1 ){
376        //        //
377        // we are reprocessing all the file        // we are reprocessing all the file
378        // 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 391  int OrbitalInfoCore(UInt_t run, TFile *f
391        //        //
392        // copying old tree to a new file        // copying old tree to a new file
393        //        //
394          gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
395          myfold = true;
396        tempfile = new TFile(tempname.str().c_str(),"RECREATE");        tempfile = new TFile(tempname.str().c_str(),"RECREATE");
397        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
398        tempOrbitalInfo->SetName("OrbitalInfo-old");        tempOrbitalInfo->SetName("OrbitalInfo-old");
# Line 341  int OrbitalInfoCore(UInt_t run, TFile *f Line 413  int OrbitalInfoCore(UInt_t run, TFile *f
413    file->cd();    file->cd();
414    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");
415    OrbitalInfotr->SetAutoSave(900000000000000LL);    OrbitalInfotr->SetAutoSave(900000000000000LL);
416      orbitalinfo->Set();//ELENA **TEMPORANEO?**
417    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);
418    //    //
419    if ( reproc && !reprocall ){    if ( reproc && !reprocall ){
# Line 387  int OrbitalInfoCore(UInt_t run, TFile *f Line 460  int OrbitalInfoCore(UInt_t run, TFile *f
460      //      //
461      // retrieve the first run ID to be processed using the RunInfo list      // retrieve the first run ID to be processed using the RunInfo list
462      //      //
463        
464      idRun = runlist->At(irun);      idRun = runlist->At(irun);
465      if (verbose){      if (verbose){
466        printf("\n\n\n ####################################################################### \n");        printf("\n\n\n ####################################################################### \n");
# Line 419  int OrbitalInfoCore(UInt_t run, TFile *f Line 493  int OrbitalInfoCore(UInt_t run, TFile *f
493      // prepare the timesync for the db      // prepare the timesync for the db
494      //      //
495      dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);      dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
496      
497      //      //
498      // 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.
499      //      //
# Line 428  int OrbitalInfoCore(UInt_t run, TFile *f Line 503  int OrbitalInfoCore(UInt_t run, TFile *f
503      ftmpname << glroot->PATH.Data() << "/";      ftmpname << glroot->PATH.Data() << "/";
504      ftmpname << glroot->NAME.Data();      ftmpname << glroot->NAME.Data();
505      fname = ftmpname.str().c_str();      fname = ftmpname.str().c_str();
506        ftmpname.str("");
507      //      //
508      // print out informations      // print nout informations
509      //      //
510      totevent = runinfo->NEVENTS;      totevent = runinfo->NEVENTS;
511        evfrom = runinfo->EV_FROM;
512        //cout<<"totevents = "<<totevent<<"\n";
513      if (verbose){      if (verbose){
514        printf("\n LEVEL0 data file: %s \n",fname.Data());        printf("\n LEVEL0 data file: %s \n",fname.Data());
515        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);        printf(" RUN HEADER absolute time is:  %u \n",runinfo->RUNHEADER_TIME);
516        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
517        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);
518      }//      }//
519        //
520        //    if ( !totevent ) goto closeandexit;
521      // Open Level0 file      // Open Level0 file
522      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
523      if ( !l0File ) {      if ( !l0File ) {
# Line 464  int OrbitalInfoCore(UInt_t run, TFile *f Line 544  int OrbitalInfoCore(UInt_t run, TFile *f
544      // end EM      // end EM
545      nevents = l0head->GetEntries();      nevents = l0head->GetEntries();
546      //      //
547      if ( nevents < 1 ) {      if ( nevents < 1 && totevent ) {
548        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
549        l0File->Close();        l0File->Close();
550        code = -11;        code = -11;
551        goto closeandexit;        goto closeandexit;
552      };      };
553      //      //
554      if ( runinfo->EV_TO > nevents-1 ) {      if ( runinfo->EV_TO > nevents-1 && totevent ) {
555        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");
556        l0File->Close();        l0File->Close();
557        code = -12;        code = -12;
558        goto closeandexit;        goto closeandexit;
559      };      };
560      //      //
561    //     TTree *tp = (TTree*)l0File->Get("RunHeader");
562    //     tp->SetBranchAddress("Header", &eH);
563    //     tp->SetBranchAddress("RunHeader", &reh);
564    //     tp->GetEntry(0);
565    //     ph = eH->GetPscuHeader();
566    //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
567    //     ULong_t ObtSync = reh->OBT_TIME_SYNC;    
568    //     if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
569    //
570        ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
571        ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
572        ULong_t DeltaOBT = TimeSync - ObtSync;
573    
574        if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
575        //
576        // Read MCMDs from up to 11 files, 5 before and 5 after the present one in order to have some kind of inclination information
577        //
578        ch = new TChain("Mcmd","Mcmd");
579        //
580        // look in the DB to find the closest files to this run
581        //
582        TSQLResult *pResult = 0;
583        TSQLRow *Row = 0;
584        stringstream myquery;
585        UInt_t l0fid[10];
586        Int_t i = 0;
587        memset(l0fid,0,10*sizeof(Int_t));
588        //
589        myquery.str("");
590        myquery << "select ID_ROOT_L0 from GL_RUN where RUNHEADER_TIME<=" << runinfo->RUNHEADER_TIME << " group by ID_ROOT_L0 order by RUNHEADER_TIME desc limit 5;";
591        //
592        pResult = dbc->Query(myquery.str().c_str());
593        //
594        i = 9;
595        if( pResult ){
596          //
597          Row = pResult->Next();
598          //
599          while ( Row ){
600            //
601            // store infos and exit
602            //
603            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
604            i--;
605            Row = pResult->Next();  
606            //
607          };
608          pResult->Delete();
609        };
610        //
611        myquery.str("");
612        myquery << "select ID_ROOT_L0 from GL_RUN where RUNHEADER_TIME>" << runinfo->RUNHEADER_TIME << " group by ID_ROOT_L0 order by RUNHEADER_TIME asc limit 5;";
613        //
614        pResult = dbc->Query(myquery.str().c_str());
615        //
616        i = 0;
617        if( pResult ){
618          //
619          Row = pResult->Next();
620          //
621          while ( Row ){
622            //
623            // store infos and exit
624            //
625            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
626            i++;
627            Row = pResult->Next();  
628            //
629          };
630          pResult->Delete();
631        };
632        //
633        i = 0;
634        UInt_t previd = 0;
635        while ( i < 10 ){
636          if ( l0fid[i] && previd != l0fid[i] ){
637            previd = l0fid[i];
638            myquery.str("");
639            myquery << "select PATH,NAME from GL_ROOT where ID=" << l0fid[i] << " ;";
640            //
641            pResult = dbc->Query(myquery.str().c_str());
642            //
643            if( pResult ){
644              //
645              Row = pResult->Next();
646              //
647              if ( debug ) printf(" Using inclination informations from file: %s \n",(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1)).Data());
648              ch->Add(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1));
649              //
650              pResult->Delete();
651            };
652          };
653          i++;
654        };
655        //
656        //    l0trm = (TTree*)l0File->Get("Mcmd");
657        //    ch->ls();
658        ch->SetBranchAddress("Mcmd",&mcmdev);
659        //    printf(" entries %llu \n", ch->GetEntries());
660        //    l0trm = ch->GetTree();
661        //    neventsm = l0trm->GetEntries();
662        neventsm = ch->GetEntries();
663        if ( debug ) printf(" entries %u \n", neventsm);
664        //    neventsm = 0;
665        //
666        if (neventsm == 0){
667          if ( debug ) printf("InclinationInfo - WARNING: No quaternions in this File");
668          //      l0File->Close();
669          code = 900;
670          //      goto closeandexit;
671        }
672        //
673        
674        //    l0trm->SetBranchAddress("Mcmd", &mcmdev);
675        //    l0trm->SetBranchAddress("Header", &eh);
676        //
677        //
678        //
679        UInt_t mctren = 0;    
680        UInt_t mcreen = 0;  
681        UInt_t numrec = 0;
682        //
683        Double_t upperqtime = 0;
684        Double_t lowerqtime = 0;
685        
686        Double_t incli = 0;
687        oi = 0;
688        UInt_t ooi = 0;
689        //
690        // init quaternions sync
691        //
692        Bool_t isf = true;
693        Int_t fgh = 0;
694        //
695      // run over all the events of the run      // run over all the events of the run
696      //      //
697      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");
698      //      //
699         //
700      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
701        //        //
702        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
703          if ( debug ) printf(" %i \n",procev);      
704        //        //
705        l0head->GetEntry(re);        l0head->GetEntry(re);
706        //        //
707        // absolute time of this event        // absolute time of this event
708        //        //
709        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
710        atime = dbtime->DBabsTime(ph->GetOrbitalTime());          atime = dbtime->DBabsTime(ph->GetOrbitalTime());
711          if ( debug ) printf(" %i absolute time \n",procev);      
712        //        //
713        // paranoid check        // paranoid check
714        //        //
715        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {        if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1))  ) {
716          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");
717          debug = true;          jumped++;
718    //      debug = true;
719          continue;          continue;
720        }        }
721    
722          //
723          // retrieve tof informations
724          //
725          if ( !reprocall ){
726            itr = nobefrun + (re - evfrom - jumped);
727            //itr = re-(46438+200241);
728          } else {
729            itr = runinfo->GetFirstEntry() + (re - evfrom - jumped);
730          };
731          //
732          if ( !standalone ){
733            if ( itr > nevtofl2 ){  
734              if ( verbose ) printf(" OrbitalInfo - ERROR: no tof events with entry = %i in Level2 file\n",itr);
735              if ( debug ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
736              l0File->Close();
737              code = -901;
738              goto closeandexit;
739            };
740            //
741            tof->Clear();
742            //
743            ttof->GetEntry(itr);
744            //
745          };
746        //        //
747        procev++;        procev++;
748        //        //
749        // start processing        // start processing
750        //        //
751          if ( debug ) printf(" %i start processing \n",procev);      
752        orbitalinfo->Clear();        orbitalinfo->Clear();
753        //        //
754        // CHANGE HERE!!!!        OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
755          if( !(orbitalinfo->OrbitalInfoTrk) ) orbitalinfo->OrbitalInfoTrk = new TClonesArray("OrbitalInfoTrkVar",2);
756          TClonesArray &tor = *orbitalinfo->OrbitalInfoTrk;
757        //        //
758        orbitalinfo->absTime = atime;        // Fill OBT, pkt_num and absTime
759        // EM: add OBT and plt_num infos from the header        //      
       ph = eh->GetPscuHeader();  
760        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
761        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
762          orbitalinfo->absTime = atime;
763        // If the absolute time of the event overpass the time of the        if ( debug ) printf(" %i pktnum obt abstime \n",procev);      
764        // tle, get a new tle.  GL_TLE::GetToTime() default to zero.        //
765          // Propagate the orbit from the tle time to atime, using SGP(D)4.
766          //
767          if ( debug ) printf(" %i sgp4 \n",procev);      
768          cCoordGeo coo;
769          Float_t jyear=0.;    
770        //        //
       // 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;  
   
771        if(atime >= gltle->GetToTime()) {        if(atime >= gltle->GetToTime()) {
772          if ( !gltle->Query(atime, dbc) ){          if ( !gltle->Query(atime, dbc) ){
773                        //      
774            // Compute the magnetic dipole moment.            // Compute the magnetic dipole moment.
775              //
776              if ( debug ) printf(" %i compute magnetic dipole moment \n",procev);      
777            UInt_t year, month, day, hour, min, sec;            UInt_t year, month, day, hour, min, sec;
778                        //
779            TTimeStamp t = TTimeStamp(atime, kTRUE);            TTimeStamp t = TTimeStamp(atime, kTRUE);
780            t.GetDate(kTRUE, 0, &year, &month, &day);            t.GetDate(kTRUE, 0, &year, &month, &day);
781            t.GetTime(kTRUE, 0, &hour, &min, &sec);            t.GetTime(kTRUE, 0, &hour, &min, &sec);
782            jyear = (float) year            jyear = (float) year
783              + (month*31.+ (float) day)/365.              + (month*31.+ (float) day)/365.
784              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);
785                        //
786              if ( debug ) printf(" %i compute magnetic dipole moment get dipole moment for year\n",procev);      
787            feldcof_(&jyear, &dimo); // get dipole moment for year            feldcof_(&jyear, &dimo); // get dipole moment for year
788              if ( debug ) printf(" %i compute magnetic dipole moment end\n",procev);      
789          } else {          } else {
790            code = -56;            code = -56;
791            goto closeandexit;            goto closeandexit;
792          };          };
793        }        }
794          coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());
795        // Propagate the orbit from the tle time to atime, using SGP(D)4.        //
796        cCoordGeo coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());        cOrbit orbits(*gltle->GetTle());
797          //
798          if ( debug ) printf(" I am Here \n");
799          //
800          // synchronize with quaternions data
801          //
802          if ( isf && neventsm>0 ){
803            if ( debug ) printf(" I am here \n");
804            //
805            // First event
806            //
807            isf = false;
808            upperqtime = atime;
809            lowerqtime = runinfo->RUNHEADER_TIME;
810            for ( ik = 0; ik < neventsm; ik++){
811              //      l0trm->GetEntry(ik);
812              ch->GetEntry(ik);
813              tmpSize = mcmdev->Records->GetEntries();
814              numrec = tmpSize;
815              for (Int_t j3 = 0;j3<tmpSize;j3++){
816                if ( debug ) printf(" ik %i j3 %i eh eh eh \n",ik,j3);
817                mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
818                if ( mcmdrc ){ // missing inclination bug [8RED 090116]
819                  if ((int)mcmdrc->ID1 == 226){
820                    L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
821                    for (UInt_t ui = 0; ui < 6; ui++){
822                      if (ui>0){
823                        if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
824                          if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){
825                            upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
826                            orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
827                            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]);
828                          }else {
829                            lowerqtime = upperqtime;
830                            upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
831                            orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
832                            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]);
833                            mcreen = j3;
834                            mctren = ik;
835                            if(fgh==0){
836                              CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
837                              CopyAng(RYPang_lower,RYPang_upper);
838                            }
839                            oi=ui;
840                            goto closethisloop;
841                          }
842                          fgh++;
843                          CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
844                          CopyAng(RYPang_lower,RYPang_upper);
845                        }
846                      }else{
847                        if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){
848                          upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
849                          orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
850                          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]);
851                        }
852                        else {
853                          lowerqtime = upperqtime;
854                          upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
855                          orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
856                          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]);
857                          mcreen = j3;
858                          mctren = ik;
859                          if(fgh==0){
860                            CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
861                            CopyAng(RYPang_lower,RYPang_upper);
862                            lowerqtime = atime-1;
863                          }
864                          oi=ui;
865                          goto closethisloop;
866                          //_0 = true;
867                        }
868                        fgh++;
869                        CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
870                        CopyAng(RYPang_lower,RYPang_upper);
871                        //_0 = true;
872                      };
873                      //cin>>grib;
874                    };
875                  };
876                };
877              };
878            };
879          };
880        closethisloop:
881          //
882          if ( debug ) printf(" I am There \n");
883          //
884          if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){
885            if ( debug ) printf(" I am there \n");
886            //
887            lowerqtime = upperqtime;
888            Long64_t maxloop = 100000000LL;
889            Long64_t mn = 0;
890            Bool_t gh=false;
891            ooi=oi;
892            if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);
893            while (!gh){      
894              if ( mn > maxloop ){
895                if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");
896                gh = true;
897                neventsm = 0;
898              };
899              mn++;
900              if (oi<5) oi++;
901              else oi=0;
902              if (oi==0 && numrec > 0){
903                if ( debug ) printf(" mumble \n");
904                mcreen++;
905                if (mcreen == numrec){
906                  mctren++;
907                  mcreen = 0;
908                  //              l0trm->GetEntry(mctren);
909                  ch->GetEntry(mctren);
910                  numrec = mcmdev->Records->GetEntries();
911                }
912                CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
913                CopyAng(RYPang_lower,RYPang_upper);
914                mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);
915                if ( mcmdrc ){ // missing inclination bug [8RED 090116]
916                  if ((int)mcmdrc->ID1 == 226){
917                    L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
918                    upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
919                    if (upperqtime<lowerqtime){
920                      upperqtime=runinfo->RUNTRAILER_TIME;
921                      CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);
922                      CopyAng(RYPang_upper,RYPang_lower);
923                    }else{
924                      orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
925                      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]);
926                    }
927                    //            re--;
928                    gh=true;
929                  }
930                };
931              }else{
932                if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){
933                  upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
934                  orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
935                  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]);
936                  orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi);
937                  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]);
938                  //              re--;
939                  gh=true;
940                };
941              };
942            };
943            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);
944          };
945          //
946          if ( debug ) printf(" I am THIS \n");
947          //
948          // Fill in quaternions and angles
949          //
950          if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)&& neventsm>0){      
951            if ( debug ) printf(" I am this \n");
952            UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
953            if (oi == 0){
954              if ((tut!=5)||(tut!=6)){
955                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)));
956                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));
957                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)));
958                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));
959                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)));
960                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));
961                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)));
962                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));
963            
964                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)));
965                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
966                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)));
967                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
968                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)));
969                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
970              }
971              if (tut==6){
972                if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
973                  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)));
974                  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));
975                  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)));
976                  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));
977                  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)));
978                  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));
979                  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)));
980                  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));
981            
982                  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)));
983                  orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
984                  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)));
985                  orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
986                  //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";
987                  //cin>>grib;
988                  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)));
989                  orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
990                }
991              }
992            } else {
993              if((tut!=6)||(tut!=7)||(tut!=9)){
994                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)));
995                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));
996                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)));
997                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));
998                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)));
999                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));
1000                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)));
1001                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));
1002            
1003                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)));
1004                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1005                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)));
1006                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1007                //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";
1008                //cin>>grib;
1009                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)));
1010                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1011              }
1012              if (tut==6){
1013                if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
1014                  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)));
1015                  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));
1016                  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)));
1017                  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));
1018                  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)));
1019                  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));
1020                  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)));
1021                  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));
1022            
1023                  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)));
1024                  orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1025                  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)));
1026                  orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1027                  //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";
1028                  //cin>>grib;
1029                  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)));
1030                  orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
1031                }
1032              }            
1033            }
1034            //
1035            orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
1036            //
1037          } else {
1038            if ( debug ) printf(" ops no incl! \n");
1039            orbitalinfo->mode = 10;
1040          };
1041          //
1042          // ops no inclination information
1043          //
1044          if ( orbitalinfo->q0< -999 || orbitalinfo->q1 < -999 || orbitalinfo->q2 < -999 || orbitalinfo->q3 < -999 || orbitalinfo->q0 != orbitalinfo->q0 || orbitalinfo->q1 != orbitalinfo->q1 || orbitalinfo->q2 != orbitalinfo->q2 || orbitalinfo->q3 != orbitalinfo->q3 ){
1045            orbitalinfo->mode = 10;
1046            orbitalinfo->q0 = -1000.;
1047            orbitalinfo->q1 = -1000.;
1048            orbitalinfo->q2 = -1000.;
1049            orbitalinfo->q3 = -1000.;
1050            orbitalinfo->etha = -1000.;
1051            orbitalinfo->phi = -1000.;
1052            orbitalinfo->theta = -1000.;
1053          };
1054          //
1055          // #########################################################################################################################  
1056          //
1057          // fill orbital positions
1058          //        
1059        // Build coordinates in the right range.  We want to convert,        // Build coordinates in the right range.  We want to convert,
1060        // longitude from (0, 2*pi) to (-180deg, 180deg).  Altitude is        // longitude from (0, 2*pi) to (-180deg, 180deg).  Altitude is
1061        // in meters.        // in meters.
1062        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);
1063        lat = rad2deg(coo.m_Lat);        lat = rad2deg(coo.m_Lat);
1064        alt = coo.m_Alt;        alt = coo.m_Alt;
1065          //
   
       //      if((lon>180) || (lon<-180) || (lat>90) || (lat<-90) || (alt<0))  
       //        continue;  
1066        if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){          if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){  
1067            //      
1068          orbitalinfo->lon = lon;          orbitalinfo->lon = lon;
1069          orbitalinfo->lat = lat;          orbitalinfo->lat = lat;
1070          orbitalinfo->alt = alt ;          orbitalinfo->alt = alt ;
1071                    //
1072          // compute mag field components and L shell.          // compute mag field components and L shell.
1073            //
1074          feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);          feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);
1075          shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);          shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);
1076          findb0_(&stps, &bdel, &value, &bequ, &rr0);          findb0_(&stps, &bdel, &value, &bequ, &rr0);
1077                    //
1078          orbitalinfo->Bnorth = bnorth;          orbitalinfo->Bnorth = bnorth;
1079          orbitalinfo->Beast = beast;          orbitalinfo->Beast = beast;
1080          orbitalinfo->Bdown = bdown;          orbitalinfo->Bdown = bdown;
1081          orbitalinfo->Babs = babs;          orbitalinfo->Babs = babs;
1082          orbitalinfo->BB0 = babs/bequ;          orbitalinfo->BB0 = babs/bequ;
1083          orbitalinfo->L = xl;          orbitalinfo->L = xl;      
           
1084          // Set Stormer vertical cutoff using L shell.          // Set Stormer vertical cutoff using L shell.
1085          orbitalinfo->cutoff[0] = 14.9/(xl*xl);          orbitalinfo->cutoffsvl = 14.9/(xl*xl);
1086            //
1087          };      
1088          //
1089          if ( debug ) printf(" pitch angle \n");
1090          //
1091          // pitch angles
1092          //
1093          if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){
1094            //
1095            Float_t Bx = -orbitalinfo->Bdown;                       //don't need for PamExp ExpOnly for all geography areas
1096            Float_t By = orbitalinfo->Beast;                        //don't need for PamExp ExpOnly for all geography areas
1097            Float_t Bz = orbitalinfo->Bnorth;                       //don't need for PamExp ExpOnly for all geography areas
1098            //
1099            TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);
1100            TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);
1101            TMatrixD Iij = PO->ColPermutation(Dij);
1102            //
1103            orbitalinfo->Iij.ResizeTo(Iij);
1104            orbitalinfo->Iij = Iij;
1105            //
1106            A1 = Iij(0,2);
1107            A2 = Iij(1,2);
1108            A3 = Iij(2,2);
1109            //      
1110            //      orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3);                        // Angle between zenit and Pamela's main axiz
1111            //      orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz);                 // Angle between Pamela's main axiz and B
1112            //
1113            if ( !standalone && tof->ntrk() > 0 ){
1114              //
1115              Int_t nn = 0;
1116              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1117                //
1118                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1119                Double_t E11x = ptt->xtr_tof[0]; // tr->x[0];
1120                Double_t E11y = ptt->ytr_tof[0]; //tr->y[0];
1121                Double_t E11z = zin[0];
1122                Double_t E22x = ptt->xtr_tof[3];//tr->x[3];
1123                Double_t E22y = ptt->ytr_tof[3];//tr->y[3];
1124                Double_t E22z = zin[3];
1125                if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1  ){
1126                  Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1127    //            Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1128    //            if(E22x-E11x>=0 && E22y-E11y <0) MyAzim =  360. - MyAzim;
1129    //            if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1130    //            if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1131    //            if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1132                  Px = (E22x-E11x)/norm;
1133                  Py = (E22y-E11y)/norm;
1134                  Pz = (E22z-E11z)/norm;
1135                  //
1136                  t_orb->trkseqno = ptt->trkseqno;
1137                  //
1138                  TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);
1139                  t_orb->Eij.ResizeTo(Eij);
1140                  t_orb->Eij = Eij;
1141                  //
1142                  TMatrixD Sij = PO->PamelatoGEO(Fij,Px,Py,Pz);
1143                  t_orb->Sij.ResizeTo(Sij);
1144                  t_orb->Sij = Sij;
1145                  //            
1146                  t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);
1147                  //
1148                  //
1149                  Double_t omega = PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),cos(orbitalinfo->lon+TMath::Pi()/2)-sin(orbitalinfo->lon+TMath::Pi()/2),cos(orbitalinfo->lon+TMath::Pi()/2)+sin(orbitalinfo->lon+TMath::Pi()/2),1);
1150                  //
1151                  t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1152                  //
1153                  if ( t_orb->pitch != t_orb->pitch ) t_orb->pitch = -1000.;
1154                  if ( t_orb->cutoff != t_orb->cutoff ) t_orb->cutoff = -1000.;
1155                  //
1156                  if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1157                  //
1158                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1159                  nn++;
1160                  //
1161                  t_orb->Clear();
1162                  //
1163                };
1164                //
1165              };
1166            } else {
1167              if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());
1168            };
1169            //
1170          } else {
1171            if ( !standalone && tof->ntrk() > 0 ){
1172              //
1173              Int_t nn = 0;
1174              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1175                //
1176                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1177                if ( ptt->trkseqno != -1  ){
1178                  //
1179                  t_orb->trkseqno = ptt->trkseqno;
1180                  //
1181                  t_orb->Eij = 0;  
1182                  //
1183                  t_orb->Sij = 0;
1184                  //            
1185                  t_orb->pitch = -1000.;
1186                  //
1187                  t_orb->cutoff = -1000.;
1188                  //
1189                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1190                  nn++;
1191                  //
1192                  t_orb->Clear();
1193                  //
1194                };
1195                //
1196              };    
1197            };
1198        };        };
1199                //
1200        // end EM        // Fill the class
1201          //
1202        OrbitalInfotr->Fill();        OrbitalInfotr->Fill();
1203      }        //
1204              delete t_orb;
1205          //
1206        }; // loop over the events in the run
1207      //      //
1208      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
1209      //      //
1210      delete dbtime;      delete dbtime;
1211        if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1212        if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
1213        if ( RYPang_upper ) delete RYPang_upper;
1214        if ( RYPang_lower ) delete RYPang_lower;
1215    }; // process all the runs    }; // process all the runs
1216    //    
1217    if (verbose) printf("\n Finished processing data \n");    if (verbose) printf("\n Finished processing data \n");
1218    //    //
1219   closeandexit:   closeandexit:
# Line 626  int OrbitalInfoCore(UInt_t run, TFile *f Line 1251  int OrbitalInfoCore(UInt_t run, TFile *f
1251    //    //
1252    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
1253    if ( tempfile ) tempfile->Close();                if ( tempfile ) tempfile->Close();            
1254    gSystem->Unlink(tempname.str().c_str());    if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1255    //    //
1256    if ( runinfo ) runinfo->Close();        if ( runinfo ) runinfo->Close();    
1257    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
1258      if ( tof ) tof->Delete();
1259      if ( ttof ) ttof->Delete();
1260      //
1261    if ( file ){    if ( file ){
1262      file->cd();      file->cd();
1263      file->Write();      file->Write();
1264    };    };
1265    //    //
1266    gSystem->Unlink(OrbitalInfofolder.str().c_str());    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1267    //    //
1268    // the end    // the end
1269    //    //
1270      if ( dbc ){
1271        dbc->Close();
1272        delete dbc;
1273      };
1274    if (verbose) printf("\n Exiting...\n");    if (verbose) printf("\n Exiting...\n");
1275    if(OrbitalInfotr)OrbitalInfotr->Delete();    if(OrbitalInfotr)OrbitalInfotr->Delete();
1276    //    //
1277      if ( PO ) delete PO;
1278    if ( orbitalinfo ) delete orbitalinfo;    if ( orbitalinfo ) delete orbitalinfo;
1279    if ( orbitalinfoclone ) delete orbitalinfoclone;    if ( orbitalinfoclone ) delete orbitalinfoclone;
1280    if ( glroot ) delete glroot;    if ( glroot ) delete glroot;
# Line 663  cCoordGeo getCoo(UInt_t atime, UInt_t tl Line 1296  cCoordGeo getCoo(UInt_t atime, UInt_t tl
1296  {  {
1297    cEci eci;    cEci eci;
1298    cOrbit orbit(*tle);    cOrbit orbit(*tle);
     
1299    orbit.getPosition((double) (atime - tletime)/60., &eci);    orbit.getPosition((double) (atime - tletime)/60., &eci);
1300        
1301    return eci.toGeo();    return eci.toGeo();
1302  }  }
1303    
1304    // function of copyng of quatrnions classes
1305    
1306    void CopyQ(Quaternions *Q1, Quaternions *Q2){
1307      for(UInt_t i = 0; i < 6; i++){
1308        Q1->time[i]=Q2->time[i];
1309        for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j];
1310      }
1311      return;
1312    }
1313    
1314    // functions of copyng InclinationInfo classes
1315    
1316    void CopyAng(InclinationInfo *A1, InclinationInfo *A2){
1317      A1->Tangazh = A2->Tangazh;
1318      A1->Ryskanie = A2->Ryskanie;
1319      A1->Kren = A2->Kren;
1320      return;
1321    }
1322    
1323    UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
1324      
1325      UInt_t hole = 10;
1326      Bool_t R10l = false;     // Sign of R10 mode in lower quaternions array
1327      Bool_t R10u = false;     // Sign of R10 mode in upper quaternions array
1328      Bool_t insm = false;     // Sign that we inside quaternions array
1329      Bool_t mxtml = false;    // Sign of mixt mode in lower quaternions array
1330      Bool_t mxtmu = false;    // Sign of mixt mode in upper quaternions array
1331      Bool_t npasm = false;     // Sign of normall pass between R10 and non R10 or between non R10 and R10
1332      UInt_t NCQl = 6;       // Number of correct quaternions in lower array
1333      UInt_t NCQu = 6;       // Number of correct quaternions in upper array
1334      if (f>0){
1335        insm = true;
1336        if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false;
1337        if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true;
1338      }else{
1339        insm = false;
1340        if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true;
1341        if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true;
1342        if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false;
1343        if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false;
1344        if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){
1345          mxtml = true;
1346          for(UInt_t i = 1; i < 6; i++){
1347            if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i;
1348          }
1349        }
1350        if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){
1351          mxtmu = true;
1352          for(UInt_t i = 1; i < 6; i++){
1353            if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i;
1354          }
1355        }
1356      }
1357      
1358      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;
1359      
1360      
1361      if (R10u&&insm) hole=0; // best event R10
1362      if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct
1363      if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10
1364      if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10
1365      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
1366      if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10
1367      if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10
1368      if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10
1369      if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10
1370      if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10
1371      return hole;
1372    }
1373    

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

  ViewVC Help
Powered by ViewVC 1.1.23