TTree::Draw with pretty-printed epoch time?

I have a TTree with a unix timestamp (seconds since 1970…). Is there a convenient way to use TTree::Draw(“myvar:time”) with time on the X-axis in such a way that the axis labels are human-readable dates or times? I can subtract off the initial time and then divide by 606024 to get it in elapsed days, but I would really prefer a date like DD/MM/YY.

If I can’t do it directly from the TTree::Draw, what would be the recipe for converting a TGraph with epoch times on the x-axis into a new TGraph with date labels?


It looks like I figured it out (modulo time-zone errors, but my time scale is months so I’m not worried).

I have to subtract off the first time value so that all my times are in seconds since t0. Then I have to make a TDatime that corresponds to t0 and then Convert() it to feed to the SetTimeOffset method:

import time
import ROOT

f = ROOT.TFile("input_file.root","READ")
t = f.Get("environment")

t0 = t.time
lt = time.localtime(t0)
t0_CERN = ROOT.TDatime(lt.tm_year, lt.tm_mon, lt.tm_mday, lt.tm_hour, lt.tm_min, lt.tm_sec)

t.Draw("temperature:(time-%d)" % t0)
g = ROOT.gROOT.FindObject("Graph").Clone("g")

xax = g.GetXaxis()