{ "cells": [ { "cell_type": "markdown", "id": "f2863788", "metadata": {}, "source": [ "# gr017_time\n", "\n", "\n", "\n", "**Author:** Rene Brun \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:38 PM." ] }, { "cell_type": "markdown", "id": "f6bb845e", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": 1, "id": "2a0bccf0", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:06.102978Z", "iopub.status.busy": "2026-05-19T20:38:06.102864Z", "iopub.status.idle": "2026-05-19T20:38:06.429850Z", "shell.execute_reply": "2026-05-19T20:38:06.429177Z" } }, "outputs": [], "source": [ "Int_t nsteps = 500;\n", "Int_t np = 100;" ] }, { "cell_type": "code", "execution_count": 2, "id": "d57b5f9b", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:06.432178Z", "iopub.status.busy": "2026-05-19T20:38:06.432051Z", "iopub.status.idle": "2026-05-19T20:38:07.335986Z", "shell.execute_reply": "2026-05-19T20:38:07.335420Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "input_line_53:4:1: warning: 'size' shadows a declaration with the same name in the 'std' namespace; use '::size' to reference this declaration\n", "std::vector rr(np), phi(np), dr(np), size(np);\n", "^\n", "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "if (np > 1000) np = 1000;\n", "std::vector color(np);\n", "std::vector rr(np), phi(np), dr(np), size(np);\n", "TRandom3 r;\n", "Double_t xmin = -10, xmax = 10, ymin = -10, ymax = 10;\n", "auto g = new TGraphTime(nsteps, xmin, ymin, xmax, ymax);\n", "g->SetTitle(\"TGraphTime demo;X domain;Y domain\");\n", "for (Int_t i = 0; i < np; i++) { // calculate some object parameters\n", " rr[i] = r.Uniform(0.1 * xmax, 0.2 * xmax);\n", " phi[i] = r.Uniform(0, 2 * TMath::Pi());\n", " dr[i] = r.Uniform(0, 1) * 0.9 * xmax / Double_t(nsteps);\n", " Double_t rc = r.Rndm();\n", " if (rc > 0.7)\n", " color[i] = kYellow;\n", " else if (rc > 0.3)\n", " color[i] = kBlue;\n", " else\n", " color[i] = kRed;\n", "\n", " size[i] = r.Uniform(0.5, 6);\n", "}\n", "for (Int_t s = 0; s < nsteps; s++) { // fill the TGraphTime step by step\n", " for (Int_t i = 0; i < np; i++) {\n", " Double_t newr = rr[i] + dr[i] * s;\n", " Double_t newsize = 0.2 + size[i] * TMath::Abs(TMath::Sin(newr + 10));\n", " Double_t newphi = phi[i] + 0.01 * s;\n", " Double_t xx = newr * TMath::Cos(newphi);\n", " Double_t yy = newr * TMath::Sin(newphi);\n", " TMarker *m = new TMarker(xx, yy, 20);\n", " m->SetMarkerColor(color[i]);\n", " m->SetMarkerSize(newsize);\n", " g->Add(m, s);\n", " if (i == np - 1)\n", " g->Add(new TArrow(xmin, ymax, xx, yy, 0.02, \"-|>\"), s);\n", " }\n", " g->Add(new TPaveLabel(.90, .92, .98, .97, TString::Format(\"%d\", s + 1), \"brNDC\"), s);\n", "}\n", "\n", "g->Draw();" ] }, { "cell_type": "markdown", "id": "f2f35b03", "metadata": {}, "source": [ "save object as animated gif\n", "g->SaveAnimatedGif(\"gr17_time.gif\");" ] }, { "cell_type": "markdown", "id": "e596b77b", "metadata": {}, "source": [ "save object to a file" ] }, { "cell_type": "code", "execution_count": 3, "id": "ad68cfce", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:07.337802Z", "iopub.status.busy": "2026-05-19T20:38:07.337678Z", "iopub.status.idle": "2026-05-19T20:38:07.549412Z", "shell.execute_reply": "2026-05-19T20:38:07.548752Z" } }, "outputs": [], "source": [ "auto f = TFile::Open(\"gr17_time.root\",\"recreate\");\n", "f->WriteObject(g, \"g\");\n", "delete f;" ] }, { "cell_type": "markdown", "id": "8317e6c7", "metadata": {}, "source": [ "to view this object in another session do\n", "TFile::Open(\"gr17_time.root\");\n", "g->Draw();" ] }, { "cell_type": "markdown", "id": "f14d07b2", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 4, "id": "4d6a9aff", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:07.551207Z", "iopub.status.busy": "2026-05-19T20:38:07.551094Z", "iopub.status.idle": "2026-05-19T20:38:07.762722Z", "shell.execute_reply": "2026-05-19T20:38:07.762044Z" } }, "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 }