/[PAMELA software]/DarthVader/OrbitalInfo/src/OrbitalInfoCore.cpp
ViewVC logotype

Diff of /DarthVader/OrbitalInfo/src/OrbitalInfoCore.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

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

  ViewVC Help
Powered by ViewVC 1.1.23