+void AliTimestamp::SetNs(Int_t ns)
+{
+// Set the remaining fractional number of seconds in nanosecond precision.
+// Notes :
+// -------
+// 1) The allowed range for the argument "ns" is [0,99999999].
+// Outside that range no action is performed.
+// 2) The ns fraction can also be entered directly via SetMJD() etc...
+// 3) For additional accuracy see SetPs().
+
+ if (ns>=0 && ns<=99999999) fJns=ns;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliTimestamp::GetNs() const
+{
+// Provide the remaining fractional number of seconds in nanosecond precision.
+// This function allows trigger/timing analysis for (astro)particle physics
+// experiments.
+// Note : For additional accuracy see also GetPs().
+
+ return fJns;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::SetPs(Int_t ps)
+{
+// Set the remaining fractional number of nanoseconds in picoseconds.
+// Notes :
+// -------
+// 1) The allowed range for the argument "ps" is [0,999].
+// Outside that range no action is performed.
+// 2) The ps fraction can also be entered directly via SetMJD() etc...
+
+ if (ps>=0 && ps<=999) fJps=ps;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliTimestamp::GetPs() const
+{
+// Provide remaining fractional number of nanoseconds in picoseconds.
+// This function allows time of flight analysis for particle physics
+// experiments.
+
+ return fJps;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::Add(Int_t d,Int_t s,Int_t ns,Int_t ps)
+{
+// Add (or subtract) a certain time difference to the current timestamp.
+// Subtraction can be achieved by entering negative values as input arguments.
+//
+// The time difference is entered via the following input arguments :
+//
+// d : elapsed number of days
+// s : (remaining) elapsed number of seconds
+// ns : (remaining) elapsed number of nanoseconds
+// ps : (remaining) elapsed number of picoseconds
+//
+// The specified d, s, ns and ps values will be used in an additive
+// way to determine the time difference.
+// So, specification of d=1, s=100, ns=0, ps=0 will result in the
+// same time difference addition as d=0, s=24*3600+100, ns=0, ps=0.
+// However, by making use of the latter the user should take care
+// of possible integer overflow problems in the input arguments,
+// which obviously will provide incorrect results.
+//
+// Note : ps=0 is the default value.
+
+ Int_t days=0;
+ Int_t secs=0;
+ Int_t nsec=0;
+ // Use Get functions to ensure updated Julian parameters.
+ GetMJD(days,secs,nsec);
+ Int_t psec=GetPs();
+
+ psec+=ps%1000;
+ nsec+=ps/1000;
+ while (psec<0)
+ {
+ nsec-=1;
+ psec+=1000;
+ }
+ while (psec>999)
+ {
+ nsec+=1;
+ psec-=1000;
+ }
+
+ nsec+=ns%1000000000;
+ secs+=ns/1000000000;
+ while (nsec<0)
+ {
+ secs-=1;
+ nsec+=1000000000;
+ }
+ while (nsec>999999999)
+ {
+ secs+=1;
+ nsec-=1000000000;
+ }
+
+ secs+=s%(24*3600);
+ days+=s/(24*3600);
+ while (secs<0)
+ {
+ days-=1;
+ secs+=24*3600;
+ }
+ while (secs>=24*3600)
+ {
+ days+=1;
+ secs-=24*3600;
+ }
+
+ days+=d;
+
+ SetMJD(days,secs,nsec,psec);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::Add(Double_t hours)
+{
+// Add (or subtract) a certain time difference to the current timestamp.
+// The time difference is specified as a (fractional) number of hours.
+// Subtraction can be achieved by entering a negative value as input argument.
+
+ Int_t d,s,ns,ps;
+ Double_t h=fabs(hours);
+ d=int(h/24.);
+ h-=double(d)*24.;
+ h*=3600.;
+ s=int(h);
+ h-=double(s);
+ h*=1.e9;
+ ns=int(h);
+ h-=double(ns);
+ ps=int(h*1000.);
+ if (hours>0) Add(d,s,ns,ps);
+ if (hours<0) Add(-d,-s,-ns,-ps);
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliTimestamp::GetDifference(AliTimestamp* t,Int_t& d,Int_t& s,Int_t& ns,Int_t& ps)
+{
+// Provide the time difference w.r.t the AliTimestamp specified on the input.
+// This memberfunction supports both very small (i.e. time of flight analysis
+// for particle physics experiments) and very long (i.e. investigation of
+// astrophysical phenomena) timescales.
+//
+// The time difference is returned via the following output arguments :
+// d : elapsed number of days
+// s : remaining elapsed number of seconds
+// ns : remaining elapsed number of nanoseconds
+// ps : remaining elapsed number of picoseconds
+//
+// Note :
+// ------
+// The calculated time difference is the absolute value of the time interval.
+// This implies that the values of d, s, ns and ps are always positive or zero.
+//
+// The integer return argument indicates whether the AliTimestamp specified
+// on the input argument occurred earlier (-1), simultaneously (0) or later (1).
+
+ if (!t) return 0;
+
+ // Ensure updated Julian parameters for this AliTimestamp instance
+ if (fCalcs != GetSec() || fCalcns != GetNanoSec()) FillJulian();
+
+ // Use Get functions to ensure updated Julian parameters.
+ t->GetMJD(d,s,ns);
+ ps=t->GetPs();
+
+ d-=fMJD;
+ s-=fJsec;
+ ns-=fJns;
+ ps-=fJps;
+
+ if (!d && !s && !ns && !ps) return 0;
+
+ Int_t sign=0;
+
+ if (d>0) sign=1;
+ if (d<0) sign=-1;
+
+ if (!sign && s>0) sign=1;
+ if (!sign && s<0) sign=-1;
+
+ if (!sign && ns>0) sign=1;
+ if (!sign && ns<0) sign=-1;
+
+ if (!sign && ps>0) sign=1;
+ if (!sign && ps<0) sign=-1;
+
+ // In case the input stamp was earlier, take the reverse difference
+ // to simplify the algebra.
+ if (sign<0)
+ {
+ d=-d;
+ s=-s;
+ ns=-ns;
+ ps=-ps;
+ }
+
+ // Here we always have a positive time difference
+ // and can now unambiguously correct for other negative values.
+ if (ps<0)
+ {
+ ns-=1;
+ ps+=1000;
+ }
+
+ if (ns<0)
+ {
+ s-=1;
+ ns+=1000000000;
+ }
+
+ if (s<0)
+ {
+ d-=1;
+ s+=24*3600;
+ }
+
+ return sign;
+}
+///////////////////////////////////////////////////////////////////////////
+Int_t AliTimestamp::GetDifference(AliTimestamp& t,Int_t& d,Int_t& s,Int_t& ns,Int_t& ps)
+{
+// Provide the time difference w.r.t the AliTimestamp specified on the input.
+// This memberfunction supports both very small (i.e. time of flight analysis
+// for particle physics experiments) and very long (i.e. investigation of
+// astrophysical phenomena) timescales.
+//
+// The time difference is returned via the following output arguments :
+// d : elapsed number of days
+// s : remaining elapsed number of seconds
+// ns : remaining elapsed number of nanoseconds
+// ps : remaining elapsed number of picoseconds
+//
+// Note :
+// ------
+// The calculated time difference is the absolute value of the time interval.
+// This implies that the values of d, s, ns and ps are always positive or zero.
+//
+// The integer return argument indicates whether the AliTimestamp specified
+// on the input argument occurred earlier (-1), simultaneously (0) or later (1).
+
+ return GetDifference(&t,d,s,ns,ps);
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetDifference(AliTimestamp* t,TString u,Int_t mode)
+{
+// Provide the time difference w.r.t the AliTimestamp specified on the input
+// argument in the units as specified by the TString argument.
+// A positive return value means that the AliTimestamp specified on the input
+// argument occurred later, whereas a negative return value indicates an
+// earlier occurence.
+//
+// The units may be specified as :
+// u = "d" ==> Time difference returned as (fractional) day count
+// "s" ==> Time difference returned as (fractional) second count
+// "ns" ==> Time difference returned as (fractional) nanosecond count
+// "ps" ==> Time difference returned as picosecond count
+//
+// It may be clear that for a time difference of several days, the picosecond
+// and even the nanosecond accuracy may be lost.
+// To cope with this, the "mode" argument has been introduced to allow
+// timestamp comparison on only the specified units.
+//
+// The following operation modes are supported :
+// mode = 1 : Full time difference is returned in specified units
+// 2 : Time difference is returned in specified units by
+// neglecting the elapsed time for the larger units than the
+// ones specified.
+// 3 : Time difference is returned in specified units by only
+// comparing the timestamps on the level of the specified units.
+//
+// Example :
+// ---------
+// AliTimestamp t1; // Corresponding to days=3, secs=501, ns=31, ps=7
+// AliTimestamp t2; // Corresponding to days=5, secs=535, ns=12, ps=15
+//
+// The statement : Double_t val=t1.GetDifference(t2,....)
+// would return the following values :
+// val=(2*24*3600)+34-(19*1e-9)+(8*1e-12) for u="s" and mode=1
+// val=34-(19*1e-9)+(8*1e-12) for u="s" and mode=2
+// val=34 for u="s" and mode=3
+// val=-19 for u="ns" and mode=3
+//
+// The default is mode=1.
+
+ if (!t || mode<1 || mode>3) return 0;
+
+ Double_t dt=0;
+
+ // Ensure updated Julian parameters for this AliTimestamp instance
+ if (fCalcs != GetSec() || fCalcns != GetNanoSec()) FillJulian();
+
+ Int_t dd=0;
+ Int_t ds=0;
+ Int_t dns=0;
+ Int_t dps=0;
+
+ // Use Get functions to ensure updated Julian parameters.
+ t->GetMJD(dd,ds,dns);
+ dps=t->GetPs();
+
+ dd-=fMJD;
+ ds-=fJsec;
+ dns-=fJns;
+ dps-=fJps;
+
+ // Time difference for the specified units only
+ if (mode==3)
+ {
+ if (u=="d") dt=dd;
+ if (u=="s") dt=ds;
+ if (u=="ns") dt=dns;
+ if (u=="ps") dt=dps;
+ return dt;
+ }
+
+ // Suppress elapsed time for the larger units than specified
+ if (mode==2)
+ {
+ if (u=="s") dd=0;
+ if (u=="ns")
+ {
+ dd=0;
+ ds=0;
+ }
+ if (u=="ps")
+ {
+ dd=0;
+ ds=0;
+ dns=0;
+ }
+ }
+
+ // Compute the time difference as requested
+ if (u=="s" || u=="d")
+ {
+ // The time difference in (fractional) seconds
+ dt=double(dd*24*3600+ds)+(double(dns)*1e-9)+(double(dps)*1e-12);
+ if (u=="d") dt=dt/double(24*3600);
+ }
+ if (u=="ns") dt=(double(dd*24*3600+ds)*1e9)+double(dns)+(double(dps)*1e-3);
+ if (u=="ps") dt=(double(dd*24*3600+ds)*1e12)+(double(dns)*1e3)+double(dps);
+
+ return dt;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetDifference(AliTimestamp& t,TString u,Int_t mode)
+{
+// Provide the time difference w.r.t the AliTimestamp specified on the input
+// argument in the units as specified by the TString argument.
+// A positive return value means that the AliTimestamp specified on the input
+// argument occurred later, whereas a negative return value indicates an
+// earlier occurence.
+//
+// The units may be specified as :
+// u = "d" ==> Time difference returned as (fractional) day count
+// "s" ==> Time difference returned as (fractional) second count
+// "ns" ==> Time difference returned as (fractional) nanosecond count
+// "ps" ==> Time difference returned as picosecond count
+//
+// It may be clear that for a time difference of several days, the picosecond
+// and even the nanosecond accuracy may be lost.
+// To cope with this, the "mode" argument has been introduced to allow
+// timestamp comparison on only the specified units.
+//
+// The following operation modes are supported :
+// mode = 1 : Full time difference is returned in specified units
+// 2 : Time difference is returned in specified units by
+// neglecting the elapsed time for the larger units than the
+// ones specified.
+// 3 : Time difference is returned in specified units by only
+// comparing the timestamps on the level of the specified units.
+//
+// Example :
+// ---------
+// AliTimestamp t1; // Corresponding to days=3, secs=501, ns=31, ps=7
+// AliTimestamp t2; // Corresponding to days=5, secs=535, ns=12, ps=15
+//
+// The statement : Double_t val=t1.GetDifference(t2,....)
+// would return the following values :
+// val=(2*24*3600)+34-(19*1e-9)+(8*1e-12) for u="s" and mode=1
+// val=34-(19*1e-9)+(8*1e-12) for u="s" and mode=2
+// val=34 for u="s" and mode=3
+// val=-19 for u="ns" and mode=3
+//
+// The default is mode=1.
+
+ return GetDifference(&t,u,mode);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::SetUT(Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns,Int_t ps)
+{
+// Set the AliTimestamp parameters corresponding to the UT date and time
+// in the Gregorian calendar as specified by the input arguments.
+// This facility is exact upto picosecond precision and as such is
+// for scientific observations preferable above the corresponding
+// Set function(s) of TTimestamp.
+// The latter has a random spread in the sub-second part, which
+// might be of use in generating distinguishable timestamps while
+// still keeping second precision.
+//
+// The input arguments represent the following :
+// y : year in UT (e.g. 1952, 2003 etc...)
+// m : month in UT (1=jan 2=feb etc...)
+// d : day in UT (1-31)
+// hh : elapsed hours in UT (0-23)
+// mm : elapsed minutes in UT (0-59)
+// ss : elapsed seconds in UT (0-59)
+// ns : remaining fractional elapsed second of UT in nanosecond
+// ps : remaining fractional elapsed nanosecond of UT in picosecond
+//
+// Note : ns=0 and ps=0 are the default values.
+//
+// This facility first determines the elapsed days, seconds etc...
+// since the beginning of the specified UT year on basis of the
+// input arguments. Subsequently it invokes the SetUT memberfunction
+// for the elapsed timespan.
+// As such this facility is valid for all AD dates in the Gregorian
+// calendar with picosecond precision.
+
+ Int_t day=GetDayOfYear(d,m,y);
+ Int_t secs=hh*3600+mm*60+ss;
+ SetUT(y,day-1,secs,ns,ps);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::SetUT(Int_t y,Int_t d,Int_t s,Int_t ns,Int_t ps)
+{
+// Set the AliTimestamp parameters corresponding to the specified elapsed
+// timespan since the beginning of the new UT year.
+// This facility is exact upto picosecond precision and as such is
+// for scientific observations preferable above the corresponding
+// Set function(s) of TTimestamp.
+// The latter has a random spread in the sub-second part, which
+// might be of use in generating distinguishable timestamps while
+// still keeping second precision.
+//
+// The UT year and elapsed time span is entered via the following input arguments :
+//
+// y : year in UT (e.g. 1952, 2003 etc...)
+// d : elapsed number of days
+// s : (remaining) elapsed number of seconds
+// ns : (remaining) elapsed number of nanoseconds
+// ps : (remaining) elapsed number of picoseconds
+//
+// The specified d, s, ns and ps values will be used in an additive
+// way to determine the elapsed timespan.
+// So, specification of d=1, s=100, ns=0, ps=0 will result in the
+// same elapsed time span as d=0, s=24*3600+100, ns=0, ps=0.
+// However, by making use of the latter the user should take care
+// of possible integer overflow problems in the input arguments,
+// which obviously will provide incorrect results.
+//
+// Note : ns=0 and ps=0 are the default values.
+//
+// This facility first sets the (M)JD corresponding to the start (01-jan 00:00:00)
+// of the specified UT year following the recipe of R.W. Sinnott
+// Sky & Telescope 82, (aug. 1991) 183.
+// Subsequently the day and (sub)second parts are added to the AliTimestamp.
+// As such this facility is valid for all AD dates in the Gregorian calendar.
+
+ Double_t jd=GetJD(y,1,1,0,0,0,0);
+ SetJD(jd);
+
+ Int_t mjd,sec,nsec;
+ GetMJD(mjd,sec,nsec);
+ SetMJD(mjd,0,0,0);
+ Add(d,s,ns,ps);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::GetUT(Int_t& hh,Int_t& mm,Int_t& ss,Int_t& ns,Int_t& ps)
+{
+// Provide the corrresponding UT as hh:mm:ss:ns:ps.
+// This facility is based on the MJD, so the TTimeStamp limitations
+// do not apply here.
+
+ Int_t mjd,sec,nsec,psec;
+
+ GetMJD(mjd,sec,nsec);
+ psec=GetPs();
+
+ hh=sec/3600;
+ sec=sec%3600;
+ mm=sec/60;
+ ss=sec%60;
+ ns=nsec;
+ ps=psec;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetUT()
+{
+// Provide the corrresponding UT in fractional hours.
+// This facility is based on the MJD, so the TTimeStamp limitations
+// do not apply here.
+
+ Int_t hh,mm,ss,ns,ps;
+
+ GetUT(hh,mm,ss,ns,ps);
+
+ Double_t ut=Convert(hh,mm,ss,ns,ps);
+
+ return ut;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::GetGMST(Int_t& hh,Int_t& mm,Int_t& ss,Int_t& ns,Int_t& ps)
+{
+// Provide the corrresponding Greenwich Mean Sideral Time (GMST).
+// The algorithm used is the one described at p. 83 of the book
+// Astronomy Methods by Hale Bradt.
+// This facility is based on the MJD, so the TTimeStamp limitations
+// do not apply here.
+
+ Int_t mjd,sec,nsec,psec;
+
+ // The current UT based timestamp data
+ GetMJD(mjd,sec,nsec);
+ psec=fJps;
+
+ // The basis for the daily corrections in units of Julian centuries w.r.t. J2000.
+ // Note : Epoch J2000 starts at 01-jan-2000 12:00:00 UT.
+ Double_t tau=(GetJD()-2451545.)/36525.;
+
+ // Syncronise sidereal time with current timestamp
+ AliTimestamp sid;
+ sid.SetMJD(mjd,sec,nsec,psec);
+
+ // Add offset for GMST start value defined as 06:41:50.54841 at 01-jan 00:00:00 UT
+ sec=6*3600+41*60+50;
+ nsec=548410000;
+ psec=0;
+ sid.Add(0,sec,nsec,psec);
+
+ // Daily correction for precession and polar motion
+ Double_t addsec=8640184.812866*tau+0.093104*pow(tau,2)-6.2e-6*pow(tau,3);
+ sec=int(addsec);
+ addsec-=double(sec);
+ nsec=int(addsec*1.e9);
+ addsec-=double(nsec)*1.e-9;
+ psec=int(addsec*1.e12);
+ sid.Add(0,sec,nsec,psec);
+
+ sid.GetMJD(mjd,sec,nsec);
+ psec=sid.GetPs();
+
+ hh=sec/3600;
+ sec=sec%3600;
+ mm=sec/60;
+ ss=sec%60;
+ ns=nsec;
+ ps=psec;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetGMST()
+{
+// Provide the corrresponding Greenwich Mean Sideral Time (GMST)
+// in fractional hours.
+// This facility is based on the MJD, so the TTimeStamp limitations
+// do not apply here.
+
+ Int_t hh,mm,ss,ns,ps;
+
+ GetGMST(hh,mm,ss,ns,ps);
+
+ Double_t gst=Convert(hh,mm,ss,ns,ps);
+
+ return gst;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetGAST()
+{
+// Provide the corrresponding Greenwich Apparent Sideral Time (GAST)
+// in fractional hours.
+// In case a hh:mm:ss.sss format is needed, please invoke the Convert()
+// memberfunction for conversion of the provided fractional hour value.
+//
+// The GAST is the GMST corrected for the shift of the vernal equinox
+// due to nutation. The right ascension component of the nutation correction
+// of the vernal equinox is called the "equation of the equinoxes".
+// So we have :
+//
+// GAST = GMST + (equation of the equinoxes)
+//
+// The equation of the equinoxes is determined via the Almanac() memberfunction.
+//
+// Since GMST is based on the MJD, the TTimeStamp limitations do not apply here.
+
+ Double_t da=Almanac();
+
+ // Convert to fractional hours
+ da/=3600.;
+
+ Double_t gast=GetGMST()+da;
+
+ while (gast<0)
+ {
+ gast+=24.;
+ }
+ while (gast>24.)
+ {
+ gast-=24.;
+ }
+
+ return gast;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetLT(Double_t offset)
+{
+// Provide the corresponding local time in fractional hours.
+// The "offset" denotes the time difference in (fractional) hours w.r.t. UT.
+// A mean solar day lasts 24h (i.e. 86400s).
+//
+// In case a hh:mm:ss format is needed, please use the Convert() facility.
+
+ // Current UT time in fractional hours
+ Double_t h=GetUT();
+
+ h+=offset;
+
+ while (h<0)
+ {
+ h+=24.;
+ }
+ while (h>24)
+ {
+ h-=24.;
+ }
+
+ return h;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetLMST(Double_t offset)
+{
+// Provide the corresponding Local Mean Sidereal Time (LMST) in fractional hours.
+// The "offset" denotes the time difference in (fractional) hours w.r.t. GMST.
+// A sidereal day corresponds to 23h 56m 04.09s (i.e. 86164.09s) mean solar time.
+// The definition of GMST is such that a sidereal clock corresponds with
+// 24 sidereal hours per revolution of the Earth.
+// As such, local time offsets w.r.t. UT and GMST can be treated similarly.
+//
+// In case a hh:mm:ss format is needed, please use the Convert() facility.
+
+ // Current GMST time in fractional hours
+ Double_t h=GetGMST();
+
+ h+=offset;
+
+ while (h<0)
+ {
+ h+=24.;
+ }
+ while (h>24)
+ {
+ h-=24.;
+ }
+
+ return h;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetLAST(Double_t offset)
+{
+// Provide the corresponding Local Apparent Sidereal Time (LAST) in fractional hours.
+// The "offset" denotes the time difference in (fractional) hours w.r.t. GAST.
+// A sidereal day corresponds to 23h 56m 04.09s (i.e. 86164.09s) mean solar time.
+// The definition of GMST and GAST is such that a sidereal clock corresponds with
+// 24 sidereal hours per revolution of the Earth.
+// As such, local time offsets w.r.t. UT, GMST and GAST can be treated similarly.
+//
+// In case a hh:mm:ss.sss format is needed, please use the Convert() facility.
+
+ // Current GAST time in fractional hours
+ Double_t h=GetGAST();
+
+ h+=offset;
+
+ while (h<0)
+ {
+ h+=24.;
+ }
+ while (h>24)
+ {
+ h-=24.;
+ }
+
+ return h;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::SetLT(Double_t dt,Int_t y,Int_t m,Int_t d,Int_t hh,Int_t mm,Int_t ss,Int_t ns,Int_t ps)
+{
+// Set the AliTimestamp parameters corresponding to the LT date and time
+// in the Gregorian calendar as specified by the input arguments.
+// This facility is exact upto picosecond precision and as such is
+// for scientific observations preferable above the corresponding
+// Set function(s) of TTimestamp.
+// The latter has a random spread in the sub-second part, which
+// might be of use in generating distinguishable timestamps while
+// still keeping second precision.
+//
+// The input arguments represent the following :
+//
+// dt : the local time offset in fractional hours w.r.t. UT.
+// y : year in LT (e.g. 1952, 2003 etc...)
+// m : month in LT (1=jan 2=feb etc...)
+// d : day in LT (1-31)
+// hh : elapsed hours in LT (0-23)
+// mm : elapsed minutes in LT (0-59)
+// ss : elapsed seconds in LT (0-59)
+// ns : remaining fractional elapsed second of LT in nanosecond
+// ps : remaining fractional elapsed nanosecond of LT in picosecond
+//
+// Note : ns=0 and ps=0 are the default values.
+//
+// This facility first sets the UT as specified by the input arguments
+// and then corrects the UT by subtracting the local time offset w.r.t. UT.
+// As such this facility is valid for all AD dates in the Gregorian
+// calendar with picosecond precision.
+
+ SetUT(y,m,d,hh,mm,ss,ns,ps);
+ Add(-dt);
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::SetLT(Double_t dt,Int_t y,Int_t d,Int_t s,Int_t ns,Int_t ps)
+{
+// Set the AliTimestamp parameters corresponding to the specified elapsed
+// timespan since the beginning of the new LT year.
+// This facility is exact upto picosecond precision and as such is
+// for scientific observations preferable above the corresponding
+// Set function(s) of TTimestamp.
+// The latter has a random spread in the sub-second part, which
+// might be of use in generating distinguishable timestamps while
+// still keeping second precision.
+//
+// The LT year and elapsed time span is entered via the following input arguments :
+//
+// dt : the local time offset in fractional hours w.r.t. UT.
+// y : year in LT (e.g. 1952, 2003 etc...)
+// d : elapsed number of days
+// s : (remaining) elapsed number of seconds
+// ns : (remaining) elapsed number of nanoseconds
+// ps : (remaining) elapsed number of picoseconds
+//
+// The specified d, s, ns and ps values will be used in an additive
+// way to determine the elapsed timespan.
+// So, specification of d=1, s=100, ns=0, ps=0 will result in the
+// same elapsed time span as d=0, s=24*3600+100, ns=0, ps=0.
+// However, by making use of the latter the user should take care
+// of possible integer overflow problems in the input arguments,
+// which obviously will provide incorrect results.
+//
+// Note : ns=0 and ps=0 are the default values.
+//
+// This facility first sets the UT as specified by the input arguments
+// and then corrects the UT by subtracting the local time offset w.r.t. UT.
+// As such this facility is valid for all AD dates in the Gregorian calendar.
+
+ SetUT(y,d,s,ns,ps);
+ Add(-dt);
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetJD(Double_t e,TString mode) const
+{
+// Provide the fractional Julian Date from epoch e.
+// The sort of epoch may be specified via the "mode" parameter.
+//
+// mode = "J" ==> Julian epoch
+// "B" ==> Besselian epoch
+//
+// The default value is mode="J".
+
+ Double_t jd=0;
+
+ if (mode=="J" || mode=="j") jd=(e-2000.0)*365.25+2451545.0;
+
+ if (mode=="B" || mode=="b") jd=(e-1900.0)*365.242198781+2415020.31352;
+
+ return jd;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetMJD(Double_t e,TString mode) const
+{
+// Provide the fractional Modified Julian Date from epoch e.
+// The sort of epoch may be specified via the "mode" parameter.
+//
+// mode = "J" ==> Julian epoch
+// "B" ==> Besselian epoch
+//
+// The default value is mode="J".
+
+ Double_t mjd=GetJD(e,mode)-2400000.5;
+
+ return mjd;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetTJD(Double_t e,TString mode) const
+{
+// Provide the fractional Truncated Julian Date from epoch e.
+// The sort of epoch may be specified via the "mode" parameter.
+//
+// mode = "J" ==> Julian epoch
+// "B" ==> Besselian epoch
+//
+// The default value is mode="J".
+
+ Double_t tjd=GetJD(e,mode)-2440000.5;
+
+ return tjd;
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::Almanac(Double_t* dpsi,Double_t* deps,Double_t* eps)
+{
+// Determination of some astronomical observables which may be needed
+// for further calculations like e.g. precession of coordinates.
+//
+// The standard returned value is the "equation of the equinoxes"
+// (i.e. the nutational shift of the RA of the vernal equinox) in seconds.
+// The memberfunction arguments provide the possibility of retrieving
+// optional returned values. The corresponding observables are :
+//
+// dpsi : Nutational shift in ecliptic longitude in arcseconds
+// deps : Nutational shift in ecliptic obliquity in arcseconds
+// eps : Mean obliquity of the ecliptic in arcseconds
+//
+// All shifts are determined for the current timestamp with
+// J2000.0 (i.e. 01-jan-2000 12:00:00 UT) as the reference epoch.
+//
+// Invokation example :
+// --------------------
+// AliTimestamp t;
+// Double_t da,dpsi,deps,eps;
+// da=t.Almanac(&dpsi,&deps,&eps);
+//
+// The nutation model used is the new one as documented in :
+// "The IAU Resolutions on Astronomical Reference Systems,
+// Time Scales and Earth Rotation Models".
+// This document is freely available as Circular 179 (2005) of the
+// United States Naval Observatory (USNO).
+// (See : http://aa.usno.navy.mil/publications/docs).
+//
+// The change in ecliptic longitude (dpsi) and ecliptic obliquity (deps)
+// are evaluated using the IAU 2000A nutation series expansion
+// as provided in the USNO Circular 179.
+// The new expression for the equation of the equinoxes is based on a series
+// expansion and is the most accurate one known to date.
+// The components are documented on p.17 of the USNO Circular 179.
+//
+// In the current implementation only the first 28 terms of the nutation series
+// are used. This provides an accuracy of about 0.01 arcsec corresponding to 0.001 sec.
+// In case a better accuracy is required, the series can be extended.
+// The total series expansion consists of 1365 terms.
+//
+// Since all calculations are based on the JD, the TTimeStamp limitations
+// do not apply here.
+
+ Double_t pi=acos(-1.);
+
+ Double_t t; // Time difference in fractional Julian centuries w.r.t. the start of J2000.
+ Double_t epsilon; // Mean obliquity of the ecliptic
+ Double_t l; // Mean anomaly of the Moon
+ Double_t lp; // Mean anomaly of the Sun
+ Double_t f; // Mean argument of latitude of the moon
+ Double_t d; // Mean elongation of the Moon from the Sun
+ Double_t om; // Mean longitude of the Moon's mean ascending mode
+
+ t=(GetJD()-2451545.0)/36525.;
+
+ // Values of epsilon and the fundamental luni-solar arguments in arcseconds
+ epsilon=84381.406-46.836769*t-0.0001831*pow(t,2)+0.00200340*pow(t,3)
+ -0.000000576*pow(t,4)-0.0000000434*pow(t,5);
+ l=485868.249036+1717915923.2178*t+31.8792*pow(t,2)+0.051635*pow(t,3)-0.00024470*pow(t,4);
+ lp=1287104.79305+129596581.0481*t-0.5532*pow(t,2)+0.000136*pow(t,3)-0.00001149*pow(t,4);
+ f=335779.526232+1739527262.8478*t-12.7512*pow(t,2)-0.001037*pow(t,3)+0.00000417*pow(t,4);
+ d=1072260.70369+1602961601.2090*t-6.3706*pow(t,2)+0.006593*pow(t,3)-0.00003169*pow(t,4);
+ om=450160.398036-6962890.5431*t+7.4722*pow(t,2)+0.007702*pow(t,3)-0.00005939*pow(t,4);
+
+ if (eps) *eps=epsilon;
+
+ // Convert to radians
+ epsilon=epsilon*pi/(180.*3600.);
+ f=f*pi/(180.*3600.);
+ d=d*pi/(180.*3600.);
+ l=l*pi/(180.*3600.);
+ lp=lp*pi/(180.*3600.);
+ om=om*pi/(180.*3600.);
+
+ //The IAU 2000A nutation series expansion.
+ Double_t phi[28]={om,2.*(f-d+om),2.*(f+om),2.*om,lp,lp+2.*(f-d+om),l,
+ 2.*f+om,l+2.*(f+om),2.*(f-d+om)-lp,2.*(f-d)+om,2.*(f+om)-l,2.*d-l,l+om,
+ om-l,2.*(f+d+om)-l,l+2.*f+om,2.*(f-l)+om,2.*d,2.*(f+d+om),2.*(f-d+om-lp),
+ 2.*(d-l),2.*(l+d+om),l+2.*(f-d+om),2.*f+om-l,2.*l,2.*f,lp+om};
+ Double_t s[28]={-17.2064161,-1.3170907,-0.2276413, 0.2074554, 0.1475877,-0.0516821, 0.0711159,
+ -0.0387298,-0.0301461, 0.0215829, 0.0128227, 0.0123457, 0.0156994, 0.0063110,
+ -0.0057976,-0.0059641,-0.0051613, 0.0045893, 0.0063384,-0.0038571, 0.0032481,
+ -0.0047722,-0.0031046, 0.0028593, 0.0020441, 0.0029243, 0.0025887,-0.0014053};
+ Double_t sd[28]={-0.0174666,-0.0001675,-0.0000234, 0.0000207,-0.0003633, 0.0001226, 0.0000073,
+ -0.0000367,-0.0000036,-0.0000494, 0.0000137, 0.0000011, 0.0000010, 0.0000063,
+ -0.0000063,-0.0000011,-0.0000042, 0.0000050, 0.0000011,-0.0000001, 0.0000000,
+ 0.0000000,-0.0000001, 0.0000000, 0.0000021, 0.0000000, 0.0000000,-0.0000025};
+ Double_t cp[28]={ 0.0033386,-0.0013696, 0.0002796,-0.0000698, 0.0011817,-0.0000524,-0.0000872,
+ 0.0000380, 0.0000816, 0.0000111, 0.0000181, 0.0000019,-0.0000168, 0.0000027,
+ -0.0000189, 0.0000149, 0.0000129, 0.0000031,-0.0000150, 0.0000158, 0.0000000,
+ -0.0000018, 0.0000131,-0.0000001, 0.0000010,-0.0000074,-0.0000066, 0.0000079};
+ Double_t c[28]= { 9.2052331, 0.5730336, 0.0978459,-0.0897492, 0.0073871, 0.0224386,-0.0006750,
+ 0.0200728, 0.0129025,-0.0095929,-0.0068982,-0.0053311,-0.0001235,-0.0033228,
+ 0.0031429, 0.0025543, 0.0026366,-0.0024236,-0.0001220, 0.0016452,-0.0013870,
+ 0.0000477, 0.0013238,-0.0012338,-0.0010758,-0.0000609,-0.0000550, 0.0008551};
+ Double_t cd[28]={ 0.0009086,-0.0003015,-0.0000485, 0.0000470,-0.0000184,-0.0000677, 0.0000000,
+ 0.0000018,-0.0000063, 0.0000299,-0.0000009, 0.0000032, 0.0000000, 0.0000000,
+ 0.0000000,-0.0000011, 0.0000000,-0.0000010, 0.0000000,-0.0000011, 0.0000000,
+ 0.0000000,-0.0000011, 0.0000010, 0.0000000, 0.0000000, 0.0000000,-0.0000002};
+ Double_t sp[28]={ 0.0015377,-0.0004587, 0.0001374,-0.0000291,-0.0001924,-0.0000174, 0.0000358,
+ 0.0000318, 0.0000367, 0.0000132, 0.0000039,-0.0000004, 0.0000082,-0.0000009,
+ -0.0000075, 0.0000066, 0.0000078, 0.0000020, 0.0000029, 0.0000068, 0.0000000,
+ -0.0000025, 0.0000059,-0.0000003,-0.0000003, 0.0000013, 0.0000011,-0.0000045};
+
+ Double_t dp=0,de=0,da=0;
+ for (Int_t i=0; i<28; i++)
+ {
+ dp+=(s[i]+sd[i]*t)*sin(phi[i])+cp[i]*cos(phi[i]);
+ de+=(c[i]+cd[i]*t)*cos(phi[i])+sp[i]*sin(phi[i]);
+ }
+
+ da=dp*cos(epsilon)+0.00264096*sin(om)+0.00006352*sin(2.*om)
+ +0.00001175*sin(2.*f-2.*d+3.*om)+0.00001121*sin(2.*f-2.*d+om)
+ -0.00000455*sin(2.*f-2.*d+2.*om)+0.00000202*sin(2.*f+3.*om)+0.00000198*sin(2.*f+om)
+ -0.00000172*sin(3.*om)-0.00000087*t*sin(om);
+
+ if (dpsi) *dpsi=dp;
+ if (deps) *deps=de;
+
+ // Convert to seconds
+ da/=15.;
+
+ return da;
+}
+///////////////////////////////////////////////////////////////////////////
+void AliTimestamp::SetEpoch(Double_t e,TString mode)
+{
+// Set the timestamp parameters according to the epoch as specified by
+// the input argument "e".
+// Via the input argument "mode" the user can specify the type of epoch
+//
+// mode = "B" ==> Besselian epoch
+// "J" ==> Julian epoch
+
+ Double_t jd=GetJD(e,mode);
+ SetJD(jd);
+}
+///////////////////////////////////////////////////////////////////////////
+Double_t AliTimestamp::GetEpoch(TString mode)
+{
+// Provide the corresponding epoch value.
+// Via the input argument "mode" the user can specify the type of epoch
+//
+// mode = "B" ==> Besselian epoch
+// "J" ==> Julian epoch
+
+ Double_t e=0;
+ if (mode=="B" || mode=="b") e=GetBE();
+ if (mode=="J" || mode=="j") e=GetJE();
+ return e;
+}
+///////////////////////////////////////////////////////////////////////////