--- quicklook/dataToXML/OrbitalRate.cpp 2006/05/31 07:11:04 1.4 +++ quicklook/dataToXML/OrbitalRate.cpp 2006/06/30 13:19:25 1.5 @@ -22,12 +22,14 @@ #include "cTle.h" #include "cEci.h" #include "cOrbit.h" +#include "cJulian.h" #include "TH2F.h" #include "TFrame.h" #include "TGraph.h" #include "TCanvas.h" #include "TASImage.h" #include "TMarker.h" +#include #include "TString.h" #include "TObjString.h" @@ -105,18 +107,18 @@ } -void Rate(TString base, TString outDirectory = "", TString format = "jpg", TString mapFile = "", TString tleFile = ""){ +void Rate(TString base, TString outDirectory = "", TString format = "jpg", TString mapFile = "", TString tleFile = "", int offDate = 20060614, int offTime = 210000){ TTree *tr = 0; pamela::McmdEvent *mcmdev = 0; pamela::McmdRecord *mcmdrc = 0; - TArrayC *mcmddata = 0; + pamela::EventHeader *eh = 0; + pamela::PscuHeader *ph = 0; + TArrayC *mcmddata; ULong64_t nevents = 0; - ULong64_t timesync = 0; - pamela::EventHeader *eh = 0; - pamela::PscuHeader *ph = 0; + double timesync = 0; stringstream oss; double offsetTime = 0; - double absTime; + double absTime = 0; UInt_t i = 0; UInt_t j = 0; struct stat buf; @@ -130,10 +132,10 @@ TString filename = ((TObjString*)base.Tokenize('/')->Last())->GetString(); filename = ((TObjString*)filename.Tokenize('.')->First())->GetString(); - // Test SGP4 - string str1 = "SGP4 Test"; - string str2 = "1 25544U 98067A 06117.32388940 .00009459 00000-0 64427-4 0 8131"; - string str3 = "2 25544 51.6388 89.2928 0009043 155.3293 354.6512 15.75673697425143"; + + string str1 = "RESURS-DK 1"; + string str2 = "1 29228U 06021A 06166.45315890 -.00001271 40192-5 00000+0 0 12"; + string str3 = "2 29228 069.9476 065.6885 0106036 060.6946 300.4810 16.02948390 10"; if (tleFile != ""){ fstream fileTle(tleFile.Data(),ios::in); if (fileTle.is_open()) { @@ -170,17 +172,30 @@ recEntries = mcmdev->Records->GetEntries(); while (j < recEntries){ mcmdrc = (pamela::McmdRecord*)mcmdev->Records->At(j); - if (not (mcmdrc == NULL) && mcmdrc->ID1 == 0xE0){ - mcmddata = mcmdrc->McmdData; - timesync = (((ULong64_t)mcmddata->At(0)<<24)&0xFF000000) + - (((ULong64_t)mcmddata->At(1)<<16)&0x00FF0000) + - (((ULong64_t)mcmddata->At(2)<<8)&0x0000FF00) + - (((ULong64_t)mcmddata->At(3))&0x000000FF); - offsetTime = timesync - (mcmdrc->MCMD_RECORD_OBT)*(1./1000.); - timeFound = TRUE; + //mcmddata = mcmdrc->McmdData; + //printf(" timesync TimeSync %i \n", (unsigned int)mcmddata->At(0)); + //It is a TimeSync? + if ((mcmdrc != 0) && (mcmdrc->ID1 == 0xE0)){ + mcmddata = mcmdrc->McmdData; + timesync = (((unsigned int)mcmddata->At(0)<<24)&0xFF000000) + (((unsigned int)mcmddata->At(1)<<16)&0x00FF0000) + (((unsigned int)mcmddata->At(2)<<8)&0x0000FF00) + (((unsigned int)mcmddata->At(3))&0x000000FF); + timesync = timesync - (mcmdrc->MCMD_RECORD_OBT)*(1./1000.); + timeFound = TRUE; + //printf(" timesync TimeSync %i \n", timesync); + } + + //It is an Inclination Mcmd? + if ((mcmdrc != 0) && (mcmdrc->ID1 == 0xE2)){ + mcmddata = mcmdrc->McmdData; + timesync = (((mcmddata->At(0) << 24) & 0xFF000000) + ((mcmddata->At(1) << 16) & 0x00FF0000) + ((mcmddata->At(2) << 8) & 0x0000FF00) + (mcmddata->At(3) & 0x000000FF))/128.0; + timesync = timesync - (mcmdrc->MCMD_RECORD_OBT)*(1./1000.); + timeFound = TRUE; + //printf(" timesync Inclination %16.8f \n", timesync); } - j++; + + if (timeFound) break; + j++; } + if (timeFound) break; i++; } @@ -188,24 +203,42 @@ printf("No timesync info have been found in the file %s", base.Data()); exit(0); } + + //printf("%d \n", tle1.getField(cTle::FLD_EPOCHYEAR)); + //printf("%d \n", tle1.getField(cTle::FLD_EPOCHDAY)); + //Get the Julian date of the TLE Epoch + cJulian offTLE = cJulian(((int)tle1.getField(cTle::FLD_EPOCHYEAR) + 2000), tle1.getField(cTle::FLD_EPOCHDAY)); + //cJulian offTLE = cJulian(2006, 178.79019958); + + + //Get the Julian date of the Resours offset + TDatime offRes = TDatime(offDate, offTime); + cJulian offResours = cJulian(offRes.GetYear(), offRes.GetMonth(), offRes.GetDay(), offRes.GetHour(), offRes.GetMinute(), offRes.GetSecond()); + //Add to the Resours Offset the seconds differece beetwen the timesynch from MCMD and the relative OBT + offResours.addSec(timesync); + //printf(" diff %16.8f \n", timesync); + + //Get the MINUTES past since the TLE Epoch + offsetTime = (offResours.getDate() - offTLE.getDate()) * 24.0 * 60.0; + printf(" offSET %16.8f \n", offsetTime); + + //printf(" offResours %16.8f \n", offResours.getDate()); + //printf(" offTLE %16.8f \n", offTLE.getDate()); tr = (TTree*)rootFile->Get("Physics"); TBranch *headBr = tr->GetBranch("Header"); tr->SetBranchAddress("Header", &eh); nevents = tr->GetEntries(); //Fill variables from root-ple for (i = 0; i < nevents; i++){ + //for (i = 0; i < 1000; i++){ tr->GetEntry(i); ph = eh->GetPscuHeader(); - absTime = ((ph->GetOrbitalTime()*(1./1000.)) + absTime)/60; + absTime = offsetTime + (ph->GetOrbitalTime()*(1./60000.)); + //printf(" absTime %16.8f \n", absTime); orbit.getPosition(absTime, &eci); coo = eci.toGeo(); - rate->Fill(rad2deg(coo.m_Lon), rad2deg(coo.m_Lat)); - /* - printf(" %16.8f %16.8f %16.8f\n", - rad2deg(coo.m_Lat), - rad2deg(coo.m_Lon), - coo.m_Alt); - */ + rate->Fill(rad2deg(coo.m_Lon) - 180.0 , rad2deg(coo.m_Lat)); + printf(" Time: %16.8f Lat: %16.8f Long: %16.8f Alt: %16.8f\n", absTime, rad2deg(coo.m_Lat), rad2deg(coo.m_Lon), coo.m_Alt); } double posx=-1000,posy=-1000,oldposx=-1000,oldposy=-1000; @@ -296,6 +329,8 @@ TString mapFile = ""; TString tleFile = ""; TString format = "jpg"; + int offDate = 20060614; + int offTime = 210000; if (argc < 2){ printf("You have to insert at least the file to analyze and the mapFile \n"); @@ -314,6 +349,8 @@ printf( "\t\t\t2 25544 51.6388 89.2928 0009043 155.3293 354.6512 15.75673697425143\n"); printf( "\t -outDir[path] Path where to put the output [default ~/tmp] \n"); printf( "\t -format[jpg|gif|ps] Format for output files [default 'jpg'] \n"); + printf( "\t -offDate Date of resetting of the Resource counter [format YYMMDD default 20060614] \n"); + printf( "\t -offTime Time of resetting of the Resource counter [format HHMMSS default 210000] \n"); exit(1); } @@ -340,6 +377,30 @@ } } + if (!strcmp(argv[i], "-offTime")){ + if (++i >= argc){ + printf( "-offTime needs arguments. \n"); + printf( "Try '--help' for more information. \n"); + exit(1); + } + else{ + offTime = atol(argv[i]); + continue; + } + } + + if (!strcmp(argv[i], "-offDate")){ + if (++i >= argc){ + printf( "-offDate needs arguments. \n"); + printf( "Try '--help' for more information. \n"); + exit(1); + } + else{ + offDate = atol(argv[i]); + continue; + } + } + if (!strcmp(argv[i], "-map")){ if (++i >= argc){ printf( "-map needs arguments. \n"); @@ -363,7 +424,7 @@ } } if (mapFile != ""){ - Rate(argv[1], outDir, format, mapFile); + Rate(argv[1], outDir, format, mapFile, tleFile, offDate, offTime); } else { printf("You have to insert at least the file to analyze and the mapFile \n"); printf("Try '--help' for more information. \n");