{ "cells": [ { "cell_type": "markdown", "id": "bf668ac3", "metadata": {}, "source": [ "# pdf007_multivarGaus\n", "Tutorial illustrating the multivariate gaussian random number generation\n", "\n", "\n", "\n", "\n", "**Author:** Jorge Lopez \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:26 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "a35d0042", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:44.182722Z", "iopub.status.busy": "2026-05-19T20:26:44.182589Z", "iopub.status.idle": "2026-05-19T20:26:44.644556Z", "shell.execute_reply": "2026-05-19T20:26:44.643917Z" } }, "outputs": [], "source": [ "ROOT::Math::GSLRandomEngine rnd;\n", "rnd.Initialize();\n", "\n", "const int dim = 3;\n", "double pars[dim] = {0, 0, 0.5};\n", "double genpars[dim] = {0, 0, 0};\n", "double cov[dim * dim] = {1.0, -0.2, 0.0, -0.2, 1.0, 0.5, 0.0, 0.5, 0.75};\n", "\n", "TH1F* hX = new TH1F(\"hX\", \"hX;x;Counts\", 100, -5, 5);\n", "TH1F* hY = new TH1F(\"hY\", \"hY;y;Counts\", 100, -5, 5);\n", "TH1F* hZ = new TH1F(\"hZ\", \"hZ;z;Counts\", 100, -5, 5);\n", "\n", "TH2F* hXY = new TH2F(\"hXY\", \"hXY;x;y;Counts\", 100, -5, 5, 100, -5, 5);\n", "TH2F* hXZ = new TH2F(\"hXZ\", \"hXZ;x;z;Counts\", 100, -5, 5, 100, -5, 5);\n", "TH2F* hYZ = new TH2F(\"hYZ\", \"hYZ;y;z;Counts\", 100, -5, 5, 100, -5, 5);\n", "\n", "const int MAX = 10000;\n", "for (int iEvent = 0; iEvent < MAX; ++iEvent) {\n", " rnd.GaussianND(dim, pars, cov, genpars);\n", " auto x = genpars[0];\n", " auto y = genpars[1];\n", " auto z = genpars[2];\n", " hX->Fill(x);\n", " hY->Fill(y);\n", " hZ->Fill(z);\n", " hXY->Fill(x, y);\n", " hXZ->Fill(x, z);\n", " hYZ->Fill(y, z);\n", "}\n", "\n", "TCanvas* c = new TCanvas(\"c\", \"Multivariate gaussian random numbers\");\n", "c->Divide(3, 2);\n", "c->cd(1);\n", "hX->Draw();\n", "c->cd(2);\n", "hY->Draw();\n", "c->cd(3);\n", "hZ->Draw();\n", "c->cd(4);\n", "hXY->Draw(\"COL\");\n", "c->cd(5);\n", "hXZ->Draw(\"COL\");\n", "c->cd(6);\n", "hYZ->Draw(\"COL\");" ] }, { "cell_type": "markdown", "id": "515f0fd0", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 2, "id": "044f5d6d", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:26:44.646406Z", "iopub.status.busy": "2026-05-19T20:26:44.646273Z", "iopub.status.idle": "2026-05-19T20:26:44.853433Z", "shell.execute_reply": "2026-05-19T20:26:44.852754Z" } }, "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 }