Time axis on time history plots

Hi,

I’ve written a small proof-of-concept macro to make a time history plot of two different recorded variables. I’ve the timestamps of each measurement and the actual measurements for each variable in arrays that I declared within the macro. The actual data is going to come from a database query with a certain timestamp field. I was wondering if/how I would be able to display these graphs without first converting the timestamp into seconds from a certain year/date/time.

If converting it to seconds is the only way to do it, then that’s okay too, but then I have a question about the time axis. Right now it starts from some date in 1994, but once or twice it started from 2006 (arbitrarily, I don’t believe I changed anything of importance). What can I do to start the time axis from a very specific date and time?

My macro is attached. Run it with:
root [0] .L timegraphL.C
root [1] twoscales()

Thank you very much,
Mikhail
timegraphL.C (2.28 KB)

here is an example:

timeonaxis4 ()
{
   TGraph *graph = new TGraph;
   gStyle->SetTimeOffset(0);
                                                                                
   // Point 1 given by : date -d "01/01/1985" +%s
   graph->SetPoint(0, 473382000.0     ,1.0);
                                                                                
   // Point 2 given by : date -d "07/02/1985" +%s
   graph->SetPoint(1, 489103200.0     ,2.0);
                                                                                
   // Point 3 given by : date -d "01/01/1986" +%s
   graph->SetPoint(2, 504918000.0     ,3.0);
                                                                                
   graph->Draw("AL*");
   TH1F *hist = graph->GetHistogram();
   TAxis *axis = hist->GetXaxis();
   axis->SetTimeDisplay(1);
   axis->SetTimeFormat("%Y-%m-%d");
   axis->SetNdivisions(204,false);
}

Hi,

Is there any way to evaluate the date statement from within a ROOT macro?

I’d like to do something like this with the below code:


TString strTime = “01/01/1985”;
graph->SetPoint(0, date -d strTime +%s ,1.0);


[Obviously the above code doesn’t work, but I’m trying to achieve something like that]

Thanks a lot,
Mikhail

Try:

root [0] gSystem->Exec(“date -d “01/01/1985” +%s”);
473382000
root [1]

That almost works…

So if I do
graph->SetPoint(0, 473407200 ,1.0);
it gives me the point at the correct date in 1985.

At the root prompt,
root [2] gSystem->Exec(“date -d “01/01/1985 00:00:00” +%s”)
473407200
(Int_t)0

Works fine… but…
graph->SetPoint(0, gSystem->Exec(“date -d “01/01/1985 00:00:00” +%s”) ,1.0);
Sets it to some date in 1969…

What’s going on here?

Thank you,
Mikhail

Use TDatime like in the examples:

$ROOTSYS/tutorials/timeonaxis2.C
$ROOTSYS/tutorials/timeonaxis.C