TDatime and retrieving time from x-axis

Dear ROOT-experts

I am having a bit of trouble understanding how to use the TDatime class.

I create a histogram with a time-axis like this (times read in from a string of type yyyy-mm-dd hh:mm:ss) pseudocode)

dt_start = TDatime("2012-01-01 01:01:00");
dt_end = TDatime("2012-12-31 23:59:59");

h = TH1F("h","h",100,dt_start.Convert(),dt_end.Convert());

I believe I have to do the Convert, otherwise TH1F won’t understand what the x-axis is, right?

Then I fill my histogram in this way


and set the timedisplay for plotting like this


I now wonder: If I want to check the value of the x-axis for a certain point in my histogram, say doing


I get as a result an integer number. Is there any way of me converting this number back into a datetime object? And get the date/time out as a string?

So principle questions are

  1. Am I defining and filling the histogram in the correct way for using a time-axis?
  2. Is there any obvious way of getting hold of the date and time from a specific histogram point/bin - and not just the integer number?

and a 3.rd question
3) Why is it necessary to set an offset? Won’t the axis just start from the dt_start and end at the dt_end automatically, like I defined my histograms? If not, is it correct to set the offset to the start of the histogram, so to dt_start?

( I have had a look at the TDatime examples in the tutorial, but have not gotten the answer to this question)

Thanks a lot,

All the available getters are listed here.

Thanks for your reply.

Yes I know that they are listed there, but I do not understand which to use after I have already used Convert? Am I doing the things correctly?

Sorry for my ignorance, but hope still for some indication if this is possible.


It looks like you need to use a combination of those:

static void	GetDateTime(UInt_t datetime, Int_t& date, Int_t& time)
Int_t	GetDay() const
Int_t	GetDayOfWeek() const
Int_t	GetHour() const
Int_t	GetMinute() const
Int_t	GetMonth() const
Int_t	GetSecond() const
Int_t	GetTime() const
Int_t	GetYear() const

because none of them returns a string.


thanks a lot for your reply.

But my question is: when I have already used Convert() (which I think I need to do in order to actually be able to make a histogram of the date time-objects) can I then extract the information from the bin? The bin is now just an integer ?

Thanks a lot, and sorry if it is obvious, I just have not managed to do

xbin_val = histo.GetBinLowEdge(bin)

and then extract the actual date and time from the xbin_val that is a converted date time-object.

I might be doing something completely wrong? I.e. looking at the example I tried to explain in the first post?


It looks like using TTimeStamp instead of TDatime makes it easier:

root [0] TTimeStamp *t1 = new TTimeStamp(2012,8,2,0,0,0)
root [1] t1->GetDate()
(const unsigned int)20120802
root [2] t1->GetSec()
(const time_t)1343865600

root [3] TTimeStamp *t2 = new TTimeStamp()
root [4] t2->SetSec(1343865600)    // use the integer value of t1 to initialise t2
root [5] t2->GetDate()
(const unsigned int)20120802 // retrive the date in t2

Thanks a lot for your suggestion. That worked very well.

Now, I am having problems getting the x-axis to respond in the way I wish, but I believe this is a python question, so I continue asking in the pyroot-support.

Thank you very much,