{ "cells": [ { "cell_type": "markdown", "id": "ab4cffce", "metadata": {}, "source": [ "# vo007_PhysicsHelpers\n", "In this tutorial we demonstrate RVec helpers for physics computations such\n", "as angle differences $\\Delta \\phi$, the distance in the $\\eta$-$\\phi$\n", "plane $\\Delta R$ and the invariant mass.\n", "\n", "\n", "\n", "\n", "**Author:** Stefan Wunsch \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:28 PM." ] }, { "cell_type": "markdown", "id": "ed413ef8", "metadata": {}, "source": [ "The DeltaPhi helper computes the closest angle between angles.\n", "This means that the resulting value is in the range [-pi, pi]." ] }, { "cell_type": "markdown", "id": "37aeb7e4", "metadata": {}, "source": [ "Note that the helper also supports to compute the angle difference of an\n", "RVec and a scalar and two scalars. In addition, the computation of the\n", "difference and the behaviour at the boundary can be adjusted to radian and\n", "degrees." ] }, { "cell_type": "code", "execution_count": 1, "id": "ff658128", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:28:17.082787Z", "iopub.status.busy": "2026-05-19T20:28:17.082671Z", "iopub.status.idle": "2026-05-19T20:28:17.402105Z", "shell.execute_reply": "2026-05-19T20:28:17.401490Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_44:3:12: error: cannot deduce 'auto' from unknown expression\n", "auto idx = Combinations(phis, 2);\n", " ^\n" ] } ], "source": [ "ROOT::RVecF phis = {0.0, 1.0, -0.5, M_PI + 1.0};\n", "auto idx = Combinations(phis, 2);\n", "\n", "auto phi1 = Take(phis, idx[0]);\n", "auto phi2 = Take(phis, idx[1]);\n", "auto dphi = DeltaPhi(phi1, phi2);\n", "\n", "std::cout << \"DeltaPhi(phi1 = \" << phi1 << \",\\n\"\n", " << \" phi2 = \" << phi2 << \")\\n\"\n", " << \" = \" << dphi << \"\\n\";" ] }, { "cell_type": "markdown", "id": "bd85a15c", "metadata": {}, "source": [ "The DeltaR helper is similar to the DeltaPhi helper and computes the distance\n", "in the $\\eta$-$\\phi$ plane." ] }, { "cell_type": "code", "execution_count": 2, "id": "0dbd189f", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:28:17.403551Z", "iopub.status.busy": "2026-05-19T20:28:17.403433Z", "iopub.status.idle": "2026-05-19T20:28:17.609486Z", "shell.execute_reply": "2026-05-19T20:28:17.608914Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_53:4:13: error: cannot deduce 'auto' from unknown expression\n", "auto eta1 = Take(etas, idx[0]);\n", " ^\n" ] } ], "source": [ "ROOT::RVecF etas = {2.4, -1.5, 1.0, 0.0};\n", "\n", "auto eta1 = Take(etas, idx[0]);\n", "auto eta2 = Take(etas, idx[1]);\n", "auto dr = DeltaR(eta1, eta2, phi1, phi2);\n", "\n", "std::cout << \"\\nDeltaR(eta1 = \" << eta1 << \",\\n\"\n", " << \" eta2 = \" << eta2 << \",\\n\"\n", " << \" phi1 = \" << phi1 << \",\\n\"\n", " << \" phi2 = \" << phi2 << \")\\n\"\n", " << \" = \" << dr << \"\\n\";" ] }, { "cell_type": "markdown", "id": "3e212ff4", "metadata": {}, "source": [ "The InvariantMasses helper computes the invariant mass of a two particle system\n", "given the properties transverse momentum (pt), rapidity (eta), azimuth (phi)\n", "and mass." ] }, { "cell_type": "code", "execution_count": 3, "id": "845480d2", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:28:17.611036Z", "iopub.status.busy": "2026-05-19T20:28:17.610918Z", "iopub.status.idle": "2026-05-19T20:28:17.817170Z", "shell.execute_reply": "2026-05-19T20:28:17.816529Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_54:12:16: error: cannot deduce 'auto' from unknown expression\n", "auto invMass = InvariantMasses(pt3, eta3, phi3, mass3, pt4, eta4, phi4, mass4);\n", " ^\n" ] } ], "source": [ "ROOT::RVecF pt3 = {40, 20, 30};\n", "ROOT::RVecF eta3 = {2.5, 0.5, -1.0};\n", "ROOT::RVecF phi3 = {-0.5, 0.0, 1.0};\n", "ROOT::RVecF mass3 = {10, 10, 10};\n", "\n", "ROOT::RVecF pt4 = {20, 10, 40};\n", "ROOT::RVecF eta4 = {0.5, -0.5, 1.0};\n", "ROOT::RVecF phi4 = {0.0, 1.0, -1.0};\n", "ROOT::RVecF mass4 = {2, 2, 2};\n", "\n", "auto invMass = InvariantMasses(pt3, eta3, phi3, mass3, pt4, eta4, phi4, mass4);\n", "\n", "std::cout << \"\\nInvariantMass(pt1 = \" << pt3 << \",\\n\"\n", " << \" eta1 = \" << eta3 << \",\\n\"\n", " << \" phi1 = \" << phi3 << \",\\n\"\n", " << \" mass1 = \" << mass3 << \",\\n\"\n", " << \" pt2 = \" << pt4 << \",\\n\"\n", " << \" eta2 = \" << eta4 << \",\\n\"\n", " << \" phi2 = \" << phi4 << \",\\n\"\n", " << \" mass2 = \" << mass4 << \")\\n\"\n", " << \" = \" << invMass << \"\\n\";" ] }, { "cell_type": "markdown", "id": "62b5735f", "metadata": {}, "source": [ "The InvariantMass helper also accepts a single set of (pt, eta, phi, mass) vectors. Then,\n", "the invariant mass of all particles in the collection is computed." ] }, { "cell_type": "code", "execution_count": 4, "id": "7a9ba539", "metadata": { "collapsed": false, "execution": { "iopub.execute_input": "2026-05-19T20:28:17.818585Z", "iopub.status.busy": "2026-05-19T20:28:17.818472Z", "iopub.status.idle": "2026-05-19T20:28:18.024594Z", "shell.execute_reply": "2026-05-19T20:28:18.023965Z" } }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "input_line_55:2:18: error: cannot deduce 'auto' from unknown expression\n", " auto invMass2 = InvariantMass(pt3, eta3, phi3, mass3);\n", " ^\n" ] } ], "source": [ "auto invMass2 = InvariantMass(pt3, eta3, phi3, mass3);\n", "\n", "std::cout << \"\\nInvariantMass(pt = \" << pt3 << \",\\n\"\n", " << \" eta = \" << eta3 << \",\\n\"\n", " << \" phi = \" << phi3 << \",\\n\"\n", " << \" mass = \" << mass3 << \")\\n\"\n", " << \" = \" << invMass2 << \"\\n\";" ] } ], "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 }