/[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.22 by mocchiut, Tue May 22 08:15:07 2007 UTC revision 1.56 by mocchiut, Thu Apr 12 12:27:02 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 <TF1.h>
14    
15  #include <TTree.h>  #include <TTree.h>
16  #include <TClassEdit.h>  #include <TClassEdit.h>
17  #include <TObject.h>  #include <TObject.h>
# Line 44  Line 47 
47  #include <OrbitalInfoCore.h>  #include <OrbitalInfoCore.h>
48  #include <InclinationInfo.h>  #include <InclinationInfo.h>
49    
50    
51  using namespace std;  using namespace std;
52    
53  //  //
54  // CORE ROUTINE  // CORE ROUTINE
55  //  //
56  //  //
57  int OrbitalInfoCore(UInt_t run, TFile *file, TSQLServer *dbc, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){  int OrbitalInfoCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){
58    //    //
59    Int_t i = 0;    Int_t i = 0;
60      TString host = glt->CGetHost();
61      TString user = glt->CGetUser();
62      TString psw = glt->CGetPsw();
63      TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
64      //
65      stringstream myquery;
66      myquery.str("");
67      myquery << "SET time_zone='+0:00'";
68      dbc->Query(myquery.str().c_str());
69    //    //
70    TString processFolder = Form("OrbitalInfoFolder_%u",run);    TString processFolder = Form("OrbitalInfoFolder_%u",run);
71    //    //
# Line 61  int OrbitalInfoCore(UInt_t run, TFile *f Line 74  int OrbitalInfoCore(UInt_t run, TFile *f
74    Bool_t debug = false;    Bool_t debug = false;
75    //    //
76    Bool_t verbose = false;    Bool_t verbose = false;
77      //
78      Bool_t standalone = false;
79      //
80    if ( OrbitalInfoargc > 0 ){    if ( OrbitalInfoargc > 0 ){
81      i = 0;      i = 0;
82      while ( i < OrbitalInfoargc ){      while ( i < OrbitalInfoargc ){
# Line 79  int OrbitalInfoCore(UInt_t run, TFile *f Line 94  int OrbitalInfoCore(UInt_t run, TFile *f
94        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {        if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {
95          verbose = true;          verbose = true;
96        };        };
97          if ( (!strcmp(OrbitalInfoargv[i],"--standalone")) ) {
98            standalone = true;
99          };
100          if ( (!strcmp(OrbitalInfoargv[i],"--calculate-pitch")) ) {
101            standalone = false;
102          };
103        i++;        i++;
104      };      };
105    };    };
# Line 107  int OrbitalInfoCore(UInt_t run, TFile *f Line 128  int OrbitalInfoCore(UInt_t run, TFile *f
128    TString fname;    TString fname;
129    UInt_t totfileentries = 0;    UInt_t totfileentries = 0;
130    UInt_t idRun = 0;    UInt_t idRun = 0;
131      UInt_t anni5 = 60 * 60 * 24 * 365 * 5 ;//1576800
132    //    //
133    // My variables. Vitaly.    // My variables. Vitaly.
134    //    //
135    //  UInt_t iev = 0;  //  UInt_t oi = 0;
   //  UInt_t j3 = 0;  
   UInt_t oi = 0;  
136    Int_t tmpSize = 0;    Int_t tmpSize = 0;
137    //    //
138    // variables needed to handle error signals    // variables needed to handle error signals
# Line 124  int OrbitalInfoCore(UInt_t run, TFile *f Line 144  int OrbitalInfoCore(UInt_t run, TFile *f
144    //    //
145    OrbitalInfo *orbitalinfo = new OrbitalInfo();    OrbitalInfo *orbitalinfo = new OrbitalInfo();
146    OrbitalInfo *orbitalinfoclone = new OrbitalInfo();    OrbitalInfo *orbitalinfoclone = new OrbitalInfo();
147    
148    //    //
149    // define variables for opening and reading level0 file    // define variables for opening and reading level0 file
150    //    //
151    TFile *l0File = 0;    TFile *l0File = 0;
152    TTree *l0tr = 0;    TTree *l0tr = 0;
153    TTree *l0trm = 0;    //  TTree *l0trm = 0;
154      TChain *ch = 0;
155    // EM: open also header branch    // EM: open also header branch
156    TBranch *l0head = 0;    TBranch *l0head = 0;
157    pamela::EventHeader *eh = 0;    pamela::EventHeader *eh = 0;
# Line 159  int OrbitalInfoCore(UInt_t run, TFile *f Line 181  int OrbitalInfoCore(UInt_t run, TFile *f
181    //    //
182    // IGRF stuff    // IGRF stuff
183    //    //
184    float dimo = 0.0; // dipole moment (computed from dat files)    Float_t dimo = 0.0; // dipole moment (computed from dat files)
185    float bnorth, beast, bdown, babs;    Float_t bnorth, beast, bdown, babs;
186    float xl; // L value    Float_t xl; // L value
187    float icode; // code value for L accuracy (see fortran code)    Float_t icode; // code value for L accuracy (see fortran code)
188    float bab1; // What's  the difference with babs?    Float_t bab1; // What's  the difference with babs?
189    float stps = 0.005; // step size for field line tracing    Float_t stps = 0.005; // step size for field line tracing
190    float bdel = 0.01; // required accuracy    Float_t bdel = 0.01; // required accuracy
191    float bequ;  // equatorial b value (also called b_0)    Float_t bequ;  // equatorial b value (also called b_0)
192    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
193    float rr0; // equatorial radius normalized to earth radius    Float_t rr0; // equatorial radius normalized to earth radius
194    
195    //    //
196    // Working filename    // Working filename
# Line 184  int OrbitalInfoCore(UInt_t run, TFile *f Line 206  int OrbitalInfoCore(UInt_t run, TFile *f
206    TTree *tempOrbitalInfo = 0;    TTree *tempOrbitalInfo = 0;
207    stringstream tempname;    stringstream tempname;
208    stringstream OrbitalInfofolder;    stringstream OrbitalInfofolder;
209      Bool_t myfold = false;
210    tempname.str("");    tempname.str("");
211    tempname << outDir;    tempname << outDir;
212    tempname << "/" << processFolder.Data();    tempname << "/" << processFolder.Data();
213    OrbitalInfofolder.str("");    OrbitalInfofolder.str("");
214    OrbitalInfofolder << tempname.str().c_str();    OrbitalInfofolder << tempname.str().c_str();
   gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());  
215    tempname << "/OrbitalInfotree_run";    tempname << "/OrbitalInfotree_run";
216    tempname << run << ".root";      tempname << run << ".root";  
217      UInt_t totnorun = 0;
218    //    //
219    // DB classes    // DB classes
220    //    //
# Line 209  int OrbitalInfoCore(UInt_t run, TFile *f Line 232  int OrbitalInfoCore(UInt_t run, TFile *f
232    cEci eCi;    cEci eCi;
233        
234    // Initialize fortran routines!!!    // Initialize fortran routines!!!
235      Int_t ltp1 = 0;
236    Int_t ltp2 = 0;    Int_t ltp2 = 0;
237    Int_t ltp3 = 0;    Int_t ltp3 = 0;
238    Int_t uno = 1;    //  Int_t uno = 1;
239    char *niente = " ";    //  const char *niente = " ";
240    GL_PARAM *glparam = new GL_PARAM();    GL_PARAM *glparam = new GL_PARAM();
241    GL_PARAM *glparam2 = new GL_PARAM();    GL_PARAM *glparam2 = new GL_PARAM();
242    Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table    GL_PARAM *glparam3 = new GL_PARAM();
243      
244    if ( parerror<0 ) {    //
245      code = parerror;    // Orientation variables. Vitaly
     goto closeandexit;  
   };  
   ltp2 = (Int_t)(glparam->PATH+glparam->NAME).Length();  
   if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());  
246    //    //
247    parerror=glparam2->Query_GL_PARAM(1,302,dbc); // parameters stored in DB in GL_PRAM table    UInt_t evfrom = 0;
248      UInt_t jumped = 0;
249      Int_t itr = -1;    
250      Double_t A1;
251      Double_t A2;
252      Double_t A3;
253      Double_t Px = 0;
254      Double_t Py = 0;      
255      Double_t Pz = 0;  
256      TTree *ttof = 0;
257      ToFLevel2 *tof = new ToFLevel2();
258      OrientationInfo *PO = new OrientationInfo();
259      Int_t nz = 6;
260      Float_t zin[6];
261      Int_t nevtofl2 = 0;
262      if ( verbose ) cout<<"Reading quaternions external file"<<endl;
263      cout.setf(ios::fixed,ios::floatfield);  
264      /******Reading recovered quaternions...*********/
265      vector<Double_t> recqtime;
266      vector<Float_t> recq0;
267      vector<Float_t> recq1;
268      vector<Float_t> recq2;
269      vector<Float_t> recq3;
270      Float_t Norm = 1;
271      Int_t parerror=glparam->Query_GL_PARAM(1,303,dbc); // parameters stored in DB in GL_PRAM table  
272      ifstream in((glparam->PATH+glparam->NAME).Data(),ios::in);
273    if ( parerror<0 ) {    if ( parerror<0 ) {
274      code = parerror;      code = parerror;
275      goto closeandexit;      goto closeandexit;
276      }
277      while(!in.eof()){
278        recqtime.resize(recqtime.size()+1);
279        Int_t sizee = recqtime.size();
280        recq0.resize(sizee);
281        recq1.resize(sizee);
282        recq2.resize(sizee);
283        recq3.resize(sizee);
284        in>>recqtime[sizee-1];
285        in>>recq0[sizee-1];
286        in>>recq1[sizee-1];
287        in>>recq2[sizee-1];
288        in>>recq3[sizee-1];
289        in>>Norm;
290      }
291      if ( verbose ) cout<<"We have read recovered data"<<endl;
292    
293    
294      // IGRF stuff moved inside run loop!  
295    
296      for (Int_t ip=0;ip<nz;ip++){
297        zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
298    };    };
   ltp3 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();  
   if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());  
299    //    //
300    initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);    if ( !standalone ){
301    //      //
302    // End IGRF stuff//      // Does it contain the Tracker tree?
303    //      //
304        ttof = (TTree*)file->Get("ToF");
305        if ( !ttof ) {
306          if ( verbose ) printf(" OrbitalInfo - ERROR: no tof tree\n");
307          code = -900;
308          goto closeandexit;
309        };
310        ttof->SetBranchAddress("ToFLevel2",&tof);  
311        nevtofl2 = ttof->GetEntries();
312      };
313    //    //
314    // Let's start!    // Let's start!
315    //    //
# Line 291  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 337  int OrbitalInfoCore(UInt_t run, TFile *f Line 410  int OrbitalInfoCore(UInt_t run, TFile *f
410        //        //
411        // copying old tree to a new file        // copying old tree to a new file
412        //        //
413          gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
414          myfold = true;
415        tempfile = new TFile(tempname.str().c_str(),"RECREATE");        tempfile = new TFile(tempname.str().c_str(),"RECREATE");
416        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
417        tempOrbitalInfo->SetName("OrbitalInfo-old");        tempOrbitalInfo->SetName("OrbitalInfo-old");
# Line 357  int OrbitalInfoCore(UInt_t run, TFile *f Line 432  int OrbitalInfoCore(UInt_t run, TFile *f
432    file->cd();    file->cd();
433    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");
434    OrbitalInfotr->SetAutoSave(900000000000000LL);    OrbitalInfotr->SetAutoSave(900000000000000LL);
435      orbitalinfo->Set();//ELENA **TEMPORANEO?**
436    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);
437    //    //
438    if ( reproc && !reprocall ){    if ( reproc && !reprocall ){
# Line 376  int OrbitalInfoCore(UInt_t run, TFile *f Line 452  int OrbitalInfoCore(UInt_t run, TFile *f
452        }        }
453        for (UInt_t j = 0; j < nobefrun; j++){        for (UInt_t j = 0; j < nobefrun; j++){
454          //          //
455          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
456          //          //
457          // copy orbitalinfoclone to mydec          // copy orbitalinfoclone to mydec
458          //          //
# Line 393  int OrbitalInfoCore(UInt_t run, TFile *f Line 469  int OrbitalInfoCore(UInt_t run, TFile *f
469      };                };          
470    };    };
471    //    //
472      //
473    // 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.
474    //    //
475    runlist = runinfo->GetRunList();    runlist = runinfo->GetRunList();
476    //    //
477    // Loop over the run to be processed    // Loop over the run to be processed
478    //    //
     
479    for (UInt_t irun=0; irun < numbofrun; irun++){    for (UInt_t irun=0; irun < numbofrun; irun++){
480      //      //
481      // retrieve the first run ID to be processed using the RunInfo list      // retrieve the first run ID to be processed using the RunInfo list
# Line 449  int OrbitalInfoCore(UInt_t run, TFile *f Line 525  int OrbitalInfoCore(UInt_t run, TFile *f
525      fname = ftmpname.str().c_str();      fname = ftmpname.str().c_str();
526      ftmpname.str("");      ftmpname.str("");
527      //      //
528      // print out informations      // print nout informations
529      //      //
530      totevent = runinfo->NEVENTS;      totevent = runinfo->NEVENTS;
531        evfrom = runinfo->EV_FROM;
532      //cout<<"totevents = "<<totevent<<"\n";      //cout<<"totevents = "<<totevent<<"\n";
533      if (verbose){      if (verbose){
534        printf("\n LEVEL0 data file: %s \n",fname.Data());        printf("\n LEVEL0 data file: %s \n",fname.Data());
# Line 459  int OrbitalInfoCore(UInt_t run, TFile *f Line 536  int OrbitalInfoCore(UInt_t run, TFile *f
536        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
537        printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM+1,runinfo->EV_FROM+totevent);        printf(" %i events to be processed for run %u: from %i to %i \n\n",totevent,idRun,runinfo->EV_FROM+1,runinfo->EV_FROM+totevent);
538      }//      }//
539        //
540        //    if ( !totevent ) goto closeandexit;
541      // Open Level0 file      // Open Level0 file
542      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
543      if ( !l0File ) {      if ( !l0File ) {
# Line 485  int OrbitalInfoCore(UInt_t run, TFile *f Line 564  int OrbitalInfoCore(UInt_t run, TFile *f
564      // end EM      // end EM
565      nevents = l0head->GetEntries();      nevents = l0head->GetEntries();
566      //      //
567      if ( nevents < 1 ) {      if ( nevents < 1 && totevent ) {
568        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
569        l0File->Close();        l0File->Close();
570        code = -11;        code = -11;
571        goto closeandexit;        goto closeandexit;
572      };      };
573      //      //
574      if ( runinfo->EV_TO > nevents-1 ) {      if ( runinfo->EV_TO > nevents-1 && totevent ) {
575        if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");        if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");
576        l0File->Close();        l0File->Close();
577        code = -12;        code = -12;
578        goto closeandexit;        goto closeandexit;
579      };      };
580    
581        //
582        // open IGRF files and do it only once if we are processing a full level2 file
583        //
584        if ( irun == 0 ){
585          if ( l0head->GetEntry(runinfo->EV_FROM) <= 0 ) throw -36;
586          //
587          // absolute time of first event of the run (it should not matter a lot)
588          //
589          ph = eh->GetPscuHeader();
590          atime = dbtime->DBabsTime(ph->GetOrbitalTime());
591          
592          parerror=glparam->Query_GL_PARAM(atime-anni5,301,dbc); // parameters stored in DB in GL_PRAM table  
593          if ( parerror<0 ) {
594            code = parerror;
595            goto closeandexit;
596        };
597          ltp1 = (Int_t)(glparam->PATH+glparam->NAME).Length();
598          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
599          //
600          parerror=glparam2->Query_GL_PARAM(atime,301,dbc); // parameters stored in DB in GL_PRAM table  
601          if ( parerror<0 ) {
602            code = parerror;
603            goto closeandexit;
604          };
605          ltp2 = (Int_t)(glparam2->PATH+glparam->NAME).Length();
606          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
607          //
608          parerror=glparam3->Query_GL_PARAM(atime,302,dbc); // parameters stored in DB in GL_PRAM table
609          if ( parerror<0 ) {
610            code = parerror;
611            goto closeandexit;
612          };
613          ltp3 = (Int_t)(glparam3->PATH+glparam2->NAME).Length();
614          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam3->PATH+glparam3->NAME).Data());
615          //
616          initize_((char *)(glparam->PATH+glparam->NAME).Data(),&ltp1,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp2,(char *)(glparam3->PATH+glparam3->NAME).Data(),&ltp3);
617          //
618        }
619        //
620        // End IGRF stuff//
621        //
622    
623        //
624        //     TTree *tp = (TTree*)l0File->Get("RunHeader");
625        //     tp->SetBranchAddress("Header", &eH);
626        //     tp->SetBranchAddress("RunHeader", &reh);
627        //     tp->GetEntry(0);
628        //     ph = eH->GetPscuHeader();
629        //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
630        //     ULong_t ObtSync = reh->OBT_TIME_SYNC;    
631        //     if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
632      //      //
 //     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);  
 //  
633      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
634      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
635      ULong_t DeltaOBT = TimeSync - ObtSync;      ULong_t DeltaOBT = TimeSync - ObtSync;
636    
637      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);
638            //
639      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
640      neventsm = l0trm->GetEntries();      //
641        ch = new TChain("Mcmd","Mcmd");
642        //
643        // look in the DB to find the closest files to this run
644        //
645        TSQLResult *pResult = 0;
646        TSQLRow *Row = 0;
647        stringstream myquery;
648        UInt_t l0fid[10];
649        Int_t i = 0;
650        memset(l0fid,0,10*sizeof(Int_t));
651        //
652        myquery.str("");
653        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;";
654        //
655        pResult = dbc->Query(myquery.str().c_str());
656        //
657        i = 9;
658        if( pResult ){
659          //
660          Row = pResult->Next();
661          //
662          while ( Row ){
663            //
664            // store infos and exit
665            //
666            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
667            i--;
668            Row = pResult->Next();  
669            //
670          };
671          pResult->Delete();
672        };
673        //
674        myquery.str("");
675        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;";
676        //
677        pResult = dbc->Query(myquery.str().c_str());
678        //
679        i = 0;
680        if( pResult ){
681          //
682          Row = pResult->Next();
683          //
684          while ( Row ){
685            //
686            // store infos and exit
687            //
688            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
689            i++;
690            Row = pResult->Next();  
691            //
692          };
693          pResult->Delete();
694        };
695        //
696        i = 0;
697        UInt_t previd = 0;
698        while ( i < 10 ){
699          if ( l0fid[i] && previd != l0fid[i] ){
700            previd = l0fid[i];
701            myquery.str("");
702            myquery << "select PATH,NAME from GL_ROOT where ID=" << l0fid[i] << " ;";
703            //
704            pResult = dbc->Query(myquery.str().c_str());
705            //
706            if( pResult ){
707              //
708              Row = pResult->Next();
709              //
710              if ( debug ) printf(" Using inclination informations from file: %s \n",(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1)).Data());
711              ch->Add(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1));
712              //
713              pResult->Delete();
714            };
715          };
716          i++;
717        };
718        //
719        //    l0trm = (TTree*)l0File->Get("Mcmd");
720        //    ch->ls();
721        ch->SetBranchAddress("Mcmd",&mcmdev);
722        //    printf(" entries %llu \n", ch->GetEntries());
723        //    l0trm = ch->GetTree();
724        //    neventsm = l0trm->GetEntries();
725        neventsm = ch->GetEntries();
726        if ( debug ) printf(" entries %u \n", neventsm);
727      //    neventsm = 0;      //    neventsm = 0;
728      //      //
729      if (neventsm == 0){      if (neventsm == 0){
# Line 526  int OrbitalInfoCore(UInt_t run, TFile *f Line 734  int OrbitalInfoCore(UInt_t run, TFile *f
734      }      }
735      //      //
736            
737      l0trm->SetBranchAddress("Mcmd", &mcmdev);      //    l0trm->SetBranchAddress("Mcmd", &mcmdev);
738      //    l0trm->SetBranchAddress("Header", &eh);      //    l0trm->SetBranchAddress("Header", &eh);
739      //      //
740      //      //
741      //      //
742      UInt_t mctren = 0;      
743      UInt_t mcreen = 0;    //    UInt_t mctren = 0;    
744    //    UInt_t mcreen = 0;        
745      UInt_t numrec = 0;      UInt_t numrec = 0;
746      //      //
747      Double_t upperqtime = 0;      Double_t upperqtime = 0;
748      Double_t lowerqtime = 0;      Double_t lowerqtime = 0;
749            
750      Double_t incli = 0;  //    Double_t incli = 0;
751      oi = 0;  //    oi = 0;
752      UInt_t ooi = 0;  //    UInt_t ooi = 0;
753      //      //
754      // init quaternions sync      // init quaternions information from mcmd-packets
755      //      //
756      Bool_t isf = true;      Bool_t isf = true;
757      Int_t fgh = 0;  //    Int_t fgh = 0;
758    
759        vector<Float_t> q0;
760        vector<Float_t> q1;
761        vector<Float_t> q2;
762        vector<Float_t> q3;
763        vector<Double_t> qtime;
764        vector<Float_t> qPitch;
765        vector<Float_t> qRoll;
766        vector<Float_t> qYaw;
767        vector<Int_t> qmode;
768    
769        Int_t nt = 0;
770        
771        //init sine-function interpolation
772        
773        //cout<<"Sine coeficient initialisation..."<<endl;
774        vector<Sine> q0sine;
775        vector<Sine> q1sine;
776        vector<Sine> q2sine;
777        vector<Sine> q3sine;
778        vector<Sine> Yawsine;
779    
780        /*TH2F* q0testing = new TH2F();
781          TH2F* q1testing = new TH2F();
782          TH2F* q2testing = new TH2F();
783          TH2F* q3testing = new TH2F();
784          TH2F* Pitchtesting = new TH2F();
785        */
786        UInt_t must = 0;
787    
788      //      //
789      // run over all the events of the run      // run over all the events of the run
790      //      //
791      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");
792      //      //
793        //
794      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
       
795        //        //
796        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
797        if ( debug ) printf(" %i \n",procev);              if ( debug ) printf(" %i \n",procev);      
798        //        //
799        l0head->GetEntry(re);        if ( l0head->GetEntry(re) <= 0 ) throw -36;
800        //        //
801        // absolute time of this event        // absolute time of this event
802        //        //
803        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
804        atime = dbtime->DBabsTime(ph->GetOrbitalTime());        atime = dbtime->DBabsTime(ph->GetOrbitalTime());
805          if ( debug ) printf(" %i absolute time \n",procev);      
806        //        //
807        // paranoid check        // paranoid check
808        //        //
809        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {        if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1))  ) {
810          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");
811  //      debug = true;          jumped++;
812            //      debug = true;
813          continue;          continue;
814        }        }
815    
816          //
817          // retrieve tof informations
818          //
819          if ( !reprocall ){
820            itr = nobefrun + (re - evfrom - jumped);
821            //itr = re-(46438+200241);
822          } else {
823            itr = runinfo->GetFirstEntry() + (re - evfrom - jumped);
824          };
825          //
826          if ( !standalone ){
827            if ( itr > nevtofl2 ){  
828              if ( verbose ) printf(" OrbitalInfo - ERROR: no tof events with entry = %i in Level2 file\n",itr);
829              if ( debug ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
830              l0File->Close();
831              code = -901;
832              goto closeandexit;
833            };
834            //
835            tof->Clear();
836            //
837            if ( ttof->GetEntry(itr) <= 0 ) throw -36;
838            //
839          };
840        //        //
841        procev++;        procev++;
842        //        //
843        // start processing        // start processing
844        //        //
845          if ( debug ) printf(" %i start processing \n",procev);      
846        orbitalinfo->Clear();        orbitalinfo->Clear();
847        //        //
848          OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
849          if( !(orbitalinfo->OrbitalInfoTrk) ) orbitalinfo->OrbitalInfoTrk = new TClonesArray("OrbitalInfoTrkVar",2);
850          TClonesArray &tor = *orbitalinfo->OrbitalInfoTrk;
851          //
852        // Fill OBT, pkt_num and absTime        // Fill OBT, pkt_num and absTime
853        //              //      
       //      ph = eh->GetPscuHeader();  
854        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
855        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
856        orbitalinfo->absTime = atime;        orbitalinfo->absTime = atime;
857          if ( debug ) printf(" %i pktnum obt abstime \n",procev);      
858        //        //
859        // 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.
860        //        //
861          if ( debug ) printf(" %i sgp4 \n",procev);      
862        cCoordGeo coo;        cCoordGeo coo;
863        float jyear=0;            Float_t jyear=0.;    
864        //        //
865        if(atime >= gltle->GetToTime()) {        if(atime >= gltle->GetToTime()) {
866          if ( !gltle->Query(atime, dbc) ){          if ( !gltle->Query(atime, dbc) ){
867            //                  //      
868            // Compute the magnetic dipole moment.            // Compute the magnetic dipole moment.
869            //            //
870              if ( debug ) printf(" %i compute magnetic dipole moment \n",procev);      
871            UInt_t year, month, day, hour, min, sec;            UInt_t year, month, day, hour, min, sec;
872            //            //
873            TTimeStamp t = TTimeStamp(atime, kTRUE);            TTimeStamp t = TTimeStamp(atime, kTRUE);
# Line 602  int OrbitalInfoCore(UInt_t run, TFile *f Line 875  int OrbitalInfoCore(UInt_t run, TFile *f
875            t.GetTime(kTRUE, 0, &hour, &min, &sec);            t.GetTime(kTRUE, 0, &hour, &min, &sec);
876            jyear = (float) year            jyear = (float) year
877              + (month*31.+ (float) day)/365.              + (month*31.+ (float) day)/365.
878              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);              + (hour*3600.+min*60.+(float)sec)/(24.*3600.*365.);
879            //            //
880              if ( debug ) printf(" %i compute magnetic dipole moment get dipole moment for year\n",procev);      
881            feldcof_(&jyear, &dimo); // get dipole moment for year            feldcof_(&jyear, &dimo); // get dipole moment for year
882              if ( debug ) printf(" %i compute magnetic dipole moment end\n",procev);      
883          } else {          } else {
884            code = -56;            code = -56;
885            goto closeandexit;            goto closeandexit;
# Line 619  int OrbitalInfoCore(UInt_t run, TFile *f Line 894  int OrbitalInfoCore(UInt_t run, TFile *f
894        // synchronize with quaternions data        // synchronize with quaternions data
895        //        //
896        if ( isf && neventsm>0 ){        if ( isf && neventsm>0 ){
         if ( debug ) printf(" I am here \n");  
897          //          //
898          // First event          // First event
899          //          //
900          isf = false;          isf = false;
901          upperqtime = atime;          upperqtime = atime;
902          lowerqtime = runinfo->RUNHEADER_TIME;          lowerqtime = runinfo->RUNHEADER_TIME;
903          for ( ik = 0; ik < neventsm; ik++){          for ( ik = 0; ik < neventsm; ik++){  //number of macrocommad packets
904            l0trm->GetEntry(ik);            if ( ch->GetEntry(ik) <= 0 ) throw -36;
905            tmpSize = mcmdev->Records->GetEntries();            tmpSize = mcmdev->Records->GetEntries();
906            numrec = tmpSize;            numrec = tmpSize;
907            for (Int_t j3 = 0;j3<tmpSize;j3++){            for (Int_t j3 = 0;j3<tmpSize;j3++){  //number of subpackets
908                if ( debug ) printf(" ik %i j3 %i eh eh eh \n",ik,j3);
909              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
910              if ((int)mcmdrc->ID1 == 226){              if ( mcmdrc ){ // missing inclination bug [8RED 090116]
911                L_QQ_Q_l_upper->fill(mcmdrc->McmdData);                if ( debug ) printf(" pluto \n");
912                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
913                  if (ui>0){                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
914                    if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){                  for (UInt_t ui = 0; ui < 6; ui++){
915                      if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){                    if (ui>0){
916                        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]){
917                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          if ( debug ) printf(" here1 %i \n",ui);
918                        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));
919                      }else {                        Int_t recSize = recqtime.size();
920                        lowerqtime = upperqtime;                        if(lowerqtime > recqtime[recSize-1]){
921                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));                            Int_t sizeqmcmd = qtime.size();
922                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
923                        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;
924                        mcreen = j3;                            q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
925                        mctren = ik;                            q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
926                        if(fgh==0){                            q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
927                          CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                            q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
928                          CopyAng(RYPang_lower,RYPang_upper);                            qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
929                              lowerqtime = u_time;
930                              orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
931                              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]);
932                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
933                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
934                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
935                          }
936                          for(Int_t mu = nt;mu<recSize;mu++){
937                            if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
938                              nt=mu;
939                              Int_t sizeqmcmd = qtime.size();
940                              inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
941                              qtime[sizeqmcmd]=recqtime[mu];
942                              q0[sizeqmcmd]=recq0[mu];
943                              q1[sizeqmcmd]=recq1[mu];
944                              q2[sizeqmcmd]=recq2[mu];
945                              q3[sizeqmcmd]=recq3[mu];
946                              qmode[sizeqmcmd]=-10;
947                              orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
948                              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]);
949                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
950                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
951                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
952                            }
953                            if(recqtime[mu]>=u_time){
954                              Int_t sizeqmcmd = qtime.size();
955                              inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
956                              qtime[sizeqmcmd]=u_time;
957                              q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
958                              q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
959                              q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
960                              q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
961                              qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
962                              lowerqtime = u_time;
963                              orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
964                              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]);
965                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
966                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
967                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
968                              break;
969                            }
970                        }                        }
                       oi=ui;  
                       goto closethisloop;  
971                      }                      }
972                      fgh++;                    }else{
973                      CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          if ( debug ) printf(" here2 %i \n",ui);
974                      CopyAng(RYPang_lower,RYPang_upper);                      Double_t u_time = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
975                    }                      if(lowerqtime>u_time)nt=0;
976                  }else{                      Int_t recSize = recqtime.size();
977                    if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){                      if(lowerqtime > recqtime[recSize-1]){
978                      upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                          Int_t sizeqmcmd = qtime.size();
979                      orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
980                      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;
981                    }                          q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
982                    else {                          q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
983                      lowerqtime = upperqtime;                          q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
984                      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];
985                      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);
986                      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;
987                      mcreen = j3;                          orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
988                      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]);
989                      if(fgh==0){                          qRoll[sizeqmcmd]=RYPang_upper->Kren;
990                        CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
991                        CopyAng(RYPang_lower,RYPang_upper);                          qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
992                        lowerqtime = atime-1;                      }
993                        for(Int_t mu = nt;mu<recSize;mu++){
994                          if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
995                            nt=mu;
996                            Int_t sizeqmcmd = qtime.size();
997                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
998                            qtime[sizeqmcmd]=recqtime[mu];
999                            q0[sizeqmcmd]=recq0[mu];
1000                            q1[sizeqmcmd]=recq1[mu];
1001                            q2[sizeqmcmd]=recq2[mu];
1002                            q3[sizeqmcmd]=recq3[mu];
1003                            qmode[sizeqmcmd]=-10;
1004                            orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1005                            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]);
1006                            qRoll[sizeqmcmd]=RYPang_upper->Kren;
1007                            qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1008                            qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1009                          }
1010                          if(recqtime[mu]>=u_time){
1011                            Int_t sizeqmcmd = qtime.size();
1012                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1013                            qtime[sizeqmcmd]=u_time;
1014                            q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
1015                            q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
1016                            q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
1017                            q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
1018                            qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1019                            lowerqtime = u_time;
1020                            orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1021                            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]);
1022                            qRoll[sizeqmcmd]=RYPang_upper->Kren;
1023                            qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1024                            qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1025                            CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
1026                            break;
1027                          }
1028                      }                      }
                     oi=ui;  
                     goto closethisloop;  
                     //_0 = true;  
1029                    }                    }
1030                    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){  
             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]);  
1031                }                }
               //              re--;  
               gh=true;  
1032              }              }
1033            }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));  
1034            }            }
1035            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));  
1036                    
1037                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){
1038                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++){
1039                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();
1040                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);
1041                //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];
1042                //cin>>grib;                  q0[sizeqmcmd]=recq0[my];
1043                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];
1044                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];
1045                    q3[sizeqmcmd]=recq3[my];
1046                    qmode[sizeqmcmd]=-10;
1047                    orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1048                    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]);
1049                    qRoll[sizeqmcmd]=RYPang_upper->Kren;
1050                    qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1051                    qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1052              }              }
1053            }          }
         } 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));  
1054                    
1055              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");
1056              orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1057              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)));          //sineparam(q0sine,qtime,q0,qRoll,qPitch,0.60);
1058              orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));          //sineparam(q1sine,qtime,q1,qRoll,qPitch,0.82);
1059              //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";          //sineparam(q2sine,qtime,q2,qRoll,qPitch,0.82);
1060              //cin>>grib;          //sineparam(q3sine,qtime,q3,qRoll,qPitch,0.60);
1061              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)));          //sineparam(Yawsine,qtime,qYaw,qRoll,qPitch,4);
1062              orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1063            }          if ( debug ) printf(" puffi \n");
1064            if (tut==6){          Double_t tmin = 9999999999.;
1065              if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){          Double_t tmax = 0.;
1066                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)));          for(UInt_t tre = 0;tre<qtime.size();tre++){
1067                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));            if(qtime[tre]>tmax)tmax = qtime[tre];
1068                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)));            if(qtime[tre]<tmin)tmin = qtime[tre];
1069                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));          }
1070                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)));          if ( debug ) printf(" gnfuffi \n");
1071                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));  
1072                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)));          //q0testing->SetName("q0testing");
1073                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));          //q1testing->SetName("q1testing");
1074            //q2testing->SetName("q2testing");
1075            //q3testing->SetName("q3testing");
1076                    
1077                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)));  //      Int_t ss=10.*(tmax-tmin);
1078                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));          //q0testing->SetBins(ss,tmin,tmax,1000,-1.,1.);
1079                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)));          //Pitchtesting->SetBins(ss,tmin,tmax,1000,-40.,40.);
1080                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1081                //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";  //      for(Int_t tre = 0;tre<qtime.size();tre++){
1082                //cin>>grib;            //cout<<"q0["<<tre<<" = "<<q0[tre]<<endl;
1083                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)));            //q0testing->Fill(qtime[tre],q0[tre]);
1084                orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));            //q1testing->Fill(qtime[tre],q1[tre]);
1085              }            //Pitchtesting->Fill(qtime[tre],qPitch[tre],100);
1086            }                        //if(qmode[tre] == -10)Pitchtesting->Fill(qtime[tre],10,100);
1087              //q2testing->Fill(qtime[tre],q2[tre],100);
1088              //q3testing->Fill(qtime[tre],q3[tre],100);
1089    //      }
1090            
1091            //for(Int_t tre=0;tre<q0sine.size();tre++)cout<<q1sine[tre].A<<"*sin("<<q1sine[tre].b<<"x+"<<q1sine[tre].c<<")\t time start: "<<q1sine[tre].startPoint<<"\ttime end: "<<q1sine[tre].finishPoint<<endl;
1092            //for(Int_t tre=0;tre<q0sine.size();tre++)cout<<q1sine[tre].A<<"*sin("<<q1sine[tre].b<<"x+"<<q1sine[tre].c<<")\t time start: "<<q0sine[tre].startPoint<<"\ttime end: "<<q0sine[tre].finishPoint<<endl;
1093          } // if we processed first event
1094          
1095          //Filling Inclination information
1096          Double_t incli = 0;
1097          if ( qtime.size() > 1 ){
1098          for(UInt_t mu = must;mu<qtime.size()-1;mu++){
1099            if ( debug ) printf(" ??grfuffi %i sixe %i must %i \n",mu,qtime.size()-1,must);
1100            if(qtime[mu+1]>qtime[mu]){
1101              if ( debug ) printf(" grfuffi2 %i \n",mu);
1102              if(atime<=qtime[mu+1] && atime>=qtime[mu]){
1103                must = mu;
1104                incli = (qPitch[mu+1]-qPitch[mu])/(qtime[mu+1]-qtime[mu]);
1105                orbitalinfo->theta =  incli*atime+qPitch[mu+1]-incli*qtime[mu+1];
1106                incli = (qRoll[mu+1]-qRoll[mu])/(qtime[mu+1]-qtime[mu]);
1107                orbitalinfo->etha =  incli*atime+qRoll[mu+1]-incli*qtime[mu+1];
1108                incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1109                orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1110                
1111                incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1112                orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1113                incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1114                orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1115                incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1116                orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1117                incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1118                orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1119                
1120                orbitalinfo->TimeGap = qtime[mu+1]-qtime[mu];
1121                orbitalinfo->mode = qmode[mu+1];
1122                //if(qmode[mu+1]==-10) orbitalinfo->R10r = true;else orbitalinfo->R10r = false;
1123                //reserved for next versions Vitaly.
1124                /*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){
1125                  //linear interpolation
1126                  incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1127                  orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1128                  incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1129                  orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1130                  incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1131                  orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1132                  incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1133                  orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1134                }else{
1135                  //sine interpolation
1136                  for(UInt_t mt=0;mt<q0sine.size();mt++){
1137                    if(atime<=q0sine[mt].finishPoint && atime>=q0sine[mt].startPoint){
1138                      if(!q0sine[mt].NeedFit)orbitalinfo->q0=q0sine[mt].A*sin(q0sine[mt].b*atime+q0sine[mt].c);else{
1139                        incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1140                        orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1141                      }
1142                    }
1143                    if(atime<=q1sine[mt].finishPoint && atime>=q1sine[mt].startPoint){
1144                      if(!q1sine[mt].NeedFit)orbitalinfo->q1=q1sine[mt].A*sin(q1sine[mt].b*atime+q1sine[mt].c);else{
1145                        incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1146                        orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1147                      }
1148                    }
1149                    if(atime<=q2sine[mt].finishPoint && atime>=q2sine[mt].startPoint){
1150                      if(!q2sine[mt].NeedFit)orbitalinfo->q2=q0sine[mt].A*sin(q2sine[mt].b*atime+q2sine[mt].c);else{
1151                        incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1152                        orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1153                      }
1154                    }
1155                    if(atime<=q3sine[mt].finishPoint && atime>=q3sine[mt].startPoint){
1156                      if(!q3sine[mt].NeedFit)orbitalinfo->q3=q0sine[mt].A*sin(q3sine[mt].b*atime+q3sine[mt].c);else{
1157                        incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1158                        orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1159                      }
1160                    }
1161                    if(atime<=Yawsine[mt].finishPoint && atime>=Yawsine[mt].startPoint){
1162                      if(!Yawsine[mt].NeedFit)orbitalinfo->phi=Yawsine[mt].A*sin(Yawsine[mt].b*atime+Yawsine[mt].c);else{
1163                        incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1164                        orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1165                      }
1166                    }
1167                  }
1168                }*/
1169                //q0testing->Fill(atime,orbitalinfo->q0,100);
1170                //q1testing->Fill(atime,orbitalinfo->q1,100);
1171                //Pitchtesting->Fill(atime,orbitalinfo->etha);
1172                //q2testing->Fill(atime,orbitalinfo->q2);
1173                //q3testing->Fill(atime,orbitalinfo->q3);
1174                break;
1175              }
1176          }          }
1177          //        }
1178          orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);        }
1179          //        //
1180        } else {        // ops no inclination information
1181          if ( debug ) printf(" ops no incl! \n");        //
1182          orbitalinfo->mode = -1;  
1183          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 ){
1184            orbitalinfo->mode = 10;
1185            orbitalinfo->q0 = -1000.;
1186            orbitalinfo->q1 = -1000.;
1187            orbitalinfo->q2 = -1000.;
1188            orbitalinfo->q3 = -1000.;
1189            orbitalinfo->etha = -1000.;
1190            orbitalinfo->phi = -1000.;
1191            orbitalinfo->theta = -1000.;
1192        };        };
1193            //
1194          // #########################################################################################################################  
1195        //        //
1196        // fill orbital positions        // fill orbital positions
1197        //                //        
# Line 879  int OrbitalInfoCore(UInt_t run, TFile *f Line 1221  int OrbitalInfoCore(UInt_t run, TFile *f
1221          orbitalinfo->BB0 = babs/bequ;          orbitalinfo->BB0 = babs/bequ;
1222          orbitalinfo->L = xl;                orbitalinfo->L = xl;      
1223          // Set Stormer vertical cutoff using L shell.          // Set Stormer vertical cutoff using L shell.
1224          orbitalinfo->cutoff[0] = 14.9/(xl*xl);          orbitalinfo->cutoffsvl = 14.9/(xl*xl);
1225            orbitalinfo->igrf_icode = icode;
1226          //          //
1227        };              };      
1228        //        //
1229          if ( debug ) printf(" pitch angle \n");
1230          //
1231          // pitch angles
1232          //
1233          //if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){
1234          if( orbitalinfo->TimeGap>0 && orbitalinfo->TimeGap<2000000){
1235            //
1236            Float_t Bx = -orbitalinfo->Bdown;
1237            Float_t By = orbitalinfo->Beast;
1238            Float_t Bz = orbitalinfo->Bnorth;
1239            //
1240            TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);
1241            TMatrixD Gij = PO->ColPermutation(Fij);
1242            TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);
1243            TMatrixD Iij = PO->ColPermutation(Dij);
1244            //
1245            orbitalinfo->Iij.ResizeTo(Iij);
1246            orbitalinfo->Iij = Iij;
1247            //
1248            A1 = Iij(0,2);
1249            A2 = Iij(1,2);
1250            A3 = Iij(2,2);
1251            //
1252            //      orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3);                        // Angle between zenit and Pamela's main axiz
1253            //      orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz);                 // Angle between Pamela's main axiz and B
1254            //
1255            if ( !standalone && tof->ntrk() > 0 ){
1256              //
1257              Int_t nn = 0;
1258              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1259                //
1260                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1261                Double_t E11x = ptt->xtr_tof[0]; // tr->x[0];
1262                Double_t E11y = ptt->ytr_tof[0]; //tr->y[0];
1263                Double_t E11z = zin[0];
1264                Double_t E22x = ptt->xtr_tof[3];//tr->x[3];
1265                Double_t E22y = ptt->ytr_tof[3];//tr->y[3];
1266                Double_t E22z = zin[3];
1267                if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1  ){
1268                  Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1269                  //              Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1270                  //              if(E22x-E11x>=0 && E22y-E11y <0) MyAzim =  360. - MyAzim;
1271                  //              if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1272                  //              if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1273                  //              if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1274                  Px = (E22x-E11x)/norm;
1275                  Py = (E22y-E11y)/norm;
1276                  Pz = (E22z-E11z)/norm;
1277                  //
1278                  t_orb->trkseqno = ptt->trkseqno;
1279                  //
1280                  TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);
1281                  t_orb->Eij.ResizeTo(Eij);
1282                  t_orb->Eij = Eij;
1283                  //
1284                  TMatrixD Sij = PO->PamelatoGEO(Gij,Px,Py,Pz);
1285                  t_orb->Sij.ResizeTo(Sij);
1286                  t_orb->Sij = Sij;
1287                  //            
1288                  t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);
1289                  //
1290                  //
1291                  Double_t omega = PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),cos(orbitalinfo->lon+TMath::Pi()/2)-sin(orbitalinfo->lon+TMath::Pi()/2),cos(orbitalinfo->lon+TMath::Pi()/2)+sin(orbitalinfo->lon+TMath::Pi()/2),1);
1292                  //
1293                  t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1294                  //
1295                  if ( t_orb->pitch != t_orb->pitch ) t_orb->pitch = -1000.;
1296                  if ( t_orb->cutoff != t_orb->cutoff ) t_orb->cutoff = -1000.;
1297                  //
1298                  if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1299                  //
1300                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1301                  nn++;
1302                  //
1303                  t_orb->Clear();
1304                  //
1305                };
1306                //
1307              };
1308            } else {
1309              if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());
1310            };
1311            //
1312          } else {
1313            if ( !standalone && tof->ntrk() > 0 ){
1314              //
1315              Int_t nn = 0;
1316              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1317                //
1318                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1319                if ( ptt->trkseqno != -1  ){
1320                  //
1321                  t_orb->trkseqno = ptt->trkseqno;
1322                  //
1323                  t_orb->Eij = 0;  
1324                  //
1325                  t_orb->Sij = 0;
1326                  //            
1327                  t_orb->pitch = -1000.;
1328                  //
1329                  t_orb->cutoff = -1000.;
1330                  //
1331                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1332                  nn++;
1333                  //
1334                  t_orb->Clear();
1335                  //
1336                };
1337                //
1338              };    
1339            };
1340          };
1341          //
1342        // Fill the class        // Fill the class
1343        //        //
1344        OrbitalInfotr->Fill();        OrbitalInfotr->Fill();
1345        //        //
1346          delete t_orb;
1347          //
1348      }; // loop over the events in the run      }; // loop over the events in the run
1349      //      //
1350      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
1351      //      //
1352    
1353        //gStyle->SetOptStat(000000);
1354        //gStyle->SetPalette(1);
1355        
1356        /*TCanvas* c1 = new TCanvas("c1","",1200,800);
1357        //c1->Divide(1,4);
1358        c1->cd(1);
1359        //q0testing->Draw("colz");
1360        //c1->cd(2);
1361        //q1testing->Draw("colz");
1362        //c1->cd(3);
1363        Pitchtesting->Draw("colz");
1364        //c1->cd(4);
1365        //q3testing->Draw("colz");
1366        c1->SaveAs("9.Rollhyst.png");
1367        delete c1;*/
1368    
1369      delete dbtime;      delete dbtime;
1370      if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;      if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1371      if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;      if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
# Line 915  int OrbitalInfoCore(UInt_t run, TFile *f Line 1390  int OrbitalInfoCore(UInt_t run, TFile *f
1390          //          //
1391          // Get entry from old tree          // Get entry from old tree
1392          //          //
1393          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
1394          //          //
1395          // copy orbitalinfoclone to OrbitalInfo          // copy orbitalinfoclone to OrbitalInfo
1396          //          //
# Line 935  int OrbitalInfoCore(UInt_t run, TFile *f Line 1410  int OrbitalInfoCore(UInt_t run, TFile *f
1410    //    //
1411    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
1412    if ( tempfile ) tempfile->Close();                if ( tempfile ) tempfile->Close();            
1413    gSystem->Unlink(tempname.str().c_str());    if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1414    //    //
1415    if ( runinfo ) runinfo->Close();        if ( runinfo ) runinfo->Close();    
1416    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
1417      if ( tof ) tof->Delete();
1418      if ( ttof ) ttof->Delete();
1419      //
1420    if ( file ){    if ( file ){
1421      file->cd();      file->cd();
1422      file->Write();      file->Write();
1423    };    };
1424    //    //
1425    gSystem->Unlink(OrbitalInfofolder.str().c_str());    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1426    //    //
1427    // the end    // the end
1428    //    //
1429      if ( dbc ){
1430        dbc->Close();
1431        delete dbc;
1432      };
1433    if (verbose) printf("\n Exiting...\n");    if (verbose) printf("\n Exiting...\n");
1434    if(OrbitalInfotr)OrbitalInfotr->Delete();    if(OrbitalInfotr)OrbitalInfotr->Delete();
1435    //    //
1436      if ( PO ) delete PO;
1437    if ( orbitalinfo ) delete orbitalinfo;    if ( orbitalinfo ) delete orbitalinfo;
1438    if ( orbitalinfoclone ) delete orbitalinfoclone;    if ( orbitalinfoclone ) delete orbitalinfoclone;
1439    if ( glroot ) delete glroot;    if ( glroot ) delete glroot;
# Line 999  void CopyAng(InclinationInfo *A1, Inclin Line 1482  void CopyAng(InclinationInfo *A1, Inclin
1482  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){
1483        
1484    UInt_t hole = 10;    UInt_t hole = 10;
1485    bool R10l = false;     // Sign of R10 mode in lower quaternions array    Bool_t R10l = false;     // Sign of R10 mode in lower quaternions array
1486    bool R10u = false;     // Sign of R10 mode in upper quaternions array    Bool_t R10u = false;     // Sign of R10 mode in upper quaternions array
1487    bool insm = false;     // Sign that we inside quaternions array    Bool_t insm = false;     // Sign that we inside quaternions array
1488    bool mxtml = false;    // Sign of mixt mode in lower quaternions array    Bool_t mxtml = false;    // Sign of mixt mode in lower quaternions array
1489    bool mxtmu = false;    // Sign of mixt mode in upper quaternions array    Bool_t mxtmu = false;    // Sign of mixt mode in upper quaternions array
1490    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
1491    UInt_t NCQl = 6;       // Number of correct quaternions in lower array    UInt_t NCQl = 6;       // Number of correct quaternions in lower array
1492    UInt_t NCQu = 6;       // Number of correct quaternions in upper array    UInt_t NCQu = 6;       // Number of correct quaternions in upper array
1493    if (f>0){    if (f>0){
# Line 1047  UInt_t holeq(Double_t lower,Double_t upp Line 1530  UInt_t holeq(Double_t lower,Double_t upp
1530    return hole;    return hole;
1531  }  }
1532    
1533    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){
1534      Int_t sizee = t.size()+1;
1535      t.resize(sizee);
1536      q0.resize(sizee);
1537      q1.resize(sizee);
1538      q2.resize(sizee);
1539      q3.resize(sizee);
1540      mode.resize(sizee);
1541      Roll.resize(sizee);
1542      Pitch.resize(sizee);
1543      Yaw.resize(sizee);
1544    }
1545    
1546    //Find fitting sine functions for q0,q1,q2,q3 and Yaw-angle;
1547    void sineparam(vector<Sine>& qsine, vector<Double_t>& qtime, vector<Float_t>& q, vector<Float_t>& Roll, vector<Float_t>& Pitch, Float_t limsin){
1548      UInt_t mulast = 0;
1549      UInt_t munow = 0;
1550      UInt_t munext = 0;
1551      Bool_t increase = false;
1552      Bool_t decrease = false;
1553      Bool_t Max_is_defined = false;
1554      Bool_t Start_point_is_defined = false;
1555      Bool_t Period_is_defined = false;
1556      Bool_t Large_gap = false;
1557      Bool_t normal_way = true;
1558      Bool_t small_gap_on_ridge = false;
1559      Double_t t1 = 0;
1560      Double_t t1A = 0;
1561      Int_t sinesize = 0;
1562      Int_t nfi = 0;
1563      for(UInt_t mu = 0;mu<qtime.size();mu++){
1564        //cout<<"Roll["<<mu<<"] = "<<Roll[mu]<<endl;
1565        if(TMath::Abs(Roll[mu])<1. && TMath::Abs(Pitch[mu])<1. && TMath::Abs(q[mu])<limsin){
1566        //cout<<"q["<<mu<<endl<<"] = "<<q[mu]<<endl;
1567        if(mulast!=0 && munow!=0 && munext!=0){mulast=munow;munow=munext;munext=mu;}
1568        if(munext==0 && munow!=0)munext=mu;
1569        if(munow==0 && mulast!=0)munow=mu;
1570        if(mulast==0)mulast=mu;
1571        
1572        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1573        //Int_t ref;
1574        //cin>>ref;
1575        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;
1576        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;
1577        //if(normal_way)cout<<"Normal_Way"<<endl;
1578        if(Large_gap || small_gap_on_ridge){
1579          //cout<<"Large gap..."<<endl;
1580          //if(small_gap_on_ridge)cout<<"small gap..."<<endl;
1581          //cout<<"q["<<mulast<<"] = "<<q[mulast]<<"\tq["<<munow<<"] = "<<q[munow]<<"\tq["<<munext<<"] = "<<q[munext]<<endl;
1582          //cout<<"qtime["<<mulast<<"] = "<<qtime[mulast]<<"\tqtime["<<munow<<"] = "<<qtime[munow]<<"\tqtime["<<munext<<"] = "<<qtime[munext]<<endl;
1583          increase = false;
1584          decrease = false;
1585          if(nfi>0){
1586            qsine.resize(qsine.size()-1);
1587            sinesize = qsine.size();
1588            //cout<<"nfi was larger then zero"<<endl;
1589          }else{
1590            //cout<<"nfi was not larger then zero :( nfi = "<<nfi<<endl;
1591            //cout<<"qsine.size = "<<qsine.size()<<endl;
1592            if(!Period_is_defined){
1593              //cout<<"Period was defined"<<endl;
1594              if(qsine.size()>1){
1595                qsine[sinesize-1].b = qsine[sinesize-2].b;
1596                qsine[sinesize-1].c = qsine[sinesize-2].c;
1597              }else{
1598                qsine[sinesize-1].b = TMath::Pi()/1591.54;
1599                qsine[sinesize-1].c = qsine[sinesize-1].startPoint;
1600              }
1601            }
1602            if(!Max_is_defined){
1603              //cout<<"Max was already defined"<<endl;
1604              if(qsine.size()>1)qsine[sinesize-1].A = qsine[sinesize-2].A;else qsine[sinesize-1].A = limsin;
1605            }
1606            qsine[sinesize-1].NeedFit = true;
1607          }
1608          qsine[sinesize-1].finishPoint = qtime[munow];
1609          //cout<<"finish point before large gap = "<<qtime[munow]<<endl;
1610          nfi = 0;
1611          Max_is_defined = false;
1612          Start_point_is_defined = false;
1613          Period_is_defined = false;
1614          small_gap_on_ridge = false;
1615        }
1616        //cout<<"Slope "<<increase<<"\t"<<decrease<<endl;
1617        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1618        if((munext>munow) && (munow>mulast) && normal_way){
1619          if(!increase && !decrease){
1620            //cout<<"Normal way have started"<<endl;
1621            qsine.resize(qsine.size()+1);
1622            sinesize = qsine.size();
1623            qsine[sinesize-1].startPoint=qtime[mulast];
1624            if(q[munext]>q[munow] && q[munow]>q[mulast]) increase = true;
1625            if(q[munext]<q[munow] && q[munow]<q[mulast]) decrease = true;
1626          }
1627          //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;}
1628          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){
1629            //cout<<"Max point is qtime = "<<qtime[munow]<<"\tq = "<<q[munow]<<endl;
1630            if(q[munow]>q[mulast]){
1631              increase = false;
1632              decrease = true;
1633            }
1634            if(q[munow]<q[mulast]){
1635              increase = true;
1636              decrease = false;
1637            }
1638            if(Max_is_defined && !Start_point_is_defined){
1639              Double_t qPer = qtime[munow]-t1A;
1640              if(qPer>1000){
1641                //cout<<"qsine["<<sinesize-1<<"] = "<<qPer<<" = "<<qtime[munow]<<" - "<<t1A<<"\tlim = "<<limsin<<endl;
1642                qsine[sinesize-1].b=TMath::Pi()/qPer;
1643                if(decrease)qsine[sinesize-1].c=-qsine[sinesize-1].b*t1A;
1644                if(increase)qsine[sinesize-1].c=-qsine[sinesize-1].b*(t1A-qPer);
1645                Period_is_defined = true;
1646              }
1647            }
1648            Max_is_defined = true;
1649            qsine[sinesize-1].A = TMath::Abs(q[munow]);
1650            if(Start_point_is_defined && Period_is_defined){
1651              qsine[sinesize-1].finishPoint = qtime[munow];
1652              nfi++;
1653              qsine[sinesize-1].NeedFit = false;
1654              Max_is_defined = false;
1655              Start_point_is_defined = false;
1656              Period_is_defined = false;
1657              qsine.resize(qsine.size()+1);
1658              sinesize = qsine.size();
1659              qsine[sinesize-1].startPoint = qtime[munow];
1660            }
1661            if(!Start_point_is_defined) t1A=qtime[munow];
1662          }
1663          //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;
1664          if(((q[munow]>=0 && q[mulast]<=0) || (q[munow]<=0 && q[mulast]>=0)) && qtime[munow]-qtime[mulast]<2000 && qtime[munext]-qtime[munow]<2000){
1665            Double_t tcrosszero = 0;
1666            //cout<<"cross zero point...qtime = "<<qtime[munow]<<endl;
1667            if(q[munow]==0.) tcrosszero = qtime[munow];else
1668              if(q[mulast]==0.)tcrosszero = qtime[mulast];else{
1669                Double_t k_ = (q[munow]-q[mulast])/(qtime[munow]-qtime[mulast]);
1670                Double_t b_ = q[munow]-k_*qtime[munow];
1671                tcrosszero = -b_/k_;
1672              }
1673            if(Start_point_is_defined){
1674              //cout<<"Start Point allready defined"<<endl;
1675              Double_t qPer = tcrosszero - t1;
1676              qsine[sinesize-1].b = TMath::Pi()/qPer;
1677              //cout<<"qsine["<<sinesize-1<<"].b = "<<TMath::Pi()/qPer<<endl;
1678              Period_is_defined = true;
1679              Float_t x0 = 0;
1680              if(decrease)x0 = t1;
1681              if(increase)x0 = tcrosszero;
1682              qsine[sinesize-1].c = -qsine[sinesize-1].b*x0;
1683              if(Max_is_defined){
1684                //cout<<"Max was previous defined"<<endl;
1685                qsine[sinesize-1].finishPoint = qtime[munow];
1686                nfi++;
1687                qsine[sinesize-1].NeedFit = false;
1688                Max_is_defined = false;
1689                t1 = tcrosszero;
1690                Start_point_is_defined = true;
1691                Period_is_defined = false;
1692                qsine.resize(qsine.size()+1);
1693                sinesize = qsine.size();
1694                qsine[sinesize-1].startPoint = qtime[munow];
1695              }
1696            }else{
1697              t1 = tcrosszero;
1698              Start_point_is_defined = true;
1699            }
1700          }
1701        }
1702        }
1703      }
1704    
1705      //cout<<"FINISH SINE INTERPOLATION FUNCTION..."<<endl<<endl;
1706    }

Legend:
Removed from v.1.22  
changed lines
  Added in v.1.56

  ViewVC Help
Powered by ViewVC 1.1.23