/[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.69 - (hide annotations) (download)
Fri Mar 28 20:47:15 2014 UTC (10 years, 11 months ago) by pam-mep
Branch: MAIN
Changes since 1.68: +771 -274 lines
new OrbitalInfo code

1 mocchiut 1.1 // C/C++ headers
2     //
3     #include <fstream>
4     #include <string.h>
5     #include <iostream>
6     #include <cstring>
7     #include <stdio.h>
8     //
9     // ROOT headers
10     //
11 mocchiut 1.44 //#include <TCanvas.h>
12 pam-mep 1.60 #include <TH2F.h> //for test only. Vitaly.
13     #include <TVector3.h>
14 mocchiut 1.44 //#include <TF1.h>
15    
16 mocchiut 1.1 #include <TTree.h>
17     #include <TClassEdit.h>
18     #include <TObject.h>
19     #include <TList.h>
20 mocchiut 1.5 #include <TArrayI.h>
21 mocchiut 1.1 #include <TSystem.h>
22     #include <TSystemDirectory.h>
23     #include <TString.h>
24     #include <TFile.h>
25     #include <TClass.h>
26     #include <TSQLServer.h>
27     #include <TSQLRow.h>
28     #include <TSQLResult.h>
29     //
30 mocchiut 1.8 // RunInfo header
31     //
32     #include <RunInfo.h>
33     #include <GLTables.h>
34     //
35 mocchiut 1.1 // YODA headers
36     //
37     #include <PamelaRun.h>
38     #include <PscuHeader.h>
39     #include <PscuEvent.h>
40     #include <EventHeader.h>
41 mocchiut 1.15 #include <mcmd/McmdEvent.h>
42     #include <mcmd/McmdRecord.h>
43 mocchiut 1.1 //
44     // This program headers
45     //
46     #include <OrbitalInfo.h>
47 mocchiut 1.7 #include <OrbitalInfoVerl2.h>
48 mocchiut 1.1 #include <OrbitalInfoCore.h>
49 mocchiut 1.15 #include <InclinationInfo.h>
50 mocchiut 1.1
51 pam-mep 1.69 //
52     // Tracker and ToF classes headers and definitions
53     //
54     #include <ToFLevel2.h>
55     #include <TrkLevel2.h>
56 mocchiut 1.40
57 mocchiut 1.1 using namespace std;
58    
59     //
60     // CORE ROUTINE
61     //
62     //
63 mocchiut 1.25 int OrbitalInfoCore(UInt_t run, TFile *file, GL_TABLES *glt, Int_t OrbitalInfoargc, char *OrbitalInfoargv[]){
64 mocchiut 1.15 //
65 mocchiut 1.1 Int_t i = 0;
66 mocchiut 1.25 TString host = glt->CGetHost();
67     TString user = glt->CGetUser();
68     TString psw = glt->CGetPsw();
69     TSQLServer *dbc = TSQLServer::Connect(host.Data(),user.Data(),psw.Data());
70 mocchiut 1.1 //
71 mocchiut 1.26 stringstream myquery;
72     myquery.str("");
73     myquery << "SET time_zone='+0:00'";
74 mocchiut 1.59 delete dbc->Query(myquery.str().c_str());
75 mocchiut 1.26 //
76 mocchiut 1.16 TString processFolder = Form("OrbitalInfoFolder_%u",run);
77 mocchiut 1.1 //
78     // Set these to true to have a very verbose output.
79     //
80     Bool_t debug = false;
81     //
82     Bool_t verbose = false;
83 mocchiut 1.30 //
84 mocchiut 1.31 Bool_t standalone = false;
85 mocchiut 1.30 //
86 mocchiut 1.1 if ( OrbitalInfoargc > 0 ){
87     i = 0;
88     while ( i < OrbitalInfoargc ){
89     if ( !strcmp(OrbitalInfoargv[i],"-processFolder") ) {
90     if ( OrbitalInfoargc < i+1 ){
91     throw -3;
92     };
93     processFolder = (TString)OrbitalInfoargv[i+1];
94     i++;
95     };
96     if ( (!strcmp(OrbitalInfoargv[i],"--debug")) || (!strcmp(OrbitalInfoargv[i],"-g")) ) {
97     verbose = true;
98 mocchiut 1.15 debug = true;
99 mocchiut 1.1 };
100     if ( (!strcmp(OrbitalInfoargv[i],"--verbose")) || (!strcmp(OrbitalInfoargv[i],"-v")) ) {
101     verbose = true;
102     };
103 mocchiut 1.30 if ( (!strcmp(OrbitalInfoargv[i],"--standalone")) ) {
104     standalone = true;
105     };
106     if ( (!strcmp(OrbitalInfoargv[i],"--calculate-pitch")) ) {
107     standalone = false;
108     };
109 mocchiut 1.1 i++;
110     };
111     };
112     //
113     const char* outDir = gSystem->DirName(gSystem->DirName(file->GetPath()));
114     //
115     TTree *OrbitalInfotr = 0;
116 mocchiut 1.5 UInt_t nevents = 0;
117 mocchiut 1.15 UInt_t neventsm = 0;
118 mocchiut 1.1 //
119     // variables needed to reprocess data
120     //
121 mocchiut 1.6 Long64_t maxsize = 10000000000LL;
122     TTree::SetMaxTreeSize(maxsize);
123     //
124 mocchiut 1.1 TString OrbitalInfoversion;
125     ItoRunInfo *runinfo = 0;
126 mocchiut 1.5 TArrayI *runlist = 0;
127 mocchiut 1.1 TTree *OrbitalInfotrclone = 0;
128     Bool_t reproc = false;
129     Bool_t reprocall = false;
130 mocchiut 1.66 Bool_t igrfloaded = false;
131 mocchiut 1.1 UInt_t nobefrun = 0;
132     UInt_t noaftrun = 0;
133     UInt_t numbofrun = 0;
134     stringstream ftmpname;
135     TString fname;
136 mocchiut 1.5 UInt_t totfileentries = 0;
137 mocchiut 1.15 UInt_t idRun = 0;
138 pam-fi 1.53 UInt_t anni5 = 60 * 60 * 24 * 365 * 5 ;//1576800
139 mocchiut 1.15 //
140     // My variables. Vitaly.
141     //
142 mocchiut 1.44 // UInt_t oi = 0;
143 mocchiut 1.15 Int_t tmpSize = 0;
144 mocchiut 1.1 //
145     // variables needed to handle error signals
146     //
147     Int_t code = 0;
148     Int_t sgnl;
149     //
150     // OrbitalInfo classes
151     //
152     OrbitalInfo *orbitalinfo = new OrbitalInfo();
153     OrbitalInfo *orbitalinfoclone = new OrbitalInfo();
154 mocchiut 1.44
155 mocchiut 1.1 //
156     // define variables for opening and reading level0 file
157     //
158     TFile *l0File = 0;
159     TTree *l0tr = 0;
160 mocchiut 1.37 // TTree *l0trm = 0;
161     TChain *ch = 0;
162 mocchiut 1.2 // EM: open also header branch
163     TBranch *l0head = 0;
164     pamela::EventHeader *eh = 0;
165     pamela::PscuHeader *ph = 0;
166 mocchiut 1.15 pamela::McmdEvent *mcmdev = 0;
167     pamela::McmdRecord *mcmdrc = 0;
168 mocchiut 1.2 // end EM
169 mocchiut 1.15
170     // pamela::RunHeaderEvent *reh = new pamela::RunHeaderEvent;
171     // pamela::EventHeader *eH = new pamela::EventHeader;
172    
173 mocchiut 1.1 //
174     // Define other basic variables
175     //
176     UInt_t procev = 0;
177     stringstream file2;
178     stringstream file3;
179     stringstream qy;
180     Int_t totevent = 0;
181 mocchiut 1.5 UInt_t atime = 0;
182     UInt_t re = 0;
183 mocchiut 1.15 UInt_t ik = 0;
184 mocchiut 1.7
185     // Position
186     Float_t lon, lat, alt;
187    
188     //
189     // IGRF stuff
190     //
191 mocchiut 1.64 Double_t dimo = 0.0; // dipole moment (computed from dat files) // EM GCC 4.7
192 mocchiut 1.40 Float_t bnorth, beast, bdown, babs;
193     Float_t xl; // L value
194     Float_t icode; // code value for L accuracy (see fortran code)
195     Float_t bab1; // What's the difference with babs?
196     Float_t stps = 0.005; // step size for field line tracing
197     Float_t bdel = 0.01; // required accuracy
198     Float_t bequ; // equatorial b value (also called b_0)
199     Bool_t value = 0; // false if bequ is not the minimum b value
200     Float_t rr0; // equatorial radius normalized to earth radius
201 mocchiut 1.7
202 mocchiut 1.1 //
203     // Working filename
204     //
205     TString outputfile;
206     stringstream name;
207     name.str("");
208     name << outDir << "/";
209     //
210     // temporary file and folder
211     //
212     TFile *tempfile = 0;
213     TTree *tempOrbitalInfo = 0;
214     stringstream tempname;
215     stringstream OrbitalInfofolder;
216 mocchiut 1.23 Bool_t myfold = false;
217 mocchiut 1.1 tempname.str("");
218     tempname << outDir;
219     tempname << "/" << processFolder.Data();
220     OrbitalInfofolder.str("");
221     OrbitalInfofolder << tempname.str().c_str();
222     tempname << "/OrbitalInfotree_run";
223     tempname << run << ".root";
224 mocchiut 1.40 UInt_t totnorun = 0;
225 mocchiut 1.1 //
226     // DB classes
227     //
228     GL_ROOT *glroot = new GL_ROOT();
229 mocchiut 1.5 GL_TIMESYNC *dbtime = 0;
230 mocchiut 1.7 GL_TLE *gltle = new GL_TLE();
231 mocchiut 1.15 //
232     //Quaternions classes
233     //
234 mocchiut 1.57 Quaternions *L_QQ_Q_l_lower = 0;
235     InclinationInfo *RYPang_lower = 0;
236     Quaternions *L_QQ_Q_l_upper = 0;
237     InclinationInfo *RYPang_upper = 0;
238 mocchiut 1.15
239     cEci eCi;
240    
241 mocchiut 1.7 // Initialize fortran routines!!!
242 mocchiut 1.52 Int_t ltp1 = 0;
243 mocchiut 1.7 Int_t ltp2 = 0;
244     Int_t ltp3 = 0;
245 mocchiut 1.55 // Int_t uno = 1;
246     // const char *niente = " ";
247 pam-mep 1.69 GL_PARAM *glparam0 = new GL_PARAM();
248 mocchiut 1.7 GL_PARAM *glparam = new GL_PARAM();
249 mocchiut 1.10 GL_PARAM *glparam2 = new GL_PARAM();
250 mocchiut 1.52 GL_PARAM *glparam3 = new GL_PARAM();
251 mocchiut 1.44
252 mocchiut 1.30 //
253 mocchiut 1.44 // Orientation variables. Vitaly
254 mocchiut 1.30 //
255     UInt_t evfrom = 0;
256     UInt_t jumped = 0;
257     Int_t itr = -1;
258 mocchiut 1.64 // Double_t A1;
259     // Double_t A2;
260     // Double_t A3;
261 mocchiut 1.30 Double_t Px = 0;
262     Double_t Py = 0;
263     Double_t Pz = 0;
264     TTree *ttof = 0;
265     ToFLevel2 *tof = new ToFLevel2();
266 pam-mep 1.69 TTree *ttrke = 0;
267     TrkLevel2 *trke = new TrkLevel2();
268 mocchiut 1.30 OrientationInfo *PO = new OrientationInfo();
269     Int_t nz = 6;
270     Float_t zin[6];
271     Int_t nevtofl2 = 0;
272 pam-mep 1.69 Int_t nevtrkl2 = 0;
273 mocchiut 1.44 if ( verbose ) cout<<"Reading quaternions external file"<<endl;
274     cout.setf(ios::fixed,ios::floatfield);
275     /******Reading recovered quaternions...*********/
276     vector<Double_t> recqtime;
277     vector<Float_t> recq0;
278     vector<Float_t> recq1;
279     vector<Float_t> recq2;
280     vector<Float_t> recq3;
281     Float_t Norm = 1;
282 pam-mep 1.69 Int_t parerror=glparam0->Query_GL_PARAM(1,303,dbc); // parameters stored in DB in GL_PRAM table
283     cout<<parerror<<"\t"<<(char*)(glparam0->PATH+glparam0->NAME).Data()<<endl;
284     ifstream in((char*)(glparam0->PATH+glparam0->NAME).Data(),ios::in);
285 mocchiut 1.44 if ( parerror<0 ) {
286     code = parerror;
287 pam-mep 1.69 //goto closeandexit;
288 pam-mep 1.54 }
289 mocchiut 1.44 while(!in.eof()){
290     recqtime.resize(recqtime.size()+1);
291     Int_t sizee = recqtime.size();
292     recq0.resize(sizee);
293     recq1.resize(sizee);
294     recq2.resize(sizee);
295     recq3.resize(sizee);
296     in>>recqtime[sizee-1];
297     in>>recq0[sizee-1];
298     in>>recq1[sizee-1];
299     in>>recq2[sizee-1];
300     in>>recq3[sizee-1];
301     in>>Norm;
302     }
303 pam-mep 1.69 in.close();
304 mocchiut 1.44 if ( verbose ) cout<<"We have read recovered data"<<endl;
305 pam-mep 1.69 if (debug) cout << "size of recovered quaterions data set is " << recqtime.size() << endl;
306    
307     vector<UInt_t> RTtime1;
308     vector<UInt_t> RTtime2;
309     vector<Double_t> RTbank1;
310     vector<Double_t> RTbank2;
311     vector<Int_t> RTazim;
312     vector<Int_t> RTdir1;
313     vector<Int_t> RTdir2;
314     vector<Int_t> RTerrq;
315    
316     // 10RED CHECK
317    
318     // TH2F* DIFFX = new TH2F("diffx","",100,0,100,90,0,90);
319     // TH2F* DIFFY = new TH2F("diffy","",100,0,100,90,0,90);
320     // TH2F* DIFFZ = new TH2F("diffz","",100,0,100,90,0,90);
321    
322     ofstream mc;
323     TString gr = "methodscomparison_";
324     gr+=run;
325     gr+=".txt";
326     mc.open(gr);
327     mc.setf(ios::fixed,ios::floatfield);
328     // 10RED CHECK END
329    
330     if ( verbose ) cout<<"read Rotation Table"<<endl;
331    
332     Int_t parerror2=glparam0->Query_GL_PARAM(1,305,dbc);
333     ifstream an((char*)(glparam0->PATH+glparam0->NAME).Data(),ios::in);
334     cout<<parerror2<<"\t"<<(char*)(glparam0->PATH+glparam0->NAME).Data()<<endl;
335     // if ( parerror2<0 ) {
336     // code = parerror;
337     //goto closeandexit;
338     // }
339    
340     //ifstream an("/data03/Malakhov/pam9Malakhov/installed10/calib/orb-param/RDBCC.txt",ios::in);
341     while(!an.eof()){
342     RTtime1.resize(RTtime1.size()+1);
343     Int_t sizee = RTtime1.size();
344     RTbank1.resize(sizee+1);
345     RTazim.resize(sizee+1);
346     RTdir1.resize(sizee+1);
347     RTerrq.resize(sizee+1);
348     an>>RTtime1[sizee-1];
349     an>>RTbank1[sizee-1];
350     an>>RTazim[sizee-1];
351     an>>RTdir1[sizee-1];
352     an>>RTerrq[sizee-1];
353     if(sizee>1) {
354     RTtime2.resize(sizee+1);
355     RTbank2.resize(sizee+1);
356     RTdir2.resize(sizee+1);
357     RTtime2[sizee-2]=RTtime1[sizee-1];
358     RTbank2[sizee-2]=RTbank1[sizee-1];
359     RTdir2[sizee-2]=RTdir1[sizee-1];
360     }
361     }
362     an.close();
363     //cout<<"put some number here"<<endl;
364     //Int_t yupi;
365     //cin>>yupi;
366    
367     if ( verbose ) cout<<"We have read Rotation Table"<<endl;
368     //Geomagnetic coordinates calculations staff
369    
370     GMtype_CoordGeodetic location;
371     GMtype_CoordDipole GMlocation;
372     GMtype_Ellipsoid Ellip;
373     GMtype_Data G0, G1, H1;
374    
375     // { // this braces is necessary to avoid jump to label 'closeandexit' error // but it is wrong since the variable "igpath" will not exist outside. To overcome the "jump to label 'closeandexit' error" it is necessary to set the "igpath" before line 276
376     // TString igpath="/data03/Malakhov/pam9Malakhov/installed10/calib/orb-param/";
377     // }
378    
379     // GM_ScanIGRF(glparam->PATH, &G0, &G1, &H1);
380     GM_ScanIGRF(dbc, &G0, &G1, &H1);
381    
382     //cout << G0.element[0] << "\t" << G1.element[0] << "\t" << H1.element[0] << endl;
383     //cout << G0.element[5] << "\t" << G1.element[5] << "\t" << H1.element[5] << endl;
384    
385     GM_SetEllipsoid(&Ellip);
386 mocchiut 1.44
387 mocchiut 1.55 // IGRF stuff moved inside run loop!
388    
389 mocchiut 1.30 for (Int_t ip=0;ip<nz;ip++){
390     zin[ip] = tof->GetZTOF(tof->GetToFPlaneID(ip));
391     };
392     //
393     if ( !standalone ){
394     //
395     // Does it contain the Tracker tree?
396     //
397     ttof = (TTree*)file->Get("ToF");
398     if ( !ttof ) {
399     if ( verbose ) printf(" OrbitalInfo - ERROR: no tof tree\n");
400     code = -900;
401     goto closeandexit;
402 pam-mep 1.69 }
403 mocchiut 1.30 ttof->SetBranchAddress("ToFLevel2",&tof);
404     nevtofl2 = ttof->GetEntries();
405 pam-mep 1.69
406     ttrke = (TTree*)file->Get("Tracker");
407     if ( !ttrke ) {
408     if ( verbose ) printf(" OrbitalInfo - ERROR: no trk tree\n");
409     code = -903;
410     goto closeandexit;
411     }
412     ttrke->SetBranchAddress("TrkLevel2",&trke);
413     nevtrkl2 = ttrke->GetEntries();
414     }
415 mocchiut 1.1 //
416     // Let's start!
417     //
418     // 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
419     // if run != 0 we must process only that run but first we have to check if the tree MyDetector2 already exist in the file
420     // if it exists we are reprocessing data and we must delete that entries, if not we must create it.
421     //
422 mocchiut 1.5 if ( run == 0 ) reproc = true;
423 mocchiut 1.1 //
424     //
425     // Output file is "outputfile"
426     //
427     if ( !file->IsOpen() ){
428     //printf(" OrbitalInfo - ERROR: cannot open file for writing\n");
429     throw -901;
430     };
431     //
432     // Retrieve GL_RUN variables from the level2 file
433     //
434     OrbitalInfoversion = OrbitalInfoInfo(false); // we should decide how to handle versioning system
435     //
436     // create an interface to RunInfo called "runinfo"
437     //
438     runinfo = new ItoRunInfo(file);
439     //
440     // open "Run" tree in level2 file, if not existing return an error (sngl != 0)
441     //
442     sgnl = 0;
443     sgnl = runinfo->Update(run, "ORB", OrbitalInfoversion);
444     //sgnl = runinfo->Read(run);
445    
446     if ( sgnl ){
447     //printf("OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");
448     code = sgnl;
449     goto closeandexit;
450     } else {
451     sgnl = 0;
452     };
453     //
454     // number of events in the file BEFORE the first event of our run
455     //
456     nobefrun = runinfo->GetFirstEntry();
457     //
458     // total number of events in the file
459     //
460     totfileentries = runinfo->GetFileEntries();
461     //
462     // first file entry AFTER the last event of our run
463     //
464     noaftrun = runinfo->GetLastEntry() + 1;
465     //
466     // number of run to be processed
467     //
468     numbofrun = runinfo->GetNoRun();
469 mocchiut 1.40 totnorun = runinfo->GetRunEntries();
470 mocchiut 1.1 //
471     // Try to access the OrbitalInfo tree in the file, if it exists we are reprocessing data if not we are processing a new run
472     //
473     OrbitalInfotrclone = (TTree*)file->Get("OrbitalInfo");
474     //
475     if ( !OrbitalInfotrclone ){
476     //
477     // tree does not exist, we are not reprocessing
478     //
479     reproc = false;
480 mocchiut 1.5 if ( run == 0 ){
481 mocchiut 1.1 if (verbose) printf(" OrbitalInfo - WARNING: you are reprocessing data but OrbitalInfo tree does not exist!\n");
482     }
483 mocchiut 1.5 if ( runinfo->IsReprocessing() && run != 0 ) {
484 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");
485     }
486     } else {
487     //
488     // tree exists, we are reprocessing data. Are we reprocessing a single run or all the file?
489     //
490 mocchiut 1.6 OrbitalInfotrclone->SetAutoSave(900000000000000LL);
491 mocchiut 1.1 reproc = true;
492     //
493     //
494     if (verbose) printf("\n Preparing the pre-processing...\n");
495     //
496 mocchiut 1.22 if ( run == 0 || totnorun == 1 ){
497 mocchiut 1.1 //
498     // we are reprocessing all the file
499     // 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
500     //
501     reprocall = true;
502     //
503 mocchiut 1.57 if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing all runs\n Deleting old tree...\n");
504 mocchiut 1.1 //
505     } else {
506     //
507     // 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
508     //
509     reprocall = false;
510     //
511 mocchiut 1.5 if (verbose) printf("\n OrbitalInfo - WARNING: Reprocessing run number %u \n",run);
512 mocchiut 1.1 //
513     // copying old tree to a new file
514     //
515 mocchiut 1.23 gSystem->MakeDirectory(OrbitalInfofolder.str().c_str());
516     myfold = true;
517 mocchiut 1.1 tempfile = new TFile(tempname.str().c_str(),"RECREATE");
518     tempOrbitalInfo = OrbitalInfotrclone->CloneTree(-1,"fast");
519     tempOrbitalInfo->SetName("OrbitalInfo-old");
520     tempfile->Write();
521 mocchiut 1.57 tempOrbitalInfo->Delete();
522 mocchiut 1.1 tempfile->Close();
523     }
524     //
525     // Delete the old tree from old file and memory
526     //
527 mocchiut 1.57 OrbitalInfotrclone->Clear();
528 mocchiut 1.1 OrbitalInfotrclone->Delete("all");
529     //
530     if (verbose) printf(" ...done!\n");
531     //
532     };
533     //
534     // create mydetector tree mydect
535     //
536     file->cd();
537     OrbitalInfotr = new TTree("OrbitalInfo-new","PAMELA OrbitalInfo data");
538 mocchiut 1.6 OrbitalInfotr->SetAutoSave(900000000000000LL);
539 mocchiut 1.30 orbitalinfo->Set();//ELENA **TEMPORANEO?**
540 mocchiut 1.1 OrbitalInfotr->Branch("OrbitalInfo","OrbitalInfo",&orbitalinfo);
541     //
542     if ( reproc && !reprocall ){
543     //
544     // open new file and retrieve also tree informations
545     //
546     tempfile = new TFile(tempname.str().c_str(),"READ");
547     OrbitalInfotrclone = (TTree*)tempfile->Get("OrbitalInfo-old");
548 mocchiut 1.6 OrbitalInfotrclone->SetAutoSave(900000000000000LL);
549 mocchiut 1.1 OrbitalInfotrclone->SetBranchAddress("OrbitalInfo",&orbitalinfoclone);
550     //
551     if ( nobefrun > 0 ){
552     if (verbose){
553 mocchiut 1.7 printf("\n Pre-processing: copying events from the old tree before the processed run\n");
554     printf(" Copying %u events in the file which are before the beginning of the run %u \n",nobefrun,run);
555     printf(" Start copying at event number 0, end copying at event number %u \n",nobefrun);
556 mocchiut 1.1 }
557     for (UInt_t j = 0; j < nobefrun; j++){
558     //
559 mocchiut 1.43 if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;
560 mocchiut 1.1 //
561     // copy orbitalinfoclone to mydec
562     //
563 mocchiut 1.3 orbitalinfo->Clear();
564 mocchiut 1.5 //
565 mocchiut 1.1 memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
566     //
567     // Fill entry in the new tree
568     //
569     OrbitalInfotr->Fill();
570     //
571     };
572     if (verbose) printf(" Finished successful copying!\n");
573 mocchiut 1.57 };
574 mocchiut 1.1 };
575     //
576 mocchiut 1.44 //
577 mocchiut 1.1 // Get the list of run to be processed, if only one run has to be processed the list will contain one entry only.
578     //
579     runlist = runinfo->GetRunList();
580     //
581     // Loop over the run to be processed
582     //
583     for (UInt_t irun=0; irun < numbofrun; irun++){
584 mocchiut 1.57
585     L_QQ_Q_l_lower = new Quaternions();
586     RYPang_lower = new InclinationInfo();
587     L_QQ_Q_l_upper = new Quaternions();
588     RYPang_upper = new InclinationInfo();
589    
590 mocchiut 1.1 //
591     // retrieve the first run ID to be processed using the RunInfo list
592     //
593 mocchiut 1.15
594 mocchiut 1.1 idRun = runlist->At(irun);
595     if (verbose){
596     printf("\n\n\n ####################################################################### \n");
597     printf(" PROCESSING RUN NUMBER %i \n",(int)idRun);
598     printf(" ####################################################################### \n\n\n");
599     }
600     //
601 mocchiut 1.5 runinfo->ID_ROOT_L0 = 0;
602 mocchiut 1.1 //
603     // store in the runinfo class the GL_RUN variables for our run
604     //
605     sgnl = 0;
606     sgnl = runinfo->GetRunInfo(idRun);
607     if ( sgnl ){
608 mocchiut 1.5 if ( debug ) printf("\n OrbitalInfo - ERROR: RunInfo exited with non-zero status\n");
609 mocchiut 1.1 code = sgnl;
610     goto closeandexit;
611     } else {
612     sgnl = 0;
613     };
614     //
615     // now you can access that variables using the RunInfo class this way runinfo->ID_REG_RUN
616     //
617 mocchiut 1.5 if ( runinfo->ID_ROOT_L0 == 0 ){
618     if ( debug ) printf("\n OrbitalInfo - ERROR: no run with ID_RUN = %u \n\n Exiting... \n\n",idRun);
619 mocchiut 1.1 code = -5;
620     goto closeandexit;
621     };
622     //
623 mocchiut 1.5 // prepare the timesync for the db
624     //
625     dbtime = new GL_TIMESYNC(runinfo->ID_ROOT_L0,"ID",dbc);
626 mocchiut 1.15
627 mocchiut 1.5 //
628 mocchiut 1.1 // Search in the DB the path and name of the LEVEL0 file to be processed.
629     //
630 mocchiut 1.5 glroot->Query_GL_ROOT(runinfo->ID_ROOT_L0,dbc);
631 mocchiut 1.1 //
632     ftmpname.str("");
633     ftmpname << glroot->PATH.Data() << "/";
634     ftmpname << glroot->NAME.Data();
635     fname = ftmpname.str().c_str();
636 mocchiut 1.15 ftmpname.str("");
637 mocchiut 1.1 //
638 mocchiut 1.40 // print nout informations
639 mocchiut 1.1 //
640 mocchiut 1.5 totevent = runinfo->NEVENTS;
641 mocchiut 1.30 evfrom = runinfo->EV_FROM;
642 mocchiut 1.15 //cout<<"totevents = "<<totevent<<"\n";
643 mocchiut 1.1 if (verbose){
644     printf("\n LEVEL0 data file: %s \n",fname.Data());
645 mocchiut 1.5 printf(" RUN HEADER absolute time is: %u \n",runinfo->RUNHEADER_TIME);
646     printf(" RUN TRAILER absolute time is: %u \n",runinfo->RUNTRAILER_TIME);
647 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);
648 mocchiut 1.1 }//
649 mocchiut 1.27 //
650 mocchiut 1.28 // if ( !totevent ) goto closeandexit;
651 mocchiut 1.1 // Open Level0 file
652 mocchiut 1.59 if ( l0File ) l0File->Close();
653 mocchiut 1.1 l0File = new TFile(fname.Data());
654     if ( !l0File ) {
655 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: problems opening Level0 file\n");
656 mocchiut 1.1 code = -6;
657     goto closeandexit;
658     };
659     l0tr = (TTree*)l0File->Get("Physics");
660     if ( !l0tr ) {
661 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Physics tree in Level0 file\n");
662 mocchiut 1.1 l0File->Close();
663     code = -7;
664     goto closeandexit;
665     };
666 mocchiut 1.2 // EM: open header branch as well
667     l0head = l0tr->GetBranch("Header");
668     if ( !l0head ) {
669 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: no Header branch in Level0 tree\n");
670 mocchiut 1.2 l0File->Close();
671     code = -8;
672     goto closeandexit;
673     };
674     l0tr->SetBranchAddress("Header", &eh);
675     // end EM
676 mocchiut 1.5 nevents = l0head->GetEntries();
677 mocchiut 1.1 //
678 mocchiut 1.28 if ( nevents < 1 && totevent ) {
679 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: Level0 file is empty\n\n");
680 mocchiut 1.1 l0File->Close();
681     code = -11;
682     goto closeandexit;
683     };
684 mocchiut 1.20 //
685 mocchiut 1.28 if ( runinfo->EV_TO > nevents-1 && totevent ) {
686 mocchiut 1.5 if ( debug ) printf(" OrbitalInfo - ERROR: too few entries in the registry tree\n");
687 mocchiut 1.1 l0File->Close();
688     code = -12;
689     goto closeandexit;
690     };
691 mocchiut 1.55
692     //
693     // open IGRF files and do it only once if we are processing a full level2 file
694     //
695 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
696     if ( irun == 0 ){
697     if ( l0head->GetEntry(runinfo->EV_FROM) <= 0 ) throw -36;
698     //
699     // absolute time of first event of the run (it should not matter a lot)
700     //
701     ph = eh->GetPscuHeader();
702     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
703    
704     parerror=glparam->Query_GL_PARAM(atime-anni5,301,dbc); // parameters stored in DB in GL_PRAM table
705     if ( parerror<0 ) {
706     code = parerror;
707     goto closeandexit;
708     };
709     ltp1 = (Int_t)(glparam->PATH+glparam->NAME).Length();
710     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
711     //
712     parerror=glparam2->Query_GL_PARAM(atime,301,dbc); // parameters stored in DB in GL_PRAM table
713     if ( parerror<0 ) {
714     code = parerror;
715     goto closeandexit;
716     };
717     ltp2 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();
718     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
719     //
720     parerror=glparam3->Query_GL_PARAM(atime,302,dbc); // parameters stored in DB in GL_PRAM table
721     if ( parerror<0 ) {
722     code = parerror;
723     goto closeandexit;
724     };
725     ltp3 = (Int_t)(glparam3->PATH+glparam3->NAME).Length();
726     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam3->PATH+glparam3->NAME).Data());
727     //
728     initize_((char *)(glparam->PATH+glparam->NAME).Data(),&ltp1,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp2,(char *)(glparam3->PATH+glparam3->NAME).Data(),&ltp3);
729     if (debug) cout<<"initize: "<<(char *)(glparam->PATH+glparam->NAME).Data()<<"\t"<<(char *)(glparam2->PATH+glparam2->NAME).Data()<<"\t"<<(char *)(glparam3->PATH+glparam3->NAME).Data()<<endl;
730     //
731     =======
732 mocchiut 1.68 if ( !igrfloaded ){
733 mocchiut 1.66
734     if ( l0head->GetEntry(runinfo->EV_FROM) > 0 ){
735     igrfloaded = true;
736 mocchiut 1.68 //
737     // absolute time of first event of the run (it should not matter a lot)
738     //
739     ph = eh->GetPscuHeader();
740     atime = dbtime->DBabsTime(ph->GetOrbitalTime());
741    
742     parerror=glparam->Query_GL_PARAM(atime-anni5,301,dbc); // parameters stored in DB in GL_PRAM table
743     if ( parerror<0 ) {
744     code = parerror;
745     goto closeandexit;
746     }
747     ltp1 = (Int_t)(glparam->PATH+glparam->NAME).Length();
748     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam->PATH+glparam->NAME).Data());
749     //
750     parerror=glparam2->Query_GL_PARAM(atime,301,dbc); // parameters stored in DB in GL_PRAM table
751     if ( parerror<0 ) {
752     code = parerror;
753     goto closeandexit;
754     }
755     ltp2 = (Int_t)(glparam2->PATH+glparam2->NAME).Length();
756     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam2->PATH+glparam2->NAME).Data());
757     //
758     parerror=glparam3->Query_GL_PARAM(atime,302,dbc); // parameters stored in DB in GL_PRAM table
759     if ( parerror<0 ) {
760     code = parerror;
761     goto closeandexit;
762     }
763     ltp3 = (Int_t)(glparam3->PATH+glparam3->NAME).Length();
764     if ( verbose ) printf(" Reading Earth's Magnetic Field parameter file: %s \n",(glparam3->PATH+glparam3->NAME).Data());
765     //
766     initize_((char *)(glparam->PATH+glparam->NAME).Data(),&ltp1,(char *)(glparam2->PATH+glparam2->NAME).Data(),&ltp2,(char *)(glparam3->PATH+glparam3->NAME).Data(),&ltp3);
767     //
768 mocchiut 1.66 }
769 pam-mep 1.69 >>>>>>> 1.68
770 mocchiut 1.55 }
771     //
772     // End IGRF stuff//
773     //
774    
775 mocchiut 1.1 //
776 mocchiut 1.44 // TTree *tp = (TTree*)l0File->Get("RunHeader");
777     // tp->SetBranchAddress("Header", &eH);
778     // tp->SetBranchAddress("RunHeader", &reh);
779     // tp->GetEntry(0);
780     // ph = eH->GetPscuHeader();
781     // ULong_t TimeSync = reh->LAST_TIME_SYNC_INFO;
782     // ULong_t ObtSync = reh->OBT_TIME_SYNC;
783     // if ( debug ) printf(" 1 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",TimeSync,ObtSync,TimeSync-ObtSync);
784     //
785 mocchiut 1.15 ULong_t TimeSync = (ULong_t)dbtime->GetTimesync();
786     ULong_t ObtSync = (ULong_t)(dbtime->GetObt0()/1000);
787     ULong_t DeltaOBT = TimeSync - ObtSync;
788    
789     if ( debug ) printf(" 2 TimeSync %lu ObtSync %lu DeltaOBT %lu\n",(ULong_t)(dbtime->GetTimesync()/1000),(ULong_t)dbtime->GetObt0(),TimeSync-ObtSync);
790 mocchiut 1.37 //
791     // Read MCMDs from up to 11 files, 5 before and 5 after the present one in order to have some kind of inclination information
792     //
793     ch = new TChain("Mcmd","Mcmd");
794     //
795     // look in the DB to find the closest files to this run
796     //
797     TSQLResult *pResult = 0;
798     TSQLRow *Row = 0;
799     stringstream myquery;
800     UInt_t l0fid[10];
801     Int_t i = 0;
802     memset(l0fid,0,10*sizeof(Int_t));
803     //
804     myquery.str("");
805     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;";
806     //
807     pResult = dbc->Query(myquery.str().c_str());
808     //
809     i = 9;
810     if( pResult ){
811     //
812     Row = pResult->Next();
813     //
814     while ( Row ){
815     //
816     // store infos and exit
817     //
818     l0fid[i] = (UInt_t)atoll(Row->GetField(0));
819     i--;
820     Row = pResult->Next();
821     //
822     };
823     pResult->Delete();
824     };
825     //
826     myquery.str("");
827     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;";
828     //
829     pResult = dbc->Query(myquery.str().c_str());
830     //
831     i = 0;
832     if( pResult ){
833     //
834     Row = pResult->Next();
835     //
836     while ( Row ){
837     //
838     // store infos and exit
839     //
840     l0fid[i] = (UInt_t)atoll(Row->GetField(0));
841     i++;
842     Row = pResult->Next();
843     //
844     };
845     pResult->Delete();
846     };
847     //
848     i = 0;
849     UInt_t previd = 0;
850     while ( i < 10 ){
851     if ( l0fid[i] && previd != l0fid[i] ){
852     previd = l0fid[i];
853     myquery.str("");
854     myquery << "select PATH,NAME from GL_ROOT where ID=" << l0fid[i] << " ;";
855     //
856     pResult = dbc->Query(myquery.str().c_str());
857     //
858     if( pResult ){
859     //
860     Row = pResult->Next();
861     //
862     if ( debug ) printf(" Using inclination informations from file: %s \n",(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1)).Data());
863     ch->Add(((TString)gSystem->ExpandPathName(Row->GetField(0)))+"/"+(TString)Row->GetField(1));
864     //
865     pResult->Delete();
866     };
867     };
868     i++;
869     };
870     //
871     // l0trm = (TTree*)l0File->Get("Mcmd");
872     // ch->ls();
873     ch->SetBranchAddress("Mcmd",&mcmdev);
874     // printf(" entries %llu \n", ch->GetEntries());
875     // l0trm = ch->GetTree();
876     // neventsm = l0trm->GetEntries();
877     neventsm = ch->GetEntries();
878     if ( debug ) printf(" entries %u \n", neventsm);
879 mocchiut 1.18 // neventsm = 0;
880 mocchiut 1.15 //
881     if (neventsm == 0){
882 mocchiut 1.18 if ( debug ) printf("InclinationInfo - WARNING: No quaternions in this File");
883     // l0File->Close();
884     code = 900;
885     // goto closeandexit;
886 mocchiut 1.15 }
887     //
888    
889 mocchiut 1.37 // l0trm->SetBranchAddress("Mcmd", &mcmdev);
890 mocchiut 1.18 // l0trm->SetBranchAddress("Header", &eh);
891 mocchiut 1.15 //
892     //
893     //
894 mocchiut 1.44
895     // UInt_t mctren = 0;
896     // UInt_t mcreen = 0;
897 mocchiut 1.64 // UInt_t numrec = 0;
898 mocchiut 1.15 //
899 mocchiut 1.64 // Double_t upperqtime = 0;
900 mocchiut 1.15 Double_t lowerqtime = 0;
901    
902 mocchiut 1.65 // Double_t incli = 0;
903     // oi = 0;
904     // UInt_t ooi = 0;
905 mocchiut 1.15 //
906 mocchiut 1.44 // init quaternions information from mcmd-packets
907 mocchiut 1.15 //
908     Bool_t isf = true;
909 mocchiut 1.65 // Int_t fgh = 0;
910 mocchiut 1.44
911     vector<Float_t> q0;
912     vector<Float_t> q1;
913     vector<Float_t> q2;
914     vector<Float_t> q3;
915     vector<Double_t> qtime;
916     vector<Float_t> qPitch;
917     vector<Float_t> qRoll;
918     vector<Float_t> qYaw;
919     vector<Int_t> qmode;
920    
921     Int_t nt = 0;
922    
923     UInt_t must = 0;
924    
925 mocchiut 1.15 //
926 mocchiut 1.1 // run over all the events of the run
927     //
928     if (verbose) printf("\n Ready to start! \n\n Processed events: \n\n");
929     //
930 mocchiut 1.44 //
931 mocchiut 1.5 for ( re = runinfo->EV_FROM; re < (runinfo->EV_FROM+runinfo->NEVENTS); re++){
932 mocchiut 1.1 //
933 mocchiut 1.5 if ( procev%1000 == 0 && procev > 0 && verbose ) printf(" %iK \n",procev/1000);
934 mocchiut 1.15 if ( debug ) printf(" %i \n",procev);
935 mocchiut 1.1 //
936 mocchiut 1.43 if ( l0head->GetEntry(re) <= 0 ) throw -36;
937 mocchiut 1.1 //
938     // absolute time of this event
939     //
940 mocchiut 1.5 ph = eh->GetPscuHeader();
941 mocchiut 1.15 atime = dbtime->DBabsTime(ph->GetOrbitalTime());
942 mocchiut 1.40 if ( debug ) printf(" %i absolute time \n",procev);
943 mocchiut 1.1 //
944     // paranoid check
945     //
946 mocchiut 1.34 if ( (atime > (runinfo->RUNTRAILER_TIME+1)) || (atime < (runinfo->RUNHEADER_TIME-1)) ) {
947 mocchiut 1.1 if (verbose) printf(" OrbitalInfo - WARNING: event at time outside the run time window, skipping it\n");
948 mocchiut 1.30 jumped++;
949 mocchiut 1.44 // debug = true;
950 mocchiut 1.7 continue;
951     }
952 mocchiut 1.30
953     //
954     // retrieve tof informations
955     //
956     if ( !reprocall ){
957     itr = nobefrun + (re - evfrom - jumped);
958     //itr = re-(46438+200241);
959     } else {
960     itr = runinfo->GetFirstEntry() + (re - evfrom - jumped);
961     };
962     //
963     if ( !standalone ){
964     if ( itr > nevtofl2 ){
965     if ( verbose ) printf(" OrbitalInfo - ERROR: no tof events with entry = %i in Level2 file\n",itr);
966     if ( debug ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
967     l0File->Close();
968 pam-mep 1.69 code = -904;
969 mocchiut 1.30 goto closeandexit;
970     };
971     //
972     tof->Clear();
973     //
974 emocchiutti 1.67 if ( ttof->GetEntry(itr) <= 0 ){
975     if ( verbose ) printf(" problems with tof tree entries... entry = %i in Level2 file\n",itr);
976     if ( verbose ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
977     throw -36;
978     }
979 mocchiut 1.30 //
980 pam-mep 1.69 }
981     //
982     // retrieve tracker informations
983     //
984     if ( !standalone ){
985     if ( itr > nevtrkl2 ){
986     if ( verbose ) printf(" OrbitalInfo - ERROR: no trk events with entry = %i in Level2 file\n",itr);
987     if ( debug ) printf(" nobefrun %u re %u evfrom %u jumped %u reprocall %i \n",nobefrun,re,evfrom,jumped,reprocall);
988     l0File->Close();
989     code = -905;
990     goto closeandexit;
991     };
992     //
993     trke->Clear();
994     //
995     if ( ttrke->GetEntry(itr) <= 0 ) throw -36;
996     //
997     }
998    
999    
1000 mocchiut 1.1 //
1001     procev++;
1002     //
1003     // start processing
1004     //
1005 mocchiut 1.40 if ( debug ) printf(" %i start processing \n",procev);
1006 mocchiut 1.3 orbitalinfo->Clear();
1007 mocchiut 1.5 //
1008 mocchiut 1.30 OrbitalInfoTrkVar *t_orb = new OrbitalInfoTrkVar();
1009     if( !(orbitalinfo->OrbitalInfoTrk) ) orbitalinfo->OrbitalInfoTrk = new TClonesArray("OrbitalInfoTrkVar",2);
1010     TClonesArray &tor = *orbitalinfo->OrbitalInfoTrk;
1011 pam-mep 1.69
1012     // Geomagnetic coordinates calculation variables
1013     GMtype_CoordSpherical CoordSpherical, DipoleSpherical;
1014     GMtype_CoordCartesian CoordCartesian, DipoleCartesian;
1015     GMtype_Model Model;
1016     GMtype_Pole Pole;
1017    
1018 mocchiut 1.30 //
1019 mocchiut 1.15 // Fill OBT, pkt_num and absTime
1020     //
1021 mocchiut 1.2 orbitalinfo->pkt_num = ph->GetCounter();
1022     orbitalinfo->OBT = ph->GetOrbitalTime();
1023 mocchiut 1.15 orbitalinfo->absTime = atime;
1024 mocchiut 1.40 if ( debug ) printf(" %i pktnum obt abstime \n",procev);
1025 mocchiut 1.15 //
1026     // Propagate the orbit from the tle time to atime, using SGP(D)4.
1027     //
1028 mocchiut 1.40 if ( debug ) printf(" %i sgp4 \n",procev);
1029 mocchiut 1.15 cCoordGeo coo;
1030 mocchiut 1.40 Float_t jyear=0.;
1031 mocchiut 1.7 //
1032     if(atime >= gltle->GetToTime()) {
1033 mocchiut 1.9 if ( !gltle->Query(atime, dbc) ){
1034 mocchiut 1.15 //
1035 mocchiut 1.9 // Compute the magnetic dipole moment.
1036 mocchiut 1.15 //
1037 mocchiut 1.40 if ( debug ) printf(" %i compute magnetic dipole moment \n",procev);
1038 mocchiut 1.9 UInt_t year, month, day, hour, min, sec;
1039 mocchiut 1.15 //
1040 mocchiut 1.9 TTimeStamp t = TTimeStamp(atime, kTRUE);
1041     t.GetDate(kTRUE, 0, &year, &month, &day);
1042     t.GetTime(kTRUE, 0, &hour, &min, &sec);
1043     jyear = (float) year
1044     + (month*31.+ (float) day)/365.
1045 mocchiut 1.44 + (hour*3600.+min*60.+(float)sec)/(24.*3600.*365.);
1046 mocchiut 1.15 //
1047 pam-mep 1.69 if ( debug ) printf(" %i compute magnetic dipole moment get dipole moment for year\n",procev);
1048 mocchiut 1.9 feldcof_(&jyear, &dimo); // get dipole moment for year
1049 pam-mep 1.69 if ( debug ) printf(" %i jyear %f dimo %f \n",procev,jyear,dimo);
1050     if ( debug ) printf(" %i compute magnetic dipole moment end\n",procev);
1051    
1052     GM_TimeAdjustCoefs(year, jyear, G0, G1, H1, &Model);
1053     GM_PoleLocation(Model, &Pole);
1054    
1055 mocchiut 1.9 } else {
1056     code = -56;
1057     goto closeandexit;
1058     };
1059 mocchiut 1.7 }
1060 mocchiut 1.15 coo = getCoo(atime, gltle->GetFromTime(), gltle->GetTle());
1061     //
1062     cOrbit orbits(*gltle->GetTle());
1063     //
1064     // synchronize with quaternions data
1065     //
1066 mocchiut 1.18 if ( isf && neventsm>0 ){
1067 mocchiut 1.15 //
1068     // First event
1069     //
1070     isf = false;
1071 mocchiut 1.64 // upperqtime = atime;
1072 mocchiut 1.15 lowerqtime = runinfo->RUNHEADER_TIME;
1073 mocchiut 1.44 for ( ik = 0; ik < neventsm; ik++){ //number of macrocommad packets
1074 mocchiut 1.43 if ( ch->GetEntry(ik) <= 0 ) throw -36;
1075 mocchiut 1.15 tmpSize = mcmdev->Records->GetEntries();
1076 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1077     numrec = tmpSize;
1078     if ( debug ) cout << "packet number " << ik <<"\tnumber of subpackets is " << numrec << endl;
1079     =======
1080 mocchiut 1.64 // numrec = tmpSize;
1081 pam-mep 1.69 >>>>>>> 1.68
1082 mocchiut 1.44 for (Int_t j3 = 0;j3<tmpSize;j3++){ //number of subpackets
1083 mocchiut 1.15 mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j3);
1084 mocchiut 1.38 if ( mcmdrc ){ // missing inclination bug [8RED 090116]
1085 pam-mep 1.69 //if ( debug ) printf(" pluto \n");
1086 mocchiut 1.44 if ((int)mcmdrc->ID1 == 226 && mcmdrc->Mcmd_Block_crc_ok == 1){ //Check that it is Inclination Packet
1087 pam-mep 1.69 L_QQ_Q_l_upper->fill(mcmdrc->McmdData);
1088 mocchiut 1.38 for (UInt_t ui = 0; ui < 6; ui++){
1089     if (ui>0){
1090     if (L_QQ_Q_l_upper->time[ui]>L_QQ_Q_l_upper->time[0]){
1091 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1092     //if ( debug ) printf(" here1 %i \n",ui);
1093     =======
1094 mocchiut 1.65 if ( debug ) printf(" here1 %i \n",ui);
1095 pam-mep 1.69 >>>>>>> 1.68
1096 mocchiut 1.44 Double_t u_time = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[ui]*1000-DeltaOBT*1000));
1097     Int_t recSize = recqtime.size();
1098 pam-mep 1.54 if(lowerqtime > recqtime[recSize-1]){
1099 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1100     // to avoid interpolation between bad quaternions arrays
1101     if(sqrt(pow(L_QQ_Q_l_upper->quat[ui][0],2)+pow(L_QQ_Q_l_upper->quat[ui][1],2)+pow(L_QQ_Q_l_upper->quat[ui][2],2)+pow(L_QQ_Q_l_upper->quat[ui][3],2))>0.99999){
1102     Int_t sizeqmcmd = qtime.size();
1103     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1104     qtime[sizeqmcmd]=u_time;
1105     q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
1106     q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
1107     q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
1108     q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
1109     qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1110     lowerqtime = u_time;
1111     orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1112     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]);
1113     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1114     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1115     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1116     }
1117     =======
1118 mocchiut 1.65 Int_t sizeqmcmd = qtime.size();
1119     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1120     qtime[sizeqmcmd]=u_time;
1121     q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
1122     q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
1123     q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
1124     q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
1125     qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1126     lowerqtime = u_time;
1127     orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1128     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]);
1129     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1130     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1131     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1132 pam-mep 1.69 >>>>>>> 1.68
1133 pam-mep 1.54 }
1134 mocchiut 1.44 for(Int_t mu = nt;mu<recSize;mu++){
1135     if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
1136 pam-mep 1.69 if(sqrt(pow(recq0[mu],2)+pow(recq1[mu],2)+pow(recq2[mu],2)+pow(recq3[mu],2))>0.99999){
1137     nt=mu;
1138     Int_t sizeqmcmd = qtime.size();
1139     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1140     qtime[sizeqmcmd]=recqtime[mu];
1141     q0[sizeqmcmd]=recq0[mu];
1142     q1[sizeqmcmd]=recq1[mu];
1143     q2[sizeqmcmd]=recq2[mu];
1144     q3[sizeqmcmd]=recq3[mu];
1145     qmode[sizeqmcmd]=-10;
1146     orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1147     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]);
1148     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1149     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1150     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1151     }
1152 mocchiut 1.44 }
1153     if(recqtime[mu]>=u_time){
1154 pam-mep 1.69 if(sqrt(pow(L_QQ_Q_l_upper->quat[ui][0],2)+pow(L_QQ_Q_l_upper->quat[ui][1],2)+pow(L_QQ_Q_l_upper->quat[ui][2],2)+pow(L_QQ_Q_l_upper->quat[ui][3],2))>0.99999){
1155     Int_t sizeqmcmd = qtime.size();
1156     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1157     qtime[sizeqmcmd]=u_time;
1158     q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][0];
1159     q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][1];
1160     q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][2];
1161     q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[ui][3];
1162     qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1163     lowerqtime = u_time;
1164     orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1165     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]);
1166     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1167     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1168     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1169     break;
1170     }
1171 mocchiut 1.38 }
1172     }
1173     }
1174     }else{
1175 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1176     //if ( debug ) printf(" here2 %i \n",ui);
1177     =======
1178 mocchiut 1.65 if ( debug ) printf(" here2 %i \n",ui);
1179 pam-mep 1.69 >>>>>>> 1.68
1180 mocchiut 1.44 Double_t u_time = dbtime->DBabsTime((UInt_t)(L_QQ_Q_l_upper->time[0]*1000-DeltaOBT*1000));
1181     if(lowerqtime>u_time)nt=0;
1182     Int_t recSize = recqtime.size();
1183 pam-mep 1.54 if(lowerqtime > recqtime[recSize-1]){
1184 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1185     if(sqrt(pow(L_QQ_Q_l_upper->quat[ui][0],2)+pow(L_QQ_Q_l_upper->quat[ui][1],2)+pow(L_QQ_Q_l_upper->quat[ui][2],2)+pow(L_QQ_Q_l_upper->quat[ui][3],2))>0.99999){
1186     Int_t sizeqmcmd = qtime.size();
1187     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1188     qtime[sizeqmcmd]=u_time;
1189     q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
1190     q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
1191     q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
1192     q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
1193     qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1194     lowerqtime = u_time;
1195     orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1196     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]);
1197     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1198     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1199     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1200     }
1201     =======
1202 mocchiut 1.65 Int_t sizeqmcmd = qtime.size();
1203     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1204     qtime[sizeqmcmd]=u_time;
1205     q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
1206     q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
1207     q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
1208     q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
1209     qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1210     lowerqtime = u_time;
1211     orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1212     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]);
1213     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1214     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1215     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1216 pam-mep 1.69 >>>>>>> 1.68
1217 pam-mep 1.54 }
1218 mocchiut 1.44 for(Int_t mu = nt;mu<recSize;mu++){
1219     if(recqtime[mu]>lowerqtime && recqtime[mu]<u_time){
1220 pam-mep 1.69 if(sqrt(pow(recq0[mu],2)+pow(recq1[mu],2)+pow(recq2[mu],2)+pow(recq3[mu],2))>0.99999){
1221     nt=mu;
1222     Int_t sizeqmcmd = qtime.size();
1223     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1224     qtime[sizeqmcmd]=recqtime[mu];
1225     q0[sizeqmcmd]=recq0[mu];
1226     q1[sizeqmcmd]=recq1[mu];
1227     q2[sizeqmcmd]=recq2[mu];
1228     q3[sizeqmcmd]=recq3[mu];
1229     qmode[sizeqmcmd]=-10;
1230     orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1231     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]);
1232     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1233     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1234     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1235     }
1236 mocchiut 1.44 }
1237     if(recqtime[mu]>=u_time){
1238 pam-mep 1.69 if(sqrt(pow(L_QQ_Q_l_upper->quat[0][0],2)+pow(L_QQ_Q_l_upper->quat[0][1],2)+pow(L_QQ_Q_l_upper->quat[0][2],2)+pow(L_QQ_Q_l_upper->quat[0][3],2))>0.99999){
1239     Int_t sizeqmcmd = qtime.size();
1240     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1241     qtime[sizeqmcmd]=u_time;
1242     q0[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][0];
1243     q1[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][1];
1244     q2[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][2];
1245     q3[sizeqmcmd]=L_QQ_Q_l_upper->quat[0][3];
1246     qmode[sizeqmcmd]=holeq(lowerqtime,qtime[sizeqmcmd],L_QQ_Q_l_lower,L_QQ_Q_l_upper,ui);
1247     lowerqtime = u_time;
1248     orbits.getPosition((double) (u_time - gltle->GetFromTime())/60., &eCi);
1249     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]);
1250     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1251     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1252     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1253     CopyQ(L_QQ_Q_l_lower,L_QQ_Q_l_upper);
1254     break;
1255     }
1256 mocchiut 1.15 }
1257     }
1258 mocchiut 1.44 }
1259 mocchiut 1.38 }
1260 mocchiut 1.15 }
1261 mocchiut 1.44 }
1262 pam-mep 1.69 //if ( debug ) cout << "subpacket " << j3 << "\t qtime = " << qtime[qtime.size()-1] << endl;
1263 mocchiut 1.15 }
1264 mocchiut 1.44 }
1265 mocchiut 1.47
1266 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1267     if(qtime.size()==0){ // in case if no orientation information in data
1268     //if ( debug ) cout << "qtime.size() = 0" << endl;
1269     for(UInt_t my=0;my<recqtime.size();my++){
1270     if(sqrt(pow(recq0[my],2)+pow(recq1[my],2)+pow(recq2[my],2)+pow(recq3[my],2))>0.99999){
1271     Int_t sizeqmcmd = qtime.size();
1272     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1273     qtime[sizeqmcmd]=recqtime[my];
1274     q0[sizeqmcmd]=recq0[my];
1275     q1[sizeqmcmd]=recq1[my];
1276     q2[sizeqmcmd]=recq2[my];
1277     q3[sizeqmcmd]=recq3[my];
1278     qmode[sizeqmcmd]=-10;
1279     orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1280     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]);
1281     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1282     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1283     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1284     }
1285     }
1286     =======
1287 mocchiut 1.47 if(qtime.size()==0){
1288 mocchiut 1.65 for(UInt_t my=0;my<recqtime.size();my++){
1289     Int_t sizeqmcmd = qtime.size();
1290     inclresize(qtime,q0,q1,q2,q3,qmode,qRoll,qPitch,qYaw);
1291     qtime[sizeqmcmd]=recqtime[my];
1292     q0[sizeqmcmd]=recq0[my];
1293     q1[sizeqmcmd]=recq1[my];
1294     q2[sizeqmcmd]=recq2[my];
1295     q3[sizeqmcmd]=recq3[my];
1296     qmode[sizeqmcmd]=-10;
1297     orbits.getPosition((double) (qtime[sizeqmcmd] - gltle->GetFromTime())/60., &eCi);
1298     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]);
1299     qRoll[sizeqmcmd]=RYPang_upper->Kren;
1300     qYaw[sizeqmcmd]=RYPang_upper->Ryskanie;
1301     qPitch[sizeqmcmd]=RYPang_upper->Tangazh;
1302     }
1303 pam-mep 1.69 >>>>>>> 1.68
1304 mocchiut 1.47 }
1305    
1306 mocchiut 1.49
1307 mocchiut 1.46 if ( debug ) printf(" puffi \n");
1308 mocchiut 1.44 Double_t tmin = 9999999999.;
1309     Double_t tmax = 0.;
1310     for(UInt_t tre = 0;tre<qtime.size();tre++){
1311     if(qtime[tre]>tmax)tmax = qtime[tre];
1312     if(qtime[tre]<tmin)tmin = qtime[tre];
1313     }
1314 pam-mep 1.69 // sorting quaternions by time
1315     Bool_t t = true;
1316     while(t){
1317     t=false;
1318     for(UInt_t i=0;i<qtime.size()-1;i++){
1319     if(qtime[i]>qtime[i+1]){
1320     Double_t tmpr = qtime[i];
1321     qtime[i]=qtime[i+1];
1322     qtime[i+1] = tmpr;
1323     tmpr = q0[i];
1324     q0[i]=q0[i+1];
1325     q0[i+1] = tmpr;
1326     tmpr = q1[i];
1327     q1[i]=q1[i+1];
1328     q1[i+1] = tmpr;
1329     tmpr = q2[i];
1330     q2[i]=q2[i+1];
1331     q2[i+1] = tmpr;
1332     tmpr = q3[i];
1333     q3[i]=q3[i+1];
1334     q3[i+1] = tmpr;
1335     tmpr = qRoll[i];
1336     qRoll[i]=qRoll[i+1];
1337     qRoll[i+1] = tmpr;
1338     tmpr = qYaw[i];
1339     qYaw[i]=qYaw[i+1];
1340     qYaw[i+1] = tmpr;
1341     tmpr = qPitch[i];
1342     qPitch[i]=qPitch[i+1];
1343     qPitch[i+1] = tmpr;
1344     t=true;
1345     }
1346     }
1347     }
1348    
1349     if ( debug ){
1350     cout << "we have loaded quaternions: size of quaternions set is "<< qtime.size() << endl;
1351     for(UInt_t i=0;i<qtime.size();i++) cout << qtime[i] << "\t";
1352     cout << endl << endl;
1353     Int_t lopu;
1354     cin >> lopu;
1355     }
1356 mocchiut 1.46
1357 mocchiut 1.44 } // if we processed first event
1358 pam-mep 1.60
1359 mocchiut 1.44
1360     //Filling Inclination information
1361     Double_t incli = 0;
1362 mocchiut 1.46 if ( qtime.size() > 1 ){
1363 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1364     if ( debug ) cout << "ok quaternions is exist and mu = " << must << endl;
1365     if ( debug ) cout << "qtimes[ " << qtime[0] << " , " << qtime[qtime.size()-1] << " ]\tatime = "<<atime<<endl;
1366     for(UInt_t mu = must;mu<qtime.size()-1;mu++){
1367     //if ( debug ) printf(" ??grfuffi %i sixe %i must %i \n",mu,qtime.size()-1,must);
1368     if(qtime[mu+1]>qtime[mu]){
1369     if ( debug ) cout << "qtime[" << mu << "] = " << qtime[mu] << "\tqtime[" << mu+1 << "] = " << qtime[mu+1] << "\tatime = " << atime << endl;
1370     if(atime<=qtime[mu+1] && atime>=qtime[mu]){
1371     if ( debug ) cout << "here we have found proper quaternions for interpolation: mu = "<<mu<<endl;
1372     must = mu;
1373     incli = (qPitch[mu+1]-qPitch[mu])/(qtime[mu+1]-qtime[mu]);
1374     orbitalinfo->theta = incli*atime+qPitch[mu+1]-incli*qtime[mu+1];
1375     incli = (qRoll[mu+1]-qRoll[mu])/(qtime[mu+1]-qtime[mu]);
1376     orbitalinfo->etha = incli*atime+qRoll[mu+1]-incli*qtime[mu+1];
1377     incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1378     orbitalinfo->phi = incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1379    
1380     incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1381     orbitalinfo->q0 = incli*atime+q0[mu+1]-incli*qtime[mu+1];
1382     incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1383     orbitalinfo->q1 = incli*atime+q1[mu+1]-incli*qtime[mu+1];
1384     incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1385     orbitalinfo->q2 = incli*atime+q2[mu+1]-incli*qtime[mu+1];
1386     incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1387     orbitalinfo->q3 = incli*atime+q3[mu+1]-incli*qtime[mu+1];
1388     Float_t tg = (qtime[mu+1]-qtime[mu])/1000.;
1389     if(tg>=1) tg=0.00;
1390     orbitalinfo->TimeGap = TMath::Min(TMath::Abs(qtime[mu+1])-atime,TMath::Abs(atime-qtime[mu]))+tg;//qtime[mu+1]-qtime[mu];
1391     orbitalinfo->mode = qmode[mu+1];
1392    
1393     //if(atime==qtime[mu] || atime==qtime[mu+1]) orbitalinfo->qkind = 0; else orbitalinfo->qkind=1;
1394     //if(qmode[mu+1]==-10) orbitalinfo->R10r = true;else orbitalinfo->R10r = false;
1395    
1396     break;
1397     }
1398     }
1399     }
1400     =======
1401 mocchiut 1.65 for(UInt_t mu = must;mu<qtime.size()-1;mu++){
1402     if ( debug ) printf(" ??grfuffi %i sixe %i must %i \n",mu,qtime.size()-1,must);
1403     if(qtime[mu+1]>qtime[mu]){
1404     if ( debug ) printf(" grfuffi2 %i \n",mu);
1405     if(atime<=qtime[mu+1] && atime>=qtime[mu]){
1406     must = mu;
1407     if ( debug ) printf(" grfuffi3 %i \n",mu);
1408     incli = (qPitch[mu+1]-qPitch[mu])/(qtime[mu+1]-qtime[mu]);
1409     orbitalinfo->theta = incli*atime+qPitch[mu+1]-incli*qtime[mu+1];
1410     incli = (qRoll[mu+1]-qRoll[mu])/(qtime[mu+1]-qtime[mu]);
1411     orbitalinfo->etha = incli*atime+qRoll[mu+1]-incli*qtime[mu+1];
1412     incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1413     orbitalinfo->phi = incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1414    
1415     incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1416     orbitalinfo->q0 = incli*atime+q0[mu+1]-incli*qtime[mu+1];
1417     incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1418     orbitalinfo->q1 = incli*atime+q1[mu+1]-incli*qtime[mu+1];
1419     incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1420     orbitalinfo->q2 = incli*atime+q2[mu+1]-incli*qtime[mu+1];
1421     incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1422     orbitalinfo->q3 = incli*atime+q3[mu+1]-incli*qtime[mu+1];
1423    
1424     orbitalinfo->TimeGap = qtime[mu+1]-qtime[mu];
1425     orbitalinfo->mode = qmode[mu+1];
1426     //if(qmode[mu+1]==-10) orbitalinfo->R10r = true;else orbitalinfo->R10r = false;
1427     //reserved for next versions Vitaly.
1428     /*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){
1429 mocchiut 1.44 //linear interpolation
1430     incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1431     orbitalinfo->q0 = incli*atime+q0[mu+1]-incli*qtime[mu+1];
1432     incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1433     orbitalinfo->q1 = incli*atime+q1[mu+1]-incli*qtime[mu+1];
1434     incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1435     orbitalinfo->q2 = incli*atime+q2[mu+1]-incli*qtime[mu+1];
1436     incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1437     orbitalinfo->q3 = incli*atime+q3[mu+1]-incli*qtime[mu+1];
1438 mocchiut 1.65 }else{
1439 mocchiut 1.44 //sine interpolation
1440     for(UInt_t mt=0;mt<q0sine.size();mt++){
1441 mocchiut 1.65 if(atime<=q0sine[mt].finishPoint && atime>=q0sine[mt].startPoint){
1442     if(!q0sine[mt].NeedFit)orbitalinfo->q0=q0sine[mt].A*sin(q0sine[mt].b*atime+q0sine[mt].c);else{
1443     incli = (q0[mu+1]-q0[mu])/(qtime[mu+1]-qtime[mu]);
1444     orbitalinfo->q0 = incli*atime+q0[mu+1]-incli*qtime[mu+1];
1445     }
1446     }
1447     if(atime<=q1sine[mt].finishPoint && atime>=q1sine[mt].startPoint){
1448     if(!q1sine[mt].NeedFit)orbitalinfo->q1=q1sine[mt].A*sin(q1sine[mt].b*atime+q1sine[mt].c);else{
1449     incli = (q1[mu+1]-q1[mu])/(qtime[mu+1]-qtime[mu]);
1450     orbitalinfo->q1 = incli*atime+q1[mu+1]-incli*qtime[mu+1];
1451     }
1452     }
1453     if(atime<=q2sine[mt].finishPoint && atime>=q2sine[mt].startPoint){
1454     if(!q2sine[mt].NeedFit)orbitalinfo->q2=q0sine[mt].A*sin(q2sine[mt].b*atime+q2sine[mt].c);else{
1455     incli = (q2[mu+1]-q2[mu])/(qtime[mu+1]-qtime[mu]);
1456     orbitalinfo->q2 = incli*atime+q2[mu+1]-incli*qtime[mu+1];
1457     }
1458     }
1459     if(atime<=q3sine[mt].finishPoint && atime>=q3sine[mt].startPoint){
1460     if(!q3sine[mt].NeedFit)orbitalinfo->q3=q0sine[mt].A*sin(q3sine[mt].b*atime+q3sine[mt].c);else{
1461     incli = (q3[mu+1]-q3[mu])/(qtime[mu+1]-qtime[mu]);
1462     orbitalinfo->q3 = incli*atime+q3[mu+1]-incli*qtime[mu+1];
1463     }
1464     }
1465     if(atime<=Yawsine[mt].finishPoint && atime>=Yawsine[mt].startPoint){
1466     if(!Yawsine[mt].NeedFit)orbitalinfo->phi=Yawsine[mt].A*sin(Yawsine[mt].b*atime+Yawsine[mt].c);else{
1467     incli = (qYaw[mu+1]-qYaw[mu])/(qtime[mu+1]-qtime[mu]);
1468     orbitalinfo->phi = incli*atime+qYaw[mu+1]-incli*qtime[mu+1];
1469     }
1470     }
1471 mocchiut 1.44 }
1472 mocchiut 1.65 }*/
1473     //q0testing->Fill(atime,orbitalinfo->q0,100);
1474     //q1testing->Fill(atime,orbitalinfo->q1,100);
1475     //Pitchtesting->Fill(atime,orbitalinfo->etha);
1476     //q2testing->Fill(atime,orbitalinfo->q2);
1477     //q3testing->Fill(atime,orbitalinfo->q3);
1478     if ( debug ) printf(" grfuffi4 %i \n",mu);
1479     break;
1480     }
1481     }
1482     }
1483 pam-mep 1.69 >>>>>>> 1.68
1484 mocchiut 1.46 }
1485 mocchiut 1.65 if ( debug ) printf(" grfuffi5 \n");
1486 mocchiut 1.30 //
1487     // ops no inclination information
1488     //
1489 mocchiut 1.65
1490 mocchiut 1.30 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 ){
1491 pam-mep 1.69 if ( debug ) cout << "ops no iclination information" << endl;
1492 mocchiut 1.30 orbitalinfo->mode = 10;
1493     orbitalinfo->q0 = -1000.;
1494     orbitalinfo->q1 = -1000.;
1495     orbitalinfo->q2 = -1000.;
1496     orbitalinfo->q3 = -1000.;
1497     orbitalinfo->etha = -1000.;
1498     orbitalinfo->phi = -1000.;
1499     orbitalinfo->theta = -1000.;
1500 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1501     orbitalinfo->TimeGap = -1000.;
1502     //orbitalinfo->qkind = -1000;
1503     };
1504     if ( debug ){
1505     Int_t lopu;
1506     cin >> lopu;
1507     }
1508     =======
1509 mocchiut 1.65 if ( debug ) printf(" grfuffi6 \n");
1510     }
1511 pam-mep 1.69 >>>>>>> 1.68
1512 mocchiut 1.30 //
1513 mocchiut 1.65 if ( debug ) printf(" filling \n");
1514 mocchiut 1.30 // #########################################################################################################################
1515 mocchiut 1.15 //
1516     // fill orbital positions
1517     //
1518 mocchiut 1.7 // Build coordinates in the right range. We want to convert,
1519     // longitude from (0, 2*pi) to (-180deg, 180deg). Altitude is
1520     // in meters.
1521     lon = (coo.m_Lon > M_PI) ? rad2deg(coo.m_Lon - 2*M_PI) : rad2deg(coo.m_Lon);
1522     lat = rad2deg(coo.m_Lat);
1523     alt = coo.m_Alt;
1524 pam-mep 1.69 <<<<<<< OrbitalInfoCore.cpp
1525    
1526     cOrbit orbits2(*gltle->GetTle());
1527     orbits2.getPosition((double) (atime - gltle->GetFromTime())/60., &eCi);
1528     Float_t x=eCi.getPos().m_x;
1529     Float_t y=eCi.getPos().m_y;
1530     Float_t z=eCi.getPos().m_z;
1531    
1532     TVector3 V(eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z);
1533     TVector3 Pos(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z);
1534    
1535     Float_t dlon=Pos.Phi()*TMath::RadToDeg()-lon;
1536    
1537     Pos.RotateZ(-dlon*TMath::DegToRad());
1538     V.RotateZ(-dlon*TMath::DegToRad());
1539     Float_t diro;
1540     if(V.Z()>0) diro=1; else diro=-1;
1541    
1542     // 10REDNEW
1543     Int_t errq=0;
1544     Int_t azim=0;;
1545     for(UInt_t mu = must;mu<RTtime2.size()-1;mu++){
1546     if(atime<=RTtime2[mu] && atime>=RTtime1[mu]){
1547     errq=RTerrq[mu];
1548     azim=RTazim[mu];
1549     }
1550     }
1551     orbitalinfo->errq = errq;
1552     orbitalinfo->azim = azim;
1553     orbitalinfo->qkind = 0;
1554    
1555     if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){
1556     =======
1557 mocchiut 1.65 if ( debug ) printf(" coord done \n");
1558 mocchiut 1.15 //
1559 mocchiut 1.7 if( lon<180 && lon>-180 && lat<90 && lat>-90 && alt>0 ){
1560 pam-mep 1.69 >>>>>>> 1.68
1561 mocchiut 1.15 //
1562 mocchiut 1.7 orbitalinfo->lon = lon;
1563     orbitalinfo->lat = lat;
1564 pam-mep 1.69 orbitalinfo->alt = alt;
1565     orbitalinfo->V = V;
1566    
1567     GMtype_CoordGeodetic location;
1568     location.lambda = lon;
1569     location.phi = lat;
1570     location.HeightAboveEllipsoid = alt;
1571    
1572     GM_GeodeticToSpherical(Ellip, location, &CoordSpherical);
1573     GM_SphericalToCartesian(CoordSpherical, &CoordCartesian);
1574     GM_EarthCartToDipoleCartCD(Pole, CoordCartesian, &DipoleCartesian);
1575     GM_CartesianToSpherical(DipoleCartesian, &DipoleSpherical);
1576     orbitalinfo->londip = DipoleSpherical.lambda;
1577     orbitalinfo->latdip = DipoleSpherical.phig;
1578    
1579     if(debug)cout<<"geodetic:\t"<<lon<<"\t"<<lat<<"\tgeomagnetic:\t"<<orbitalinfo->londip<<"\t"<<orbitalinfo->latdip<<endl;
1580    
1581 mocchiut 1.15 //
1582 mocchiut 1.7 // compute mag field components and L shell.
1583 mocchiut 1.15 //
1584 mocchiut 1.65 if ( debug ) printf(" call igrf feldg \n");
1585 mocchiut 1.7 feldg_(&lat, &lon, &alt, &bnorth, &beast, &bdown, &babs);
1586 mocchiut 1.65 if ( debug ) printf(" call igrf shellg \n");
1587 mocchiut 1.7 shellg_(&lat, &lon, &alt, &dimo, &xl, &icode, &bab1);
1588 mocchiut 1.65 if ( debug ) printf(" call igrf findb \n");
1589 mocchiut 1.7 findb0_(&stps, &bdel, &value, &bequ, &rr0);
1590 mocchiut 1.15 //
1591 mocchiut 1.65 if ( debug ) printf(" done igrf \n");
1592 mocchiut 1.7 orbitalinfo->Bnorth = bnorth;
1593     orbitalinfo->Beast = beast;
1594     orbitalinfo->Bdown = bdown;
1595     orbitalinfo->Babs = babs;
1596 pam-mep 1.60 orbitalinfo->M = dimo;
1597 mocchiut 1.7 orbitalinfo->BB0 = babs/bequ;
1598 mocchiut 1.15 orbitalinfo->L = xl;
1599 mocchiut 1.7 // Set Stormer vertical cutoff using L shell.
1600 mocchiut 1.57 orbitalinfo->cutoffsvl = 14.295 / (xl*xl); //
1601 pam-mep 1.69 if(debug)cout << "L = " << xl << "\tM = " << dimo << "\tvertical cutoff: "<< orbitalinfo->cutoffsvl << endl;
1602    
1603 mocchiut 1.57 /*
1604 mocchiut 1.65 ---------- Forwarded message ----------
1605     Date: Wed, 09 May 2012 12:16:47 +0200
1606     From: Alessandro Bruno <alessandro.bruno@ba.infn.it>
1607     To: Mirko Boezio <mirko.boezio@ts.infn.it>
1608     Cc: Francesco S. Cafagna <Francesco.Cafagna@ba.infn.it>
1609     Subject: Störmer vertical cutoff
1610    
1611     Ciao Mirko,
1612     volevo segnalarti che il valore dello Störmer vertical cutoff nel Level2 è
1613     sovrastimato di circa il 4%.
1614     Dopo un'approfondita analisi con l'IGRF-05 abbiamo ricavano un valore pari
1615     a: 14.295 / L^2 anzichè 14.9 / L^2, valore obsoleto in quanto riferito agli
1616     anni '50.
1617     */
1618 mocchiut 1.57 //14.9/(xl*xl);
1619 mocchiut 1.56 orbitalinfo->igrf_icode = icode;
1620 mocchiut 1.15 //
1621 mocchiut 1.65 }
1622 pamelaprod 1.11 //
1623 mocchiut 1.40 if ( debug ) printf(" pitch angle \n");
1624     //
1625 mocchiut 1.30 // pitch angles
1626     //
1627 pam-mep 1.69 if( orbitalinfo->TimeGap>0){
1628 mocchiut 1.30 //
1629 mocchiut 1.65 if ( debug ) printf(" timegap %f \n",orbitalinfo->TimeGap);
1630 mocchiut 1.49 Float_t Bx = -orbitalinfo->Bdown;
1631     Float_t By = orbitalinfo->Beast;
1632     Float_t Bz = orbitalinfo->Bnorth;
1633 pam-mep 1.69
1634     TMatrixD Qiji(3,3);
1635     TMatrixD Qij = PO->QuatoECI(orbitalinfo->q0,orbitalinfo->q1,orbitalinfo->q2,orbitalinfo->q3);
1636     TMatrixD Dij = PO->ECItoGEO(Qij,orbitalinfo->absTime,orbitalinfo->lat,orbitalinfo->lon);
1637    
1638     //10REDNEW
1639     /* If initial orientation data have reason to be inaccurate */
1640     Double_t tg = 0;
1641     cout<<modf(orbitalinfo->TimeGap,&tg)<<endl;
1642     // if(orbitalinfo->TimeGap>0 && errq==0 && azim==0){ // 10RED CHECK (comparison between three metod of recovering orientation)
1643     if(((orbitalinfo->TimeGap>60.0 && TMath::Abs(orbitalinfo->etha)>0.5) || errq!=0 || modf(orbitalinfo->TimeGap,&tg)*1000>700 || modf(orbitalinfo->TimeGap,&tg)*1000==0.0 ) && azim==0){ //Standard condition to use this; One of these two cases should be commented
1644     /* found in Rotation Table this data for this time interval*/
1645     if(atime<RTtime1[0])
1646     orbitalinfo->azim = 5; //means that RotationTable no started yet
1647     else{
1648     for(UInt_t mu = must;mu<RTtime2.size()-1;mu++){
1649     if(atime<=RTtime2[mu] && atime>=RTtime1[mu]){
1650     // search for angle betwean velosity and direction to north in tangential to Earth surfase plane in satellite position
1651     Double_t tlat=orbitalinfo->lat;
1652     /* Double_t phint=(163.7-0.0002387*tlat-0.005802*tlat*tlat-0.005802e-7*tlat*tlat*tlat-1.776e-6*tlat*tlat*tlat*tlat+1.395e-10*tlat*tlat*tlat*tlat*tlat);
1653     Double_t phin=TMath::Abs(90.0*(1+diro)-phint);
1654     Double_t phi=TMath::Abs(90.0*(1-diro)-TMath::RadToDeg()*atan(TMath::Abs(tan(TMath::DegToRad()*phin))/sqrt(1+pow(tan(TMath::DegToRad()*tlat),2))));
1655    
1656     //Get vectors of Satellite reference frame axis in GEO in satndard case (No rotations, all Euler angles equals to 0)
1657     TVector3 XDij(0,sin(TMath::DegToRad()*phi),cos(TMath::DegToRad()*phi));
1658     TVector3 YDij(1,0,0);
1659     TVector3 ZDij(0,sin(TMath::DegToRad()*(phi+90)),cos(TMath::DegToRad()*(phi+90.0)));
1660    
1661     //Get Vectors to rotate about
1662     TVector3 B1 = V;
1663     B1.RotateZ(-lon*TMath::DegToRad());
1664     B1.RotateY(lat*TMath::DegToRad());
1665     Float_t elipangle=TMath::ACos((pow(B1.Y(),2)+pow(B1.Z(),2))/B1.Mag()/sqrt(pow(B1.Y(),2)+pow(B1.Z(),2)));
1666     TVector3 Tre(0,B1.Y(),B1.Z());
1667     if(B1.X()<0) elipangle=-elipangle;
1668     TVector3 Vperp=B1; // axis to rotate around initial Dij on ellip and spitch angles
1669     Vperp.RotateX(TMath::Pi()/2.);
1670     Vperp.SetX(0);
1671     */ Double_t kar=(RTbank2[mu]-RTbank1[mu])/(RTtime2[mu]-RTtime1[mu]);
1672     Double_t bak=RTbank1[mu]-kar*RTtime1[mu];
1673     Double_t bank=kar*atime+bak;
1674     Float_t spitch = 0.00001; // temprary not zero to avoid problem with tranzition from Euler angles to orientation matrix
1675    
1676     //Estimations of pitch angle of satellite
1677     if(TMath::Abs(bank)>0.7){
1678     Float_t spitch1=TMath::DegToRad()*0.7*RTdir1[mu];
1679     Float_t spitch2=TMath::DegToRad()*0.7*RTdir2[mu];
1680     Float_t kva=(spitch2-spitch1)/(RTtime2[mu]-RTtime1[mu]);
1681     Float_t bva=spitch1-kva*RTtime1[mu];
1682     spitch=kva*atime+bva;
1683     }
1684     /* //spitch=0.0;
1685     //Rotations future Dij matrix on ellip and spitch angles
1686     XDij.Rotate(-elipangle-spitch,Vperp);
1687     YDij.Rotate(-elipangle-spitch,Vperp);
1688     ZDij.Rotate(-elipangle-spitch,Vperp);
1689    
1690     //Rotation on bank angle;
1691     if(TMath::Abs(bank)>0.5){
1692     XDij.Rotate(TMath::DegToRad()*bank,B1);
1693     YDij.Rotate(TMath::DegToRad()*bank,B1);
1694     ZDij.Rotate(TMath::DegToRad()*bank,B1);
1695     }
1696     Dij(0,0)=XDij.X(); Dij(1,0)=XDij.Y(); Dij(2,0)=XDij.Z();
1697     Dij(0,1)=YDij.X(); Dij(1,1)=YDij.Y(); Dij(2,1)=YDij.Z();
1698     Dij(0,2)=ZDij.X(); Dij(1,2)=ZDij.Y(); Dij(2,2)=ZDij.Z();
1699     */
1700     //Calculate Yaw angle accordingly with fit, see picture FitYaw.jpg
1701     Double_t yaw=0.00001; // temprary not zero to avoid problem with tranzition from Euler angles to orientation matrix
1702     if(TMath::Abs(tlat)<70)
1703     yaw = -3.7e-8*tlat*tlat*tlat*tlat + 1.4e-7*tlat*tlat*tlat - 0.0005*tlat*tlat - 0.00025*tlat + 3.6;
1704     yaw = diro*yaw; //because should be different sign for ascending and descending orbits!
1705    
1706     if(TMath::Abs(bank)>0.5 && TMath::Abs(yaw-orbitalinfo->phi)<3.0) yaw=orbitalinfo->phi;
1707    
1708     // Qiji = PO->EulertoEci(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,bank,yaw,spitch); // 10RED CHECK
1709     Qij = PO->EulertoEci(eCi.getPos().m_x,eCi.getPos().m_y,eCi.getPos().m_z,eCi.getVel().m_x,eCi.getVel().m_y,eCi.getVel().m_z,bank,yaw,spitch); // STANDARD
1710     orbitalinfo->qkind = 1;
1711    
1712     break;
1713     }
1714     } // enf of loop for(UInt_t mu = must;mu<RTtime2.size()-1;mu++){
1715    
1716     //Qij = PO->GEOtoECI(Dij,orbitalinfo->absTime,orbitalinfo->lat,orbitalinfo->lon); // to convert from Dij to Qij
1717    
1718     } // end of if(atime<RTtime1[0]
1719     } // end of f(((orbitalinfo->TimeGap>60.0 && TMath...
1720    
1721     TMatrixD qij = PO->ColPermutation(Qij);
1722     TMatrixD Fij = PO->ECItoGreenwich(Qij,orbitalinfo->absTime);
1723 mocchiut 1.49 TMatrixD Gij = PO->ColPermutation(Fij);
1724 pam-mep 1.69 Dij = PO->ECItoGEO(Qij,orbitalinfo->absTime,orbitalinfo->lat,orbitalinfo->lon);
1725 mocchiut 1.30 TMatrixD Iij = PO->ColPermutation(Dij);
1726 pam-mep 1.69 TVector3 SP = PO->GetSunPosition(orbitalinfo->absTime);
1727     // go to Pamela reference frame from Resurs reference frame
1728     Float_t tmpy = SP.Y();
1729     SP.SetY(SP.Z());
1730     SP.SetZ(-tmpy);
1731     TVector3 SunZenith;
1732     SunZenith.SetMagThetaPhi(1,23.439281*TMath::DegToRad(),TMath::Pi()/2.);
1733     TVector3 SunMag = -SP;
1734     SunMag.Rotate(-45*TMath::DegToRad(),SunZenith);
1735     tmpy=SunMag.Y();
1736     SunMag.SetY(SunMag.Z());
1737     SunMag.SetZ(-tmpy);
1738    
1739 mocchiut 1.33 orbitalinfo->Iij.ResizeTo(Iij);
1740     orbitalinfo->Iij = Iij;
1741     //
1742 mocchiut 1.64 // A1 = Iij(0,2);
1743     // A2 = Iij(1,2);
1744     // A3 = Iij(2,2);
1745 mocchiut 1.49 //
1746 mocchiut 1.33 // orbitalinfo->pamzenitangle = (Float_t)PO->GetPitchAngle(1,0,0,A1,A2,A3); // Angle between zenit and Pamela's main axiz
1747     // orbitalinfo->pamBangle = (Float_t)PO->GetPitchAngle(A1,A2,A3,Bx,By,Bz); // Angle between Pamela's main axiz and B
1748 mocchiut 1.30 //
1749 mocchiut 1.65 if ( debug ) printf(" matrixes done \n");
1750 mocchiut 1.30 if ( !standalone && tof->ntrk() > 0 ){
1751 mocchiut 1.65 if ( debug ) printf(" !standalone \n");
1752 mocchiut 1.30 //
1753     Int_t nn = 0;
1754     for(Int_t nt=0; nt < tof->ntrk(); nt++){
1755     //
1756     ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1757 pam-mep 1.69 if (debug) cout<<"tof->ntrk() = "<<tof->ntrk()<<"\tptt->trkseqno = "<<ptt->trkseqno<<"\ttrke->ntrk() = "<<trke->ntrk()<<endl;
1758 mocchiut 1.30 Double_t E11x = ptt->xtr_tof[0]; // tr->x[0];
1759     Double_t E11y = ptt->ytr_tof[0]; //tr->y[0];
1760     Double_t E11z = zin[0];
1761     Double_t E22x = ptt->xtr_tof[3];//tr->x[3];
1762     Double_t E22y = ptt->ytr_tof[3];//tr->y[3];
1763     Double_t E22z = zin[3];
1764 mocchiut 1.32 if ( (E11x < 100. && E11y < 100. && E22x < 100. && E22y < 100.) || ptt->trkseqno != -1 ){
1765 pam-mep 1.69 TrkTrack *mytrack = trke->GetStoredTrack(ptt->trkseqno);
1766     Float_t rig=1/mytrack->GetDeflection();
1767 mocchiut 1.30 Double_t norm = sqrt(pow(E22x-E11x,2)+pow(E22y-E11y,2)+pow(E22z-E11z,2));
1768 mocchiut 1.44 // Double_t MyAzim = TMath::RadToDeg()*atan(TMath::Abs(E22y-E11y)/TMath::Abs(E22x-E11x));
1769     // if(E22x-E11x>=0 && E22y-E11y <0) MyAzim = 360. - MyAzim;
1770     // if(E22x-E11x>=0 && E22y-E11y >=0) MyAzim = MyAzim;
1771     // if(E22x-E11x<0 && E22y-E11y >0) MyAzim = 180. - MyAzim;
1772     // if(E22x-E11x<0 && E22y-E11y <0) MyAzim = 180. + MyAzim;
1773 mocchiut 1.30 Px = (E22x-E11x)/norm;
1774     Py = (E22y-E11y)/norm;
1775     Pz = (E22z-E11z)/norm;
1776     //
1777 mocchiut 1.33 t_orb->trkseqno = ptt->trkseqno;
1778     //
1779     TMatrixD Eij = PO->PamelatoGEO(Iij,Px,Py,Pz);
1780     t_orb->Eij.ResizeTo(Eij);
1781     t_orb->Eij = Eij;
1782     //
1783 pam-mep 1.51 TMatrixD Sij = PO->PamelatoGEO(Gij,Px,Py,Pz);
1784 mocchiut 1.33 t_orb->Sij.ResizeTo(Sij);
1785     t_orb->Sij = Sij;
1786 mocchiut 1.30 //
1787     t_orb->pitch = (Float_t)PO->GetPitchAngle(Eij(0,0),Eij(1,0),Eij(2,0),Bx,By,Bz);
1788 mocchiut 1.33 //
1789 pam-mep 1.69 // SunPosition in instrumental reference frame
1790     TMatrixD Kij = PO->PamelatoGEO(qij,Px,Py,Pz);
1791     TMatrixD Lij = PO->PamelatoGEO(qij,0,0,1);
1792     t_orb->sunangle=(Float_t)PO->GetPitchAngle(Kij(0,0),Kij(1,0),Kij(2,0),-SP.X(),-SP.Y(),-SP.Z());
1793     t_orb->sunmagangle=(Float_t)PO->GetPitchAngle(Kij(0,0),Kij(1,0),Kij(2,0),SunMag.X(),SunMag.Y(),SunMag.Z());
1794    
1795 mocchiut 1.33 //
1796     //
1797 pam-mep 1.69 //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);
1798     Double_t omega = PO->GetPitchAngle(-Eij(0,0),-Eij(1,0),-Eij(2,0),1,0,0) * TMath::DegToRad();
1799     TVector3 Bxy(0,By,Bz);
1800     TVector3 Exy(0,-Eij(1,0),-Eij(2,0));
1801     Double_t dzeta=Bxy.Angle(Exy);
1802     if (-Eij(1,0) < 0) dzeta=2.0*TMath::Pi() - dzeta;
1803    
1804     if(debug) cout << "omega = "<<omega*TMath::RadToDeg()<<"\tdzeta = "<<dzeta*TMath::RadToDeg()<<endl;
1805    
1806     // Formula from D.F. Smart *, M.A. Shea [2005]; A review of geomagnetic cutoff rigidities for earth-orbiting spacecraft
1807     if(rig>=0) t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow(1+sqrt(1-sin(omega)*sin(dzeta)*pow(cos(orbitalinfo->lat*TMath::DegToRad()),3)),2));
1808     else t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow(1+sqrt(1-sin(omega)*sin(TMath::Pi()+dzeta)*pow(cos(orbitalinfo->lat*TMath::DegToRad()),3)),2));
1809     if (debug) cout << "R = " << rig << "\tcutoff = " << t_orb->cutoff << endl;
1810    
1811     //t_orb->cutoff = 59.3/(pow(orbitalinfo->L,2)*pow((1+sqrt(1-pow(orbitalinfo->L,-3/2)*cos(omega))),2));
1812    
1813 mocchiut 1.33 //
1814 mocchiut 1.36 if ( t_orb->pitch != t_orb->pitch ) t_orb->pitch = -1000.;
1815     if ( t_orb->cutoff != t_orb->cutoff ) t_orb->cutoff = -1000.;
1816 pam-mep 1.69 if ( t_orb->sunangle != t_orb->sunangle ) t_orb->sunangle = -1000.;
1817     if ( t_orb->sunmagangle != t_orb->sunmagangle ) t_orb->sunmagangle = -1000.;
1818 mocchiut 1.36 //
1819 mocchiut 1.33 if ( debug ) printf(" orbitalinfo->cutoffsvl %f vitaly %f \n",orbitalinfo->cutoffsvl,t_orb->cutoff);
1820 mocchiut 1.30 //
1821     new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1822     nn++;
1823     //
1824     t_orb->Clear();
1825     //
1826     };
1827     //
1828     };
1829     } else {
1830 mocchiut 1.65 if ( debug ) printf(" mmm... mode %u standalone \n",orbitalinfo->mode);
1831     }
1832 mocchiut 1.30 //
1833 mocchiut 1.35 } else {
1834     if ( !standalone && tof->ntrk() > 0 ){
1835     //
1836     Int_t nn = 0;
1837     for(Int_t nt=0; nt < tof->ntrk(); nt++){
1838     //
1839     ToFTrkVar *ptt = tof->GetToFTrkVar(nt);
1840     if ( ptt->trkseqno != -1 ){
1841     //
1842     t_orb->trkseqno = ptt->trkseqno;
1843     //
1844     t_orb->Eij = 0;
1845     //
1846     t_orb->Sij = 0;
1847     //
1848     t_orb->pitch = -1000.;
1849     //
1850 pam-mep 1.69 t_orb->sunangle = -1000.;
1851     //
1852     t_orb->sunmagangle = -1000;
1853     //
1854 mocchiut 1.35 t_orb->cutoff = -1000.;
1855     //
1856     new(tor[nn]) OrbitalInfoTrkVar(*t_orb);
1857     nn++;
1858     //
1859     t_orb->Clear();
1860     //
1861     };
1862     //
1863     };
1864     };
1865 pam-mep 1.69 }; // if( orbitalinfo->TimeGap>0){
1866 mocchiut 1.30 //
1867 mocchiut 1.15 // Fill the class
1868 pamelaprod 1.11 //
1869 mocchiut 1.1 OrbitalInfotr->Fill();
1870 mocchiut 1.15 //
1871 mocchiut 1.30 delete t_orb;
1872     //
1873 mocchiut 1.15 }; // loop over the events in the run
1874 mocchiut 1.1 //
1875     // Here you may want to clear some variables before processing another run
1876     //
1877 mocchiut 1.44
1878 mocchiut 1.57 if ( verbose ) printf(" Clear before new run \n");
1879 mocchiut 1.5 delete dbtime;
1880 mocchiut 1.57
1881 mocchiut 1.62 if ( mcmdrc ) mcmdrc->Clear();
1882 mocchiut 1.57 mcmdrc = 0;
1883    
1884     if ( verbose ) printf(" Clear before new run1 \n");
1885     if ( L_QQ_Q_l_lower ) delete L_QQ_Q_l_lower;
1886     if ( verbose ) printf(" Clear before new run2 \n");
1887 mocchiut 1.18 if ( L_QQ_Q_l_upper ) delete L_QQ_Q_l_upper;
1888 mocchiut 1.57 if ( verbose ) printf(" Clear before new run3 \n");
1889 mocchiut 1.18 if ( RYPang_upper ) delete RYPang_upper;
1890 mocchiut 1.57 if ( verbose ) printf(" Clear before new run4 \n");
1891 mocchiut 1.18 if ( RYPang_lower ) delete RYPang_lower;
1892 mocchiut 1.57
1893     if ( l0tr ) l0tr->Delete();
1894    
1895     if ( verbose ) printf(" End run \n");
1896    
1897 mocchiut 1.1 }; // process all the runs
1898 mocchiut 1.15
1899 mocchiut 1.1 if (verbose) printf("\n Finished processing data \n");
1900     //
1901     closeandexit:
1902     //
1903     // 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.
1904     //
1905     if ( !reprocall && reproc && code >= 0 ){
1906     if ( totfileentries > noaftrun ){
1907     if (verbose){
1908     printf("\n Post-processing: copying events from the old tree after the processed run\n");
1909     printf(" Copying %i events in the file which are after the end of the run %i \n",(int)(totfileentries-noaftrun),(int)run);
1910     printf(" Start copying at event number %i end copying at event number %i \n",(int)noaftrun,(int)totfileentries);
1911     }
1912     for (UInt_t j = noaftrun; j < totfileentries; j++ ){
1913     //
1914     // Get entry from old tree
1915     //
1916 mocchiut 1.43 if ( OrbitalInfotrclone->GetEntry(j) <= 0 ) throw -36;
1917 mocchiut 1.1 //
1918     // copy orbitalinfoclone to OrbitalInfo
1919     //
1920 mocchiut 1.3 orbitalinfo->Clear();
1921 mocchiut 1.5 //
1922 mocchiut 1.1 memcpy(&orbitalinfo,&orbitalinfoclone,sizeof(orbitalinfoclone));
1923     //
1924     // Fill entry in the new tree
1925     //
1926     OrbitalInfotr->Fill();
1927     };
1928     if (verbose) printf(" Finished successful copying!\n");
1929     };
1930 mocchiut 1.57 //if ( OrbitalInfotrclone ) OrbitalInfotrclone->Clear();
1931     //if ( OrbitalInfotrclone ) OrbitalInfotrclone->Delete();
1932 mocchiut 1.1 };
1933     //
1934     // Close files, delete old tree(s), write and close level2 file
1935     //
1936 pam-mep 1.69
1937 mocchiut 1.1 if ( l0File ) l0File->Close();
1938 mocchiut 1.23 if ( myfold ) gSystem->Unlink(tempname.str().c_str());
1939 mocchiut 1.5 //
1940 mocchiut 1.1 if ( OrbitalInfotr ) OrbitalInfotr->SetName("OrbitalInfo");
1941 mocchiut 1.30 //
1942 mocchiut 1.1 if ( file ){
1943     file->cd();
1944 mocchiut 1.63 if ( OrbitalInfotr ) OrbitalInfotr->Write("OrbitalInfo", TObject::kOverwrite); // 10 RED bug fixed
1945 mocchiut 1.1 };
1946     //
1947 mocchiut 1.57 if (verbose) printf("\n Exiting...\n");
1948    
1949 mocchiut 1.23 if ( myfold ) gSystem->Unlink(OrbitalInfofolder.str().c_str());
1950 mocchiut 1.1 //
1951     // the end
1952     //
1953 mocchiut 1.25 if ( dbc ){
1954     dbc->Close();
1955     delete dbc;
1956     };
1957 mocchiut 1.57 //
1958 mocchiut 1.1 if (verbose) printf("\n Exiting...\n");
1959 mocchiut 1.57 if ( tempfile ) tempfile->Close();
1960    
1961 mocchiut 1.30 if ( PO ) delete PO;
1962 mocchiut 1.57 if ( gltle ) delete gltle;
1963     if ( glparam ) delete glparam;
1964     if ( glparam2 ) delete glparam2;
1965     if ( glparam3 ) delete glparam3;
1966     if (verbose) printf("\n Exiting3...\n");
1967 mocchiut 1.4 if ( glroot ) delete glroot;
1968 mocchiut 1.57 if (verbose) printf("\n Exiting4...\n");
1969     if ( runinfo ) runinfo->Close();
1970 mocchiut 1.4 if ( runinfo ) delete runinfo;
1971 mocchiut 1.58
1972 pam-mep 1.69 if ( tof ) delete tof;
1973     if ( trke ) delete trke;
1974    
1975 mocchiut 1.58 if ( debug ){
1976 mocchiut 1.57 cout << "1 0x" << OrbitalInfotr << endl;
1977     cout << "2 0x" << OrbitalInfotrclone << endl;
1978     cout << "3 0x" << l0tr << endl;
1979     cout << "4 0x" << tempOrbitalInfo << endl;
1980     cout << "5 0x" << ttof << endl;
1981 mocchiut 1.58 }
1982 mocchiut 1.57 //
1983 mocchiut 1.58 if ( debug ) file->ls();
1984 mocchiut 1.4 //
1985 mocchiut 1.1 if(code < 0) throw code;
1986     return(code);
1987     }
1988    
1989 mocchiut 1.7
1990     //
1991     // Returns the cCoordGeo structure holding the geographical
1992     // coordinates for the event (see sgp4.h).
1993     //
1994     // atime is the abstime of the event in UTC unix time.
1995     // tletime is the time of the tle in UTC unix time.
1996     // tle is the previous and nearest tle (compared to atime).
1997     cCoordGeo getCoo(UInt_t atime, UInt_t tletime, cTle *tle)
1998     {
1999     cEci eci;
2000     cOrbit orbit(*tle);
2001     orbit.getPosition((double) (atime - tletime)/60., &eci);
2002    
2003     return eci.toGeo();
2004     }
2005 mocchiut 1.15
2006     // function of copyng of quatrnions classes
2007    
2008     void CopyQ(Quaternions *Q1, Quaternions *Q2){
2009     for(UInt_t i = 0; i < 6; i++){
2010     Q1->time[i]=Q2->time[i];
2011     for (UInt_t j = 0; j < 4; j++)Q1->quat[i][j]=Q2->quat[i][j];
2012     }
2013     return;
2014     }
2015    
2016     // functions of copyng InclinationInfo classes
2017    
2018     void CopyAng(InclinationInfo *A1, InclinationInfo *A2){
2019     A1->Tangazh = A2->Tangazh;
2020     A1->Ryskanie = A2->Ryskanie;
2021     A1->Kren = A2->Kren;
2022     return;
2023     }
2024    
2025     UInt_t holeq(Double_t lower,Double_t upper,Quaternions *Qlower, Quaternions *Qupper, UInt_t f){
2026    
2027     UInt_t hole = 10;
2028 mocchiut 1.40 Bool_t R10l = false; // Sign of R10 mode in lower quaternions array
2029     Bool_t R10u = false; // Sign of R10 mode in upper quaternions array
2030     Bool_t insm = false; // Sign that we inside quaternions array
2031 mocchiut 1.64 // Bool_t mxtml = false; // Sign of mixt mode in lower quaternions array
2032     // Bool_t mxtmu = false; // Sign of mixt mode in upper quaternions array
2033 mocchiut 1.40 Bool_t npasm = false; // Sign of normall pass between R10 and non R10 or between non R10 and R10
2034 mocchiut 1.15 UInt_t NCQl = 6; // Number of correct quaternions in lower array
2035 mocchiut 1.64 // UInt_t NCQu = 6; // Number of correct quaternions in upper array
2036 mocchiut 1.15 if (f>0){
2037     insm = true;
2038     if(Qupper->time[f]-Qupper->time[f-1]==30) R10u = false;
2039     if(Qupper->time[f]-Qupper->time[f-1]<1) R10u = true;
2040     }else{
2041     insm = false;
2042     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]<2)) R10l = true;
2043     if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]<2)) R10u = true;
2044     if((Qlower->time[5]-Qlower->time[0]==150)&&(Qlower->time[1]-Qlower->time[0]==30)) R10l = false;
2045     if((Qupper->time[5]-Qupper->time[0]==150)&&(Qupper->time[1]-Qupper->time[0]==30)) R10u = false;
2046     if((Qlower->time[5]-Qlower->time[0]<2)&&(Qlower->time[1]-Qlower->time[0]==30)){
2047 mocchiut 1.64 // mxtml = true;
2048 mocchiut 1.15 for(UInt_t i = 1; i < 6; i++){
2049     if(Qlower->time[i]-Qlower->time[0]==30*i) NCQl=i;
2050     }
2051     }
2052 mocchiut 1.64 // if((Qupper->time[5]-Qupper->time[0]<2)&&(Qupper->time[1]-Qupper->time[0]==30)){
2053     // mxtmu = true;
2054     // for(UInt_t i = 1; i < 6; i++){
2055     // if(Qupper->time[i]-Qupper->time[0]==30*i) NCQu=i;
2056     // }
2057     // }
2058 mocchiut 1.15 }
2059    
2060     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;
2061    
2062    
2063     if (R10u&&insm) hole=0; // best event R10
2064     if ((upper-lower<=5)&&(!insm)&&R10l&&R10u) hole = 1; // when first of 6 quaternions in array is correct
2065     if (((!R10u)&&insm)||((!insm)&&(!R10u)&&(!R10l)&&((upper-lower==210+(6-NCQl)*30)||(upper-lower==30)))) hole = 2; //non R10
2066     if (npasm&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 3; //normall pass from R10 to non R10 or from non R10 to R10
2067     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
2068     if ((upper-lower>=300)&&(!insm)&&((R10l&&!R10u)||(R10u&&!R10l))) hole = 5; //uneliminable hole between R10 and non R10 or between non R10 and R10
2069     if ((upper-lower>5)&&(upper-lower<=300)&&R10u&&R10l) hole = 6; // eliminable hole inside R10
2070     if ((upper-lower>300)&&R10u&&R10l) hole = 7; //uneliminable hole inside R10
2071     if ((upper-lower>210)&&(upper-lower<=1200)&&(!R10u)&&(!R10l)) hole = 8; //eliminable hole inside non R10
2072     if ((upper-lower>1200)&&!R10u&&!R10l) hole = 9; // uneliminable hole inside non R10
2073     return hole;
2074     }
2075    
2076 mocchiut 1.44 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){
2077     Int_t sizee = t.size()+1;
2078     t.resize(sizee);
2079     q0.resize(sizee);
2080     q1.resize(sizee);
2081     q2.resize(sizee);
2082     q3.resize(sizee);
2083     mode.resize(sizee);
2084     Roll.resize(sizee);
2085     Pitch.resize(sizee);
2086     Yaw.resize(sizee);
2087     }
2088    
2089 pam-mep 1.69 // geomagnetic calculation staff
2090    
2091     //void GM_ScanIGRF(TString PATH, GMtype_Data *G0, GMtype_Data *G1, GMtype_Data *H1)
2092     void GM_ScanIGRF(TSQLServer *dbc, GMtype_Data *G0, GMtype_Data *G1, GMtype_Data *H1)
2093     {
2094     GL_PARAM *glp = new GL_PARAM();
2095     Int_t parerror=glp->Query_GL_PARAM(1,304,dbc); // parameters stored in DB in GL_PRAM table
2096     if ( parerror<0 ) {
2097     throw -902;
2098     }
2099     /*This function scans inputs G0, G1, and H1 of the IGRF table into 3 data arrays*/
2100     // TString SATH="/data03/Malakhov/pam9Malakhov/installed10/calib/orb-param/";
2101     int i;
2102     double temp;
2103     char buffer[200];
2104     FILE *IGRF;
2105     IGRF = fopen((glp->PATH+glp->NAME).Data(), "r");
2106     // IGRF = fopen(PATH+"IGRF.tab", "r");
2107     G0->size = 25;
2108     G1->size = 25;
2109     H1->size = 25;
2110     for( i = 0; i < 4; i++)
2111     {
2112     fgets(buffer, 200, IGRF);
2113 mocchiut 1.44 }
2114 pam-mep 1.69 fscanf(IGRF, "g 1 0 %lf ", &G0->element[0]);
2115     for(i = 1; i <= 22; i++)
2116     {
2117     fscanf(IGRF ,"%lf ", &G0->element[i]);
2118 mocchiut 1.44 }
2119 pam-mep 1.69 fscanf(IGRF ,"%lf\n", &temp);
2120     G0->element[23] = temp * 5 + G0->element[22];
2121     G0->element[24] = G0->element[23] + 5 * temp;
2122     fscanf(IGRF, "g 1 1 %lf ", &G1->element[0]);
2123     for(i = 1; i <= 22; i++)
2124     {
2125     fscanf( IGRF, "%lf ", &G1->element[i]);
2126 mocchiut 1.44 }
2127 pam-mep 1.69 fscanf(IGRF, "%lf\n", &temp);
2128     G1->element[23] = temp * 5 + G1->element[22];
2129     G1->element[24] = temp * 5 + G1->element[23];
2130     fscanf(IGRF, "h 1 1 %lf ", &H1->element[0]);
2131     for(i = 1; i <= 22; i++)
2132     {
2133     fscanf( IGRF, "%lf ", &H1->element[i]);
2134 mocchiut 1.44 }
2135 pam-mep 1.69 fscanf(IGRF, "%lf\n", &temp);
2136     H1->element[23] = temp * 5 + H1->element[22];
2137     H1->element[24] = temp * 5 + H1->element[23];
2138     if ( glp ) delete glp;
2139     } /*GM_ScanIGRF*/
2140    
2141     void GM_SetEllipsoid(GMtype_Ellipsoid *Ellip)
2142     {
2143     /*This function sets the WGS84 reference ellipsoid to its default values*/
2144     Ellip->a = 6378.137; /*semi-major axis of the ellipsoid in */
2145     Ellip->b = 6356.7523142;/*semi-minor axis of the ellipsoid in */
2146     Ellip->fla = 1/298.257223563;/* flattening */
2147     Ellip->eps = sqrt(1- ( Ellip->b * Ellip->b) / (Ellip->a * Ellip->a )); /*first eccentricity */
2148     Ellip->epssq = (Ellip->eps * Ellip->eps); /*first eccentricity squared */
2149     Ellip->re = 6371.2;/* Earth's radius */
2150     } /*GM_SetEllipsoid*/
2151    
2152    
2153     void GM_EarthCartToDipoleCartCD(GMtype_Pole Pole, GMtype_CoordCartesian EarthCoord, GMtype_CoordCartesian *DipoleCoords)
2154     {
2155     /*This function converts from Earth centered cartesian coordinates to dipole centered cartesian coordinates*/
2156     double X, Y, Z, CosPhi, SinPhi, CosLambda, SinLambda;
2157     CosPhi = cos(TMath::DegToRad()*Pole.phi);
2158     SinPhi = sin(TMath::DegToRad()*Pole.phi);
2159     CosLambda = cos(TMath::DegToRad()*Pole.lambda);
2160     SinLambda = sin(TMath::DegToRad()*Pole.lambda);
2161     X = EarthCoord.x;
2162     Y = EarthCoord.y;
2163     Z = EarthCoord.z;
2164    
2165     /*These equations are taken from a document by Wallace H. Campbell*/
2166     DipoleCoords->x = X * CosPhi * CosLambda + Y * CosPhi * SinLambda - Z * SinPhi;
2167     DipoleCoords->y = -X * SinLambda + Y * CosLambda;
2168     DipoleCoords->z = X * SinPhi * CosLambda + Y * SinPhi * SinLambda + Z * CosPhi;
2169     } /*GM_EarthCartToDipoleCartCD*/
2170    
2171     void GM_GeodeticToSpherical(GMtype_Ellipsoid Ellip, GMtype_CoordGeodetic CoordGeodetic, GMtype_CoordSpherical *CoordSpherical)
2172     {
2173     double CosLat, SinLat, rc, xp, zp; /*all local variables */
2174     /*
2175     ** Convert geodetic coordinates, (defined by the WGS-84
2176     ** reference ellipsoid), to Earth Centered Earth Fixed Cartesian
2177     ** coordinates, and then to spherical coordinates.
2178     */
2179    
2180     CosLat = cos(TMath::DegToRad()*CoordGeodetic.phi);
2181     SinLat = sin(TMath::DegToRad()*CoordGeodetic.phi);
2182    
2183     /* compute the local radius of curvature on the WGS-84 reference ellipsoid */
2184    
2185     rc = Ellip.a / sqrt(1.0 - Ellip.epssq * SinLat * SinLat);
2186    
2187     /* compute ECEF Cartesian coordinates of specified point (for longitude=0) */
2188    
2189     xp = (rc + CoordGeodetic.HeightAboveEllipsoid) * CosLat;
2190     zp = (rc*(1.0 - Ellip.epssq) + CoordGeodetic.HeightAboveEllipsoid) * SinLat;
2191    
2192     /* compute spherical radius and angle lambda and phi of specified point */
2193    
2194     CoordSpherical->r = sqrt(xp * xp + zp * zp);
2195     CoordSpherical->phig = TMath::RadToDeg()*asin(zp / CoordSpherical->r); /* geocentric latitude */
2196     CoordSpherical->lambda = CoordGeodetic.lambda; /* longitude */
2197     } /*GM_GeodeticToSpherical*/
2198    
2199     void GM_PoleLocation(GMtype_Model Model, GMtype_Pole *Pole)
2200     {
2201     /*This function finds the location of the north magnetic pole in spherical coordinates. The equations are
2202     **from Wallace H. Campbell's Introduction to Geomagnetic Fields*/
2203    
2204     Pole->phi = TMath::RadToDeg()*-atan(sqrt(Model.h1 * Model.h1 + Model.g1 * Model.g1)/Model.g0);
2205     Pole->lambda = TMath::RadToDeg()*atan(Model.h1/Model.g1);
2206     } /*GM_PoleLocation*/
2207    
2208     void GM_SphericalToCartesian(GMtype_CoordSpherical CoordSpherical, GMtype_CoordCartesian *CoordCartesian)
2209     {
2210     /*This function converts spherical coordinates into Cartesian coordinates*/
2211     double CosPhi = cos(TMath::DegToRad()*CoordSpherical.phig);
2212     double SinPhi = sin(TMath::DegToRad()*CoordSpherical.phig);
2213     double CosLambda = cos(TMath::DegToRad()*CoordSpherical.lambda);
2214     double SinLambda = sin(TMath::DegToRad()*CoordSpherical.lambda);
2215    
2216     CoordCartesian->x = CoordSpherical.r * CosPhi * CosLambda;
2217     CoordCartesian->y = CoordSpherical.r * CosPhi * SinLambda;
2218     CoordCartesian->z = CoordSpherical.r * SinPhi;
2219     } /*GM_SphericalToCartesian*/
2220    
2221     void GM_TimeAdjustCoefs(Float_t year, Float_t jyear, GMtype_Data g0d, GMtype_Data g1d, GMtype_Data h1d, GMtype_Model *Model)
2222     {
2223     /*This function calls GM_LinearInterpolation for the coefficients to estimate the value of the
2224     **coefficient for the given date*/
2225     int index;
2226     double x;
2227     index = (year - GM_STARTYEAR) / 5;
2228     x = (jyear - GM_STARTYEAR) / 5;
2229     Model->g0 = GM_LinearInterpolation(index, index+1, g0d.element[index], g0d.element[index+1], x);
2230     Model->g1 = GM_LinearInterpolation(index, index+1, g1d.element[index], g1d.element[index+1], x);
2231     Model->h1 = GM_LinearInterpolation(index, index+1, h1d.element[index], h1d.element[index+1], x);
2232     } /*GM_TimeAdjustCoefs*/
2233    
2234     double GM_LinearInterpolation(double x1, double x2, double y1, double y2, double x)
2235     {
2236     /*This function takes a linear interpolation between two given points for x*/
2237     double weight, y;
2238     weight = (x - x1) / (x2 - x1);
2239     y = y1 * (1 - weight) + y2 * weight;
2240     return y;
2241     }/*GM_LinearInterpolation*/
2242 mocchiut 1.44
2243 pam-mep 1.69 void GM_CartesianToSpherical(GMtype_CoordCartesian CoordCartesian, GMtype_CoordSpherical *CoordSpherical)
2244     {
2245     /*This function converts a point from Cartesian coordinates into spherical coordinates*/
2246     double X, Y, Z;
2247    
2248     X = CoordCartesian.x;
2249     Y = CoordCartesian.y;
2250     Z = CoordCartesian.z;
2251    
2252     CoordSpherical->r = sqrt(X * X + Y * Y + Z * Z);
2253     CoordSpherical->phig = TMath::RadToDeg()*asin(Z / (CoordSpherical->r));
2254     CoordSpherical->lambda = TMath::RadToDeg()*atan2(Y, X);
2255     } /*GM_CartesianToSpherical*/

  ViewVC Help
Powered by ViewVC 1.1.23