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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.34 - (hide annotations) (download)
Fri Nov 28 09:05:21 2008 UTC (16 years, 3 months ago) by mocchiut
Branch: MAIN
Changes since 1.33: +1 -1 lines
Event loss due to timesync bug fixed + ToF dE/dx II order correction implemented

1 mocchiut 1.1 //
2     // C/C++ headers
3     //
4     #include <fstream>
5     #include <string.h>
6     #include <iostream>
7     #include <cstring>
8     #include <stdio.h>
9     //
10     // ROOT headers
11     //
12     #include <TTree.h>
13     #include <TClassEdit.h>
14     #include <TObject.h>
15     #include <TList.h>
16 mocchiut 1.5 #include <TArrayI.h>
17 mocchiut 1.1 #include <TSystem.h>
18     #include <TSystemDirectory.h>
19     #include <TString.h>
20     #include <TFile.h>
21     #include <TClass.h>
22     #include <TSQLServer.h>
23     #include <TSQLRow.h>
24     #include <TSQLResult.h>
25     //
26 mocchiut 1.8 // RunInfo header
27     //
28     #include <RunInfo.h>
29     #include <GLTables.h>
30     //
31 mocchiut 1.1 // YODA headers
32     //
33     #include <PamelaRun.h>
34     #include <PscuHeader.h>
35     #include <PscuEvent.h>
36     #include <EventHeader.h>
37 mocchiut 1.15 #include <mcmd/McmdEvent.h>
38     #include <mcmd/McmdRecord.h>
39 mocchiut 1.1 //
40     // This program headers
41     //
42     #include <OrbitalInfo.h>
43 mocchiut 1.7 #include <OrbitalInfoVerl2.h>
44 mocchiut 1.1 #include <OrbitalInfoCore.h>
45 mocchiut 1.15 #include <InclinationInfo.h>
46 mocchiut 1.1
47     using namespace std;
48    
49     //
50     // CORE ROUTINE
51     //
52     //
53 mocchiut 1.25 int OrbitalInfoCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){
54 mocchiut 1.15 //
55 mocchiut 1.1 Int_t i = 0;
56 mocchiut 1.25 TString host = glt->CGetHost();
57     TString user = glt->CGetUser();
58     TString psw = glt->CGetPsw();
59     TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
60 mocchiut 1.1 //
61 mocchiut 1.26 stringstream myquery;
62     myquery.str("");
63     myquery << "SET time_zone='+0:00'";
64     dbc->Query(myquery.str().c_str());
65     //
66 mocchiut 1.16 TString processFolder = Form("OrbitalInfoFolder_%u",run);
67 mocchiut 1.1 //
68     // Set these to true to have a very verbose output.
69     //
70     Bool_t debug = false;
71     //
72     Bool_t verbose = false;
73 mocchiut 1.30 //
74 mocchiut 1.31 Bool_t standalone = false;
75 mocchiut 1.30 //
76 mocchiut 1.1 if ( OrbitalInfoargc > 0 ){
77     i = 0;
78     while ( i < OrbitalInfoargc ){
79     if ( !strcmp(OrbitalInfoargv[i],"-processFolder") ) {
80     if ( OrbitalInfoargc < i+1 ){
81     throw -3;
82     };
83     processFolder = (TString)OrbitalInfoargv[i+1];
84     i++;
85     };
86     if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {
87     verbose = true;
88 mocchiut 1.15 debug = true;
89 mocchiut 1.1 };
90     if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {
91     verbose = true;
92     };
93 mocchiut 1.30 if ( (!strcmp(OrbitalInfoargv[i],"--standalone")) ) {
94     standalone = true;
95     };
96     if ( (!strcmp(OrbitalInfoargv[i],"--calculate-pitch")) ) {
97     standalone = false;
98     };
99 mocchiut 1.1 i++;
100     };
101     };
102     //
103     const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath()));
104     //
105     TTree *OrbitalInfotr = 0;
106 mocchiut 1.5 UInt_t nevents = 0;
107 mocchiut 1.15 UInt_t neventsm = 0;
108 mocchiut 1.1 //
109     // variables needed to reprocess data
110     //
111 mocchiut 1.6 Long64_t maxsize = 10000000000LL;
112     TTree::SetMaxTreeSize(maxsize);
113     //
114 mocchiut 1.1 TString OrbitalInfoversion;
115     ItoRunInfo *runinfo = 0;
116 mocchiut 1.5 TArrayI *runlist = 0;
117 mocchiut 1.1 TTree *OrbitalInfotrclone = 0;
118     Bool_t reproc = false;
119     Bool_t reprocall = false;
120     UInt_t nobefrun = 0;
121     UInt_t noaftrun = 0;
122     UInt_t numbofrun = 0;
123     stringstream ftmpname;
124     TString fname;
125 mocchiut 1.5 UInt_t totfileentries = 0;
126 mocchiut 1.15 UInt_t idRun = 0;
127     //
128     // My variables. Vitaly.
129     //
130     // UInt_t iev = 0;
131     // UInt_t j3 = 0;
132     UInt_t oi = 0;
133     Int_t tmpSize = 0;
134 mocchiut 1.1 //
135     // variables needed to handle error signals
136     //
137     Int_t code = 0;
138     Int_t sgnl;
139     //
140     // OrbitalInfo classes
141     //
142     OrbitalInfo *orbitalinfo = new OrbitalInfo();
143     OrbitalInfo *orbitalinfoclone = new OrbitalInfo();
144     //
145     // define variables for opening and reading level0 file
146     //
147     TFile *l0File = 0;
148     TTree *l0tr = 0;
149 mocchiut 1.15 TTree *l0trm = 0;
150 mocchiut 1.2 // EM: open also header branch
151     TBranch *l0head = 0;
152     pamela::EventHeader *eh = 0;
153     pamela::PscuHeader *ph = 0;
154 mocchiut 1.15 pamela::McmdEvent *mcmdev = 0;
155     pamela::McmdRecord *mcmdrc = 0;
156 mocchiut 1.2 // end EM
157 mocchiut 1.15
158     // pamela::RunHeaderEvent *reh = new pamela::RunHeaderEvent;
159     // pamela::EventHeader *eH = new pamela::EventHeader;
160    
161 mocchiut 1.1 //
162     // Define other basic variables
163     //
164     UInt_t procev = 0;
165     stringstream file2;
166     stringstream file3;
167     stringstream qy;
168     Int_t totevent = 0;
169 mocchiut 1.5 UInt_t atime = 0;
170     UInt_t re = 0;
171 mocchiut 1.15 UInt_t ik = 0;
172 mocchiut 1.7
173     // Position
174     Float_t lon, lat, alt;
175    
176     //
177     // IGRF stuff
178     //
179     float dimo = 0.0; // dipole moment (computed from dat files)
180     float bnorth, beast, bdown, babs;
181     float xl; // L value
182     float icode; // code value for L accuracy (see fortran code)
183     float bab1; // What's the difference with babs?
184     float stps = 0.005; // step size for field line tracing
185     float bdel = 0.01; // required accuracy
186     float bequ; // equatorial b value (also called b_0)
187     bool value = 0; // false if bequ is not the minimum b value
188     float rr0; // equatorial radius normalized to earth radius
189    
190 mocchiut 1.1 //
191     // Working filename
192     //
193     TString outputfile;
194     stringstream name;
195     name.str("");
196     name << outDir << "/";
197     //
198     // temporary file and folder
199     //
200     TFile *tempfile = 0;
201     TTree *tempOrbitalInfo = 0;
202     stringstream tempname;
203     stringstream OrbitalInfofolder;
204 mocchiut 1.23 Bool_t myfold = false;
205 mocchiut 1.1 tempname.str("");
206     tempname << outDir;
207     tempname << "/" << processFolder.Data();
208     OrbitalInfofolder.str("");
209     OrbitalInfofolder << tempname.str().c_str();
210     tempname << "/OrbitalInfotree_run";
211     tempname << run << ".root";
212     //
213     // DB classes
214     //
215     GL_ROOT *glroot = new GL_ROOT();
216 mocchiut 1.5 GL_TIMESYNC *dbtime = 0;
217 mocchiut 1.7 GL_TLE *gltle = new GL_TLE();
218 mocchiut 1.15 //
219     //Quaternions classes
220     //
221     Quaternions *L_QQ_Q_l_lower = new Quaternions();
222     InclinationInfo *RYPang_lower = new InclinationInfo();
223     Quaternions *L_QQ_Q_l_upper = new Quaternions();
224     InclinationInfo *RYPang_upper = new InclinationInfo();
225    
226     cEci eCi;
227    
228 mocchiut 1.7 // Initialize fortran routines!!!
229     Int_t ltp2 = 0;
230     Int_t ltp3 = 0;
231     Int_t uno = 1;
232     char *niente = " ";
233     GL_PARAM *glparam = new GL_PARAM();
234 mocchiut 1.10 GL_PARAM *glparam2 = new GL_PARAM();
235 mocchiut 1.7 Int_t parerror=glparam->Query_GL_PARAM(1,301,dbc); // parameters stored in DB in GL_PRAM table
236 mocchiut 1.30 //
237     // Orientation variables
238     //
239     UInt_t evfrom = 0;
240     UInt_t jumped = 0;
241     Int_t itr = -1;
242     Double_t A1;
243     Double_t A2;
244     Double_t A3;
245     Double_t Px = 0;
246     Double_t Py = 0;
247     Double_t Pz = 0;
248     TTree *ttof = 0;
249     ToFLevel2 *tof = new ToFLevel2();
250     OrientationInfo *PO = new OrientationInfo();
251     Int_t nz = 6;
252     Float_t zin[6];
253     Int_t nevtofl2 = 0;
254     //
255 mocchiut 1.7 if ( parerror<0 ) {
256     code = parerror;
257     goto closeandexit;
258     };
259     ltp2 = (Int_t)(glparam->PATH+glparam->NAME).Length();
260     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
261     //
262     parerror=glparam2->Query_GL_PARAM(1,302,dbc); // parameters stored in DB in GL_PRAM table
263     if ( parerror<0 ) {
264     code = parerror;
265     goto closeandexit;
266     };
267     ltp3 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();
268     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
269     //
270     initize_((char *)niente,&uno,(char *)(glparam->PATH+glparam->NAME).Data(),&ltp2,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp3);
271     //
272     // End IGRF stuff//
273     //
274 mocchiut 1.30 for (Int_t ip=0;ip<nz;ip++){
275     zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
276     };
277     //
278     if ( !standalone ){
279     //
280     // Does it contain the Tracker tree?
281     //
282     ttof = (TTree*)file->Get("ToF");
283     if ( !ttof ) {
284     if ( verbose ) printf(" OrbitalInfo - ERROR: no tof tree\n");
285     code = -900;
286     goto closeandexit;
287     };
288     ttof->SetBranchAddress("ToFLevel2",&tof);
289     nevtofl2 = ttof->GetEntries();
290     };
291 mocchiut 1.1 //
292     // Let's start!
293     //
294     // As a first thing we must check what we have to do: if run = 0 we must process all events in the file has been passed
295     // if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file
296     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
297     //
298 mocchiut 1.5 if ( run == 0 ) reproc = true;
299 mocchiut 1.1 //
300     //
301     // Output file is "outputfile"
302     //
303     if ( !file->IsOpen() ){
304     //printf(" OrbitalInfo - ERROR: cannot open file for writing\n");
305     throw -901;
306     };
307     //
308     // Retrieve GL_RUN variables from the level2 file
309     //
310     OrbitalInfoversion = OrbitalInfoInfo(false); // we should decide how to handle versioning system
311     //
312     // create an interface to RunInfo called "runinfo"
313     //
314     runinfo = new ItoRunInfo(file);
315     //
316     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
317     //
318     sgnl = 0;
319     sgnl = runinfo->Update(run, "ORB", OrbitalInfoversion);
320     //sgnl = runinfo->Read(run);
321    
322     if ( sgnl ){
323     //printf("OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");
324     code = sgnl;
325     goto closeandexit;
326     } else {
327     sgnl = 0;
328     };
329     //
330     // number of events in the file BEFORE the first event of our run
331     //
332     nobefrun = runinfo->GetFirstEntry();
333     //
334     // total number of events in the file
335     //
336     totfileentries = runinfo->GetFileEntries();
337     //
338     // first file entry AFTER the last event of our run
339     //
340     noaftrun = runinfo->GetLastEntry() + 1;
341     //
342     // number of run to be processed
343     //
344     numbofrun = runinfo->GetNoRun();
345 mocchiut 1.22 UInt_t totnorun = runinfo->GetRunEntries();
346 mocchiut 1.1 //
347     // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run
348     //
349     OrbitalInfotrclone = (TTree*)file->Get("OrbitalInfo");
350     //
351     if ( !OrbitalInfotrclone ){
352     //
353     // tree does not exist, we are not reprocessing
354     //
355     reproc = false;
356 mocchiut 1.5 if ( run == 0 ){
357 mocchiut 1.1 if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n");
358     }
359 mocchiut 1.5 if ( runinfo->IsReprocessing() && run != 0 ) {
360 mocchiut 1.1 if (verbose) printf(" OrbitalInfo - WARNING: it seems you are not reprocessing data but OrbitalInfo\n versioning information already exists in RunInfo.\n");
361     }
362     } else {
363     //
364     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
365     //
366 mocchiut 1.6 OrbitalInfotrclone->SetAutoSave(900000000000000LL);
367 mocchiut 1.1 reproc = true;
368     //
369     //
370     if (verbose) printf("\n Preparing the pre-processing...\n");
371     //
372 mocchiut 1.22 if ( run == 0 || totnorun == 1 ){
373 mocchiut 1.1 //
374     // we are reprocessing all the file
375     // 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
376     //
377     reprocall = true;
378     //
379     if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n");
380     //
381     } else {
382     //
383     // we are reprocessing a single run, we must copy to the new tree the events in the file which preceed the first event of the run
384     //
385     reprocall = false;
386     //
387 mocchiut 1.5 if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %u \n",run);
388 mocchiut 1.1 //
389     // copying old tree to a new file
390     //
391 mocchiut 1.23 gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
392     myfold = true;
393 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
394     tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
395     tempOrbitalInfo->SetName("OrbitalInfo-old");
396     tempfile->Write();
397     tempfile->Close();
398     }
399     //
400     // Delete the old tree from old file and memory
401     //
402     OrbitalInfotrclone->Delete("all");
403     //
404     if (verbose) printf(" ...done!\n");
405     //
406     };
407     //
408     // create mydetector tree mydect
409     //
410     file->cd();
411     OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");
412 mocchiut 1.6 OrbitalInfotr->SetAutoSave(900000000000000LL);
413 mocchiut 1.30 orbitalinfo->Set();//ELENA **TEMPORANEO?**
414 mocchiut 1.1 OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);
415     //
416     if ( reproc && !reprocall ){
417     //
418     // open new file and retrieve also tree informations
419     //
420     tempfile = new TFile(tempname.str().c_str(),"READ");
421     OrbitalInfotrclone = (TTree*)tempfile->Get("OrbitalInfo-old");
422 mocchiut 1.6 OrbitalInfotrclone->SetAutoSave(900000000000000LL);
423 mocchiut 1.1 OrbitalInfotrclone->SetBranchAddress("OrbitalInfo",&orbitalinfoclone);
424     //
425     if ( nobefrun > 0 ){
426     if (verbose){
427 mocchiut 1.7 printf("\n Pre-processing: copying events from the old tree before the processed run\n");
428     printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
429     printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
430 mocchiut 1.1 }
431     for (UInt_t j = 0; j < nobefrun; j++){
432     //
433     OrbitalInfotrclone->GetEntry(j);
434     //
435     // copy orbitalinfoclone to mydec
436     //
437 mocchiut 1.3 orbitalinfo->Clear();
438 mocchiut 1.5 //
439 mocchiut 1.1 memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
440     //
441     // Fill entry in the new tree
442     //
443     OrbitalInfotr->Fill();
444     //
445     };
446     if (verbose) printf(" Finished successful copying!\n");
447     };
448     };
449     //
450     // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
451     //
452     runlist = runinfo->GetRunList();
453     //
454     // Loop over the run to be processed
455     //
456     for (UInt_t irun=0; irun < numbofrun; irun++){
457     //
458     // retrieve the first run ID to be processed using the RunInfo list
459     //
460 mocchiut 1.15
461 mocchiut 1.1 idRun = runlist->At(irun);
462     if (verbose){
463     printf("\n\n\n ####################################################################### \n");
464     printf(" PROCESSING RUN NUMBER %i \n",(int)idRun);
465     printf(" ####################################################################### \n\n\n");
466     }
467     //
468 mocchiut 1.5 runinfo->ID_ROOT_L0 = 0;
469 mocchiut 1.1 //
470     // store in the runinfo class the GL_RUN variables for our run
471     //
472     sgnl = 0;
473     sgnl = runinfo->GetRunInfo(idRun);
474     if ( sgnl ){
475 mocchiut 1.5 if ( debug ) printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");
476 mocchiut 1.1 code = sgnl;
477     goto closeandexit;
478     } else {
479     sgnl = 0;
480     };
481     //
482     // now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN
483     //
484 mocchiut 1.5 if ( runinfo->ID_ROOT_L0 == 0 ){
485     if ( debug ) printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
486 mocchiut 1.1 code = -5;
487     goto closeandexit;
488     };
489     //
490 mocchiut 1.5 // prepare the timesync for the db
491     //
492     dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
493 mocchiut 1.15
494 mocchiut 1.5 //
495 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
496     //
497 mocchiut 1.5 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
498 mocchiut 1.1 //
499     ftmpname.str("");
500     ftmpname << glroot->PATH.Data() << "/";
501     ftmpname << glroot->NAME.Data();
502     fname = ftmpname.str().c_str();
503 mocchiut 1.15 ftmpname.str("");
504 mocchiut 1.1 //
505     // print out informations
506     //
507 mocchiut 1.5 totevent = runinfo->NEVENTS;
508 mocchiut 1.30 evfrom = runinfo->EV_FROM;
509 mocchiut 1.15 //cout<<"totevents = "<<totevent<<"\n";
510 mocchiut 1.1 if (verbose){
511     printf("\n LEVEL0 data file: %s \n",fname.Data());
512 mocchiut 1.5 printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
513     printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
514 mocchiut 1.15 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);
515 mocchiut 1.1 }//
516 mocchiut 1.27 //
517 mocchiut 1.28 // if ( !totevent ) goto closeandexit;
518 mocchiut 1.1 // Open Level0 file
519     l0File = new TFile(fname.Data());
520     if ( !l0File ) {
521 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");
522 mocchiut 1.1 code = -6;
523     goto closeandexit;
524     };
525     l0tr = (TTree*)l0File->Get("Physics");
526     if ( !l0tr ) {
527 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n");
528 mocchiut 1.1 l0File->Close();
529     code = -7;
530     goto closeandexit;
531     };
532 mocchiut 1.2 // EM: open header branch as well
533     l0head = l0tr->GetBranch("Header");
534     if ( !l0head ) {
535 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Header branch in Level0 tree\n");
536 mocchiut 1.2 l0File->Close();
537     code = -8;
538     goto closeandexit;
539     };
540     l0tr->SetBranchAddress("Header", &eh);
541     // end EM
542 mocchiut 1.5 nevents = l0head->GetEntries();
543 mocchiut 1.1 //
544 mocchiut 1.28 if ( nevents < 1 && totevent ) {
545 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
546 mocchiut 1.1 l0File->Close();
547     code = -11;
548     goto closeandexit;
549     };
550 mocchiut 1.20 //
551 mocchiut 1.28 if ( runinfo->EV_TO > nevents-1 && totevent ) {
552 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");
553 mocchiut 1.1 l0File->Close();
554     code = -12;
555     goto closeandexit;
556     };
557     //
558 mocchiut 1.15 // TTree *tp = (TTree*)l0File->Get("RunHeader");
559     // tp->SetBranchAddress("Header", &eH);
560     // tp->SetBranchAddress("RunHeader", &reh);
561     // tp->GetEntry(0);
562     // ph = eH->GetPscuHeader();
563     // ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
564     // ULong_t ObtSync = reh->OBT_TIME_SYNC;
565     // if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
566     //
567     ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
568     ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
569     ULong_t DeltaOBT = TimeSync - ObtSync;
570    
571     if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
572    
573     l0trm = (TTree*)l0File->Get("Mcmd");
574     neventsm = l0trm->GetEntries();
575 mocchiut 1.18 // neventsm = 0;
576 mocchiut 1.15 //
577     if (neventsm == 0){
578 mocchiut 1.18 if ( debug ) printf("InclinationInfo - WARNING: No quaternions in this File");
579     // l0File->Close();
580     code = 900;
581     // goto closeandexit;
582 mocchiut 1.15 }
583     //
584    
585     l0trm->SetBranchAddress("Mcmd", &mcmdev);
586 mocchiut 1.18 // l0trm->SetBranchAddress("Header", &eh);
587 mocchiut 1.15 //
588     //
589     //
590     UInt_t mctren = 0;
591     UInt_t mcreen = 0;
592     UInt_t numrec = 0;
593     //
594     Double_t upperqtime = 0;
595     Double_t lowerqtime = 0;
596    
597     Double_t incli = 0;
598     oi = 0;
599     UInt_t ooi = 0;
600     //
601     // init quaternions sync
602     //
603     Bool_t isf = true;
604     Int_t fgh = 0;
605     //
606 mocchiut 1.1 // run over all the events of the run
607     //
608     if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n");
609     //
610 mocchiut 1.25 //
611 mocchiut 1.5 for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
612 mocchiut 1.15
613 mocchiut 1.1 //
614 mocchiut 1.5 if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
615 mocchiut 1.15 if ( debug ) printf(" %i \n",procev);
616 mocchiut 1.1 //
617 mocchiut 1.5 l0head->GetEntry(re);
618 mocchiut 1.1 //
619     // absolute time of this event
620     //
621 mocchiut 1.5 ph = eh->GetPscuHeader();
622 mocchiut 1.15 atime = dbtime->DBabsTime(ph->GetOrbitalTime());
623 mocchiut 1.1 //
624     // paranoid check
625     //
626 mocchiut 1.34 if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1)) ) {
627 mocchiut 1.1 if (verbose) printf(" OrbitalInfo - WARNING: event at time outside the run time window, skipping it\n");
628 mocchiut 1.30 jumped++;
629 mocchiut 1.19 // debug = true;
630 mocchiut 1.7 continue;
631     }
632 mocchiut 1.30
633     //
634     // retrieve tof informations
635     //
636     if ( !reprocall ){
637     itr = nobefrun + (re - evfrom - jumped);
638     //itr = re-(46438+200241);
639     } else {
640     itr = runinfo->GetFirstEntry() + (re - evfrom - jumped);
641     };
642     //
643     if ( !standalone ){
644     if ( itr > nevtofl2 ){
645     if ( verbose ) printf(" OrbitalInfo - ERROR: no tof events with entry = %i in Level2 file\n",itr);
646     if ( debug ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
647     l0File->Close();
648     code = -901;
649     goto closeandexit;
650     };
651     //
652     tof->Clear();
653     //
654     ttof->GetEntry(itr);
655     //
656     };
657 mocchiut 1.1 //
658     procev++;
659     //
660     // start processing
661     //
662 mocchiut 1.3 orbitalinfo->Clear();
663 mocchiut 1.5 //
664 mocchiut 1.30 OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
665     if( !(orbitalinfo->OrbitalInfoTrk) ) orbitalinfo->OrbitalInfoTrk = new TClonesArray("OrbitalInfoTrkVar",2);
666     TClonesArray &tor = *orbitalinfo->OrbitalInfoTrk;
667     //
668 mocchiut 1.15 // Fill OBT, pkt_num and absTime
669     //
670 mocchiut 1.2 orbitalinfo->pkt_num = ph->GetCounter();
671     orbitalinfo->OBT = ph->GetOrbitalTime();
672 mocchiut 1.15 orbitalinfo->absTime = atime;
673     //
674     // Propagate the orbit from the tle time to atime, using SGP(D)4.
675     //
676     cCoordGeo coo;
677     float jyear=0;
678 mocchiut 1.7 //
679     if(atime >= gltle->GetToTime()) {
680 mocchiut 1.9 if ( !gltle->Query(atime, dbc) ){
681 mocchiut 1.15 //
682 mocchiut 1.9 // Compute the magnetic dipole moment.
683 mocchiut 1.15 //
684 mocchiut 1.9 UInt_t year, month, day, hour, min, sec;
685 mocchiut 1.15 //
686 mocchiut 1.9 TTimeStamp t = TTimeStamp(atime, kTRUE);
687     t.GetDate(kTRUE, 0, &year, &month, &day);
688     t.GetTime(kTRUE, 0, &hour, &min, &sec);
689     jyear = (float) year
690     + (month*31.+ (float) day)/365.
691     + (hour*3600.+min*60.+(float)sec)/(24*3600*365.);
692 mocchiut 1.15 //
693 mocchiut 1.9 feldcof_(&jyear, &dimo); // get dipole moment for year
694     } else {
695     code = -56;
696     goto closeandexit;
697     };
698 mocchiut 1.7 }
699 mocchiut 1.15 coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());
700     //
701     cOrbit orbits(*gltle->GetTle());
702     //
703 mocchiut 1.18 if ( debug ) printf(" I am Here \n");
704     //
705 mocchiut 1.15 // synchronize with quaternions data
706     //
707 mocchiut 1.18 if ( isf && neventsm>0 ){
708     if ( debug ) printf(" I am here \n");
709 mocchiut 1.15 //
710     // First event
711     //
712     isf = false;
713     upperqtime = atime;
714     lowerqtime = runinfo->RUNHEADER_TIME;
715     for ( ik = 0; ik < neventsm; ik++){
716     l0trm->GetEntry(ik);
717     tmpSize = mcmdev->Records->GetEntries();
718     numrec = tmpSize;
719     for (Int_t j3 = 0;j3<tmpSize;j3++){
720 mocchiut 1.29 if ( debug ) printf(" eh eh eh \n");
721 mocchiut 1.15 mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
722     if ((int)mcmdrc->ID1 == 226){
723     L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
724     for (UInt_t ui = 0; ui < 6; ui++){
725     if (ui>0){
726     if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
727     if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000))<atime){
728     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
729     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
730     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]);
731     }else {
732     lowerqtime = upperqtime;
733     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
734     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
735     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]);
736     mcreen = j3;
737     mctren = ik;
738     if(fgh==0){
739     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
740     CopyAng(RYPang_lower,RYPang_upper);
741     }
742     oi=ui;
743     goto closethisloop;
744     }
745     fgh++;
746     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
747     CopyAng(RYPang_lower,RYPang_upper);
748     }
749     }else{
750     if (dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000))<atime){
751     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
752     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
753     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]);
754     }
755     else {
756     lowerqtime = upperqtime;
757     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
758     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
759     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]);
760     mcreen = j3;
761     mctren = ik;
762     if(fgh==0){
763     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
764     CopyAng(RYPang_lower,RYPang_upper);
765     lowerqtime = atime-1;
766     }
767     oi=ui;
768     goto closethisloop;
769     //_0 = true;
770     }
771     fgh++;
772     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
773     CopyAng(RYPang_lower,RYPang_upper);
774     //_0 = true;
775     };
776     //cin>>grib;
777     };
778     };
779     };
780     };
781     };
782     closethisloop:
783     //
784 mocchiut 1.18 if ( debug ) printf(" I am There \n");
785     //
786     if (((atime>(UInt_t)upperqtime)||(atime<(UInt_t)lowerqtime)) && neventsm>0 ){
787     if ( debug ) printf(" I am there \n");
788 mocchiut 1.15 //
789     lowerqtime = upperqtime;
790 mocchiut 1.21 Long64_t maxloop = 100000000LL;
791     Long64_t mn = 0;
792 mocchiut 1.15 bool gh=false;
793     ooi=oi;
794     if ( verbose ) printf(" OrbitalInfoCore: sync with quaternions data upperqtime %u lowerqtime %u atime %u \n",(UInt_t)upperqtime,(UInt_t)lowerqtime,atime);
795     while (!gh){
796     if ( mn > maxloop ){
797     if ( verbose ) printf(" OrbitalInfoCore: quaternions sync out of range! exiting\n");
798     gh = true;
799 mocchiut 1.21 neventsm = 0;
800 mocchiut 1.15 };
801     mn++;
802     if (oi<5) oi++;
803     else oi=0;
804 mocchiut 1.29 if (oi==0 && numrec > 0){
805     if ( debug ) printf(" mumble \n");
806 mocchiut 1.15 mcreen++;
807     if (mcreen == numrec){
808     mctren++;
809     mcreen = 0;
810     l0trm->GetEntry(mctren);
811     numrec = mcmdev->Records->GetEntries();
812     }
813     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
814     CopyAng(RYPang_lower,RYPang_upper);
815     mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(mcreen);
816     if ((int)mcmdrc->ID1 == 226){
817     L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
818     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
819     if (upperqtime<lowerqtime){
820     upperqtime=runinfo->RUNTRAILER_TIME;
821     CopyQ(L_QQ_Q_l_upper,L_QQ_Q_l_lower);
822     CopyAng(RYPang_upper,RYPang_lower);
823     }else{
824     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
825     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]);
826     }
827     // re--;
828     gh=true;
829     }
830     }else{
831     if ((Int_t)L_QQ_Q_l_upper->time[oi]>(Int_t)L_QQ_Q_l_upper->time[0]){
832     upperqtime = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
833     orbits.getPosition((double) (upperqtime - gltle->GetFromTime())/60., &eCi);
834     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]);
835     orbits.getPosition((double) (lowerqtime - gltle->GetFromTime())/60., &eCi);
836     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]);
837     // re--;
838     gh=true;
839     };
840     };
841     };
842     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);
843     };
844     //
845 mocchiut 1.18 if ( debug ) printf(" I am THIS \n");
846     //
847 mocchiut 1.15 // Fill in quaternions and angles
848     //
849 mocchiut 1.18 if ((atime<=(UInt_t)upperqtime)&&(atime>=(UInt_t)lowerqtime)&& neventsm>0){
850     if ( debug ) printf(" I am this \n");
851 mocchiut 1.15 UInt_t tut = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
852     if (oi == 0){
853     if ((tut!=5)||(tut!=6)){
854     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)));
855     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));
856     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)));
857     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));
858     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)));
859     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));
860     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)));
861     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));
862    
863     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)));
864     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
865     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)));
866     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
867     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)));
868     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
869     }
870     if (tut==6){
871     if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
872     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)));
873     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));
874     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)));
875     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));
876     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)));
877     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));
878     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)));
879     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));
880    
881     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)));
882     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
883     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)));
884     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
885     //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";
886     //cin>>grib;
887     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)));
888     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
889     }
890     }
891     } else {
892     if((tut!=6)||(tut!=7)||(tut!=9)){
893     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)));
894     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));
895     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)));
896     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));
897     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)));
898     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));
899     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)));
900     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));
901    
902     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)));
903     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
904     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)));
905     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
906     //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";
907     //cin>>grib;
908     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)));
909     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
910     }
911     if (tut==6){
912     if (fabs(RYPang_lower->Kren-RYPang_upper->Kren)<0.1){
913     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)));
914     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));
915     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)));
916     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));
917     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)));
918     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));
919     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)));
920     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));
921    
922     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)));
923     orbitalinfo->theta = incli*atime+RYPang_upper->Tangazh-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
924     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)));
925     orbitalinfo->phi = incli*atime+RYPang_upper->Ryskanie-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
926     //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";
927     //cin>>grib;
928     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)));
929     orbitalinfo->etha = incli*atime+RYPang_upper->Kren-incli*dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[oi]*1000-DeltaOBT*1000));
930     }
931     }
932     }
933 mocchiut 1.18 //
934 mocchiut 1.15 orbitalinfo->mode = holeq(lowerqtime, upperqtime, L_QQ_Q_l_lower, L_QQ_Q_l_upper, oi);
935 mocchiut 1.18 //
936 mocchiut 1.15 } else {
937 mocchiut 1.18 if ( debug ) printf(" ops no incl! \n");
938 mocchiut 1.30 orbitalinfo->mode = 10;
939     };
940     //
941     // ops no inclination information
942     //
943     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 ){
944     orbitalinfo->mode = 10;
945     orbitalinfo->q0 = -1000.;
946     orbitalinfo->q1 = -1000.;
947     orbitalinfo->q2 = -1000.;
948     orbitalinfo->q3 = -1000.;
949     orbitalinfo->etha = -1000.;
950     orbitalinfo->phi = -1000.;
951     orbitalinfo->theta = -1000.;
952 mocchiut 1.15 };
953 mocchiut 1.30 //
954     // #########################################################################################################################
955 mocchiut 1.15 //
956     // fill orbital positions
957     //
958 mocchiut 1.7 // Build coordinates in the right range. We want to convert,
959     // longitude from (0, 2*pi) to (-180deg, 180deg). Altitude is
960     // in meters.
961     lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon);
962     lat = rad2deg(coo.m_Lat);
963     alt = coo.m_Alt;
964 mocchiut 1.15 //
965 mocchiut 1.7 if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){
966 mocchiut 1.15 //
967 mocchiut 1.7 orbitalinfo->lon = lon;
968     orbitalinfo->lat = lat;
969     orbitalinfo->alt = alt ;
970 mocchiut 1.15 //
971 mocchiut 1.7 // compute mag field components and L shell.
972 mocchiut 1.15 //
973 mocchiut 1.7 feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);
974     shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);
975     findb0_(&stps, &bdel, &value, &bequ, &rr0);
976 mocchiut 1.15 //
977 mocchiut 1.7 orbitalinfo->Bnorth = bnorth;
978     orbitalinfo->Beast = beast;
979     orbitalinfo->Bdown = bdown;
980     orbitalinfo->Babs = babs;
981     orbitalinfo->BB0 = babs/bequ;
982 mocchiut 1.15 orbitalinfo->L = xl;
983 mocchiut 1.7 // Set Stormer vertical cutoff using L shell.
984 mocchiut 1.33 orbitalinfo->cutoffsvl = 14.9/(xl*xl);
985 mocchiut 1.15 //
986     };
987 pamelaprod 1.11 //
988 mocchiut 1.30 // pitch angles
989     //
990     if ( orbitalinfo->mode != 10 && orbitalinfo->mode != 5 && orbitalinfo->mode !=7 && orbitalinfo->mode != 9 ){
991     //
992     Float_t Bx = -orbitalinfo->Bdown; //don't need for PamExp ExpOnly for all geography areas
993     Float_t By = orbitalinfo->Beast; //don't need for PamExp ExpOnly for all geography areas
994     Float_t Bz = orbitalinfo->Bnorth; //don't need for PamExp ExpOnly for all geography areas
995     //
996     TMatrixD Fij = PO->ECItoGreenwich(PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3),orbitalinfo->absTime);
997     TMatrixD Dij = PO->GreenwichtoGEO(orbitalinfo->lat,orbitalinfo->lon,Fij);
998     TMatrixD Iij = PO->ColPermutation(Dij);
999     //
1000 mocchiut 1.33 orbitalinfo->Iij.ResizeTo(Iij);
1001     orbitalinfo->Iij = Iij;
1002     //
1003 mocchiut 1.30 A1 = Iij(0,2);
1004     A2 = Iij(1,2);
1005     A3 = Iij(2,2);
1006     //
1007 mocchiut 1.33 // orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3); // Angle between zenit and Pamela's main axiz
1008     // orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz); // Angle between Pamela's main axiz and B
1009 mocchiut 1.30 //
1010     if ( !standalone && tof->ntrk() > 0 ){
1011     //
1012     Int_t nn = 0;
1013     for(Int_t nt=0; nt < tof->ntrk(); nt++){
1014     //
1015     ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1016     Double_t E11x = ptt->xtr_tof[0]; // tr->x[0];
1017     Double_t E11y = ptt->ytr_tof[0]; //tr->y[0];
1018     Double_t E11z = zin[0];
1019     Double_t E22x = ptt->xtr_tof[3];//tr->x[3];
1020     Double_t E22y = ptt->ytr_tof[3];//tr->y[3];
1021     Double_t E22z = zin[3];
1022 mocchiut 1.32 if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1 ){
1023 mocchiut 1.30 Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1024     Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1025     if(E22x-E11x>=0 && E22y-E11y <0) MyAzim = 360. - MyAzim;
1026     if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1027     if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1028     if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1029     Px = (E22x-E11x)/norm;
1030     Py = (E22y-E11y)/norm;
1031     Pz = (E22z-E11z)/norm;
1032     //
1033 mocchiut 1.33 t_orb->trkseqno = ptt->trkseqno;
1034     //
1035     TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);
1036     t_orb->Eij.ResizeTo(Eij);
1037     t_orb->Eij = Eij;
1038     //
1039     TMatrixD Sij = PO->PamelatoGEO(Fij,Px,Py,Pz);
1040     t_orb->Sij.ResizeTo(Sij);
1041     t_orb->Sij = Sij;
1042 mocchiut 1.30 //
1043     t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);
1044 mocchiut 1.33 //
1045     //
1046     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);
1047     //
1048     t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1049     //
1050     if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1051 mocchiut 1.30 //
1052     new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1053     nn++;
1054     //
1055     t_orb->Clear();
1056     //
1057     };
1058     //
1059     };
1060     } else {
1061     if ( debug ) printf(" mmm... mode %u standalone %i ntrk %i \n",orbitalinfo->mode,standalone,tof->ntrk());
1062     };
1063     //
1064     };
1065     //
1066 mocchiut 1.15 // Fill the class
1067 pamelaprod 1.11 //
1068 mocchiut 1.1 OrbitalInfotr->Fill();
1069 mocchiut 1.15 //
1070 mocchiut 1.30 delete t_orb;
1071     //
1072 mocchiut 1.15 }; // loop over the events in the run
1073 mocchiut 1.1 //
1074     // Here you may want to clear some variables before processing another run
1075     //
1076 mocchiut 1.5 delete dbtime;
1077 mocchiut 1.18 if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1078     if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
1079     if ( RYPang_upper ) delete RYPang_upper;
1080     if ( RYPang_lower ) delete RYPang_lower;
1081 mocchiut 1.1 }; // process all the runs
1082 mocchiut 1.15
1083 mocchiut 1.1 if (verbose) printf("\n Finished processing data \n");
1084     //
1085     closeandexit:
1086     //
1087     // we have finished processing the run(s). If we processed a single run now we must copy all the events after our run from the old tree to the new one and delete the old tree.
1088     //
1089     if ( !reprocall && reproc && code >= 0 ){
1090     if ( totfileentries > noaftrun ){
1091     if (verbose){
1092     printf("\n Post-processing: copying events from the old tree after the processed run\n");
1093     printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
1094     printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
1095     }
1096     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1097     //
1098     // Get entry from old tree
1099     //
1100     OrbitalInfotrclone->GetEntry(j);
1101     //
1102     // copy orbitalinfoclone to OrbitalInfo
1103     //
1104 mocchiut 1.3 orbitalinfo->Clear();
1105 mocchiut 1.5 //
1106 mocchiut 1.1 memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
1107     //
1108     // Fill entry in the new tree
1109     //
1110     OrbitalInfotr->Fill();
1111     };
1112     if (verbose) printf(" Finished successful copying!\n");
1113     };
1114     };
1115     //
1116     // Close files, delete old tree(s), write and close level2 file
1117     //
1118     if ( l0File ) l0File->Close();
1119     if ( tempfile ) tempfile->Close();
1120 mocchiut 1.23 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1121 mocchiut 1.5 //
1122 mocchiut 1.1 if ( runinfo ) runinfo->Close();
1123     if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");
1124 mocchiut 1.30 if ( tof ) tof->Delete();
1125     if ( ttof ) ttof->Delete();
1126     //
1127 mocchiut 1.1 if ( file ){
1128     file->cd();
1129     file->Write();
1130     };
1131     //
1132 mocchiut 1.23 if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1133 mocchiut 1.1 //
1134     // the end
1135     //
1136 mocchiut 1.25 if ( dbc ){
1137     dbc->Close();
1138     delete dbc;
1139     };
1140 mocchiut 1.1 if (verbose) printf("\n Exiting...\n");
1141     if(OrbitalInfotr)OrbitalInfotr->Delete();
1142 mocchiut 1.4 //
1143 mocchiut 1.30 if ( PO ) delete PO;
1144 mocchiut 1.4 if ( orbitalinfo ) delete orbitalinfo;
1145     if ( orbitalinfoclone ) delete orbitalinfoclone;
1146     if ( glroot ) delete glroot;
1147     if ( runinfo ) delete runinfo;
1148     //
1149 mocchiut 1.1 if(code < 0) throw code;
1150     return(code);
1151     }
1152    
1153 mocchiut 1.7
1154     //
1155     // Returns the cCoordGeo structure holding the geographical
1156     // coordinates for the event (see sgp4.h).
1157     //
1158     // atime is the abstime of the event in UTC unix time.
1159     // tletime is the time of the tle in UTC unix time.
1160     // tle is the previous and nearest tle (compared to atime).
1161     cCoordGeo getCoo(UInt_t atime, UInt_t tletime, cTle *tle)
1162     {
1163     cEci eci;
1164     cOrbit orbit(*tle);
1165     orbit.getPosition((double) (atime - tletime)/60., &eci);
1166    
1167     return eci.toGeo();
1168     }
1169 mocchiut 1.15
1170     // function of copyng of quatrnions classes
1171    
1172     void CopyQ(Quaternions *Q1, Quaternions *Q2){
1173     for(UInt_t i = 0; i < 6; i++){
1174     Q1->time[i]=Q2->time[i];
1175     for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j];
1176     }
1177     return;
1178     }
1179    
1180     // functions of copyng InclinationInfo classes
1181    
1182     void CopyAng(InclinationInfo *A1, InclinationInfo *A2){
1183     A1->Tangazh = A2->Tangazh;
1184     A1->Ryskanie = A2->Ryskanie;
1185     A1->Kren = A2->Kren;
1186     return;
1187     }
1188    
1189     UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
1190    
1191     UInt_t hole = 10;
1192     bool R10l = false; // Sign of R10 mode in lower quaternions array
1193     bool R10u = false; // Sign of R10 mode in upper quaternions array
1194     bool insm = false; // Sign that we inside quaternions array
1195     bool mxtml = false; // Sign of mixt mode in lower quaternions array
1196     bool mxtmu = false; // Sign of mixt mode in upper quaternions array
1197     bool npasm = false; // Sign of normall pass between R10 and non R10 or between non R10 and R10
1198     UInt_t NCQl = 6; // Number of correct quaternions in lower array
1199     UInt_t NCQu = 6; // Number of correct quaternions in upper array
1200     if (f>0){
1201     insm = true;
1202     if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false;
1203     if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true;
1204     }else{
1205     insm = false;
1206     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true;
1207     if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true;
1208     if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false;
1209     if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false;
1210     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){
1211     mxtml = true;
1212     for(UInt_t i = 1; i < 6; i++){
1213     if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i;
1214     }
1215     }
1216     if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){
1217     mxtmu = true;
1218     for(UInt_t i = 1; i < 6; i++){
1219     if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i;
1220     }
1221     }
1222     }
1223    
1224     if(((upper-lower==1.5)||(upper-lower==3.)||(upper-lower==30.)||(upper-lower==31.5)||(upper-lower==33.)||(upper-lower==181.5)||(upper-lower==210.)||(upper-lower==211.5))&&!insm) npasm = true;
1225    
1226    
1227     if (R10u&&insm) hole=0; // best event R10
1228     if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct
1229     if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10
1230     if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10
1231     if ((!npasm)&&(upper-lower<=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 4; // eliminable hole between R10 and non R10 or between non R10 and R10
1232     if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10
1233     if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10
1234     if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10
1235     if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10
1236     if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10
1237     return hole;
1238     }
1239    

  ViewVC Help
Powered by ViewVC 1.1.23