{ "cells": [ { "cell_type": "markdown", "id": "082b1fcc", "metadata": {}, "source": [ "# gr018_time2\n", "a set of particles with their time stamp in a MonteCarlo program.\n", "\n", "See the [TGraphTime documentation](https://root.cern/doc/master/classTGraphTime.html)\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": "f1871219", "metadata": {}, "source": [ " Arguments are defined. " ] }, { "cell_type": "code", "execution_count": 1, "id": "a4b8b437", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:06.932624Z", "iopub.status.busy": "2026-05-19T20:38:06.932503Z", "iopub.status.idle": "2026-05-19T20:38:07.259782Z", "shell.execute_reply": "2026-05-19T20:38:07.259207Z" } }, "outputs": [], "source": [ "Int_t nsteps = 200;\n", "Int_t np = 5000;" ] }, { "cell_type": "code", "execution_count": 2, "id": "e84ad14d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:07.261449Z", "iopub.status.busy": "2026-05-19T20:38:07.261329Z", "iopub.status.idle": "2026-05-19T20:38:08.408558Z", "shell.execute_reply": "2026-05-19T20:38:08.408127Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "name": "stderr", "output_type": "stream", "text": [ "Info in : created default TCanvas with name c1\n" ] } ], "source": [ "if (np > 5000) np = 5000;\n", "std::vector color(np);\n", "std::vector cosphi(np), sinphi(np), speed(np);\n", "TRandom3 r;\n", "Double_t xmin = 0, xmax = 10, ymin = -10, ymax = 10;\n", "TGraphTime *g = new TGraphTime(nsteps,xmin,ymin,xmax,ymax);\n", "g->SetTitle(\"TGraphTime demo 2;X;Y\");\n", "Double_t fact = xmax/Double_t(nsteps);\n", "for (Int_t i = 0; i < np; i++) { // calculate some object parameters\n", " speed[i] = r.Uniform(0.5, 1);\n", " Double_t phi = r.Gaus(0, TMath::Pi() / 6.);\n", " cosphi[i] = fact * speed[i] * TMath::Cos(phi);\n", " sinphi[i] = fact * speed[i] * TMath::Sin(phi);\n", " Double_t rc = r.Rndm();\n", " color[i] = kRed;\n", " if (rc > 0.3) color[i] = kBlue;\n", " if (rc > 0.7) color[i] = kYellow;\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 xx = s*cosphi[i];\n", " if (xx < xmin) continue;\n", " Double_t yy = s*sinphi[i];\n", " TMarker *m = new TMarker(xx,yy,25);\n", " m->SetMarkerColor(color[i]);\n", " m->SetMarkerSize(1.5 -s/(speed[i]*nsteps));\n", " g->Add(m, s);\n", " }\n", " g->Add(new TPaveLabel(.70,.92,.98,.99,TString::Format(\"shower at %5.3f nsec\",3.*s/nsteps),\"brNDC\"),s);\n", "}\n", "\n", "g->Draw();" ] }, { "cell_type": "markdown", "id": "2a8af00f", "metadata": {}, "source": [ "save object as animated gif\n", "g->SaveAnimatedGif(\"gr18_time2.gif\");" ] }, { "cell_type": "markdown", "id": "87c2f66c", "metadata": {}, "source": [ "start animation, can be stopped with g->Animate(kFALSE);\n", "g->Animate();" ] }, { "cell_type": "markdown", "id": "4ecf48d2", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 3, "id": "864b85aa", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:38:08.409862Z", "iopub.status.busy": "2026-05-19T20:38:08.409744Z", "iopub.status.idle": "2026-05-19T20:38:08.625902Z", "shell.execute_reply": "2026-05-19T20:38:08.625379Z" } }, "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 }