Time axis for histograms

Dear Root Talk,

I am using a time axis for some histograms and I can’t figure out how to have it start at 00:00 of a particular day.

For example when I use the UNIX time stamp 1262062801 (which is midnight in New York) as the offset I am at best short by one hour – instead of starting at 00:00 it starts at 23:00.

Can someone please show me the correct way of using the above time stamp and having the histogram axis start at midnight.

Thanks and Happy New Year!
time_axis.cpp (1.29 KB)

Olivier will process your mail when CERN will reopen next week.


bump :wink:

Sorry I missed it … I will look at you macro right now and answer asap.

   // Define the lowest histogram limit as 2010, January 10th 00:00
   TDatime T1(2010,01,10,00,00,00);
   Double_t X1 = T1.Convert();
   // Define the lowest histogram limit as 2010, January 10th 05:00
   TDatime T2(2010,01,10,05,00,00);
   Double_t X2 = T2.Convert();
   TH1F * h1 = new TH1F("h1","test",100,X1,X2);
   TRandom r;
   for (Int_t i=0;i<30000;i++) {
      Double_t noise = r.Gaus(0.5*(X1+X2),0.1*(X2-X1));
   h1->GetXaxis()->SetTimeOffset(0, "gmt");

Sorry for not replying sooner, got busy teaching.

With the actual code I read in a data file of time stamped values. As I look at the file during the day I don’t know the end time stamp yet – at the end of the day a new file is created so then I have a 24 hours time window.

Now if I don’t set X2 as a time stamp why does the histogram begin one hour offset?
Instead of needing to subtract 5 hours

I only need to subtract 4 hours

time_axisv2.cpp (1.37 KB)

Why don’t you proceed like in the example I sent you as it does what you are looking for. You need to specify the axis limits X1 and X2 when you create an histogram and, it you request a time axis, they are both considered as time values.


Thanks for your time.