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