/[PAMELA software]/quicklook/OrbitalRate/src/OrbitalRate.cpp
ViewVC logotype

Diff of /quicklook/OrbitalRate/src/OrbitalRate.cpp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.6 by pam-rm2, Thu Mar 15 12:34:28 2007 UTC revision 1.9 by pam-rm2, Sun Nov 4 16:01:37 2007 UTC
# Line 324  void Rate(TString *filename, TString out Line 324  void Rate(TString *filename, TString out
324      exit(EXIT_FAILURE);      exit(EXIT_FAILURE);
325    }    }
326    
327    //Get the Julian date of the Resours offset    // Here I do: resurs offset + timesync
328    TDatime offRes = TDatime(offDate, offTime);    TDatime offRes = TDatime(offDate, offTime);
329    // Add to the Resours Offset the timesync.  This is now the date at    TTimeStamp offResTS = TTimeStamp(offRes.GetYear(), offRes.GetMonth(), offRes.GetDay(), offRes.GetHour(), offRes.GetMinute(), offRes.GetSecond(), 0, kTRUE, timesync);
330    // the moment of the timesync.  //   cout<<"timesync="<<timesync<<"  obt_timesync="<<obt_timesync<<endl;
331    offRes.Set(offRes.Convert() + (UInt_t) timesync);  //   cout<<"offResTS.GetSec()="<<offResTS.GetSec()<<endl;
332    //   cout<<"offResTS.AsString()="<<offResTS.AsString()<<endl<<endl;
333    
334    // Now I need a pointer to a cTle object.  The class misses a    // Now I need a pointer to a cTle object.  The class misses a
335    // constructor without arguments, so we have to give it a dummy TLE.    // constructor without arguments, so we have to give it a dummy TLE.
# Line 339  void Rate(TString *filename, TString out Line 340  void Rate(TString *filename, TString out
340    
341    // If we have to use a TLE file, call getTle().    // If we have to use a TLE file, call getTle().
342    if (tleFile != "")    if (tleFile != "")
343      tle1 = getTle(tleFile, offRes);      tle1 = getTle(tleFile, offResTS); // modify getTle() to use offResTS!
344      else
345        cout<<"OrbitalRate: Warning!!! No tle file supplied.\n";
346    
347      // Here I do: resurs offset + timesync - obt of the timesync
348      //  cout<<"here0 "<<offResTS.GetSec()<<endl;
349      //  offResTS.Set(offResTS.GetSec() - obt_timesync, kTRUE, 0, kFALSE);
350      offResTS.Set(offResTS.GetSec() - obt_timesync, kFALSE, 0, kFALSE);
351      //  cout<<"here1 "<<offResTS.GetSec()<<endl;
352    
353    cOrbit       orbit(*tle1);    cOrbit       orbit(*tle1);
354    cEci         eci;    cEci         eci;
355    cCoordGeo    coo;    cCoordGeo    coo;
356    
357    // offRes is now "offset date" + timesync.  Now I subtract the obt    // Here I do: resurs offset + timesync - obt of the timesync - tle time
358    // of the timesync.  Remember that the time of the event from the    TTimeStamp tledate = getTleDatetime(tle1);
   // tle date is:  
   // tle date - (offset date + timesync - obt timesync + obt event).  
   offRes.Set(offRes.Convert() - (UInt_t) obt_timesync);  
   
   // Get the Julian date of the TLE epoch  
   string datetime = getTleDatetime(tle1);  
   TDatime tledate = TDatime(datetime.c_str());  
   
359    cJulian jdatetime = cJulian((int) (tle1->getField(cTle::FLD_EPOCHYEAR)+2e3), tle1->getField(cTle::FLD_EPOCHDAY));    cJulian jdatetime = cJulian((int) (tle1->getField(cTle::FLD_EPOCHYEAR)+2e3), tle1->getField(cTle::FLD_EPOCHDAY));
360    int pYear, pMon; double pDOM;    int pYear, pMon; double pDOM;
361    jdatetime.getComponent(&pYear, &pMon, &pDOM);    jdatetime.getComponent(&pYear, &pMon, &pDOM);
362      offsetTime = ((Long64_t) offResTS.GetSec() - (Long64_t) tledate.GetSec());
363    offsetTime = ((Long64_t) offRes.Convert() - (Long64_t) tledate.Convert());  //   cerr<<"offsetTime="<<offsetTime<<endl
364    //       <<"offResTS.GetSec()="<<offResTS.GetSec()<<endl
365    //       <<"tledate.GetSec()="<<tledate.GetSec()<<endl<<endl;
366    
367    /********** Magnetic Field **************/    /********** Magnetic Field **************/
368    // Check that all this is correct!    // Check that all this is correct!
# Line 368  void Rate(TString *filename, TString out Line 371  void Rate(TString *filename, TString out
371    // I can now compute the magnetic dipole moment at the actual date,    // I can now compute the magnetic dipole moment at the actual date,
372    // using the cJulian date.  I don't to recompute it for every event    // using the cJulian date.  I don't to recompute it for every event
373    // beacause changes are not relevant at all.    // beacause changes are not relevant at all.
374    Int_t y = tledate.GetYear();    UInt_t y, m, d;
375    Int_t m = tledate.GetMonth();    tledate.GetDate(kTRUE, 0, &y, &m, &d);
   Int_t d = tledate.GetDay();  
376    float year = (float) y + (m*31+d)/365;    float year = (float) y + (m*31+d)/365;
377    
378    // Initialize common data for geopack    // Initialize common data for geopack
# Line 428  void Rate(TString *filename, TString out Line 430  void Rate(TString *filename, TString out
430        // event and the tle date.  I use seconds and not milliseconds        // event and the tle date.  I use seconds and not milliseconds
431        // because the indetermination on the timesync is about 1s.        // because the indetermination on the timesync is about 1s.
432        timeElapsedFromTLE = offsetTime + obt/1000;        timeElapsedFromTLE = offsetTime + obt/1000;
433          if(!i) cerr<<"1st event: timeElapsedFromTLE="<<timeElapsedFromTLE<<endl;
434    
435        // I also need the abstime in seconds rounded to the lower        // I also need the abstime in seconds rounded to the lower
436        // value.  Every second, we set a_second_is_over to true.  Only        // value.  Every second, we set a_second_is_over to true.  Only
# Line 730  void Rate(TString *filename, TString out Line 733  void Rate(TString *filename, TString out
733  // Scale() and Merge()).  // Scale() and Merge()).
734  //  //
735  // This function depends on InitStyle();  // This function depends on InitStyle();
736  int printHist(TH2F *h, TString mapFile, TString outDirectory, TString outputFilename, char *title, int width, int height, bool use_log, bool bool_shift)  int printHist(TH2F *h, TString mapFile, TString outDirectory, TString outputFilename, const char *title, int width, int height, bool use_log, bool bool_shift)
737  {  {
738    InitStyle();    InitStyle();
739    
# Line 828  void saveHist(TH1 *h, TString savetoroot Line 831  void saveHist(TH1 *h, TString savetoroot
831  // querying the database with the RESURS DK-1 id number 29228,  // querying the database with the RESURS DK-1 id number 29228,
832  // selecting the widest timespan, including the satellite name in the  // selecting the widest timespan, including the satellite name in the
833  // results.  // results.
834  cTle *getTle(TString tleFile, TDatime offRes)  cTle *getTle(TString tleFile, TTimeStamp offResTS)
835  {  {
836    Float_t tledatefromfile, tledatefromroot;    Float_t tledatefromfile, tledatefromroot;
837    fstream tlefile(tleFile.Data(), ios::in);    fstream tlefile(tleFile.Data(), ios::in);
# Line 858  cTle *getTle(TString tleFile, TDatime of Line 861  cTle *getTle(TString tleFile, TDatime of
861    // Sort by date    // Sort by date
862    sort(ctles.begin(), ctles.end(), compTLE);    sort(ctles.begin(), ctles.end(), compTLE);
863    
864    tledatefromroot = (offRes.GetYear()-2000)*1e3 + (offRes.Convert() - (TDatime(offRes.GetYear(), 1, 1, 0, 0, 0)).Convert())/ (24.*3600.);    UInt_t year, month, day;
865      offResTS.GetDate(kTRUE, 0, &year, &month, &day);
866      TTimeStamp firstofjan = TTimeStamp(year, 1, 1, 0, 0, 0);
867      tledatefromroot = (year-2000)*1e3 + (offResTS.GetSec() - firstofjan.GetSec())/(24.*3600.);
868    
869    for(iter = ctles.begin(); iter != ctles.end(); iter++) {    for(iter = ctles.begin(); iter != ctles.end(); iter++) {
870      cTle *tle = *iter;      cTle *tle = *iter;
# Line 902  float getTleJulian(cTle *tle) { Line 908  float getTleJulian(cTle *tle) {
908    
909  // Look for a timesync in the TFile rootFile.  Set timesync and  // Look for a timesync in the TFile rootFile.  Set timesync and
910  // obt_timesync.  Returns 1 if timesync is found, 0 otherwise.  // obt_timesync.  Returns 1 if timesync is found, 0 otherwise.
911  int lookforTimesync(TFile *rootFile, Float_t *timesync, Float_t *obt_timesync) {  UInt_t lookforTimesync(TFile *rootFile, Float_t *timesync, Float_t *obt_timesync) {
912    *timesync = -1;  // will be != -1 if found    *timesync = -1;  // will be != -1 if found
913    
914    ULong64_t             nevents    = 0;    ULong64_t             nevents    = 0;
# Line 973  TH2F* shiftHist(TH2F* h, Float_t shift) Line 979  TH2F* shiftHist(TH2F* h, Float_t shift)
979  }  }
980    
981    
982  // Return a string like YYYY-MM-DD hh:mm:ss, a datetime format.  //
983  string getTleDatetime(cTle *tle)  // Returns the tle date as a TTimeStamp object.
984    //
985    TTimeStamp getTleDatetime(cTle *tle)
986  {  {
987    int year, mon, day, hh, mm, ss;    int year, mon, day, hh, mm, ss;
988    double dom; // day of month (is double!)    double dom; // day of month (is double!)
# Line 994  string getTleDatetime(cTle *tle) Line 1002  string getTleDatetime(cTle *tle)
1002    ss = (int) floor( ((((dom - day) * 24 - hh) * 60 - mm) * 60));    ss = (int) floor( ((((dom - day) * 24 - hh) * 60 - mm) * 60));
1003    //  ms = (int) floor( (((((dom - day) * 24 - hh) * 60 - mm) * 60) - ss) * 1000);    //  ms = (int) floor( (((((dom - day) * 24 - hh) * 60 - mm) * 60) - ss) * 1000);
1004    
1005    date << year << "-" << mon << "-" << day << " " << hh << ":" << mm << ":" << ss;    TTimeStamp t = TTimeStamp(year, mon, day, hh, mm, ss, 0, true);
1006    
1007    return date.str();    return t;
1008  }  }
1009    
1010  //  //

Legend:
Removed from v.1.6  
changed lines
  Added in v.1.9

  ViewVC Help
Powered by ViewVC 1.1.23