/[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.30 by mocchiut, Wed Oct 1 15:25:44 2008 UTC revision 1.58 by mocchiut, Tue May 15 15:10:42 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  //  //
# Line 71  int OrbitalInfoCore(UInt_t run, TFile *f Line 75  int OrbitalInfoCore(UInt_t run, TFile *f
75    //    //
76    Bool_t verbose = false;    Bool_t verbose = false;
77    //    //
78    Bool_t standalone = true;    Bool_t standalone = false;
79    //    //
80    if ( OrbitalInfoargc > 0 ){    if ( OrbitalInfoargc > 0 ){
81      i = 0;      i = 0;
# Line 124  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 141  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 176  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 209  int OrbitalInfoCore(UInt_t run, TFile *f Line 214  int OrbitalInfoCore(UInt_t run, TFile *f
214    OrbitalInfofolder << tempname.str().c_str();    OrbitalInfofolder << tempname.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 218  int OrbitalInfoCore(UInt_t run, TFile *f Line 224  int OrbitalInfoCore(UInt_t run, TFile *f
224    //    //
225    //Quaternions classes    //Quaternions classes
226    //    //
227    Quaternions *L_QQ_Q_l_lower = new Quaternions();    Quaternions *L_QQ_Q_l_lower = 0;
228    InclinationInfo *RYPang_lower = new InclinationInfo();    InclinationInfo *RYPang_lower = 0;
229    Quaternions *L_QQ_Q_l_upper = new Quaternions();    Quaternions *L_QQ_Q_l_upper = 0;
230    InclinationInfo *RYPang_upper = new InclinationInfo();    InclinationInfo *RYPang_upper = 0;
231        
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    //    //
245    // Orientation variables    // Orientation variables. Vitaly
246    //    //
247    UInt_t evfrom = 0;    UInt_t evfrom = 0;
248    UInt_t jumped = 0;    UInt_t jumped = 0;
# Line 251  int OrbitalInfoCore(UInt_t run, TFile *f Line 259  int OrbitalInfoCore(UInt_t run, TFile *f
259    Int_t nz = 6;    Int_t nz = 6;
260    Float_t zin[6];    Float_t zin[6];
261    Int_t nevtofl2 = 0;    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    ltp2 = (Int_t)(glparam->PATH+glparam->NAME).Length();    while(!in.eof()){
278    if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());      recqtime.resize(recqtime.size()+1);
279    //      Int_t sizee = recqtime.size();
280    parerror=glparam2->Query_GL_PARAM(1,302,dbc); // parameters stored in DB in GL_PRAM table      recq0.resize(sizee);
281    if ( parerror<0 ) {      recq1.resize(sizee);
282      code = parerror;      recq2.resize(sizee);
283      goto closeandexit;      recq3.resize(sizee);
284    };      in>>recqtime[sizee-1];
285    ltp3 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();      in>>recq0[sizee-1];
286    if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());      in>>recq1[sizee-1];
287    //      in>>recq2[sizee-1];
288    initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);      in>>recq3[sizee-1];
289    //      in>>Norm;
290    // End IGRF stuff//    }
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++){    for (Int_t ip=0;ip<nz;ip++){
297      zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));      zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
298    };    };
# Line 342  int OrbitalInfoCore(UInt_t run, TFile *f Line 364  int OrbitalInfoCore(UInt_t run, TFile *f
364    // number of run to be processed    // number of run to be processed
365    //    //
366    numbofrun = runinfo->GetNoRun();    numbofrun = runinfo->GetNoRun();
367    UInt_t totnorun = runinfo->GetRunEntries();    totnorun = runinfo->GetRunEntries();
368    //    //
369    // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run    // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run
370    //    //
# Line 376  int OrbitalInfoCore(UInt_t run, TFile *f Line 398  int OrbitalInfoCore(UInt_t run, TFile *f
398        //        //
399        reprocall = true;        reprocall = true;
400        //        //
401        if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n");        if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n Deleting old tree...\n");
402        //        //
403      } else {      } else {
404        //        //
# Line 394  int OrbitalInfoCore(UInt_t run, TFile *f Line 416  int OrbitalInfoCore(UInt_t run, TFile *f
416        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
417        tempOrbitalInfo->SetName("OrbitalInfo-old");        tempOrbitalInfo->SetName("OrbitalInfo-old");
418        tempfile->Write();        tempfile->Write();
419          tempOrbitalInfo->Delete();
420        tempfile->Close();          tempfile->Close();  
421      }      }
422      //      //
423      // Delete the old tree from old file and memory      // Delete the old tree from old file and memory
424      //      //
425        OrbitalInfotrclone->Clear();
426      OrbitalInfotrclone->Delete("all");      OrbitalInfotrclone->Delete("all");
427      //      //
428      if (verbose) printf(" ...done!\n");      if (verbose) printf(" ...done!\n");
# Line 430  int OrbitalInfoCore(UInt_t run, TFile *f Line 454  int OrbitalInfoCore(UInt_t run, TFile *f
454        }        }
455        for (UInt_t j = 0; j < nobefrun; j++){        for (UInt_t j = 0; j < nobefrun; j++){
456          //          //
457          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
458          //          //
459          // copy orbitalinfoclone to mydec          // copy orbitalinfoclone to mydec
460          //          //
# Line 444  int OrbitalInfoCore(UInt_t run, TFile *f Line 468  int OrbitalInfoCore(UInt_t run, TFile *f
468          //          //
469        };        };
470        if (verbose) printf(" Finished successful copying!\n");        if (verbose) printf(" Finished successful copying!\n");
471      };                };
472    };    };
473    //    //
474      //
475    // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.    // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
476    //    //
477    runlist = runinfo->GetRunList();    runlist = runinfo->GetRunList();
# Line 454  int OrbitalInfoCore(UInt_t run, TFile *f Line 479  int OrbitalInfoCore(UInt_t run, TFile *f
479    // Loop over the run to be processed    // Loop over the run to be processed
480    //    //
481    for (UInt_t irun=0; irun < numbofrun; irun++){    for (UInt_t irun=0; irun < numbofrun; irun++){
482    
483        L_QQ_Q_l_lower = new Quaternions();
484        RYPang_lower = new InclinationInfo();
485        L_QQ_Q_l_upper = new Quaternions();
486        RYPang_upper = new InclinationInfo();
487    
488      //      //
489      // retrieve the first run ID to be processed using the RunInfo list      // retrieve the first run ID to be processed using the RunInfo list
490      //      //
# Line 502  int OrbitalInfoCore(UInt_t run, TFile *f Line 533  int OrbitalInfoCore(UInt_t run, TFile *f
533      fname = ftmpname.str().c_str();      fname = ftmpname.str().c_str();
534      ftmpname.str("");      ftmpname.str("");
535      //      //
536      // print out informations      // print nout informations
537      //      //
538      totevent = runinfo->NEVENTS;      totevent = runinfo->NEVENTS;
539      evfrom = runinfo->EV_FROM;      evfrom = runinfo->EV_FROM;
# Line 554  int OrbitalInfoCore(UInt_t run, TFile *f Line 585  int OrbitalInfoCore(UInt_t run, TFile *f
585        code = -12;        code = -12;
586        goto closeandexit;        goto closeandexit;
587      };      };
588    
589        //
590        // open IGRF files and do it only once if we are processing a full level2 file
591        //
592        if ( irun == 0 ){
593          if ( l0head->GetEntry(runinfo->EV_FROM) <= 0 ) throw -36;
594          //
595          // absolute time of first event of the run (it should not matter a lot)
596          //
597          ph = eh->GetPscuHeader();
598          atime = dbtime->DBabsTime(ph->GetOrbitalTime());
599          
600          parerror=glparam->Query_GL_PARAM(atime-anni5,301,dbc); // parameters stored in DB in GL_PRAM table  
601          if ( parerror<0 ) {
602            code = parerror;
603            goto closeandexit;
604        };
605          ltp1 = (Int_t)(glparam->PATH+glparam->NAME).Length();
606          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
607          //
608          parerror=glparam2->Query_GL_PARAM(atime,301,dbc); // parameters stored in DB in GL_PRAM table  
609          if ( parerror<0 ) {
610            code = parerror;
611            goto closeandexit;
612          };
613          ltp2 = (Int_t)(glparam2->PATH+glparam->NAME).Length();
614          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
615          //
616          parerror=glparam3->Query_GL_PARAM(atime,302,dbc); // parameters stored in DB in GL_PRAM table
617          if ( parerror<0 ) {
618            code = parerror;
619            goto closeandexit;
620          };
621          ltp3 = (Int_t)(glparam3->PATH+glparam2->NAME).Length();
622          if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam3->PATH+glparam3->NAME).Data());
623          //
624          initize_((char *)(glparam->PATH+glparam->NAME).Data(),&ltp1,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp2,(char *)(glparam3->PATH+glparam3->NAME).Data(),&ltp3);
625          //
626        }
627        //
628        // End IGRF stuff//
629        //
630    
631        //
632        //     TTree *tp = (TTree*)l0File->Get("RunHeader");
633        //     tp->SetBranchAddress("Header", &eH);
634        //     tp->SetBranchAddress("RunHeader", &reh);
635        //     tp->GetEntry(0);
636        //     ph = eH->GetPscuHeader();
637        //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
638        //     ULong_t ObtSync = reh->OBT_TIME_SYNC;    
639        //     if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
640      //      //
 //     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);  
 //  
641      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
642      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
643      ULong_t DeltaOBT = TimeSync - ObtSync;      ULong_t DeltaOBT = TimeSync - ObtSync;
644    
645      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);
646            //
647      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
648      neventsm = l0trm->GetEntries();      //
649        ch = new TChain("Mcmd","Mcmd");
650        //
651        // look in the DB to find the closest files to this run
652        //
653        TSQLResult *pResult = 0;
654        TSQLRow *Row = 0;
655        stringstream myquery;
656        UInt_t l0fid[10];
657        Int_t i = 0;
658        memset(l0fid,0,10*sizeof(Int_t));
659        //
660        myquery.str("");
661        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;";
662        //
663        pResult = dbc->Query(myquery.str().c_str());
664        //
665        i = 9;
666        if( pResult ){
667          //
668          Row = pResult->Next();
669          //
670          while ( Row ){
671            //
672            // store infos and exit
673            //
674            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
675            i--;
676            Row = pResult->Next();  
677            //
678          };
679          pResult->Delete();
680        };
681        //
682        myquery.str("");
683        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;";
684        //
685        pResult = dbc->Query(myquery.str().c_str());
686        //
687        i = 0;
688        if( pResult ){
689          //
690          Row = pResult->Next();
691          //
692          while ( Row ){
693            //
694            // store infos and exit
695            //
696            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
697            i++;
698            Row = pResult->Next();  
699            //
700          };
701          pResult->Delete();
702        };
703        //
704        i = 0;
705        UInt_t previd = 0;
706        while ( i < 10 ){
707          if ( l0fid[i] && previd != l0fid[i] ){
708            previd = l0fid[i];
709            myquery.str("");
710            myquery << "select PATH,NAME from GL_ROOT where ID=" << l0fid[i] << " ;";
711            //
712            pResult = dbc->Query(myquery.str().c_str());
713            //
714            if( pResult ){
715              //
716              Row = pResult->Next();
717              //
718              if ( debug ) printf(" Using inclination informations from file: %s \n",(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1)).Data());
719              ch->Add(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1));
720              //
721              pResult->Delete();
722            };
723          };
724          i++;
725        };
726        //
727        //    l0trm = (TTree*)l0File->Get("Mcmd");
728        //    ch->ls();
729        ch->SetBranchAddress("Mcmd",&mcmdev);
730        //    printf(" entries %llu \n", ch->GetEntries());
731        //    l0trm = ch->GetTree();
732        //    neventsm = l0trm->GetEntries();
733        neventsm = ch->GetEntries();
734        if ( debug ) printf(" entries %u \n", neventsm);
735      //    neventsm = 0;      //    neventsm = 0;
736      //      //
737      if (neventsm == 0){      if (neventsm == 0){
# Line 582  int OrbitalInfoCore(UInt_t run, TFile *f Line 742  int OrbitalInfoCore(UInt_t run, TFile *f
742      }      }
743      //      //
744            
745      l0trm->SetBranchAddress("Mcmd", &mcmdev);      //    l0trm->SetBranchAddress("Mcmd", &mcmdev);
746      //    l0trm->SetBranchAddress("Header", &eh);      //    l0trm->SetBranchAddress("Header", &eh);
747      //      //
748      //      //
749      //      //
750      UInt_t mctren = 0;      
751      UInt_t mcreen = 0;    //    UInt_t mctren = 0;    
752    //    UInt_t mcreen = 0;        
753      UInt_t numrec = 0;      UInt_t numrec = 0;
754      //      //
755      Double_t upperqtime = 0;      Double_t upperqtime = 0;
756      Double_t lowerqtime = 0;      Double_t lowerqtime = 0;
757            
758      Double_t incli = 0;  //    Double_t incli = 0;
759      oi = 0;  //    oi = 0;
760      UInt_t ooi = 0;  //    UInt_t ooi = 0;
761      //      //
762      // init quaternions sync      // init quaternions information from mcmd-packets
763      //      //
764      Bool_t isf = true;      Bool_t isf = true;
765      Int_t fgh = 0;  //    Int_t fgh = 0;
766    
767        vector<Float_t> q0;
768        vector<Float_t> q1;
769        vector<Float_t> q2;
770        vector<Float_t> q3;
771        vector<Double_t> qtime;
772        vector<Float_t> qPitch;
773        vector<Float_t> qRoll;
774        vector<Float_t> qYaw;
775        vector<Int_t> qmode;
776    
777        Int_t nt = 0;
778        
779        //init sine-function interpolation
780        
781        //cout<<"Sine coeficient initialisation..."<<endl;
782        vector<Sine> q0sine;
783        vector<Sine> q1sine;
784        vector<Sine> q2sine;
785        vector<Sine> q3sine;
786        vector<Sine> Yawsine;
787    
788        /*TH2F* q0testing = new TH2F();
789          TH2F* q1testing = new TH2F();
790          TH2F* q2testing = new TH2F();
791          TH2F* q3testing = new TH2F();
792          TH2F* Pitchtesting = new TH2F();
793        */
794        UInt_t must = 0;
795    
796      //      //
797      // run over all the events of the run      // run over all the events of the run
798      //      //
799      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");
800      //      //
801       //      //
802      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
       
803        //        //
804        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
805        if ( debug ) printf(" %i \n",procev);              if ( debug ) printf(" %i \n",procev);      
806        //        //
807        l0head->GetEntry(re);        if ( l0head->GetEntry(re) <= 0 ) throw -36;
808        //        //
809        // absolute time of this event        // absolute time of this event
810        //        //
811        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
812        atime = dbtime->DBabsTime(ph->GetOrbitalTime());        atime = dbtime->DBabsTime(ph->GetOrbitalTime());
813          if ( debug ) printf(" %i absolute time \n",procev);      
814        //        //
815        // paranoid check        // paranoid check
816        //        //
817        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {        if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1))  ) {
818          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");
819          jumped++;          jumped++;
820  //      debug = true;          //      debug = true;
821          continue;          continue;
822        }        }
823    
# Line 651  int OrbitalInfoCore(UInt_t run, TFile *f Line 842  int OrbitalInfoCore(UInt_t run, TFile *f
842          //          //
843          tof->Clear();          tof->Clear();
844          //          //
845          ttof->GetEntry(itr);          if ( ttof->GetEntry(itr) <= 0 ) throw -36;
846          //          //
847        };        };
848        //        //
# Line 659  int OrbitalInfoCore(UInt_t run, TFile *f Line 850  int OrbitalInfoCore(UInt_t run, TFile *f
850        //        //
851        // start processing        // start processing
852        //        //
853          if ( debug ) printf(" %i start processing \n",procev);      
854        orbitalinfo->Clear();        orbitalinfo->Clear();
855        //        //
856        OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();        OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
# Line 670  int OrbitalInfoCore(UInt_t run, TFile *f Line 862  int OrbitalInfoCore(UInt_t run, TFile *f
862        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
863        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
864        orbitalinfo->absTime = atime;        orbitalinfo->absTime = atime;
865          if ( debug ) printf(" %i pktnum obt abstime \n",procev);      
866        //        //
867        // 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.
868        //        //
869          if ( debug ) printf(" %i sgp4 \n",procev);      
870        cCoordGeo coo;        cCoordGeo coo;
871        float jyear=0;            Float_t jyear=0.;    
872        //        //
873        if(atime >= gltle->GetToTime()) {        if(atime >= gltle->GetToTime()) {
874          if ( !gltle->Query(atime, dbc) ){          if ( !gltle->Query(atime, dbc) ){
875            //                  //      
876            // Compute the magnetic dipole moment.            // Compute the magnetic dipole moment.
877            //            //
878              if ( debug ) printf(" %i compute magnetic dipole moment \n",procev);      
879            UInt_t year, month, day, hour, min, sec;            UInt_t year, month, day, hour, min, sec;
880            //            //
881            TTimeStamp t = TTimeStamp(atime, kTRUE);            TTimeStamp t = TTimeStamp(atime, kTRUE);
# Line 688  int OrbitalInfoCore(UInt_t run, TFile *f Line 883  int OrbitalInfoCore(UInt_t run, TFile *f
883            t.GetTime(kTRUE, 0, &hour, &min, &sec);            t.GetTime(kTRUE, 0, &hour, &min, &sec);
884            jyear = (float) year            jyear = (float) year
885              + (month*31.+ (float) day)/365.              + (month*31.+ (float) day)/365.
886              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);              + (hour*3600.+min*60.+(float)sec)/(24.*3600.*365.);
887            //            //
888              if ( debug ) printf(" %i compute magnetic dipole moment get dipole moment for year\n",procev);      
889              if ( debug ) printf(" %i jyear %f dimo %f \n",procev,jyear,dimo);      
890            feldcof_(&jyear, &dimo); // get dipole moment for year            feldcof_(&jyear, &dimo); // get dipole moment for year
891              if ( debug ) printf(" %i compute magnetic dipole moment end\n",procev);      
892          } else {          } else {
893            code = -56;            code = -56;
894            goto closeandexit;            goto closeandexit;
# Line 705  int OrbitalInfoCore(UInt_t run, TFile *f Line 903  int OrbitalInfoCore(UInt_t run, TFile *f
903        // synchronize with quaternions data        // synchronize with quaternions data
904        //        //
905        if ( isf && neventsm>0 ){        if ( isf && neventsm>0 ){
         if ( debug ) printf(" I am here \n");  
906          //          //
907          // First event          // First event
908          //          //
909          isf = false;          isf = false;
910          upperqtime = atime;          upperqtime = atime;
911          lowerqtime = runinfo->RUNHEADER_TIME;          lowerqtime = runinfo->RUNHEADER_TIME;
912          for ( ik = 0; ik < neventsm; ik++){          for ( ik = 0; ik < neventsm; ik++){  //number of macrocommad packets
913            l0trm->GetEntry(ik);            if ( ch->GetEntry(ik) <= 0 ) throw -36;
914            tmpSize = mcmdev->Records->GetEntries();            tmpSize = mcmdev->Records->GetEntries();
915            numrec = tmpSize;            numrec = tmpSize;
916            for (Int_t j3 = 0;j3<tmpSize;j3++){            for (Int_t j3 = 0;j3<tmpSize;j3++){  //number of subpackets
917              if ( debug ) printf(" eh eh eh \n");              if ( debug ) printf(" ik %i j3 %i eh eh eh \n",ik,j3);
918              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
919              if ((int)mcmdrc->ID1 == 226){              if ( mcmdrc ){ // missing inclination bug [8RED 090116]
920                L_QQ_Q_l_upper->fill(mcmdrc->McmdData);                if ( debug ) printf(" pluto \n");
921                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
922                  if (ui>0){                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
923                    if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){                  for (UInt_t ui = 0; ui < 6; ui++){
924                      if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){                    if (ui>0){
925                        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]){
926                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          if ( debug ) printf(" here1 %i \n",ui);
927                        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));
928                      }else {                        Int_t recSize = recqtime.size();
929                        lowerqtime = upperqtime;                        if(lowerqtime > recqtime[recSize-1]){
930                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));                            Int_t sizeqmcmd = qtime.size();
931                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
932                        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;
933                        mcreen = j3;                            q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
934                        mctren = ik;                            q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
935                        if(fgh==0){                            q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
936                          CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                            q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
937                          CopyAng(RYPang_lower,RYPang_upper);                            qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
938                              lowerqtime = u_time;
939                              orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
940                              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]);
941                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
942                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
943                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
944                          }
945                          for(Int_t mu = nt;mu<recSize;mu++){
946                            if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
947                              nt=mu;
948                              Int_t sizeqmcmd = qtime.size();
949                              inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
950                              qtime[sizeqmcmd]=recqtime[mu];
951                              q0[sizeqmcmd]=recq0[mu];
952                              q1[sizeqmcmd]=recq1[mu];
953                              q2[sizeqmcmd]=recq2[mu];
954                              q3[sizeqmcmd]=recq3[mu];
955                              qmode[sizeqmcmd]=-10;
956                              orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
957                              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]);
958                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
959                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
960                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
961                            }
962                            if(recqtime[mu]>=u_time){
963                              Int_t sizeqmcmd = qtime.size();
964                              inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
965                              qtime[sizeqmcmd]=u_time;
966                              q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
967                              q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
968                              q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
969                              q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
970                              qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
971                              lowerqtime = u_time;
972                              orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
973                              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]);
974                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
975                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
976                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
977                              break;
978                            }
979                        }                        }
                       oi=ui;  
                       goto closethisloop;  
980                      }                      }
981                      fgh++;                    }else{
982                      CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          if ( debug ) printf(" here2 %i \n",ui);
983                      CopyAng(RYPang_lower,RYPang_upper);                      Double_t u_time = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
984                    }                      if(lowerqtime>u_time)nt=0;
985                  }else{                      Int_t recSize = recqtime.size();
986                    if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){                      if(lowerqtime > recqtime[recSize-1]){
987                      upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                          Int_t sizeqmcmd = qtime.size();
988                      orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
989                      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;
990                    }                          q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
991                    else {                          q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
992                      lowerqtime = upperqtime;                          q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
993                      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];
994                      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);
995                      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;
996                      mcreen = j3;                          orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
997                      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]);
998                      if(fgh==0){                          qRoll[sizeqmcmd]=RYPang_upper->Kren;
999                        CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1000                        CopyAng(RYPang_lower,RYPang_upper);                          qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1001                        lowerqtime = atime-1;                      }
1002                        for(Int_t mu = nt;mu<recSize;mu++){
1003                          if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
1004                            nt=mu;
1005                            Int_t sizeqmcmd = qtime.size();
1006                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1007                            qtime[sizeqmcmd]=recqtime[mu];
1008                            q0[sizeqmcmd]=recq0[mu];
1009                            q1[sizeqmcmd]=recq1[mu];
1010                            q2[sizeqmcmd]=recq2[mu];
1011                            q3[sizeqmcmd]=recq3[mu];
1012                            qmode[sizeqmcmd]=-10;
1013                            orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1014                            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]);
1015                            qRoll[sizeqmcmd]=RYPang_upper->Kren;
1016                            qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1017                            qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1018                          }
1019                          if(recqtime[mu]>=u_time){
1020                            Int_t sizeqmcmd = qtime.size();
1021                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1022                            qtime[sizeqmcmd]=u_time;
1023                            q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
1024                            q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
1025                            q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
1026                            q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
1027                            qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1028                            lowerqtime = u_time;
1029                            orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1030                            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                            qRoll[sizeqmcmd]=RYPang_upper->Kren;
1032                            qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1033                            qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1034                            CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
1035                            break;
1036                          }
1037                      }                      }
                     oi=ui;  
                     goto closethisloop;  
                     //_0 = true;  
1038                    }                    }
1039                    fgh++;                  }
                   CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);  
                   CopyAng(RYPang_lower,RYPang_upper);  
                   //_0 = true;  
                 };  
                 //cin>>grib;  
               };  
             };  
           };  
         };  
       };  
     closethisloop:  
       //  
       if ( debug ) printf(" I am There \n");  
       //  
       if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){  
         if ( debug ) printf(" I am there \n");  
         //  
         lowerqtime = upperqtime;  
         Long64_t maxloop = 100000000LL;  
         Long64_t mn = 0;  
         bool gh=false;  
         ooi=oi;  
         if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);  
         while (!gh){        
           if ( mn > maxloop ){  
             if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");  
             gh = true;  
             neventsm = 0;  
           };  
           mn++;  
           if (oi<5) oi++;  
           else oi=0;  
           if (oi==0 && numrec > 0){  
             if ( debug ) printf(" mumble \n");  
             mcreen++;  
             if (mcreen == numrec){  
               mctren++;  
               mcreen = 0;  
               l0trm->GetEntry(mctren);  
               numrec = mcmdev->Records->GetEntries();  
             }  
             CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);  
             CopyAng(RYPang_lower,RYPang_upper);  
             mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);  
             if ((int)mcmdrc->ID1 == 226){  
               L_QQ_Q_l_upper->fill(mcmdrc->McmdData);  
               upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));  
               if (upperqtime<lowerqtime){  
                 upperqtime=runinfo->RUNTRAILER_TIME;  
                 CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);  
                 CopyAng(RYPang_upper,RYPang_lower);  
               }else{  
                 orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);  
                 RYPang_upper->TransAngle(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,L_QQ_Q_l_upper->quat[0][0],L_QQ_Q_l_upper->quat[0][1],L_QQ_Q_l_upper->quat[0][2],L_QQ_Q_l_upper->quat[0][3]);  
1040                }                }
               //              re--;  
               gh=true;  
1041              }              }
1042            }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));  
1043            }            }
1044            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));  
1045                    
1046                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){
1047                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++){
1048                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();
1049                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);
1050                //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];
1051                //cin>>grib;                  q0[sizeqmcmd]=recq0[my];
1052                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];
1053                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];
1054                    q3[sizeqmcmd]=recq3[my];
1055                    qmode[sizeqmcmd]=-10;
1056                    orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1057                    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]);
1058                    qRoll[sizeqmcmd]=RYPang_upper->Kren;
1059                    qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1060                    qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1061              }              }
1062            }          }
         } 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));  
1063                    
1064              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");
1065              orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1066              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);
1067              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);
1068              //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);
1069              //cin>>grib;          //sineparam(q3sine,qtime,q3,qRoll,qPitch,0.60);
1070              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);
1071              orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1072            }          if ( debug ) printf(" puffi \n");
1073            if (tut==6){          Double_t tmin = 9999999999.;
1074              if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){          Double_t tmax = 0.;
1075                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++){
1076                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];
1077                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];
1078                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));          }
1079                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");
1080                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));  
1081                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");
1082                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");
1083            //q2testing->SetName("q2testing");
1084            //q3testing->SetName("q3testing");
1085                    
1086                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);
1087                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.);
1088                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.);
1089                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1090                //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++){
1091                //cin>>grib;            //cout<<"q0["<<tre<<" = "<<q0[tre]<<endl;
1092                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]);
1093                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]);
1094              }            //Pitchtesting->Fill(qtime[tre],qPitch[tre],100);
1095            }                        //if(qmode[tre] == -10)Pitchtesting->Fill(qtime[tre],10,100);
1096              //q2testing->Fill(qtime[tre],q2[tre],100);
1097              //q3testing->Fill(qtime[tre],q3[tre],100);
1098    //      }
1099            
1100            //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;
1101            //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;
1102          } // if we processed first event
1103          
1104          //Filling Inclination information
1105          Double_t incli = 0;
1106          if ( qtime.size() > 1 ){
1107          for(UInt_t mu = must;mu<qtime.size()-1;mu++){
1108            if ( debug ) printf(" ??grfuffi %i sixe %i must %i \n",mu,qtime.size()-1,must);
1109            if(qtime[mu+1]>qtime[mu]){
1110              if ( debug ) printf(" grfuffi2 %i \n",mu);
1111              if(atime<=qtime[mu+1] && atime>=qtime[mu]){
1112                must = mu;
1113                incli = (qPitch[mu+1]-qPitch[mu])/(qtime[mu+1]-qtime[mu]);
1114                orbitalinfo->theta =  incli*atime+qPitch[mu+1]-incli*qtime[mu+1];
1115                incli = (qRoll[mu+1]-qRoll[mu])/(qtime[mu+1]-qtime[mu]);
1116                orbitalinfo->etha =  incli*atime+qRoll[mu+1]-incli*qtime[mu+1];
1117                incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1118                orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1119                
1120                incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1121                orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1122                incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1123                orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1124                incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1125                orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1126                incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1127                orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1128                
1129                orbitalinfo->TimeGap = qtime[mu+1]-qtime[mu];
1130                orbitalinfo->mode = qmode[mu+1];
1131                //if(qmode[mu+1]==-10) orbitalinfo->R10r = true;else orbitalinfo->R10r = false;
1132                //reserved for next versions Vitaly.
1133                /*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){
1134                  //linear interpolation
1135                  incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1136                  orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1137                  incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1138                  orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1139                  incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1140                  orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1141                  incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1142                  orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1143                }else{
1144                  //sine interpolation
1145                  for(UInt_t mt=0;mt<q0sine.size();mt++){
1146                    if(atime<=q0sine[mt].finishPoint && atime>=q0sine[mt].startPoint){
1147                      if(!q0sine[mt].NeedFit)orbitalinfo->q0=q0sine[mt].A*sin(q0sine[mt].b*atime+q0sine[mt].c);else{
1148                        incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1149                        orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1150                      }
1151                    }
1152                    if(atime<=q1sine[mt].finishPoint && atime>=q1sine[mt].startPoint){
1153                      if(!q1sine[mt].NeedFit)orbitalinfo->q1=q1sine[mt].A*sin(q1sine[mt].b*atime+q1sine[mt].c);else{
1154                        incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1155                        orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1156                      }
1157                    }
1158                    if(atime<=q2sine[mt].finishPoint && atime>=q2sine[mt].startPoint){
1159                      if(!q2sine[mt].NeedFit)orbitalinfo->q2=q0sine[mt].A*sin(q2sine[mt].b*atime+q2sine[mt].c);else{
1160                        incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1161                        orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1162                      }
1163                    }
1164                    if(atime<=q3sine[mt].finishPoint && atime>=q3sine[mt].startPoint){
1165                      if(!q3sine[mt].NeedFit)orbitalinfo->q3=q0sine[mt].A*sin(q3sine[mt].b*atime+q3sine[mt].c);else{
1166                        incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1167                        orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1168                      }
1169                    }
1170                    if(atime<=Yawsine[mt].finishPoint && atime>=Yawsine[mt].startPoint){
1171                      if(!Yawsine[mt].NeedFit)orbitalinfo->phi=Yawsine[mt].A*sin(Yawsine[mt].b*atime+Yawsine[mt].c);else{
1172                        incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1173                        orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1174                      }
1175                    }
1176                  }
1177                }*/
1178                //q0testing->Fill(atime,orbitalinfo->q0,100);
1179                //q1testing->Fill(atime,orbitalinfo->q1,100);
1180                //Pitchtesting->Fill(atime,orbitalinfo->etha);
1181                //q2testing->Fill(atime,orbitalinfo->q2);
1182                //q3testing->Fill(atime,orbitalinfo->q3);
1183                break;
1184              }
1185          }          }
1186          //        }
1187          orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);        }
         //  
       } else {  
         if ( debug ) printf(" ops no incl! \n");  
         orbitalinfo->mode = 10;  
       };  
1188        //        //
1189        // ops no inclination information        // ops no inclination information
1190        //        //
1191    
1192        if ( orbitalinfo->q0< -999 || orbitalinfo->q1 < -999 || orbitalinfo->q2 < -999 || orbitalinfo->q3 < -999 || orbitalinfo->q0 != orbitalinfo->q0 || orbitalinfo->q1 != orbitalinfo->q1 || orbitalinfo->q2 != orbitalinfo->q2 || orbitalinfo->q3 != orbitalinfo->q3 ){        if ( orbitalinfo->q0< -999 || orbitalinfo->q1 < -999 || orbitalinfo->q2 < -999 || orbitalinfo->q3 < -999 || orbitalinfo->q0 != orbitalinfo->q0 || orbitalinfo->q1 != orbitalinfo->q1 || orbitalinfo->q2 != orbitalinfo->q2 || orbitalinfo->q3 != orbitalinfo->q3 ){
1193          orbitalinfo->mode = 10;          orbitalinfo->mode = 10;
1194          orbitalinfo->q0 = -1000.;          orbitalinfo->q0 = -1000.;
# Line 981  int OrbitalInfoCore(UInt_t run, TFile *f Line 1230  int OrbitalInfoCore(UInt_t run, TFile *f
1230          orbitalinfo->BB0 = babs/bequ;          orbitalinfo->BB0 = babs/bequ;
1231          orbitalinfo->L = xl;                orbitalinfo->L = xl;      
1232          // Set Stormer vertical cutoff using L shell.          // Set Stormer vertical cutoff using L shell.
1233          orbitalinfo->cutoff[0] = 14.9/(xl*xl);          orbitalinfo->cutoffsvl = 14.295 / (xl*xl); //
1234            /*
1235    ---------- Forwarded message ----------
1236    Date: Wed, 09 May 2012 12:16:47 +0200
1237    From: Alessandro Bruno <alessandro.bruno@ba.infn.it>
1238    To: Mirko Boezio <mirko.boezio@ts.infn.it>
1239    Cc: Francesco S. Cafagna <Francesco.Cafagna@ba.infn.it>
1240    Subject: Störmer vertical cutoff
1241    
1242    Ciao Mirko,
1243    volevo segnalarti che il valore dello Störmer vertical cutoff nel Level2 è
1244    sovrastimato di circa il 4%.
1245    Dopo un'approfondita analisi con l'IGRF-05 abbiamo ricavano un valore pari
1246    a: 14.295 / L^2 anzichè 14.9 / L^2, valore obsoleto in quanto riferito agli
1247    anni '50.
1248    */
1249            //14.9/(xl*xl);
1250            orbitalinfo->igrf_icode = icode;
1251          //          //
1252        };              };      
1253        //        //
1254          if ( debug ) printf(" pitch angle \n");
1255          //
1256        // pitch angles        // pitch angles
1257        //        //
1258        if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){        //if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){
1259          if( orbitalinfo->TimeGap>0 && orbitalinfo->TimeGap<2000000){
1260          //          //
1261          Float_t Bx = -orbitalinfo->Bdown;                       //don't need for PamExp ExpOnly for all geography areas          Float_t Bx = -orbitalinfo->Bdown;
1262          Float_t By = orbitalinfo->Beast;                        //don't need for PamExp ExpOnly for all geography areas          Float_t By = orbitalinfo->Beast;
1263          Float_t Bz = orbitalinfo->Bnorth;                       //don't need for PamExp ExpOnly for all geography areas          Float_t Bz = orbitalinfo->Bnorth;
1264          //          //
1265          TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);          TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);
1266            TMatrixD Gij = PO->ColPermutation(Fij);
1267          TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);          TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);
1268          TMatrixD Iij = PO->ColPermutation(Dij);          TMatrixD Iij = PO->ColPermutation(Dij);
1269          //          //
1270            orbitalinfo->Iij.ResizeTo(Iij);
1271            orbitalinfo->Iij = Iij;
1272            //
1273          A1 = Iij(0,2);          A1 = Iij(0,2);
1274          A2 = Iij(1,2);          A2 = Iij(1,2);
1275          A3 = Iij(2,2);          A3 = Iij(2,2);
1276          //                //
1277          orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3);                        // Angle between zenit and Pamela's main axiz          //      orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3);                        // Angle between zenit and Pamela's main axiz
1278          orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz);                 // Angle between Pamela's main axiz and B          //      orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz);                 // Angle between Pamela's main axiz and B
1279          //          //
1280          if ( !standalone && tof->ntrk() > 0 ){          if ( !standalone && tof->ntrk() > 0 ){
1281            //            //
# Line 1016  int OrbitalInfoCore(UInt_t run, TFile *f Line 1289  int OrbitalInfoCore(UInt_t run, TFile *f
1289              Double_t E22x = ptt->xtr_tof[3];//tr->x[3];              Double_t E22x = ptt->xtr_tof[3];//tr->x[3];
1290              Double_t E22y = ptt->ytr_tof[3];//tr->y[3];              Double_t E22y = ptt->ytr_tof[3];//tr->y[3];
1291              Double_t E22z = zin[3];              Double_t E22z = zin[3];
1292              if ( E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.  ){              if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1  ){
1293                Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));                Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1294                Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));                //              Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1295                if(E22x-E11x>=0 && E22y-E11y <0) MyAzim =  360. - MyAzim;                //              if(E22x-E11x>=0 && E22y-E11y <0) MyAzim =  360. - MyAzim;
1296                if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;                //              if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1297                if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;                //              if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1298                if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;                //              if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1299                Px = (E22x-E11x)/norm;                Px = (E22x-E11x)/norm;
1300                Py = (E22y-E11y)/norm;                Py = (E22y-E11y)/norm;
1301                Pz = (E22z-E11z)/norm;                Pz = (E22z-E11z)/norm;
1302                //                //
               TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);              
               //              
1303                t_orb->trkseqno = ptt->trkseqno;                t_orb->trkseqno = ptt->trkseqno;
1304                  //
1305                  TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);
1306                  t_orb->Eij.ResizeTo(Eij);
1307                  t_orb->Eij = Eij;
1308                  //
1309                  TMatrixD Sij = PO->PamelatoGEO(Gij,Px,Py,Pz);
1310                  t_orb->Sij.ResizeTo(Sij);
1311                  t_orb->Sij = Sij;
1312                  //            
1313                t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);                t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);
1314                  //
1315                  //
1316                  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);
1317                  //
1318                  t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1319                  //
1320                  if ( t_orb->pitch != t_orb->pitch ) t_orb->pitch = -1000.;
1321                  if ( t_orb->cutoff != t_orb->cutoff ) t_orb->cutoff = -1000.;
1322                  //
1323                  if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1324                //                //
1325                new(tor[nn]) OrbitalInfoTrkVar(*t_orb);                new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1326                nn++;                nn++;
# Line 1044  int OrbitalInfoCore(UInt_t run, TFile *f Line 1334  int OrbitalInfoCore(UInt_t run, TFile *f
1334            if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());            if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());
1335          };          };
1336          //          //
1337          } else {
1338            if ( !standalone && tof->ntrk() > 0 ){
1339              //
1340              Int_t nn = 0;
1341              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1342                //
1343                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1344                if ( ptt->trkseqno != -1  ){
1345                  //
1346                  t_orb->trkseqno = ptt->trkseqno;
1347                  //
1348                  t_orb->Eij = 0;  
1349                  //
1350                  t_orb->Sij = 0;
1351                  //            
1352                  t_orb->pitch = -1000.;
1353                  //
1354                  t_orb->cutoff = -1000.;
1355                  //
1356                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1357                  nn++;
1358                  //
1359                  t_orb->Clear();
1360                  //
1361                };
1362                //
1363              };    
1364            };
1365        };        };
1366        //        //
1367        // Fill the class        // Fill the class
# Line 1056  int OrbitalInfoCore(UInt_t run, TFile *f Line 1374  int OrbitalInfoCore(UInt_t run, TFile *f
1374      //      //
1375      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
1376      //      //
1377    
1378        //gStyle->SetOptStat(000000);
1379        //gStyle->SetPalette(1);
1380        
1381        /*TCanvas* c1 = new TCanvas("c1","",1200,800);
1382        //c1->Divide(1,4);
1383        c1->cd(1);
1384        //q0testing->Draw("colz");
1385        //c1->cd(2);
1386        //q1testing->Draw("colz");
1387        //c1->cd(3);
1388        Pitchtesting->Draw("colz");
1389        //c1->cd(4);
1390        //q3testing->Draw("colz");
1391        c1->SaveAs("9.Rollhyst.png");
1392        delete c1;*/
1393    
1394        if ( verbose ) printf(" Clear before new run \n");
1395      delete dbtime;      delete dbtime;
1396      if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;  
1397        mcmdrc->Clear();
1398        mcmdrc = 0;
1399        
1400        if ( verbose ) printf(" Clear before new run1 \n");
1401      if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;      if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
1402        if ( verbose ) printf(" Clear before new run2 \n");
1403        if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1404        if ( verbose ) printf(" Clear before new run3 \n");
1405      if ( RYPang_upper ) delete RYPang_upper;      if ( RYPang_upper ) delete RYPang_upper;
1406        if ( verbose ) printf(" Clear before new run4 \n");
1407      if ( RYPang_lower ) delete RYPang_lower;      if ( RYPang_lower ) delete RYPang_lower;
1408    
1409        if ( l0tr ) l0tr->Delete();
1410        
1411        if ( verbose ) printf(" End run \n");
1412    
1413    }; // process all the runs    }; // process all the runs
1414        
1415    if (verbose) printf("\n Finished processing data \n");    if (verbose) printf("\n Finished processing data \n");
# Line 1080  int OrbitalInfoCore(UInt_t run, TFile *f Line 1429  int OrbitalInfoCore(UInt_t run, TFile *f
1429          //          //
1430          // Get entry from old tree          // Get entry from old tree
1431          //          //
1432          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
1433          //          //
1434          // copy orbitalinfoclone to OrbitalInfo          // copy orbitalinfoclone to OrbitalInfo
1435          //          //
# Line 1094  int OrbitalInfoCore(UInt_t run, TFile *f Line 1443  int OrbitalInfoCore(UInt_t run, TFile *f
1443        };        };
1444        if (verbose) printf(" Finished successful copying!\n");        if (verbose) printf(" Finished successful copying!\n");
1445      };      };
1446        //if ( OrbitalInfotrclone )    OrbitalInfotrclone->Clear();        
1447        //if ( OrbitalInfotrclone )    OrbitalInfotrclone->Delete();        
1448    };    };
1449    //    //
1450    // Close files, delete old tree(s), write and close level2 file    // Close files, delete old tree(s), write and close level2 file
1451    //    //
1452    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
   if ( tempfile ) tempfile->Close();              
1453    if ( myfold ) gSystem->Unlink(tempname.str().c_str());    if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1454    //    //
   if ( runinfo ) runinfo->Close();      
1455    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
   if ( tof ) tof->Delete();  
   if ( ttof ) ttof->Delete();  
1456    //    //
1457    if ( file ){    if ( file ){
1458      file->cd();      file->cd();
1459      file->Write();      OrbitalInfotr->Write("OrbitalInfo", TObject::kOverwrite);
1460    };    };
1461    //    //
1462      if (verbose) printf("\n Exiting...\n");
1463    
1464    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1465    //    //
1466    // the end    // the end
# Line 1120  int OrbitalInfoCore(UInt_t run, TFile *f Line 1469  int OrbitalInfoCore(UInt_t run, TFile *f
1469      dbc->Close();      dbc->Close();
1470      delete dbc;      delete dbc;
1471    };    };
   if (verbose) printf("\n Exiting...\n");  
   if(OrbitalInfotr)OrbitalInfotr->Delete();  
1472    //    //
1473      if (verbose) printf("\n Exiting...\n");
1474      if ( tempfile ) tempfile->Close();            
1475      
1476    if ( PO ) delete PO;    if ( PO ) delete PO;
1477    if ( orbitalinfo ) delete orbitalinfo;    if ( gltle ) delete gltle;
1478    if ( orbitalinfoclone ) delete orbitalinfoclone;    if ( glparam ) delete glparam;
1479      if ( glparam2 ) delete glparam2;
1480      if ( glparam3 ) delete glparam3;
1481      if (verbose) printf("\n Exiting3...\n");
1482    if ( glroot ) delete glroot;    if ( glroot ) delete glroot;
1483      if (verbose) printf("\n Exiting4...\n");
1484      if ( runinfo ) runinfo->Close();    
1485    if ( runinfo ) delete runinfo;    if ( runinfo ) delete runinfo;
1486    
1487      if ( debug ){  
1488      cout << "1   0x" << OrbitalInfotr << endl;
1489      cout << "2   0x" << OrbitalInfotrclone << endl;
1490      cout << "3   0x" << l0tr << endl;
1491      cout << "4   0x" << tempOrbitalInfo << endl;
1492      cout << "5   0x" << ttof << endl;
1493      }
1494      //
1495      if ( debug )  file->ls();
1496    //    //
1497    if(code < 0)  throw code;    if(code < 0)  throw code;
1498    return(code);    return(code);
# Line 1172  void CopyAng(InclinationInfo *A1, Inclin Line 1537  void CopyAng(InclinationInfo *A1, Inclin
1537  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){
1538        
1539    UInt_t hole = 10;    UInt_t hole = 10;
1540    bool R10l = false;     // Sign of R10 mode in lower quaternions array    Bool_t R10l = false;     // Sign of R10 mode in lower quaternions array
1541    bool R10u = false;     // Sign of R10 mode in upper quaternions array    Bool_t R10u = false;     // Sign of R10 mode in upper quaternions array
1542    bool insm = false;     // Sign that we inside quaternions array    Bool_t insm = false;     // Sign that we inside quaternions array
1543    bool mxtml = false;    // Sign of mixt mode in lower quaternions array    Bool_t mxtml = false;    // Sign of mixt mode in lower quaternions array
1544    bool mxtmu = false;    // Sign of mixt mode in upper quaternions array    Bool_t mxtmu = false;    // Sign of mixt mode in upper quaternions array
1545    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
1546    UInt_t NCQl = 6;       // Number of correct quaternions in lower array    UInt_t NCQl = 6;       // Number of correct quaternions in lower array
1547    UInt_t NCQu = 6;       // Number of correct quaternions in upper array    UInt_t NCQu = 6;       // Number of correct quaternions in upper array
1548    if (f>0){    if (f>0){
# Line 1220  UInt_t holeq(Double_t lower,Double_t upp Line 1585  UInt_t holeq(Double_t lower,Double_t upp
1585    return hole;    return hole;
1586  }  }
1587    
1588    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){
1589      Int_t sizee = t.size()+1;
1590      t.resize(sizee);
1591      q0.resize(sizee);
1592      q1.resize(sizee);
1593      q2.resize(sizee);
1594      q3.resize(sizee);
1595      mode.resize(sizee);
1596      Roll.resize(sizee);
1597      Pitch.resize(sizee);
1598      Yaw.resize(sizee);
1599    }
1600    
1601    //Find fitting sine functions for q0,q1,q2,q3 and Yaw-angle;
1602    void sineparam(vector<Sine>& qsine, vector<Double_t>& qtime, vector<Float_t>& q, vector<Float_t>& Roll, vector<Float_t>& Pitch, Float_t limsin){
1603      UInt_t mulast = 0;
1604      UInt_t munow = 0;
1605      UInt_t munext = 0;
1606      Bool_t increase = false;
1607      Bool_t decrease = false;
1608      Bool_t Max_is_defined = false;
1609      Bool_t Start_point_is_defined = false;
1610      Bool_t Period_is_defined = false;
1611      Bool_t Large_gap = false;
1612      Bool_t normal_way = true;
1613      Bool_t small_gap_on_ridge = false;
1614      Double_t t1 = 0;
1615      Double_t t1A = 0;
1616      Int_t sinesize = 0;
1617      Int_t nfi = 0;
1618      for(UInt_t mu = 0;mu<qtime.size();mu++){
1619        //cout<<"Roll["<<mu<<"] = "<<Roll[mu]<<endl;
1620        if(TMath::Abs(Roll[mu])<1. && TMath::Abs(Pitch[mu])<1. && TMath::Abs(q[mu])<limsin){
1621        //cout<<"q["<<mu<<endl<<"] = "<<q[mu]<<endl;
1622        if(mulast!=0 && munow!=0 && munext!=0){mulast=munow;munow=munext;munext=mu;}
1623        if(munext==0 && munow!=0)munext=mu;
1624        if(munow==0 && mulast!=0)munow=mu;
1625        if(mulast==0)mulast=mu;
1626        
1627        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1628        //Int_t ref;
1629        //cin>>ref;
1630        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;
1631        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;
1632        //if(normal_way)cout<<"Normal_Way"<<endl;
1633        if(Large_gap || small_gap_on_ridge){
1634          //cout<<"Large gap..."<<endl;
1635          //if(small_gap_on_ridge)cout<<"small gap..."<<endl;
1636          //cout<<"q["<<mulast<<"] = "<<q[mulast]<<"\tq["<<munow<<"] = "<<q[munow]<<"\tq["<<munext<<"] = "<<q[munext]<<endl;
1637          //cout<<"qtime["<<mulast<<"] = "<<qtime[mulast]<<"\tqtime["<<munow<<"] = "<<qtime[munow]<<"\tqtime["<<munext<<"] = "<<qtime[munext]<<endl;
1638          increase = false;
1639          decrease = false;
1640          if(nfi>0){
1641            qsine.resize(qsine.size()-1);
1642            sinesize = qsine.size();
1643            //cout<<"nfi was larger then zero"<<endl;
1644          }else{
1645            //cout<<"nfi was not larger then zero :( nfi = "<<nfi<<endl;
1646            //cout<<"qsine.size = "<<qsine.size()<<endl;
1647            if(!Period_is_defined){
1648              //cout<<"Period was defined"<<endl;
1649              if(qsine.size()>1){
1650                qsine[sinesize-1].b = qsine[sinesize-2].b;
1651                qsine[sinesize-1].c = qsine[sinesize-2].c;
1652              }else{
1653                qsine[sinesize-1].b = TMath::Pi()/1591.54;
1654                qsine[sinesize-1].c = qsine[sinesize-1].startPoint;
1655              }
1656            }
1657            if(!Max_is_defined){
1658              //cout<<"Max was already defined"<<endl;
1659              if(qsine.size()>1)qsine[sinesize-1].A = qsine[sinesize-2].A;else qsine[sinesize-1].A = limsin;
1660            }
1661            qsine[sinesize-1].NeedFit = true;
1662          }
1663          qsine[sinesize-1].finishPoint = qtime[munow];
1664          //cout<<"finish point before large gap = "<<qtime[munow]<<endl;
1665          nfi = 0;
1666          Max_is_defined = false;
1667          Start_point_is_defined = false;
1668          Period_is_defined = false;
1669          small_gap_on_ridge = false;
1670        }
1671        //cout<<"Slope "<<increase<<"\t"<<decrease<<endl;
1672        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1673        if((munext>munow) && (munow>mulast) && normal_way){
1674          if(!increase && !decrease){
1675            //cout<<"Normal way have started"<<endl;
1676            qsine.resize(qsine.size()+1);
1677            sinesize = qsine.size();
1678            qsine[sinesize-1].startPoint=qtime[mulast];
1679            if(q[munext]>q[munow] && q[munow]>q[mulast]) increase = true;
1680            if(q[munext]<q[munow] && q[munow]<q[mulast]) decrease = true;
1681          }
1682          //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;}
1683          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){
1684            //cout<<"Max point is qtime = "<<qtime[munow]<<"\tq = "<<q[munow]<<endl;
1685            if(q[munow]>q[mulast]){
1686              increase = false;
1687              decrease = true;
1688            }
1689            if(q[munow]<q[mulast]){
1690              increase = true;
1691              decrease = false;
1692            }
1693            if(Max_is_defined && !Start_point_is_defined){
1694              Double_t qPer = qtime[munow]-t1A;
1695              if(qPer>1000){
1696                //cout<<"qsine["<<sinesize-1<<"] = "<<qPer<<" = "<<qtime[munow]<<" - "<<t1A<<"\tlim = "<<limsin<<endl;
1697                qsine[sinesize-1].b=TMath::Pi()/qPer;
1698                if(decrease)qsine[sinesize-1].c=-qsine[sinesize-1].b*t1A;
1699                if(increase)qsine[sinesize-1].c=-qsine[sinesize-1].b*(t1A-qPer);
1700                Period_is_defined = true;
1701              }
1702            }
1703            Max_is_defined = true;
1704            qsine[sinesize-1].A = TMath::Abs(q[munow]);
1705            if(Start_point_is_defined && Period_is_defined){
1706              qsine[sinesize-1].finishPoint = qtime[munow];
1707              nfi++;
1708              qsine[sinesize-1].NeedFit = false;
1709              Max_is_defined = false;
1710              Start_point_is_defined = false;
1711              Period_is_defined = false;
1712              qsine.resize(qsine.size()+1);
1713              sinesize = qsine.size();
1714              qsine[sinesize-1].startPoint = qtime[munow];
1715            }
1716            if(!Start_point_is_defined) t1A=qtime[munow];
1717          }
1718          //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;
1719          if(((q[munow]>=0 && q[mulast]<=0) || (q[munow]<=0 && q[mulast]>=0)) && qtime[munow]-qtime[mulast]<2000 && qtime[munext]-qtime[munow]<2000){
1720            Double_t tcrosszero = 0;
1721            //cout<<"cross zero point...qtime = "<<qtime[munow]<<endl;
1722            if(q[munow]==0.) tcrosszero = qtime[munow];else
1723              if(q[mulast]==0.)tcrosszero = qtime[mulast];else{
1724                Double_t k_ = (q[munow]-q[mulast])/(qtime[munow]-qtime[mulast]);
1725                Double_t b_ = q[munow]-k_*qtime[munow];
1726                tcrosszero = -b_/k_;
1727              }
1728            if(Start_point_is_defined){
1729              //cout<<"Start Point allready defined"<<endl;
1730              Double_t qPer = tcrosszero - t1;
1731              qsine[sinesize-1].b = TMath::Pi()/qPer;
1732              //cout<<"qsine["<<sinesize-1<<"].b = "<<TMath::Pi()/qPer<<endl;
1733              Period_is_defined = true;
1734              Float_t x0 = 0;
1735              if(decrease)x0 = t1;
1736              if(increase)x0 = tcrosszero;
1737              qsine[sinesize-1].c = -qsine[sinesize-1].b*x0;
1738              if(Max_is_defined){
1739                //cout<<"Max was previous defined"<<endl;
1740                qsine[sinesize-1].finishPoint = qtime[munow];
1741                nfi++;
1742                qsine[sinesize-1].NeedFit = false;
1743                Max_is_defined = false;
1744                t1 = tcrosszero;
1745                Start_point_is_defined = true;
1746                Period_is_defined = false;
1747                qsine.resize(qsine.size()+1);
1748                sinesize = qsine.size();
1749                qsine[sinesize-1].startPoint = qtime[munow];
1750              }
1751            }else{
1752              t1 = tcrosszero;
1753              Start_point_is_defined = true;
1754            }
1755          }
1756        }
1757        }
1758      }
1759    
1760      //cout<<"FINISH SINE INTERPOLATION FUNCTION..."<<endl<<endl;
1761    }

Legend:
Removed from v.1.30  
changed lines
  Added in v.1.58

  ViewVC Help
Powered by ViewVC 1.1.23