{
"cells": [
{
"cell_type": "markdown",
"id": "0e4ae0a6",
"metadata": {},
"source": [
"# timeonaxis3\n",
"with what gives TGaxis. It can be used as referenced test to check if TGaxis\n",
"is working properly.\n",
"The original code was developed by Philippe Gras (CEA Saclay. IRFU/SEDI)\n",
"\n",
"\n",
"\n",
"\n",
"**Author:** Philippe Gras, Bertrand Bellenot, Olivier Couet \n",
"This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Tuesday, May 19, 2026 at 08:37 PM."
]
},
{
"cell_type": "markdown",
"id": "42116b74",
"metadata": {},
"source": [
" Definition of a helper function: "
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "6c55b73b",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:37:32.807059Z",
"iopub.status.busy": "2026-05-19T20:37:32.806947Z",
"iopub.status.idle": "2026-05-19T20:37:32.811912Z",
"shell.execute_reply": "2026-05-19T20:37:32.811438Z"
}
},
"outputs": [],
"source": [
"%%cpp -d\n",
"\n",
"#include \"TAxis.h\"\n",
"#include \"TGaxis.h\"\n",
"#include \"TCanvas.h\"\n",
"#include \"TString.h\"\n",
"#include \"TLine.h\"\n",
"#include \"TLatex.h\"\n",
"#include \n",
"#include \n",
"\n",
"TString stime(time_t *t, bool utc = false, bool display_time_zone = true)\n",
"{\n",
" struct tm *tt;\n",
" if (utc)\n",
" tt = gmtime(t);\n",
" else\n",
" tt = localtime(t);\n",
" char buf[256];\n",
" if (display_time_zone)\n",
" strftime(buf, sizeof(buf), \"%Y-%m-%d %H:%M:%S %Z\", tt);\n",
" else\n",
" strftime(buf, sizeof(buf), \"%Y-%m-%d %H:%M:%S\", tt);\n",
" return TString(buf);\n",
"}"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "3f0f74a4",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:37:32.813203Z",
"iopub.status.busy": "2026-05-19T20:37:32.813086Z",
"iopub.status.idle": "2026-05-19T20:37:33.338957Z",
"shell.execute_reply": "2026-05-19T20:37:33.338428Z"
}
},
"outputs": [],
"source": [
"double f = 1.8;\n",
"\n",
"auto c = new TCanvas;\n",
"\n",
"TLatex tex1;\n",
"tex1.SetNDC();\n",
"tex1.SetTextFont(102);\n",
"tex1.SetTextSize(0.055 * f);\n",
"\n",
"TLatex tex3;\n",
"tex3.SetNDC();\n",
"tex3.SetTextFont(102);\n",
"tex3.SetTextSize(0.07 * f);\n",
"tex3.SetTextColor(kBlue + 2);\n",
"\n",
"TLatex tex2;\n",
"tex2.SetNDC();\n",
"tex2.SetTextFont(102);\n",
"tex2.SetTextSize(0.07 * f);\n",
"tex2.SetTextColor(kOrange + 3);\n",
"\n",
"time_t offset[] = {0, 0, 1325376000, 1341100800};\n",
"time_t t[] = {1331150400, 1336417200, 0, 36000};\n",
"\n",
"c->SetTopMargin(0);\n",
"c->SetBottomMargin(0);\n",
"c->SetLeftMargin(0);\n",
"c->SetRightMargin(0);\n",
"c->Divide(2, 4, -1, -1);\n",
"TLine l;\n",
"l.DrawLine(0.5, 0, 0.5, 1.);\n",
"\n",
"for (int i = 0; i < 4; ++i) {\n",
" for (int gmt = 0; gmt < 2; ++gmt) {\n",
" const char *opt = (gmt ? \"gmt\" : \"local\");\n",
" TVirtualPad *p = c->cd(2 * i + gmt + 1);\n",
" p->SetTopMargin(0);\n",
" p->SetBottomMargin(0);\n",
" p->SetLeftMargin(0);\n",
" p->SetRightMargin(0);\n",
" p->SetFillStyle(4000);\n",
"\n",
" TGaxis *ga = new TGaxis(.4, .25, 5., .25, t[i], t[i] + 1, 1, \"t\");\n",
" ga->SetTimeFormat(\"TGaxis label: #color[2]{%Y-%m-%d %H:%M:%S}\");\n",
" ga->SetLabelFont(102);\n",
" ga->SetLabelColor(kBlue + 2);\n",
"\n",
" ga->SetTimeOffset(offset[i], opt);\n",
" ga->SetLabelOffset(0.04 * f);\n",
" ga->SetLabelSize(0.07 * f);\n",
" ga->SetLineColor(0);\n",
" ga->Draw();\n",
"\n",
" // Get offset string of axis time format: there is not accessor\n",
" // to time format in TGaxis.\n",
" // Assumes TAxis use the same format.\n",
" TAxis a(10, 0, 1600000000);\n",
" a.SetTimeOffset(offset[i], opt);\n",
" const char *offsettimeformat = a.GetTimeFormat();\n",
"\n",
" char buf[256];\n",
" if (offset[i] < t[i]) {\n",
" snprintf(buf, 256, \"#splitline{%s, %s}{offset: %ld, option %s}\", stime(t + i).Data(),\n",
" stime(t + i, true).Data(), offset[i], opt);\n",
" } else {\n",
" int h = t[i] / 3600;\n",
" int m = (t[i] - 3600 * h) / 60;\n",
" int s = (t[i] - h * 3600 - m * 60);\n",
" snprintf(buf, 256, \"#splitline{%d h %d m %d s}{offset: %s, option %s}\", h, m, s,\n",
" stime(offset + i, gmt).Data(), opt);\n",
" }\n",
" tex1.DrawLatex(.01, .75, buf);\n",
" tex2.DrawLatex(.01, .50, offsettimeformat);\n",
" time_t t_ = t[i] + offset[i];\n",
" snprintf(buf, 256, \"Expecting: #color[2]{%s}\", stime(&t_, gmt, false).Data());\n",
" tex3.DrawLatex(.01, .24, buf);\n",
" if (i > 0)\n",
" l.DrawLine(0, 0.95, 1, 0.95);\n",
" }\n",
"}"
]
},
{
"cell_type": "markdown",
"id": "673e507a",
"metadata": {},
"source": [
"Draw all canvases "
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "7f0df125",
"metadata": {
"collapsed": false,
"execution": {
"iopub.execute_input": "2026-05-19T20:37:33.340422Z",
"iopub.status.busy": "2026-05-19T20:37:33.340304Z",
"iopub.status.idle": "2026-05-19T20:37:33.551721Z",
"shell.execute_reply": "2026-05-19T20:37:33.551233Z"
}
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"\n",
"\n",
"
\n",
"\n",
"\n",
"\n"
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"gROOT->GetListOfCanvases()->Draw()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "ROOT C++",
"language": "c++",
"name": "root"
},
"language_info": {
"codemirror_mode": "text/x-c++src",
"file_extension": ".C",
"mimetype": " text/x-c++src",
"name": "c++"
}
},
"nbformat": 4,
"nbformat_minor": 5
}