/[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.19 by mocchiut, Sat May 5 12:48:33 2007 UTC revision 1.47 by mocchiut, Mon Feb 1 05:34:39 2010 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 212  int OrbitalInfoCore(UInt_t run, TFile *f Line 234  int OrbitalInfoCore(UInt_t run, TFile *f
234    Int_t ltp2 = 0;    Int_t ltp2 = 0;
235    Int_t ltp3 = 0;    Int_t ltp3 = 0;
236    Int_t uno = 1;    Int_t uno = 1;
237    char *niente = " ";    const char *niente = " ";
238    GL_PARAM *glparam = new GL_PARAM();    GL_PARAM *glparam = new GL_PARAM();
239    GL_PARAM *glparam2 = new GL_PARAM();    GL_PARAM *glparam2 = new GL_PARAM();
240    Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table  
241        //
242      // Orientation variables. Vitaly
243      //
244      UInt_t evfrom = 0;
245      UInt_t jumped = 0;
246      Int_t itr = -1;    
247      Double_t A1;
248      Double_t A2;
249      Double_t A3;
250      Double_t Px = 0;
251      Double_t Py = 0;      
252      Double_t Pz = 0;  
253      TTree *ttof = 0;
254      ToFLevel2 *tof = new ToFLevel2();
255      OrientationInfo *PO = new OrientationInfo();
256      Int_t nz = 6;
257      Float_t zin[6];
258      Int_t nevtofl2 = 0;
259      if ( verbose ) cout<<"Reading quaternions external file"<<endl;
260      cout.setf(ios::fixed,ios::floatfield);  
261      /******Reading recovered quaternions...*********/
262      vector<Double_t> recqtime;
263      vector<Float_t> recq0;
264      vector<Float_t> recq1;
265      vector<Float_t> recq2;
266      vector<Float_t> recq3;
267      Float_t Norm = 1;
268      Int_t parerror=glparam->Query_GL_PARAM(1,303,dbc); // parameters stored in DB in GL_PRAM table  
269      ifstream in((glparam->PATH+glparam->NAME).Data(),ios::in);
270      if ( parerror<0 ) {
271        code = parerror;
272        goto closeandexit;
273      };
274      while(!in.eof()){
275        recqtime.resize(recqtime.size()+1);
276        Int_t sizee = recqtime.size();
277        recq0.resize(sizee);
278        recq1.resize(sizee);
279        recq2.resize(sizee);
280        recq3.resize(sizee);
281        in>>recqtime[sizee-1];
282        in>>recq0[sizee-1];
283        in>>recq1[sizee-1];
284        in>>recq2[sizee-1];
285        in>>recq3[sizee-1];
286        in>>Norm;
287      }
288      if ( verbose ) cout<<"We have read recovered data"<<endl;
289    
290    
291      parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table  
292    if ( parerror<0 ) {    if ( parerror<0 ) {
293      code = parerror;      code = parerror;
294      goto closeandexit;      goto closeandexit;
# Line 236  int OrbitalInfoCore(UInt_t run, TFile *f Line 308  int OrbitalInfoCore(UInt_t run, TFile *f
308    //    //
309    // End IGRF stuff//    // End IGRF stuff//
310    //    //
311      for (Int_t ip=0;ip<nz;ip++){
312        zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
313      };
314      //
315      if ( !standalone ){
316        //
317        // Does it contain the Tracker tree?
318        //
319        ttof = (TTree*)file->Get("ToF");
320        if ( !ttof ) {
321          if ( verbose ) printf(" OrbitalInfo - ERROR: no tof tree\n");
322          code = -900;
323          goto closeandexit;
324        };
325        ttof->SetBranchAddress("ToFLevel2",&tof);  
326        nevtofl2 = ttof->GetEntries();
327      };
328    //    //
329    // Let's start!    // Let's start!
330    //    //
# Line 291  int OrbitalInfoCore(UInt_t run, TFile *f Line 379  int OrbitalInfoCore(UInt_t run, TFile *f
379    // number of run to be processed    // number of run to be processed
380    //    //
381    numbofrun = runinfo->GetNoRun();    numbofrun = runinfo->GetNoRun();
382      totnorun = runinfo->GetRunEntries();
383    //    //
384    // 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
385    //    //
# Line 317  int OrbitalInfoCore(UInt_t run, TFile *f Line 406  int OrbitalInfoCore(UInt_t run, TFile *f
406      //      //
407      if (verbose) printf("\n Preparing the pre-processing...\n");      if (verbose) printf("\n Preparing the pre-processing...\n");
408      //      //
409      if ( run == 0 ){      if ( run == 0 || totnorun == 1 ){
410        //        //
411        // we are reprocessing all the file        // we are reprocessing all the file
412        // if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately        // if we are reprocessing everything we don't need to copy any old event and we can just work with the new tree and delete the old one immediately
# Line 336  int OrbitalInfoCore(UInt_t run, TFile *f Line 425  int OrbitalInfoCore(UInt_t run, TFile *f
425        //        //
426        // copying old tree to a new file        // copying old tree to a new file
427        //        //
428          gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
429          myfold = true;
430        tempfile = new TFile(tempname.str().c_str(),"RECREATE");        tempfile = new TFile(tempname.str().c_str(),"RECREATE");
431        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");        tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
432        tempOrbitalInfo->SetName("OrbitalInfo-old");        tempOrbitalInfo->SetName("OrbitalInfo-old");
# Line 356  int OrbitalInfoCore(UInt_t run, TFile *f Line 447  int OrbitalInfoCore(UInt_t run, TFile *f
447    file->cd();    file->cd();
448    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");    OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");
449    OrbitalInfotr->SetAutoSave(900000000000000LL);    OrbitalInfotr->SetAutoSave(900000000000000LL);
450      orbitalinfo->Set();//ELENA **TEMPORANEO?**
451    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);    OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);
452    //    //
453    if ( reproc && !reprocall ){    if ( reproc && !reprocall ){
# Line 375  int OrbitalInfoCore(UInt_t run, TFile *f Line 467  int OrbitalInfoCore(UInt_t run, TFile *f
467        }        }
468        for (UInt_t j = 0; j < nobefrun; j++){        for (UInt_t j = 0; j < nobefrun; j++){
469          //          //
470          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
471          //          //
472          // copy orbitalinfoclone to mydec          // copy orbitalinfoclone to mydec
473          //          //
# Line 392  int OrbitalInfoCore(UInt_t run, TFile *f Line 484  int OrbitalInfoCore(UInt_t run, TFile *f
484      };                };          
485    };    };
486    //    //
487      //
488    // 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.
489    //    //
490    runlist = runinfo->GetRunList();    runlist = runinfo->GetRunList();
491    //    //
492    // Loop over the run to be processed    // Loop over the run to be processed
493    //    //
     
494    for (UInt_t irun=0; irun < numbofrun; irun++){    for (UInt_t irun=0; irun < numbofrun; irun++){
495      //      //
496      // 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 448  int OrbitalInfoCore(UInt_t run, TFile *f Line 540  int OrbitalInfoCore(UInt_t run, TFile *f
540      fname = ftmpname.str().c_str();      fname = ftmpname.str().c_str();
541      ftmpname.str("");      ftmpname.str("");
542      //      //
543      // print out informations      // print nout informations
544      //      //
545      totevent = runinfo->NEVENTS;      totevent = runinfo->NEVENTS;
546        evfrom = runinfo->EV_FROM;
547      //cout<<"totevents = "<<totevent<<"\n";      //cout<<"totevents = "<<totevent<<"\n";
548      if (verbose){      if (verbose){
549        printf("\n LEVEL0 data file: %s \n",fname.Data());        printf("\n LEVEL0 data file: %s \n",fname.Data());
# Line 458  int OrbitalInfoCore(UInt_t run, TFile *f Line 551  int OrbitalInfoCore(UInt_t run, TFile *f
551        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);        printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
552        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);
553      }//      }//
554        //
555        //    if ( !totevent ) goto closeandexit;
556      // Open Level0 file      // Open Level0 file
557      l0File = new TFile(fname.Data());      l0File = new TFile(fname.Data());
558      if ( !l0File ) {      if ( !l0File ) {
# Line 484  int OrbitalInfoCore(UInt_t run, TFile *f Line 579  int OrbitalInfoCore(UInt_t run, TFile *f
579      // end EM      // end EM
580      nevents = l0head->GetEntries();      nevents = l0head->GetEntries();
581      //      //
582      if ( nevents < 1 ) {      if ( nevents < 1 && totevent ) {
583        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");        if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
584        l0File->Close();        l0File->Close();
585        code = -11;        code = -11;
586        goto closeandexit;        goto closeandexit;
587      };      };
588      //      //
589      if ( runinfo->EV_TO > nevents-1 ) {      if ( runinfo->EV_TO > nevents-1 && totevent ) {
590        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");
591        l0File->Close();        l0File->Close();
592        code = -12;        code = -12;
593        goto closeandexit;        goto closeandexit;
594      };      };
595      //      //
596  //     TTree *tp = (TTree*)l0File->Get("RunHeader");      //     TTree *tp = (TTree*)l0File->Get("RunHeader");
597  //     tp->SetBranchAddress("Header", &eH);      //     tp->SetBranchAddress("Header", &eH);
598  //     tp->SetBranchAddress("RunHeader", &reh);      //     tp->SetBranchAddress("RunHeader", &reh);
599  //     tp->GetEntry(0);      //     tp->GetEntry(0);
600  //     ph = eH->GetPscuHeader();      //     ph = eH->GetPscuHeader();
601  //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;      //     ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
602  //     ULong_t ObtSync = reh->OBT_TIME_SYNC;          //     ULong_t ObtSync = reh->OBT_TIME_SYNC;    
603  //     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);
604  //      //
605      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();      ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
606      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);      ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
607      ULong_t DeltaOBT = TimeSync - ObtSync;      ULong_t DeltaOBT = TimeSync - ObtSync;
608    
609      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);
610            //
611      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
612      neventsm = l0trm->GetEntries();      //
613        ch = new TChain("Mcmd","Mcmd");
614        //
615        // look in the DB to find the closest files to this run
616        //
617        TSQLResult *pResult = 0;
618        TSQLRow *Row = 0;
619        stringstream myquery;
620        UInt_t l0fid[10];
621        Int_t i = 0;
622        memset(l0fid,0,10*sizeof(Int_t));
623        //
624        myquery.str("");
625        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;";
626        //
627        pResult = dbc->Query(myquery.str().c_str());
628        //
629        i = 9;
630        if( pResult ){
631          //
632          Row = pResult->Next();
633          //
634          while ( Row ){
635            //
636            // store infos and exit
637            //
638            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
639            i--;
640            Row = pResult->Next();  
641            //
642          };
643          pResult->Delete();
644        };
645        //
646        myquery.str("");
647        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;";
648        //
649        pResult = dbc->Query(myquery.str().c_str());
650        //
651        i = 0;
652        if( pResult ){
653          //
654          Row = pResult->Next();
655          //
656          while ( Row ){
657            //
658            // store infos and exit
659            //
660            l0fid[i] = (UInt_t)atoll(Row->GetField(0));
661            i++;
662            Row = pResult->Next();  
663            //
664          };
665          pResult->Delete();
666        };
667        //
668        i = 0;
669        UInt_t previd = 0;
670        while ( i < 10 ){
671          if ( l0fid[i] && previd != l0fid[i] ){
672            previd = l0fid[i];
673            myquery.str("");
674            myquery << "select PATH,NAME from GL_ROOT where ID=" << l0fid[i] << " ;";
675            //
676            pResult = dbc->Query(myquery.str().c_str());
677            //
678            if( pResult ){
679              //
680              Row = pResult->Next();
681              //
682              if ( debug ) printf(" Using inclination informations from file: %s \n",(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1)).Data());
683              ch->Add(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1));
684              //
685              pResult->Delete();
686            };
687          };
688          i++;
689        };
690        //
691        //    l0trm = (TTree*)l0File->Get("Mcmd");
692        //    ch->ls();
693        ch->SetBranchAddress("Mcmd",&mcmdev);
694        //    printf(" entries %llu \n", ch->GetEntries());
695        //    l0trm = ch->GetTree();
696        //    neventsm = l0trm->GetEntries();
697        neventsm = ch->GetEntries();
698        if ( debug ) printf(" entries %u \n", neventsm);
699      //    neventsm = 0;      //    neventsm = 0;
700      //      //
701      if (neventsm == 0){      if (neventsm == 0){
# Line 525  int OrbitalInfoCore(UInt_t run, TFile *f Line 706  int OrbitalInfoCore(UInt_t run, TFile *f
706      }      }
707      //      //
708            
709      l0trm->SetBranchAddress("Mcmd", &mcmdev);      //    l0trm->SetBranchAddress("Mcmd", &mcmdev);
710      //    l0trm->SetBranchAddress("Header", &eh);      //    l0trm->SetBranchAddress("Header", &eh);
711      //      //
712      //      //
713      //      //
714      UInt_t mctren = 0;      
715      UInt_t mcreen = 0;    //    UInt_t mctren = 0;    
716    //    UInt_t mcreen = 0;        
717      UInt_t numrec = 0;      UInt_t numrec = 0;
718      //      //
719      Double_t upperqtime = 0;      Double_t upperqtime = 0;
720      Double_t lowerqtime = 0;      Double_t lowerqtime = 0;
721            
722      Double_t incli = 0;  //    Double_t incli = 0;
723      oi = 0;  //    oi = 0;
724      UInt_t ooi = 0;  //    UInt_t ooi = 0;
725      //      //
726      // init quaternions sync      // init quaternions information from mcmd-packets
727      //      //
728      Bool_t isf = true;      Bool_t isf = true;
729      Int_t fgh = 0;  //    Int_t fgh = 0;
730    
731        vector<Float_t> q0;
732        vector<Float_t> q1;
733        vector<Float_t> q2;
734        vector<Float_t> q3;
735        vector<Double_t> qtime;
736        vector<Float_t> qPitch;
737        vector<Float_t> qRoll;
738        vector<Float_t> qYaw;
739        vector<Int_t> qmode;
740    
741        Int_t nt = 0;
742        
743        //init sine-function interpolation
744        
745        //cout<<"Sine coeficient initialisation..."<<endl;
746        vector<Sine> q0sine;
747        vector<Sine> q1sine;
748        vector<Sine> q2sine;
749        vector<Sine> q3sine;
750        vector<Sine> Yawsine;
751    
752        /*TH2F* q0testing = new TH2F();
753          TH2F* q1testing = new TH2F();
754          TH2F* q2testing = new TH2F();
755          TH2F* q3testing = new TH2F();
756          TH2F* Pitchtesting = new TH2F();
757        */
758        UInt_t must = 0;
759    
760      //      //
761      // run over all the events of the run      // run over all the events of the run
762      //      //
763      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");
764      //      //
765        //
766      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){      for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
       
767        //        //
768        if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);          if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);  
769        if ( debug ) printf(" %i \n",procev);              if ( debug ) printf(" %i \n",procev);      
770        //        //
771        l0head->GetEntry(re);        if ( l0head->GetEntry(re) <= 0 ) throw -36;
772        //        //
773        // absolute time of this event        // absolute time of this event
774        //        //
775        ph = eh->GetPscuHeader();        ph = eh->GetPscuHeader();
776        atime = dbtime->DBabsTime(ph->GetOrbitalTime());        atime = dbtime->DBabsTime(ph->GetOrbitalTime());
777          if ( debug ) printf(" %i absolute time \n",procev);      
778        //        //
779        // paranoid check        // paranoid check
780        //        //
781        if ( (atime > runinfo->RUNTRAILER_TIME) || (atime < runinfo->RUNHEADER_TIME)  ) {        if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1))  ) {
782          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");
783  //      debug = true;          jumped++;
784            //      debug = true;
785          continue;          continue;
786        }        }
787    
788          //
789          // retrieve tof informations
790          //
791          if ( !reprocall ){
792            itr = nobefrun + (re - evfrom - jumped);
793            //itr = re-(46438+200241);
794          } else {
795            itr = runinfo->GetFirstEntry() + (re - evfrom - jumped);
796          };
797          //
798          if ( !standalone ){
799            if ( itr > nevtofl2 ){  
800              if ( verbose ) printf(" OrbitalInfo - ERROR: no tof events with entry = %i in Level2 file\n",itr);
801              if ( debug ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
802              l0File->Close();
803              code = -901;
804              goto closeandexit;
805            };
806            //
807            tof->Clear();
808            //
809            if ( ttof->GetEntry(itr) <= 0 ) throw -36;
810            //
811          };
812        //        //
813        procev++;        procev++;
814        //        //
815        // start processing        // start processing
816        //        //
817          if ( debug ) printf(" %i start processing \n",procev);      
818        orbitalinfo->Clear();        orbitalinfo->Clear();
819        //        //
820          OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
821          if( !(orbitalinfo->OrbitalInfoTrk) ) orbitalinfo->OrbitalInfoTrk = new TClonesArray("OrbitalInfoTrkVar",2);
822          TClonesArray &tor = *orbitalinfo->OrbitalInfoTrk;
823          //
824        // Fill OBT, pkt_num and absTime        // Fill OBT, pkt_num and absTime
825        //              //      
       //      ph = eh->GetPscuHeader();  
826        orbitalinfo->pkt_num = ph->GetCounter();        orbitalinfo->pkt_num = ph->GetCounter();
827        orbitalinfo->OBT = ph->GetOrbitalTime();        orbitalinfo->OBT = ph->GetOrbitalTime();
828        orbitalinfo->absTime = atime;        orbitalinfo->absTime = atime;
829          if ( debug ) printf(" %i pktnum obt abstime \n",procev);      
830        //        //
831        // 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.
832        //        //
833          if ( debug ) printf(" %i sgp4 \n",procev);      
834        cCoordGeo coo;        cCoordGeo coo;
835        float jyear=0;            Float_t jyear=0.;    
836        //        //
837        if(atime >= gltle->GetToTime()) {        if(atime >= gltle->GetToTime()) {
838          if ( !gltle->Query(atime, dbc) ){          if ( !gltle->Query(atime, dbc) ){
839            //                  //      
840            // Compute the magnetic dipole moment.            // Compute the magnetic dipole moment.
841            //            //
842              if ( debug ) printf(" %i compute magnetic dipole moment \n",procev);      
843            UInt_t year, month, day, hour, min, sec;            UInt_t year, month, day, hour, min, sec;
844            //            //
845            TTimeStamp t = TTimeStamp(atime, kTRUE);            TTimeStamp t = TTimeStamp(atime, kTRUE);
# Line 601  int OrbitalInfoCore(UInt_t run, TFile *f Line 847  int OrbitalInfoCore(UInt_t run, TFile *f
847            t.GetTime(kTRUE, 0, &hour, &min, &sec);            t.GetTime(kTRUE, 0, &hour, &min, &sec);
848            jyear = (float) year            jyear = (float) year
849              + (month*31.+ (float) day)/365.              + (month*31.+ (float) day)/365.
850              + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);              + (hour*3600.+min*60.+(float)sec)/(24.*3600.*365.);
851            //            //
852              if ( debug ) printf(" %i compute magnetic dipole moment get dipole moment for year\n",procev);      
853            feldcof_(&jyear, &dimo); // get dipole moment for year            feldcof_(&jyear, &dimo); // get dipole moment for year
854              if ( debug ) printf(" %i compute magnetic dipole moment end\n",procev);      
855          } else {          } else {
856            code = -56;            code = -56;
857            goto closeandexit;            goto closeandexit;
# Line 618  int OrbitalInfoCore(UInt_t run, TFile *f Line 866  int OrbitalInfoCore(UInt_t run, TFile *f
866        // synchronize with quaternions data        // synchronize with quaternions data
867        //        //
868        if ( isf && neventsm>0 ){        if ( isf && neventsm>0 ){
         if ( debug ) printf(" I am here \n");  
869          //          //
870          // First event          // First event
871          //          //
872          isf = false;          isf = false;
873          upperqtime = atime;          upperqtime = atime;
874          lowerqtime = runinfo->RUNHEADER_TIME;          lowerqtime = runinfo->RUNHEADER_TIME;
875          for ( ik = 0; ik < neventsm; ik++){          for ( ik = 0; ik < neventsm; ik++){  //number of macrocommad packets
876            l0trm->GetEntry(ik);            if ( ch->GetEntry(ik) <= 0 ) throw -36;
877            tmpSize = mcmdev->Records->GetEntries();            tmpSize = mcmdev->Records->GetEntries();
878            numrec = tmpSize;            numrec = tmpSize;
879            for (Int_t j3 = 0;j3<tmpSize;j3++){            for (Int_t j3 = 0;j3<tmpSize;j3++){  //number of subpackets
880                if ( debug ) printf(" ik %i j3 %i eh eh eh \n",ik,j3);
881              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);              mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
882              if ((int)mcmdrc->ID1 == 226){              if ( mcmdrc ){ // missing inclination bug [8RED 090116]
883                L_QQ_Q_l_upper->fill(mcmdrc->McmdData);                if ( debug ) printf(" pluto \n");
884                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
885                  if (ui>0){                  L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
886                    if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){                  for (UInt_t ui = 0; ui < 6; ui++){
887                      if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){                    if (ui>0){
888                        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]){
889                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          if ( debug ) printf(" here1 %i \n",ui);
890                        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));
891                      }else {                        Int_t recSize = recqtime.size();
892                        lowerqtime = upperqtime;                        for(Int_t mu = nt;mu<recSize;mu++){
893                        upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));                          if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
894                        orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                            nt=mu;
895                        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();
896                        mcreen = j3;                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
897                        mctren = ik;                            qtime[sizeqmcmd]=recqtime[mu];
898                        if(fgh==0){                            q0[sizeqmcmd]=recq0[mu];
899                          CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                            q1[sizeqmcmd]=recq1[mu];
900                          CopyAng(RYPang_lower,RYPang_upper);                            q2[sizeqmcmd]=recq2[mu];
901                              q3[sizeqmcmd]=recq3[mu];
902                              qmode[sizeqmcmd]=-10;
903                              orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
904                              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]);
905                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
906                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
907                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
908                            }
909                            if(recqtime[mu]>=u_time){
910                              Int_t sizeqmcmd = qtime.size();
911                              inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
912                              qtime[sizeqmcmd]=u_time;
913                              q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
914                              q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
915                              q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
916                              q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
917                              qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
918                              lowerqtime = u_time;
919                              orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
920                              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]);
921                              qRoll[sizeqmcmd]=RYPang_upper->Kren;
922                              qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
923                              qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
924                              break;
925                            }
926                        }                        }
                       oi=ui;  
                       goto closethisloop;  
927                      }                      }
928                      fgh++;                    }else{
929                      CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          if ( debug ) printf(" here2 %i \n",ui);
930                      CopyAng(RYPang_lower,RYPang_upper);                      Double_t u_time = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
931                    }                      if(lowerqtime>u_time)nt=0;
932                  }else{                      Int_t recSize = recqtime.size();
933                    if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){                      for(Int_t mu = nt;mu<recSize;mu++){
934                      upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                        if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
935                      orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          nt=mu;
936                      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();
937                    }                          inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
938                    else {                          qtime[sizeqmcmd]=recqtime[mu];
939                      lowerqtime = upperqtime;                          q0[sizeqmcmd]=recq0[mu];
940                      upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));                          q1[sizeqmcmd]=recq1[mu];
941                      orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);                          q2[sizeqmcmd]=recq2[mu];
942                      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];
943                      mcreen = j3;                          qmode[sizeqmcmd]=-10;
944                      mctren = ik;                          orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
945                      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]);
946                        CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);                          qRoll[sizeqmcmd]=RYPang_upper->Kren;
947                        CopyAng(RYPang_lower,RYPang_upper);                          qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
948                        lowerqtime = atime-1;                          qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
949                          }
950                          if(recqtime[mu]>=u_time){
951                            Int_t sizeqmcmd = qtime.size();
952                            inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
953                            qtime[sizeqmcmd]=u_time;
954                            q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
955                            q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
956                            q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
957                            q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
958                            qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
959                            lowerqtime = u_time;
960                            orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
961                            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]);
962                            qRoll[sizeqmcmd]=RYPang_upper->Kren;
963                            qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
964                            qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
965                            CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
966                            break;
967                          }
968                      }                      }
                     oi=ui;  
                     goto closethisloop;  
                     //_0 = true;  
969                    }                    }
970                    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;  
         UInt_t maxloop = 100000000;      
         UInt_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;  
           };  
           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]);  
971                }                }
               //              re--;  
               gh=true;  
972              }              }
973            }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));  
974            }            }
975            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));  
976                    
977                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){
978                orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));              for(Int_t my=0;my<recqtime.size();my++){
979                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();
980                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);
981                //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];
982                //cin>>grib;                  q0[sizeqmcmd]=recq0[my];
983                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];
984                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];
985                    q3[sizeqmcmd]=recq3[my];
986                    qmode[sizeqmcmd]=-10;
987                    orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
988                    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]);
989                    qRoll[sizeqmcmd]=RYPang_upper->Kren;
990                    qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
991                    qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
992              }              }
993            }          }
         } 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));  
994                    
995              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");
996              orbitalinfo->theta =  incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));          sineparam(q0sine,qtime,q0,qRoll,qPitch,0.60);
997              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(q1sine,qtime,q1,qRoll,qPitch,0.82);
998              orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));          sineparam(q2sine,qtime,q2,qRoll,qPitch,0.82);
999              //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(q3sine,qtime,q3,qRoll,qPitch,0.60);
1000              //cin>>grib;          sineparam(Yawsine,qtime,qYaw,qRoll,qPitch,4);
1001              incli = (RYPang_upper->Kren-RYPang_lower->Kren)/(dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000))-dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi-1]*1000-DeltaOBT*1000)));          if ( debug ) printf(" puffi \n");
1002              orbitalinfo->etha =  incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));          Double_t tmin = 9999999999.;
1003            }          Double_t tmax = 0.;
1004            if (tut==6){          for(UInt_t tre = 0;tre<qtime.size();tre++){
1005              if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){            if(qtime[tre]>tmax)tmax = qtime[tre];
1006                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)));            if(qtime[tre]<tmin)tmin = qtime[tre];
1007                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));          }
1008                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 ( debug ) printf(" gnfuffi \n");
1009                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));  
1010                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)));          //q0testing->SetName("q0testing");
1011                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));          //q1testing->SetName("q1testing");
1012                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)));          //q2testing->SetName("q2testing");
1013                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));          //q3testing->SetName("q3testing");
1014                    
1015                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);
1016                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.);
1017                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.);
1018                orbitalinfo->phi =  incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));  
1019                //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++){
1020                //cin>>grib;            //cout<<"q0["<<tre<<" = "<<q0[tre]<<endl;
1021                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]);
1022                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]);
1023              //Pitchtesting->Fill(qtime[tre],qPitch[tre],100);
1024              //if(qmode[tre] == -10)Pitchtesting->Fill(qtime[tre],10,100);
1025              //q2testing->Fill(qtime[tre],q2[tre],100);
1026              //q3testing->Fill(qtime[tre],q3[tre],100);
1027    //      }
1028            
1029            //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;
1030            //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;
1031          } // if we processed first event
1032          
1033          //Filling Inclination information
1034          Double_t incli = 0;
1035          if ( qtime.size() > 1 ){
1036          for(UInt_t mu = must;mu<qtime.size()-1;mu++){
1037            if ( debug ) printf(" ??grfuffi %i sixe %i must %i \n",mu,qtime.size()-1,must);
1038            if(qtime[mu+1]>qtime[mu]){
1039              if ( debug ) printf(" grfuffi2 %i \n",mu);
1040              if(atime<=qtime[mu+1] && atime>=qtime[mu]){
1041                must = mu;
1042                incli = (qPitch[mu+1]-qPitch[mu])/(qtime[mu+1]-qtime[mu]);
1043                orbitalinfo->theta =  incli*atime+qPitch[mu+1]-incli*qtime[mu+1];
1044                incli = (qRoll[mu+1]-qRoll[mu])/(qtime[mu+1]-qtime[mu]);
1045                orbitalinfo->etha =  incli*atime+qRoll[mu+1]-incli*qtime[mu+1];
1046                incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1047                orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1048                
1049                incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1050                orbitalinfo->q0t =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1051                incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1052                orbitalinfo->q1t =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1053                incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1054                orbitalinfo->q2t =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1055                incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1056                orbitalinfo->q3t =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1057                
1058                orbitalinfo->TimeGap = qtime[mu+1]-qtime[mu];
1059                orbitalinfo->mode = qmode[mu+1];
1060                if(qmode[mu+1]==-10) orbitalinfo->R10r = true;else orbitalinfo->R10r = false;
1061                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){
1062                  //linear interpolation
1063                  incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1064                  orbitalinfo->q0 =  incli*atime+q0[mu+1]-incli*qtime[mu+1];
1065                  incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1066                  orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1067                  incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1068                  orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1069                  incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1070                  orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1071                }else{
1072                  //sine interpolation
1073                  for(UInt_t mt=0;mt<q0sine.size();mt++){
1074                    if(atime<=q0sine[mt].finishPoint && atime>=q0sine[mt].startPoint){
1075                      if(!q0sine[mt].NeedFit)orbitalinfo->q0=q0sine[mt].A*sin(q0sine[mt].b*atime+q0sine[mt].c);else{
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                      }
1079                    }
1080                    if(atime<=q1sine[mt].finishPoint && atime>=q1sine[mt].startPoint){
1081                      if(!q1sine[mt].NeedFit)orbitalinfo->q1=q1sine[mt].A*sin(q1sine[mt].b*atime+q1sine[mt].c);else{
1082                        incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1083                        orbitalinfo->q1 =  incli*atime+q1[mu+1]-incli*qtime[mu+1];
1084                      }
1085                    }
1086                    if(atime<=q2sine[mt].finishPoint && atime>=q2sine[mt].startPoint){
1087                      if(!q2sine[mt].NeedFit)orbitalinfo->q2=q0sine[mt].A*sin(q2sine[mt].b*atime+q2sine[mt].c);else{
1088                        incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1089                        orbitalinfo->q2 =  incli*atime+q2[mu+1]-incli*qtime[mu+1];
1090                      }
1091                    }
1092                    if(atime<=q3sine[mt].finishPoint && atime>=q3sine[mt].startPoint){
1093                      if(!q3sine[mt].NeedFit)orbitalinfo->q3=q0sine[mt].A*sin(q3sine[mt].b*atime+q3sine[mt].c);else{
1094                        incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1095                        orbitalinfo->q3 =  incli*atime+q3[mu+1]-incli*qtime[mu+1];
1096                      }
1097                    }
1098                    if(atime<=Yawsine[mt].finishPoint && atime>=Yawsine[mt].startPoint){
1099                      if(!Yawsine[mt].NeedFit)orbitalinfo->phi=Yawsine[mt].A*sin(Yawsine[mt].b*atime+Yawsine[mt].c);else{
1100                        incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1101                        orbitalinfo->phi =  incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1102                      }
1103                    }
1104                  }
1105              }              }
1106            }                          //q0testing->Fill(atime,orbitalinfo->q0,100);
1107                //q1testing->Fill(atime,orbitalinfo->q1,100);
1108                //Pitchtesting->Fill(atime,orbitalinfo->etha);
1109                //q2testing->Fill(atime,orbitalinfo->q2);
1110                //q3testing->Fill(atime,orbitalinfo->q3);
1111                break;
1112              }
1113          }          }
1114          //        }
1115          orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);        }
1116          //        //
1117        } else {        // ops no inclination information
1118          if ( debug ) printf(" ops no incl! \n");        //
1119          orbitalinfo->mode = -1;  
1120          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 ){
1121            orbitalinfo->mode = 10;
1122            orbitalinfo->q0 = -1000.;
1123            orbitalinfo->q1 = -1000.;
1124            orbitalinfo->q2 = -1000.;
1125            orbitalinfo->q3 = -1000.;
1126            orbitalinfo->etha = -1000.;
1127            orbitalinfo->phi = -1000.;
1128            orbitalinfo->theta = -1000.;
1129        };        };
1130            //
1131          // #########################################################################################################################  
1132        //        //
1133        // fill orbital positions        // fill orbital positions
1134        //                //        
# Line 877  int OrbitalInfoCore(UInt_t run, TFile *f Line 1158  int OrbitalInfoCore(UInt_t run, TFile *f
1158          orbitalinfo->BB0 = babs/bequ;          orbitalinfo->BB0 = babs/bequ;
1159          orbitalinfo->L = xl;                orbitalinfo->L = xl;      
1160          // Set Stormer vertical cutoff using L shell.          // Set Stormer vertical cutoff using L shell.
1161          orbitalinfo->cutoff[0] = 14.9/(xl*xl);          orbitalinfo->cutoffsvl = 14.9/(xl*xl);
1162          //          //
1163        };              };      
1164        //        //
1165          if ( debug ) printf(" pitch angle \n");
1166          //
1167          // pitch angles
1168          //
1169          if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){
1170            //
1171            Float_t Bx = -orbitalinfo->Bdown;                       //don't need for PamExp ExpOnly for all geography areas
1172            Float_t By = orbitalinfo->Beast;                        //don't need for PamExp ExpOnly for all geography areas
1173            Float_t Bz = orbitalinfo->Bnorth;                       //don't need for PamExp ExpOnly for all geography areas
1174            //
1175            TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);
1176            TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);
1177            TMatrixD Iij = PO->ColPermutation(Dij);
1178            //
1179            orbitalinfo->Iij.ResizeTo(Iij);
1180            orbitalinfo->Iij = Iij;
1181            //
1182            A1 = Iij(0,2);
1183            A2 = Iij(1,2);
1184            A3 = Iij(2,2);
1185            //      
1186            //      orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3);                        // Angle between zenit and Pamela's main axiz
1187            //      orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz);                 // Angle between Pamela's main axiz and B
1188            //
1189            if ( !standalone && tof->ntrk() > 0 ){
1190              //
1191              Int_t nn = 0;
1192              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1193                //
1194                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1195                Double_t E11x = ptt->xtr_tof[0]; // tr->x[0];
1196                Double_t E11y = ptt->ytr_tof[0]; //tr->y[0];
1197                Double_t E11z = zin[0];
1198                Double_t E22x = ptt->xtr_tof[3];//tr->x[3];
1199                Double_t E22y = ptt->ytr_tof[3];//tr->y[3];
1200                Double_t E22z = zin[3];
1201                if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1  ){
1202                  Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1203                  //              Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1204                  //              if(E22x-E11x>=0 && E22y-E11y <0) MyAzim =  360. - MyAzim;
1205                  //              if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1206                  //              if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1207                  //              if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1208                  Px = (E22x-E11x)/norm;
1209                  Py = (E22y-E11y)/norm;
1210                  Pz = (E22z-E11z)/norm;
1211                  //
1212                  t_orb->trkseqno = ptt->trkseqno;
1213                  //
1214                  TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);
1215                  t_orb->Eij.ResizeTo(Eij);
1216                  t_orb->Eij = Eij;
1217                  //
1218                  TMatrixD Sij = PO->PamelatoGEO(Fij,Px,Py,Pz);
1219                  t_orb->Sij.ResizeTo(Sij);
1220                  t_orb->Sij = Sij;
1221                  //            
1222                  t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);
1223                  //
1224                  //
1225                  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);
1226                  //
1227                  t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1228                  //
1229                  if ( t_orb->pitch != t_orb->pitch ) t_orb->pitch = -1000.;
1230                  if ( t_orb->cutoff != t_orb->cutoff ) t_orb->cutoff = -1000.;
1231                  //
1232                  if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1233                  //
1234                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1235                  nn++;
1236                  //
1237                  t_orb->Clear();
1238                  //
1239                };
1240                //
1241              };
1242            } else {
1243              if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());
1244            };
1245            //
1246          } else {
1247            if ( !standalone && tof->ntrk() > 0 ){
1248              //
1249              Int_t nn = 0;
1250              for(Int_t nt=0; nt < tof->ntrk(); nt++){  
1251                //
1252                ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1253                if ( ptt->trkseqno != -1  ){
1254                  //
1255                  t_orb->trkseqno = ptt->trkseqno;
1256                  //
1257                  t_orb->Eij = 0;  
1258                  //
1259                  t_orb->Sij = 0;
1260                  //            
1261                  t_orb->pitch = -1000.;
1262                  //
1263                  t_orb->cutoff = -1000.;
1264                  //
1265                  new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1266                  nn++;
1267                  //
1268                  t_orb->Clear();
1269                  //
1270                };
1271                //
1272              };    
1273            };
1274          };
1275          //
1276        // Fill the class        // Fill the class
1277        //        //
1278        OrbitalInfotr->Fill();        OrbitalInfotr->Fill();
1279        //        //
1280          delete t_orb;
1281          //
1282      }; // loop over the events in the run      }; // loop over the events in the run
1283      //      //
1284      // Here you may want to clear some variables before processing another run        // Here you may want to clear some variables before processing another run  
1285      //      //
1286    
1287        //gStyle->SetOptStat(000000);
1288        //gStyle->SetPalette(1);
1289        
1290        /*TCanvas* c1 = new TCanvas("c1","",1200,800);
1291        //c1->Divide(1,4);
1292        c1->cd(1);
1293        //q0testing->Draw("colz");
1294        //c1->cd(2);
1295        //q1testing->Draw("colz");
1296        //c1->cd(3);
1297        Pitchtesting->Draw("colz");
1298        //c1->cd(4);
1299        //q3testing->Draw("colz");
1300        c1->SaveAs("9.Rollhyst.png");
1301        delete c1;*/
1302    
1303      delete dbtime;      delete dbtime;
1304      if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;      if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1305      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 913  int OrbitalInfoCore(UInt_t run, TFile *f Line 1324  int OrbitalInfoCore(UInt_t run, TFile *f
1324          //          //
1325          // Get entry from old tree          // Get entry from old tree
1326          //          //
1327          OrbitalInfotrclone->GetEntry(j);                    if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;    
1328          //          //
1329          // copy orbitalinfoclone to OrbitalInfo          // copy orbitalinfoclone to OrbitalInfo
1330          //          //
# Line 933  int OrbitalInfoCore(UInt_t run, TFile *f Line 1344  int OrbitalInfoCore(UInt_t run, TFile *f
1344    //    //
1345    if ( l0File ) l0File->Close();    if ( l0File ) l0File->Close();
1346    if ( tempfile ) tempfile->Close();                if ( tempfile ) tempfile->Close();            
1347    gSystem->Unlink(tempname.str().c_str());    if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1348    //    //
1349    if ( runinfo ) runinfo->Close();        if ( runinfo ) runinfo->Close();    
1350    if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");        if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");    
1351      if ( tof ) tof->Delete();
1352      if ( ttof ) ttof->Delete();
1353      //
1354    if ( file ){    if ( file ){
1355      file->cd();      file->cd();
1356      file->Write();      file->Write();
1357    };    };
1358    //    //
1359    gSystem->Unlink(OrbitalInfofolder.str().c_str());    if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1360    //    //
1361    // the end    // the end
1362    //    //
1363      if ( dbc ){
1364        dbc->Close();
1365        delete dbc;
1366      };
1367    if (verbose) printf("\n Exiting...\n");    if (verbose) printf("\n Exiting...\n");
1368    if(OrbitalInfotr)OrbitalInfotr->Delete();    if(OrbitalInfotr)OrbitalInfotr->Delete();
1369    //    //
1370      if ( PO ) delete PO;
1371    if ( orbitalinfo ) delete orbitalinfo;    if ( orbitalinfo ) delete orbitalinfo;
1372    if ( orbitalinfoclone ) delete orbitalinfoclone;    if ( orbitalinfoclone ) delete orbitalinfoclone;
1373    if ( glroot ) delete glroot;    if ( glroot ) delete glroot;
# Line 997  void CopyAng(InclinationInfo *A1, Inclin Line 1416  void CopyAng(InclinationInfo *A1, Inclin
1416  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){
1417        
1418    UInt_t hole = 10;    UInt_t hole = 10;
1419    bool R10l = false;     // Sign of R10 mode in lower quaternions array    Bool_t R10l = false;     // Sign of R10 mode in lower quaternions array
1420    bool R10u = false;     // Sign of R10 mode in upper quaternions array    Bool_t R10u = false;     // Sign of R10 mode in upper quaternions array
1421    bool insm = false;     // Sign that we inside quaternions array    Bool_t insm = false;     // Sign that we inside quaternions array
1422    bool mxtml = false;    // Sign of mixt mode in lower quaternions array    Bool_t mxtml = false;    // Sign of mixt mode in lower quaternions array
1423    bool mxtmu = false;    // Sign of mixt mode in upper quaternions array    Bool_t mxtmu = false;    // Sign of mixt mode in upper quaternions array
1424    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
1425    UInt_t NCQl = 6;       // Number of correct quaternions in lower array    UInt_t NCQl = 6;       // Number of correct quaternions in lower array
1426    UInt_t NCQu = 6;       // Number of correct quaternions in upper array    UInt_t NCQu = 6;       // Number of correct quaternions in upper array
1427    if (f>0){    if (f>0){
# Line 1045  UInt_t holeq(Double_t lower,Double_t upp Line 1464  UInt_t holeq(Double_t lower,Double_t upp
1464    return hole;    return hole;
1465  }  }
1466    
1467    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){
1468      Int_t sizee = t.size()+1;
1469      t.resize(sizee);
1470      q0.resize(sizee);
1471      q1.resize(sizee);
1472      q2.resize(sizee);
1473      q3.resize(sizee);
1474      mode.resize(sizee);
1475      Roll.resize(sizee);
1476      Pitch.resize(sizee);
1477      Yaw.resize(sizee);
1478    }
1479    
1480    //Find fitting sine functions for q0,q1,q2,q3 and Yaw-angle;
1481    void sineparam(vector<Sine>& qsine, vector<Double_t>& qtime, vector<Float_t>& q, vector<Float_t>& Roll, vector<Float_t>& Pitch, Float_t limsin){
1482      UInt_t mulast = 0;
1483      UInt_t munow = 0;
1484      UInt_t munext = 0;
1485      Bool_t increase = false;
1486      Bool_t decrease = false;
1487      Bool_t Max_is_defined = false;
1488      Bool_t Start_point_is_defined = false;
1489      Bool_t Period_is_defined = false;
1490      Bool_t Large_gap = false;
1491      Bool_t normal_way = true;
1492      Bool_t small_gap_on_ridge = false;
1493      Double_t t1 = 0;
1494      Double_t t1A = 0;
1495      Int_t sinesize = 0;
1496      Int_t nfi = 0;
1497      for(UInt_t mu = 0;mu<qtime.size();mu++){
1498        //cout<<"Roll["<<mu<<"] = "<<Roll[mu]<<endl;
1499        if(TMath::Abs(Roll[mu])<1. && TMath::Abs(Pitch[mu])<1. && TMath::Abs(q[mu])<limsin){
1500        //cout<<"q["<<mu<<endl<<"] = "<<q[mu]<<endl;
1501        if(mulast!=0 && munow!=0 && munext!=0){mulast=munow;munow=munext;munext=mu;}
1502        if(munext==0 && munow!=0)munext=mu;
1503        if(munow==0 && mulast!=0)munow=mu;
1504        if(mulast==0)mulast=mu;
1505        
1506        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1507        //Int_t ref;
1508        //cin>>ref;
1509        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;
1510        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;
1511        //if(normal_way)cout<<"Normal_Way"<<endl;
1512        if(Large_gap || small_gap_on_ridge){
1513          //cout<<"Large gap..."<<endl;
1514          //if(small_gap_on_ridge)cout<<"small gap..."<<endl;
1515          //cout<<"q["<<mulast<<"] = "<<q[mulast]<<"\tq["<<munow<<"] = "<<q[munow]<<"\tq["<<munext<<"] = "<<q[munext]<<endl;
1516          //cout<<"qtime["<<mulast<<"] = "<<qtime[mulast]<<"\tqtime["<<munow<<"] = "<<qtime[munow]<<"\tqtime["<<munext<<"] = "<<qtime[munext]<<endl;
1517          increase = false;
1518          decrease = false;
1519          if(nfi>0){
1520            qsine.resize(qsine.size()-1);
1521            sinesize = qsine.size();
1522            //cout<<"nfi was larger then zero"<<endl;
1523          }else{
1524            //cout<<"nfi was not larger then zero :( nfi = "<<nfi<<endl;
1525            //cout<<"qsine.size = "<<qsine.size()<<endl;
1526            if(!Period_is_defined){
1527              //cout<<"Period was defined"<<endl;
1528              if(qsine.size()>1){
1529                qsine[sinesize-1].b = qsine[sinesize-2].b;
1530                qsine[sinesize-1].c = qsine[sinesize-2].c;
1531              }else{
1532                qsine[sinesize-1].b = TMath::Pi()/1591.54;
1533                qsine[sinesize-1].c = qsine[sinesize-1].startPoint;
1534              }
1535            }
1536            if(!Max_is_defined){
1537              //cout<<"Max was already defined"<<endl;
1538              if(qsine.size()>1)qsine[sinesize-1].A = qsine[sinesize-2].A;else qsine[sinesize-1].A = limsin;
1539            }
1540            qsine[sinesize-1].NeedFit = true;
1541          }
1542          qsine[sinesize-1].finishPoint = qtime[munow];
1543          //cout<<"finish point before large gap = "<<qtime[munow]<<endl;
1544          nfi = 0;
1545          Max_is_defined = false;
1546          Start_point_is_defined = false;
1547          Period_is_defined = false;
1548          small_gap_on_ridge = false;
1549        }
1550        //cout<<"Slope "<<increase<<"\t"<<decrease<<endl;
1551        //cout<<"mulast = "<<mulast<<"\tmunow = "<<munow<<"\tmunext = "<<munext<<endl;
1552        if((munext>munow) && (munow>mulast) && normal_way){
1553          if(!increase && !decrease){
1554            //cout<<"Normal way have started"<<endl;
1555            qsine.resize(qsine.size()+1);
1556            sinesize = qsine.size();
1557            qsine[sinesize-1].startPoint=qtime[mulast];
1558            if(q[munext]>q[munow] && q[munow]>q[mulast]) increase = true;
1559            if(q[munext]<q[munow] && q[munow]<q[mulast]) decrease = true;
1560          }
1561          //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;}
1562          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){
1563            //cout<<"Max point is qtime = "<<qtime[munow]<<"\tq = "<<q[munow]<<endl;
1564            if(q[munow]>q[mulast]){
1565              increase = false;
1566              decrease = true;
1567            }
1568            if(q[munow]<q[mulast]){
1569              increase = true;
1570              decrease = false;
1571            }
1572            if(Max_is_defined && !Start_point_is_defined){
1573              Double_t qPer = qtime[munow]-t1A;
1574              if(qPer>1000){
1575                //cout<<"qsine["<<sinesize-1<<"] = "<<qPer<<" = "<<qtime[munow]<<" - "<<t1A<<"\tlim = "<<limsin<<endl;
1576                qsine[sinesize-1].b=TMath::Pi()/qPer;
1577                if(decrease)qsine[sinesize-1].c=-qsine[sinesize-1].b*t1A;
1578                if(increase)qsine[sinesize-1].c=-qsine[sinesize-1].b*(t1A-qPer);
1579                Period_is_defined = true;
1580              }
1581            }
1582            Max_is_defined = true;
1583            qsine[sinesize-1].A = TMath::Abs(q[munow]);
1584            if(Start_point_is_defined && Period_is_defined){
1585              qsine[sinesize-1].finishPoint = qtime[munow];
1586              nfi++;
1587              qsine[sinesize-1].NeedFit = false;
1588              Max_is_defined = false;
1589              Start_point_is_defined = false;
1590              Period_is_defined = false;
1591              qsine.resize(qsine.size()+1);
1592              sinesize = qsine.size();
1593              qsine[sinesize-1].startPoint = qtime[munow];
1594            }
1595            if(!Start_point_is_defined) t1A=qtime[munow];
1596          }
1597          //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;
1598          if(((q[munow]>=0 && q[mulast]<=0) || (q[munow]<=0 && q[mulast]>=0)) && qtime[munow]-qtime[mulast]<2000 && qtime[munext]-qtime[munow]<2000){
1599            Double_t tcrosszero = 0;
1600            //cout<<"cross zero point...qtime = "<<qtime[munow]<<endl;
1601            if(q[munow]==0.) tcrosszero = qtime[munow];else
1602              if(q[mulast]==0.)tcrosszero = qtime[mulast];else{
1603                Double_t k_ = (q[munow]-q[mulast])/(qtime[munow]-qtime[mulast]);
1604                Double_t b_ = q[munow]-k_*qtime[munow];
1605                tcrosszero = -b_/k_;
1606              }
1607            if(Start_point_is_defined){
1608              //cout<<"Start Point allready defined"<<endl;
1609              Double_t qPer = tcrosszero - t1;
1610              qsine[sinesize-1].b = TMath::Pi()/qPer;
1611              //cout<<"qsine["<<sinesize-1<<"].b = "<<TMath::Pi()/qPer<<endl;
1612              Period_is_defined = true;
1613              Float_t x0 = 0;
1614              if(decrease)x0 = t1;
1615              if(increase)x0 = tcrosszero;
1616              qsine[sinesize-1].c = -qsine[sinesize-1].b*x0;
1617              if(Max_is_defined){
1618                //cout<<"Max was previous defined"<<endl;
1619                qsine[sinesize-1].finishPoint = qtime[munow];
1620                nfi++;
1621                qsine[sinesize-1].NeedFit = false;
1622                Max_is_defined = false;
1623                t1 = tcrosszero;
1624                Start_point_is_defined = true;
1625                Period_is_defined = false;
1626                qsine.resize(qsine.size()+1);
1627                sinesize = qsine.size();
1628                qsine[sinesize-1].startPoint = qtime[munow];
1629              }
1630            }else{
1631              t1 = tcrosszero;
1632              Start_point_is_defined = true;
1633            }
1634          }
1635        }
1636        }
1637      }
1638    
1639      //cout<<"FINISH SINE INTERPOLATION FUNCTION..."<<endl<<endl;
1640    }

Legend:
Removed from v.1.19  
changed lines
  Added in v.1.47

  ViewVC Help
Powered by ViewVC 1.1.23