/[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.34 by mocchiut, Fri Nov 28 09:05:21 2008 UTC revision 1.60 by pam-mep, Thu Jun 7 14:04:00 2012 UTC
# Line 1  Line 1 
 //  
1  // C/C++ headers  // C/C++ headers
2  //  //
3  #include <fstream>  #include <fstream>
# Line 9  Line 8 
8  //  //
9  // ROOT headers  // ROOT headers
10  //  //
11    //#include <TCanvas.h>
12    #include <TH2F.h> //for test only. Vitaly.
13    #include <TVector3.h>
14    //#include <TF1.h>
15    
16  #include <TTree.h>  #include <TTree.h>
17  #include <TClassEdit.h>  #include <TClassEdit.h>
18  #include <TObject.h>  #include <TObject.h>
# Line 44  Line 48 
48  #include <OrbitalInfoCore.h>  #include <OrbitalInfoCore.h>
49  #include <InclinationInfo.h>  #include <InclinationInfo.h>
50    
51    
52  using namespace std;  using namespace std;
53    
54  //  //
# Line 61  int OrbitalInfoCore(UInt_t run, TFile *f Line 66  int OrbitalInfoCore(UInt_t run, TFile *f
66    stringstream myquery;    stringstream myquery;
67    myquery.str("");    myquery.str("");
68    myquery << "SET time_zone='+0:00'";    myquery << "SET time_zone='+0:00'";
69    dbc->Query(myquery.str().c_str());    delete dbc->Query(myquery.str().c_str());
70    //    //
71    TString processFolder = Form("OrbitalInfoFolder_%u",run);    TString processFolder = Form("OrbitalInfoFolder_%u",run);
72    //    //
# Line 124  int OrbitalInfoCore(UInt_t run, TFile *f Line 129  int OrbitalInfoCore(UInt_t run, TFile *f
129    TString fname;    TString fname;
130    UInt_t totfileentries = 0;    UInt_t totfileentries = 0;
131    UInt_t idRun = 0;    UInt_t idRun = 0;
132      UInt_t anni5 = 60 * 60 * 24 * 365 * 5 ;//1576800
133    //    //
134    // My variables. Vitaly.    // My variables. Vitaly.
135    //    //
136    //  UInt_t iev = 0;  //  UInt_t oi = 0;
   //  UInt_t j3 = 0;  
   UInt_t oi = 0;  
137    Int_t tmpSize = 0;    Int_t tmpSize = 0;
138    //    //
139    // variables needed to handle error signals    // variables needed to handle error signals
# Line 141  int OrbitalInfoCore(UInt_t run, TFile *f Line 145  int OrbitalInfoCore(UInt_t run, TFile *f
145    //    //
146    OrbitalInfo *orbitalinfo = new OrbitalInfo();    OrbitalInfo *orbitalinfo = new OrbitalInfo();
147    OrbitalInfo *orbitalinfoclone = new OrbitalInfo();    OrbitalInfo *orbitalinfoclone = new OrbitalInfo();
148    
149    //    //
150    // define variables for opening and reading level0 file    // define variables for opening and reading level0 file
151    //    //
152    TFile *l0File = 0;    TFile *l0File = 0;
153    TTree *l0tr = 0;    TTree *l0tr = 0;
154    TTree *l0trm = 0;    //  TTree *l0trm = 0;
155      TChain *ch = 0;
156    // EM: open also header branch    // EM: open also header branch
157    TBranch *l0head = 0;    TBranch *l0head = 0;
158    pamela::EventHeader *eh = 0;    pamela::EventHeader *eh = 0;
# Line 176  int OrbitalInfoCore(UInt_t run, TFile *f Line 182  int OrbitalInfoCore(UInt_t run, TFile *f
182    //    //
183    // IGRF stuff    // IGRF stuff
184    //    //
185    float dimo = 0.0; // dipole moment (computed from dat files)    Float_t dimo = 0.0; // dipole moment (computed from dat files)
186    float bnorth, beast, bdown, babs;    Float_t bnorth, beast, bdown, babs;
187    float xl; // L value    Float_t xl; // L value
188    float icode; // code value for L accuracy (see fortran code)    Float_t icode; // code value for L accuracy (see fortran code)
189    float bab1; // What's  the difference with babs?    Float_t bab1; // What's  the difference with babs?
190    float stps = 0.005; // step size for field line tracing    Float_t stps = 0.005; // step size for field line tracing
191    float bdel = 0.01; // required accuracy    Float_t bdel = 0.01; // required accuracy
192    float bequ;  // equatorial b value (also called b_0)    Float_t bequ;  // equatorial b value (also called b_0)
193    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
194    float rr0; // equatorial radius normalized to earth radius    Float_t rr0; // equatorial radius normalized to earth radius
195    
196    //    //
197    // Working filename    // Working filename
# Line 209  int OrbitalInfoCore(UInt_t run, TFile *f Line 215  int OrbitalInfoCore(UInt_t run, TFile *f
215    OrbitalInfofolder << tempname.str().c_str();    OrbitalInfofolder << tempname.str().c_str();
216    tempname << "/OrbitalInfotree_run";    tempname << "/OrbitalInfotree_run";
217    tempname << run << ".root";      tempname << run << ".root";  
218      UInt_t totnorun = 0;
219    //    //
220    // DB classes    // DB classes
221    //    //
# Line 218  int OrbitalInfoCore(UInt_t run, TFile *f Line 225  int OrbitalInfoCore(UInt_t run, TFile *f
225    //    //
226    //Quaternions classes    //Quaternions classes
227    //    //
228    Quaternions *L_QQ_Q_l_lower = new Quaternions();    Quaternions *L_QQ_Q_l_lower = 0;
229    InclinationInfo *RYPang_lower = new InclinationInfo();    InclinationInfo *RYPang_lower = 0;
230    Quaternions *L_QQ_Q_l_upper = new Quaternions();    Quaternions *L_QQ_Q_l_upper = 0;
231    InclinationInfo *RYPang_upper = new InclinationInfo();    InclinationInfo *RYPang_upper = 0;
232        
233    cEci eCi;    cEci eCi;
234        
235    // Initialize fortran routines!!!    // Initialize fortran routines!!!
236      Int_t ltp1 = 0;
237    Int_t ltp2 = 0;    Int_t ltp2 = 0;
238    Int_t ltp3 = 0;    Int_t ltp3 = 0;
239    Int_t uno = 1;    //  Int_t uno = 1;
240    char *niente = " ";    //  const char *niente = " ";
241    GL_PARAM *glparam = new GL_PARAM();    GL_PARAM *glparam = new GL_PARAM();
242    GL_PARAM *glparam2 = new GL_PARAM();    GL_PARAM *glparam2 = new GL_PARAM();
243    Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table    GL_PARAM *glparam3 = new GL_PARAM();
244    
245    //    //
246    // Orientation variables    // Orientation variables. Vitaly
247    //    //
248    UInt_t evfrom = 0;    UInt_t evfrom = 0;
249    UInt_t jumped = 0;    UInt_t jumped = 0;
# Line 251  int OrbitalInfoCore(UInt_t run, TFile *f Line 260  int OrbitalInfoCore(UInt_t run, TFile *f
260    Int_t nz = 6;    Int_t nz = 6;
261    Float_t zin[6];    Float_t zin[6];
262    Int_t nevtofl2 = 0;    Int_t nevtofl2 = 0;
263    //      if ( verbose ) cout<<"Reading quaternions external file"<<endl;
264    if ( parerror<0 ) {    cout.setf(ios::fixed,ios::floatfield);  
265      code = parerror;    /******Reading recovered quaternions...*********/
266      goto closeandexit;    vector<Double_t> recqtime;
267    };    vector<Float_t> recq0;
268    ltp2 = (Int_t)(glparam->PATH+glparam->NAME).Length();    vector<Float_t> recq1;
269    if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());    vector<Float_t> recq2;
270    //    vector<Float_t> recq3;
271    parerror=glparam2->Query_GL_PARAM(1,302,dbc); // parameters stored in DB in GL_PRAM table    Float_t Norm = 1;
272      Int_t parerror=glparam->Query_GL_PARAM(1,303,dbc); // parameters stored in DB in GL_PRAM table  
273      ifstream in((glparam->PATH+glparam->NAME).Data(),ios::in);
274    if ( parerror<0 ) {    if ( parerror<0 ) {
275      code = parerror;      code = parerror;
276      goto closeandexit;      goto closeandexit;
277    };    }
278    ltp3 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();    while(!in.eof()){
279    if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());      recqtime.resize(recqtime.size()+1);
280    //      Int_t sizee = recqtime.size();
281    initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);      recq0.resize(sizee);
282    //      recq1.resize(sizee);
283    // End IGRF stuff//      recq2.resize(sizee);
284    //      recq3.resize(sizee);
285        in>>recqtime[sizee-1];
286        in>>recq0[sizee-1];
287        in>>recq1[sizee-1];
288        in>>recq2[sizee-1];
289        in>>recq3[sizee-1];
290        in>>Norm;
291      }
292      if ( verbose ) cout<<"We have read recovered data"<<endl;
293    
294      // IGRF stuff moved inside run loop!  
295    
296    for (Int_t ip=0;ip<nz;ip++){    for (Int_t ip=0;ip<nz;ip++){
297      zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));      zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
298    };    };
# Line 342  int OrbitalInfoCore(UInt_t run, TFile *f Line 364  int OrbitalInfoCore(UInt_t run, TFile *f
364    // number of run to be processed    // number of run to be processed
365    //    //
366    numbofrun = runinfo->GetNoRun();    numbofrun = runinfo->GetNoRun();
367    UInt_t totnorun = runinfo->GetRunEntries();    totnorun = runinfo->GetRunEntries();
368    //    //
369    // 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
370    //    //
# Line 376  int OrbitalInfoCore(UInt_t run, TFile *f Line 398  int OrbitalInfoCore(UInt_t run, TFile *f
398        //        //
399        reprocall = true;        reprocall = true;
400        //        //
401        if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n");        if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n Deleting old tree...\n");
402        //        //
403      } else {      } else {
404        //        //
# Line 394  int OrbitalInfoCore(UInt_t run, TFile *f Line 416  int OrbitalInfoCore(UInt_t run, TFile *f
416        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
417        tempOrbitalInfo->SetName("OrbitalInfo-old");        tempOrbitalInfo->SetName("OrbitalInfo-old");
418        tempfile->Write();        tempfile->Write();
419          tempOrbitalInfo->Delete();
420        tempfile->Close();          tempfile->Close();  
421      }      }
422      //      //
423      // Delete the old tree from old file and memory      // Delete the old tree from old file and memory
424      //      //
425        OrbitalInfotrclone->Clear();
426      OrbitalInfotrclone->Delete("all");      OrbitalInfotrclone->Delete("all");
427      //      //
428      if (verbose) printf(" ...done!\n");      if (verbose) printf(" ...done!\n");
# Line 430  int OrbitalInfoCore(UInt_t run, TFile *f Line 454  int OrbitalInfoCore(UInt_t run, TFile *f
454        }        }
455        for (UInt_t j = 0; j < nobefrun; j++){        for (UInt_t j = 0; j < nobefrun; j++){
456          //          //
457          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
458          //          //
459          // copy orbitalinfoclone to mydec          // copy orbitalinfoclone to mydec
460          //          //
# Line 444  int OrbitalInfoCore(UInt_t run, TFile *f Line 468  int OrbitalInfoCore(UInt_t run, TFile *f
468          //          //
469        };        };
470        if (verbose) printf(" Finished successful copying!\n");        if (verbose) printf(" Finished successful copying!\n");
471      };                };
472    };    };
473    //    //
474      //
475    // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.    // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
476    //    //
477    runlist = runinfo->GetRunList();    runlist = runinfo->GetRunList();
# Line 454  int OrbitalInfoCore(UInt_t run, TFile *f Line 479  int OrbitalInfoCore(UInt_t run, TFile *f
479    // Loop over the run to be processed    // Loop over the run to be processed
480    //    //
481    for (UInt_t irun=0; irun < numbofrun; irun++){    for (UInt_t irun=0; irun < numbofrun; irun++){
482    
483        L_QQ_Q_l_lower = new Quaternions();
484        RYPang_lower = new InclinationInfo();
485        L_QQ_Q_l_upper = new Quaternions();
486        RYPang_upper = new InclinationInfo();
487    
488      //      //
489      // retrieve the first run ID to be processed using the RunInfo list      // retrieve the first run ID to be processed using the RunInfo list
490      //      //
# Line 502  int OrbitalInfoCore(UInt_t run, TFile *f Line 533  int OrbitalInfoCore(UInt_t run, TFile *f
533      fname = ftmpname.str().c_str();      fname = ftmpname.str().c_str();
534      ftmpname.str("");      ftmpname.str("");
535      //      //
536      // print out informations      // print nout informations
537      //      //
538      totevent = runinfo->NEVENTS;      totevent = runinfo->NEVENTS;
539      evfrom = runinfo->EV_FROM;      evfrom = runinfo->EV_FROM;
# Line 516  int OrbitalInfoCore(UInt_t run, TFile *f Line 547  int OrbitalInfoCore(UInt_t run, TFile *f
547      //      //
548      //    if ( !totevent ) goto closeandexit;      //    if ( !totevent ) goto closeandexit;
549      // Open Level0 file      // Open Level0 file
550        if ( l0File ) l0File->Close();
551      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
552      if ( !l0File ) {      if ( !l0File ) {
553        if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");        if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");
# Line 554  int OrbitalInfoCore(UInt_t run, TFile *f Line 586  int OrbitalInfoCore(UInt_t run, TFile *f
586        code = -12;        code = -12;
587        goto closeandexit;        goto closeandexit;
588      };      };
589    
590        //
591        // open IGRF files and do it only once if we are processing a full level2 file
592        //
593        if ( irun == 0 ){
594          if ( l0head->GetEntry(runinfo->EV_FROM) <= 0 ) throw -36;
595          //
596          // absolute time of first event of the run (it should not matter a lot)
597          //
598          ph = eh->GetPscuHeader();
599          atime = dbtime->DBabsTime(ph->GetOrbitalTime());
600          
601          parerror=glparam->Query_GL_PARAM(atime-anni5,301,dbc); // parameters stored in DB in GL_PRAM table  
602          if ( parerror<0 ) {
603            code = parerror;
604            goto closeandexit;
605        };
606          ltp1 = (Int_t)(glparam->PATH+glparam->NAME).Length();
607          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
608          //
609          parerror=glparam2->Query_GL_PARAM(atime,301,dbc); // parameters stored in DB in GL_PRAM table  
610          if ( parerror<0 ) {
611            code = parerror;
612            goto closeandexit;
613          };
614          ltp2 = (Int_t)(glparam2->PATH+glparam->NAME).Length();
615          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
616          //
617          parerror=glparam3->Query_GL_PARAM(atime,302,dbc); // parameters stored in DB in GL_PRAM table
618          if ( parerror<0 ) {
619            code = parerror;
620            goto closeandexit;
621          };
622          ltp3 = (Int_t)(glparam3->PATH+glparam2->NAME).Length();
623          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam3->PATH+glparam3->NAME).Data());
624          //
625          initize_((char *)(glparam->PATH+glparam->NAME).Data(),&ltp1,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp2,(char *)(glparam3->PATH+glparam3->NAME).Data(),&ltp3);
626          //
627        }
628        //
629        // End IGRF stuff//
630        //
631    
632        //
633        //     TTree *tp = (TTree*)l0File->Get("RunHeader");
634        //     tp->SetBranchAddress("Header", &eH);
635        //     tp->SetBranchAddress("RunHeader", &reh);
636        //     tp->GetEntry(0);
637        //     ph = eH->GetPscuHeader();
638        //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
639        //     ULong_t ObtSync = reh->OBT_TIME_SYNC;    
640        //     if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
641      //      //
 //     TTree *tp = (TTree*)l0File->Get("RunHeader");  
 //     tp->SetBranchAddress("Header", &eH);  
 //     tp->SetBranchAddress("RunHeader", &reh);  
 //     tp->GetEntry(0);  
 //     ph = eH->GetPscuHeader();  
 //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;  
 //     ULong_t ObtSync = reh->OBT_TIME_SYNC;      
 //     if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);  
 //  
642      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
643      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
644      ULong_t DeltaOBT = TimeSync - ObtSync;      ULong_t DeltaOBT = TimeSync - ObtSync;
645    
646      if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);      if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
647            //
648      l0trm = (TTree*)l0File->Get("Mcmd");      // Read MCMDs from up to 11 files, 5 before and 5 after the present one in order to have some kind of inclination information
649      neventsm = l0trm->GetEntries();      //
650        ch = new TChain("Mcmd","Mcmd");
651        //
652        // look in the DB to find the closest files to this run
653        //
654        TSQLResult *pResult = 0;
655        TSQLRow *Row = 0;
656        stringstream myquery;
657        UInt_t l0fid[10];
658        Int_t i = 0;
659        memset(l0fid,0,10*sizeof(Int_t));
660        //
661        myquery.str("");
662        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;";
663        //
664        pResult = dbc->Query(myquery.str().c_str());
665        //
666        i = 9;
667        if( pResult ){
668          //
669          Row = pResult->Next();
670          //
671          while ( Row ){
672            //
673            // store infos and exit
674            //
675            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
676            i--;
677            Row = pResult->Next();  
678            //
679          };
680          pResult->Delete();
681        };
682        //
683        myquery.str("");
684        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;";
685        //
686        pResult = dbc->Query(myquery.str().c_str());
687        //
688        i = 0;
689        if( pResult ){
690          //
691          Row = pResult->Next();
692          //
693          while ( Row ){
694            //
695            // store infos and exit
696            //
697            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
698            i++;
699            Row = pResult->Next();  
700            //
701          };
702          pResult->Delete();
703        };
704        //
705        i = 0;
706        UInt_t previd = 0;
707        while ( i < 10 ){
708          if ( l0fid[i] && previd != l0fid[i] ){
709            previd = l0fid[i];
710            myquery.str("");
711            myquery << "select PATH,NAME from GL_ROOT where ID=" << l0fid[i] << " ;";
712            //
713            pResult = dbc->Query(myquery.str().c_str());
714            //
715            if( pResult ){
716              //
717              Row = pResult->Next();
718              //
719              if ( debug ) printf(" Using inclination informations from file: %s \n",(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1)).Data());
720              ch->Add(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1));
721              //
722              pResult->Delete();
723            };
724          };
725          i++;
726        };
727        //
728        //    l0trm = (TTree*)l0File->Get("Mcmd");
729        //    ch->ls();
730        ch->SetBranchAddress("Mcmd",&mcmdev);
731        //    printf(" entries %llu \n", ch->GetEntries());
732        //    l0trm = ch->GetTree();
733        //    neventsm = l0trm->GetEntries();
734        neventsm = ch->GetEntries();
735        if ( debug ) printf(" entries %u \n", neventsm);
736      //    neventsm = 0;      //    neventsm = 0;
737      //      //
738      if (neventsm == 0){      if (neventsm == 0){
# Line 582  int OrbitalInfoCore(UInt_t run, TFile *f Line 743  int OrbitalInfoCore(UInt_t run, TFile *f
743      }      }
744      //      //
745            
746      l0trm->SetBranchAddress("Mcmd", &mcmdev);      //    l0trm->SetBranchAddress("Mcmd", &mcmdev);
747      //    l0trm->SetBranchAddress("Header", &eh);      //    l0trm->SetBranchAddress("Header", &eh);
748      //      //
749      //      //
750      //      //
751      UInt_t mctren = 0;      
752      UInt_t mcreen = 0;    //    UInt_t mctren = 0;    
753    //    UInt_t mcreen = 0;        
754      UInt_t numrec = 0;      UInt_t numrec = 0;
755      //      //
756      Double_t upperqtime = 0;      Double_t upperqtime = 0;
757      Double_t lowerqtime = 0;      Double_t lowerqtime = 0;
758            
759      Double_t incli = 0;  //    Double_t incli = 0;
760      oi = 0;  //    oi = 0;
761      UInt_t ooi = 0;  //    UInt_t ooi = 0;
762      //      //
763      // init quaternions sync      // init quaternions information from mcmd-packets
764      //      //
765      Bool_t isf = true;      Bool_t isf = true;
766      Int_t fgh = 0;  //    Int_t fgh = 0;
767    
768        vector<Float_t> q0;
769        vector<Float_t> q1;
770        vector<Float_t> q2;
771        vector<Float_t> q3;
772        vector<Double_t> qtime;
773        vector<Float_t> qPitch;
774        vector<Float_t> qRoll;
775        vector<Float_t> qYaw;
776        vector<Int_t> qmode;
777    
778        Int_t nt = 0;
779        
780        //init sine-function interpolation
781        
782        //cout<<"Sine coeficient initialisation..."<<endl;
783        vector<Sine> q0sine;
784        vector<Sine> q1sine;
785        vector<Sine> q2sine;
786        vector<Sine> q3sine;
787        vector<Sine> Yawsine;
788    
789        /*TH2F* q0testing = new TH2F();
790          TH2F* q1testing = new TH2F();
791          TH2F* q2testing = new TH2F();
792          TH2F* q3testing = new TH2F();
793          TH2F* Pitchtesting = new TH2F();
794        */
795        UInt_t must = 0;
796    
797      //      //
798      // run over all the events of the run      // run over all the events of the run
799      //      //
800      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");
801      //      //
802       //      //
803      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
       
804        //        //
805        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
806        if ( debug ) printf(" %i \n",procev);              if ( debug ) printf(" %i \n",procev);      
807        //        //
808        l0head->GetEntry(re);        if ( l0head->GetEntry(re) <= 0 ) throw -36;
809        //        //
810        // absolute time of this event        // absolute time of this event
811        //        //
812        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
813        atime = dbtime->DBabsTime(ph->GetOrbitalTime());        atime = dbtime->DBabsTime(ph->GetOrbitalTime());
814          if ( debug ) printf(" %i absolute time \n",procev);      
815        //        //
816        // paranoid check        // paranoid check
817        //        //
818        if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1))  ) {        if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1))  ) {
819          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");
820          jumped++;          jumped++;
821  //      debug = true;          //      debug = true;
822          continue;          continue;
823        }        }
824    
# Line 651  int OrbitalInfoCore(UInt_t run, TFile *f Line 843  int OrbitalInfoCore(UInt_t run, TFile *f
843          //          //
844          tof->Clear();          tof->Clear();
845          //          //
846          ttof->GetEntry(itr);          if ( ttof->GetEntry(itr) <= 0 ) throw -36;
847          //          //
848        };        };
849        //        //
# Line 659  int OrbitalInfoCore(UInt_t run, TFile *f Line 851  int OrbitalInfoCore(UInt_t run, TFile *f
851        //        //
852        // start processing        // start processing
853        //        //
854          if ( debug ) printf(" %i start processing \n",procev);      
855        orbitalinfo->Clear();        orbitalinfo->Clear();
856        //        //
857        OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();        OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
# Line 670  int OrbitalInfoCore(UInt_t run, TFile *f Line 863  int OrbitalInfoCore(UInt_t run, TFile *f
863        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
864        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
865        orbitalinfo->absTime = atime;        orbitalinfo->absTime = atime;
866          if ( debug ) printf(" %i pktnum obt abstime \n",procev);      
867        //        //
868        // Propagate the orbit from the tle time to atime, using SGP(D)4.        // Propagate the orbit from the tle time to atime, using SGP(D)4.
869        //        //
870          if ( debug ) printf(" %i sgp4 \n",procev);      
871        cCoordGeo coo;        cCoordGeo coo;
872        float jyear=0;            Float_t jyear=0.;    
873        //        //
874        if(atime >= gltle->GetToTime()) {        if(atime >= gltle->GetToTime()) {
875          if ( !gltle->Query(atime, dbc) ){          if ( !gltle->Query(atime, dbc) ){
876            //                  //      
877            // Compute the magnetic dipole moment.            // Compute the magnetic dipole moment.
878            //            //
879              if ( debug ) printf(" %i compute magnetic dipole moment \n",procev);      
880            UInt_t year, month, day, hour, min, sec;            UInt_t year, month, day, hour, min, sec;
881            //            //
882            TTimeStamp t = TTimeStamp(atime, kTRUE);            TTimeStamp t = TTimeStamp(atime, kTRUE);
# Line 688  int OrbitalInfoCore(UInt_t run, TFile *f Line 884  int OrbitalInfoCore(UInt_t run, TFile *f
884            t.GetTime(kTRUE, 0, &hour, &min, &sec);            t.GetTime(kTRUE, 0, &hour, &min, &sec);
885            jyear = (float) year            jyear = (float) year
886              + (month*31.+ (float) day)/365.              + (month*31.+ (float) day)/365.
887              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);              + (hour*3600.+min*60.+(float)sec)/(24.*3600.*365.);
888            //            //
889              if ( debug ) printf(" %i compute magnetic dipole moment get dipole moment for year\n",procev);      
890              if ( debug ) printf(" %i jyear %f dimo %f \n",procev,jyear,dimo);      
891            feldcof_(&jyear, &dimo); // get dipole moment for year            feldcof_(&jyear, &dimo); // get dipole moment for year
892              if ( debug ) printf(" %i compute magnetic dipole moment end\n",procev);      
893          } else {          } else {
894            code = -56;            code = -56;
895            goto closeandexit;            goto closeandexit;
# Line 705  int OrbitalInfoCore(UInt_t run, TFile *f Line 904  int OrbitalInfoCore(UInt_t run, TFile *f
904        // synchronize with quaternions data        // synchronize with quaternions data
905        //        //
906        if ( isf && neventsm>0 ){        if ( isf && neventsm>0 ){
         if ( debug ) printf(" I am here \n");  
907          //          //
908          // First event          // First event
909          //          //
910          isf = false;          isf = false;
911          upperqtime = atime;          upperqtime = atime;
912          lowerqtime = runinfo->RUNHEADER_TIME;          lowerqtime = runinfo->RUNHEADER_TIME;
913          for ( ik = 0; ik < neventsm; ik++){          for ( ik = 0; ik < neventsm; ik++){  //number of macrocommad packets
914            l0trm->GetEntry(ik);            if ( ch->GetEntry(ik) <= 0 ) throw -36;
915            tmpSize = mcmdev->Records->GetEntries();            tmpSize = mcmdev->Records->GetEntries();
916            numrec = tmpSize;            numrec = tmpSize;
917            for (Int_t j3 = 0;j3<tmpSize;j3++){            for (Int_t j3 = 0;j3<tmpSize;j3++){  //number of subpackets
918              if ( debug ) printf(" eh eh eh \n");              if ( debug ) printf(" ik %i j3 %i eh eh eh \n",ik,j3);
919              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
920              if ((int)mcmdrc->ID1 == 226){              if ( mcmdrc ){ // missing inclination bug [8RED 090116]
921                L_QQ_Q_l_upper->fill(mcmdrc->McmdData);                if ( debug ) printf(" pluto \n");
922                for (UInt_t ui = 0; ui < 6; ui++){                if ((int)mcmdrc->ID1 == 226 && mcmdrc->Mcmd_Block_crc_ok == 1){ //Check that it is Inclination Packet
923                  if (ui>0){                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
924                    if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){                  for (UInt_t ui = 0; ui < 6; ui++){
925                      if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){                    if (ui>0){
926                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));                      if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
927                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          if ( debug ) printf(" here1 %i \n",ui);
928                        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]);                        Double_t u_time = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
929                      }else {                        Int_t recSize = recqtime.size();
930                        lowerqtime = upperqtime;                        if(lowerqtime > recqtime[recSize-1]){
931                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));                            Int_t sizeqmcmd = qtime.size();
932                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
933                        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]);                            qtime[sizeqmcmd]=u_time;
934                        mcreen = j3;                            q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
935                        mctren = ik;                            q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
936                        if(fgh==0){                            q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
937                          CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                            q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
938                          CopyAng(RYPang_lower,RYPang_upper);                            qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
939                              lowerqtime = u_time;
940                              orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
941                              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]);
942                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
943                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
944                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
945                          }
946                          for(Int_t mu = nt;mu<recSize;mu++){
947                            if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
948                              nt=mu;
949                              Int_t sizeqmcmd = qtime.size();
950                              inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
951                              qtime[sizeqmcmd]=recqtime[mu];
952                              q0[sizeqmcmd]=recq0[mu];
953                              q1[sizeqmcmd]=recq1[mu];
954                              q2[sizeqmcmd]=recq2[mu];
955                              q3[sizeqmcmd]=recq3[mu];
956                              qmode[sizeqmcmd]=-10;
957                              orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
958                              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,recq0[mu],recq1[mu],recq2[mu],recq3[mu]);
959                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
960                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
961                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
962                            }
963                            if(recqtime[mu]>=u_time){
964                              Int_t sizeqmcmd = qtime.size();
965                              inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
966                              qtime[sizeqmcmd]=u_time;
967                              q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
968                              q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
969                              q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
970                              q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
971                              qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
972                              lowerqtime = u_time;
973                              orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
974                              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]);
975                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
976                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
977                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
978                              break;
979                            }
980                        }                        }
                       oi=ui;  
                       goto closethisloop;  
981                      }                      }
982                      fgh++;                    }else{
983                      CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          if ( debug ) printf(" here2 %i \n",ui);
984                      CopyAng(RYPang_lower,RYPang_upper);                      Double_t u_time = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
985                    }                      if(lowerqtime>u_time)nt=0;
986                  }else{                      Int_t recSize = recqtime.size();
987                    if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){                      if(lowerqtime > recqtime[recSize-1]){
988                      upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                          Int_t sizeqmcmd = qtime.size();
989                      orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
990                      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]);                          qtime[sizeqmcmd]=u_time;
991                    }                          q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
992                    else {                          q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
993                      lowerqtime = upperqtime;                          q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
994                      upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                          q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
995                      orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
996                      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]);                          lowerqtime = u_time;
997                      mcreen = j3;                          orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
998                      mctren = ik;                          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]);
999                      if(fgh==0){                          qRoll[sizeqmcmd]=RYPang_upper->Kren;
1000                        CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1001                        CopyAng(RYPang_lower,RYPang_upper);                          qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1002                        lowerqtime = atime-1;                      }
1003                        for(Int_t mu = nt;mu<recSize;mu++){
1004                          if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
1005                            nt=mu;
1006                            Int_t sizeqmcmd = qtime.size();
1007                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1008                            qtime[sizeqmcmd]=recqtime[mu];
1009                            q0[sizeqmcmd]=recq0[mu];
1010                            q1[sizeqmcmd]=recq1[mu];
1011                            q2[sizeqmcmd]=recq2[mu];
1012                            q3[sizeqmcmd]=recq3[mu];
1013                            qmode[sizeqmcmd]=-10;
1014                            orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1015                            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,recq0[mu],recq1[mu],recq2[mu],recq3[mu]);
1016                            qRoll[sizeqmcmd]=RYPang_upper->Kren;
1017                            qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1018                            qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1019                          }
1020                          if(recqtime[mu]>=u_time){
1021                            Int_t sizeqmcmd = qtime.size();
1022                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1023                            qtime[sizeqmcmd]=u_time;
1024                            q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
1025                            q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
1026                            q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
1027                            q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
1028                            qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1029                            lowerqtime = u_time;
1030                            orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1031                            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]);
1032                            qRoll[sizeqmcmd]=RYPang_upper->Kren;
1033                            qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1034                            qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1035                            CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
1036                            break;
1037                          }
1038                      }                      }
                     oi=ui;  
                     goto closethisloop;  
                     //_0 = true;  
1039                    }                    }
1040                    fgh++;                  }
                   CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);  
                   CopyAng(RYPang_lower,RYPang_upper);  
                   //_0 = true;  
                 };  
                 //cin>>grib;  
               };  
             };  
           };  
         };  
       };  
     closethisloop:  
       //  
       if ( debug ) printf(" I am There \n");  
       //  
       if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){  
         if ( debug ) printf(" I am there \n");  
         //  
         lowerqtime = upperqtime;  
         Long64_t maxloop = 100000000LL;  
         Long64_t mn = 0;  
         bool gh=false;  
         ooi=oi;  
         if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);  
         while (!gh){        
           if ( mn > maxloop ){  
             if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");  
             gh = true;  
             neventsm = 0;  
           };  
           mn++;  
           if (oi<5) oi++;  
           else oi=0;  
           if (oi==0 && numrec > 0){  
             if ( debug ) printf(" mumble \n");  
             mcreen++;  
             if (mcreen == numrec){  
               mctren++;  
               mcreen = 0;  
               l0trm->GetEntry(mctren);  
               numrec = mcmdev->Records->GetEntries();  
             }  
             CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);  
             CopyAng(RYPang_lower,RYPang_upper);  
             mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);  
             if ((int)mcmdrc->ID1 == 226){  
               L_QQ_Q_l_upper->fill(mcmdrc->McmdData);  
               upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));  
               if (upperqtime<lowerqtime){  
                 upperqtime=runinfo->RUNTRAILER_TIME;  
                 CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);  
                 CopyAng(RYPang_upper,RYPang_lower);  
               }else{  
                 orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);  
                 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]);  
1041                }                }
               //              re--;  
               gh=true;  
1042              }              }
1043            }else{              if ( debug ) printf(" ciccio \n");
             if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){  
               upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
               orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);  
               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]);  
               orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi);  
               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]);  
               //              re--;  
               gh=true;  
             };  
           };  
         };  
         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);  
       };  
       //  
       if ( debug ) printf(" I am THIS \n");  
       //  
       // Fill in quaternions and angles  
       //  
       if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)&& neventsm>0){        
         if ( debug ) printf(" I am this \n");  
         UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);  
         if (oi == 0){  
           if ((tut!=5)||(tut!=6)){  
             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)));  
             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));  
             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)));  
             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));  
             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)));  
             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));  
             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)));  
             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));  
           
             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)));  
             orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));  
             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)));  
             orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));  
             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)));  
             orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));  
1044            }            }
1045            if (tut==6){          }
             if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){  
               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)));  
               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));  
               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)));  
               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));  
               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)));  
               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));  
               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)));  
               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));  
1046                    
1047                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)));          if(qtime.size()==0){
1048                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));              for(UInt_t my=0;my<recqtime.size();my++){
1049                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)));                  Int_t sizeqmcmd = qtime.size();
1050                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                  inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1051                //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";                  qtime[sizeqmcmd]=recqtime[my];
1052                //cin>>grib;                  q0[sizeqmcmd]=recq0[my];
1053                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)));                  q1[sizeqmcmd]=recq1[my];
1054                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                  q2[sizeqmcmd]=recq2[my];
1055                    q3[sizeqmcmd]=recq3[my];
1056                    qmode[sizeqmcmd]=-10;
1057                    orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1058                    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,recq0[my],recq1[my],recq2[my],recq3[my]);
1059                    qRoll[sizeqmcmd]=RYPang_upper->Kren;
1060                    qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1061                    qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1062              }              }
1063            }          }
         } else {  
           if((tut!=6)||(tut!=7)||(tut!=9)){  
             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)));  
             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));  
             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)));  
             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));  
             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)));  
             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));  
             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)));  
             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));  
1064                    
1065              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)));          if ( debug ) printf(" fuffi \n");
1066              orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1067              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)));          if ( debug ) printf(" puffi \n");
1068              orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));          Double_t tmin = 9999999999.;
1069              //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";          Double_t tmax = 0.;
1070              //cin>>grib;          for(UInt_t tre = 0;tre<qtime.size();tre++){
1071              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)));            if(qtime[tre]>tmax)tmax = qtime[tre];
1072              orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));            if(qtime[tre]<tmin)tmin = qtime[tre];
1073            }
1074            if ( debug ) printf(" gnfuffi \n");
1075    
1076          } // if we processed first event
1077    
1078          
1079          //Filling Inclination information
1080          Double_t incli = 0;
1081          if ( qtime.size() > 1 ){
1082          for(UInt_t mu = must;mu<qtime.size()-1;mu++){
1083            if ( debug ) printf(" ??grfuffi %i sixe %i must %i \n",mu,qtime.size()-1,must);
1084            if(qtime[mu+1]>qtime[mu]){
1085              if ( debug ) printf(" grfuffi2 %i \n",mu);
1086              if(atime<=qtime[mu+1] && atime>=qtime[mu]){
1087                must = mu;
1088                incli = (qPitch[mu+1]-qPitch[mu])/(qtime[mu+1]-qtime[mu]);
1089                orbitalinfo->theta =  incli*atime+qPitch[mu+1]-incli*qtime[mu+1];
1090                incli = (qRoll[mu+1]-qRoll[mu])/(qtime[mu+1]-qtime[mu]);
1091                orbitalinfo->etha =  incli*atime+qRoll[mu+1]-incli*qtime[mu+1];
1092                incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1093                orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1094                
1095                incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1096                orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1097                incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1098                orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1099                incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1100                orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1101                incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1102                orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1103                
1104                orbitalinfo->TimeGap = qtime[mu+1]-qtime[mu];
1105                orbitalinfo->mode = qmode[mu+1];
1106                //if(qmode[mu+1]==-10) orbitalinfo->R10r = true;else orbitalinfo->R10r = false;
1107                //reserved for next versions Vitaly.
1108                /*if(qmode[mu+1]==-10 || qmode[mu+1]==0 || qmode[mu+1]==1 || qmode[mu+1]==3 || qmode[mu+1]==4 || qmode[mu+1]==6){
1109                  //linear interpolation
1110                  incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1111                  orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1112                  incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1113                  orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1114                  incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1115                  orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1116                  incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1117                  orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1118                }else{
1119                  //sine interpolation
1120                  for(UInt_t mt=0;mt<q0sine.size();mt++){
1121                    if(atime<=q0sine[mt].finishPoint && atime>=q0sine[mt].startPoint){
1122                      if(!q0sine[mt].NeedFit)orbitalinfo->q0=q0sine[mt].A*sin(q0sine[mt].b*atime+q0sine[mt].c);else{
1123                        incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1124                        orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1125                      }
1126                    }
1127                    if(atime<=q1sine[mt].finishPoint && atime>=q1sine[mt].startPoint){
1128                      if(!q1sine[mt].NeedFit)orbitalinfo->q1=q1sine[mt].A*sin(q1sine[mt].b*atime+q1sine[mt].c);else{
1129                        incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1130                        orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1131                      }
1132                    }
1133                    if(atime<=q2sine[mt].finishPoint && atime>=q2sine[mt].startPoint){
1134                      if(!q2sine[mt].NeedFit)orbitalinfo->q2=q0sine[mt].A*sin(q2sine[mt].b*atime+q2sine[mt].c);else{
1135                        incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1136                        orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1137                      }
1138                    }
1139                    if(atime<=q3sine[mt].finishPoint && atime>=q3sine[mt].startPoint){
1140                      if(!q3sine[mt].NeedFit)orbitalinfo->q3=q0sine[mt].A*sin(q3sine[mt].b*atime+q3sine[mt].c);else{
1141                        incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1142                        orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1143                      }
1144                    }
1145                    if(atime<=Yawsine[mt].finishPoint && atime>=Yawsine[mt].startPoint){
1146                      if(!Yawsine[mt].NeedFit)orbitalinfo->phi=Yawsine[mt].A*sin(Yawsine[mt].b*atime+Yawsine[mt].c);else{
1147                        incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1148                        orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1149                      }
1150                    }
1151                  }
1152                }*/
1153                //q0testing->Fill(atime,orbitalinfo->q0,100);
1154                //q1testing->Fill(atime,orbitalinfo->q1,100);
1155                //Pitchtesting->Fill(atime,orbitalinfo->etha);
1156                //q2testing->Fill(atime,orbitalinfo->q2);
1157                //q3testing->Fill(atime,orbitalinfo->q3);
1158                break;
1159            }            }
           if (tut==6){  
             if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){  
               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)));  
               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));  
               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)));  
               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));  
               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)));  
               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));  
               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)));  
               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));  
           
               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)));  
               orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
               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)));  
               orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
               //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";  
               //cin>>grib;  
               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)));  
               orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
             }  
           }              
1160          }          }
1161          //        }
1162          orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);        }
         //  
       } else {  
         if ( debug ) printf(" ops no incl! \n");  
         orbitalinfo->mode = 10;  
       };  
1163        //        //
1164        // ops no inclination information        // ops no inclination information
1165        //        //
1166    
1167        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 ){        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 ){
1168          orbitalinfo->mode = 10;          orbitalinfo->mode = 10;
1169          orbitalinfo->q0 = -1000.;          orbitalinfo->q0 = -1000.;
# Line 978  int OrbitalInfoCore(UInt_t run, TFile *f Line 1202  int OrbitalInfoCore(UInt_t run, TFile *f
1202          orbitalinfo->Beast = beast;          orbitalinfo->Beast = beast;
1203          orbitalinfo->Bdown = bdown;          orbitalinfo->Bdown = bdown;
1204          orbitalinfo->Babs = babs;          orbitalinfo->Babs = babs;
1205            orbitalinfo->M = dimo;
1206          orbitalinfo->BB0 = babs/bequ;          orbitalinfo->BB0 = babs/bequ;
1207          orbitalinfo->L = xl;                orbitalinfo->L = xl;      
1208          // Set Stormer vertical cutoff using L shell.          // Set Stormer vertical cutoff using L shell.
1209          orbitalinfo->cutoffsvl = 14.9/(xl*xl);          orbitalinfo->cutoffsvl = 14.295 / (xl*xl); //
1210            /*
1211    ---------- Forwarded message ----------
1212    Date: Wed, 09 May 2012 12:16:47 +0200
1213    From: Alessandro Bruno <alessandro.bruno@ba.infn.it>
1214    To: Mirko Boezio <mirko.boezio@ts.infn.it>
1215    Cc: Francesco S. Cafagna <Francesco.Cafagna@ba.infn.it>
1216    Subject: Störmer vertical cutoff
1217    
1218    Ciao Mirko,
1219    volevo segnalarti che il valore dello Störmer vertical cutoff nel Level2 è
1220    sovrastimato di circa il 4%.
1221    Dopo un'approfondita analisi con l'IGRF-05 abbiamo ricavano un valore pari
1222    a: 14.295 / L^2 anzichè 14.9 / L^2, valore obsoleto in quanto riferito agli
1223    anni '50.
1224    */
1225            //14.9/(xl*xl);
1226            orbitalinfo->igrf_icode = icode;
1227          //          //
1228        };              };      
1229        //        //
1230          if ( debug ) printf(" pitch angle \n");
1231          //
1232        // pitch angles        // pitch angles
1233        //        //
1234        if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){        //if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){
1235          if( orbitalinfo->TimeGap>0 && orbitalinfo->TimeGap<2000000){
1236          //          //
1237          Float_t Bx = -orbitalinfo->Bdown;                       //don't need for PamExp ExpOnly for all geography areas          Float_t Bx = -orbitalinfo->Bdown;
1238          Float_t By = orbitalinfo->Beast;                        //don't need for PamExp ExpOnly for all geography areas          Float_t By = orbitalinfo->Beast;
1239          Float_t Bz = orbitalinfo->Bnorth;                       //don't need for PamExp ExpOnly for all geography areas          Float_t Bz = orbitalinfo->Bnorth;
1240          //          //
1241          TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);          TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);
1242            TMatrixD Gij = PO->ColPermutation(Fij);
1243          TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);          TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);
1244          TMatrixD Iij = PO->ColPermutation(Dij);          TMatrixD Iij = PO->ColPermutation(Dij);
1245          //          //
# Line 1003  int OrbitalInfoCore(UInt_t run, TFile *f Line 1249  int OrbitalInfoCore(UInt_t run, TFile *f
1249          A1 = Iij(0,2);          A1 = Iij(0,2);
1250          A2 = Iij(1,2);          A2 = Iij(1,2);
1251          A3 = Iij(2,2);          A3 = Iij(2,2);
1252          //                //
1253          //      orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3);                        // Angle between zenit and Pamela's main axiz          //      orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3);                        // Angle between zenit and Pamela's main axiz
1254          //      orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz);                 // Angle between Pamela's main axiz and B          //      orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz);                 // Angle between Pamela's main axiz and B
1255          //          //
# Line 1021  int OrbitalInfoCore(UInt_t run, TFile *f Line 1267  int OrbitalInfoCore(UInt_t run, TFile *f
1267              Double_t E22z = zin[3];              Double_t E22z = zin[3];
1268              if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1  ){              if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1  ){
1269                Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));                Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1270                Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));                //              Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1271                if(E22x-E11x>=0 && E22y-E11y <0) MyAzim =  360. - MyAzim;                //              if(E22x-E11x>=0 && E22y-E11y <0) MyAzim =  360. - MyAzim;
1272                if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;                //              if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1273                if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;                //              if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1274                if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;                //              if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1275                Px = (E22x-E11x)/norm;                Px = (E22x-E11x)/norm;
1276                Py = (E22y-E11y)/norm;                Py = (E22y-E11y)/norm;
1277                Pz = (E22z-E11z)/norm;                Pz = (E22z-E11z)/norm;
# Line 1036  int OrbitalInfoCore(UInt_t run, TFile *f Line 1282  int OrbitalInfoCore(UInt_t run, TFile *f
1282                t_orb->Eij.ResizeTo(Eij);                t_orb->Eij.ResizeTo(Eij);
1283                t_orb->Eij = Eij;                t_orb->Eij = Eij;
1284                //                //
1285                TMatrixD Sij = PO->PamelatoGEO(Fij,Px,Py,Pz);                TMatrixD Sij = PO->PamelatoGEO(Gij,Px,Py,Pz);
1286                t_orb->Sij.ResizeTo(Sij);                t_orb->Sij.ResizeTo(Sij);
1287                t_orb->Sij = Sij;                t_orb->Sij = Sij;
1288                //                            //            
# Line 1047  int OrbitalInfoCore(UInt_t run, TFile *f Line 1293  int OrbitalInfoCore(UInt_t run, TFile *f
1293                //                //
1294                t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));                t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1295                //                //
1296                  if ( t_orb->pitch != t_orb->pitch ) t_orb->pitch = -1000.;
1297                  if ( t_orb->cutoff != t_orb->cutoff ) t_orb->cutoff = -1000.;
1298                  //
1299                if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);                if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1300                //                //
1301                new(tor[nn]) OrbitalInfoTrkVar(*t_orb);                new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
# Line 1061  int OrbitalInfoCore(UInt_t run, TFile *f Line 1310  int OrbitalInfoCore(UInt_t run, TFile *f
1310            if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());            if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());
1311          };          };
1312          //          //
1313          } else {
1314            if ( !standalone && tof->ntrk() > 0 ){
1315              //
1316              Int_t nn = 0;
1317              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1318                //
1319                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1320                if ( ptt->trkseqno != -1  ){
1321                  //
1322                  t_orb->trkseqno = ptt->trkseqno;
1323                  //
1324                  t_orb->Eij = 0;  
1325                  //
1326                  t_orb->Sij = 0;
1327                  //            
1328                  t_orb->pitch = -1000.;
1329                  //
1330                  t_orb->cutoff = -1000.;
1331                  //
1332                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1333                  nn++;
1334                  //
1335                  t_orb->Clear();
1336                  //
1337                };
1338                //
1339              };    
1340            };
1341        };        };
1342        //        //
1343        // Fill the class        // Fill the class
# Line 1073  int OrbitalInfoCore(UInt_t run, TFile *f Line 1350  int OrbitalInfoCore(UInt_t run, TFile *f
1350      //      //
1351      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
1352      //      //
1353    
1354        //gStyle->SetOptStat(000000);
1355        //gStyle->SetPalette(1);
1356        
1357        /*TCanvas* c1 = new TCanvas("c1","",1200,800);
1358        //c1->Divide(1,4);
1359        c1->cd(1);
1360        //q0testing->Draw("colz");
1361        //c1->cd(2);
1362        //q1testing->Draw("colz");
1363        //c1->cd(3);
1364        Pitchtesting->Draw("colz");
1365        //c1->cd(4);
1366        //q3testing->Draw("colz");
1367        c1->SaveAs("9.Rollhyst.png");
1368        delete c1;*/
1369    
1370        if ( verbose ) printf(" Clear before new run \n");
1371      delete dbtime;      delete dbtime;
1372      if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;  
1373        mcmdrc->Clear();
1374        mcmdrc = 0;
1375        
1376        if ( verbose ) printf(" Clear before new run1 \n");
1377      if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;      if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
1378        if ( verbose ) printf(" Clear before new run2 \n");
1379        if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1380        if ( verbose ) printf(" Clear before new run3 \n");
1381      if ( RYPang_upper ) delete RYPang_upper;      if ( RYPang_upper ) delete RYPang_upper;
1382        if ( verbose ) printf(" Clear before new run4 \n");
1383      if ( RYPang_lower ) delete RYPang_lower;      if ( RYPang_lower ) delete RYPang_lower;
1384    
1385        if ( l0tr ) l0tr->Delete();
1386        
1387        if ( verbose ) printf(" End run \n");
1388    
1389    }; // process all the runs    }; // process all the runs
1390        
1391    if (verbose) printf("\n Finished processing data \n");    if (verbose) printf("\n Finished processing data \n");
# Line 1097  int OrbitalInfoCore(UInt_t run, TFile *f Line 1405  int OrbitalInfoCore(UInt_t run, TFile *f
1405          //          //
1406          // Get entry from old tree          // Get entry from old tree
1407          //          //
1408          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
1409          //          //
1410          // copy orbitalinfoclone to OrbitalInfo          // copy orbitalinfoclone to OrbitalInfo
1411          //          //
# Line 1111  int OrbitalInfoCore(UInt_t run, TFile *f Line 1419  int OrbitalInfoCore(UInt_t run, TFile *f
1419        };        };
1420        if (verbose) printf(" Finished successful copying!\n");        if (verbose) printf(" Finished successful copying!\n");
1421      };      };
1422        //if ( OrbitalInfotrclone )    OrbitalInfotrclone->Clear();        
1423        //if ( OrbitalInfotrclone )    OrbitalInfotrclone->Delete();        
1424    };    };
1425    //    //
1426    // Close files, delete old tree(s), write and close level2 file    // Close files, delete old tree(s), write and close level2 file
1427    //    //
1428    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
   if ( tempfile ) tempfile->Close();              
1429    if ( myfold ) gSystem->Unlink(tempname.str().c_str());    if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1430    //    //
   if ( runinfo ) runinfo->Close();      
1431    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
   if ( tof ) tof->Delete();  
   if ( ttof ) ttof->Delete();  
1432    //    //
1433    if ( file ){    if ( file ){
1434      file->cd();      file->cd();
1435      file->Write();      OrbitalInfotr->Write("OrbitalInfo", TObject::kOverwrite);
1436    };    };
1437    //    //
1438      if (verbose) printf("\n Exiting...\n");
1439    
1440    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1441    //    //
1442    // the end    // the end
# Line 1137  int OrbitalInfoCore(UInt_t run, TFile *f Line 1445  int OrbitalInfoCore(UInt_t run, TFile *f
1445      dbc->Close();      dbc->Close();
1446      delete dbc;      delete dbc;
1447    };    };
   if (verbose) printf("\n Exiting...\n");  
   if(OrbitalInfotr)OrbitalInfotr->Delete();  
1448    //    //
1449      if (verbose) printf("\n Exiting...\n");
1450      if ( tempfile ) tempfile->Close();            
1451      
1452    if ( PO ) delete PO;    if ( PO ) delete PO;
1453    if ( orbitalinfo ) delete orbitalinfo;    if ( gltle ) delete gltle;
1454    if ( orbitalinfoclone ) delete orbitalinfoclone;    if ( glparam ) delete glparam;
1455      if ( glparam2 ) delete glparam2;
1456      if ( glparam3 ) delete glparam3;
1457      if (verbose) printf("\n Exiting3...\n");
1458    if ( glroot ) delete glroot;    if ( glroot ) delete glroot;
1459      if (verbose) printf("\n Exiting4...\n");
1460      if ( runinfo ) runinfo->Close();    
1461    if ( runinfo ) delete runinfo;    if ( runinfo ) delete runinfo;
1462    
1463      if ( debug ){  
1464      cout << "1   0x" << OrbitalInfotr << endl;
1465      cout << "2   0x" << OrbitalInfotrclone << endl;
1466      cout << "3   0x" << l0tr << endl;
1467      cout << "4   0x" << tempOrbitalInfo << endl;
1468      cout << "5   0x" << ttof << endl;
1469      }
1470      //
1471      if ( debug )  file->ls();
1472    //    //
1473    if(code < 0)  throw code;    if(code < 0)  throw code;
1474    return(code);    return(code);
# Line 1189  void CopyAng(InclinationInfo *A1, Inclin Line 1513  void CopyAng(InclinationInfo *A1, Inclin
1513  UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){  UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
1514        
1515    UInt_t hole = 10;    UInt_t hole = 10;
1516    bool R10l = false;     // Sign of R10 mode in lower quaternions array    Bool_t R10l = false;     // Sign of R10 mode in lower quaternions array
1517    bool R10u = false;     // Sign of R10 mode in upper quaternions array    Bool_t R10u = false;     // Sign of R10 mode in upper quaternions array
1518    bool insm = false;     // Sign that we inside quaternions array    Bool_t insm = false;     // Sign that we inside quaternions array
1519    bool mxtml = false;    // Sign of mixt mode in lower quaternions array    Bool_t mxtml = false;    // Sign of mixt mode in lower quaternions array
1520    bool mxtmu = false;    // Sign of mixt mode in upper quaternions array    Bool_t mxtmu = false;    // Sign of mixt mode in upper quaternions array
1521    bool npasm = false;     // Sign of normall pass between R10 and non R10 or between non R10 and R10    Bool_t npasm = false;     // Sign of normall pass between R10 and non R10 or between non R10 and R10
1522    UInt_t NCQl = 6;       // Number of correct quaternions in lower array    UInt_t NCQl = 6;       // Number of correct quaternions in lower array
1523    UInt_t NCQu = 6;       // Number of correct quaternions in upper array    UInt_t NCQu = 6;       // Number of correct quaternions in upper array
1524    if (f>0){    if (f>0){
# Line 1237  UInt_t holeq(Double_t lower,Double_t upp Line 1561  UInt_t holeq(Double_t lower,Double_t upp
1561    return hole;    return hole;
1562  }  }
1563    
1564    void inclresize(vector<Double_t>& t,vector<Float_t>& q0,vector<Float_t>& q1,vector<Float_t>& q2,vector<Float_t>& q3,vector<Int_t>& mode,vector<Float_t>& Roll,vector<Float_t>& Pitch,vector<Float_t>& Yaw){
1565      Int_t sizee = t.size()+1;
1566      t.resize(sizee);
1567      q0.resize(sizee);
1568      q1.resize(sizee);
1569      q2.resize(sizee);
1570      q3.resize(sizee);
1571      mode.resize(sizee);
1572      Roll.resize(sizee);
1573      Pitch.resize(sizee);
1574      Yaw.resize(sizee);
1575    }
1576    
1577    //Find fitting sine functions for q0,q1,q2,q3 and Yaw-angle;
1578    void sineparam(vector<Sine>& qsine, vector<Double_t>& qtime, vector<Float_t>& q, vector<Float_t>& Roll, vector<Float_t>& Pitch, Float_t limsin){
1579      UInt_t mulast = 0;
1580      UInt_t munow = 0;
1581      UInt_t munext = 0;
1582      Bool_t increase = false;
1583      Bool_t decrease = false;
1584      Bool_t Max_is_defined = false;
1585      Bool_t Start_point_is_defined = false;
1586      Bool_t Period_is_defined = false;
1587      Bool_t Large_gap = false;
1588      Bool_t normal_way = true;
1589      Bool_t small_gap_on_ridge = false;
1590      Double_t t1 = 0;
1591      Double_t t1A = 0;
1592      Int_t sinesize = 0;
1593      Int_t nfi = 0;
1594      for(UInt_t mu = 0;mu<qtime.size();mu++){
1595        //cout<<"Roll["<<mu<<"] = "<<Roll[mu]<<endl;
1596        if(TMath::Abs(Roll[mu])<1. && TMath::Abs(Pitch[mu])<1. && TMath::Abs(q[mu])<limsin){
1597        //cout<<"q["<<mu<<endl<<"] = "<<q[mu]<<endl;
1598        if(mulast!=0 && munow!=0 && munext!=0){mulast=munow;munow=munext;munext=mu;}
1599        if(munext==0 && munow!=0)munext=mu;
1600        if(munow==0 && mulast!=0)munow=mu;
1601        if(mulast==0)mulast=mu;
1602        
1603        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1604        //Int_t ref;
1605        //cin>>ref;
1606        if(TMath::Abs(q[munow])>TMath::Abs(q[mulast]) && TMath::Abs(q[munow])>TMath::Abs(q[munext]) && q[mulast]*q[munext]>0 && qtime[munext]-qtime[mulast]>400)small_gap_on_ridge = true;
1607        if(munext>mulast && (qtime[munext]-qtime[mulast]>=2000 || qtime[munext]-qtime[mulast]<0)){if(Large_gap){normal_way = false;Large_gap = false;}else{Large_gap = true;normal_way = false;}}else normal_way = true;
1608        //if(normal_way)cout<<"Normal_Way"<<endl;
1609        if(Large_gap || small_gap_on_ridge){
1610          //cout<<"Large gap..."<<endl;
1611          //if(small_gap_on_ridge)cout<<"small gap..."<<endl;
1612          //cout<<"q["<<mulast<<"] = "<<q[mulast]<<"\tq["<<munow<<"] = "<<q[munow]<<"\tq["<<munext<<"] = "<<q[munext]<<endl;
1613          //cout<<"qtime["<<mulast<<"] = "<<qtime[mulast]<<"\tqtime["<<munow<<"] = "<<qtime[munow]<<"\tqtime["<<munext<<"] = "<<qtime[munext]<<endl;
1614          increase = false;
1615          decrease = false;
1616          if(nfi>0){
1617            qsine.resize(qsine.size()-1);
1618            sinesize = qsine.size();
1619            //cout<<"nfi was larger then zero"<<endl;
1620          }else{
1621            //cout<<"nfi was not larger then zero :( nfi = "<<nfi<<endl;
1622            //cout<<"qsine.size = "<<qsine.size()<<endl;
1623            if(!Period_is_defined){
1624              //cout<<"Period was defined"<<endl;
1625              if(qsine.size()>1){
1626                qsine[sinesize-1].b = qsine[sinesize-2].b;
1627                qsine[sinesize-1].c = qsine[sinesize-2].c;
1628              }else{
1629                qsine[sinesize-1].b = TMath::Pi()/1591.54;
1630                qsine[sinesize-1].c = qsine[sinesize-1].startPoint;
1631              }
1632            }
1633            if(!Max_is_defined){
1634              //cout<<"Max was already defined"<<endl;
1635              if(qsine.size()>1)qsine[sinesize-1].A = qsine[sinesize-2].A;else qsine[sinesize-1].A = limsin;
1636            }
1637            qsine[sinesize-1].NeedFit = true;
1638          }
1639          qsine[sinesize-1].finishPoint = qtime[munow];
1640          //cout<<"finish point before large gap = "<<qtime[munow]<<endl;
1641          nfi = 0;
1642          Max_is_defined = false;
1643          Start_point_is_defined = false;
1644          Period_is_defined = false;
1645          small_gap_on_ridge = false;
1646        }
1647        //cout<<"Slope "<<increase<<"\t"<<decrease<<endl;
1648        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1649        if((munext>munow) && (munow>mulast) && normal_way){
1650          if(!increase && !decrease){
1651            //cout<<"Normal way have started"<<endl;
1652            qsine.resize(qsine.size()+1);
1653            sinesize = qsine.size();
1654            qsine[sinesize-1].startPoint=qtime[mulast];
1655            if(q[munext]>q[munow] && q[munow]>q[mulast]) increase = true;
1656            if(q[munext]<q[munow] && q[munow]<q[mulast]) decrease = true;
1657          }
1658          //if(TMath::Abs(q[munow])>TMath::Abs(q[mulast]) && TMath::Abs(q[munow])>TMath::Abs(q[munext]) && TMath::Abs(q[munow])>limsin && qtime[munow]-qtime[mulast]>=400 || qtime[munext]-qtime[munow]>=400){small_gap_on_ridge = true;mu--;continue;}
1659          if(TMath::Abs(q[munow])>TMath::Abs(q[mulast]) && TMath::Abs(q[munow])>TMath::Abs(q[munext]) && TMath::Abs(q[munow])>0.9*limsin && qtime[munow]-qtime[mulast]<400 && qtime[munext]-qtime[munow]<400){
1660            //cout<<"Max point is qtime = "<<qtime[munow]<<"\tq = "<<q[munow]<<endl;
1661            if(q[munow]>q[mulast]){
1662              increase = false;
1663              decrease = true;
1664            }
1665            if(q[munow]<q[mulast]){
1666              increase = true;
1667              decrease = false;
1668            }
1669            if(Max_is_defined && !Start_point_is_defined){
1670              Double_t qPer = qtime[munow]-t1A;
1671              if(qPer>1000){
1672                //cout<<"qsine["<<sinesize-1<<"] = "<<qPer<<" = "<<qtime[munow]<<" - "<<t1A<<"\tlim = "<<limsin<<endl;
1673                qsine[sinesize-1].b=TMath::Pi()/qPer;
1674                if(decrease)qsine[sinesize-1].c=-qsine[sinesize-1].b*t1A;
1675                if(increase)qsine[sinesize-1].c=-qsine[sinesize-1].b*(t1A-qPer);
1676                Period_is_defined = true;
1677              }
1678            }
1679            Max_is_defined = true;
1680            qsine[sinesize-1].A = TMath::Abs(q[munow]);
1681            if(Start_point_is_defined && Period_is_defined){
1682              qsine[sinesize-1].finishPoint = qtime[munow];
1683              nfi++;
1684              qsine[sinesize-1].NeedFit = false;
1685              Max_is_defined = false;
1686              Start_point_is_defined = false;
1687              Period_is_defined = false;
1688              qsine.resize(qsine.size()+1);
1689              sinesize = qsine.size();
1690              qsine[sinesize-1].startPoint = qtime[munow];
1691            }
1692            if(!Start_point_is_defined) t1A=qtime[munow];
1693          }
1694          //if((q[munow]>=0 && q[mulast]<=0) || (q[munow]<=0 && q[mulast]>=0))cout<<"cross zero point diference = "<<qtime[munext] - qtime[mulast]<<"\tqlast = "<<qtime[mulast]<<"\tqnow = "<<qtime[munow]<<"\tqnext = "<<qtime[munext]<<endl;
1695          if(((q[munow]>=0 && q[mulast]<=0) || (q[munow]<=0 && q[mulast]>=0)) && qtime[munow]-qtime[mulast]<2000 && qtime[munext]-qtime[munow]<2000){
1696            Double_t tcrosszero = 0;
1697            //cout<<"cross zero point...qtime = "<<qtime[munow]<<endl;
1698            if(q[munow]==0.) tcrosszero = qtime[munow];else
1699              if(q[mulast]==0.)tcrosszero = qtime[mulast];else{
1700                Double_t k_ = (q[munow]-q[mulast])/(qtime[munow]-qtime[mulast]);
1701                Double_t b_ = q[munow]-k_*qtime[munow];
1702                tcrosszero = -b_/k_;
1703              }
1704            if(Start_point_is_defined){
1705              //cout<<"Start Point allready defined"<<endl;
1706              Double_t qPer = tcrosszero - t1;
1707              qsine[sinesize-1].b = TMath::Pi()/qPer;
1708              //cout<<"qsine["<<sinesize-1<<"].b = "<<TMath::Pi()/qPer<<endl;
1709              Period_is_defined = true;
1710              Float_t x0 = 0;
1711              if(decrease)x0 = t1;
1712              if(increase)x0 = tcrosszero;
1713              qsine[sinesize-1].c = -qsine[sinesize-1].b*x0;
1714              if(Max_is_defined){
1715                //cout<<"Max was previous defined"<<endl;
1716                qsine[sinesize-1].finishPoint = qtime[munow];
1717                nfi++;
1718                qsine[sinesize-1].NeedFit = false;
1719                Max_is_defined = false;
1720                t1 = tcrosszero;
1721                Start_point_is_defined = true;
1722                Period_is_defined = false;
1723                qsine.resize(qsine.size()+1);
1724                sinesize = qsine.size();
1725                qsine[sinesize-1].startPoint = qtime[munow];
1726              }
1727            }else{
1728              t1 = tcrosszero;
1729              Start_point_is_defined = true;
1730            }
1731          }
1732        }
1733        }
1734      }
1735    
1736      //cout<<"FINISH SINE INTERPOLATION FUNCTION..."<<endl<<endl;
1737    }

Legend:
Removed from v.1.34  
changed lines
  Added in v.1.60

  ViewVC Help
Powered by ViewVC 1.1.23