{ "cells": [ { "cell_type": "markdown", "id": "dc81620b", "metadata": {}, "source": [ "# annotation3d\n", "polylines. It also demonstrates how the axis labels can be modified.\n", "It was created for the book:\n", "[Statistical Methods for Data Analysis in Particle Physics](http://www.springer.com/la/book/9783319201757)\n", "\n", "\n", "\n", "**Author:** Luca Lista, 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:36 PM." ] }, { "cell_type": "code", "execution_count": 1, "id": "c103a284", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:45.290399Z", "iopub.status.busy": "2026-05-19T20:36:45.290247Z", "iopub.status.idle": "2026-05-19T20:36:45.658973Z", "shell.execute_reply": "2026-05-19T20:36:45.658633Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "\n", "
\n", "
\n", "\n", "\n", "\n" ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "auto c = new TCanvas(\"c\", \"c\", 600, 600);\n", "c->SetTheta(30);\n", "c->SetPhi(50);\n", "gStyle->SetOptStat(0);\n", "gStyle->SetHistTopMargin(0);\n", "gStyle->SetOptTitle(kFALSE);" ] }, { "cell_type": "markdown", "id": "7923a797", "metadata": {}, "source": [ "Define and draw a surface" ] }, { "cell_type": "code", "execution_count": 2, "id": "d354f9ab", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:45.670325Z", "iopub.status.busy": "2026-05-19T20:36:45.670189Z", "iopub.status.idle": "2026-05-19T20:36:45.882070Z", "shell.execute_reply": "2026-05-19T20:36:45.881673Z" } }, "outputs": [], "source": [ "auto f = new TF2(\"f\", \"[0]*cos(x)*cos(y)\", -1, 1, -1, 1);\n", "f->SetParameter(0, 1);\n", "double s = 1. / f->Integral(-1, 1, -1, 1);\n", "f->SetParameter(0, s);\n", "f->SetNpx(50);\n", "f->SetNpy(50);\n", "\n", "f->GetXaxis()->SetTitle(\"x\");\n", "f->GetXaxis()->SetTitleOffset(1.4);\n", "f->GetXaxis()->SetTitleSize(0.04);\n", "f->GetXaxis()->CenterTitle();\n", "f->GetXaxis()->SetNdivisions(505);\n", "f->GetXaxis()->SetTitleOffset(1.3);\n", "f->GetXaxis()->SetLabelSize(0.03);\n", "f->GetXaxis()->ChangeLabelByValue(-0.5, -1, -1, -1, kRed, -1, \"X_{0}\");\n", "\n", "f->GetYaxis()->SetTitle(\"y\");\n", "f->GetYaxis()->CenterTitle();\n", "f->GetYaxis()->SetTitleOffset(1.4);\n", "f->GetYaxis()->SetTitleSize(0.04);\n", "f->GetYaxis()->SetTitleOffset(1.3);\n", "f->GetYaxis()->SetNdivisions(505);\n", "f->GetYaxis()->SetLabelSize(0.03);\n", "\n", "f->GetZaxis()->SetTitle(\"dP/dx\");\n", "f->GetZaxis()->CenterTitle();\n", "f->GetZaxis()->SetTitleOffset(1.3);\n", "f->GetZaxis()->SetNdivisions(505);\n", "f->GetZaxis()->SetTitleSize(0.04);\n", "f->GetZaxis()->SetLabelSize(0.03);\n", "\n", "f->SetLineWidth(1);\n", "f->SetLineColorAlpha(kAzure - 2, 0.3);\n", "\n", "c->Add(f, \"surf1 fb\");" ] }, { "cell_type": "markdown", "id": "075e9a1d", "metadata": {}, "source": [ "Lines for 3D annotation" ] }, { "cell_type": "code", "execution_count": 3, "id": "b7328af3", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:45.907006Z", "iopub.status.busy": "2026-05-19T20:36:45.906831Z", "iopub.status.idle": "2026-05-19T20:36:46.116845Z", "shell.execute_reply": "2026-05-19T20:36:46.115630Z" } }, "outputs": [], "source": [ "double x[11] = {-0.500, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.5, -0.500};\n", "double y[11] = {-0.985, -0.8, -0.6, -0.4, -0.2, 0.0, 0.2, 0.4, 0.6, 0.8, 0.985};\n", "double z[11];\n", "for (int i = 0; i < 11; ++i)\n", " z[i] = s * cos(x[i]) * cos(y[i]);\n", "auto g2 = new TPolyLine3D(11, x, y, z);\n", "\n", "double xx[2] = {-0.5, -0.5};\n", "double yy[2] = {-0.985, -0.985};\n", "double zz[2] = {0.11, s * cos(-0.5) * cos(-0.985)};\n", "auto l2 = new TPolyLine3D(2, xx, yy, zz);\n", "\n", "g2->SetLineColor(kRed);\n", "g2->SetLineWidth(3);\n", "c->Add(g2);\n", "\n", "l2->SetLineColor(kRed);\n", "l2->SetLineStyle(kDashed);\n", "l2->SetLineWidth(1);\n", "c->Add(l2);" ] }, { "cell_type": "markdown", "id": "1a25db94", "metadata": {}, "source": [ "Draw text Annotations" ] }, { "cell_type": "code", "execution_count": 4, "id": "1090a644", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:46.118299Z", "iopub.status.busy": "2026-05-19T20:36:46.118167Z", "iopub.status.idle": "2026-05-19T20:36:46.328667Z", "shell.execute_reply": "2026-05-19T20:36:46.327701Z" } }, "outputs": [], "source": [ "auto txt = new TAnnotation(-0.45, -0.2, 0.33, \"f(y,x_{0})\");\n", "txt->SetTextFont(42);\n", "txt->SetTextColor(kRed);\n", "c->Add(txt);\n", "\n", "auto txt1 = new TAnnotation(0.5, 0.5, 0.3, \"f(x,y)\");\n", "txt1->SetTextColor(kBlue);\n", "txt1->SetTextFont(42);\n", "c->Add(txt1);" ] }, { "cell_type": "markdown", "id": "f3853a2f", "metadata": {}, "source": [ "Draw all canvases " ] }, { "cell_type": "code", "execution_count": 5, "id": "11c5b428", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:36:46.330135Z", "iopub.status.busy": "2026-05-19T20:36:46.330019Z", "iopub.status.idle": "2026-05-19T20:36:46.539284Z", "shell.execute_reply": "2026-05-19T20:36:46.538633Z" } }, "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 }