Trying to plot a histogram with time axis

I read every tread on the forum about plotting the histograms with unix time converted to human-readable time, but can’t get it to work. In root 6.06/02 there is a crash, and in root 6.12/06 the plot is displayed, but all the x-axis values are listed as ‘invalid’. I attached the file and the commands I use in the interpreter.

Appreciate your help!

TFile f("outputCalibratedCrystals.root");
TH1D* ht = (TH1D*)f.Get("timeE");
ht->GetXaxis()->SetTimeOffset(0, "gmt");

outputCalibratedCrystals.root (341.2 KB)

Well, ht->GetXaxis()->GetXmin() returns 1.5228211e+18 so, it doesn’t seem to be in “seconds” units, see: TAxis::SetTimeFormat

Well, you can try to play with:

ht->GetXaxis()->SetLimits(ht->GetXaxis()->GetXmin() / 1.e9, ht->GetXaxis()->GetXmax() / 1.e9); // from [ns] to [s]

Thanks for your help! Is it possible to have sub-second precision?

Try with ht->GetXaxis()->SetTimeFormat("#splitline{%H:%M}{%S}"); and then “zoom” the x-axis (e.g. with a mouse).

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.